From ce3b02fa098a746b7528d7f9d346f979e7ce45b6 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 13 Nov 2011 02:13:07 -0200 Subject: [PATCH] add menu example in playerground module --- modules/core_styles/images/menu.png | Bin 0 -> 262 bytes modules/playground/filemenu.otui | 10 ++++++++ modules/playground/menubar.otui | 29 ++++++++++++++++++++++ modules/playground/playground.lua | 11 +++++++- src/framework/luascript/luafunctions.cpp | 3 +++ src/framework/luascript/luavaluecasts.cpp | 23 +++++++++++++++++ src/framework/luascript/luavaluecasts.h | 1 + src/framework/ui/uiwidget.cpp | 15 ++++++----- 8 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 modules/core_styles/images/menu.png create mode 100644 modules/playground/filemenu.otui create mode 100644 modules/playground/menubar.otui diff --git a/modules/core_styles/images/menu.png b/modules/core_styles/images/menu.png new file mode 100644 index 0000000000000000000000000000000000000000..d7e283027911dbb3ada1368aa0fe4d3ad4de4791 GIT binary patch literal 262 zcmeAS@N?(olHy`uVBq!ia0vp^4nS{XE)7O>#HaCyB0OQ*B`0GF++02lL66gHf z+|;}hAeVu`xhOTUBsE2$JhLQ2!QIn0AVn{g9Vi~_>EalYaqsO-M@9w#5mv`|5%uz? zQ!cpKH|@E}QG8dbc&}JY{zFEv85l&vlC1f!xiN%c0+O|=r7V+qj<+j("getSize", &UIWidget::getSize); g_lua.bindClassMemberFunction("setSize", &UIWidget::resize); g_lua.bindClassMemberFunction("getPosition", &UIWidget::getPosition); + g_lua.bindClassMemberFunction("getX", &UIWidget::getX); + g_lua.bindClassMemberFunction("getY", &UIWidget::getY); g_lua.bindClassMemberFunction("moveTo", &UIWidget::moveTo); g_lua.bindClassMemberFunction("moveChildToIndex", &UIWidget::moveChildToIndex); g_lua.bindClassMemberFunction("getParent", &UIWidget::getParent); @@ -59,6 +61,7 @@ void LuaInterface::registerFunctions() g_lua.bindClassMemberFunction("getOpacity", &UIWidget::getOpacity); g_lua.bindClassMemberFunction("setOpacity", &UIWidget::setOpacity); g_lua.bindClassMemberFunction("setStyle", &UIWidget::setStyle); + g_lua.bindClassMemberFunction("applyStyle", &UIWidget::applyStyle); g_lua.bindClassMemberFunction("getStyle", &UIWidget::getStyle); g_lua.bindClassMemberFunction("getMarginTop", &UIWidget::getMarginTop); g_lua.bindClassMemberFunction("setMarginTop", &UIWidget::setMarginTop); diff --git a/src/framework/luascript/luavaluecasts.cpp b/src/framework/luascript/luavaluecasts.cpp index a285bd8b..20f24b86 100644 --- a/src/framework/luascript/luavaluecasts.cpp +++ b/src/framework/luascript/luavaluecasts.cpp @@ -252,6 +252,29 @@ void push_luavalue(const OTMLNodePtr& node) g_lua.pushNil(); } +bool luavalue_cast(int index, OTMLNodePtr& node) +{ + node = OTMLNode::create(); + node->setUnique(true); + if(g_lua.isTable(index)) { + g_lua.pushNil(); + while(g_lua.next(index < 0 ? index-1 : index)) { + std::string cnodeName = g_lua.toString(-2); + if(g_lua.isTable()) { + OTMLNodePtr cnode; + if(luavalue_cast(-1, node)) { + cnode->setTag(cnodeName); + node->addChild(cnode); + } + } else + node->writeAt(cnodeName, g_lua.toString()); + g_lua.pop(); + } + } else + return false; + return true; +} + // object ptr bool luavalue_cast(int index, LuaObjectPtr& obj) { if(g_lua.isUserdata(index)) { diff --git a/src/framework/luascript/luavaluecasts.h b/src/framework/luascript/luavaluecasts.h index f4c3abe8..124f6f40 100644 --- a/src/framework/luascript/luavaluecasts.h +++ b/src/framework/luascript/luavaluecasts.h @@ -70,6 +70,7 @@ bool luavalue_cast(int index, Size& size); // otml nodes void push_luavalue(const OTMLNodePtr& node); +bool luavalue_cast(int index, OTMLNodePtr& node); // enum template diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index d167ea56..dc6417ef 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -75,8 +75,10 @@ void UIWidget::setup() void UIWidget::destroy() { // remove itself from parent - if(UIWidgetPtr parent = getParent()) - parent->removeChild(asUIWidget()); + if(UIWidgetPtr parent = getParent()) { + if(parent->hasChild(asUIWidget())) + parent->removeChild(asUIWidget()); + } setVisible(false); setEnabled(false); } @@ -680,10 +682,10 @@ void UIWidget::updateState(Fw::WidgetState state) updateStyle(); - if(state == Fw::FocusState) - onFocusChange(newStatus, m_lastFocusReason); - else if(state == Fw::HoverState) - onHoverChange(newStatus); + if(state == Fw::FocusState) { + g_dispatcher.addEvent(std::bind(&UIWidget::onFocusChange, asUIWidget(), newStatus, m_lastFocusReason)); + } else if(state == Fw::HoverState) + g_dispatcher.addEvent(std::bind(&UIWidget::onHoverChange, asUIWidget(), newStatus)); } } @@ -884,6 +886,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode) anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge); } } else if(node->tag() == "onClick" || + node->tag() == "onMousePress" || node->tag() == "onHoverChange") { g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]"); luaSetField(node->tag());