From 9be38780cd6357748c8d2976660f4c251623aaec Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 18 Jan 2023 15:50:52 +0200 Subject: [PATCH] Removed remaining parts of Geomeotries.h/cpp --- client/CMakeLists.txt | 3 +- client/CMessage.h | 1 - client/CVideoHandler.cpp | 2 +- client/Graphics.h | 1 - client/battle/BattleAnimationClasses.h | 1 - client/battle/BattleEffectsController.h | 2 +- client/battle/BattleProjectileController.cpp | 1 - client/battle/BattleProjectileController.h | 3 +- client/battle/BattleStacksController.h | 2 +- client/gui/CAnimation.h | 3 +- client/gui/CGuiHandler.h | 2 +- client/gui/CIntObject.h | 3 +- client/gui/Canvas.cpp | 1 - client/gui/Canvas.h | 3 +- client/gui/CursorHandler.h | 2 +- client/gui/Geometries.cpp | 35 -------------- client/gui/Geometries.h | 42 ---------------- client/gui/InterfaceObjectConfigurable.h | 1 + client/gui/SDL_Extensions.cpp | 51 ++++++++++++++++---- client/gui/SDL_Extensions.h | 22 +++++---- client/gui/TextAlignment.h | 12 +++++ client/mapHandler.h | 2 +- client/widgets/AdventureMapClasses.cpp | 4 +- client/widgets/TextControls.h | 1 + client/windows/CAdvmapInterface.cpp | 2 +- client/windows/InfoWindows.cpp | 2 +- client/windows/InfoWindows.h | 1 + 27 files changed, 86 insertions(+), 119 deletions(-) delete mode 100644 client/gui/Geometries.cpp delete mode 100644 client/gui/Geometries.h create mode 100644 client/gui/TextAlignment.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 668698873..ea7c16cd8 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -23,7 +23,6 @@ set(client_SRCS gui/CIntObject.cpp gui/ColorFilter.cpp gui/Fonts.cpp - gui/Geometries.cpp gui/SDL_Extensions.cpp gui/NotificationHandler.cpp gui/InterfaceObjectConfigurable.cpp @@ -110,7 +109,7 @@ set(client_HEADERS gui/ColorFilter.h gui/CIntObject.h gui/Fonts.h - gui/Geometries.h + gui/TextAlignment.h gui/SDL_Compat.h gui/SDL_Extensions.h gui/SDL_Pixels.h diff --git a/client/CMessage.h b/client/CMessage.h index d407eadb2..8eac68881 100644 --- a/client/CMessage.h +++ b/client/CMessage.h @@ -10,7 +10,6 @@ #pragma once #include "Graphics.h" -#include "gui/Geometries.h" struct SDL_Surface; class CInfoWindow; diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index c9464d1dc..46514e598 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -442,7 +442,7 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey) if(stopOnKey && keyDown()) return false; - SDL_Rect rect = Geometry::toSDL(pos); + SDL_Rect rect = CSDL_Ext::toSDL(pos); SDL_RenderCopy(mainRenderer, texture, nullptr, &rect); SDL_RenderPresent(mainRenderer); diff --git a/client/Graphics.h b/client/Graphics.h index 947ffddc6..0b539d396 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -11,7 +11,6 @@ #include "gui/Fonts.h" #include "../lib/GameConstants.h" -#include "gui/Geometries.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/client/battle/BattleAnimationClasses.h b/client/battle/BattleAnimationClasses.h index 867234977..580e1b7c1 100644 --- a/client/battle/BattleAnimationClasses.h +++ b/client/battle/BattleAnimationClasses.h @@ -10,7 +10,6 @@ #pragma once #include "../../lib/battle/BattleHex.h" -#include "../gui/Geometries.h" #include "BattleConstants.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/client/battle/BattleEffectsController.h b/client/battle/BattleEffectsController.h index cb7a1bf30..49af24316 100644 --- a/client/battle/BattleEffectsController.h +++ b/client/battle/BattleEffectsController.h @@ -10,7 +10,7 @@ #pragma once #include "../../lib/battle/BattleHex.h" -#include "../gui/Geometries.h" +#include "../../lib/Point.h" #include "BattleConstants.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/client/battle/BattleProjectileController.cpp b/client/battle/BattleProjectileController.cpp index f9862fa7e..429d11fc1 100644 --- a/client/battle/BattleProjectileController.cpp +++ b/client/battle/BattleProjectileController.cpp @@ -15,7 +15,6 @@ #include "BattleStacksController.h" #include "CreatureAnimation.h" -#include "../gui/Geometries.h" #include "../gui/CAnimation.h" #include "../gui/Canvas.h" #include "../gui/CGuiHandler.h" diff --git a/client/battle/BattleProjectileController.h b/client/battle/BattleProjectileController.h index 10b201b2b..102a99f09 100644 --- a/client/battle/BattleProjectileController.h +++ b/client/battle/BattleProjectileController.h @@ -10,7 +10,7 @@ #pragma once #include "../../lib/CCreatureHandler.h" -#include "../gui/Geometries.h" +#include "../../lib/Point.h" VCMI_LIB_NAMESPACE_BEGIN @@ -19,7 +19,6 @@ class CSpell; VCMI_LIB_NAMESPACE_END -class Point; class CAnimation; class Canvas; class BattleInterface; diff --git a/client/battle/BattleStacksController.h b/client/battle/BattleStacksController.h index 0e3113c25..31d859c73 100644 --- a/client/battle/BattleStacksController.h +++ b/client/battle/BattleStacksController.h @@ -9,7 +9,6 @@ */ #pragma once -#include "../gui/Geometries.h" #include "../gui/ColorFilter.h" VCMI_LIB_NAMESPACE_BEGIN @@ -33,6 +32,7 @@ class CreatureAnimation; class BattleAnimation; class BattleRenderer; class IImage; +class Point; struct BattleStackFilterEffect { diff --git a/client/gui/CAnimation.h b/client/gui/CAnimation.h index add6a3f72..d32ab424e 100644 --- a/client/gui/CAnimation.h +++ b/client/gui/CAnimation.h @@ -10,7 +10,6 @@ #pragma once #include "../../lib/vcmi_endian.h" -#include "Geometries.h" #include "../../lib/GameConstants.h" #ifdef IN @@ -31,6 +30,8 @@ struct SDL_Surface; struct SDL_Color; class CDefFile; class ColorFilter; +class Rect; +class Point; /* * Base class for images, can be used for non-animation pictures as well diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index e2c0385fb..38f540185 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -9,7 +9,7 @@ */ #pragma once -#include "Geometries.h" +#include "../../lib/Point.h" #include diff --git a/client/gui/CIntObject.h b/client/gui/CIntObject.h index 8ec51eb5f..e4836c544 100644 --- a/client/gui/CIntObject.h +++ b/client/gui/CIntObject.h @@ -9,7 +9,7 @@ */ #pragma once -#include "Geometries.h" +#include "../../lib/Rect.h" #include "../Graphics.h" struct SDL_Surface; @@ -19,6 +19,7 @@ class CPicture; struct SDL_KeyboardEvent; struct SDL_TextInputEvent; struct SDL_TextEditingEvent; +struct SDL_MouseMotionEvent; using boost::logic::tribool; diff --git a/client/gui/Canvas.cpp b/client/gui/Canvas.cpp index c35a9de48..adc443924 100644 --- a/client/gui/Canvas.cpp +++ b/client/gui/Canvas.cpp @@ -11,7 +11,6 @@ #include "Canvas.h" #include "SDL_Extensions.h" -#include "Geometries.h" #include "CAnimation.h" #include "../Graphics.h" diff --git a/client/gui/Canvas.h b/client/gui/Canvas.h index 80d16040e..d4fcc1619 100644 --- a/client/gui/Canvas.h +++ b/client/gui/Canvas.h @@ -9,7 +9,8 @@ */ #pragma once -#include "Geometries.h" +#include "TextAlignment.h" +#include "../../lib/Rect.h" struct SDL_Color; struct SDL_Surface; diff --git a/client/gui/CursorHandler.h b/client/gui/CursorHandler.h index c769da048..b66bfb92b 100644 --- a/client/gui/CursorHandler.h +++ b/client/gui/CursorHandler.h @@ -15,7 +15,7 @@ struct SDL_Surface; struct SDL_Texture; struct SDL_Cursor; -#include "Geometries.h" +#include "../../lib/Point.h" namespace Cursor { diff --git a/client/gui/Geometries.cpp b/client/gui/Geometries.cpp deleted file mode 100644 index 530cbebe4..000000000 --- a/client/gui/Geometries.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Geometries.cpp, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -#include "StdInc.h" -#include "Geometries.h" - -#include -#include - -Rect Geometry::fromSDL(const SDL_Rect & rect) -{ - return Rect(Point(rect.x, rect.y), Point(rect.w, rect.h)); -} - -SDL_Rect Geometry::toSDL(const Rect & rect) -{ - SDL_Rect result; - result.x = rect.x; - result.y = rect.y; - result.w = rect.w; - result.h = rect.h; - return result; -} - -Point Geometry::fromSDL(const SDL_MouseMotionEvent & motion) -{ - return { motion.x, motion.y }; -} diff --git a/client/gui/Geometries.h b/client/gui/Geometries.h deleted file mode 100644 index e2d60050a..000000000 --- a/client/gui/Geometries.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Geometries.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ -#pragma once - -struct SDL_MouseMotionEvent; -struct SDL_Rect; - -#include "../../lib/Point.h" -#include "../../lib/Rect.h" - -VCMI_LIB_NAMESPACE_BEGIN -class int3; -VCMI_LIB_NAMESPACE_END - -#ifdef VCMI_LIB_NAMESPACE -using VCMI_LIB_WRAP_NAMESPACE(Rect); -using VCMI_LIB_WRAP_NAMESPACE(Point); -#endif - -enum class ETextAlignment {TOPLEFT, CENTER, BOTTOMRIGHT}; - -namespace Geometry -{ - -/// creates Point using provided event -Point fromSDL(const SDL_MouseMotionEvent & motion); - -/// creates Rect using provided rect -Rect fromSDL(const SDL_Rect & rect); - -/// creates SDL_Rect using provided rect -SDL_Rect toSDL(const Rect & rect); - -} - diff --git a/client/gui/InterfaceObjectConfigurable.h b/client/gui/InterfaceObjectConfigurable.h index ccdb11efa..7506592fc 100644 --- a/client/gui/InterfaceObjectConfigurable.h +++ b/client/gui/InterfaceObjectConfigurable.h @@ -11,6 +11,7 @@ #pragma once #include "CIntObject.h" +#include "TextAlignment.h" #include "../../lib/JsonNode.h" diff --git a/client/gui/SDL_Extensions.cpp b/client/gui/SDL_Extensions.cpp index 7fe62b4e3..b2ef89c3c 100644 --- a/client/gui/SDL_Extensions.cpp +++ b/client/gui/SDL_Extensions.cpp @@ -41,6 +41,37 @@ const SDL_Color Colors::PURPLE = {255, 75, 125, SDL_ALPHA_OPAQUE}; const SDL_Color Colors::BLACK = {0, 0, 0, SDL_ALPHA_OPAQUE}; const SDL_Color Colors::TRANSPARENT = {0, 0, 0, SDL_ALPHA_TRANSPARENT}; +Rect CSDL_Ext::genRect(const int & hh, const int & ww, const int & xx, const int & yy) +{ + Rect ret; + ret.h=hh; + ret.w=ww; + ret.x=xx; + ret.y=yy; + return ret; +} + +Rect CSDL_Ext::fromSDL(const SDL_Rect & rect) +{ + return Rect(Point(rect.x, rect.y), Point(rect.w, rect.h)); +} + +SDL_Rect CSDL_Ext::toSDL(const Rect & rect) +{ + SDL_Rect result; + result.x = rect.x; + result.y = rect.y; + result.w = rect.w; + result.h = rect.h; + return result; +} + +Point CSDL_Ext::fromSDL(const SDL_MouseMotionEvent & motion) +{ + return { motion.x, motion.y }; +} + + void CSDL_Ext::setColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) { SDL_SetPaletteColors(surface->format->palette,colors,firstcolor,ncolors); @@ -73,7 +104,7 @@ void CSDL_Ext::setAlpha(SDL_Surface * bg, int value) void CSDL_Ext::updateRect(SDL_Surface *surface, const Rect & rect ) { - SDL_Rect rectSDL = Geometry::toSDL(rect); + SDL_Rect rectSDL = CSDL_Ext::toSDL(rect); if(0 !=SDL_UpdateTexture(screenTexture, &rectSDL, surface->pixels, surface->pitch)) logGlobal->error("%sSDL_UpdateTexture %s", __FUNCTION__, SDL_GetError()); @@ -220,8 +251,8 @@ Uint32 CSDL_Ext::getPixel(SDL_Surface *surface, const int & x, const int & y, bo template int CSDL_Ext::blit8bppAlphaTo24bppT(const SDL_Surface * src, const Rect & srcRectInput, SDL_Surface * dst, const Point & dstPointInput) { - SDL_Rect srcRectInstance = Geometry::toSDL(srcRectInput); - SDL_Rect dstRectInstance = Geometry::toSDL(Rect(dstPointInput, srcRectInput.dimensions())); + SDL_Rect srcRectInstance = CSDL_Ext::toSDL(srcRectInput); + SDL_Rect dstRectInstance = CSDL_Ext::toSDL(Rect(dstPointInput, srcRectInput.dimensions())); SDL_Rect * srcRect =&srcRectInstance; SDL_Rect * dstRect =&dstRectInstance; @@ -803,8 +834,8 @@ SDL_Surface * CSDL_Ext::scaleSurface(SDL_Surface *surf, int width, int height) void CSDL_Ext::blitSurface(SDL_Surface * src, const Rect & srcRectInput, SDL_Surface * dst, const Point & dstPoint) { - SDL_Rect srcRect = Geometry::toSDL(srcRectInput); - SDL_Rect dstRect = Geometry::toSDL(Rect(dstPoint, srcRectInput.dimensions())); + SDL_Rect srcRect = CSDL_Ext::toSDL(srcRectInput); + SDL_Rect dstRect = CSDL_Ext::toSDL(Rect(dstPoint, srcRectInput.dimensions())); SDL_UpperBlit(src, &srcRect, dst, &dstRect); } @@ -825,7 +856,7 @@ void CSDL_Ext::fillSurface( SDL_Surface *dst, const SDL_Color & color ) void CSDL_Ext::fillRect( SDL_Surface *dst, const Rect & dstrect, const SDL_Color & color ) { - SDL_Rect newRect = Geometry::toSDL(dstrect); + SDL_Rect newRect = CSDL_Ext::toSDL(dstrect); uint32_t sdlColor = SDL_MapRGBA(dst->format, color.r, color.g, color.b, color.a); SDL_FillRect(dst, &newRect, sdlColor); @@ -859,9 +890,9 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a) void CSDL_Ext::startTextInput(const Rect & whereInput) { - SDL_Rect where = Geometry::toSDL(whereInput); + const SDL_Rect where = CSDL_Ext::toSDL(whereInput); - auto impl = [](SDL_Rect & where) + auto impl = [](SDL_Rect where) { if (SDL_IsTextInputActive() == SDL_FALSE) { @@ -945,7 +976,7 @@ void CSDL_Ext::setDefaultColorKeyPresize(SDL_Surface * surface) void CSDL_Ext::setClipRect(SDL_Surface * src, const Rect & other) { - SDL_Rect rect = Geometry::toSDL(other); + SDL_Rect rect = CSDL_Ext::toSDL(other); SDL_SetClipRect(src, &rect); } @@ -956,7 +987,7 @@ void CSDL_Ext::getClipRect(SDL_Surface * src, Rect & other) SDL_GetClipRect(src, &rect); - other = Geometry::fromSDL(rect); + other = CSDL_Ext::fromSDL(rect); } diff --git a/client/gui/SDL_Extensions.h b/client/gui/SDL_Extensions.h index 75a4339cc..9d39021ea 100644 --- a/client/gui/SDL_Extensions.h +++ b/client/gui/SDL_Extensions.h @@ -11,8 +11,8 @@ #pragma once #include #include -#include "Geometries.h" #include "../../lib/GameConstants.h" +#include "../../lib/Rect.h" struct SDL_Window; struct SDL_Renderer; @@ -26,6 +26,7 @@ extern SDL_Texture * screenTexture; extern SDL_Surface * screen, *screen2, *screenBuf; class Rect; +class Point; /** * The colors class defines color constants of type SDL_Color. @@ -68,6 +69,15 @@ public: namespace CSDL_Ext { +/// creates Point using provided event +Point fromSDL(const SDL_MouseMotionEvent & motion); + +/// creates Rect using provided rect +Rect fromSDL(const SDL_Rect & rect); + +/// creates SDL_Rect using provided rect +SDL_Rect toSDL(const Rect & rect); + void setColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors); void warpMouse(int x, int y); bool isCtrlKeyDown(); @@ -95,15 +105,7 @@ std::string makeNumberShort(IntType number, IntType maxLength = 3) //the output return boost::lexical_cast(number) + *iter; } -inline Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy) -{ - Rect ret; - ret.h=hh; - ret.w=ww; - ret.x=xx; - ret.y=yy; - return ret; -} +Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy); typedef void (*TColorPutter)(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B); typedef void (*TColorPutterAlpha)(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B, const Uint8 & A); diff --git a/client/gui/TextAlignment.h b/client/gui/TextAlignment.h new file mode 100644 index 000000000..8cb379e70 --- /dev/null +++ b/client/gui/TextAlignment.h @@ -0,0 +1,12 @@ +/* + * TextAlignment.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +enum class ETextAlignment {TOPLEFT, CENTER, BOTTOMRIGHT}; diff --git a/client/mapHandler.h b/client/mapHandler.h index 3d4127c7a..daca70154 100644 --- a/client/mapHandler.h +++ b/client/mapHandler.h @@ -12,7 +12,7 @@ #include "../lib/int3.h" #include "../lib/spells/ViewSpellInt.h" -#include "gui/Geometries.h" +#include "../lib/Rect.h" #include "SDL.h" #ifdef IN diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index 732091417..2b7968b90 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -237,7 +237,7 @@ void CHeroList::CHeroItem::open() void CHeroList::CHeroItem::showTooltip() { - CRClickPopup::createAndPush(hero, Geometry::fromSDL(GH.current->motion)); + CRClickPopup::createAndPush(hero, CSDL_Ext::fromSDL(GH.current->motion)); } std::string CHeroList::CHeroItem::getHoverText() @@ -329,7 +329,7 @@ void CTownList::CTownItem::open() void CTownList::CTownItem::showTooltip() { - CRClickPopup::createAndPush(town, Geometry::fromSDL(GH.current->motion)); + CRClickPopup::createAndPush(town, CSDL_Ext::fromSDL(GH.current->motion)); } std::string CTownList::CTownItem::getHoverText() diff --git a/client/widgets/TextControls.h b/client/widgets/TextControls.h index 70092d0f8..064e47536 100644 --- a/client/widgets/TextControls.h +++ b/client/widgets/TextControls.h @@ -10,6 +10,7 @@ #pragma once #include "../gui/CIntObject.h" +#include "../gui/TextAlignment.h" #include "../gui/SDL_Extensions.h" #include "../../lib/FunctionList.h" diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index 8a0c23a65..7ae0a3796 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -1814,7 +1814,7 @@ void CAdvMapInt::tileRClicked(const int3 &mapPos) return; } - CRClickPopup::createAndPush(obj, Geometry::fromSDL(GH.current->motion), ETextAlignment::CENTER); + CRClickPopup::createAndPush(obj, CSDL_Ext::fromSDL(GH.current->motion), ETextAlignment::CENTER); } void CAdvMapInt::enterCastingMode(const CSpell * sp) diff --git a/client/windows/InfoWindows.cpp b/client/windows/InfoWindows.cpp index 18cecd486..3641941dd 100644 --- a/client/windows/InfoWindows.cpp +++ b/client/windows/InfoWindows.cpp @@ -306,7 +306,7 @@ void CRClickPopup::createAndPush(const std::string &txt, const CInfoWindow::TCom player = PlayerColor(1); auto temp = std::make_shared(txt, player, comps); - temp->center(Geometry::fromSDL(GH.current->motion)); //center on mouse + temp->center(CSDL_Ext::fromSDL(GH.current->motion)); //center on mouse #ifdef VCMI_IOS // TODO: enable also for android? temp->moveBy({0, -temp->pos.h / 2}); diff --git a/client/windows/InfoWindows.h b/client/windows/InfoWindows.h index b73af37e3..870b2b5ea 100644 --- a/client/windows/InfoWindows.h +++ b/client/windows/InfoWindows.h @@ -10,6 +10,7 @@ #pragma once #include "CWindowObject.h" +#include "../gui/TextAlignment.h" #include "../../lib/FunctionList.h" VCMI_LIB_NAMESPACE_BEGIN