blob: 03fb0e5de701115746613590846e68ea3752c448 [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:
thatb63e2f92015-06-27 21:35:11 +020049 Page(xml_node<>* page, std::vector<xml_node<>*> *templates);
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:
thatb63e2f92015-06-27 21:35:11 +020075 bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth);
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);
that74ac6062015-03-04 22:39:34 +010091 const ResourceManager* GetResources();
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
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600105 std::vector<xml_node<>*> styles;
106
Dees_Troy51a0e822012-09-05 15:24:24 -0400107protected:
Ethan Yonker780cd392014-07-21 15:24:39 -0500108 int LoadPages(xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -0400110
111protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200112 char* mXmlFile;
113 xml_document<> mDoc;
114 ResourceManager* mResources;
115 std::vector<Page*> mPages;
Ethan Yonker780cd392014-07-21 15:24:39 -0500116 std::vector<xml_node<>*> templates;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200117 Page* mCurrentPage;
Ethan Yonker1c273312015-03-16 12:18:56 -0500118 std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen
Vojtech Boceke979abd2015-01-12 18:29:12 +0100119 std::vector<xml_document<>*> mIncludedDocs;
Dees_Troy51a0e822012-09-05 15:24:24 -0400120};
121
122class PageManager
123{
124public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200125 // Used by GUI
Ethan Yonker561c58d2015-10-05 08:48:22 -0500126 static char* LoadFileToBuffer(std::string filename, ZipArchive* package);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200127 static int LoadPackage(std::string name, std::string package, std::string startpage);
128 static PageSet* SelectPackage(std::string name);
129 static int ReloadPackage(std::string name, std::string package);
130 static void ReleasePackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400131
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200132 // Used for actions and pages
133 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400134 static int ChangeOverlay(std::string name);
that74ac6062015-03-04 22:39:34 +0100135 static const ResourceManager* GetResources();
Dees_Troy51a0e822012-09-05 15:24:24 -0400136
Ethan Yonker03a42f62014-08-08 11:03:51 -0500137 // Used for console-only mode
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200138 static int SwitchToConsole(void);
Ethan Yonker03a42f62014-08-08 11:03:51 -0500139 static int EndConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400140
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200141 // Helper to identify if a particular page is the active page
142 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 // These are routing routines
145 static int Render(void);
146 static int Update(void);
147 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100148 static int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400149 static int NotifyKeyboard(int key);
150 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200151 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400152
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100153 static MouseCursor *GetMouseCursor();
154 static void LoadCursorData(xml_node<>* node);
155
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100156 static HardwareKeyboard *GetHardwareKeyboard();
157
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600158 static xml_node<>* FindStyle(std::string name);
159
Dees_Troy51a0e822012-09-05 15:24:24 -0400160protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200161 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400162
163protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200164 static std::map<std::string, PageSet*> mPageSets;
165 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400166 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100167 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100168 static HardwareKeyboard *mHardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -0400169};
170
Dees_Troye4a88112012-12-18 21:29:33 +0000171#endif // _PAGES_HEADER_HPP