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/console.cpp | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'gui/console.cpp') diff --git a/gui/console.cpp b/gui/console.cpp index 9c780c06b..bb70400c9 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -129,32 +129,15 @@ GUIConsole::GUIConsole(xml_node<>* node) : GUIObject(node) child = node->first_node("font"); if (child) { - attr = child->first_attribute("resource"); - if (attr) - mFont = PageManager::FindResource(attr->value()); + mFont = LoadAttrFont(child, "resource"); } child = node->first_node("color"); if (child) { - attr = child->first_attribute("foreground"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mForegroundColor); - } - attr = child->first_attribute("background"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mBackgroundColor); - } - attr = child->first_attribute("scroll"); - if (attr) - { - std::string color = attr->value(); - ConvertStrToColor(color, &mScrollColor); - } + mForegroundColor = LoadAttrColor(child, "foreground", mForegroundColor); + mBackgroundColor = LoadAttrColor(child, "background", mBackgroundColor); + mScrollColor = LoadAttrColor(child, "scroll", mScrollColor); } // Load the placement @@ -166,21 +149,19 @@ GUIConsole::GUIConsole(xml_node<>* node) : GUIObject(node) mSlideout = 1; LoadPlacement(child, &mSlideoutX, &mSlideoutY); - attr = child->first_attribute("resource"); - if (attr) mSlideoutImage = PageManager::FindResource(attr->value()); + mSlideoutImage = LoadAttrImage(child, "resource"); if (mSlideoutImage && mSlideoutImage->GetResource()) { - mSlideoutW = gr_get_width(mSlideoutImage->GetResource()); - mSlideoutH = gr_get_height(mSlideoutImage->GetResource()); + mSlideoutW = mSlideoutImage->GetWidth(); + mSlideoutH = mSlideoutImage->GetHeight(); } } } - mFontHeight = gr_getMaxFontHeight(mFont ? mFont->GetResource() : NULL); + mFontHeight = mFont->GetHeight(); SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH); SetRenderPos(mConsoleX, mConsoleY); - return; } int GUIConsole::RenderSlideout(void) -- cgit v1.2.3