WidgetInfo ResourceLayout::parseWidget(xml::ElementEnumerator& _widget) { WidgetInfo widgetInfo; std::string tmp; _widget->findAttribute("type", widgetInfo.type); _widget->findAttribute("skin", widgetInfo.skin); _widget->findAttribute("layer", widgetInfo.layer); if (_widget->findAttribute("align", tmp)) widgetInfo.align = Align::parse(tmp); _widget->findAttribute("name", widgetInfo.name); if (_widget->findAttribute("style", tmp)) widgetInfo.style = WidgetStyle::parse(tmp); IntCoord coord; if (_widget->findAttribute("position", tmp)) { widgetInfo.intCoord = IntCoord::parse(tmp); widgetInfo.positionType = WidgetInfo::Pixels; } else if (_widget->findAttribute("position_real", tmp)) { widgetInfo.floatCoord = FloatCoord::parse(tmp); widgetInfo.positionType = WidgetInfo::Relative; } // берем детей и крутимся xml::ElementEnumerator node = _widget->getElementEnumerator(); while (node.next()) { if (node->getName() == "Widget") { widgetInfo.childWidgetsInfo.push_back(parseWidget(node)); } else if (node->getName() == "Property") { widgetInfo.properties.push_back(PairString(node->findAttribute("key"), node->findAttribute("value"))); } else if (node->getName() == "UserString") { widgetInfo.userStrings[node->findAttribute("key")] = node->findAttribute("value"); } else if (node->getName() == "Controller") { ControllerInfo controllerInfo; controllerInfo.type = node->findAttribute("type"); xml::ElementEnumerator prop = node->getElementEnumerator(); while (prop.next("Property")) { controllerInfo.properties[prop->findAttribute("key")] = prop->findAttribute("value"); } } } return widgetInfo; }
void parseWidget(vstdom *dom, widget *wid) { std::string einrueckung; int a = 0; while( a < depth) { einrueckung += "|"; a++; } einrueckung += " "; // Ausgabe eineindeutige ID cout << endl << einrueckung.c_str() << " Widget ID " << wid->_iId; cout << endl << einrueckung.c_str(); // Ausgabe der Properties cout << endl << einrueckung.c_str() << " Properties"; cout << endl << einrueckung.c_str() << " width " << wid->_iWidth; cout << endl << einrueckung.c_str() << " height " << wid->_iHeight; cout << endl << einrueckung.c_str() << " xCoord " << wid->_iXCoord; cout << endl << einrueckung.c_str() << " yCoord " << wid->_iYCoord; cout << endl << einrueckung.c_str() << " title " << (wid->_sTitle).c_str(); cout << endl << einrueckung.c_str() << " text " << (wid->_sText).c_str(); cout << endl << einrueckung.c_str() << " editable " << wid->_bEditable; cout << endl << einrueckung.c_str() << " checked " << wid->_bchecked; cout << endl << einrueckung.c_str() << " Callback " << wid->_iCallbackId; cout << endl << einrueckung.c_str(); switch( wid->_eWidgetType) { case kwindow: { cout << "\n## window gefunden"; break; } case kbutton: { cout << "\n## button gefunden"; } } // Rekursiv über alle Childs cout << endl << einrueckung.c_str() << " " << wid->_iId << " hat " << wid->_vChildWidgets.size() << " Childwidgets."; for( int i = 0; i < wid->_vChildWidgets.size(); i++) { cout << endl << einrueckung.c_str(); cout << endl << einrueckung.c_str() << i << ". Childwidget von " << wid->_iId << " ist " << wid->_vChildWidgets.at(i); widget *childwidget = dom->getWidget( wid->_vChildWidgets.at(i)); if( childwidget != NULL) { depth++; parseWidget(dom, childwidget); depth--; } } }
void ResourceLayout::deserialization(xml::ElementPtr _node, Version _version) { Base::deserialization(_node, _version); mLayoutData.clear(); xml::ElementEnumerator widget = _node->getElementEnumerator(); while (widget.next("Widget")) mLayoutData.push_back(parseWidget(widget)); }
void EditorWidgets::loadxmlDocument(MyGUI::xml::xmlDocument * doc) { MyGUI::xml::xmlNodePtr root = doc->getRoot(); std::string type; if (root->findAttribute("type", type)) { if (type == "Layout") { // берем детей и крутимся MyGUI::xml::xmlNodeIterator widget = root->getNodeIterator(); while (widget.nextNode("Widget")) parseWidget(widget, 0); } } }
bool EditorWidgets::load(std::string _fileName) { std::string _instance = "Editor"; MyGUI::xml::xmlDocument doc; std::string file(MyGUI::helper::getResourcePath(_fileName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)); if (file.empty()) { if (false == doc.open(_fileName)) { LOGGING(LogSection, Error, _instance << " : '" << _fileName << "' not found"); return false; } } else if (false == doc.open(file)) { LOGGING(LogSection, Error, _instance << " : " << doc.getLastError()); return false; } MyGUI::xml::xmlNodePtr root = doc.getRoot(); if ( (null == root) || (root->getName() != "MyGUI") ) { LOGGING(LogSection, Error, _instance << " : '" << _fileName << "', tag 'MyGUI' not found"); return false; } std::string type; if (root->findAttribute("type", type)) { if (type == "Layout") { // берем детей и крутимся MyGUI::xml::xmlNodeIterator widget = root->getNodeIterator(); while (widget.nextNode("Widget")) parseWidget(widget, 0); } } return true; }
void EditorWidgets::parseWidget(MyGUI::xml::xmlNodeIterator & _widget, MyGUI::WidgetPtr _parent) { WidgetContainer * container = new WidgetContainer(); // парсим атрибуты виджета MyGUI::IntCoord coord; MyGUI::Align align = MyGUI::ALIGN_DEFAULT; _widget->findAttribute("name", container->name); _widget->findAttribute("type", container->type); _widget->findAttribute("skin", container->skin); _widget->findAttribute("layer", container->layer); if (_widget->findAttribute("align", container->align)) align = MyGUI::SkinManager::getInstance().parseAlign(container->align); if (_widget->findAttribute("position", container->position)) coord = MyGUI::IntCoord::parse(container->position); if (_widget->findAttribute("position_real", container->position_real)) coord = MyGUI::Gui::getInstance().convertRelativeToInt(MyGUI::FloatCoord::parse(container->position_real), _parent); // в гуе на 2 одноименных виджета ругается и падает, а у нас будет просто переименовывать if (false == container->name.empty()) { WidgetContainer * iter = find(container->name); if (null != iter) { LOGGING(LogSection, Warning, "widget with same name name '" << container->name << "'. Renamed"); static long renameN=0; container->name = MyGUI::utility::toString(container->name, renameN++); } } std::string tmpname = container->name; if (tmpname.empty()) { tmpname = MyGUI::utility::toString(container->type, global_counter); global_counter++; } //может и не стоит tmpname = "LayoutEditor_" + tmpname; if (null == _parent) { container->widget = MyGUI::Gui::getInstance().createWidgetT(container->type, container->skin, coord, align, container->layer, tmpname); add(container); } else { container->widget = _parent->createWidgetT(container->type, container->skin, coord, align, tmpname); add(container); } // берем детей и крутимся MyGUI::xml::xmlNodeIterator widget = _widget->getNodeIterator(); while (widget.nextNode()) { std::string key, value; if (widget->getName() == "Widget") parseWidget(widget, container->widget); else if (widget->getName() == "Property") { // парсим атрибуты if (false == widget->findAttribute("key", key)) continue; if (false == widget->findAttribute("value", value)) continue; // и парсим свойство if (("Message_Modal" != key) && ("Window_AutoAlpha" != key)) MyGUI::WidgetManager::getInstance().parse(container->widget, key, value); container->mProperty.push_back(std::make_pair(key, value)); } else if (widget->getName() == "UserString") { // парсим атрибуты if (false == widget->findAttribute("key", key)) continue; if (false == widget->findAttribute("value", value)) continue; container->mUserString.insert(std::make_pair(key, value)); } }; }
void EditorWidgets::parseWidget(MyGUI::xml::xmlNodeIterator & _widget, MyGUI::WidgetPtr _parent) { WidgetContainer * container = new WidgetContainer(); // парсим атрибуты виджета MyGUI::IntCoord coord; MyGUI::Align align = MyGUI::ALIGN_DEFAULT; _widget->findAttribute("name", container->name); _widget->findAttribute("type", container->type); _widget->findAttribute("skin", container->skin); _widget->findAttribute("layer", container->layer); if (_widget->findAttribute("align", container->align)) align = MyGUI::SkinManager::getInstance().parseAlign(container->align); if (_widget->findAttribute("position", container->position)) coord = MyGUI::IntCoord::parse(container->position); if (_widget->findAttribute("position_real", container->position_real)) coord = MyGUI::Gui::getInstance().convertRelativeToInt(MyGUI::FloatCoord::parse(container->position_real), _parent); // в гуе на 2 одноименных виджета ругается и падает, а у нас будет просто переименовывать if (false == container->name.empty()) { WidgetContainer * iter = find(container->name); if (null != iter) { static long renameN=0; std::string mess = MyGUI::utility::toString("widget with same name name '", container->name, "'. Renamed to '", container->name, renameN, "'."); LOGGING(LogSection, Warning, mess); MyGUI::Message::_createMessage("Warning", mess, "", "LayoutEditor_Popup", true, null, MyGUI::Message::IconWarning | MyGUI::Message::Ok); container->name = MyGUI::utility::toString(container->name, renameN++); } } std::string tmpname = container->name; if (tmpname.empty()) { tmpname = MyGUI::utility::toString(container->type, global_counter); global_counter++; } //может и не стоит tmpname = "LayoutEditor_" + tmpname; if (null == _parent) { container->widget = MyGUI::Gui::getInstance().createWidgetT(container->type, container->skin, coord, align, container->layer, tmpname); add(container); } else { container->widget = _parent->createWidgetT(container->type, container->skin, coord, align, tmpname); add(container); } // берем детей и крутимся MyGUI::xml::xmlNodeIterator widget = _widget->getNodeIterator(); while (widget.nextNode()) { std::string key, value; if (widget->getName() == "Widget") parseWidget(widget, container->widget); else if (widget->getName() == "Property") { // парсим атрибуты if (false == widget->findAttribute("key", key)) continue; if (false == widget->findAttribute("value", value)) continue; // и парсим свойство try{ if (("Message_Modal" != key) && ("Window_AutoAlpha" != key) && ("Window_Snap" != key)) MyGUI::WidgetManager::getInstance().parse(container->widget, key, value); Ogre::Root::getSingleton().renderOneFrame(); } catch(...) { MyGUI::Message::_createMessage("Warning", "No such " + key + ": '" + value + "'", "", "LayoutEditor_Popup", true, null, MyGUI::Message::IconWarning | MyGUI::Message::Ok); if (key == "Image_Texture") MyGUI::WidgetManager::getInstance().parse(container->widget, key, ""); }// for incorrect meshes or textures container->mProperty.push_back(std::make_pair(key, value)); } else if (widget->getName() == "UserString") { // парсим атрибуты if (false == widget->findAttribute("key", key)) continue; if (false == widget->findAttribute("value", value)) continue; container->mUserString.insert(std::make_pair(key, value)); } }; }
int main( int argC, char *argV[]) { // vstdom mit xml file initiieren vstdom *testvstdom = new vstdom("xml/formular_test.xml"); // vstdom *testvstdom = new vstdom("xml/beispiel.xml"); // leere Instanz von vstdom erzeugen vstdom *testnew = new vstdom(); // Anzahl der root Elemente ermitteln cout << endl << "Anzahl der root Widget " << testvstdom->getNumberOfChildWidget() << endl; // Schleife ueber alle root Elemente for( int i = 0; i < testvstdom->getNumberOfChildWidget(); i++) { // root Element einem widget zuordnen widget *rootwidget = testvstdom->getWidget(testvstdom->getIdOfRootWidget(i)); // Ausgabe der Attribute und Proberties aller Elemente (rekursiv) parseWidget(testvstdom, rootwidget); } // definiere neues Widget widget updatedWidget; updatedWidget._iId = 8; updatedWidget._eWidgetType = kbutton; updatedWidget._iWidth = 100; updatedWidget._iHeight = 50; updatedWidget._iXCoord = 10; updatedWidget._iYCoord = 10; updatedWidget._sText = "geänderter Text"; updatedWidget._bEditable = true; // uebertrage geaendertes Widget testvstdom->updateWidget( updatedWidget, updatedWidget._iId); widget newWidget; newWidget._eWidgetType = kwindow; newWidget._iId = 88; newWidget._iCallbackId = 120; newWidget._iHeight = 43; newWidget._iWidth = 66; newWidget._iXCoord = 5; newWidget._iYCoord = 7; newWidget._bchecked = true; newWidget._bIsScrollable = false; newWidget._bEditable = true; newWidget._sMnemonic = "Alt-Q"; newWidget._sTitle = "Keine Ahnung"; newWidget._sText = "Text-O-Text"; // testvstdom->addWidget(newWidget); testnew->addWidget(newWidget); widget newWidgetZwei; newWidgetZwei._eWidgetType = klabel; newWidgetZwei._iId = 10; newWidgetZwei._iCallbackId = 12; newWidgetZwei._iHeight = 4; newWidgetZwei._iWidth = 6; newWidgetZwei._iXCoord = 52; newWidgetZwei._iYCoord = 72; newWidgetZwei._bchecked = true; newWidgetZwei._bIsScrollable = false; newWidgetZwei._bEditable = true; newWidgetZwei._sMnemonic = "Alt-Q"; newWidgetZwei._sTitle = "Label Text"; newWidgetZwei._sText = "Text-O-Text"; testvstdom->addWidget(newWidgetZwei, 88); // schreibe neues xml File testvstdom->writexml( "neues_xml.xml"); testnew->writexml("newxml.xml"); delete testvstdom; cout << "\n" << flush; return 0; }