blob: a55211cb850982c4e8711f2e7cf6b6a9d8fa7c3b [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001// pages.hpp - Base classes for page manager of GUI
2
3#ifndef _PAGES_HEADER
4#define _PAGES_HEADER
5
6typedef struct {
7 unsigned char red;
8 unsigned char green;
9 unsigned char blue;
10 unsigned char alpha;
11} COLOR;
12
13// Utility Functions
14int ConvertStrToColor(std::string str, COLOR* color);
15int gui_forceRender(void);
16int gui_changePage(std::string newPage);
17int gui_changeOverlay(std::string newPage);
18std::string gui_parse_text(string inText);
19
20class Resource;
21class ResourceManager;
22class RenderObject;
23class ActionObject;
24class InputObject;
25
26class Page
27{
28public:
29 virtual ~Page() {}
30
31public:
32 Page(xml_node<>* page, xml_node<>* templates = NULL);
33 std::string GetName(void) { return mName; }
34
35public:
36 virtual int Render(void);
37 virtual int Update(void);
38 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
39 virtual int NotifyKey(int key);
40 virtual int NotifyKeyboard(int key);
41 virtual int SetKeyBoardFocus(int inFocus);
42 virtual int NotifyVarChange(std::string varName, std::string value);
43 virtual void SetPageFocus(int inFocus);
44
45protected:
46 std::string mName;
47 std::vector<RenderObject*> mRenders;
48 std::vector<ActionObject*> mActions;
49 std::vector<InputObject*> mInputs;
50
51 ActionObject* mTouchStart;
52 COLOR mBackground;
53
54protected:
55 bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
56};
57
58class PageSet
59{
60public:
61 PageSet(char* xmlFile);
62 virtual ~PageSet();
63
64public:
65 int Load(ZipArchive* package);
66
67 Page* FindPage(std::string name);
68 int SetPage(std::string page);
69 int SetOverlay(Page* page);
70 Resource* FindResource(std::string name);
71
72 // Helper routine for identifing if we're the current page
73 int IsCurrentPage(Page* page);
74
75 // These are routing routines
76 int Render(void);
77 int Update(void);
78 int NotifyTouch(TOUCH_STATE state, int x, int y);
79 int NotifyKey(int key);
80 int NotifyKeyboard(int key);
81 int SetKeyBoardFocus(int inFocus);
82 int NotifyVarChange(std::string varName, std::string value);
83
84protected:
85 int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
86 int LoadVariables(xml_node<>* vars);
87
88protected:
89 char* mXmlFile;
90 xml_document<> mDoc;
91 ResourceManager* mResources;
92 std::vector<Page*> mPages;
93 Page* mCurrentPage;
94 Page* mOverlayPage; // This is a special case, used for "locking" the screen
95};
96
97class PageManager
98{
99public:
100 // Used by GUI
101 static int LoadPackage(std::string name, std::string package, std::string startpage);
102 static PageSet* SelectPackage(std::string name);
103 static int ReloadPackage(std::string name, std::string package);
104 static void ReleasePackage(std::string name);
105
106 // Used for actions and pages
107 static int ChangePage(std::string name);
108 static int ChangeOverlay(std::string name);
109 static Resource* FindResource(std::string name);
110 static Resource* FindResource(std::string package, std::string name);
111
112 // Used for console-only mode - Can be reverted via ChangePage
113 static int SwitchToConsole(void);
114
115 // Helper to identify if a particular page is the active page
116 static int IsCurrentPage(Page* page);
117
118 // These are routing routines
119 static int Render(void);
120 static int Update(void);
121 static int NotifyTouch(TOUCH_STATE state, int x, int y);
122 static int NotifyKey(int key);
123 static int NotifyKeyboard(int key);
124 static int SetKeyBoardFocus(int inFocus);
125 static int NotifyVarChange(std::string varName, std::string value);
126
127protected:
128 static PageSet* FindPackage(std::string name);
129
130protected:
131 static std::map<std::string, PageSet*> mPageSets;
132 static PageSet* mCurrentSet;
133 static PageSet* mBaseSet;
134};
135
136#endif // _PAGES_HEADER
137