implement chat colors, rework on UI layout update system

This commit is contained in:
Eduardo Bart
2012-01-08 20:32:55 -02:00
parent 23ebcd9048
commit fdc9087870
23 changed files with 205 additions and 136 deletions

View File

@@ -39,10 +39,9 @@ FIND_PACKAGE(ZLIB REQUIRED)
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch -Wno-missing-field-initializers")
SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}")
SET(CMAKE_CXX_FLAGS_FULLDEBUG "-O0 -g3 -ggdb3 -fno-inline")
SET(CMAKE_CXX_FLAGS_DEBUG "-O1 -g -ggdb -fno-inline")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -ggdb -fno-inline")
SET(CMAKE_CXX_LINK_FLAGS "-static-libgcc -static-libstdc++ -Wl,--as-needed")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

View File

@@ -257,18 +257,18 @@ public:
return tmp;
}
void bound(const TRect<T> &r) {
void bound(const TRect<T> &r, bool resize = false) {
if(isNull() || r.isNull())
return;
if(right() > r.right())
moveRight(r.right());
if(bottom() > r.bottom())
moveBottom(r.bottom());
if(left() < r.left())
moveLeft(r.left());
if(top() < r.top())
moveTop(r.top());
if(bottom() > r.bottom())
moveBottom(r.bottom());
if(right() > r.right())
moveRight(r.right());
}
TRect<T>& operator=(const TRect<T>& other) { x1 = other.x1; y1 = other.y1; x2 = other.x2; y2 = other.y2; return *this; }

View File

@@ -71,23 +71,6 @@ void UIAnchorLayout::fill(const UIWidgetPtr& anchoredWidget, const std::string&
addAnchor(anchoredWidget, Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
}
void UIAnchorLayout::update()
{
// reset all anchors groups update state
for(auto& it : m_anchorsGroups) {
UIAnchorGroup& anchorGroup = it.second;
anchorGroup.setUpdated(false);
}
// update all anchors
for(auto& it : m_anchorsGroups) {
const UIWidgetPtr& widget = it.first;
UIAnchorGroup& anchorGroup = it.second;
if(!anchorGroup.isUpdated())
updateWidget(widget, anchorGroup);
}
}
void UIAnchorLayout::addWidget(const UIWidgetPtr& widget)
{
update();
@@ -210,3 +193,20 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
widget->setRect(newRect);
anchorGroup.setUpdated(true);
}
void UIAnchorLayout::internalUpdate()
{
// reset all anchors groups update state
for(auto& it : m_anchorsGroups) {
UIAnchorGroup& anchorGroup = it.second;
anchorGroup.setUpdated(false);
}
// update all anchors
for(auto& it : m_anchorsGroups) {
const UIWidgetPtr& widget = it.first;
UIAnchorGroup& anchorGroup = it.second;
if(!anchorGroup.isUpdated())
updateWidget(widget, anchorGroup);
}
}

View File

@@ -69,12 +69,14 @@ public:
void centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);
void fill(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);
void update();
void addWidget(const UIWidgetPtr& widget);
void removeWidget(const UIWidgetPtr& widget);
UIAnchorLayoutPtr asUIAnchorLayout() { return std::static_pointer_cast<UIAnchorLayout>(shared_from_this()); }
protected:
void internalUpdate();
private:
void updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup);
std::map<UIWidgetPtr, UIAnchorGroup> m_anchorsGroups;

View File

@@ -21,3 +21,26 @@
*/
#include "uilayout.h"
#include <framework/core/eventdispatcher.h>
void UILayout::update()
{
assert(!m_updating);
m_updating = true;
internalUpdate();
m_updating = false;
}
void UILayout::updateLater()
{
if(m_updateScheduled)
return;
auto self = asUILayout();
g_dispatcher.addEvent([self] {
self->m_updateScheduled = false;
self->update();
});
m_updateScheduled = true;
}

View File

@@ -32,16 +32,27 @@ class UILayout : public LuaObject
public:
UILayout(UIWidgetPtr parentWidget) : m_parentWidget(parentWidget) { }
void update();
void updateLater();
virtual void applyStyle(const OTMLNodePtr& styleNode) { }
virtual void update() = 0;
virtual void addWidget(const UIWidgetPtr& widget) = 0;
virtual void removeWidget(const UIWidgetPtr& widget) = 0;
UIWidgetPtr getParentWidget() { return m_parentWidget.lock(); }
bool isUpdating() { return m_updating; }
virtual bool needsUpdatesOnChildChange() { return false; }
UILayoutPtr asUILayout() { return std::static_pointer_cast<UILayout>(shared_from_this()); }
virtual UIAnchorLayoutPtr asUIAnchorLayout() { return nullptr; }
virtual UIVerticalLayoutPtr asUIVerticalLayout() { return nullptr; }
protected:
virtual void internalUpdate() = 0;
Boolean<false> m_updating;
Boolean<false> m_updateScheduled;
UIWidgetWeakPtr m_parentWidget;
};

View File

