From 21ff02a69331fbcd53dc93a1af9a93618225b4bf Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Wed, 18 Feb 2015 14:35:00 -0600 Subject: GUI: Support styles in xml to reduce xml file size Also allow sliders to have their own text label instead of requiring a whole separate text object for the label in the xml. Change-Id: I6e314efb4bb454d496555ff7e003d743063a1308 --- gui/button.cpp | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) (limited to 'gui/button.cpp') diff --git a/gui/button.cpp b/gui/button.cpp index 6ea0beec9..18b5560c4 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -63,15 +63,11 @@ GUIButton::GUIButton(xml_node<>* node) mButtonLabel = new GUIText(node); mAction = new GUIAction(node); - child = node->first_node("image"); - if (child) + mButtonImg = new GUIImage(node); + if (mButtonImg->Render() < 0) { - mButtonImg = new GUIImage(node); - if (mButtonImg->Render() < 0) - { - delete mButtonImg; - mButtonImg = NULL; - } + delete mButtonImg; + mButtonImg = NULL; } if (mButtonLabel->Render() < 0) { @@ -79,45 +75,22 @@ GUIButton::GUIButton(xml_node<>* node) mButtonLabel = NULL; } // Load fill if it exists - memset(&mFillColor, 0, sizeof(COLOR)); - child = node->first_node("fill"); - if (child) - { - attr = child->first_attribute("color"); - if (attr) { - hasFill = true; - std::string color = attr->value(); - ConvertStrToColor(color, &mFillColor); - } - } + mFillColor = LoadAttrColor(FindNode(node, "fill"), "color", &hasFill); if (!hasFill && mButtonImg == NULL) { LOGERR("No image resource or fill specified for button.\n"); } // The icon is a special case - child = node->first_node("icon"); - if (child) - { - mButtonIcon = LoadAttrImage(child, "resource"); - } + mButtonIcon = LoadAttrImage(FindNode(node, "icon"), "resource"); - memset(&mHighlightColor, 0, sizeof(COLOR)); - child = node->first_node("highlight"); - if (child) { - attr = child->first_attribute("color"); - if (attr) { - hasHighlightColor = true; - std::string color = attr->value(); - ConvertStrToColor(color, &mHighlightColor); - } - } + mHighlightColor = LoadAttrColor(FindNode(node, "highlight"), "color", &hasHighlightColor); int x, y, w, h; TextPlacement = TOP_LEFT; if (mButtonImg) { mButtonImg->GetRenderPos(x, y, w, h); } else if (hasFill) { - LoadPlacement(node->first_node("placement"), &x, &y, &w, &h, &TextPlacement); + LoadPlacement(FindNode(node, "placement"), &x, &y, &w, &h, &TextPlacement); } SetRenderPos(x, y, w, h); } -- cgit v1.2.3