mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
performance improvments
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
#include "uielement.h"
|
||||
#include "uiskins.h"
|
||||
#include "uielementskin.h"
|
||||
#include <graphics/graphics.h>
|
||||
#include "graphics/graphics.h"
|
||||
|
||||
UIElement::UIElement(UI::EElementType type) :
|
||||
UILayout(),
|
||||
@@ -35,9 +35,7 @@ UIElement::UIElement(UI::EElementType type) :
|
||||
m_enabled(true),
|
||||
m_focused(false)
|
||||
{
|
||||
// set default skin
|
||||
if(type > UI::Container)
|
||||
setSkin(g_uiSkins.getElementSkin(type));
|
||||
|
||||
}
|
||||
|
||||
bool UIElement::setSkin(const std::string& skinName)
|
||||
@@ -48,10 +46,11 @@ bool UIElement::setSkin(const std::string& skinName)
|
||||
|
||||
void UIElement::setSkin(UIElementSkin* skin)
|
||||
{
|
||||
m_skin = skin;
|
||||
if(skin && !getRect().isValid()) {
|
||||
setSize(skin->getDefaultSize());
|
||||
skin->onSkinApply(this);
|
||||
}
|
||||
m_skin = skin;
|
||||
}
|
||||
|
||||
void UIElement::render()
|
||||
|
@@ -40,6 +40,7 @@ public:
|
||||
virtual ~UIElementSkin() { }
|
||||
|
||||
virtual void load(const YAML::Node& node);
|
||||
virtual void onSkinApply(UIElement *element) { }
|
||||
virtual void draw(UIElement *element);
|
||||
|
||||
const std::string& getName() const { return m_name; }
|
||||
|
@@ -28,8 +28,6 @@
|
||||
#include "prerequisites.h"
|
||||
#include "uielement.h"
|
||||
|
||||
class Font;
|
||||
|
||||
class UILabel : public UIElement
|
||||
{
|
||||
public:
|
||||
|
@@ -50,9 +50,13 @@ UIElementPtr UILoader::createElementFromId(const std::string& id)
|
||||
element = UIElementPtr(new UITextEdit);
|
||||
}
|
||||
|
||||
if(element)
|
||||
if(element) {
|
||||
element->setId(elementId);
|
||||
|
||||
// apply default skin
|
||||
element->setSkin(g_uiSkins.getElementSkin(element->getElementType()));
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
|
@@ -29,8 +29,6 @@
|
||||
UITextEdit::UITextEdit() :
|
||||
UIElement(UI::TextEdit)
|
||||
{
|
||||
UITextEditSkin *skin = static_cast<UITextEditSkin*>(getSkin());
|
||||
m_textArea.setFont(skin->getFont());
|
||||
m_textArea.enableCursor();
|
||||
}
|
||||
|
||||
@@ -48,7 +46,7 @@ void UITextEdit::onInputEvent(const InputEvent& event)
|
||||
else if(event.keycode == KC_LEFT)
|
||||
m_textArea.moveCursor(false);
|
||||
} else if(event.type == EV_MOUSE_LDOWN) {
|
||||
|
||||
|
||||
} else if(event.type == EV_MOUSE_LUP && getRect().contains(event.mousePos)) {
|
||||
m_textArea.setCursorPos(m_textArea.getTextPos(event.mousePos));
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@ public:
|
||||
|
||||
void setText(const std::string& text);
|
||||
const std::string& getText() const { return m_textArea.getText(); }
|
||||
|
||||
TextArea& getTextArea() { return m_textArea; }
|
||||
|
||||
void onLayoutRectChange(const Rect& rect);
|
||||
|
@@ -46,6 +46,12 @@ void UITextEditSkin::load(const YAML::Node& node)
|
||||
m_textMargin = 2;
|
||||
}
|
||||
|
||||
void UITextEditSkin::onSkinApply(UIElement* element)
|
||||
{
|
||||
UITextEdit *textEdit = static_cast<UITextEdit*>(element);
|
||||
textEdit->getTextArea().setFont(m_font);
|
||||
}
|
||||
|
||||
void UITextEditSkin::draw(UIElement* element)
|
||||
{
|
||||
UIElementSkin::draw(element);
|
||||
|
@@ -38,6 +38,7 @@ public:
|
||||
UIElementSkin(name, UI::TextEdit) { }
|
||||
|
||||
void load(const YAML::Node& node);
|
||||
void onSkinApply(UIElement *element);
|
||||
void draw(UIElement *element);
|
||||
|
||||
Font *getFont() const { return m_font; }
|
||||
|
Reference in New Issue
Block a user