Deduplicate child element parsing in DialogXML
This commit is contained in:
@@ -415,6 +415,35 @@ void cDialog::loadFromFile(std::string path){
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Move to a dedicated container.cpp?
|
||||
bool cContainer::parseChildControl(ticpp::Element& elem, std::map<std::string,cControl*>& controls) {
|
||||
std::string tag = elem.Value();
|
||||
if(tag == "field") {
|
||||
auto field = parent->parse<cTextField>(elem);
|
||||
controls.insert(field);
|
||||
parent->tabOrder.push_back(field);
|
||||
} else if(tag == "text") {
|
||||
auto text = parent->parse<cTextMsg>(elem);
|
||||
controls.insert(text);
|
||||
} else if(tag == "pict") {
|
||||
auto pict = parent->parse<cPict>(elem);
|
||||
controls.insert(pict);
|
||||
} else if(tag == "slider") {
|
||||
auto slide = parent->parse<cScrollbar>(elem);
|
||||
controls.insert(slide);
|
||||
} else if(tag == "button") {
|
||||
auto button = parent->parse<cButton>(elem);
|
||||
controls.insert(button);
|
||||
} else if(tag == "led") {
|
||||
auto led = parent->parse<cLed>(elem);
|
||||
controls.insert(led);
|
||||
} else if(tag == "group") {
|
||||
auto group = parent->parse<cLedGroup>(elem);
|
||||
controls.insert(group);
|
||||
} else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void cDialog::recalcRect(){
|
||||
bool haveRel = false;
|
||||
for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++) {
|
||||
|
@@ -224,6 +224,7 @@ private:
|
||||
std::string fname;
|
||||
sf::Clock animTimer, paintTimer;
|
||||
friend class cControl;
|
||||
friend class cContainer;
|
||||
};
|
||||
|
||||
/// Thrown when an invalid node (element or text/cdata) is found while parsing an XML dialog definition.
|
||||
|
@@ -454,6 +454,12 @@ private:
|
||||
class cContainer : public cControl {
|
||||
void callHandler(event_fcn<EVT_CLICK>::type onClick, cDialog& me, std::string id, eKeyMod mods) override;
|
||||
std::string clicking;
|
||||
protected:
|
||||
/// Parses a child control.
|
||||
/// @param elem The element defining the control.
|
||||
/// @param controls The map into which the control will be inserted.
|
||||
/// @return true if the element was a valid control, false otherwise.
|
||||
bool parseChildControl(ticpp::Element& elem, std::map<std::string,cControl*>& controls);
|
||||
public:
|
||||
/// Create a new container control attached to an arbitrary window, rather than a dialog.
|
||||
/// @param t The type of the control.
|
||||
|
@@ -185,33 +185,7 @@ bool cScrollPane::parseAttribute(ticpp::Attribute& attr, std::string tagName, st
|
||||
|
||||
bool cScrollPane::parseContent(ticpp::Node& content, int n, std::string tagName, std::string fname, std::string& text) {
|
||||
if(content.Type() == TiXmlNode::ELEMENT) {
|
||||
std::string tag = content.Value();
|
||||
auto& elem = dynamic_cast<ticpp::Element&>(content);
|
||||
if(tag == "field") {
|
||||
auto field = parent->parse<cTextField>(elem);
|
||||
contents.insert(field);
|
||||
// TODO: Add field to tab order
|
||||
//tabOrder.push_back(field);
|
||||
} else if(tag == "text") {
|
||||
auto text = parent->parse<cTextMsg>(elem);
|
||||
contents.insert(text);
|
||||
} else if(tag == "pict") {
|
||||
auto pict = parent->parse<cPict>(elem);
|
||||
contents.insert(pict);
|
||||
} else if(tag == "slider") {
|
||||
auto slide = parent->parse<cScrollbar>(elem);
|
||||
contents.insert(slide);
|
||||
} else if(tag == "button") {
|
||||
auto button = parent->parse<cButton>(elem);
|
||||
contents.insert(button);
|
||||
} else if(tag == "led") {
|
||||
auto led = parent->parse<cLed>(elem);
|
||||
contents.insert(led);
|
||||
} else if(tag == "group") {
|
||||
auto group = parent->parse<cLedGroup>(elem);
|
||||
contents.insert(group);
|
||||
} else throw xBadNode(tag, content.Row(), content.Column(), fname);
|
||||
return true;
|
||||
return parseChildControl(dynamic_cast<ticpp::Element&>(content), contents);
|
||||
}
|
||||
return cContainer::parseContent(content, n, tagName, fname, text);
|
||||
}
|
||||
|
@@ -168,33 +168,7 @@ bool cStack::parseAttribute(ticpp::Attribute& attr, std::string tagName, std::st
|
||||
|
||||
bool cStack::parseContent(ticpp::Node& content, int n, std::string tagName, std::string fname, std::string& text) {
|
||||
if(content.Type() == TiXmlNode::ELEMENT) {
|
||||
std::string tag = content.Value();
|
||||
auto& elem = dynamic_cast<ticpp::Element&>(content);
|
||||
if(tag == "field") {
|
||||
auto field = parent->parse<cTextField>(elem);
|
||||
controls.insert(field);
|
||||
// TODO: Add field to tab order
|
||||
//tabOrder.push_back(field);
|
||||
} else if(tag == "text") {
|
||||
auto text = parent->parse<cTextMsg>(elem);
|
||||
controls.insert(text);
|
||||
} else if(tag == "pict") {
|
||||
auto pict = parent->parse<cPict>(elem);
|
||||
controls.insert(pict);
|
||||
} else if(tag == "slider") {
|
||||
auto slide = parent->parse<cScrollbar>(elem);
|
||||
controls.insert(slide);
|
||||
} else if(tag == "button") {
|
||||
auto button = parent->parse<cButton>(elem);
|
||||
controls.insert(button);
|
||||
} else if(tag == "led") {
|
||||
auto led = parent->parse<cLed>(elem);
|
||||
controls.insert(led);
|
||||
} else if(tag == "group") {
|
||||
auto group = parent->parse<cLedGroup>(elem);
|
||||
controls.insert(group);
|
||||
} else throw xBadNode(tag, content.Row(), content.Column(), fname);
|
||||
return true;
|
||||
return parseChildControl(dynamic_cast<ticpp::Element&>(content), controls);
|
||||
}
|
||||
return cContainer::parseContent(content, n, tagName, fname, text);
|
||||
}
|
||||
|
Reference in New Issue
Block a user