new lua function for creating widgets: createWidget

This commit is contained in:
Eduardo Bart
2012-01-02 22:42:53 -02:00
parent 9fbdf3f5cb
commit 05230f44e4
29 changed files with 137 additions and 120 deletions

View File

@@ -81,7 +81,7 @@ void UIManager::inputEvent(const InputEvent& event)
};
}
bool UIManager::importStyles(const std::string& file)
bool UIManager::importStyle(const std::string& file)
{
try {
OTMLDocumentPtr doc = OTMLDocument::parse(file);
@@ -135,13 +135,21 @@ OTMLNodePtr UIManager::getStyle(const std::string& styleName)
// styles starting with UI are automatically defined
if(boost::starts_with(styleName, "UI")) {
OTMLNodePtr node = OTMLNode::create();
node->writeAt("__widgetType", styleName);
node->writeAt("__class", styleName);
return node;
}
return nullptr;
}
std::string UIManager::getStyleClass(const std::string& styleName)
{
OTMLNodePtr style = getStyle(styleName);
if(style && style->get("__class"))
return style->valueAt("__class");
return "";
}
UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent)
{
try {
@@ -176,7 +184,7 @@ UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const U
OTMLNodePtr styleNode = originalStyleNode->clone();
styleNode->merge(widgetNode);
std::string widgetType = styleNode->valueAt("__widgetType");
std::string widgetType = styleNode->valueAt("__class");
// call widget creation from lua
UIWidgetPtr widget = g_lua.callGlobalField<UIWidgetPtr>(widgetType, "create");

View File

@@ -37,9 +37,10 @@ public:
void resize(const Size& size);
void inputEvent(const InputEvent& event);
bool importStyles(const std::string& file);
bool importStyle(const std::string& file);
void importStyleFromOTML(const OTMLNodePtr& styleNode);
OTMLNodePtr getStyle(const std::string& styleName);
std::string getStyleClass(const std::string& styleName);
UIWidgetPtr loadUI(const std::string& file, const UIWidgetPtr& parent = nullptr);
UIWidgetPtr loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent);