1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Removed some instances of access to screen surface

This commit is contained in:
Ivan Savenko 2023-02-03 18:23:53 +02:00
parent 00c1a4ef76
commit 7c58a46279
20 changed files with 102 additions and 103 deletions

View File

@ -10,6 +10,7 @@
#include "StdInc.h"
#include "CVideoHandler.h"
#include "CMT.h"
#include "gui/CGuiHandler.h"
#include "renderSDL/SDL_Extensions.h"
#include "CPlayerInterface.h"

View File

@ -43,8 +43,6 @@
#include "../../lib/UnlockGuard.h"
#include "../../lib/TerrainHandler.h"
#include <SDL_surface.h>
#define ADVOPT (conf.go()->ac)
std::shared_ptr<CAdvMapInt> adventureInt;
@ -90,8 +88,8 @@ CAdvMapInt::CAdvMapInt():
swipeTargetPosition(int3(-1, -1, -1))
{
pos.x = pos.y = 0;
pos.w = screen->w;
pos.h = screen->h;
pos.w = GH.screenDimensions().x;
pos.h = GH.screenDimensions().y;
strongInterest = true; // handle all mouse move events to prevent dead mouse move space in fullscreen mode
townList.onSelect = std::bind(&CAdvMapInt::selectionChanged,this);
bg = IImage::createFromFile(ADVOPT.mainGraphic);
@ -137,7 +135,7 @@ CAdvMapInt::CAdvMapInt():
nextHero = makeButton(301, std::bind(&CAdvMapInt::fnextHero,this), ADVOPT.nextHero, SDLK_h);
endTurn = makeButton(302, std::bind(&CAdvMapInt::fendTurn,this), ADVOPT.endTurn, SDLK_e);
int panelSpaceBottom = screen->h - resdatabar.pos.h - 4;
int panelSpaceBottom = GH.screenDimensions().y - resdatabar.pos.h - 4;
panelMain = std::make_shared<CAdvMapPanel>(nullptr, Point(0, 0));
// TODO correct drawing position
@ -158,7 +156,7 @@ CAdvMapInt::CAdvMapInt():
// TODO move configs to resolutions.json, similarly to previous buttons
config::ButtonInfo worldViewBackConfig = config::ButtonInfo();
worldViewBackConfig.defName = "IOK6432.DEF";
worldViewBackConfig.x = screen->w - 73;
worldViewBackConfig.x = GH.screenDimensions().x - 73;
worldViewBackConfig.y = 343 + 195;
worldViewBackConfig.playerColoured = false;
panelWorldView->addChildToPanel(
@ -166,7 +164,7 @@ CAdvMapInt::CAdvMapInt():
config::ButtonInfo worldViewPuzzleConfig = config::ButtonInfo();
worldViewPuzzleConfig.defName = "VWPUZ.DEF";
worldViewPuzzleConfig.x = screen->w - 188;
worldViewPuzzleConfig.x = GH.screenDimensions().x - 188;
worldViewPuzzleConfig.y = 343 + 195;
worldViewPuzzleConfig.playerColoured = false;
panelWorldView->addChildToPanel( // no help text for this one
@ -175,7 +173,7 @@ CAdvMapInt::CAdvMapInt():
config::ButtonInfo worldViewScale1xConfig = config::ButtonInfo();
worldViewScale1xConfig.defName = "VWMAG1.DEF";
worldViewScale1xConfig.x = screen->w - 191;
worldViewScale1xConfig.x = GH.screenDimensions().x - 191;
worldViewScale1xConfig.y = 23 + 195;
worldViewScale1xConfig.playerColoured = false;
panelWorldView->addChildToPanel( // help text is wrong for this button
@ -183,7 +181,7 @@ CAdvMapInt::CAdvMapInt():
config::ButtonInfo worldViewScale2xConfig = config::ButtonInfo();
worldViewScale2xConfig.defName = "VWMAG2.DEF";
worldViewScale2xConfig.x = screen->w - 191 + 63;
worldViewScale2xConfig.x = GH.screenDimensions().x- 191 + 63;
worldViewScale2xConfig.y = 23 + 195;
worldViewScale2xConfig.playerColoured = false;
panelWorldView->addChildToPanel( // help text is wrong for this button
@ -191,7 +189,7 @@ CAdvMapInt::CAdvMapInt():
config::ButtonInfo worldViewScale4xConfig = config::ButtonInfo();
worldViewScale4xConfig.defName = "VWMAG4.DEF";
worldViewScale4xConfig.x = screen->w - 191 + 126;
worldViewScale4xConfig.x = GH.screenDimensions().x- 191 + 126;
worldViewScale4xConfig.y = 23 + 195;
worldViewScale4xConfig.playerColoured = false;
panelWorldView->addChildToPanel( // help text is wrong for this button
@ -200,7 +198,7 @@ CAdvMapInt::CAdvMapInt():
config::ButtonInfo worldViewUndergroundConfig = config::ButtonInfo();
worldViewUndergroundConfig.defName = "IAM010.DEF";
worldViewUndergroundConfig.additionalDefs.push_back("IAM003.DEF");
worldViewUndergroundConfig.x = screen->w - 115;
worldViewUndergroundConfig.x = GH.screenDimensions().x - 115;
worldViewUndergroundConfig.y = 343 + 195;
worldViewUndergroundConfig.playerColoured = true;
worldViewUnderground = makeButton(294, std::bind(&CAdvMapInt::fswitchLevel,this), worldViewUndergroundConfig, SDLK_u);
@ -1019,7 +1017,7 @@ void CAdvMapInt::mouseMoved( const Point & cursorPosition )
{
scrollingDir &= ~LEFT;
}
if(cursorPosition.x>screen->w-15)
if(cursorPosition.x > GH.screenDimensions().x - 15)
{
scrollingDir |= RIGHT;
}
@ -1035,7 +1033,7 @@ void CAdvMapInt::mouseMoved( const Point & cursorPosition )
{
scrollingDir &= ~UP;
}
if(cursorPosition.y>screen->h-15)
if(cursorPosition.y > GH.screenDimensions().y - 15)
{
scrollingDir |= DOWN;
}

View File

@ -22,6 +22,7 @@
#include "../render/IImage.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../widgets/TextControls.h"
#include "../CMT.h"
#include "../../CCallback.h"
#include "../../lib/CConfigHandler.h"

View File

@ -48,8 +48,6 @@
#include "../../lib/CondSh.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include <SDL_surface.h>
void BattleConsole::showAll(SDL_Surface * to)
{
CIntObject::showAll(to);
@ -475,9 +473,9 @@ BattleResultWindow::BattleResultWindow(const BattleResult & br, CPlayerInterface
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
pos = CSDL_Ext::genRect(561, 470, (screen->w - 800)/2 + 165, (screen->h - 600)/2 + 19);
background = std::make_shared<CPicture>("CPRESULT");
background->colorize(owner.playerID);
pos = center(background->pos);
exit = std::make_shared<CButton>(Point(384, 505), "iok6432.def", std::make_pair("", ""), [&](){ bExitf();}, SDLK_RETURN);
exit->setBorderColor(Colors::METALLIC_GOLD);
@ -639,7 +637,7 @@ void BattleResultWindow::activate()
void BattleResultWindow::show(SDL_Surface * to)
{
CIntObject::show(to);
CCS->videoh->update(pos.x + 107, pos.y + 70, screen, true, false);
CCS->videoh->update(pos.x + 107, pos.y + 70, to, true, false);
}
void BattleResultWindow::bExitf()

View File

@ -28,7 +28,6 @@
#include "../render/CAnimation.h"
#include "../render/Canvas.h"
#include "../adventureMap/CInGameConsole.h"
#include "../CMT.h"
#include "../../CCallback.h"
#include "../../lib/CGeneralTextHandler.h"
@ -37,8 +36,6 @@
#include "../../lib/CConfigHandler.h"
#include "../../lib/filesystem/ResourceID.h"
#include <SDL_surface.h>
BattleWindow::BattleWindow(BattleInterface & owner):
owner(owner)
{
@ -79,9 +76,9 @@ BattleWindow::BattleWindow(BattleInterface & owner):
std::string queueSize = settings["battle"]["queueSize"].String();
if(queueSize == "auto")
embedQueue = screen->h < 700;
embedQueue = GH.screenDimensions().y < 700;
else
embedQueue = screen->h < 700 || queueSize == "small";
embedQueue = GH.screenDimensions().y < 700 || queueSize == "small";
queue = std::make_shared<StackQueue>(embedQueue, owner);
if(!embedQueue && settings["battle"]["showQueue"].Bool())
@ -562,7 +559,7 @@ void BattleWindow::showAll(SDL_Surface *to)
{
CIntObject::showAll(to);
if (screen->w != 800 || screen->h !=600)
if (GH.screenDimensions().x != 800 || GH.screenDimensions().y !=600)
CMessage::drawBorder(owner.curInt->playerID, to, pos.w+28, pos.h+29, pos.x-14, pos.y-15);
}

View File

@ -740,6 +740,11 @@ const Point & CGuiHandler::getCursorPosition() const
return cursorPosition;
}
Point CGuiHandler::screenDimensions() const
{
return return Point(screen->w, screen->h);
}
bool CGuiHandler::isMouseButtonPressed() const
{
return mouseButtonsMask > 0;

View File

@ -113,6 +113,8 @@ public:
/// returns current position of mouse cursor, relative to vcmi window
const Point & getCursorPosition() const;
Point screenDimensions() const;
/// returns true if at least one mouse button is pressed
bool isMouseButtonPressed() const;

View File

@ -13,9 +13,9 @@
#include "CGuiHandler.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../windows/CMessage.h"
#include "../CMT.h"
#include <SDL_pixels.h>
#include <SDL_surface.h>
IShowActivatable::IShowActivatable()
{
@ -227,8 +227,8 @@ void CIntObject::fitToScreen(int borderWidth, bool propagate)
Point newPos = pos.topLeft();
vstd::amax(newPos.x, borderWidth);
vstd::amax(newPos.y, borderWidth);
vstd::amin(newPos.x, screen->w - borderWidth - pos.w);
vstd::amin(newPos.y, screen->h - borderWidth - pos.h);
vstd::amin(newPos.x, GH.screenDimensions().x - borderWidth - pos.w);
vstd::amin(newPos.y, GH.screenDimensions().y - borderWidth - pos.h);
if (newPos != pos.topLeft())
moveTo(newPos, propagate);
}
@ -308,7 +308,7 @@ const Rect & CIntObject::center( const Rect &r, bool propagate )
{
pos.w = r.w;
pos.h = r.h;
return center(Point(screen->w/2, screen->h/2), propagate);
return center(Point(GH.screenDimensions().x/2, GH.screenDimensions().y/2), propagate);
}
const Rect & CIntObject::center( bool propagate )

View File

@ -17,7 +17,6 @@
#include "../render/CAnimation.h"
#include "../render/IImage.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../CMT.h"
#include "../../lib/CConfigHandler.h"

View File

@ -17,7 +17,6 @@
#include "../lobby/CSelectionBase.h"
#include "../lobby/CLobbyScreen.h"
#include "../gui/CursorHandler.h"
#include "../CMT.h"
#include "../windows/GUIClasses.h"
#include "../gui/CGuiHandler.h"
#include "../widgets/CComponent.h"
@ -33,6 +32,7 @@
#include "../CVideoHandler.h"
#include "../CPlayerInterface.h"
#include "../Client.h"
#include "../CMT.h"
#include "../../CCallback.h"
@ -53,7 +53,6 @@
#include "../../lib/CondSh.h"
#include "../../lib/mapping/CCampaignHandler.h"
#include <SDL_surface.h>
namespace fs = boost::filesystem;
@ -72,7 +71,7 @@ CMenuScreen::CMenuScreen(const JsonNode & configNode)
background = std::make_shared<CPicture>(config["background"].String());
if(config["scalable"].Bool())
background->scaleTo(Point(screen->w, screen->h));
background->scaleTo(GH.screenDimensions());
pos = background->center();
@ -275,8 +274,8 @@ const JsonNode & CMainMenuConfig::getCampaigns() const
CMainMenu::CMainMenu()
{
pos.w = screen->w;
pos.h = screen->h;
pos.w = GH.screenDimensions().x;
pos.h = GH.screenDimensions().y;
GH.defActionsDef = 63;
menu = std::make_shared<CMenuScreen>(CMainMenuConfig::get().getConfig()["window"]);

View File

@ -13,6 +13,7 @@
#include "../render/Colors.h"
#include "../render/IImage.h"
#include "../CMT.h"
#include "SDL_Extensions.h"
#include <SDL_render.h>

View File

@ -14,6 +14,7 @@
#include "../render/Graphics.h"
#include "../render/Colors.h"
#include "../CMT.h"
#include <SDL_render.h>
@ -97,6 +98,11 @@ void CSDL_Ext::updateRect(SDL_Surface *surface, const Rect & rect )
}
SDL_Surface * CSDL_Ext::newSurface(int w, int h)
{
return newSurface(w, h, screen);
}
SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given
{
SDL_Surface * ret = SDL_CreateRGBSurface(0,w,h,mod->format->BitsPerPixel,mod->format->Rmask,mod->format->Gmask,mod->format->Bmask,mod->format->Amask);

View File

@ -17,17 +17,12 @@ struct SDL_Rect;
struct SDL_Window;
struct SDL_Renderer;
struct SDL_Texture;
struct SDL_Surface;
struct SDL_Color;
extern SDL_Window * mainWindow;
extern SDL_Renderer * mainRenderer;
extern SDL_Texture * screenTexture;
extern SDL_Surface * screen, *screen2, *screenBuf;
VCMI_LIB_NAMESPACE_BEGIN
class Rect;
struct SDL_Surface;
struct SDL_Color;
VCMI_LIB_NAMESPACE_BEGIN
class Rect;
class Point;
VCMI_LIB_NAMESPACE_END
@ -44,45 +39,45 @@ SDL_Rect toSDL(const Rect & rect);
/// creates Color using provided SDL_Color
ColorRGBA fromSDL(const SDL_Color & color);
/// creates SDL_Color using provided Color
SDL_Color toSDL(const ColorRGBA & color);
void setColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
void setAlpha(SDL_Surface * bg, int value);
template<typename IntType>
std::string makeNumberShort(IntType number, IntType maxLength = 3) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k)
{
IntType max = pow(10, maxLength);
if (std::abs(number) < max)
return boost::lexical_cast<std::string>(number);
std::string symbols = " kMGTPE";
auto iter = symbols.begin();
while (number >= max)
{
number /= 1000;
iter++;
assert(iter != symbols.end());//should be enough even for int64
}
return boost::lexical_cast<std::string>(number) + *iter;
}
Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy);
typedef void (*TColorPutter)(uint8_t *&ptr, const uint8_t & R, const uint8_t & G, const uint8_t & B);
typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_t & G, const uint8_t & B, const uint8_t & A);
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen);
void blitAt(SDL_Surface * src, const Rect & pos, SDL_Surface * dst=screen);
void setClipRect(SDL_Surface * src, const Rect & other);
void getClipRect(SDL_Surface * src, Rect & other);
void blitSurface(SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dest);
void blitSurface(SDL_Surface * src, SDL_Surface * dst, const Point & dest);
/// creates SDL_Color using provided Color
SDL_Color toSDL(const ColorRGBA & color);
void setColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
void setAlpha(SDL_Surface * bg, int value);
template<typename IntType>
std::string makeNumberShort(IntType number, IntType maxLength = 3) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k)
{
IntType max = pow(10, maxLength);
if (std::abs(number) < max)
return boost::lexical_cast<std::string>(number);
std::string symbols = " kMGTPE";
auto iter = symbols.begin();
while (number >= max)
{
number /= 1000;
iter++;
assert(iter != symbols.end());//should be enough even for int64
}
return boost::lexical_cast<std::string>(number) + *iter;
}
Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy);
typedef void (*TColorPutter)(uint8_t *&ptr, const uint8_t & R, const uint8_t & G, const uint8_t & B);
typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_t & G, const uint8_t & B, const uint8_t & A);
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst);
void blitAt(SDL_Surface * src, const Rect & pos, SDL_Surface * dst);
void setClipRect(SDL_Surface * src, const Rect & other);
void getClipRect(SDL_Surface * src, Rect & other);
void blitSurface(SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dest);
void blitSurface(SDL_Surface * src, SDL_Surface * dst, const Point & dest);
void fillSurface(SDL_Surface *dst, const SDL_Color & color);
void fillRect(SDL_Surface *dst, const Rect & dstrect, const SDL_Color & color);
@ -114,13 +109,14 @@ typedef void (*TColorPutterAlpha)(uint8_t *&ptr, const uint8_t & R, const uint8_
void drawLine(SDL_Surface * sur, int x1, int y1, int x2, int y2, const SDL_Color & color1, const SDL_Color & color2);
void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const SDL_Color &color, int depth = 1);
void drawBorder(SDL_Surface * sur, const Rect &r, const SDL_Color &color, int depth = 1);
void drawDashedBorder(SDL_Surface * sur, const Rect &r, const SDL_Color &color);
void setPlayerColor(SDL_Surface * sur, PlayerColor player); //sets correct color of flags; -1 for neutral
std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string
SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=screen); //creates new surface, with flags/format same as in surface given
SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface
template<int bpp>
SDL_Surface * createSurfaceWithBpp(int width, int height); //create surface with give bits per pixels value
void drawDashedBorder(SDL_Surface * sur, const Rect &r, const SDL_Color &color);
void setPlayerColor(SDL_Surface * sur, PlayerColor player); //sets correct color of flags; -1 for neutral
std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string
SDL_Surface * newSurface(int w, int h, SDL_Surface * mod); //creates new surface, with flags/format same as in surface given
SDL_Surface * newSurface(int w, int h); //creates new surface, with flags/format same as in screen surface
SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface
template<int bpp>
SDL_Surface * createSurfaceWithBpp(int width, int height); //create surface with give bits per pixels value
void VflipSurf(SDL_Surface * surf); //fluipis given surface by vertical axis
//scale surface to required size.

View File

@ -43,7 +43,6 @@
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include <SDL_surface.h>
CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str)
: CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE, BUILDING_FRAME_TIME),
@ -1066,7 +1065,7 @@ void CCreaInfo::clickRight(tribool down, bool previousState)
if(down)
{
if (showAvailable)
GH.pushIntT<CDwellingInfoBox>(screen->w/2, screen->h/2, town, level);
GH.pushIntT<CDwellingInfoBox>(GH.screenDimensions().x/2, GH.screenDimensions().y/2, town, level);
else
CRClickPopup::createAndPush(genGrowthText(), std::make_shared<CComponent>(CComponent::creature, creature->idNumber));
}

View File

@ -15,7 +15,6 @@
#include "GUIClasses.h"
#include "../CGameInfo.h"
#include "../CMT.h"
#include "../CPlayerInterface.h"
#include "../gui/CGuiHandler.h"

View File

@ -14,7 +14,6 @@
#include "InfoWindows.h"
#include "../CGameInfo.h"
#include "../CMT.h"
#include "../CPlayerInterface.h"
#include "../gui/CGuiHandler.h"
#include "../widgets/CComponent.h"

View File

@ -211,8 +211,8 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
assert(ret && ret->text);
for(int i = 0;
i < ARRAY_COUNT(sizes)
&& sizes[i][0] < screen->w - 150
&& sizes[i][1] < screen->h - 150
&& sizes[i][0] < GH.screenDimensions().x - 150
&& sizes[i][1] < GH.screenDimensions().y - 150
&& ret->text->slider;
i++)
{
@ -254,7 +254,7 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
vstd::amax(winSize.first, comps.w);
vstd::amax(winSize.first, bw);
vstd::amin(winSize.first, screen->w - 150);
vstd::amin(winSize.first, GH.screenDimensions().x - 150);
ret->bitmap = drawDialogBox (winSize.first + 2*SIDE_MARGIN, winSize.second + 2*SIDE_MARGIN, player);
ret->pos.h=ret->bitmap->h;

View File

@ -17,7 +17,6 @@
#include "CCastleInterface.h"
#include "../CGameInfo.h"
#include "../CMT.h"
#include "../CPlayerInterface.h"
#include "../CVideoHandler.h"

View File

@ -69,7 +69,7 @@ CWindowObject::CWindowObject(int options_, std::string imageName):
if(background)
pos = background->center();
else
center(Point(screen->w/2, screen->h/2));
center(GH.screenDimensions() / 2);
if(!(options & SHADOW_DISABLED))
setShadow(true);

View File

@ -245,8 +245,8 @@ CInfoPopup::CInfoPopup(SDL_Surface *Bitmap, bool Free)
if(bitmap)
{
pos.x = screen->w/2 - bitmap->w/2;
pos.y = screen->h/2 - bitmap->h/2;
pos.x = GH.screenDimensions().x/2 - bitmap->w/2;
pos.y = GH.screenDimensions().y/2 - bitmap->h/2;
pos.h = bitmap->h;
pos.w = bitmap->w;
}
@ -281,8 +281,8 @@ void CInfoPopup::init(int x, int y)
// Put the window back on screen if necessary
vstd::amax(pos.x, 0);
vstd::amax(pos.y, 0);
vstd::amin(pos.x, screen->w - bitmap->w);
vstd::amin(pos.y, screen->h - bitmap->h);
vstd::amin(pos.x, GH.screenDimensions().x - bitmap->w);
vstd::amin(pos.y, GH.screenDimensions().y - bitmap->h);
}