From ede7eab7e86e823e5955c3d2ea45066e96709881 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 15 Jun 2022 09:46:15 +0100 Subject: [PATCH] Fix `-wnarrowing` from `SDL_Rect` construction --- Source/DiabloUI/diabloui.cpp | 4 ++-- Source/DiabloUI/selstart.cpp | 3 ++- Source/DiabloUI/title.cpp | 5 +++-- Source/utils/display.cpp | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 91c93d547..3bfac9b38 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -705,13 +705,13 @@ void UiAddBackground(std::vector> *vecDialog) vecDialog->push_back(std::make_unique(PcxSprite { *ArtBackgroundWidescreen }, rectw, UiFlags::AlignCenter)); } - SDL_Rect rect = { 0, uiPositionY, 0, 0 }; + SDL_Rect rect = MakeSdlRect(0, uiPositionY, 0, 0); vecDialog->push_back(std::make_unique(PcxSpriteSheet { *ArtBackground }.sprite(0), rect, UiFlags::AlignCenter)); } void UiAddLogo(std::vector> *vecDialog, int size, int y) { - SDL_Rect rect = { 0, (Sint16)(GetUIRectangle().position.y + y), 0, 0 }; + SDL_Rect rect = MakeSdlRect(0, GetUIRectangle().position.y + y, 0, 0); vecDialog->push_back(std::make_unique( CelSpriteWithFrameHeight { ArtLogos[size]->sprite, ArtLogos[size]->frameHeight }, rect, UiFlags::AlignCenter, /*bAnimated=*/true)); } diff --git a/Source/DiabloUI/selstart.cpp b/Source/DiabloUI/selstart.cpp index d28f1a97e..6ef8848dc 100644 --- a/Source/DiabloUI/selstart.cpp +++ b/Source/DiabloUI/selstart.cpp @@ -5,6 +5,7 @@ #include "engine/load_pcx.hpp" #include "options.h" #include "utils/language.h" +#include "utils/sdl_geometry.h" namespace devilution { namespace { @@ -39,7 +40,7 @@ void UiSelStartUpGameOption() UiAddBackground(&vecDialog); const Point uiPosition = GetUIRectangle().position; - SDL_Rect rect = { 0, (Sint16)(uiPosition.y), 0, 0 }; + SDL_Rect rect = MakeSdlRect(0, uiPosition.y, 0, 0); vecDialog.push_back(std::make_unique(&artLogo, rect, UiFlags::AlignCenter, /*bAnimated=*/true)); vecDialogItems.push_back(std::make_unique(_("Enter Hellfire"), static_cast(StartUpGameMode::Hellfire))); diff --git a/Source/DiabloUI/title.cpp b/Source/DiabloUI/title.cpp index 34582a4dd..75f143c55 100644 --- a/Source/DiabloUI/title.cpp +++ b/Source/DiabloUI/title.cpp @@ -6,6 +6,7 @@ #include "engine/load_pcx.hpp" #include "engine/load_pcx_as_cel.hpp" #include "utils/language.h" +#include "utils/sdl_geometry.h" namespace devilution { namespace { @@ -39,7 +40,7 @@ void UiTitleDialog() TitleLoad(); const Point uiPosition = GetUIRectangle().position; if (gbIsHellfire) { - SDL_Rect rect = { 0, uiPosition.y, 0, 0 }; + SDL_Rect rect = MakeSdlRect(0, uiPosition.y, 0, 0); if (ArtBackgroundWidescreen) vecTitleScreen.push_back(std::make_unique(PcxSprite { *ArtBackgroundWidescreen }, rect, UiFlags::AlignCenter)); vecTitleScreen.push_back(std::make_unique(PcxSpriteSheet { *ArtBackground }, rect, UiFlags::AlignCenter)); @@ -47,7 +48,7 @@ void UiTitleDialog() UiAddBackground(&vecTitleScreen); UiAddLogo(&vecTitleScreen, LOGO_BIG, 182); - SDL_Rect rect = { (Sint16)(uiPosition.x), (Sint16)(uiPosition.y + 410), 640, 26 }; + SDL_Rect rect = MakeSdlRect(uiPosition.x, uiPosition.y + 410, 640, 26); vecTitleScreen.push_back(std::make_unique(_("Copyright © 1996-2001 Blizzard Entertainment").data(), rect, UiFlags::AlignCenter | UiFlags::FontSize24 | UiFlags::ColorUiSilver)); } diff --git a/Source/utils/display.cpp b/Source/utils/display.cpp index fc190eeb1..bdc87e730 100644 --- a/Source/utils/display.cpp +++ b/Source/utils/display.cpp @@ -23,6 +23,7 @@ #include "dx.h" #include "options.h" #include "utils/log.hpp" +#include "utils/sdl_geometry.h" #include "utils/sdl_wrap.h" #ifdef USE_SDL1 @@ -497,7 +498,7 @@ namespace { SDLSurfaceUniquePtr CreateScaledSurface(SDL_Surface *src) { - SDL_Rect stretched_rect = { 0, 0, static_cast(src->w), static_cast(src->h) }; + SDL_Rect stretched_rect = MakeSdlRect(0, 0, src->w, src->h); ScaleOutputRect(&stretched_rect); SDLSurfaceUniquePtr stretched = SDLWrap::CreateRGBSurface( SDL_SWSURFACE, stretched_rect.w, stretched_rect.h, src->format->BitsPerPixel,