blob: 31ccadb516fb5921e31166ce0fb1793f5ac78739 [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
Dees Troyb7ae0982013-09-10 20:47:35 +00006#include "../minzip/Zip.h"
thatfb759d42015-01-11 12:16:53 +01007#include <vector>
8#include <map>
9#include "rapidxml.hpp"
10using namespace rapidxml;
11
12enum TOUCH_STATE {
13 TOUCH_START = 0,
14 TOUCH_DRAG = 1,
15 TOUCH_RELEASE = 2,
16 TOUCH_HOLD = 3,
17 TOUCH_REPEAT = 4
18};
Dees Troyb7ae0982013-09-10 20:47:35 +000019
thatf6ed8fc2015-02-14 20:23:16 +010020struct COLOR {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020021 unsigned char red;
22 unsigned char green;
23 unsigned char blue;
24 unsigned char alpha;
thatf6ed8fc2015-02-14 20:23:16 +010025 COLOR() : red(0), green(0), blue(0), alpha(0) {}
26 COLOR(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
27 : red(r), green(g), blue(b), alpha(a) {}
28};
Dees_Troy51a0e822012-09-05 15:24:24 -040029
30// Utility Functions
31int ConvertStrToColor(std::string str, COLOR* color);
32int gui_forceRender(void);
33int gui_changePage(std::string newPage);
34int gui_changeOverlay(std::string newPage);
35std::string gui_parse_text(string inText);
36
37class Resource;
38class ResourceManager;
39class RenderObject;
40class ActionObject;
41class InputObject;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010042class MouseCursor;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010043class GUIObject;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010044class HardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -040045
46class Page
47{
48public:
Ethan Yonker780cd392014-07-21 15:24:39 -050049 Page(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL);
Vojtech Bocekbfb63342014-02-08 00:32:31 +010050 virtual ~Page();
51
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020052 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040053
54public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 virtual int Render(void);
56 virtual int Update(void);
57 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010058 virtual int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -040059 virtual int NotifyKeyboard(int key);
60 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020061 virtual int NotifyVarChange(std::string varName, std::string value);
62 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040063
64protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020065 std::string mName;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010066 std::vector<GUIObject*> mObjects;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067 std::vector<RenderObject*> mRenders;
68 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040069 std::vector<InputObject*> mInputs;
70
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020071 ActionObject* mTouchStart;
72 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040073
74protected:
Ethan Yonker780cd392014-07-21 15:24:39 -050075 bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL, int depth = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040076};
77
78class PageSet
79{
80public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 PageSet(char* xmlFile);
82 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040083
84public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 int Load(ZipArchive* package);
Ethan Yonker780cd392014-07-21 15:24:39 -050086 int CheckInclude(ZipArchive* package, xml_document<> *parentDoc);
Dees_Troy51a0e822012-09-05 15:24:24 -040087
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020088 Page* FindPage(std::string name);
89 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040090 int SetOverlay(Page* page);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020091 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040092
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020093 // Helper routine for identifing if we're the current page
94 int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -040095
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096 // These are routing routines
97 int Render(void);
98 int Update(void);
99 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100100 int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400101 int NotifyKeyboard(int key);
102 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200103 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400104
105protected:
Ethan Yonker780cd392014-07-21 15:24:39 -0500106 int LoadPages(xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200107 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -0400108
109protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200110 char* mXmlFile;
111 xml_document<> mDoc;
112 ResourceManager* mResources;
113 std::vector<Page*> mPages;
Ethan Yonker780cd392014-07-21 15:24:39 -0500114 std::vector<xml_node<>*> templates;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200115 Page* mCurrentPage;
116 Page* mOverlayPage; // This is a special case, used for "locking" the screen
Vojtech Boceke979abd2015-01-12 18:29:12 +0100117 std::vector<xml_document<>*> mIncludedDocs;
Dees_Troy51a0e822012-09-05 15:24:24 -0400118};
119
120class PageManager
121{
122public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200123 // Used by GUI
124 static int LoadPackage(std::string name, std::string package, std::string startpage);
125 static PageSet* SelectPackage(std::string name);
126 static int ReloadPackage(std::string name, std::string package);
127 static void ReleasePackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400128
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200129 // Used for actions and pages
130 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400131 static int ChangeOverlay(std::string name);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200132 static Resource* FindResource(std::string name);
133 static Resource* FindResource(std::string package, std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400134
Ethan Yonker03a42f62014-08-08 11:03:51 -0500135 // Used for console-only mode
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200136 static int SwitchToConsole(void);
Ethan Yonker03a42f62014-08-08 11:03:51 -0500137 static int EndConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400138
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200139 // Helper to identify if a particular page is the active page
140 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400141
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200142 // These are routing routines
143 static int Render(void);
144 static int Update(void);
145 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100146 static int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400147 static int NotifyKeyboard(int key);
148 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400150
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100151 static MouseCursor *GetMouseCursor();
152 static void LoadCursorData(xml_node<>* node);
153
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100154 static HardwareKeyboard *GetHardwareKeyboard();
155
Dees_Troy51a0e822012-09-05 15:24:24 -0400156protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200157 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400158
159protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 static std::map<std::string, PageSet*> mPageSets;
161 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400162 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100163 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100164 static HardwareKeyboard *mHardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -0400165};
166
Dees_Troye4a88112012-12-18 21:29:33 +0000167#endif // _PAGES_HEADER_HPP