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/input.cpp | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'gui/input.cpp') diff --git a/gui/input.cpp b/gui/input.cpp index e89333575..299034a2c 100644 --- a/gui/input.cpp +++ b/gui/input.cpp @@ -88,35 +88,21 @@ GUIInput::GUIInput(xml_node<>* node) child = node->first_node("background"); if (child) { - attr = child->first_attribute("resource"); - if (attr) - mBackground = PageManager::FindResource(attr->value()); - attr = child->first_attribute("color"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mBackgroundColor); - } + mBackground = LoadAttrImage(child, "resource"); + mBackgroundColor = LoadAttrColor(child, "color", mBackgroundColor); } if (mBackground && mBackground->GetResource()) { - mBackgroundW = gr_get_width(mBackground->GetResource()); - mBackgroundH = gr_get_height(mBackground->GetResource()); + mBackgroundW = mBackground->GetWidth(); + mBackgroundH = mBackground->GetHeight(); } // Load the cursor color child = node->first_node("cursor"); if (child) { - attr = child->first_attribute("resource"); - if (attr) - mCursor = PageManager::FindResource(attr->value()); - attr = child->first_attribute("color"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mCursorColor); - } + mCursor = LoadAttrImage(child, "resource"); + mCursorColor = LoadAttrColor(child, "color", mCursorColor); attr = child->first_attribute("hasfocus"); if (attr) { @@ -132,15 +118,12 @@ GUIInput::GUIInput(xml_node<>* node) } DrawCursor = HasInputFocus; - // Load the font, and possibly override the color + // Load the font child = node->first_node("font"); if (child) { - attr = child->first_attribute("resource"); - if (attr) { - mFont = PageManager::FindResource(attr->value()); - mFontHeight = gr_getMaxFontHeight(mFont ? mFont->GetResource() : NULL); - } + mFont = LoadAttrFont(child, "resource"); + mFontHeight = mFont->GetHeight(); } child = node->first_node("text"); @@ -213,8 +196,8 @@ GUIInput::GUIInput(xml_node<>* node) GUIInput::~GUIInput() { - if (mInputText) delete mInputText; - if (mAction) delete mAction; + delete mInputText; + delete mAction; } int GUIInput::HandleTextLocation(int x) -- cgit v1.2.3