blob: b042c0db8dafef6a232ead03037b7c76266fccf0 [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
Dees_Troy51a0e822012-09-05 15:24:24 -040020typedef struct {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020021 unsigned char red;
22 unsigned char green;
23 unsigned char blue;
24 unsigned char alpha;
Dees_Troy51a0e822012-09-05 15:24:24 -040025} COLOR;
26
27// Utility Functions
28int ConvertStrToColor(std::string str, COLOR* color);
29int gui_forceRender(void);
30int gui_changePage(std::string newPage);
31int gui_changeOverlay(std::string newPage);
32std::string gui_parse_text(string inText);
33
34class Resource;
35class ResourceManager;
36class RenderObject;
37class ActionObject;
38class InputObject;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010039class MouseCursor;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010040class GUIObject;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010041class HardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -040042
43class Page
44{
45public:
Ethan Yonker780cd392014-07-21 15:24:39 -050046 Page(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL);
Vojtech Bocekbfb63342014-02-08 00:32:31 +010047 virtual ~Page();
48
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040050
51public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020052 virtual int Render(void);
53 virtual int Update(void);
54 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010055 virtual int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -040056 virtual int NotifyKeyboard(int key);
57 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020058 virtual int NotifyVarChange(std::string varName, std::string value);
59 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040060
61protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020062 std::string mName;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010063 std::vector<GUIObject*> mObjects;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020064 std::vector<RenderObject*> mRenders;
65 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040066 std::vector<InputObject*> mInputs;
67
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020068 ActionObject* mTouchStart;
69 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040070
71protected:
Ethan Yonker780cd392014-07-21 15:24:39 -050072 bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL, int depth = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040073};
74
75class PageSet
76{
77public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 PageSet(char* xmlFile);
79 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040080
81public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020082 int Load(ZipArchive* package);
Ethan Yonker780cd392014-07-21 15:24:39 -050083 int CheckInclude(ZipArchive* package, xml_document<> *parentDoc);
Dees_Troy51a0e822012-09-05 15:24:24 -040084
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 Page* FindPage(std::string name);
86 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040087 int SetOverlay(Page* page);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020088 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040089
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020090 // Helper routine for identifing if we're the current page
91 int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -040092
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020093 // These are routing routines
94 int Render(void);
95 int Update(void);
96 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010097 int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -040098 int NotifyKeyboard(int key);
99 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400101
102protected:
Ethan Yonker780cd392014-07-21 15:24:39 -0500103 int LoadPages(xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200104 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
106protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200107 char* mXmlFile;
108 xml_document<> mDoc;
109 ResourceManager* mResources;
110 std::vector<Page*> mPages;
Ethan Yonker780cd392014-07-21 15:24:39 -0500111 std::vector<xml_node<>*> templates;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200112 Page* mCurrentPage;
113 Page* mOverlayPage; // This is a special case, used for "locking" the screen
Vojtech Boceke979abd2015-01-12 18:29:12 +0100114 std::vector<xml_document<>*> mIncludedDocs;
Dees_Troy51a0e822012-09-05 15:24:24 -0400115};
116
117class PageManager
118{
119public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200120 // Used by GUI
121 static int LoadPackage(std::string name, std::string package, std::string startpage);
122 static PageSet* SelectPackage(std::string name);
123 static int ReloadPackage(std::string name, std::string package);
124 static void ReleasePackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400125
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200126 // Used for actions and pages
127 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400128 static int ChangeOverlay(std::string name);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200129 static Resource* FindResource(std::string name);
130 static Resource* FindResource(std::string package, std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400131
Ethan Yonker03a42f62014-08-08 11:03:51 -0500132 // Used for console-only mode
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200133 static int SwitchToConsole(void);
Ethan Yonker03a42f62014-08-08 11:03:51 -0500134 static int EndConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400135
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200136 // Helper to identify if a particular page is the active page
137 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400138
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200139 // These are routing routines
140 static int Render(void);
141 static int Update(void);
142 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100143 static int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400144 static int NotifyKeyboard(int key);
145 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200146 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400147
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100148 static MouseCursor *GetMouseCursor();
149 static void LoadCursorData(xml_node<>* node);
150
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100151 static HardwareKeyboard *GetHardwareKeyboard();
152
Dees_Troy51a0e822012-09-05 15:24:24 -0400153protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200154 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400155
156protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200157 static std::map<std::string, PageSet*> mPageSets;
158 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400159 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100160 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100161 static HardwareKeyboard *mHardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -0400162};
163
Dees_Troye4a88112012-12-18 21:29:33 +0000164#endif // _PAGES_HEADER_HPP