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
diff --git a/gui/console.cpp b/gui/console.cpp
index 9c780c0..bb70400 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -129,32 +129,15 @@
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 @@
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)