summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorthat <github@that.at>2015-02-14 20:23:16 +0100
committerthat <github@that.at>2015-02-15 20:36:40 +0100
commitf6ed8fc1f51e368bb76905d9f1d2d3735e70a644 (patch)
treeba66418d418869274d259ce35cca8d4021d8ce4e /gui
parentRetain and display previous selection for image flashing (diff)
downloadandroid_bootable_recovery-f6ed8fc1f51e368bb76905d9f1d2d3735e70a644.tar
android_bootable_recovery-f6ed8fc1f51e368bb76905d9f1d2d3735e70a644.tar.gz
android_bootable_recovery-f6ed8fc1f51e368bb76905d9f1d2d3735e70a644.tar.bz2
android_bootable_recovery-f6ed8fc1f51e368bb76905d9f1d2d3735e70a644.tar.lz
android_bootable_recovery-f6ed8fc1f51e368bb76905d9f1d2d3735e70a644.tar.xz
android_bootable_recovery-f6ed8fc1f51e368bb76905d9f1d2d3735e70a644.tar.zst
android_bootable_recovery-f6ed8fc1f51e368bb76905d9f1d2d3735e70a644.zip
Diffstat (limited to '')
-rw-r--r--gui/animation.cpp8
-rw-r--r--gui/button.cpp19
-rw-r--r--gui/checkbox.cpp23
-rw-r--r--gui/console.cpp35
-rw-r--r--gui/fileselector.cpp30
-rw-r--r--gui/image.cpp14
-rw-r--r--gui/input.cpp39
-rw-r--r--gui/keyboard.cpp6
-rw-r--r--gui/listbox.cpp31
-rw-r--r--gui/mousecursor.cpp17
-rw-r--r--gui/objects.hpp86
-rw-r--r--gui/pages.cpp108
-rw-r--r--gui/pages.hpp7
-rw-r--r--gui/partitionlist.cpp33
-rw-r--r--gui/progressbar.cpp29
-rw-r--r--gui/resources.cpp3
-rw-r--r--gui/resources.hpp24
-rw-r--r--gui/scrolllist.cpp34
-rw-r--r--gui/slider.cpp25
-rw-r--r--gui/slidervalue.cpp32
-rw-r--r--gui/text.cpp58
21 files changed, 254 insertions, 407 deletions
diff --git a/gui/animation.cpp b/gui/animation.cpp
index 771e1c116..1e9a87d3f 100644
--- a/gui/animation.cpp
+++ b/gui/animation.cpp
@@ -43,9 +43,7 @@ GUIAnimation::GUIAnimation(xml_node<>* node) : GUIObject(node)
child = node->first_node("resource");
if (child)
{
- attr = child->first_attribute("name");
- if (attr)
- mAnimation = (AnimationResource*) PageManager::FindResource(attr->value());
+ mAnimation = LoadAttrAnimation(child, "name");
}
// Load the placement
@@ -77,8 +75,8 @@ GUIAnimation::GUIAnimation(xml_node<>* node) : GUIObject(node)
// Fetch the render sizes
if (mAnimation && mAnimation->GetResource())
{
- mRenderW = gr_get_width(mAnimation->GetResource());
- mRenderH = gr_get_height(mAnimation->GetResource());
+ mRenderW = mAnimation->GetWidth();
+ mRenderH = mAnimation->GetHeight();
// Adjust for placement
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
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;
diff --git a/gui/checkbox.cpp b/gui/checkbox.cpp
index fe5f557bb..f4900ba2c 100644
--- a/gui/checkbox.cpp
+++ b/gui/checkbox.cpp
@@ -48,12 +48,8 @@ GUICheckbox::GUICheckbox(xml_node<>* node)
child = node->first_node("image");
if (child)
{
- attr = child->first_attribute("checked");
- if (attr)
- mChecked = PageManager::FindResource(attr->value());
- attr = child->first_attribute("unchecked");
- if (attr)
- mUnchecked = PageManager::FindResource(attr->value());
+ mChecked = LoadAttrImage(child, "checked");
+ mUnchecked = LoadAttrImage(child, "unchecked");
}
// Get the variable data
@@ -68,22 +64,17 @@ GUICheckbox::GUICheckbox(xml_node<>* node)
DataManager::SetValue(mVarName, attr->value());
}
- mCheckW = 0; mCheckH = 0;
- if (mChecked && mChecked->GetResource())
- {
- mCheckW = gr_get_width(mChecked->GetResource());
- mCheckH = gr_get_height(mChecked->GetResource());
- }
- else if (mUnchecked && mUnchecked->GetResource())
+ mCheckW = mChecked->GetWidth();
+ mCheckH = mChecked->GetHeight();
+ if (mCheckW == 0)
{
- mCheckW = gr_get_width(mUnchecked->GetResource());
- mCheckH = gr_get_height(mUnchecked->GetResource());
+ mCheckW = mUnchecked->GetWidth();
+ mCheckH = mUnchecked->GetHeight();
}
int x, y, w, h;
mLabel->GetRenderPos(x, y, w, h);
SetRenderPos(x, y, 0, 0);
- return;
}
GUICheckbox::~GUICheckbox()
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)
diff --git a/gui/fileselector.cpp b/gui/fileselector.cpp
index 319b11b96..5c287c34d 100644
--- a/gui/fileselector.cpp
+++ b/gui/fileselector.cpp
@@ -40,7 +40,6 @@ GUIFileSelector::GUIFileSelector(xml_node<>* node) : GUIScrollList(node)
xml_attribute<>* attr;
xml_node<>* child;
- int mIconWidth = 0, mIconHeight = 0, mFolderIconHeight = 0, mFileIconHeight = 0, mFolderIconWidth = 0, mFileIconWidth = 0;
mFolderIcon = mFileIcon = NULL;
mShowFolders = mShowFiles = mShowNavFolders = 1;
mUpdate = 0;
@@ -109,29 +108,12 @@ GUIFileSelector::GUIFileSelector(xml_node<>* node) : GUIScrollList(node)
// Get folder and file icons if present
child = node->first_node("icon");
if (child) {
- attr = child->first_attribute("folder");
- if (attr)
- mFolderIcon = PageManager::FindResource(attr->value());
- attr = child->first_attribute("file");
- if (attr)
- mFileIcon = PageManager::FindResource(attr->value());
- }
- if (mFolderIcon && mFolderIcon->GetResource()) {
- mFolderIconWidth = gr_get_width(mFolderIcon->GetResource());
- mFolderIconHeight = gr_get_height(mFolderIcon->GetResource());
- if (mFolderIconHeight > mIconHeight)
- mIconHeight = mFolderIconHeight;
- mIconWidth = mFolderIconWidth;
- }
- if (mFileIcon && mFileIcon->GetResource()) {
- mFileIconWidth = gr_get_width(mFileIcon->GetResource());
- mFileIconHeight = gr_get_height(mFileIcon->GetResource());
- if (mFileIconHeight > mIconHeight)
- mIconHeight = mFileIconHeight;
- if (mFileIconWidth > mIconWidth)
- mIconWidth = mFileIconWidth;
+ mFolderIcon = LoadAttrImage(child, "folder");
+ mFileIcon = LoadAttrImage(child, "file");
}
- SetMaxIconSize(mIconWidth, mIconHeight);
+ int iconWidth = std::max(mFolderIcon->GetWidth(), mFileIcon->GetWidth());
+ int iconHeight = std::max(mFolderIcon->GetHeight(), mFileIcon->GetHeight());
+ SetMaxIconSize(iconWidth, iconHeight);
// Fetch the file/folder list
std::string value;
@@ -318,7 +300,7 @@ size_t GUIFileSelector::GetItemCount()
return folderSize + fileSize;
}
-int GUIFileSelector::GetListItem(size_t item_index, Resource*& icon, std::string &text)
+int GUIFileSelector::GetListItem(size_t item_index, ImageResource*& icon, std::string &text)
{
size_t folderSize = mShowFolders ? mFolderList.size() : 0;
size_t fileSize = mShowFiles ? mFileList.size() : 0;
diff --git a/gui/image.cpp b/gui/image.cpp
index 2cf3b68af..60b1cb956 100644
--- a/gui/image.cpp
+++ b/gui/image.cpp
@@ -40,12 +40,8 @@ GUIImage::GUIImage(xml_node<>* node) : GUIObject(node)
child = node->first_node("image");
if (child)
{
- attr = child->first_attribute("resource");
- if (attr)
- mImage = PageManager::FindResource(attr->value());
- attr = child->first_attribute("highlightresource");
- if (attr)
- mHighlightImage = PageManager::FindResource(attr->value());
+ mImage = LoadAttrImage(child, "resource");
+ mHighlightImage = LoadAttrImage(child, "highlightresource");
}
// Load the placement
@@ -53,8 +49,8 @@ GUIImage::GUIImage(xml_node<>* node) : GUIObject(node)
if (mImage && mImage->GetResource())
{
- mRenderW = gr_get_width(mImage->GetResource());
- mRenderH = gr_get_height(mImage->GetResource());
+ mRenderW = mImage->GetWidth();
+ mRenderH = mImage->GetHeight();
// Adjust for placement
if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
@@ -73,8 +69,6 @@ GUIImage::GUIImage(xml_node<>* node) : GUIObject(node)
}
SetPlacement(TOP_LEFT);
}
-
- return;
}
int GUIImage::Render(void)
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)
diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp
index db968aee0..5528be936 100644
--- a/gui/keyboard.cpp
+++ b/gui/keyboard.cpp
@@ -102,7 +102,7 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node)
strcpy(resource, "resource1");
attr = child->first_attribute(resource);
while (attr && layoutindex < (MAX_KEYBOARD_LAYOUTS + 1)) {
- keyboardImg[layoutindex - 1] = PageManager::FindResource(attr->value());
+ keyboardImg[layoutindex - 1] = LoadAttrImage(child, resource);
layoutindex++;
resource[8] = (char)(layoutindex + 48);
@@ -113,8 +113,8 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node)
// Check the first image to get height and width
if (keyboardImg[0] && keyboardImg[0]->GetResource())
{
- KeyboardWidth = gr_get_width(keyboardImg[0]->GetResource());
- KeyboardHeight = gr_get_height(keyboardImg[0]->GetResource());
+ KeyboardWidth = keyboardImg[0]->GetWidth();
+ KeyboardHeight = keyboardImg[0]->GetHeight();
}
// Load all of the layout maps
diff --git a/gui/listbox.cpp b/gui/listbox.cpp
index 37ba958c1..7c7afa957 100644
--- a/gui/listbox.cpp
+++ b/gui/listbox.cpp
@@ -34,36 +34,17 @@ GUIListBox::GUIListBox(xml_node<>* node) : GUIScrollList(node)
xml_attribute<>* attr;
xml_node<>* child;
mIconSelected = mIconUnselected = NULL;
- int mSelectedIconWidth = 0, mSelectedIconHeight = 0, mUnselectedIconWidth = 0, mUnselectedIconHeight = 0, mIconWidth = 0, mIconHeight = 0;
mUpdate = 0;
// Get the icons, if any
child = node->first_node("icon");
if (child) {
- attr = child->first_attribute("selected");
- if (attr)
- mIconSelected = PageManager::FindResource(attr->value());
- attr = child->first_attribute("unselected");
- if (attr)
- mIconUnselected = PageManager::FindResource(attr->value());
- }
- if (mIconSelected && mIconSelected->GetResource()) {
- mSelectedIconWidth = gr_get_width(mIconSelected->GetResource());
- mSelectedIconHeight = gr_get_height(mIconSelected->GetResource());
- if (mSelectedIconHeight > mIconHeight)
- mIconHeight = mSelectedIconHeight;
- mIconWidth = mSelectedIconWidth;
- }
-
- if (mIconUnselected && mIconUnselected->GetResource()) {
- mUnselectedIconWidth = gr_get_width(mIconUnselected->GetResource());
- mUnselectedIconHeight = gr_get_height(mIconUnselected->GetResource());
- if (mUnselectedIconHeight > mIconHeight)
- mIconHeight = mUnselectedIconHeight;
- if (mUnselectedIconWidth > mIconWidth)
- mIconWidth = mUnselectedIconWidth;
+ mIconSelected = LoadAttrImage(child, "selected");
+ mIconUnselected = LoadAttrImage(child, "unselected");
}
- SetMaxIconSize(mIconWidth, mIconHeight);
+ int iconWidth = std::max(mIconSelected->GetWidth(), mIconUnselected->GetWidth());
+ int iconHeight = std::max(mIconSelected->GetHeight(), mIconUnselected->GetHeight());
+ SetMaxIconSize(iconWidth, iconHeight);
// Handle the result variable
child = node->first_node("data");
@@ -160,7 +141,7 @@ size_t GUIListBox::GetItemCount()
return mList.size();
}
-int GUIListBox::GetListItem(size_t item_index, Resource*& icon, std::string &text)
+int GUIListBox::GetListItem(size_t item_index, ImageResource*& icon, std::string &text)
{
text = mList.at(item_index).displayName;
if (mList.at(item_index).selected)
diff --git a/gui/mousecursor.cpp b/gui/mousecursor.cpp
index 1c22356f9..625588629 100644
--- a/gui/mousecursor.cpp
+++ b/gui/mousecursor.cpp
@@ -58,19 +58,12 @@ void MouseCursor::LoadData(xml_node<>* node)
child = node->first_node("background");
if(child)
{
- attr = child->first_attribute("color");
- if(attr)
- ConvertStrToColor(attr->value(), &m_color);
-
- attr = child->first_attribute("resource");
- if(attr)
+ m_color = LoadAttrColor(child, "color", m_color);
+ m_image = LoadAttrImage(child, "resource");
+ if(m_image)
{
- m_image = PageManager::FindResource(attr->value());
- if(m_image)
- {
- mRenderW = gr_get_width(m_image->GetResource());
- mRenderH = gr_get_height(m_image->GetResource());
- }
+ mRenderW = m_image->GetWidth();
+ mRenderH = m_image->GetHeight();
}
}
diff --git a/gui/objects.hpp b/gui/objects.hpp
index 5eae919d7..537de208e 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -211,13 +211,12 @@ protected:
std::string mLastValue;
COLOR mColor;
COLOR mHighlightColor;
- Resource* mFont;
+ FontResource* mFont;
int mIsStatic;
int mVarChanged;
int mFontHeight;
unsigned maxWidth;
unsigned charSkip;
- bool hasHighlightColor;
protected:
std::string parseText(void);
@@ -242,8 +241,8 @@ public:
bool isHighlighted;
protected:
- Resource* mImage;
- Resource* mHighlightImage;
+ ImageResource* mImage;
+ ImageResource* mHighlightImage;
};
// GUIFill - Used for fill colors
@@ -402,8 +401,8 @@ protected:
request_show
};
- Resource* mFont;
- Resource* mSlideoutImage;
+ FontResource* mFont;
+ ImageResource* mSlideoutImage;
COLOR mForegroundColor;
COLOR mBackgroundColor;
COLOR mScrollColor;
@@ -453,7 +452,7 @@ public:
protected:
GUIImage* mButtonImg;
- Resource* mButtonIcon;
+ ImageResource* mButtonIcon;
GUIText* mButtonLabel;
GUIAction* mAction;
int mTextX, mTextY, mTextW, mTextH;
@@ -491,8 +490,8 @@ public:
virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
protected:
- Resource* mChecked;
- Resource* mUnchecked;
+ ImageResource* mChecked;
+ ImageResource* mUnchecked;
GUIText* mLabel;
int mTextX, mTextY;
int mCheckX, mCheckY, mCheckW, mCheckH;
@@ -501,12 +500,6 @@ protected:
std::string mVarName;
};
-struct ScrollListData {
- Resource* displayResource;
- std::string displayName;
- int list_index;
-};
-
class GUIScrollList : public GUIObject, public RenderObject, public ActionObject
{
public:
@@ -541,7 +534,7 @@ protected:
// get number of items
virtual size_t GetItemCount() { return 0; }
// get data for one item
- virtual int GetListItem(size_t item_index, Resource*& icon, std::string &text)
+ virtual int GetListItem(size_t item_index, ImageResource*& icon, std::string &text)
{ icon = NULL; text = ""; return -1; }
// an item was selected
virtual void NotifySelect(size_t item_selected) {}
@@ -568,7 +561,7 @@ protected:
protected:
// Background
COLOR mBackgroundColor;
- Resource* mBackground; // background image, if any, automatically centered
+ ImageResource* mBackground; // background image, if any, automatically centered
int mBackgroundW, mBackgroundH; // background width and height if using an image for the background
// Header
@@ -578,13 +571,13 @@ protected:
std::string mLastHeaderValue; // Header text after parsing variables
int mHeaderIsStatic; // indicates if the header is static (no need to check for changes in NotifyVarChange)
int mHeaderH; // actual header height including font, icon, padding, and separator heights
- Resource* mHeaderIcon;
+ ImageResource* mHeaderIcon;
int mHeaderIconHeight, mHeaderIconWidth; // width and height of the header icon if present
int mHeaderSeparatorH; // Height of the separator between header and list items
COLOR mHeaderSeparatorColor; // color of the header separator
// Per-item layout
- Resource* mFont;
+ FontResource* mFont;
COLOR mFontColor;
bool hasHighlightColor; // indicates if a hightlight color was set
bool hasFontHighlightColor; // indicates if the font hightlight color is set
@@ -633,7 +626,7 @@ public:
virtual void SetPageFocus(int inFocus);
virtual size_t GetItemCount();
- virtual int GetListItem(size_t item_index, Resource*& icon, std::string &text);
+ virtual int GetListItem(size_t item_index, ImageResource*& icon, std::string &text);
virtual void NotifySelect(size_t item_selected);
protected:
@@ -664,8 +657,8 @@ protected:
int mShowFolders, mShowFiles; // indicates if the list should show folders and/or files
int mShowNavFolders; // indicates if the list should include the "up a level" item and allow you to traverse folders (nav folders are disabled for the restore list, for instance)
static int mSortOrder; // must be static because it is used by the static function fileSort
- Resource* mFolderIcon;
- Resource* mFileIcon;
+ ImageResource* mFolderIcon;
+ ImageResource* mFileIcon;
bool updateFileList;
};
@@ -687,7 +680,7 @@ public:
virtual void SetPageFocus(int inFocus);
virtual size_t GetItemCount();
- virtual int GetListItem(size_t item_index, Resource*& icon, std::string &text);
+ virtual int GetListItem(size_t item_index, ImageResource*& icon, std::string &text);
virtual void NotifySelect(size_t item_selected);
protected:
@@ -701,8 +694,8 @@ protected:
std::vector<ListData> mList;
std::string mVariable;
std::string currentValue;
- Resource* mIconSelected;
- Resource* mIconUnselected;
+ ImageResource* mIconSelected;
+ ImageResource* mIconUnselected;
};
class GUIPartitionList : public GUIScrollList
@@ -723,7 +716,7 @@ public:
virtual void SetPageFocus(int inFocus);
virtual size_t GetItemCount();
- virtual int GetListItem(size_t item_index, Resource*& icon, std::string &text);
+ virtual int GetListItem(size_t item_index, ImageResource*& icon, std::string &text);
virtual void NotifySelect(size_t item_selected);
protected:
@@ -737,8 +730,8 @@ protected:
std::string selectedList;
std::string currentValue;
std::string mLastValue;
- Resource* mIconSelected;
- Resource* mIconUnselected;
+ ImageResource* mIconSelected;
+ ImageResource* mIconUnselected;
bool updateList;
};
@@ -785,8 +778,8 @@ public:
virtual int NotifyVarChange(const std::string& varName, const std::string& value);
protected:
- Resource* mEmptyBar;
- Resource* mFullBar;
+ ImageResource* mEmptyBar;
+ ImageResource* mFullBar;
std::string mMinValVar;
std::string mMaxValVar;
std::string mCurValVar;
@@ -820,9 +813,9 @@ public:
protected:
GUIAction* sAction;
- Resource* sSlider;
- Resource* sSliderUsed;
- Resource* sTouch;
+ ImageResource* sSlider;
+ ImageResource* sSliderUsed;
+ ImageResource* sTouch;
int sTouchW, sTouchH;
int sCurTouchX;
int sUpdate;
@@ -875,7 +868,7 @@ protected:
int revert_layout;
};
- Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
+ ImageResource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
bool mRendered;
@@ -924,9 +917,9 @@ protected:
protected:
GUIText* mInputText;
GUIAction* mAction;
- Resource* mBackground;
- Resource* mCursor;
- Resource* mFont;
+ ImageResource* mBackground;
+ ImageResource* mCursor;
+ FontResource* mFont;
std::string mText;
std::string mLastValue;
std::string mVariable;
@@ -1019,7 +1012,7 @@ protected:
float mValuePct;
std::string mMaxStr;
std::string mMinStr;
- Resource *mFont;
+ FontResource *mFont;
GUIText* mLabel;
int mLabelW;
COLOR mTextColor;
@@ -1041,9 +1034,9 @@ protected:
bool mChangeOnDrag;
int mLineW;
bool mDragging;
- Resource *mBackgroundImage;
- Resource *mHandleImage;
- Resource *mHandleHoverImage;
+ ImageResource *mBackgroundImage;
+ ImageResource *mHandleImage;
+ ImageResource *mHandleHoverImage;
};
class MouseCursor : public RenderObject
@@ -1067,11 +1060,20 @@ private:
bool m_moved;
float m_speedMultiplier;
COLOR m_color;
- Resource *m_image;
+ ImageResource *m_image;
bool m_present;
};
// Helper APIs
+std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue = "");
+int LoadAttrInt(xml_node<>* element, const char* attrname, int defaultvalue = 0);
+int LoadAttrIntScaleX(xml_node<>* element, const char* attrname, int defaultvalue = 0);
+int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalue = 0);
+COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue = COLOR(0,0,0,0));
+FontResource* LoadAttrFont(xml_node<>* element, const char* attrname);
+ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname);
+AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname);
+
bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
#endif // _OBJECTS_HEADER
diff --git a/gui/pages.cpp b/gui/pages.cpp
index 47e2edde8..58e99e60c 100644
--- a/gui/pages.cpp
+++ b/gui/pages.cpp
@@ -70,7 +70,7 @@ int ConvertStrToColor(std::string str, COLOR* color)
DataManager::GetValue(str, str);
// Look for some defaults
- if (str == "black") return 0;
+ if (str == "black") return 0;
else if (str == "white") { color->red = color->green = color->blue = 255; return 0; }
else if (str == "red") { color->red = 255; return 0; }
else if (str == "green") { color->green = 255; return 0; }
@@ -103,52 +103,94 @@ int ConvertStrToColor(std::string str, COLOR* color)
}
// Helper APIs
+std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue)
+{
+ if (!element)
+ return defaultvalue;
+
+ xml_attribute<>* attr = element->first_attribute(attrname);
+ return attr ? attr->value() : defaultvalue;
+}
+
+int LoadAttrInt(xml_node<>* element, const char* attrname, int defaultvalue)
+{
+ string value = LoadAttrString(element, attrname);
+ // resolve variables
+ DataManager::GetValue(value, value);
+ return value.empty() ? defaultvalue : atoi(value.c_str());
+}
+
+int LoadAttrIntScaleX(xml_node<>* element, const char* attrname, int defaultvalue)
+{
+ return scale_theme_x(LoadAttrInt(element, attrname, defaultvalue));
+}
+
+int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalue)
+{
+ return scale_theme_y(LoadAttrInt(element, attrname, defaultvalue));
+}
+
+COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue)
+{
+ string value = LoadAttrString(element, attrname);
+ // resolve variables
+ DataManager::GetValue(value, value);
+ COLOR ret = defaultvalue;
+ if (ConvertStrToColor(value, &ret) == 0)
+ return ret;
+ else
+ return defaultvalue;
+}
+
+FontResource* LoadAttrFont(xml_node<>* element, const char* attrname)
+{
+ std::string name = LoadAttrString(element, attrname, "");
+ if (name.empty())
+ return NULL;
+ else
+ return (FontResource*) PageManager::FindResource(name);
+ // TODO: make resource lookup type-safe
+}
+
+ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname)
+{
+ std::string name = LoadAttrString(element, attrname, "");
+ if (name.empty())
+ return NULL;
+ else
+ return (ImageResource*) PageManager::FindResource(name);
+ // TODO: make resource lookup type-safe
+}
+
+AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname)
+{
+ std::string name = LoadAttrString(element, attrname, "");
+ if (name.empty())
+ return NULL;
+ else
+ return (AnimationResource*) PageManager::FindResource(name);
+ // TODO: make resource lookup type-safe
+}
+
bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w /* = NULL */, int* h /* = NULL */, RenderObject::Placement* placement /* = NULL */)
{
if (!node)
return false;
- std::string value;
if (node->first_attribute("x"))
- {
- value = node->first_attribute("x")->value();
- DataManager::GetValue(value, value);
- *x = atol(value.c_str());
- *x = scale_theme_x(*x);
- *x += tw_x_offset;
- }
+ *x = LoadAttrIntScaleX(node, "x") + tw_x_offset;
if (node->first_attribute("y"))
- {
- value = node->first_attribute("y")->value();
- DataManager::GetValue(value, value);
- *y = atol(value.c_str());
- *y = scale_theme_y(*y);
- *y += tw_y_offset;
- }
+ *y = LoadAttrIntScaleY(node, "y") + tw_y_offset;
if (w && node->first_attribute("w"))
- {
- value = node->first_attribute("w")->value();
- DataManager::GetValue(value, value);
- *w = atol(value.c_str());
- *w = scale_theme_x(*w);
- }
+ *w = LoadAttrIntScaleX(node, "w");
if (h && node->first_attribute("h"))
- {
- value = node->first_attribute("h")->value();
- DataManager::GetValue(value, value);
- *h = atol(value.c_str());
- *h = scale_theme_y(*h);
- }
+ *h = LoadAttrIntScaleY(node, "h");
if (placement && node->first_attribute("placement"))
- {
- value = node->first_attribute("placement")->value();
- DataManager::GetValue(value, value);
- *placement = (RenderObject::Placement) atol(value.c_str());
- }
+ *placement = (RenderObject::Placement) LoadAttrInt(node, "placement");
return true;
}
diff --git a/gui/pages.hpp b/gui/pages.hpp
index b042c0db8..31ccadb51 100644
--- a/gui/pages.hpp
+++ b/gui/pages.hpp
@@ -17,12 +17,15 @@ enum TOUCH_STATE {
TOUCH_REPEAT = 4
};
-typedef struct {
+struct COLOR {
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
-} COLOR;
+ COLOR() : red(0), green(0), blue(0), alpha(0) {}
+ COLOR(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
+ : red(r), green(g), blue(b), alpha(a) {}
+};
// Utility Functions
int ConvertStrToColor(std::string str, COLOR* color);
diff --git a/gui/partitionlist.cpp b/gui/partitionlist.cpp
index 97f6e4ec5..8facfe7e5 100644
--- a/gui/partitionlist.cpp
+++ b/gui/partitionlist.cpp
@@ -35,7 +35,6 @@ GUIPartitionList::GUIPartitionList(xml_node<>* node) : GUIScrollList(node)
xml_attribute<>* attr;
xml_node<>* child;
- int mIconWidth = 0, mIconHeight = 0, mSelectedIconHeight = 0, mSelectedIconWidth = 0, mUnselectedIconHeight = 0, mUnselectedIconWidth = 0;
mIconSelected = mIconUnselected = NULL;
mUpdate = 0;
updateList = false;
@@ -43,12 +42,8 @@ GUIPartitionList::GUIPartitionList(xml_node<>* node) : GUIScrollList(node)
child = node->first_node("icon");
if (child)
{
- attr = child->first_attribute("selected");
- if (attr)
- mIconSelected = PageManager::FindResource(attr->value());
- attr = child->first_attribute("unselected");
- if (attr)
- mIconUnselected = PageManager::FindResource(attr->value());
+ mIconSelected = LoadAttrImage(child, "selected");
+ mIconUnselected = LoadAttrImage(child, "unselected");
}
// Handle the result variable
@@ -63,25 +58,9 @@ GUIPartitionList::GUIPartitionList(xml_node<>* node) : GUIScrollList(node)
selectedList = attr->value();
}
- if (mIconSelected && mIconSelected->GetResource())
- {
- mSelectedIconWidth = gr_get_width(mIconSelected->GetResource());
- mSelectedIconHeight = gr_get_height(mIconSelected->GetResource());
- if (mSelectedIconHeight > mIconHeight)
- mIconHeight = mSelectedIconHeight;
- mIconWidth = mSelectedIconWidth;
- }
-
- if (mIconUnselected && mIconUnselected->GetResource())
- {
- mUnselectedIconWidth = gr_get_width(mIconUnselected->GetResource());
- mUnselectedIconHeight = gr_get_height(mIconUnselected->GetResource());
- if (mUnselectedIconHeight > mIconHeight)
- mIconHeight = mUnselectedIconHeight;
- if (mUnselectedIconWidth > mIconWidth)
- mIconWidth = mUnselectedIconWidth;
- }
- SetMaxIconSize(mIconWidth, mIconHeight);
+ int iconWidth = std::max(mIconSelected->GetWidth(), mIconUnselected->GetWidth());
+ int iconHeight = std::max(mIconSelected->GetHeight(), mIconUnselected->GetHeight());
+ SetMaxIconSize(iconWidth, iconHeight);
child = node->first_node("listtype");
if (child && (attr = child->first_attribute("name"))) {
@@ -218,7 +197,7 @@ size_t GUIPartitionList::GetItemCount()
return mList.size();
}
-int GUIPartitionList::GetListItem(size_t item_index, Resource*& icon, std::string &text)
+int GUIPartitionList::GetListItem(size_t item_index, ImageResource*& icon, std::string &text)
{
text = mList.at(item_index).Display_Name;
if (mList.at(item_index).selected)
diff --git a/gui/progressbar.cpp b/gui/progressbar.cpp
index a4d132932..a49e0abb2 100644
--- a/gui/progressbar.cpp
+++ b/gui/progressbar.cpp
@@ -45,13 +45,8 @@ GUIProgressBar::GUIProgressBar(xml_node<>* node) : GUIObject(node)
child = node->first_node("resource");
if (child)
{
- attr = child->first_attribute("empty");
- if (attr)
- mEmptyBar = PageManager::FindResource(attr->value());
-
- attr = child->first_attribute("full");
- if (attr)
- mFullBar = PageManager::FindResource(attr->value());
+ mEmptyBar = LoadAttrImage(child, "empty");
+ mFullBar = LoadAttrImage(child, "full");
}
// Load the placement
@@ -61,23 +56,13 @@ GUIProgressBar::GUIProgressBar(xml_node<>* node) : GUIObject(node)
child = node->first_node("data");
if (child)
{
- attr = child->first_attribute("min");
- if (attr) mMinValVar = attr->value();
-
- attr = child->first_attribute("max");
- if (attr) mMaxValVar = attr->value();
-
- attr = child->first_attribute("name");
- if (attr) mCurValVar = attr->value();
- }
-
- if (mEmptyBar && mEmptyBar->GetResource())
- {
- mRenderW = gr_get_width(mEmptyBar->GetResource());
- mRenderH = gr_get_height(mEmptyBar->GetResource());
+ mMinValVar = LoadAttrString(child, "min");
+ mMaxValVar = LoadAttrString(child, "max");
+ mCurValVar = LoadAttrString(child, "name");
}
- return;
+ mRenderW = mEmptyBar->GetWidth();
+ mRenderH = mEmptyBar->GetHeight();
}
int GUIProgressBar::Render(void)
diff --git a/gui/resources.cpp b/gui/resources.cpp
index d9f2741d7..e0016fc7b 100644
--- a/gui/resources.cpp
+++ b/gui/resources.cpp
@@ -314,7 +314,8 @@ void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip)
{
LOGERR("Resource type (%s) not supported.\n", type.c_str());
}
- if (res == NULL || res->GetResource() == NULL)
+
+ if (res == NULL || !res->loadedOK())
{
std::string res_name;
if (child->first_attribute("name"))
diff --git a/gui/resources.hpp b/gui/resources.hpp
index cc5e7b6ff..69d24279f 100644
--- a/gui/resources.hpp
+++ b/gui/resources.hpp
@@ -17,8 +17,8 @@ public:
virtual ~Resource() {}
public:
- virtual void* GetResource(void) = 0;
- std::string GetName(void) { return mName; }
+ std::string GetName() { return mName; }
+ virtual bool loadedOK() = 0;
private:
std::string mName;
@@ -44,7 +44,10 @@ public:
virtual ~FontResource();
public:
- virtual void* GetResource(void) { return mFont; }
+ void* GetResource() { return this ? mFont : NULL; }
+ int GetHeight() { return gr_getMaxFontHeight(this ? mFont : NULL); }
+
+ virtual bool loadedOK() { return mFont != NULL; }
protected:
void* mFont;
@@ -58,7 +61,11 @@ public:
virtual ~ImageResource();
public:
- virtual void* GetResource(void) { return mSurface; }
+ gr_surface GetResource() { return this ? mSurface : NULL; }
+ int GetWidth() { return gr_get_width(this ? mSurface : NULL); }
+ int GetHeight() { return gr_get_height(this ? mSurface : NULL); }
+
+ virtual bool loadedOK() { return mSurface != NULL; }
protected:
gr_surface mSurface;
@@ -71,9 +78,12 @@ public:
virtual ~AnimationResource();
public:
- virtual void* GetResource(void) { return mSurfaces.empty() ? NULL : mSurfaces.at(0); }
- virtual void* GetResource(int entry) { return mSurfaces.empty() ? NULL : mSurfaces.at(entry); }
- virtual int GetResourceCount(void) { return mSurfaces.size(); }
+ gr_surface GetResource() { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(0); }
+ gr_surface GetResource(int entry) { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(entry); }
+ int GetWidth() { return gr_get_width(this ? GetResource() : NULL); }
+ int GetHeight() { return gr_get_height(this ? GetResource() : NULL); }
+ int GetResourceCount() { return mSurfaces.size(); }
+ virtual bool loadedOK() { return !mSurfaces.empty(); }
protected:
std::vector<gr_surface> mSurfaces;
diff --git a/gui/scrolllist.cpp b/gui/scrolllist.cpp
index eb66de8e5..822fa7644 100644
--- a/gui/scrolllist.cpp
+++ b/gui/scrolllist.cpp
@@ -41,7 +41,8 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
firstDisplayedItem = mItemSpacing = mFontHeight = mSeparatorH = y_offset = scrollingSpeed = 0;
maxIconWidth = maxIconHeight = mHeaderIconHeight = mHeaderIconWidth = 0;
mHeaderSeparatorH = mHeaderIsStatic = mHeaderH = actualItemHeight = 0;
- mBackground = mFont = mHeaderIcon = NULL;
+ mBackground = mHeaderIcon = NULL;
+ mFont = NULL;
mBackgroundW = mBackgroundH = 0;
mFastScrollW = mFastScrollLineW = mFastScrollRectW = mFastScrollRectH = 0;
lastY = last2Y = fastScroll = 0;
@@ -63,9 +64,7 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
child = node->first_node("header");
if (child)
{
- attr = child->first_attribute("icon");
- if (attr)
- mHeaderIcon = PageManager::FindResource(attr->value());
+ mHeaderIcon = LoadAttrImage(child, "icon");
attr = child->first_attribute("background");
if (attr)
@@ -119,9 +118,7 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
child = node->first_node("background");
if (child)
{
- attr = child->first_attribute("resource");
- if (attr)
- mBackground = PageManager::FindResource(attr->value());
+ mBackground = LoadAttrImage(child, "resource");
attr = child->first_attribute("color");
if (attr)
{
@@ -140,9 +137,7 @@ GUIScrollList::GUIScrollList(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");
attr = child->first_attribute("color");
if (attr)
@@ -229,13 +224,13 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
}
// Retrieve the line height
- mFontHeight = gr_getMaxFontHeight(mFont ? mFont->GetResource() : NULL);
+ mFontHeight = mFont->GetHeight();
mHeaderH = mFontHeight;
if (mHeaderIcon && mHeaderIcon->GetResource())
{
- mHeaderIconWidth = gr_get_width(mHeaderIcon->GetResource());
- mHeaderIconHeight = gr_get_height(mHeaderIcon->GetResource());
+ mHeaderIconWidth = mHeaderIcon->GetWidth();
+ mHeaderIconHeight = mHeaderIcon->GetHeight();
if (mHeaderIconHeight > mHeaderH)
mHeaderH = mHeaderIconHeight;
if (mHeaderIconWidth > maxIconWidth)
@@ -252,8 +247,8 @@ GUIScrollList::GUIScrollList(xml_node<>* node) : GUIObject(node)
if (mBackground && mBackground->GetResource())
{
- mBackgroundW = gr_get_width(mBackground->GetResource());
- mBackgroundH = gr_get_height(mBackground->GetResource());
+ mBackgroundW = mBackground->GetWidth();
+ mBackgroundH = mBackground->GetHeight();
}
}
@@ -349,7 +344,7 @@ int GUIScrollList::Render(void)
break;
// get item data
- Resource* icon;
+ ImageResource* icon;
std::string label;
if (GetListItem(itemindex, icon, label))
break;
@@ -373,8 +368,8 @@ int GUIScrollList::Render(void)
}
if (icon && icon->GetResource()) {
- int currentIconHeight = gr_get_height(icon->GetResource());
- int currentIconWidth = gr_get_width(icon->GetResource());
+ int currentIconHeight = icon->GetHeight();
+ int currentIconWidth = icon->GetWidth();
int currentIconOffsetY = (int)((actualItemHeight - currentIconHeight) / 2);
int currentIconOffsetX = (maxIconWidth - currentIconWidth) / 2;
int rect_y = 0, image_y = (yPos + currentIconOffsetY);
@@ -405,11 +400,10 @@ int GUIScrollList::Render(void)
// Now, we need the header (icon + text)
yPos = mRenderY;
{
- Resource* headerIcon;
int mIconOffsetX = 0;
// render the icon if it exists
- headerIcon = mHeaderIcon;
+ ImageResource* headerIcon = mHeaderIcon;
if (headerIcon && headerIcon->GetResource())
{
gr_blit(headerIcon->GetResource(), 0, 0, mHeaderIconWidth, mHeaderIconHeight, mRenderX + ((mHeaderIconWidth - maxIconWidth) / 2), (yPos + (int)((mHeaderH - mHeaderIconHeight) / 2)));
diff --git a/gui/slider.cpp b/gui/slider.cpp
index 98d2ddea3..c53dabc28 100644
--- a/gui/slider.cpp
+++ b/gui/slider.cpp
@@ -47,31 +47,20 @@ GUISlider::GUISlider(xml_node<>* node) : GUIObject(node)
child = node->first_node("resource");
if (child)
{
- attr = child->first_attribute("base");
- if (attr)
- sSlider = PageManager::FindResource(attr->value());
-
- attr = child->first_attribute("used");
- if (attr)
- sSliderUsed = PageManager::FindResource(attr->value());
-
- attr = child->first_attribute("touch");
- if (attr)
- sTouch = PageManager::FindResource(attr->value());
+ sSlider = LoadAttrImage(child, "base");
+ sSliderUsed = LoadAttrImage(child, "used");
+ sTouch = LoadAttrImage(child, "touch");
}
// Load the placement
LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY);
- if (sSlider && sSlider->GetResource())
- {
- mRenderW = gr_get_width(sSlider->GetResource());
- mRenderH = gr_get_height(sSlider->GetResource());
- }
+ mRenderW = sSlider->GetWidth();
+ mRenderH = sSlider->GetHeight();
if (sTouch && sTouch->GetResource())
{
- sTouchW = gr_get_width(sTouch->GetResource()); // Width of the "touch image" that follows the touch (arrow)
- sTouchH = gr_get_height(sTouch->GetResource()); // Height of the "touch image" that follows the touch (arrow)
+ sTouchW = sTouch->GetWidth(); // Width of the "touch image" that follows the touch (arrow)
+ sTouchH = sTouch->GetHeight(); // Height of the "touch image" that follows the touch (arrow)
}
//LOGINFO("mRenderW: %i mTouchW: %i\n", mRenderW, mTouchW);
diff --git a/gui/slidervalue.cpp b/gui/slidervalue.cpp
index 7c38e329e..5be58dcf3 100644
--- a/gui/slidervalue.cpp
+++ b/gui/slidervalue.cpp
@@ -73,16 +73,8 @@ GUISliderValue::GUISliderValue(xml_node<>* node) : GUIObject(node)
child = node->first_node("font");
if (child)
{
- attr = child->first_attribute("resource");
- if (attr)
- mFont = PageManager::FindResource(attr->value());
-
- attr = child->first_attribute("color");
- if (attr)
- {
- std::string color = attr->value();
- ConvertStrToColor(color, &mTextColor);
- }
+ mFont = LoadAttrFont(child, "resource");
+ mTextColor = LoadAttrColor(child, "color", mTextColor);
}
// Load the placement
@@ -103,17 +95,9 @@ GUISliderValue::GUISliderValue(xml_node<>* node) : GUIObject(node)
child = node->first_node("resource");
if (child)
{
- attr = child->first_attribute("background");
- if(attr)
- mBackgroundImage = PageManager::FindResource(attr->value());
-
- attr = child->first_attribute("handle");
- if(attr)
- mHandleImage = PageManager::FindResource(attr->value());
-
- attr = child->first_attribute("handlehover");
- if(attr)
- mHandleHoverImage = PageManager::FindResource(attr->value());
+ mBackgroundImage = LoadAttrImage(child, "background");
+ mHandleImage = LoadAttrImage(child, "handle");
+ mHandleHoverImage = LoadAttrImage(child, "handlehover");
}
child = node->first_node("data");
@@ -199,7 +183,7 @@ GUISliderValue::GUISliderValue(xml_node<>* node) : GUIObject(node)
}
}
- mFontHeight = gr_getMaxFontHeight(mFont ? mFont->GetResource() : NULL);
+ mFontHeight = mFont->GetHeight();
if(mShowCurr)
{
@@ -277,8 +261,8 @@ int GUISliderValue::SetRenderPos(int x, int y, int w, int h)
if(mBackgroundImage && mBackgroundImage->GetResource())
{
- mLineW = gr_get_width(mBackgroundImage->GetResource());
- mLineH = gr_get_height(mBackgroundImage->GetResource());
+ mLineW = mBackgroundImage->GetWidth();
+ mLineH = mBackgroundImage->GetHeight();
}
else
mLineW = mRenderW - (mLinePadding * 2);
diff --git a/gui/text.cpp b/gui/text.cpp
index 29d7ad948..cc18b170f 100644
--- a/gui/text.cpp
+++ b/gui/text.cpp
@@ -28,9 +28,6 @@ extern "C" {
GUIText::GUIText(xml_node<>* node)
: GUIObject(node)
{
- xml_attribute<>* attr;
- xml_node<>* child;
-
mFont = NULL;
mIsStatic = 1;
mVarChanged = 0;
@@ -38,53 +35,21 @@ GUIText::GUIText(xml_node<>* node)
maxWidth = 0;
charSkip = 0;
isHighlighted = false;
- hasHighlightColor = false;
if (!node)
return;
- // Initialize color to solid black
- memset(&mColor, 0, sizeof(COLOR));
- mColor.alpha = 255;
- memset(&mHighlightColor, 0, sizeof(COLOR));
- mHighlightColor.alpha = 255;
-
- attr = node->first_attribute("color");
- if (attr)
- {
- std::string color = attr->value();
- ConvertStrToColor(color, &mColor);
- }
- attr = node->first_attribute("highlightcolor");
- if (attr)
- {
- std::string color = attr->value();
- ConvertStrToColor(color, &mHighlightColor);
- hasHighlightColor = true;
- }
+ // Load colors
+ mColor = LoadAttrColor(node, "color", COLOR(0,0,0,255));
+ mHighlightColor = LoadAttrColor(node, "highlightcolor", mColor);
// Load the font, and possibly override the color
- child = node->first_node("font");
+ xml_node<>* child = node->first_node("font");
if (child)
{
- attr = child->first_attribute("resource");
- if (attr)
- mFont = PageManager::FindResource(attr->value());
-
- attr = child->first_attribute("color");
- if (attr)
- {
- std::string color = attr->value();
- ConvertStrToColor(color, &mColor);
- }
-
- attr = child->first_attribute("highlightcolor");
- if (attr)
- {
- std::string color = attr->value();
- ConvertStrToColor(color, &mHighlightColor);
- hasHighlightColor = true;
- }
+ mFont = LoadAttrFont(child, "resource");
+ mColor = LoadAttrColor(child, "color", mColor);
+ mHighlightColor = LoadAttrColor(child, "highlightcolor", mColor);
}
// Load the placement
@@ -97,8 +62,7 @@ GUIText::GUIText(xml_node<>* node)
mLastValue = parseText();
if (mLastValue != mText) mIsStatic = 0;
- mFontHeight = gr_getMaxFontHeight(mFont ? mFont->GetResource() : NULL);
- return;
+ mFontHeight = mFont->GetHeight();
}
int GUIText::Render(void)
@@ -107,13 +71,11 @@ int GUIText::Render(void)
return 0;
void* fontResource = NULL;
- string displayValue;
-
if (mFont)
fontResource = mFont->GetResource();
mLastValue = parseText();
- displayValue = mLastValue;
+ string displayValue = mLastValue;
if (charSkip)
displayValue.erase(0, charSkip);
@@ -138,7 +100,7 @@ int GUIText::Render(void)
y -= mFontHeight;
}
- if (hasHighlightColor && isHighlighted)
+ if (isHighlighted)
gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
else
gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);