UIWidgetPtr UIManager::createWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent) { OTMLNodePtr originalStyleNode = getStyle(widgetNode->tag()); if(!originalStyleNode) stdext::throw_exception(stdext::format("'%s' is not a defined style", widgetNode->tag())); OTMLNodePtr styleNode = originalStyleNode->clone(); styleNode->merge(widgetNode); std::string widgetType = styleNode->valueAt("__class"); // call widget creation from lua UIWidgetPtr widget = g_lua.callGlobalField<UIWidgetPtr>(widgetType, "create"); if(parent) parent->addChild(widget); if(widget) { widget->callLuaField("onCreate"); widget->setStyleFromNode(styleNode); for(const OTMLNodePtr& childNode : styleNode->children()) { if(!childNode->isUnique()) { createWidgetFromOTML(childNode, widget); styleNode->removeChild(childNode); } } } else stdext::throw_exception(stdext::format("unable to create widget of type '%s'", widgetType)); widget->callLuaField("onSetup"); return widget; }
bool ParticleAffector::load(const OTMLNodePtr& node) { float minDelay = 0, maxDelay = 0; float minDuration = -1, maxDuration = -1; for(const OTMLNodePtr& childNode : node->children()) { if(childNode->tag() == "delay") { minDelay = childNode->value<float>(); maxDelay = childNode->value<float>(); } else if(childNode->tag() == "min-delay") minDelay = childNode->value<float>(); else if(childNode->tag() == "max-delay") maxDelay = childNode->value<float>(); if(childNode->tag() == "duration") { minDuration = childNode->value<float>(); maxDuration = childNode->value<float>(); } else if(childNode->tag() == "min-duration") minDuration = childNode->value<float>(); else if(childNode->tag() == "max-duration") maxDuration = childNode->value<float>(); } m_delay = Fw::randomRange(minDelay, maxDelay); m_duration = Fw::randomRange(minDuration, maxDuration); return true; }
void UIProgressRect::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleName, styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "percent") setPercent(node->value<float>()); } }
void UIHorizontalLayout::applyStyle(const OTMLNodePtr& styleNode) { UIBoxLayout::applyStyle(styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "align-right") setAlignRight(node->value<bool>()); } }
void ParticleEffectType::load(const OTMLNodePtr& node) { m_node = node->clone(); for(const OTMLNodePtr& childNode : node->children()) { if(childNode->tag() == "name") m_name = childNode->value(); else if(childNode->tag() == "description") m_description = childNode->value(); } }
std::vector<std::string> Config::getList(const std::string& key) { std::vector<std::string> list; OTMLNodePtr child = m_confsDoc->get(key); if(child) { for(const OTMLNodePtr& subchild : child->children()) list.push_back(subchild->value()); } return list; }
void UIBoxLayout::applyStyle(const OTMLNodePtr& styleNode) { UILayout::applyStyle(styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "spacing") setSpacing(node->value<int>()); else if(node->tag() == "fit-children") setFitChildren(node->value<bool>()); } }
void UIMinimap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleName, styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "zoom") setZoom(node->value<int>()); else if(node->tag() == "max-zoom") setMaxZoom(node->value<int>()); else if(node->tag() == "min-zoom") setMinZoom(node->value<int>()); } }
int push_luavalue(const OTMLNodePtr& node) { if(node) { g_lua.newTable(); int currentIndex = 1; for(const OTMLNodePtr& cnode : node->children()) { push_otml_subnode_luavalue(cnode); if(cnode->isUnique() && !cnode->tag().empty()) { g_lua.setField(cnode->tag()); } else g_lua.rawSeti(currentIndex++); } } else g_lua.pushNil(); return 1; }
bool GravityAffector::load(const OTMLNodePtr& node) { if(!ParticleAffector::load(node)) return false; m_angle = 270 * DEG_TO_RAD; m_gravity = 9.8; for(const OTMLNodePtr& childNode : node->children()) { if(childNode->tag() == "angle") m_angle = childNode->value<float>() * DEG_TO_RAD; else if(childNode->tag() == "gravity") m_gravity = childNode->value<float>(); } return true; }
void ThingType::unserializeOtml(const OTMLNodePtr& node) { for(const OTMLNodePtr& node2 : node->children()) { if(node2->tag() == "opacity") m_opacity = node2->value<float>(); else if(node2->tag() == "notprewalkable") m_attribs.set(ThingAttrNotPreWalkable, node2->value<bool>()); else if(node2->tag() == "image") m_customImage = node2->value(); else if(node2->tag() == "full-ground") { if(node2->value<bool>()) m_attribs.set(ThingAttrFullGround, true); else m_attribs.remove(ThingAttrFullGround); } } }
void UIWidget::parseTextStyle(const OTMLNodePtr& styleNode) { for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "text") setText(node->value()); else if(node->tag() == "text-align") setTextAlign(Fw::translateAlignment(node->value())); else if(node->tag() == "text-offset") setTextOffset(node->value<Point>()); else if(node->tag() == "text-wrap") setTextWrap(node->value<bool>()); else if(node->tag() == "text-auto-resize") setTextAutoResize(node->value<bool>()); else if(node->tag() == "font") setFont(node->value()); } }
void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleName, styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "item-id") setItemId(node->value<int>()); else if(node->tag() == "item-count") setItemCount(node->value<int>()); else if(node->tag() == "item-visible") setItemVisible(node->value<bool>()); else if(node->tag() == "virtual") setVirtual(node->value<bool>()); else if(node->tag() == "show-id") m_showId = node->value<bool>(); } }
void UILineEdit::onStyleApply(const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "text") { setText(node->value()); setCursorPos(m_text.length()); } else if(node->tag() == "text-hidden") { setTextHidden(node->value<bool>()); } else if(node->tag() == "text-margin") { m_textHorizontalMargin = node->value<int>(); } else if(node->tag() == "always-active") { m_alwaysActive = true; } } }
void UILineEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleName, styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "text") { setText(node->value()); setCursorPos(m_text.length()); } else if(node->tag() == "text-hidden") setTextHidden(node->value<bool>()); else if(node->tag() == "text-margin") setTextHorizontalMargin(node->value<int>()); else if(node->tag() == "always-active") setAlwaysActive(node->value<bool>()); //else if(node->tag() == "disable-arrow-navitation") // setArrowNavigation(node->value<bool>()); } }
void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode) { for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "image-source") setImageSource(stdext::resolve_path(node->value(), node->source())); else if(node->tag() == "image-offset-x") setImageOffsetX(node->value<int>()); else if(node->tag() == "image-offset-y") setImageOffsetY(node->value<int>()); else if(node->tag() == "image-offset") setImageOffset(node->value<Point>()); else if(node->tag() == "image-width") setImageWidth(node->value<int>()); else if(node->tag() == "image-height") setImageHeight(node->value<int>()); else if(node->tag() == "image-size") setImageSize(node->value<Size>()); else if(node->tag() == "image-rect") setImageRect(node->value<Rect>()); else if(node->tag() == "image-clip") setImageClip(node->value<Rect>()); else if(node->tag() == "image-fixed-ratio") setImageFixedRatio(node->value<bool>()); else if(node->tag() == "image-repeated") setImageRepeated(node->value<bool>()); else if(node->tag() == "image-smooth") setImageSmooth(node->value<bool>()); else if(node->tag() == "image-color") setImageColor(node->value<Color>()); else if(node->tag() == "image-border-top") setImageBorderTop(node->value<int>()); else if(node->tag() == "image-border-right") setImageBorderRight(node->value<int>()); else if(node->tag() == "image-border-bottom") setImageBorderBottom(node->value<int>()); else if(node->tag() == "image-border-left") setImageBorderLeft(node->value<int>()); else if(node->tag() == "image-border") setImageBorder(node->value<int>()); else if(node->tag() == "image-auto-resize") setImageAutoResize(node->value<bool>()); } }
void UICheckBox::onStyleApply(const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleNode); for(OTMLNodePtr node : styleNode->children()) { if(node->tag() == "text-offset") m_textOffset = node->value<Point>(); else if(node->tag() == "text") m_text = node->value(); else if(node->tag() == "box-size") m_boxSize = node->value<Size>(); else if(node->tag() == "text-align") m_textAlign = Fw::translateAlignment(node->value()); else if(node->tag() == "checked") { // must be scheduled because setChecked can change the style again g_dispatcher.addEvent(std::bind(&UICheckBox::setChecked, asUICheckBox(), node->value<bool>())); } } }
void UIWidget::applyStyle(const OTMLNodePtr& styleNode) { if(m_destroyed) return; if(styleNode->size() == 0) return; m_loadingStyle = true; try { // translate ! style tags for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag()[0] == '!') { std::string tag = node->tag().substr(1); std::string code = stdext::format("tostring(%s)", node->value()); std::string origin = "@" + node->source() + ": [" + node->tag() + "]"; g_lua.evaluateExpression(code, origin); std::string value = g_lua.popString(); node->setTag(tag); node->setValue(value); } } onStyleApply(styleNode->tag(), styleNode); callLuaField("onStyleApply", styleNode->tag(), styleNode); if(m_firstOnStyle) { UIWidgetPtr parent = getParent(); if(isFocusable() && isExplicitlyVisible() && isExplicitlyEnabled() && parent && ((!parent->getFocusedChild() && parent->getAutoFocusPolicy() == Fw::AutoFocusFirst) || parent->getAutoFocusPolicy() == Fw::AutoFocusLast)) { focus(); } } m_firstOnStyle = false; } catch(stdext::exception& e) { g_logger.traceError(stdext::format("failed to apply style to widget '%s': %s", m_id, e.what())); } m_loadingStyle = false; }
void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleName, styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "text") { setText(node->value()); setCursorPos(m_text.length()); } else if(node->tag() == "text-hidden") setTextHidden(node->value<bool>()); else if(node->tag() == "text-margin") setTextHorizontalMargin(node->value<int>()); else if(node->tag() == "shift-navigation") setShiftNavigation(node->value<bool>()); else if(node->tag() == "multiline") setMultiline(node->value<bool>()); else if(node->tag() == "max-length") setMaxLength(node->value<int>()); } }
// otml nodes void push_otml_subnode_luavalue(const OTMLNodePtr& node) { if(node->hasValue()) { union { bool b; double d; long l; }; std::string value = node->rawValue(); if(stdext::cast(value, b)) g_lua.pushBoolean(b); else if(stdext::cast(value, l)) g_lua.pushInteger(l); else if(stdext::cast(value, d)) g_lua.pushNumber(d); else g_lua.pushString(value); } else if(node->hasChildren()) { g_lua.newTable(); bool pushedChild = false; int currentIndex = 1; for(const OTMLNodePtr& cnode : node->children()) { push_otml_subnode_luavalue(cnode); if(!g_lua.isNil()) { if(cnode->isUnique()) { g_lua.pushString(cnode->tag()); g_lua.insert(-2); g_lua.rawSet(); } else g_lua.rawSeti(currentIndex++); pushedChild = true; } else g_lua.pop(); } if(!pushedChild) { g_lua.pop(); g_lua.pushNil(); } } else g_lua.pushNil(); }
void ParticleEmitter::load(const OTMLNodePtr& node) { for(const OTMLNodePtr& childNode : node->children()) { // self related if(childNode->tag() == "position") m_position = childNode->value<Point>(); else if(childNode->tag() == "duration") m_duration = childNode->value<float>(); else if(childNode->tag() == "delay") m_delay = childNode->value<float>(); else if(childNode->tag() == "burst-rate") m_burstRate = childNode->value<float>(); else if(childNode->tag() == "burst-count") m_burstCount = childNode->value<int>(); else if(childNode->tag() == "particle-type") m_particleType = g_particles.getParticleType(childNode->value()); } if(!m_particleType) stdext::throw_exception("emitter didn't provide a valid particle type"); }
bool AttractionAffector::load(const OTMLNodePtr& node) { if(!ParticleAffector::load(node)) return false; m_acceleration = 32; m_reduction = 0; m_repelish = false; for(const OTMLNodePtr& childNode : node->children()) { if(childNode->tag() == "position") m_position = childNode->value<Point>(); else if(childNode->tag() == "acceleration") m_acceleration = childNode->value<float>(); else if(childNode->tag() == "velocity-reduction-percent") m_reduction = childNode->value<float>(); else if(childNode->tag() == "repelish") m_repelish = childNode->value<bool>(); } return true; }
void UIWidget::applyStyle(const OTMLNodePtr& styleNode) { if(m_destroyed) return; if(styleNode->size() == 0) return; m_loadingStyle = true; try { // translate ! style tags for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag()[0] == '!') { std::string tag = node->tag().substr(1); std::string code = Fw::formatString("tostring(%s)", node->value().c_str()); std::string origin = "@" + node->source() + "[" + node->tag() + "]"; g_lua.evaluateExpression(code, origin); std::string value = g_lua.popString(); node->setTag(tag); node->setValue(value); } } onStyleApply(styleNode->tag(), styleNode); callLuaField("onStyleApply", styleNode->tag(), styleNode); if(m_firstOnStyle) { callLuaField("onSetup"); // always focus new child if(isFocusable() && isExplicitlyVisible() && isExplicitlyEnabled()) focus(); } m_firstOnStyle = false; } catch(Exception& e) { logError("Failed to apply style to widget '", m_id, "' style: ", e.what()); } m_loadingStyle = false; }
void ParticleSystem::load(const OTMLNodePtr& node) { for(const OTMLNodePtr& childNode : node->children()) { if(childNode->tag() == "Emitter") { ParticleEmitterPtr emitter = ParticleEmitterPtr(new ParticleEmitter()); emitter->load(childNode); m_emitters.push_back(emitter); } else if(childNode->tag().find("Affector") != std::string::npos) { ParticleAffectorPtr affector; if(childNode->tag() == "GravityAffector") affector = ParticleAffectorPtr(new GravityAffector); else if(childNode->tag() == "AttractionAffector") affector = ParticleAffectorPtr(new AttractionAffector); if(affector) { affector->load(childNode); m_affectors.push_back(affector); } } } }
void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleName, styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "text") { setText(node->value()); setCursorPos(m_text.length()); } else if(node->tag() == "text-hidden") setTextHidden(node->value<bool>()); else if(node->tag() == "shift-navigation") setShiftNavigation(node->value<bool>()); else if(node->tag() == "multiline") setMultiline(node->value<bool>()); else if(node->tag() == "max-length") setMaxLength(node->value<int>()); else if(node->tag() == "editable") setEditable(node->value<bool>()); else if(node->tag() == "selectable") setSelectable(node->value<bool>()); else if(node->tag() == "selection-color") setSelectionColor(node->value<Color>()); else if(node->tag() == "selection-background-color") setSelectionBackgroundColor(node->value<Color>()); else if(node->tag() == "selection") { Point selectionRange = node->value<Point>(); setSelection(selectionRange.x, selectionRange.y); } else if(node->tag() == "cursor-visible") setCursorVisible(node->value<bool>()); else if(node->tag() == "change-cursor-image") setChangeCursorImage(node->value<bool>()); else if(node->tag() == "auto-scroll") setAutoScroll(node->value<bool>()); } }
void ParticleType::load(const OTMLNodePtr& node) { for(const OTMLNodePtr& childNode : node->children()) { if(childNode->tag() == "name") pName = childNode->value(); else if(childNode->tag() == "position-radius") { pMinPositionRadius = childNode->value<float>(); pMaxPositionRadius = childNode->value<float>(); } else if(childNode->tag() == "min-position-radius") pMinPositionRadius = childNode->value<float>(); else if(childNode->tag() == "max-position-radius") pMaxPositionRadius = childNode->value<float>(); else if(childNode->tag() == "position-angle") { pMinPositionAngle = childNode->value<float>() * DEG_TO_RAD; pMaxPositionAngle = childNode->value<float>() * DEG_TO_RAD; } else if(childNode->tag() == "min-position-angle") pMinPositionAngle = childNode->value<float>() * DEG_TO_RAD; else if(childNode->tag() == "max-position-angle") pMaxPositionAngle = childNode->value<float>() * DEG_TO_RAD; // velocity else if(childNode->tag() == "velocity") { pMinVelocity = childNode->value<float>(); pMaxVelocity = childNode->value<float>(); } else if(childNode->tag() == "min-velocity") pMinVelocity = childNode->value<float>(); else if(childNode->tag() == "max-velocity") pMaxVelocity = childNode->value<float>(); else if(childNode->tag() == "velocity-angle") { pMinVelocityAngle = childNode->value<float>() * DEG_TO_RAD; pMaxVelocityAngle = childNode->value<float>() * DEG_TO_RAD; } else if(childNode->tag() == "min-velocity-angle") pMinVelocityAngle = childNode->value<float>() * DEG_TO_RAD; else if(childNode->tag() == "max-velocity-angle") pMaxVelocityAngle = childNode->value<float>() * DEG_TO_RAD; else if(childNode->tag() == "acceleration") { pMinAcceleration = childNode->value<float>(); pMaxAcceleration = childNode->value<float>(); } // acceleration else if(childNode->tag() == "min-acceleration") pMinAcceleration = childNode->value<float>(); else if(childNode->tag() == "max-acceleration") pMaxAcceleration = childNode->value<float>(); else if(childNode->tag() == "acceleration-angle") { pMinAccelerationAngle = childNode->value<float>() * DEG_TO_RAD; pMaxAccelerationAngle = childNode->value<float>() * DEG_TO_RAD; } else if(childNode->tag() == "min-acceleration-angle") pMinAccelerationAngle = childNode->value<float>() * DEG_TO_RAD; else if(childNode->tag() == "max-acceleration-angle") pMaxAccelerationAngle = childNode->value<float>() * DEG_TO_RAD; // duration else if(childNode->tag() == "duration") { pMinDuration = childNode->value<float>(); pMaxDuration = childNode->value<float>(); } else if(childNode->tag() == "min-duration") pMinDuration = childNode->value<float>(); else if(childNode->tag() == "max-duration") pMaxDuration = childNode->value<float>(); else if(childNode->tag() == "ignore-physics-after") pIgnorePhysicsAfter = childNode->value<float>(); // visual else if(childNode->tag() == "size") { pStartSize = childNode->value<Size>(); pFinalSize = childNode->value<Size>(); } else if(childNode->tag() == "start-size") pStartSize = childNode->value<Size>(); else if(childNode->tag() == "final-size") pFinalSize = childNode->value<Size>(); else if(childNode->tag() == "colors") pColors = stdext::split<Color>(childNode->value()); else if(childNode->tag() == "colors-stops") pColorsStops = stdext::split<float>(childNode->value()); else if(childNode->tag() == "texture") pTexture = g_textures.getTexture(childNode->value()); else if(childNode->tag() == "composition-mode") { if(childNode->value() == "normal") pCompositionMode = Painter::CompositionMode_Normal; else if(childNode->value() == "multiply") pCompositionMode = Painter::CompositionMode_Multiply; else if(childNode->value() == "addition") pCompositionMode = Painter::CompositionMode_Add; } } if(pColors.empty()) pColors.push_back(Color(255, 255, 255, 128)); if(pColorsStops.empty()) pColorsStops.push_back(0); if(pColors.size() != pColorsStops.size()) stdext::throw_exception("particle colors must be equal to colorstops-1"); pTexture->setSmooth(true); pTexture->buildHardwareMipmaps(); }
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode) { // load styles used by all widgets for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "color") setColor(node->value<Color>()); else if(node->tag() == "x") setX(node->value<int>()); else if(node->tag() == "y") setY(node->value<int>()); else if(node->tag() == "pos") setPosition(node->value<Point>()); else if(node->tag() == "width") setWidth(node->value<int>()); else if(node->tag() == "height") setHeight(node->value<int>()); else if(node->tag() == "rect") setRect(node->value<Rect>()); else if(node->tag() == "background") setBackgroundColor(node->value<Color>()); else if(node->tag() == "background-color") setBackgroundColor(node->value<Color>()); else if(node->tag() == "background-offset-x") setBackgroundOffsetX(node->value<int>()); else if(node->tag() == "background-offset-y") setBackgroundOffsetY(node->value<int>()); else if(node->tag() == "background-offset") setBackgroundOffset(node->value<Point>()); else if(node->tag() == "background-width") setBackgroundWidth(node->value<int>()); else if(node->tag() == "background-height") setBackgroundHeight(node->value<int>()); else if(node->tag() == "background-size") setBackgroundSize(node->value<Size>()); else if(node->tag() == "background-rect") setBackgroundRect(node->value<Rect>()); else if(node->tag() == "icon") setIcon(stdext::resolve_path(node->value(), node->source())); else if(node->tag() == "icon-source") setIcon(stdext::resolve_path(node->value(), node->source())); else if(node->tag() == "icon-color") setIconColor(node->value<Color>()); else if(node->tag() == "icon-offset-x") setIconOffsetX(node->value<int>()); else if(node->tag() == "icon-offset-y") setIconOffsetY(node->value<int>()); else if(node->tag() == "icon-offset") setIconOffset(node->value<Point>()); else if(node->tag() == "icon-width") setIconWidth(node->value<int>()); else if(node->tag() == "icon-height") setIconHeight(node->value<int>()); else if(node->tag() == "icon-size") setIconSize(node->value<Size>()); else if(node->tag() == "icon-rect") setIconRect(node->value<Rect>()); else if(node->tag() == "opacity") setOpacity(node->value<float>()); else if(node->tag() == "enabled") setEnabled(node->value<bool>()); else if(node->tag() == "visible") setVisible(node->value<bool>()); else if(node->tag() == "checked") setChecked(node->value<bool>()); else if(node->tag() == "dragable") setChecked(node->value<bool>()); else if(node->tag() == "on") setOn(node->value<bool>()); else if(node->tag() == "focusable") setFocusable(node->value<bool>()); else if(node->tag() == "phantom") setPhantom(node->value<bool>()); else if(node->tag() == "size") setSize(node->value<Size>()); else if(node->tag() == "fixed-size") setFixedSize(node->value<bool>()); else if(node->tag() == "clipping") setClipping(node->value<bool>()); else if(node->tag() == "border") { auto split = stdext::split(node->value(), " "); if(split.size() == 2) { setBorderWidth(stdext::safe_cast<int>(split[0])); setBorderColor(stdext::safe_cast<Color>(split[1])); } else throw OTMLException(node, "border param must have its width followed by its color"); } else if(node->tag() == "border-width") setBorderWidth(node->value<int>()); else if(node->tag() == "border-width-top") setBorderWidthTop(node->value<int>()); else if(node->tag() == "border-width-right") setBorderWidthRight(node->value<int>()); else if(node->tag() == "border-width-bottom") setBorderWidthBottom(node->value<int>()); else if(node->tag() == "border-width-left") setBorderWidthLeft(node->value<int>()); else if(node->tag() == "border-color") setBorderColor(node->value<Color>()); else if(node->tag() == "border-color-top") setBorderColorTop(node->value<Color>()); else if(node->tag() == "border-color-right") setBorderColorRight(node->value<Color>()); else if(node->tag() == "border-color-bottom") setBorderColorBottom(node->value<Color>()); else if(node->tag() == "border-color-left") setBorderColorLeft(node->value<Color>()); else if(node->tag() == "margin-top") setMarginTop(node->value<int>()); else if(node->tag() == "margin-right") setMarginRight(node->value<int>()); else if(node->tag() == "margin-bottom") setMarginBottom(node->value<int>()); else if(node->tag() == "margin-left") setMarginLeft(node->value<int>()); else if(node->tag() == "margin") { std::string marginDesc = node->value(); std::vector<std::string> split; boost::split(split, marginDesc, boost::is_any_of(std::string(" "))); if(split.size() == 4) { setMarginTop(stdext::safe_cast<int>(split[0])); setMarginRight(stdext::safe_cast<int>(split[1])); setMarginBottom(stdext::safe_cast<int>(split[2])); setMarginLeft(stdext::safe_cast<int>(split[3])); } else if(split.size() == 3) { int marginTop = stdext::safe_cast<int>(split[0]); int marginHorizontal = stdext::safe_cast<int>(split[1]); int marginBottom = stdext::safe_cast<int>(split[2]); setMarginTop(marginTop); setMarginRight(marginHorizontal); setMarginBottom(marginBottom); setMarginLeft(marginHorizontal); } else if(split.size() == 2) { int marginVertical = stdext::safe_cast<int>(split[0]); int marginHorizontal = stdext::safe_cast<int>(split[1]); setMarginTop(marginVertical); setMarginRight(marginHorizontal); setMarginBottom(marginVertical); setMarginLeft(marginHorizontal); } else if(split.size() == 1) { int margin = stdext::safe_cast<int>(split[0]); setMarginTop(margin); setMarginRight(margin); setMarginBottom(margin); setMarginLeft(margin); } } else if(node->tag() == "padding-top") setPaddingTop(node->value<int>()); else if(node->tag() == "padding-right") setPaddingRight(node->value<int>()); else if(node->tag() == "padding-bottom") setPaddingBottom(node->value<int>()); else if(node->tag() == "padding-left") setPaddingLeft(node->value<int>()); else if(node->tag() == "padding") { std::string paddingDesc = node->value(); std::vector<std::string> split; boost::split(split, paddingDesc, boost::is_any_of(std::string(" "))); if(split.size() == 4) { setPaddingTop(stdext::safe_cast<int>(split[0])); setPaddingRight(stdext::safe_cast<int>(split[1])); setPaddingBottom(stdext::safe_cast<int>(split[2])); setPaddingLeft(stdext::safe_cast<int>(split[3])); } else if(split.size() == 3) { int paddingTop = stdext::safe_cast<int>(split[0]); int paddingHorizontal = stdext::safe_cast<int>(split[1]); int paddingBottom = stdext::safe_cast<int>(split[2]); setPaddingTop(paddingTop); setPaddingRight(paddingHorizontal); setPaddingBottom(paddingBottom); setPaddingLeft(paddingHorizontal); } else if(split.size() == 2) { int paddingVertical = stdext::safe_cast<int>(split[0]); int paddingHorizontal = stdext::safe_cast<int>(split[1]); setPaddingTop(paddingVertical); setPaddingRight(paddingHorizontal); setPaddingBottom(paddingVertical); setPaddingLeft(paddingHorizontal); } else if(split.size() == 1) { int padding = stdext::safe_cast<int>(split[0]); setPaddingTop(padding); setPaddingRight(padding); setPaddingBottom(padding); setPaddingLeft(padding); } } // layouts else if(node->tag() == "layout") { std::string layoutType; if(node->hasValue()) layoutType = node->value(); else layoutType = node->valueAt<std::string>("type", ""); if(!layoutType.empty()) { UILayoutPtr layout; if(layoutType == "horizontalBox") layout = UIHorizontalLayoutPtr(new UIHorizontalLayout(asUIWidget())); else if(layoutType == "verticalBox") layout = UIVerticalLayoutPtr(new UIVerticalLayout(asUIWidget())); else if(layoutType == "grid") layout = UIGridLayoutPtr(new UIGridLayout(asUIWidget())); else if(layoutType == "anchor") layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget())); else throw OTMLException(node, "cannot determine layout type"); setLayout(layout); } if(node->hasChildren()) m_layout->applyStyle(node); } // anchors else if(boost::starts_with(node->tag(), "anchors.")) { UIWidgetPtr parent = getParent(); if(!parent) { if(m_firstOnStyle) throw OTMLException(node, "cannot create anchor, there is no parent widget!"); else continue; } UIAnchorLayoutPtr anchorLayout = parent->getLayout()->asUIAnchorLayout(); if(!anchorLayout) throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!"); std::string what = node->tag().substr(8); if(what == "fill") { fill(node->value()); } else if(what == "centerIn") { centerIn(node->value()); } else { Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what); if(node->value() == "none") { removeAnchor(anchoredEdge); } else { std::vector<std::string> split = stdext::split(node->value(), "."); if(split.size() != 2) throw OTMLException(node, "invalid anchor description"); std::string hookedWidgetId = split[0]; Fw::AnchorEdge hookedEdge = Fw::translateAnchorEdge(split[1]); if(anchoredEdge == Fw::AnchorNone) throw OTMLException(node, "invalid anchor edge"); if(hookedEdge == Fw::AnchorNone) throw OTMLException(node, "invalid anchor target edge"); addAnchor(anchoredEdge, hookedWidgetId, hookedEdge); } } // lua functions } else if(boost::starts_with(node->tag(), "@")) { // load once if(m_firstOnStyle) { std::string funcName = node->tag().substr(1); std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]"; g_lua.loadFunction(node->value(), funcOrigin); luaSetField(funcName); } // lua fields value } else if(boost::starts_with(node->tag(), "&")) { std::string fieldName = node->tag().substr(1); std::string fieldOrigin = "@" + node->source() + "[" + node->tag() + "]"; g_lua.evaluateExpression(node->value(), fieldOrigin); luaSetField(fieldName); } } }