mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Gui cleanup3 - UI refactoring to use smart pointers (#440)
* Changed most gui classes to use shared pointers * Store and use IImage as shared_ptr * CSpellWindow redesign * AdventureMapClasses cleanup * CLabel: store background as smart pointer * Store CObjectList items as smart pointers * Removed destroy function of list item * Store toggle buttons as smart pointers * Use CComponent as smart pointer * Attempt to fix artifact merchant drawing
This commit is contained in:
committed by
ArseniyShestakov
parent
db60983b5a
commit
5c09f751b3
@@ -34,13 +34,15 @@
|
||||
#include "../../lib/CGeneralTextHandler.h" //for Unicode related stuff
|
||||
|
||||
CWindowObject::CWindowObject(int options_, std::string imageName, Point centerAt):
|
||||
CIntObject(getUsedEvents(options_), Point()),
|
||||
shadow(nullptr),
|
||||
options(options_),
|
||||
background(createBg(imageName, options & PLAYER_COLORED))
|
||||
CIntObject(getUsedEvents(options_), Point()),
|
||||
shadow(nullptr),
|
||||
options(options_),
|
||||
background(createBg(imageName, options & PLAYER_COLORED))
|
||||
{
|
||||
assert(parent == nullptr); //Safe to remove, but windows should not have parent
|
||||
|
||||
defActions = 255-DISPOSE;
|
||||
|
||||
if (options & RCLICK_POPUP)
|
||||
CCS->curh->hide();
|
||||
|
||||
@@ -54,51 +56,48 @@ CWindowObject::CWindowObject(int options_, std::string imageName, Point centerAt
|
||||
}
|
||||
|
||||
CWindowObject::CWindowObject(int options_, std::string imageName):
|
||||
CIntObject(getUsedEvents(options_), Point()),
|
||||
shadow(nullptr),
|
||||
options(options_),
|
||||
background(createBg(imageName, options & PLAYER_COLORED))
|
||||
CIntObject(getUsedEvents(options_), Point()),
|
||||
options(options_),
|
||||
background(createBg(imageName, options_ & PLAYER_COLORED))
|
||||
{
|
||||
assert(parent == nullptr); //Safe to remove, but windows should not have parent
|
||||
|
||||
if (options & RCLICK_POPUP)
|
||||
defActions = 255-DISPOSE;
|
||||
|
||||
if(options & RCLICK_POPUP)
|
||||
CCS->curh->hide();
|
||||
|
||||
if (background)
|
||||
if(background)
|
||||
pos = background->center();
|
||||
else
|
||||
center(Point(screen->w/2, screen->h/2));
|
||||
|
||||
if (!(options & SHADOW_DISABLED))
|
||||
if(!(options & SHADOW_DISABLED))
|
||||
setShadow(true);
|
||||
}
|
||||
|
||||
CWindowObject::~CWindowObject()
|
||||
{
|
||||
setShadow(false);
|
||||
}
|
||||
CWindowObject::~CWindowObject() = default;
|
||||
|
||||
CPicture * CWindowObject::createBg(std::string imageName, bool playerColored)
|
||||
std::shared_ptr<CPicture> CWindowObject::createBg(std::string imageName, bool playerColored)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
|
||||
if (imageName.empty())
|
||||
if(imageName.empty())
|
||||
return nullptr;
|
||||
|
||||
auto image = new CPicture(imageName);
|
||||
if (playerColored)
|
||||
auto image = std::make_shared<CPicture>(imageName);
|
||||
if(playerColored)
|
||||
image->colorize(LOCPLINT->playerID);
|
||||
return image;
|
||||
}
|
||||
|
||||
void CWindowObject::setBackground(std::string filename)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
|
||||
delete background;
|
||||
background = createBg(filename, options & PLAYER_COLORED);
|
||||
|
||||
if (background)
|
||||
if(background)
|
||||
pos = background->center(Point(pos.w/2 + pos.x, pos.h/2 + pos.y));
|
||||
|
||||
updateShadow();
|
||||
@@ -123,16 +122,16 @@ void CWindowObject::setShadow(bool on)
|
||||
//size of shadow
|
||||
static const int size = 8;
|
||||
|
||||
if (on == bool(shadow))
|
||||
if(on == bool(shadow))
|
||||
return;
|
||||
|
||||
vstd::clear_pointer(shadow);
|
||||
shadow.reset();
|
||||
|
||||
//object too small to cast shadow
|
||||
if (pos.h <= size || pos.w <= size)
|
||||
if(pos.h <= size || pos.w <= size)
|
||||
return;
|
||||
|
||||
if (on)
|
||||
if(on)
|
||||
{
|
||||
|
||||
//helper to set last row
|
||||
@@ -164,7 +163,7 @@ void CWindowObject::setShadow(bool on)
|
||||
static SDL_Surface * shadowRightTempl = nullptr;
|
||||
|
||||
//one-time initialization
|
||||
if (!shadowCornerTempl)
|
||||
if(!shadowCornerTempl)
|
||||
{
|
||||
//create "template" surfaces
|
||||
shadowCornerTempl = CSDL_Ext::createSurfaceWithBpp<4>(size, size);
|
||||
@@ -185,8 +184,6 @@ void CWindowObject::setShadow(bool on)
|
||||
blitAlphaRow(shadowCornerTempl, size-1);
|
||||
}
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
|
||||
//FIXME: do something with this points
|
||||
Point shadowStart;
|
||||
if (options & BORDERED)
|
||||
@@ -215,10 +212,18 @@ void CWindowObject::setShadow(bool on)
|
||||
blitAlphaRow(shadowRight, 0);
|
||||
|
||||
//generate "shadow" object with these 3 pieces in it
|
||||
shadow = new CIntObject();
|
||||
shadow->addChild(new CPicture(shadowCorner, shadowPos.x, shadowPos.y));
|
||||
shadow->addChild(new CPicture(shadowRight, shadowPos.x, shadowStart.y));
|
||||
shadow->addChild(new CPicture(shadowBottom, shadowStart.x, shadowPos.y));
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
||||
shadow = std::make_shared<CIntObject>();
|
||||
}
|
||||
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255);
|
||||
|
||||
shadow->addChild(new CPicture(shadowCorner, shadowPos.x, shadowPos.y));
|
||||
shadow->addChild(new CPicture(shadowRight, shadowPos.x, shadowStart.y));
|
||||
shadow->addChild(new CPicture(shadowBottom, shadowStart.x, shadowPos.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user