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/texturemanager.h>
|
||||
|
||||
void UIButton::setup()
|
||||
UIButton::UIButton()
|
||||
{
|
||||
UIWidget::setup();
|
||||
setFocusable(false);
|
||||
m_focusable = false;
|
||||
}
|
||||
|
||||
void UIButton::render()
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
class UIButton : public UIWidget
|
||||
{
|
||||
public:
|
||||
virtual void setup();
|
||||
UIButton();
|
||||
|
||||
virtual void render();
|
||||
|
||||
void setText(const std::string& text) { m_text = text; }
|
||||
|
|
|
@ -27,10 +27,9 @@
|
|||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
|
||||
void UICheckBox::setup()
|
||||
UICheckBox::UICheckBox()
|
||||
{
|
||||
UIWidget::setup();
|
||||
setFocusable(false);
|
||||
m_focusable = false;
|
||||
}
|
||||
|
||||
void UICheckBox::render()
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
class UICheckBox : public UIWidget
|
||||
{
|
||||
public:
|
||||
void setup();
|
||||
UICheckBox();
|
||||
void render();
|
||||
|
||||
bool isChecked();
|
||||
|
|
|
@ -27,12 +27,11 @@
|
|||
#include <framework/platform/platform.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
|
||||
void UIFrameCounter::setup()
|
||||
UIFrameCounter::UIFrameCounter()
|
||||
{
|
||||
UIWidget::setup();
|
||||
setFocusable(false);
|
||||
setPhantom(true);
|
||||
setAlign(Fw::AlignLeft);
|
||||
m_focusable = false;
|
||||
m_phantom = true;
|
||||
m_align = Fw::AlignLeft;
|
||||
m_lastFrameTicks = g_platform.getTicks();
|
||||
m_frameCount = 0;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
class UIFrameCounter : public UIWidget
|
||||
{
|
||||
public:
|
||||
virtual void setup();
|
||||
UIFrameCounter();
|
||||
virtual void render();
|
||||
|
||||
void setAlign(Fw::AlignmentFlag align) { m_align = align; }
|
||||
|
|
|
@ -25,12 +25,11 @@
|
|||
#include <framework/graphics/font.h>
|
||||
#include <framework/otml/otmlnode.h>
|
||||
|
||||
void UILabel::setup()
|
||||
UILabel::UILabel()
|
||||
{
|
||||
UIWidget::setup();
|
||||
setFocusable(false);
|
||||
setPhantom(true);
|
||||
setAlign(Fw::AlignLeft);
|
||||
m_focusable = false;
|
||||
m_phantom = true;
|
||||
m_align = Fw::AlignLeft;
|
||||
}
|
||||
|
||||
void UILabel::render()
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
class UILabel : public UIWidget
|
||||
{
|
||||
public:
|
||||
virtual void setup();
|
||||
UILabel();
|
||||
virtual void render();
|
||||
|
||||
void resizeToText();
|
||||
|
|
|
@ -32,7 +32,6 @@ void UIManager::init()
|
|||
{
|
||||
// creates root widget
|
||||
m_rootWidget = UIWidget::create<UIWidget>();
|
||||
m_rootWidget->setup();
|
||||
m_rootWidget->setId("root");
|
||||
m_rootWidget->resize(g_graphics.getScreenSize());
|
||||
}
|
||||
|
|
|
@ -24,11 +24,10 @@
|
|||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/otml/otmlnode.h>
|
||||
|
||||
void UIProgressBar::setup()
|
||||
UIProgressBar::UIProgressBar()
|
||||
{
|
||||
UIWidget::setup();
|
||||
setPhantom(true);
|
||||
setFocusable(false);
|
||||
m_phantom = false;
|
||||
m_focusable = false;
|
||||
m_percent = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
class UIProgressBar : public UIWidget
|
||||
{
|
||||
public:
|
||||
virtual void setup();
|
||||
UIProgressBar();
|
||||
virtual void render();
|
||||
|
||||
void setPercent(double percent);
|
||||
|
|
|
@ -36,53 +36,27 @@
|
|||
|
||||
UIWidget::UIWidget()
|
||||
{
|
||||
m_updateEventScheduled = false;
|
||||
m_firstOnStyle = true;
|
||||
m_lastFocusReason = Fw::ActiveFocusReason;
|
||||
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
|
||||
static unsigned long id = 1;
|
||||
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()
|
||||
{
|
||||
setVisible(false);
|
||||
setEnabled(false);
|
||||
|
||||
// remove itself from parent
|
||||
if(UIWidgetPtr parent = getParent()) {
|
||||
if(parent->hasChild(asUIWidget()))
|
||||
parent->removeChild(asUIWidget());
|
||||
}
|
||||
//setVisible(false);
|
||||
//setEnabled(false);
|
||||
}
|
||||
|
||||
void UIWidget::render()
|
||||
|
|
|
@ -31,14 +31,13 @@ class UIWidget : public LuaObject
|
|||
{
|
||||
public:
|
||||
UIWidget();
|
||||
virtual ~UIWidget();
|
||||
virtual ~UIWidget() { }
|
||||
|
||||
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();
|
||||
|
||||
virtual void setup();
|
||||
virtual void render();
|
||||
void renderSelf();
|
||||
void renderChildren();
|
||||
|
@ -184,14 +183,14 @@ protected:
|
|||
protected:
|
||||
std::string m_id;
|
||||
Fw::FocusReason m_lastFocusReason;
|
||||
bool m_enabled;
|
||||
bool m_visible;
|
||||
bool m_focusable;
|
||||
bool m_fixedSize;
|
||||
bool m_pressed;
|
||||
bool m_phantom;
|
||||
bool m_updateEventScheduled;
|
||||
bool m_firstOnStyle;
|
||||
boolean<true> m_enabled;
|
||||
boolean<true> m_visible;
|
||||
boolean<true> m_focusable;
|
||||
boolean<false> m_fixedSize;
|
||||
boolean<false> m_pressed;
|
||||
boolean<false> m_phantom;
|
||||
boolean<false> m_updateEventScheduled;
|
||||
boolean<true> m_firstOnStyle;
|
||||
Rect m_rect;
|
||||
UILayoutPtr m_layout;
|
||||
UIWidgetWeakPtr m_parent;
|
||||
|
@ -200,14 +199,12 @@ protected:
|
|||
UIWidgetPtr m_focusedChild;
|
||||
OTMLNodePtr m_style;
|
||||
OTMLNodePtr m_stateStyle;
|
||||
int m_states;
|
||||
|
||||
// basic style components used by all widgets
|
||||
ImagePtr m_image;
|
||||
FontPtr m_font;
|
||||
int m_opacity;
|
||||
Color m_backgroundColor;
|
||||
Color m_foregroundColor;
|
||||
int m_states;
|
||||
int m_opacity;
|
||||
int m_marginLeft;
|
||||
int m_marginRight;
|
||||
int m_marginTop;
|
||||
|
|
|
@ -27,14 +27,13 @@
|
|||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/otml/otml.h>
|
||||
|
||||
void UIWindow::setup()
|
||||
UIWindow::UIWindow()
|
||||
{
|
||||
UIWidget::setup();
|
||||
m_moving = false;
|
||||
m_movePolicy = DONT_MOVE;
|
||||
m_titleAlign = Fw::AlignCenter;
|
||||
m_headHeight = 0;
|
||||
m_oldIndex = -1;
|
||||
m_titleAlign = Fw::AlignCenter;
|
||||
}
|
||||
|
||||
void UIWindow::render()
|
||||
|
|
|
@ -34,7 +34,7 @@ class UIWindow : public UIWidget
|
|||
};
|
||||
|
||||
public:
|
||||
virtual void setup();
|
||||
UIWindow();
|
||||
virtual void render();
|
||||
|
||||
void setTitle(const std::string& title) { m_title = title; }
|
||||
|
@ -52,16 +52,12 @@ private:
|
|||
std::string m_title;
|
||||
bool m_moving;
|
||||
MovePolicy m_movePolicy;
|
||||
Fw::AlignmentFlag m_titleAlign;
|
||||
Point m_headOffset;
|
||||
Point m_movingReference;
|
||||
Point m_oldPos;
|
||||
int m_oldIndex;
|
||||
|
||||
// styling
|
||||
BorderImagePtr m_headImage;
|
||||
ImagePtr m_bodyImage;
|
||||
int m_headHeight;
|
||||
Point m_headOffset;
|
||||
Fw::AlignmentFlag m_titleAlign;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
class Color
|
||||
{
|
||||
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(const Color& other) : m_rgba(other.m_rgba) { }
|
||||
Color(uint32 rgba) : m_rgba(rgba) { }
|
||||
|
|
|
@ -42,8 +42,15 @@ typedef int8_t int8;
|
|||
typedef std::function<void()> SimpleCallback;
|
||||
typedef std::function<bool()> BooleanCallback;
|
||||
|
||||
#ifndef nullptr
|
||||
#define nullptr NULL
|
||||
#endif
|
||||
// boolean with default value initializer
|
||||
template<bool def>
|
||||
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
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
#include <framework/otml/otml.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
|
||||
void UICreature::setup()
|
||||
UICreature::UICreature()
|
||||
{
|
||||
UIWidget::setup();
|
||||
m_creatureMargin = 0;
|
||||
}
|
||||
|
||||
void UICreature::render()
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
class UICreature : public UIWidget
|
||||
{
|
||||
public:
|
||||
void setup();
|
||||
UICreature();
|
||||
void render();
|
||||
|
||||
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
#include <framework/otml/otml.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
|
||||
void UIItem::setup()
|
||||
UIItem::UIItem()
|
||||
{
|
||||
UIWidget::setup();
|
||||
m_itemMargin = 0;
|
||||
}
|
||||
|
||||
void UIItem::render()
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
class UIItem : public UIWidget
|
||||
{
|
||||
public:
|
||||
void setup();
|
||||
UIItem();
|
||||
void render();
|
||||
|
||||
void setItem(const ItemPtr& item) { m_item = item; }
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
#include <otclient/core/localplayer.h>
|
||||
#include <otclient/core/tile.h>
|
||||
|
||||
void UIMap::setup()
|
||||
UIMap::UIMap()
|
||||
{
|
||||
UIWidget::setup();
|
||||
m_mapMargin = 0;
|
||||
}
|
||||
|
||||
void UIMap::render()
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
class UIMap : public UIWidget
|
||||
{
|
||||
public:
|
||||
void setup();
|
||||
UIMap();
|
||||
void render();
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue