From f6ed8fc1f51e368bb76905d9f1d2d3735e70a644 Mon Sep 17 00:00:00 2001 From: that Date: Sat, 14 Feb 2015 20:23:16 +0100 Subject: gui: make resources type safe - add string, int, color and resource loading helpers - use typed resource classes, and some cleanup in loading code - remove abstract GetResource() to enforce type safe access - add height and width query methods to resources and use them - minor cleanup - simplify LoadPlacement Change-Id: I9b81785109a80b3806ad6b50cba4d893b87b0db1 --- gui/button.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'gui/button.cpp') diff --git a/gui/button.cpp b/gui/button.cpp index 943d71914..6ea0beec9 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -98,9 +98,7 @@ GUIButton::GUIButton(xml_node<>* node) child = node->first_node("icon"); if (child) { - attr = child->first_attribute("resource"); - if (attr) - mButtonIcon = PageManager::FindResource(attr->value()); + mButtonIcon = LoadAttrImage(child, "resource"); } memset(&mHighlightColor, 0, sizeof(COLOR)); @@ -122,14 +120,13 @@ GUIButton::GUIButton(xml_node<>* node) LoadPlacement(node->first_node("placement"), &x, &y, &w, &h, &TextPlacement); } SetRenderPos(x, y, w, h); - return; } GUIButton::~GUIButton() { - if (mButtonImg) delete mButtonImg; - if (mButtonLabel) delete mButtonLabel; - if (mAction) delete mAction; + delete mButtonImg; + delete mButtonLabel; + delete mAction; } int GUIButton::Render(void) @@ -221,12 +218,8 @@ int GUIButton::SetRenderPos(int x, int y, int w, int h) mRenderH = h; } - mIconW = 0; mIconH = 0; - if (mButtonIcon && mButtonIcon->GetResource()) - { - mIconW = gr_get_width(mButtonIcon->GetResource()); - mIconH = gr_get_height(mButtonIcon->GetResource()); - } + mIconW = mButtonIcon->GetWidth(); + mIconH = mButtonIcon->GetHeight(); mTextH = 0; mTextW = 0; -- cgit v1.2.3