fix leaks
This commit is contained in:
parent
9d1ddf34bf
commit
5de660a20e
|
@ -29,6 +29,7 @@
|
||||||
UIElement::UIElement(UI::EElementType type) :
|
UIElement::UIElement(UI::EElementType type) :
|
||||||
AnchorLayout(),
|
AnchorLayout(),
|
||||||
m_type(type),
|
m_type(type),
|
||||||
|
m_skin(NULL),
|
||||||
m_visible(true),
|
m_visible(true),
|
||||||
m_enabled(true)
|
m_enabled(true)
|
||||||
{
|
{
|
||||||
|
|
|
@ -76,15 +76,15 @@ ImagePtr UIElementSkin::loadImage(const YAML::Node& node)
|
||||||
}
|
}
|
||||||
|
|
||||||
image = ImagePtr(new BorderedImage(texture,
|
image = ImagePtr(new BorderedImage(texture,
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
top,
|
top,
|
||||||
bottom,
|
bottom,
|
||||||
topLeft,
|
topLeft,
|
||||||
topRight,
|
topRight,
|
||||||
bottomLeft,
|
bottomLeft,
|
||||||
bottomRight,
|
bottomRight,
|
||||||
center));
|
center));
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
UIElementSkin(const std::string& name, UI::EElementType elementType) :
|
UIElementSkin(const std::string& name, UI::EElementType elementType) :
|
||||||
m_name(name),
|
m_name(name),
|
||||||
m_elementType(elementType) { }
|
m_elementType(elementType) { }
|
||||||
|
virtual ~UIElementSkin() { }
|
||||||
|
|
||||||
virtual void load(const YAML::Node& node);
|
virtual void load(const YAML::Node& node);
|
||||||
virtual void draw(UIElement *element);
|
virtual void draw(UIElement *element);
|
||||||
|
|
|
@ -32,10 +32,18 @@
|
||||||
|
|
||||||
UISkins g_uiSkins;
|
UISkins g_uiSkins;
|
||||||
|
|
||||||
UISkins::~UISkins()
|
void UISkins::init()
|
||||||
|
{
|
||||||
|
// load default skin
|
||||||
|
g_uiSkins.load("skins/tibiaskin.yml");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UISkins::terminate()
|
||||||
{
|
{
|
||||||
for(auto it = m_elementSkins.begin(); it != m_elementSkins.end(); ++it)
|
for(auto it = m_elementSkins.begin(); it != m_elementSkins.end(); ++it)
|
||||||
delete (*it);
|
delete (*it);
|
||||||
|
m_elementSkins.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UISkins::load(const std::string& file)
|
bool UISkins::load(const std::string& file)
|
||||||
|
|
|
@ -35,7 +35,9 @@ class UISkins
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UISkins() { }
|
UISkins() { }
|
||||||
~UISkins();
|
|
||||||
|
void init();
|
||||||
|
void terminate();
|
||||||
|
|
||||||
bool load(const std::string& file);
|
bool load(const std::string& file);
|
||||||
|
|
||||||
|
|
|
@ -109,8 +109,7 @@ int main(int argc, const char *argv[])
|
||||||
// init engine
|
// init engine
|
||||||
g_engine.init();
|
g_engine.init();
|
||||||
|
|
||||||
// load UI skin
|
g_uiSkins.init();
|
||||||
g_uiSkins.load("skins/tibiaskin.yml");
|
|
||||||
|
|
||||||
// state scope
|
// state scope
|
||||||
{
|
{
|
||||||
|
@ -129,6 +128,8 @@ int main(int argc, const char *argv[])
|
||||||
|
|
||||||
// terminate stuff
|
// terminate stuff
|
||||||
g_engine.terminate();
|
g_engine.terminate();
|
||||||
|
|
||||||
|
g_uiSkins.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// save configurations before exiting
|
// save configurations before exiting
|
||||||
|
|
|
@ -127,6 +127,7 @@ void MenuState::createMainMenu()
|
||||||
|
|
||||||
// login window
|
// login window
|
||||||
UIWindowPtr window(new UIWindow("Enter Game"));
|
UIWindowPtr window(new UIWindow("Enter Game"));
|
||||||
|
UIElementWeakPtr weakWindow(window);
|
||||||
window->setSize(Size(236, 178));
|
window->setSize(Size(236, 178));
|
||||||
window->anchorHorizontalCenter(g_ui->horizontalCenter());
|
window->anchorHorizontalCenter(g_ui->horizontalCenter());
|
||||||
window->anchorVerticalCenter(g_ui->verticalCenter());
|
window->anchorVerticalCenter(g_ui->verticalCenter());
|
||||||
|
@ -162,7 +163,11 @@ void MenuState::createMainMenu()
|
||||||
button->anchorRight(window->right());
|
button->anchorRight(window->right());
|
||||||
button->anchorBottom(window->bottom());
|
button->anchorBottom(window->bottom());
|
||||||
button->setMargin(0, 0, 10, 66);
|
button->setMargin(0, 0, 10, 66);
|
||||||
button->onClick([window]{ window->setVisible(false); });
|
button->onClick([weakWindow]{
|
||||||
|
UIElementPtr window = weakWindow.lock();
|
||||||
|
if(window)
|
||||||
|
window->setVisible(false);
|
||||||
|
});
|
||||||
window->addChild(button);
|
window->addChild(button);
|
||||||
|
|
||||||
button = UIButtonPtr(new UIButton("Cancel"));
|
button = UIButtonPtr(new UIButton("Cancel"));
|
||||||
|
@ -170,7 +175,11 @@ void MenuState::createMainMenu()
|
||||||
button->anchorRight(window->right());
|
button->anchorRight(window->right());
|
||||||
button->anchorBottom(window->bottom());
|
button->anchorBottom(window->bottom());
|
||||||
button->setMargin(0, 0, 10, 13);
|
button->setMargin(0, 0, 10, 13);
|
||||||
button->onClick([window]{ window->setVisible(false); });
|
button->onClick([weakWindow]{
|
||||||
|
UIElementPtr window = weakWindow.lock();
|
||||||
|
if(window)
|
||||||
|
window->setVisible(false);
|
||||||
|
});
|
||||||
window->addChild(button);
|
window->addChild(button);
|
||||||
|
|
||||||
UITextEditPtr textEdit(new UITextEdit);
|
UITextEditPtr textEdit(new UITextEdit);
|
||||||
|
@ -185,5 +194,9 @@ void MenuState::createMainMenu()
|
||||||
textEdit->setMargin(61, 0, 0, 18);
|
textEdit->setMargin(61, 0, 0, 18);
|
||||||
window->addChild(textEdit);
|
window->addChild(textEdit);
|
||||||
|
|
||||||
enterGameButton->onClick([window] { window->setVisible(true); });
|
enterGameButton->onClick([weakWindow]{
|
||||||
|
UIElementPtr window = weakWindow.lock();
|
||||||
|
if(window)
|
||||||
|
window->setVisible(true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue