Browse Source

Removed direct usage of SDL_Surface in info windows

Ivan Savenko 1 year ago
parent
commit
658cc14cd0
3 changed files with 46 additions and 61 deletions
  1. 23 16
      client/windows/CMessage.cpp
  2. 19 32
      client/windows/InfoWindows.cpp
  3. 4 13
      client/windows/InfoWindows.h

+ 23 - 16
client/windows/CMessage.cpp

@@ -16,6 +16,7 @@
 #include "../../lib/TextOperations.h"
 #include "../../lib/TextOperations.h"
 
 
 #include "../windows/InfoWindows.h"
 #include "../windows/InfoWindows.h"
+#include "../widgets/Images.h"
 #include "../widgets/Buttons.h"
 #include "../widgets/Buttons.h"
 #include "../widgets/CComponent.h"
 #include "../widgets/CComponent.h"
 #include "../widgets/Slider.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
 	if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components
 		blitOr = true;
 		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);
 	assert(ret && ret->text);
 	for(int i = 0;
 	for(int i = 0;
 		i < std::size(sizes)
 		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;
 			&& ret->text->slider;
 		i++)
 		i++)
 	{
 	{
-		ret->text->resize(Point(sizes[i][0], sizes[i][1]));
+		ret->text->resize(sizes[i]);
 	}
 	}
 
 
 	if(ret->text->slider)
 	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);
 	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->center();
+	ret->backgroundTexture->pos = ret->pos;
 
 
 	int curh = SIDE_MARGIN;
 	int curh = SIDE_MARGIN;
 	int xOffset = (ret->pos.w - ret->text->pos.w)/2;
 	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->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));
 	ret->text->moveBy(Point(xOffset, curh));
 
 
 	curh += ret->text->pos.h;
 	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())
 	if(ret->buttons.size())
 	{
 	{
 		// Position the buttons at the bottom of the window
 		// 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)
 		for(auto & elem : ret->buttons)
 		{
 		{

+ 19 - 32
client/windows/InfoWindows.cpp

@@ -15,20 +15,21 @@
 #include "../CPlayerInterface.h"
 #include "../CPlayerInterface.h"
 #include "../CMusicHandler.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/BattleInterface.h"
 #include "../battle/BattleInterfaceClasses.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/CursorHandler.h"
 #include "../gui/Shortcut.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"
 #include "../../CCallback.h"
 
 
@@ -43,20 +44,6 @@
 
 
 #include <SDL_surface.h>
 #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)
 void CSelWindow::selectionChange(unsigned to)
 {
 {
 	for (unsigned i=0;i<components.size();i++)
 	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)
 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);
 	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
+
+	backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
+
 	ID = askID;
 	ID = askID;
 	for (int i = 0; i < Buttons.size(); i++)
 	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);
 	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
 
 
+	backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DiBoxBck"), pos);
+
 	ID = QueryID(-1);
 	ID = QueryID(-1);
 	for(auto & Button : Buttons)
 	for(auto & Button : Buttons)
 	{
 	{
@@ -188,19 +180,14 @@ void CInfoWindow::close()
 		LOCPLINT->showingDialog->setn(false);
 		LOCPLINT->showingDialog->setn(false);
 }
 }
 
 
-void CInfoWindow::show(Canvas & to)
-{
-	CIntObject::show(to);
-}
-
-CInfoWindow::~CInfoWindow() = default;
-
 void CInfoWindow::showAll(Canvas & to)
 void CInfoWindow::showAll(Canvas & to)
 {
 {
-	CSimpleWindow::show(to);
 	CIntObject::showAll(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::showInfoDialog(const std::string &text, const TCompsInfo & components, PlayerColor player)
 void CInfoWindow::showInfoDialog(const std::string &text, const TCompsInfo & components, PlayerColor player)
 {
 {
 	GH.windows().pushWindow(CInfoWindow::create(text, player, components));
 	GH.windows().pushWindow(CInfoWindow::create(text, player, components));

+ 4 - 13
client/windows/InfoWindows.h

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