improvments in widgets initialization
This commit is contained in:
parent
b736e52b29
commit
63cbe11f7e
|
@ -29,10 +29,9 @@
|
||||||
#include <framework/graphics/texture.h>
|
#include <framework/graphics/texture.h>
|
||||||
#include <framework/graphics/texturemanager.h>
|
#include <framework/graphics/texturemanager.h>
|
||||||
|
|
||||||
void UIButton::setup()
|
UIButton::UIButton()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
m_focusable = false;
|
||||||
setFocusable(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIButton::render()
|
void UIButton::render()
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
class UIButton : public UIWidget
|
class UIButton : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void setup();
|
UIButton();
|
||||||
|
|
||||||
virtual void render();
|
virtual void render();
|
||||||
|
|
||||||
void setText(const std::string& text) { m_text = text; }
|
void setText(const std::string& text) { m_text = text; }
|
||||||
|
|
|
@ -27,10 +27,9 @@
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
#include <framework/core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
void UICheckBox::setup()
|
UICheckBox::UICheckBox()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
m_focusable = false;
|
||||||
setFocusable(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UICheckBox::render()
|
void UICheckBox::render()
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
class UICheckBox : public UIWidget
|
class UICheckBox : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void setup();
|
UICheckBox();
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
bool isChecked();
|
bool isChecked();
|
||||||
|
|
|
@ -27,12 +27,11 @@
|
||||||
#include <framework/platform/platform.h>
|
#include <framework/platform/platform.h>
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
|
|
||||||
void UIFrameCounter::setup()
|
UIFrameCounter::UIFrameCounter()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
m_focusable = false;
|
||||||
setFocusable(false);
|
m_phantom = true;
|
||||||
setPhantom(true);
|
m_align = Fw::AlignLeft;
|
||||||
setAlign(Fw::AlignLeft);
|
|
||||||
m_lastFrameTicks = g_platform.getTicks();
|
m_lastFrameTicks = g_platform.getTicks();
|
||||||
m_frameCount = 0;
|
m_frameCount = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
class UIFrameCounter : public UIWidget
|
class UIFrameCounter : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void setup();
|
UIFrameCounter();
|
||||||
virtual void render();
|
virtual void render();
|
||||||
|
|
||||||
void setAlign(Fw::AlignmentFlag align) { m_align = align; }
|
void setAlign(Fw::AlignmentFlag align) { m_align = align; }
|
||||||
|
|
|
@ -25,12 +25,11 @@
|
||||||
#include <framework/graphics/font.h>
|
#include <framework/graphics/font.h>
|
||||||
#include <framework/otml/otmlnode.h>
|
#include <framework/otml/otmlnode.h>
|
||||||
|
|
||||||
void UILabel::setup()
|
UILabel::UILabel()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
m_focusable = false;
|
||||||
setFocusable(false);
|
m_phantom = true;
|
||||||
setPhantom(true);
|
m_align = Fw::AlignLeft;
|
||||||
setAlign(Fw::AlignLeft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UILabel::render()
|
void UILabel::render()
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
class UILabel : public UIWidget
|
class UILabel : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void setup();
|
UILabel();
|
||||||
virtual void render();
|
virtual void render();
|
||||||
|
|
||||||
void resizeToText();
|
void resizeToText();
|
||||||
|
|
|
@ -32,7 +32,6 @@ void UIManager::init()
|
||||||
{
|
{
|
||||||
// creates root widget
|
// creates root widget
|
||||||
m_rootWidget = UIWidget::create<UIWidget>();
|
m_rootWidget = UIWidget::create<UIWidget>();
|
||||||
m_rootWidget->setup();
|
|
||||||
m_rootWidget->setId("root");
|
m_rootWidget->setId("root");
|
||||||
m_rootWidget->resize(g_graphics.getScreenSize());
|
m_rootWidget->resize(g_graphics.getScreenSize());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,10 @@
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
#include <framework/otml/otmlnode.h>
|
#include <framework/otml/otmlnode.h>
|
||||||
|
|
||||||
void UIProgressBar::setup()
|
UIProgressBar::UIProgressBar()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
m_phantom = false;
|
||||||
setPhantom(true);
|
m_focusable = false;
|
||||||
setFocusable(false);
|
|
||||||
m_percent = 0;
|
m_percent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
class UIProgressBar : public UIWidget
|
class UIProgressBar : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void setup();
|
UIProgressBar();
|
||||||
virtual void render();
|
virtual void render();
|
||||||
|
|
||||||
void setPercent(double percent);
|
void setPercent(double percent);
|
||||||
|
|
|
@ -36,53 +36,27 @@
|
||||||
|
|
||||||
UIWidget::UIWidget()
|
UIWidget::UIWidget()
|
||||||
{
|
{
|
||||||
m_updateEventScheduled = false;
|
m_lastFocusReason = Fw::ActiveFocusReason;
|
||||||
m_firstOnStyle = true;
|
|
||||||
m_states = Fw::DefaultState;
|
m_states = Fw::DefaultState;
|
||||||
|
m_font = g_fonts.getDefaultFont();
|
||||||
|
m_opacity = 255;
|
||||||
|
m_marginTop = m_marginBottom = m_marginLeft = m_marginRight = 0;
|
||||||
|
|
||||||
// generate an unique id, this is need because anchored layouts find widgets by id
|
// generate an unique id, this is need because anchored layouts find widgets by id
|
||||||
static unsigned long id = 1;
|
static unsigned long id = 1;
|
||||||
m_id = Fw::mkstr("widget", id++);
|
m_id = Fw::mkstr("widget", id++);
|
||||||
}
|
}
|
||||||
|
|
||||||
UIWidget::~UIWidget()
|
|
||||||
{
|
|
||||||
// clear all references
|
|
||||||
releaseLuaFieldsTable();
|
|
||||||
m_focusedChild.reset();
|
|
||||||
m_layout.reset();
|
|
||||||
m_parent.reset();
|
|
||||||
m_lockedChildren.clear();
|
|
||||||
m_children.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void UIWidget::setup()
|
|
||||||
{
|
|
||||||
setVisible(true);
|
|
||||||
setEnabled(true);
|
|
||||||
setFocusable(true);
|
|
||||||
setPhantom(false);
|
|
||||||
setPressed(false);
|
|
||||||
setSizeFixed(false);
|
|
||||||
setFont(g_fonts.getDefaultFont());
|
|
||||||
setBackgroundColor(Fw::white);
|
|
||||||
setForegroundColor(Fw::white);
|
|
||||||
setOpacity(255);
|
|
||||||
setMarginTop(0);
|
|
||||||
setMarginRight(0);
|
|
||||||
setMarginBottom(0);
|
|
||||||
setMarginLeft(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UIWidget::destroy()
|
void UIWidget::destroy()
|
||||||
{
|
{
|
||||||
|
setVisible(false);
|
||||||
|
setEnabled(false);
|
||||||
|
|
||||||
// remove itself from parent
|
// remove itself from parent
|
||||||
if(UIWidgetPtr parent = getParent()) {
|
if(UIWidgetPtr parent = getParent()) {
|
||||||
if(parent->hasChild(asUIWidget()))
|
if(parent->hasChild(asUIWidget()))
|
||||||
parent->removeChild(asUIWidget());
|
parent->removeChild(asUIWidget());
|
||||||
}
|
}
|
||||||
//setVisible(false);
|
|
||||||
//setEnabled(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::render()
|
void UIWidget::render()
|
||||||
|
|
|
@ -31,14 +31,13 @@ class UIWidget : public LuaObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UIWidget();
|
UIWidget();
|
||||||
virtual ~UIWidget();
|
virtual ~UIWidget() { }
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
static std::shared_ptr<T> create() { auto t = std::shared_ptr<T>(new T); t->setup(); return t; }
|
static std::shared_ptr<T> create() { auto t = std::shared_ptr<T>(new T); return t; }
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
virtual void setup();
|
|
||||||
virtual void render();
|
virtual void render();
|
||||||
void renderSelf();
|
void renderSelf();
|
||||||
void renderChildren();
|
void renderChildren();
|
||||||
|
@ -184,14 +183,14 @@ protected:
|
||||||
protected:
|
protected:
|
||||||
std::string m_id;
|
std::string m_id;
|
||||||
Fw::FocusReason m_lastFocusReason;
|
Fw::FocusReason m_lastFocusReason;
|
||||||
bool m_enabled;
|
boolean<true> m_enabled;
|
||||||
bool m_visible;
|
boolean<true> m_visible;
|
||||||
bool m_focusable;
|
boolean<true> m_focusable;
|
||||||
bool m_fixedSize;
|
boolean<false> m_fixedSize;
|
||||||
bool m_pressed;
|
boolean<false> m_pressed;
|
||||||
bool m_phantom;
|
boolean<false> m_phantom;
|
||||||
bool m_updateEventScheduled;
|
boolean<false> m_updateEventScheduled;
|
||||||
bool m_firstOnStyle;
|
boolean<true> m_firstOnStyle;
|
||||||
Rect m_rect;
|
Rect m_rect;
|
||||||
UILayoutPtr m_layout;
|
UILayoutPtr m_layout;
|
||||||
UIWidgetWeakPtr m_parent;
|
UIWidgetWeakPtr m_parent;
|
||||||
|
@ -200,14 +199,12 @@ protected:
|
||||||
UIWidgetPtr m_focusedChild;
|
UIWidgetPtr m_focusedChild;
|
||||||
OTMLNodePtr m_style;
|
OTMLNodePtr m_style;
|
||||||
OTMLNodePtr m_stateStyle;
|
OTMLNodePtr m_stateStyle;
|
||||||
int m_states;
|
|
||||||
|
|
||||||
// basic style components used by all widgets
|
|
||||||
ImagePtr m_image;
|
ImagePtr m_image;
|
||||||
FontPtr m_font;
|
FontPtr m_font;
|
||||||
int m_opacity;
|
|
||||||
Color m_backgroundColor;
|
Color m_backgroundColor;
|
||||||
Color m_foregroundColor;
|
Color m_foregroundColor;
|
||||||
|
int m_states;
|
||||||
|
int m_opacity;
|
||||||
int m_marginLeft;
|
int m_marginLeft;
|
||||||
int m_marginRight;
|
int m_marginRight;
|
||||||
int m_marginTop;
|
int m_marginTop;
|
||||||
|
|
|
@ -27,14 +27,13 @@
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
#include <framework/otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
|
|
||||||
void UIWindow::setup()
|
UIWindow::UIWindow()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
|
||||||
m_moving = false;
|
m_moving = false;
|
||||||
m_movePolicy = DONT_MOVE;
|
m_movePolicy = DONT_MOVE;
|
||||||
|
m_titleAlign = Fw::AlignCenter;
|
||||||
m_headHeight = 0;
|
m_headHeight = 0;
|
||||||
m_oldIndex = -1;
|
m_oldIndex = -1;
|
||||||
m_titleAlign = Fw::AlignCenter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWindow::render()
|
void UIWindow::render()
|
||||||
|
|
|
@ -34,7 +34,7 @@ class UIWindow : public UIWidget
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void setup();
|
UIWindow();
|
||||||
virtual void render();
|
virtual void render();
|
||||||
|
|
||||||
void setTitle(const std::string& title) { m_title = title; }
|
void setTitle(const std::string& title) { m_title = title; }
|
||||||
|
@ -52,16 +52,12 @@ private:
|
||||||
std::string m_title;
|
std::string m_title;
|
||||||
bool m_moving;
|
bool m_moving;
|
||||||
MovePolicy m_movePolicy;
|
MovePolicy m_movePolicy;
|
||||||
|
Fw::AlignmentFlag m_titleAlign;
|
||||||
|
Point m_headOffset;
|
||||||
Point m_movingReference;
|
Point m_movingReference;
|
||||||
Point m_oldPos;
|
Point m_oldPos;
|
||||||
int m_oldIndex;
|
int m_oldIndex;
|
||||||
|
|
||||||
// styling
|
|
||||||
BorderImagePtr m_headImage;
|
|
||||||
ImagePtr m_bodyImage;
|
|
||||||
int m_headHeight;
|
int m_headHeight;
|
||||||
Point m_headOffset;
|
|
||||||
Fw::AlignmentFlag m_titleAlign;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
class Color
|
class Color
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Color() : m_rgba(0) { }
|
Color() : m_rgba(0xFFFFFFFF) { }
|
||||||
Color(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) : m_r(r), m_g(g), m_b(b), m_a(a) { }
|
Color(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) : m_r(r), m_g(g), m_b(b), m_a(a) { }
|
||||||
Color(const Color& other) : m_rgba(other.m_rgba) { }
|
Color(const Color& other) : m_rgba(other.m_rgba) { }
|
||||||
Color(uint32 rgba) : m_rgba(rgba) { }
|
Color(uint32 rgba) : m_rgba(rgba) { }
|
||||||
|
|
|
@ -42,8 +42,15 @@ typedef int8_t int8;
|
||||||
typedef std::function<void()> SimpleCallback;
|
typedef std::function<void()> SimpleCallback;
|
||||||
typedef std::function<bool()> BooleanCallback;
|
typedef std::function<bool()> BooleanCallback;
|
||||||
|
|
||||||
#ifndef nullptr
|
// boolean with default value initializer
|
||||||
#define nullptr NULL
|
template<bool def>
|
||||||
#endif
|
struct boolean {
|
||||||
|
boolean() : v(def) { }
|
||||||
|
operator bool &() { return v; }
|
||||||
|
operator bool const &() const { return v; }
|
||||||
|
bool& operator=(const bool& o) { v = o; return v; }
|
||||||
|
private:
|
||||||
|
bool v;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,9 +24,9 @@
|
||||||
#include <framework/otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
|
|
||||||
void UICreature::setup()
|
UICreature::UICreature()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
m_creatureMargin = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UICreature::render()
|
void UICreature::render()
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
class UICreature : public UIWidget
|
class UICreature : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void setup();
|
UICreature();
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
||||||
|
|
|
@ -24,9 +24,9 @@
|
||||||
#include <framework/otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
|
|
||||||
void UIItem::setup()
|
UIItem::UIItem()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
m_itemMargin = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIItem::render()
|
void UIItem::render()
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
class UIItem : public UIWidget
|
class UIItem : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void setup();
|
UIItem();
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
void setItem(const ItemPtr& item) { m_item = item; }
|
void setItem(const ItemPtr& item) { m_item = item; }
|
||||||
|
|
|
@ -29,9 +29,9 @@
|
||||||
#include <otclient/core/localplayer.h>
|
#include <otclient/core/localplayer.h>
|
||||||
#include <otclient/core/tile.h>
|
#include <otclient/core/tile.h>
|
||||||
|
|
||||||
void UIMap::setup()
|
UIMap::UIMap()
|
||||||
{
|
{
|
||||||
UIWidget::setup();
|
m_mapMargin = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIMap::render()
|
void UIMap::render()
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
class UIMap : public UIWidget
|
class UIMap : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void setup();
|
UIMap();
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in New Issue