mirror of
https://github.com/edubart/otclient.git
synced 2025-10-20 06:23:26 +02:00
Huge engine change, replace all std::shared_ptrs
Create a new shared pointer type stdext::shared_object_ptr and stdext::shared_obj using boost::intrusive_ptr Advantages: * half memory usage * faster and lightweight Disadvantages: * using weak_ptr is not supported anymore * compiling seems slower
This commit is contained in:
@@ -36,17 +36,15 @@ class UIGridLayout;
|
||||
class UIAnchorLayout;
|
||||
class UIParticles;
|
||||
|
||||
typedef std::shared_ptr<UIWidget> UIWidgetPtr;
|
||||
typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
|
||||
|
||||
typedef std::shared_ptr<UIParticles> UIParticlesPtr;
|
||||
typedef std::shared_ptr<UITextEdit> UITextEditPtr;
|
||||
typedef std::shared_ptr<UILayout> UILayoutPtr;
|
||||
typedef std::shared_ptr<UIBoxLayout> UIBoxLayoutPtr;
|
||||
typedef std::shared_ptr<UIHorizontalLayout> UIHorizontalLayoutPtr;
|
||||
typedef std::shared_ptr<UIVerticalLayout> UIVerticalLayoutPtr;
|
||||
typedef std::shared_ptr<UIGridLayout> UIGridLayoutPtr;
|
||||
typedef std::shared_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
|
||||
typedef stdext::shared_object_ptr<UIWidget> UIWidgetPtr;
|
||||
typedef stdext::shared_object_ptr<UIParticles> UIParticlesPtr;
|
||||
typedef stdext::shared_object_ptr<UITextEdit> UITextEditPtr;
|
||||
typedef stdext::shared_object_ptr<UILayout> UILayoutPtr;
|
||||
typedef stdext::shared_object_ptr<UIBoxLayout> UIBoxLayoutPtr;
|
||||
typedef stdext::shared_object_ptr<UIHorizontalLayout> UIHorizontalLayoutPtr;
|
||||
typedef stdext::shared_object_ptr<UIVerticalLayout> UIVerticalLayoutPtr;
|
||||
typedef stdext::shared_object_ptr<UIGridLayout> UIGridLayoutPtr;
|
||||
typedef stdext::shared_object_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
|
||||
|
||||
typedef std::deque<UIWidgetPtr> UIWidgetList;
|
||||
|
||||
|
@@ -74,7 +74,7 @@ public:
|
||||
void addWidget(const UIWidgetPtr& widget);
|
||||
void removeWidget(const UIWidgetPtr& widget);
|
||||
|
||||
UIAnchorLayoutPtr asUIAnchorLayout() { return std::static_pointer_cast<UIAnchorLayout>(shared_from_this()); }
|
||||
bool isUIAnchorLayout() { return true; }
|
||||
|
||||
protected:
|
||||
bool internalUpdate();
|
||||
|
@@ -38,7 +38,7 @@ public:
|
||||
void setSpacing(int spacing) { m_spacing = spacing; update(); }
|
||||
void setFitChildren(bool fitParent) { m_fitChildren = fitParent; update(); }
|
||||
|
||||
UIBoxLayoutPtr asUIBoxLayout() { return std::static_pointer_cast<UIBoxLayout>(shared_from_this()); }
|
||||
bool isUIBoxLayout() { return true; }
|
||||
|
||||
protected:
|
||||
Boolean<false> m_fitChildren;
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#ifndef UIGRIDLAYOUT_H
|
||||
#define UIGRIDLAYOUT_H
|
||||
|
||||
#include <framework/ui/uilayout.h>
|
||||
#include "uilayout.h"
|
||||
|
||||
// @bindclass
|
||||
class UIGridLayout : public UILayout
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
void setFitChildren(bool enable) { m_fitChildren = enable; update(); }
|
||||
void setFlow(bool enable) { m_flow = enable; update(); }
|
||||
|
||||
virtual UIGridLayoutPtr asUIGridLayout() { return nullptr; }
|
||||
virtual bool isUIGridLayout() { return true; }
|
||||
|
||||
protected:
|
||||
bool internalUpdate();
|
||||
|
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
void setAlignRight(bool aliginRight) { m_alignRight = aliginRight; update(); }
|
||||
|
||||
UIHorizontalLayoutPtr asUIHorizontalLayout() { return std::static_pointer_cast<UIHorizontalLayout>(shared_from_this()); }
|
||||
bool isUIHorizontalLayout() { return true; }
|
||||
|
||||
protected:
|
||||
bool internalUpdate();
|
||||
|
@@ -28,8 +28,7 @@
|
||||
void UILayout::update()
|
||||
{
|
||||
//logTraceCounter();
|
||||
UIWidgetPtr parentWidget = getParentWidget();
|
||||
if(!parentWidget || parentWidget->isDestroyed())
|
||||
if(!m_parentWidget)
|
||||
return;
|
||||
|
||||
/*
|
||||
@@ -52,7 +51,7 @@ void UILayout::update()
|
||||
|
||||
m_updating = true;
|
||||
internalUpdate();
|
||||
parentWidget->onLayoutUpdate();
|
||||
m_parentWidget->onLayoutUpdate();
|
||||
m_updating = false;
|
||||
}
|
||||
|
||||
@@ -64,7 +63,7 @@ void UILayout::updateLater()
|
||||
if(!getParentWidget())
|
||||
return;
|
||||
|
||||
auto self = asUILayout();
|
||||
auto self = self_cast<UILayout>();
|
||||
g_dispatcher.addEvent([self] {
|
||||
self->m_updateScheduled = false;
|
||||
self->update();
|
||||
|
@@ -43,17 +43,16 @@ public:
|
||||
void enableUpdates() { m_updateDisabled = std::max(m_updateDisabled-1,0); }
|
||||
|
||||
void setParent(UIWidgetPtr parentWidget) { m_parentWidget = parentWidget; }
|
||||
UIWidgetPtr getParentWidget() { return m_parentWidget.lock(); }
|
||||
UIWidgetPtr getParentWidget() { return m_parentWidget; }
|
||||
|
||||
bool isUpdateDisabled() { return m_updateDisabled > 0; }
|
||||
bool isUpdating() { return m_updating; }
|
||||
|
||||
UILayoutPtr asUILayout() { return std::static_pointer_cast<UILayout>(shared_from_this()); }
|
||||
virtual UIAnchorLayoutPtr asUIAnchorLayout() { return nullptr; }
|
||||
virtual UIBoxLayoutPtr asUIBoxLayout() { return nullptr; }
|
||||
virtual UIHorizontalLayoutPtr asUIHorizontalLayout() { return nullptr; }
|
||||
virtual UIVerticalLayoutPtr asUIVerticalLayout() { return nullptr; }
|
||||
virtual UIGridLayoutPtr asUIGridLayout() { return nullptr; }
|
||||
virtual bool isUIAnchorLayout() { return false; }
|
||||
virtual bool isUIBoxLayout() { return false; }
|
||||
virtual bool isUIHorizontalLayout() { return false; }
|
||||
virtual bool isUIVerticalLayout() { return false; }
|
||||
virtual bool isUIGridLayout() { return false; }
|
||||
|
||||
protected:
|
||||
virtual bool internalUpdate() = 0;
|
||||
@@ -61,7 +60,7 @@ protected:
|
||||
int m_updateDisabled;
|
||||
Boolean<false> m_updating;
|
||||
Boolean<false> m_updateScheduled;
|
||||
UIWidgetWeakPtr m_parentWidget;
|
||||
UIWidgetPtr m_parentWidget;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -285,7 +285,7 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget)
|
||||
g_dispatcher.scheduleEvent([backupList] {
|
||||
g_lua.collectGarbage();
|
||||
for(const UIWidgetPtr& widget : backupList) {
|
||||
if(widget->getUseCount() != 1)
|
||||
if(widget->ref_count() != 1)
|
||||
g_logger.warning(stdext::format("widget '%s' destroyed but still have %d reference(s) left", widget->getId(), widget->getUseCount()-1));
|
||||
}
|
||||
}, 1);
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#define UIMANAGER_H
|
||||
|
||||
#include "declarations.h"
|
||||
#include "uiwidget.h"
|
||||
#include <framework/core/inputevent.h>
|
||||
#include <framework/otml/declarations.h>
|
||||
|
||||
|
@@ -35,7 +35,7 @@ public:
|
||||
|
||||
void setAlignBottom(bool aliginBottom) { m_alignBottom = aliginBottom; update(); }
|
||||
|
||||
UIVerticalLayoutPtr asUIVerticalLayout() { return std::static_pointer_cast<UIVerticalLayout>(shared_from_this()); }
|
||||
bool isUIVerticalLayout() { return true; }
|
||||
|
||||
protected:
|
||||
bool internalUpdate();
|
||||
|
@@ -141,11 +141,11 @@ void UIWidget::addChild(const UIWidgetPtr& child)
|
||||
UIWidgetPtr oldLastChild = getLastChild();
|
||||
|
||||
m_children.push_back(child);
|
||||
child->setParent(asUIWidget());
|
||||
child->setParent(self_cast<UIWidget>());
|
||||
|
||||
// create default layout
|
||||
if(!m_layout)
|
||||
m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget()));
|
||||
m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(self_cast<UIWidget>()));
|
||||
|
||||
// add to layout and updates it
|
||||
m_layout->addWidget(child);
|
||||
@@ -184,11 +184,11 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
|
||||
// retrieve child by index
|
||||
auto it = m_children.begin() + index;
|
||||
m_children.insert(it, child);
|
||||
child->setParent(asUIWidget());
|
||||
child->setParent(self_cast<UIWidget>());
|
||||
|
||||
// create default layout if needed
|
||||
if(!m_layout)
|
||||
m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget()));
|
||||
m_layout = UIAnchorLayoutPtr(new UIAnchorLayout(self_cast<UIWidget>()));
|
||||
|
||||
// add to layout and updates it
|
||||
m_layout->addWidget(child);
|
||||
@@ -218,7 +218,7 @@ void UIWidget::removeChild(UIWidgetPtr child)
|
||||
m_children.erase(it);
|
||||
|
||||
// reset child parent
|
||||
assert(child->getParent() == asUIWidget());
|
||||
assert(child->getParent() == self_cast<UIWidget>());
|
||||
child->setParent(nullptr);
|
||||
|
||||
m_layout->removeWidget(child);
|
||||
@@ -504,7 +504,7 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
|
||||
callLuaField("onStyleApply", styleNode->tag(), styleNode);
|
||||
|
||||
if(m_firstOnStyle) {
|
||||
auto self = asUIWidget();
|
||||
auto self = self_cast<UIWidget>();
|
||||
g_dispatcher.addEvent([self] {
|
||||
self->callLuaField("onSetup");
|
||||
});
|
||||
@@ -525,7 +525,7 @@ void UIWidget::addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedW
|
||||
return;
|
||||
|
||||
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout())
|
||||
anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
|
||||
anchorLayout->addAnchor(self_cast<UIWidget>(), anchoredEdge, hookedWidgetId, hookedEdge);
|
||||
else
|
||||
g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
|
||||
}
|
||||
@@ -541,8 +541,8 @@ void UIWidget::centerIn(const std::string& hookedWidgetId)
|
||||
return;
|
||||
|
||||
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout()) {
|
||||
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);
|
||||
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
|
||||
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);
|
||||
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
|
||||
} else
|
||||
g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
|
||||
}
|
||||
@@ -553,10 +553,10 @@ void UIWidget::fill(const std::string& hookedWidgetId)
|
||||
return;
|
||||
|
||||
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout()) {
|
||||
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorLeft, hookedWidgetId, Fw::AnchorLeft);
|
||||
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorRight, hookedWidgetId, Fw::AnchorRight);
|
||||
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop);
|
||||
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
|
||||
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorLeft, hookedWidgetId, Fw::AnchorLeft);
|
||||
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorRight, hookedWidgetId, Fw::AnchorRight);
|
||||
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop);
|
||||
anchorLayout->addAnchor(self_cast<UIWidget>(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
|
||||
} else
|
||||
g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id));
|
||||
}
|
||||
@@ -567,7 +567,7 @@ void UIWidget::breakAnchors()
|
||||
return;
|
||||
|
||||
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout())
|
||||
anchorLayout->removeAnchors(asUIWidget());
|
||||
anchorLayout->removeAnchors(self_cast<UIWidget>());
|
||||
}
|
||||
|
||||
void UIWidget::updateParentLayout()
|
||||
@@ -601,7 +601,7 @@ void UIWidget::lock()
|
||||
return;
|
||||
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->lockChild(asUIWidget());
|
||||
parent->lockChild(self_cast<UIWidget>());
|
||||
}
|
||||
|
||||
void UIWidget::unlock()
|
||||
@@ -610,7 +610,7 @@ void UIWidget::unlock()
|
||||
return;
|
||||
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->unlockChild(asUIWidget());
|
||||
parent->unlockChild(self_cast<UIWidget>());
|
||||
}
|
||||
|
||||
void UIWidget::focus()
|
||||
@@ -622,7 +622,7 @@ void UIWidget::focus()
|
||||
return;
|
||||
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->focusChild(asUIWidget(), Fw::ActiveFocusReason);
|
||||
parent->focusChild(self_cast<UIWidget>(), Fw::ActiveFocusReason);
|
||||
}
|
||||
|
||||
void UIWidget::recursiveFocus(Fw::FocusReason reason)
|
||||
@@ -632,7 +632,7 @@ void UIWidget::recursiveFocus(Fw::FocusReason reason)
|
||||
|
||||
if(UIWidgetPtr parent = getParent()) {
|
||||
if(m_focusable)
|
||||
parent->focusChild(asUIWidget(), reason);
|
||||
parent->focusChild(self_cast<UIWidget>(), reason);
|
||||
parent->recursiveFocus(reason);
|
||||
}
|
||||
}
|
||||
@@ -644,7 +644,7 @@ void UIWidget::lower()
|
||||
|
||||
UIWidgetPtr parent = getParent();
|
||||
if(parent)
|
||||
parent->lowerChild(asUIWidget());
|
||||
parent->lowerChild(self_cast<UIWidget>());
|
||||
}
|
||||
|
||||
void UIWidget::raise()
|
||||
@@ -654,7 +654,7 @@ void UIWidget::raise()
|
||||
|
||||
UIWidgetPtr parent = getParent();
|
||||
if(parent)
|
||||
parent->raiseChild(asUIWidget());
|
||||
parent->raiseChild(self_cast<UIWidget>());
|
||||
}
|
||||
|
||||
void UIWidget::grabMouse()
|
||||
@@ -662,12 +662,12 @@ void UIWidget::grabMouse()
|
||||
if(m_destroyed)
|
||||
return;
|
||||
|
||||
g_ui.setMouseReceiver(asUIWidget());
|
||||
g_ui.setMouseReceiver(self_cast<UIWidget>());
|
||||
}
|
||||
|
||||
void UIWidget::ungrabMouse()
|
||||
{
|
||||
if(g_ui.getMouseReceiver() == asUIWidget())
|
||||
if(g_ui.getMouseReceiver() == self_cast<UIWidget>())
|
||||
g_ui.resetMouseReceiver();
|
||||
}
|
||||
|
||||
@@ -676,12 +676,12 @@ void UIWidget::grabKeyboard()
|
||||
if(m_destroyed)
|
||||
return;
|
||||
|
||||
g_ui.setKeyboardReceiver(asUIWidget());
|
||||
g_ui.setKeyboardReceiver(self_cast<UIWidget>());
|
||||
}
|
||||
|
||||
void UIWidget::ungrabKeyboard()
|
||||
{
|
||||
if(g_ui.getKeyboardReceiver() == asUIWidget())
|
||||
if(g_ui.getKeyboardReceiver() == self_cast<UIWidget>())
|
||||
g_ui.resetKeyboardReceiver();
|
||||
}
|
||||
|
||||
@@ -705,9 +705,12 @@ void UIWidget::internalDestroy()
|
||||
m_destroyed = true;
|
||||
m_visible = false;
|
||||
m_enabled = false;
|
||||
m_parent.reset();
|
||||
m_focusedChild = nullptr;
|
||||
m_layout = nullptr;
|
||||
if(m_layout) {
|
||||
m_layout->setParent(nullptr);
|
||||
m_layout = nullptr;
|
||||
}
|
||||
m_parent = nullptr;
|
||||
m_lockedChildren.clear();
|
||||
|
||||
for(const UIWidgetPtr& child : m_children)
|
||||
@@ -718,7 +721,7 @@ void UIWidget::internalDestroy()
|
||||
|
||||
releaseLuaFieldsTable();
|
||||
|
||||
g_ui.onWidgetDestroy(asUIWidget());
|
||||
g_ui.onWidgetDestroy(self_cast<UIWidget>());
|
||||
}
|
||||
|
||||
void UIWidget::destroy()
|
||||
@@ -727,7 +730,7 @@ void UIWidget::destroy()
|
||||
g_logger.warning(stdext::format("attempt to destroy widget '%s' two times", m_id));
|
||||
|
||||
// hold itself reference
|
||||
UIWidgetPtr self = asUIWidget();
|
||||
UIWidgetPtr self = self_cast<UIWidget>();
|
||||
m_destroyed = true;
|
||||
|
||||
// remove itself from parent
|
||||
@@ -772,7 +775,7 @@ void UIWidget::setParent(const UIWidgetPtr& parent)
|
||||
if(oldParent == parent)
|
||||
return;
|
||||
|
||||
UIWidgetPtr self = asUIWidget();
|
||||
UIWidgetPtr self = self_cast<UIWidget>();
|
||||
if(oldParent && oldParent->hasChild(self))
|
||||
oldParent->removeChild(self);
|
||||
|
||||
@@ -794,7 +797,7 @@ void UIWidget::setLayout(const UILayoutPtr& layout)
|
||||
if(m_layout)
|
||||
m_layout->disableUpdates();
|
||||
|
||||
layout->setParent(asUIWidget());
|
||||
layout->setParent(self_cast<UIWidget>());
|
||||
layout->disableUpdates();
|
||||
|
||||
for(const UIWidgetPtr& child : m_children) {
|
||||
@@ -833,7 +836,7 @@ bool UIWidget::setRect(const Rect& rect)
|
||||
|
||||
// avoid massive update events
|
||||
if(!m_updateEventScheduled) {
|
||||
UIWidgetPtr self = asUIWidget();
|
||||
UIWidgetPtr self = self_cast<UIWidget>();
|
||||
g_dispatcher.addEvent([self, oldRect]() {
|
||||
self->m_updateEventScheduled = false;
|
||||
if(oldRect != self->getRect())
|
||||
@@ -893,9 +896,9 @@ void UIWidget::setVisible(bool visible)
|
||||
|
||||
// visibility can change the current hovered widget
|
||||
if(visible)
|
||||
g_ui.onWidgetAppear(asUIWidget());
|
||||
g_ui.onWidgetAppear(self_cast<UIWidget>());
|
||||
else
|
||||
g_ui.onWidgetDisappear(asUIWidget());
|
||||
g_ui.onWidgetDisappear(self_cast<UIWidget>());
|
||||
|
||||
callLuaField("onVisibilityChange", visible);
|
||||
}
|
||||
@@ -960,14 +963,14 @@ bool UIWidget::isVisible()
|
||||
else if(UIWidgetPtr parent = getParent())
|
||||
return parent->isVisible();
|
||||
else
|
||||
return asUIWidget() == g_ui.getRootWidget();
|
||||
return self_cast<UIWidget>() == g_ui.getRootWidget();
|
||||
}
|
||||
|
||||
bool UIWidget::isAnchored()
|
||||
{
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
if(UIAnchorLayoutPtr anchorLayout = parent->getAnchoredLayout())
|
||||
return anchorLayout->hasAnchors(asUIWidget());
|
||||
return anchorLayout->hasAnchors(self_cast<UIWidget>());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1041,7 +1044,10 @@ UIAnchorLayoutPtr UIWidget::getAnchoredLayout()
|
||||
if(!parent)
|
||||
return nullptr;
|
||||
|
||||
return parent->getLayout()->asUIAnchorLayout();
|
||||
UILayoutPtr layout = parent->getLayout();
|
||||
if(layout->isUIAnchorLayout())
|
||||
return layout->self_cast<UIAnchorLayout>();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UIWidgetPtr UIWidget::getRootParent()
|
||||
@@ -1049,7 +1055,7 @@ UIWidgetPtr UIWidget::getRootParent()
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
return parent->getRootParent();
|
||||
else
|
||||
return asUIWidget();
|
||||
return self_cast<UIWidget>();
|
||||
}
|
||||
|
||||
UIWidgetPtr UIWidget::getChildAfter(const UIWidgetPtr& relativeChild)
|
||||
@@ -1225,7 +1231,7 @@ void UIWidget::updateState(Fw::WidgetState state)
|
||||
|
||||
switch(state) {
|
||||
case Fw::ActiveState: {
|
||||
UIWidgetPtr widget = asUIWidget();
|
||||
UIWidgetPtr widget = self_cast<UIWidget>();
|
||||
UIWidgetPtr parent;
|
||||
do {
|
||||
parent = widget->getParent();
|
||||
@@ -1240,24 +1246,24 @@ void UIWidget::updateState(Fw::WidgetState state)
|
||||
break;
|
||||
}
|
||||
case Fw::FocusState: {
|
||||
newStatus = (getParent() && getParent()->getFocusedChild() == asUIWidget());
|
||||
newStatus = (getParent() && getParent()->getFocusedChild() == self_cast<UIWidget>());
|
||||
break;
|
||||
}
|
||||
case Fw::HoverState: {
|
||||
newStatus = (g_ui.getHoveredWidget() == asUIWidget() && isEnabled());
|
||||
newStatus = (g_ui.getHoveredWidget() == self_cast<UIWidget>() && isEnabled());
|
||||
break;
|
||||
}
|
||||
case Fw::PressedState: {
|
||||
newStatus = (g_ui.getPressedWidget() == asUIWidget());
|
||||
newStatus = (g_ui.getPressedWidget() == self_cast<UIWidget>());
|
||||
break;
|
||||
}
|
||||
case Fw::DraggingState: {
|
||||
newStatus = (g_ui.getDraggingWidget() == asUIWidget());
|
||||
newStatus = (g_ui.getDraggingWidget() == self_cast<UIWidget>());
|
||||
break;
|
||||
}
|
||||
case Fw::DisabledState: {
|
||||
bool enabled = true;
|
||||
UIWidgetPtr widget = asUIWidget();
|
||||
UIWidgetPtr widget = self_cast<UIWidget>();
|
||||
do {
|
||||
if(!widget->isExplicitlyEnabled()) {
|
||||
enabled = false;
|
||||
@@ -1269,19 +1275,19 @@ void UIWidget::updateState(Fw::WidgetState state)
|
||||
break;
|
||||
}
|
||||
case Fw::FirstState: {
|
||||
newStatus = (getParent() && getParent()->getFirstChild() == asUIWidget());
|
||||
newStatus = (getParent() && getParent()->getFirstChild() == self_cast<UIWidget>());
|
||||
break;
|
||||
}
|
||||
case Fw::MiddleState: {
|
||||
newStatus = (getParent() && getParent()->getFirstChild() != asUIWidget() && getParent()->getLastChild() != asUIWidget());
|
||||
newStatus = (getParent() && getParent()->getFirstChild() != self_cast<UIWidget>() && getParent()->getLastChild() != self_cast<UIWidget>());
|
||||
break;
|
||||
}
|
||||
case Fw::LastState: {
|
||||
newStatus = (getParent() && getParent()->getLastChild() == asUIWidget());
|
||||
newStatus = (getParent() && getParent()->getLastChild() == self_cast<UIWidget>());
|
||||
break;
|
||||
}
|
||||
case Fw::AlternateState: {
|
||||
newStatus = (getParent() && (getParent()->getChildIndex(asUIWidget()) % 2) == 1);
|
||||
newStatus = (getParent() && (getParent()->getChildIndex(self_cast<UIWidget>()) % 2) == 1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -1331,7 +1337,7 @@ void UIWidget::updateStyle()
|
||||
return;
|
||||
|
||||
if(m_loadingStyle && !m_updateStyleScheduled) {
|
||||
UIWidgetPtr self = asUIWidget();
|
||||
UIWidgetPtr self = self_cast<UIWidget>();
|
||||
g_dispatcher.addEvent([self] {
|
||||
self->m_updateStyleScheduled = false;
|
||||
self->updateStyle();
|
||||
@@ -1636,7 +1642,7 @@ bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widget
|
||||
}
|
||||
}
|
||||
|
||||
widgetList.push_back(asUIWidget());
|
||||
widgetList.push_back(self_cast<UIWidget>());
|
||||
|
||||
if(!isPhantom())
|
||||
ret = true;
|
||||
@@ -1651,6 +1657,6 @@ bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMov
|
||||
child->propagateOnMouseMove(mousePos, mouseMoved, widgetList);
|
||||
}
|
||||
|
||||
widgetList.push_back(asUIWidget());
|
||||
widgetList.push_back(self_cast<UIWidget>());
|
||||
return true;
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@
|
||||
#define UIWIDGET_H
|
||||
|
||||
#include "declarations.h"
|
||||
#include "uilayout.h"
|
||||
|
||||
#include <framework/luaengine/luaobject.h>
|
||||
#include <framework/graphics/declarations.h>
|
||||
#include <framework/otml/otmlnode.h>
|
||||
@@ -68,7 +70,7 @@ protected:
|
||||
Boolean<false> m_destroyed;
|
||||
Boolean<false> m_clipping;
|
||||
UILayoutPtr m_layout;
|
||||
UIWidgetWeakPtr m_parent;
|
||||
UIWidgetPtr m_parent;
|
||||
UIWidgetList m_children;
|
||||
UIWidgetList m_lockedChildren;
|
||||
UIWidgetPtr m_focusedChild;
|
||||
@@ -152,8 +154,6 @@ public:
|
||||
UIWidgetList recursiveGetChildrenByMarginPos(const Point& childPos);
|
||||
UIWidgetPtr backwardsGetWidgetById(const std::string& id);
|
||||
|
||||
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
||||
|
||||
private:
|
||||
Boolean<false> m_updateEventScheduled;
|
||||
Boolean<false> m_loadingStyle;
|
||||
@@ -248,7 +248,7 @@ public:
|
||||
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
||||
|
||||
std::string getId() { return m_id; }
|
||||
UIWidgetPtr getParent() { return m_parent.lock(); }
|
||||
UIWidgetPtr getParent() { return m_parent; }
|
||||
UIWidgetPtr getFocusedChild() { return m_focusedChild; }
|
||||
UIWidgetList getChildren() { return m_children; }
|
||||
UIWidgetPtr getFirstChild() { return getChildByIndex(1); }
|
||||
|
@@ -243,13 +243,13 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
|
||||
if(!layoutType.empty()) {
|
||||
UILayoutPtr layout;
|
||||
if(layoutType == "horizontalBox")
|
||||
layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(asUIWidget()));
|
||||
layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(self_cast<UIWidget>()));
|
||||
else if(layoutType == "verticalBox")
|
||||
layout = UIVerticalLayoutPtr(new UIVerticalLayout(asUIWidget()));
|
||||
layout = UIVerticalLayoutPtr(new UIVerticalLayout(self_cast<UIWidget>()));
|
||||
else if(layoutType == "grid")
|
||||
layout = UIGridLayoutPtr(new UIGridLayout(asUIWidget()));
|
||||
layout = UIGridLayoutPtr(new UIGridLayout(self_cast<UIWidget>()));
|
||||
else if(layoutType == "anchor")
|
||||
layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget()));
|
||||
layout = UIAnchorLayoutPtr(new UIAnchorLayout(self_cast<UIWidget>()));
|
||||
else
|
||||
throw OTMLException(node, "cannot determine layout type");
|
||||
setLayout(layout);
|
||||
@@ -268,7 +268,11 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
|
||||
continue;
|
||||
}
|
||||
|
||||
UIAnchorLayoutPtr anchorLayout = parent->getLayout()->asUIAnchorLayout();
|
||||
UILayoutPtr layout = parent->getLayout();
|
||||
UIAnchorLayoutPtr anchorLayout;
|
||||
if(layout->isUIAnchorLayout())
|
||||
anchorLayout = layout->self_cast<UIAnchorLayout>();
|
||||
|
||||
if(!anchorLayout)
|
||||
throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!");
|
||||
|
||||
|
Reference in New Issue
Block a user