MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / parseElement

Method parseElement

src/server/gui/core/ThemeData.cpp:426–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

424
425
426void ThemeData::parseElement(const pugi::xml_node& root, const std::map<std::string, ElementPropertyType>& typeMap, ThemeElement& element)
427{
428 ThemeException error;
429 error.setFiles(mPaths);
430
431 element.type = root.name();
432 element.extra = root.attribute("extra").as_bool(false);
433
434 for(pugi::xml_node node = root.first_child(); node; node = node.next_sibling())
435 {
436 auto typeIt = typeMap.find(node.name());
437 if(typeIt == typeMap.cend())
438 throw error << "Unknown property type \"" << node.name() << "\" (for element of type " << root.name() << ").";
439
440 std::string str = resolvePlaceholders(node.text().as_string());
441
442 switch(typeIt->second)
443 {
444 case RESOLUTION_RECT:
445 {
446 Vector4f val;
447
448 auto splits = Utils::String::delimitedStringToVector(str, " ");
449 if (splits.size() == 2)
450 {
451 val = Vector4f((float)atof(splits.at(0).c_str()), (float)atof(splits.at(1).c_str()),
452 (float)atof(splits.at(0).c_str()), (float)atof(splits.at(1).c_str()));
453 }
454 else if (splits.size() == 4)
455 {
456 val = Vector4f((float)atof(splits.at(0).c_str()), (float)atof(splits.at(1).c_str()),
457 (float)atof(splits.at(2).c_str()), (float)atof(splits.at(3).c_str()));
458 }
459
460 element.properties[node.name()] = val / Vector4f(mResolution.x(), mResolution.y(), mResolution.x(), mResolution.y());
461 break;
462 }
463 case RESOLUTION_PAIR:
464 {
465 size_t divider = str.find(' ');
466 if(divider == std::string::npos)
467 throw error << "invalid normalized pair (property \"" << node.name() << "\", value \"" << str.c_str() << "\")";
468
469 std::string first = str.substr(0, divider);
470 std::string second = str.substr(divider, std::string::npos);
471
472 Vector2f val((float)atof(first.c_str()), (float)atof(second.c_str()));
473
474 element.properties[node.name()] = val / mResolution;
475 break;
476 }
477 case RESOLUTION_FLOAT:
478 {
479 float val = static_cast<float>(strtod(str.c_str(), 0));
480 element.properties[node.name()] = val / mResolution.y();
481 break;
482 }
483 case NORMALIZED_RECT:

Callers

nothing calls this directly

Calls 15

delimitedStringToVectorFunction · 0.85
resolveRelativePathFunction · 0.85
getHexColorFunction · 0.85
setFilesMethod · 0.80
nameMethod · 0.80
as_boolMethod · 0.80
attributeMethod · 0.80
first_childMethod · 0.80
next_siblingMethod · 0.80
as_stringMethod · 0.80
textMethod · 0.80
c_strMethod · 0.80

Tested by

no test coverage detected