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/objects.hpp b/gui/objects.hpp
index 5eae919..537de20 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -211,13 +211,12 @@
 	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 @@
 	bool isHighlighted;
 
 protected:
-	Resource* mImage;
-	Resource* mHighlightImage;
+	ImageResource* mImage;
+	ImageResource* mHighlightImage;
 };
 
 // GUIFill - Used for fill colors
@@ -402,8 +401,8 @@
 		request_show
 	};
 
-	Resource* mFont;
-	Resource* mSlideoutImage;
+	FontResource* mFont;
+	ImageResource* mSlideoutImage;
 	COLOR mForegroundColor;
 	COLOR mBackgroundColor;
 	COLOR mScrollColor;
@@ -453,7 +452,7 @@
 
 protected:
 	GUIImage* mButtonImg;
-	Resource* mButtonIcon;
+	ImageResource* mButtonIcon;
 	GUIText* mButtonLabel;
 	GUIAction* mAction;
 	int mTextX, mTextY, mTextW, mTextH;
@@ -491,8 +490,8 @@
 	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 @@
 	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 @@
 	// 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:
 	// 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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	std::string selectedList;
 	std::string currentValue;
 	std::string mLastValue;
-	Resource* mIconSelected;
-	Resource* mIconUnselected;
+	ImageResource* mIconSelected;
+	ImageResource* mIconUnselected;
 	bool updateList;
 };
 
@@ -785,8 +778,8 @@
 	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 @@
 
 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 @@
 		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:
 	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 @@
 	float mValuePct;
 	std::string mMaxStr;
 	std::string mMinStr;
-	Resource *mFont;
+	FontResource *mFont;
 	GUIText* mLabel;
 	int mLabelW;
 	COLOR mTextColor;
@@ -1041,9 +1034,9 @@
 	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 @@
 	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