blob: 018c2cab2a11c33269f768004a6996eedc2865f4 [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:
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -050081 PageSet(const char* xmlFile);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020082 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040083
84public:
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -050085 int Load(ZipArchive* package, char* xmlFile);
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 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;
Ethan Yonker1c273312015-03-16 12:18:56 -0500116 std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400117};
118
119class PageManager
120{
121public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200122 // Used by GUI
Ethan Yonker561c58d2015-10-05 08:48:22 -0500123 static char* LoadFileToBuffer(std::string filename, ZipArchive* package);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200124 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);
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500128 static int RunReload();
129 static void RequestReload();
Dees_Troy51a0e822012-09-05 15:24:24 -0400130
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200131 // Used for actions and pages
132 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400133 static int ChangeOverlay(std::string name);
that74ac6062015-03-04 22:39:34 +0100134 static const ResourceManager* GetResources();
Dees_Troy51a0e822012-09-05 15:24:24 -0400135
Ethan Yonker03a42f62014-08-08 11:03:51 -0500136 // Used for console-only mode
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 static int SwitchToConsole(void);
Ethan Yonker03a42f62014-08-08 11:03:51 -0500138 static int EndConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400139
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200140 // Helper to identify if a particular page is the active page
141 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400142
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200143 // These are routing routines
144 static int Render(void);
145 static int Update(void);
146 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100147 static int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400148 static int NotifyKeyboard(int key);
149 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200150 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400151
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100152 static MouseCursor *GetMouseCursor();
153 static void LoadCursorData(xml_node<>* node);
154
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100155 static HardwareKeyboard *GetHardwareKeyboard();
156
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600157 static xml_node<>* FindStyle(std::string name);
158
Dees_Troy51a0e822012-09-05 15:24:24 -0400159protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400161
162protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200163 static std::map<std::string, PageSet*> mPageSets;
164 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400165 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100166 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100167 static HardwareKeyboard *mHardwareKeyboard;
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500168 static bool mReloadTheme;
169 static std::string mStartPage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400170};
171
Dees_Troye4a88112012-12-18 21:29:33 +0000172#endif // _PAGES_HEADER_HPP