1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Removed remaining parts of Geomeotries.h/cpp

This commit is contained in:
Ivan Savenko 2023-01-18 15:50:52 +02:00
parent 6e2d09d605
commit 9be38780cd
27 changed files with 86 additions and 119 deletions

View File

@ -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

View File

@ -10,7 +10,6 @@
#pragma once
#include "Graphics.h"
#include "gui/Geometries.h"
struct SDL_Surface;
class CInfoWindow;

View File

@ -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);

View File

@ -11,7 +11,6 @@
#include "gui/Fonts.h"
#include "../lib/GameConstants.h"
#include "gui/Geometries.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -10,7 +10,6 @@
#pragma once
#include "../../lib/battle/BattleHex.h"
#include "../gui/Geometries.h"
#include "BattleConstants.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -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

View File

@ -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"

View File

@ -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;

View File

@ -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
{

View File

@ -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

View File

@ -9,7 +9,7 @@
*/
#pragma once
#include "Geometries.h"
#include "../../lib/Point.h"
#include <SDL_events.h>

View File

@ -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;

View File

@ -11,7 +11,6 @@
#include "Canvas.h"
#include "SDL_Extensions.h"
#include "Geometries.h"
#include "CAnimation.h"
#include "../Graphics.h"

View File

@ -9,7 +9,8 @@
*/
#pragma once
#include "Geometries.h"
#include "TextAlignment.h"
#include "../../lib/Rect.h"
struct SDL_Color;
struct SDL_Surface;

View File

@ -15,7 +15,7 @@ struct SDL_Surface;
struct SDL_Texture;
struct SDL_Cursor;
#include "Geometries.h"
#include "../../lib/Point.h"
namespace Cursor
{

View File

@ -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 <SDL_rect.h>
#include <SDL_events.h>
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 };
}

View File

@ -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);
}

View File

@ -11,6 +11,7 @@
#pragma once
#include "CIntObject.h"
#include "TextAlignment.h"
#include "../../lib/JsonNode.h"

View File

@ -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 bpp>
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);
}

View File

@ -11,8 +11,8 @@
#pragma once
#include <SDL_render.h>
#include <SDL_events.h>
#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<std::string>(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);

View File

@ -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};

View File

@ -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

View File

@ -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()

View File

@ -10,6 +10,7 @@
#pragma once
#include "../gui/CIntObject.h"
#include "../gui/TextAlignment.h"
#include "../gui/SDL_Extensions.h"
#include "../../lib/FunctionList.h"

View File

@ -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)

View File

@ -306,7 +306,7 @@ void CRClickPopup::createAndPush(const std::string &txt, const CInfoWindow::TCom
player = PlayerColor(1);
auto temp = std::make_shared<CInfoWindow>(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});

View File

@ -10,6 +10,7 @@
#pragma once
#include "CWindowObject.h"
#include "../gui/TextAlignment.h"
#include "../../lib/FunctionList.h"
VCMI_LIB_NAMESPACE_BEGIN