xmlgui::Control *xmlgui::Control::clone() { Control *c = INSTANTIATE(type); c->name = name; c->id = id; c->x = x; c->y = y; c->width = width; c->height = height; // parentInfo and parameterInfo will be identical except // for the pointers vector<ParameterInfo> parameterInfo; c->getParameterInfo(parameterInfo); vector<ParameterInfo> parentInfo; getParameterInfo(parentInfo); // this is the parameter info for the cloned control for(int i = 0; i < parameterInfo.size(); i++) { // this writer writes to the pointer pointing into the // attribute of the cloned control Control *writer = INSTANTIATE(parameterInfo[i].type); writer->pointToValue(parameterInfo[i].value); Control *reader = INSTANTIATE(parentInfo[i].type); reader->pointToValue(parentInfo[i].value); writer->valueFromString(reader->valueToString()); delete reader; delete writer; } c->load(); return c; }
void xmlgui::Control::saveToXmlObject(ofxXmlSettings &xml) { // create tag, xml.addTag(type); // know which tag we are in case there's multiples int which = xml.getNumTags(type) - 1; xml.addAttribute(type, "name", name, which); xml.addAttribute(type, "id", id, which); xml.addAttribute(type, "x", x, which); xml.addAttribute(type, "y", y, which); xml.addAttribute(type, "width", width, which); xml.addAttribute(type, "height", height, which); vector<ParameterInfo> parameterInfo; getParameterInfo(parameterInfo); for(int i = 0; i < parameterInfo.size(); i++) { Control *c = INSTANTIATE(parameterInfo[i].type); c->pointToValue(parameterInfo[i].value); xml.addAttribute(type, parameterInfo[i].xmlName, c->valueToString(), which); delete c; } }
void xmlgui::Control::loadFromXmlObject(TiXmlElement *xml) { // take all the base settings from this element name = xml->Attribute("name"); id = xml->Attribute("id"); xml->QueryFloatAttribute("x", &x); xml->QueryFloatAttribute("y", &y); xml->QueryFloatAttribute("width", &width); xml->QueryFloatAttribute("height", &height); // then take all the "parameterinfo" from it vector<ParameterInfo> parameterInfo; getParameterInfo(parameterInfo); for(int i = 0; i < parameterInfo.size(); i++) { Control *c = INSTANTIATE(parameterInfo[i].type); c->pointToValue(parameterInfo[i].value); c->valueFromString(string(xml->Attribute(parameterInfo[i].xmlName.c_str()))); delete c; } load(); }
void xmlgui::Control::loadFromXmlObject(TiXmlElement *xml) { // take all the base settings from this element name = xml->Attribute("name"); id = xml->Attribute("id"); xml->QueryFloatAttribute("x", &x); xml->QueryFloatAttribute("y", &y); xml->QueryFloatAttribute("width", &width); xml->QueryFloatAttribute("height", &height); // then take all the "parameterinfo" from it vector<ParameterInfo> parameterInfo; getParameterInfo(parameterInfo); //printf("Got %d params in %s\n", parameterInfo.size(), name.c_str()); for(int i = 0; i < parameterInfo.size(); i++) { //printf("Param: %s\n", parameterInfo[i].name.c_str()); //printf("Type: %s\n", parameterInfo[i].type.c_str()); Control *c = INSTANTIATE(parameterInfo[i].type); c->pointToValue(parameterInfo[i].value); const char *vv = xml->Attribute(parameterInfo[i].xmlName.c_str()); if(vv!=NULL) { string val = string(vv); // printf("val: %s\n", val.c_str()); c->valueFromString(string(xml->Attribute(parameterInfo[i].xmlName.c_str()))); } else { ofLogError() <<"No default value for "<<parameterInfo[i].name<<" in "<<name; } delete c; } load(); }