diff --git a/src/framework/ui/uibutton.cpp b/src/framework/ui/uibutton.cpp index 8a807f16..a8650f8b 100644 --- a/src/framework/ui/uibutton.cpp +++ b/src/framework/ui/uibutton.cpp @@ -29,10 +29,9 @@ #include #include -void UIButton::setup() +UIButton::UIButton() { - UIWidget::setup(); - setFocusable(false); + m_focusable = false; } void UIButton::render() diff --git a/src/framework/ui/uibutton.h b/src/framework/ui/uibutton.h index 950f3ee8..30bd4c74 100644 --- a/src/framework/ui/uibutton.h +++ b/src/framework/ui/uibutton.h @@ -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; } diff --git a/src/framework/ui/uicheckbox.cpp b/src/framework/ui/uicheckbox.cpp index 5661ed56..734ae91c 100644 --- a/src/framework/ui/uicheckbox.cpp +++ b/src/framework/ui/uicheckbox.cpp @@ -27,10 +27,9 @@ #include #include -void UICheckBox::setup() +UICheckBox::UICheckBox() { - UIWidget::setup(); - setFocusable(false); + m_focusable = false; } void UICheckBox::render() diff --git a/src/framework/ui/uicheckbox.h b/src/framework/ui/uicheckbox.h index c074679e..a93778b8 100644 --- a/src/framework/ui/uicheckbox.h +++ b/src/framework/ui/uicheckbox.h @@ -28,7 +28,7 @@ class UICheckBox : public UIWidget { public: - void setup(); + UICheckBox(); void render(); bool isChecked(); diff --git a/src/framework/ui/uiframecounter.cpp b/src/framework/ui/uiframecounter.cpp index 3f95f094..0df02ab8 100644 --- a/src/framework/ui/uiframecounter.cpp +++ b/src/framework/ui/uiframecounter.cpp @@ -27,12 +27,11 @@ #include #include -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; } diff --git a/src/framework/ui/uiframecounter.h b/src/framework/ui/uiframecounter.h index e119ae99..daa908b2 100644 --- a/src/framework/ui/uiframecounter.h +++ b/src/framework/ui/uiframecounter.h @@ -28,7 +28,7 @@ class UIFrameCounter : public UIWidget { public: - virtual void setup(); + UIFrameCounter(); virtual void render(); void setAlign(Fw::AlignmentFlag align) { m_align = align; } diff --git a/src/framework/ui/uilabel.cpp b/src/framework/ui/uilabel.cpp index 51d3cf42..8f87dbaa 100644 --- a/src/framework/ui/uilabel.cpp +++ b/src/framework/ui/uilabel.cpp @@ -25,12 +25,11 @@ #include #include -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() diff --git a/src/framework/ui/uilabel.h b/src/framework/ui/uilabel.h index bec09757..f76fce5b 100644 --- a/src/framework/ui/uilabel.h +++ b/src/framework/ui/uilabel.h @@ -28,7 +28,7 @@ class UILabel : public UIWidget { public: - virtual void setup(); + UILabel(); virtual void render(); void resizeToText(); diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 3de71c1c..492bd980 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -32,7 +32,6 @@ void UIManager::init() { // creates root widget m_rootWidget = UIWidget::create(); - m_rootWidget->setup(); m_rootWidget->setId("root"); m_rootWidget->resize(g_graphics.getScreenSize()); } diff --git a/src/framework/ui/uiprogressbar.cpp b/src/framework/ui/uiprogressbar.cpp index 7e99e794..12013a1c 100644 --- a/src/framework/ui/uiprogressbar.cpp +++ b/src/framework/ui/uiprogressbar.cpp @@ -24,11 +24,10 @@ #include #include -void UIProgressBar::setup() +UIProgressBar::UIProgressBar() { - UIWidget::setup(); - setPhantom(true); - setFocusable(false); + m_phantom = false; + m_focusable = false; m_percent = 0; } diff --git a/src/framework/ui/uiprogressbar.h b/src/framework/ui/uiprogressbar.h index 62f2e982..dd054f31 100644 --- a/src/framework/ui/uiprogressbar.h +++ b/src/framework/ui/uiprogressbar.h @@ -28,7 +28,7 @@ class UIProgressBar : public UIWidget { public: - virtual void setup(); + UIProgressBar(); virtual void render(); void setPercent(double percent); diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 35c8ed53..b398f029 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -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() diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 062ff144..5be383e5 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -31,14 +31,13 @@ class UIWidget : public LuaObject { public: UIWidget(); - virtual ~UIWidget(); + virtual ~UIWidget() { } template - static std::shared_ptr create() { auto t = std::shared_ptr(new T); t->setup(); return t; } + static std::shared_ptr create() { auto t = std::shared_ptr(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 m_enabled; + boolean m_visible; + boolean m_focusable; + boolean m_fixedSize; + boolean m_pressed; + boolean m_phantom; + boolean m_updateEventScheduled; + boolean 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; diff --git a/src/framework/ui/uiwindow.cpp b/src/framework/ui/uiwindow.cpp index 16f36839..f184f40b 100644 --- a/src/framework/ui/uiwindow.cpp +++ b/src/framework/ui/uiwindow.cpp @@ -27,14 +27,13 @@ #include #include -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() diff --git a/src/framework/ui/uiwindow.h b/src/framework/ui/uiwindow.h index 9531d1d4..72c7bafd 100644 --- a/src/framework/ui/uiwindow.h +++ b/src/framework/ui/uiwindow.h @@ -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 diff --git a/src/framework/util/color.h b/src/framework/util/color.h index 9116ccd0..1a1f95e3 100644 --- a/src/framework/util/color.h +++ b/src/framework/util/color.h @@ -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) { } diff --git a/src/framework/util/types.h b/src/framework/util/types.h index 6f6e104f..eeb5999a 100644 --- a/src/framework/util/types.h +++ b/src/framework/util/types.h @@ -42,8 +42,15 @@ typedef int8_t int8; typedef std::function SimpleCallback; typedef std::function BooleanCallback; -#ifndef nullptr -#define nullptr NULL -#endif +// boolean with default value initializer +template +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 diff --git a/src/otclient/ui/uicreature.cpp b/src/otclient/ui/uicreature.cpp index c1760414..f78751e2 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -24,9 +24,9 @@ #include #include -void UICreature::setup() +UICreature::UICreature() { - UIWidget::setup(); + m_creatureMargin = 0; } void UICreature::render() diff --git a/src/otclient/ui/uicreature.h b/src/otclient/ui/uicreature.h index 89ce6906..4bdd7424 100644 --- a/src/otclient/ui/uicreature.h +++ b/src/otclient/ui/uicreature.h @@ -30,7 +30,7 @@ class UICreature : public UIWidget { public: - void setup(); + UICreature(); void render(); void setCreature(const CreaturePtr& creature) { m_creature = creature; } diff --git a/src/otclient/ui/uiitem.cpp b/src/otclient/ui/uiitem.cpp index c97dbc1c..da19fb0c 100644 --- a/src/otclient/ui/uiitem.cpp +++ b/src/otclient/ui/uiitem.cpp @@ -24,9 +24,9 @@ #include #include -void UIItem::setup() +UIItem::UIItem() { - UIWidget::setup(); + m_itemMargin = 0; } void UIItem::render() diff --git a/src/otclient/ui/uiitem.h b/src/otclient/ui/uiitem.h index f5d50452..6acef7b6 100644 --- a/src/otclient/ui/uiitem.h +++ b/src/otclient/ui/uiitem.h @@ -30,7 +30,7 @@ class UIItem : public UIWidget { public: - void setup(); + UIItem(); void render(); void setItem(const ItemPtr& item) { m_item = item; } diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 2f198d1c..5a4c3049 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -29,9 +29,9 @@ #include #include -void UIMap::setup() +UIMap::UIMap() { - UIWidget::setup(); + m_mapMargin = 0; } void UIMap::render() diff --git a/src/otclient/ui/uimap.h b/src/otclient/ui/uimap.h index 15c518b4..a596027b 100644 --- a/src/otclient/ui/uimap.h +++ b/src/otclient/ui/uimap.h @@ -29,7 +29,7 @@ class UIMap : public UIWidget { public: - void setup(); + UIMap(); void render(); protected: