1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

Removed direct usage of SDL_Surface in info windows

This commit is contained in:
Ivan Savenko
2024-02-26 15:48:55 +02:00
parent 5419df1140
commit 658cc14cd0
3 changed files with 46 additions and 61 deletions

View File

@@ -16,6 +16,7 @@
#include "../../lib/TextOperations.h"
#include "../windows/InfoWindows.h"
#include "../widgets/Images.h"
#include "../widgets/Buttons.h"
#include "../widgets/CComponent.h"
#include "../widgets/Slider.h"
@@ -266,17 +267,22 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
blitOr = true;
const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}};
constexpr std::array sizes = {
Point(400, 125),
Point(500, 150),
Point(600, 200),
Point(480, 400)
};
assert(ret && ret->text);
for(int i = 0;
i < std::size(sizes)
&& sizes[i][0] < GH.screenDimensions().x - 150
&& sizes[i][1] < GH.screenDimensions().y - 150
&& sizes[i].x < GH.screenDimensions().x - 150
&& sizes[i].y < GH.screenDimensions().y - 150
&& ret->text->slider;
i++)
{
ret->text->resize(Point(sizes[i][0], sizes[i][1]));
ret->text->resize(sizes[i]);
}
if(ret->text->slider)
@@ -316,34 +322,35 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor play
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;
ret->pos.w=ret->bitmap->w;
ret->pos.h = winSize.second + 2 * SIDE_MARGIN;
ret->pos.w = winSize.first + 2 * SIDE_MARGIN;
ret->center();
ret->backgroundTexture->pos = ret->pos;
int curh = SIDE_MARGIN;
int xOffset = (ret->pos.w - ret->text->pos.w)/2;
if(!ret->buttons.size() && !ret->components.size()) //improvement for very small text only popups -> center text vertically
{
if(ret->bitmap->h > ret->text->pos.h + 2*SIDE_MARGIN)
curh = (ret->bitmap->h - ret->text->pos.h)/2;
if(ret->pos.h > ret->text->pos.h + 2*SIDE_MARGIN)
curh = (ret->pos.h - ret->text->pos.h)/2;
}
ret->text->moveBy(Point(xOffset, curh));
curh += ret->text->pos.h;
if (ret->components.size())
{
curh += BEFORE_COMPONENTS;
comps.blitCompsOnSur (blitOr, BETWEEN_COMPS, curh, ret->bitmap);
}
//if (ret->components.size())
//{
// curh += BEFORE_COMPONENTS;
// comps.blitCompsOnSur (blitOr, BETWEEN_COMPS, curh, ret->bitmap);
//}
if(ret->buttons.size())
{
// Position the buttons at the bottom of the window
bw = (ret->bitmap->w/2) - (bw/2);
curh = ret->bitmap->h - SIDE_MARGIN - ret->buttons[0]->pos.h;
bw = (ret->pos.w/2) - (bw/2);
curh = ret->pos.h - SIDE_MARGIN - ret->buttons[0]->pos.h;
for(auto & elem : ret->buttons)
{

View File

@@ -15,20 +15,21 @@
#include "../CPlayerInterface.h"
#include "../CMusicHandler.h"
#include "../widgets/CComponent.h"
#include "../widgets/MiscWidgets.h"
#include "../widgets/Buttons.h"
#include "../widgets/TextControls.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../adventureMap/AdventureMapInterface.h"
#include "../battle/BattleInterface.h"
#include "../battle/BattleInterfaceClasses.h"
#include "../adventureMap/AdventureMapInterface.h"
#include "../windows/CMessage.h"
#include "../render/Canvas.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../gui/CGuiHandler.h"
#include "../gui/CursorHandler.h"
#include "../gui/Shortcut.h"
#include "../gui/WindowHandler.h"
#include "../render/Canvas.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../widgets/Buttons.h"
#include "../widgets/CComponent.h"
#include "../widgets/Images.h"
#include "../widgets/MiscWidgets.h"
#include "../widgets/TextControls.h"
#include "../windows/CMessage.h"
#include "../../CCallback.h"
@@ -43,20 +44,6 @@
#include <SDL_surface.h>
void CSimpleWindow::show(Canvas & to)
{
if(bitmap)
CSDL_Ext::blitAt(bitmap, pos.x, pos.y, to.getInternalSurface());
}
CSimpleWindow::~CSimpleWindow()
{
if (bitmap)
{
SDL_FreeSurface(bitmap);
bitmap=nullptr;
}
}
void CSelWindow::selectionChange(unsigned to)
{
for (unsigned i=0;i<components.size();i++)
@@ -72,6 +59,9 @@ void CSelWindow::selectionChange(unsigned to)
CSelWindow::CSelWindow(const std::string &Text, PlayerColor player, int charperline, const std::vector<std::shared_ptr<CSelectableComponent>> & comps, const std::vector<std::pair<AnimationPath, CFunctionList<void()> > > &Buttons, QueryID askID)
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
ID = askID;
for (int i = 0; i < Buttons.size(); i++)
{
@@ -138,6 +128,8 @@ CInfoWindow::CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo
{
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
ID = QueryID(-1);
for(auto & Button : Buttons)
{
@@ -188,19 +180,14 @@ void CInfoWindow::close()
LOCPLINT->showingDialog->setn(false);
}
void CInfoWindow::show(Canvas & to)
void CInfoWindow::showAll(Canvas & to)
{
CIntObject::show(to);
CIntObject::showAll(to);
CMessage::drawBorder(LOCPLINT ? LOCPLINT->playerID : PlayerColor(1), to.getInternalSurface(), pos.w, pos.h, pos.x, pos.y);
}
CInfoWindow::~CInfoWindow() = default;
void CInfoWindow::showAll(Canvas & to)
{
CSimpleWindow::show(to);
CIntObject::showAll(to);
}
void CInfoWindow::showInfoDialog(const std::string &text, const TCompsInfo & components, PlayerColor player)
{
GH.windows().pushWindow(CInfoWindow::create(text, player, components));

View File

@@ -34,32 +34,23 @@ class CTextBox;
class CButton;
class CSlider;
class CArmyTooltip;
// Window GUI class
class CSimpleWindow : public WindowBase
{
public:
SDL_Surface * bitmap; //background
void show(Canvas & to) override;
CSimpleWindow():bitmap(nullptr){};
virtual ~CSimpleWindow();
};
class CFilledTexture;
/// text + comp. + ok button
class CInfoWindow : public CSimpleWindow
class CInfoWindow : public WindowBase
{
public:
using TButtonsInfo = std::vector<std::pair<AnimationPath, CFunctionList<void()>>>;
using TCompsInfo = std::vector<std::shared_ptr<CComponent>>;
QueryID ID; //for identification
std::shared_ptr<CFilledTexture> backgroundTexture;
std::shared_ptr<CTextBox> text;
std::vector<std::shared_ptr<CButton>> buttons;
TCompsInfo components;
void close() override;
void show(Canvas & to) override;
void showAll(Canvas & to) override;
void sliderMoved(int to);
CInfoWindow(std::string Text, PlayerColor player, const TCompsInfo & comps = TCompsInfo(), const TButtonsInfo & Buttons = TButtonsInfo());