blob: c308c1a5c15a28ce0f172984e6706ca2d02052b4 [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001// pages.hpp - Base classes for page manager of GUI
2
Dees_Troye4a88112012-12-18 21:29:33 +00003#ifndef _PAGES_HEADER_HPP
4#define _PAGES_HEADER_HPP
Dees_Troy51a0e822012-09-05 15:24:24 -04005
6typedef struct {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02007 unsigned char red;
8 unsigned char green;
9 unsigned char blue;
10 unsigned char alpha;
Dees_Troy51a0e822012-09-05 15:24:24 -040011} 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:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020029 virtual ~Page() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040030
31public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020032 Page(xml_node<>* page, xml_node<>* templates = NULL);
33 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040034
35public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020036 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);
Dees_Troy51a0e822012-09-05 15:24:24 -040040 virtual int NotifyKeyboard(int key);
41 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020042 virtual int NotifyVarChange(std::string varName, std::string value);
43 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040044
45protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020046 std::string mName;
47 std::vector<RenderObject*> mRenders;
48 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040049 std::vector<InputObject*> mInputs;
50
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020051 ActionObject* mTouchStart;
52 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040053
54protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040056};
57
58class PageSet
59{
60public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020061 PageSet(char* xmlFile);
62 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040063
64public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020065 int Load(ZipArchive* package);
Dees_Troy51a0e822012-09-05 15:24:24 -040066
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067 Page* FindPage(std::string name);
68 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040069 int SetOverlay(Page* page);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040071
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020072 // Helper routine for identifing if we're the current page
73 int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -040074
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020075 // 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);
Dees_Troy51a0e822012-09-05 15:24:24 -040080 int NotifyKeyboard(int key);
81 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020082 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -040083
84protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
86 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -040087
88protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020089 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
Dees_Troy51a0e822012-09-05 15:24:24 -040095};
96
97class PageManager
98{
99public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 // 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);
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 // Used for actions and pages
107 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400108 static int ChangeOverlay(std::string name);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 static Resource* FindResource(std::string name);
110 static Resource* FindResource(std::string package, std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400111
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200112 // Used for console-only mode - Can be reverted via ChangePage
113 static int SwitchToConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400114
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200115 // Helper to identify if a particular page is the active page
116 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400117
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200118 // 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);
Dees_Troy51a0e822012-09-05 15:24:24 -0400123 static int NotifyKeyboard(int key);
124 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200125 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400126
127protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200128 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400129
130protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200131 static std::map<std::string, PageSet*> mPageSets;
132 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400133 static PageSet* mBaseSet;
134};
135
Dees_Troye4a88112012-12-18 21:29:33 +0000136#endif // _PAGES_HEADER_HPP