@@ -23,12 +23,11 @@
#include "uiverticallayout.h"
#include "uiwidget.h"
#include <framework/otml/otml.h>
#include <framework/core/eventdispatcher.h>
UIVerticalLayout::UIVerticalLayout(UIWidgetPtr parentWidget)
: UILayout(parentWidget)
{
m_alignBottom = false;
m_fitParent = false;
m_spacing = 0;
}
@@ -46,7 +45,36 @@ void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
}
}
void UIVerticalLayout::update()
void UIVerticalLayout::addWidget(const UIWidgetPtr& widget)
{
update();
}
void UIVerticalLayout::removeWidget(const UIWidgetPtr& widget)
{
update();
}
void UIVerticalLayout::setAlignBottom(bool aliginBottom)
{
m_alignBottom = aliginBottom;
update();
}
void UIVerticalLayout::setSpacing(int spacing)
{
m_spacing = spacing;
update();
}
void UIVerticalLayout::setFitParent(bool fitParent)
{
m_fitParent = fitParent;
update();
}
void UIVerticalLayout::internalUpdate()
{
UIWidgetPtr parentWidget = getParentWidget();
UIWidgetList widgets = parentWidget->getChildren();
@@ -88,34 +116,10 @@ void UIVerticalLayout::update()
prefferedHeight -= m_spacing;
if(m_fitParent && prefferedHeight != parentWidget->getHeight())
parentWidget->setHeight(prefferedHeight);
}
void UIVerticalLayout::addWidget(const UIWidgetPtr& widget)
{
update();
}
void UIVerticalLayout::removeWidget(const UIWidgetPtr& widget)
{
update();
}
void UIVerticalLayout::setAlignBottom(bool aliginBottom)
{
m_alignBottom = aliginBottom;
update();
}
void UIVerticalLayout::setSpacing(int spacing)
{
m_spacing = spacing;
update();
}
void UIVerticalLayout::setFitParent(bool fitParent)
{
m_fitParent = fitParent;
update();
}
if(m_fitParent && prefferedHeight != parentWidget->getHeight()) {
// must set the preffered width later
g_dispatcher.addEvent([=] {
parentWidget->setHeight(prefferedHeight);
});
}
}

View File

@@ -30,18 +30,24 @@ class UIVerticalLayout : public UILayout
public:
UIVerticalLayout(UIWidgetPtr parentWidget);
virtual void applyStyle(const OTMLNodePtr& styleNode);
virtual void update();
virtual void addWidget(const UIWidgetPtr& widget);
virtual void removeWidget(const UIWidgetPtr& widget);
void applyStyle(const OTMLNodePtr& styleNode);
void addWidget(const UIWidgetPtr& widget);
void removeWidget(const UIWidgetPtr& widget);
void setAlignBottom(bool aliginBottom);
void setSpacing(int spacing);
void setFitParent(bool fitParent);
bool needsUpdatesOnChildChange() { return m_fitParent; }
UIVerticalLayoutPtr asUIVerticalLayout() { return std::static_pointer_cast<UIVerticalLayout>(shared_from_this()); }
protected:
void internalUpdate();
private:
bool m_alignBottom;
bool m_fitParent;
Boolean<false> m_alignBottom;
Boolean<false> m_fitParent;
int m_spacing;
};

View File

@@ -54,6 +54,9 @@ UIWidget::UIWidget()
void UIWidget::destroy()
{
if(m_destroyed)
logWarning("attempt to destroy widget '", m_id, "' two times");
setVisible(false);
setEnabled(false);
@@ -71,6 +74,8 @@ void UIWidget::destroy()
}
callLuaField("onDestroy");
m_destroyed = true;
}
void UIWidget::render()
@@ -289,7 +294,8 @@ void UIWidget::setRect(const Rect& rect)
UIWidgetPtr self = asUIWidget();
g_dispatcher.addEvent([self, oldRect]() {
self->m_updateEventScheduled = false;
self->onGeometryChange(oldRect, self->getRect());
if(oldRect != self->getRect())
self->onGeometryChange(oldRect, self->getRect());
});
m_updateEventScheduled = true;
}
@@ -777,6 +783,11 @@ void UIWidget::updateLayout()
{
if(m_layout)
m_layout->update();
// children can affect the parent layout
if(UIWidgetPtr parent = getParent())
if(UILayoutPtr parentLayout = parent->getLayout())
parentLayout->updateLater();
}
void UIWidget::applyStyle(const OTMLNodePtr& styleNode)

View File

@@ -120,6 +120,7 @@ public:
bool isFocusable() { return m_focusable; }
bool isPhantom() { return m_phantom; }
bool isSizeFixed() { return m_fixedSize; }
bool isDestroyed() { return m_destroyed; }
bool containsPoint(const Point& point) { return m_rect.contains(point); }
bool hasChildren() { return m_children.size() > 0; }
bool hasChild(const UIWidgetPtr& child);
@@ -230,6 +231,7 @@ protected:
Boolean<false> m_loadingStyle;
Boolean<false> m_updateStyleScheduled;
Boolean<true> m_firstOnStyle;
Boolean<false> m_destroyed;
Rect m_rect;
UILayoutPtr m_layout;
UIWidgetWeakPtr m_parent;

View File

@@ -83,7 +83,8 @@ void UIWindow::onStyleApply(const std::string& styleName, const OTMLNodePtr& sty
void UIWindow::onGeometryChange(const Rect& oldRect, const Rect& newRect)
{
bindRectToParent();
UIWidget::onGeometryChange(oldRect, newRect);
if(newRect == getRect())
UIWidget::onGeometryChange(oldRect, newRect);
}
bool UIWindow::onMousePress(const Point& mousePos, Fw::MouseButton button)

View File

@@ -27,7 +27,7 @@
bool UIGame::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers)
{
UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("chatLineEdit"));
UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("consoleLineEdit"));
if(keyboardModifiers == Fw::KeyboardNoModifier) {
if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {