blob: b2f25801f19a6180e28c3ec03b4821f158c2e728 [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>
Ethan Yonker74db1572015-10-28 12:44:49 -05009#include <string>
thatfb759d42015-01-11 12:16:53 +010010#include "rapidxml.hpp"
Ethan Yonker74db1572015-10-28 12:44:49 -050011#include "gui.hpp"
thatfb759d42015-01-11 12:16:53 +010012using namespace rapidxml;
13
14enum TOUCH_STATE {
15 TOUCH_START = 0,
16 TOUCH_DRAG = 1,
17 TOUCH_RELEASE = 2,
18 TOUCH_HOLD = 3,
19 TOUCH_REPEAT = 4
20};
Dees Troyb7ae0982013-09-10 20:47:35 +000021
thatf6ed8fc2015-02-14 20:23:16 +010022struct COLOR {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020023 unsigned char red;
24 unsigned char green;
25 unsigned char blue;
26 unsigned char alpha;
thatf6ed8fc2015-02-14 20:23:16 +010027 COLOR() : red(0), green(0), blue(0), alpha(0) {}
28 COLOR(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
29 : red(r), green(g), blue(b), alpha(a) {}
30};
Dees_Troy51a0e822012-09-05 15:24:24 -040031
Ethan Yonker74db1572015-10-28 12:44:49 -050032struct language_struct {
33 std::string filename;
34 std::string displayvalue;
35};
36
37extern std::vector<language_struct> Language_List;
38
Dees_Troy51a0e822012-09-05 15:24:24 -040039// Utility Functions
40int ConvertStrToColor(std::string str, COLOR* color);
41int gui_forceRender(void);
42int gui_changePage(std::string newPage);
43int gui_changeOverlay(std::string newPage);
Dees_Troy51a0e822012-09-05 15:24:24 -040044
45class Resource;
46class ResourceManager;
47class RenderObject;
48class ActionObject;
49class InputObject;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010050class MouseCursor;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010051class GUIObject;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010052class HardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -040053
54class Page
55{
56public:
thatb63e2f92015-06-27 21:35:11 +020057 Page(xml_node<>* page, std::vector<xml_node<>*> *templates);
Vojtech Bocekbfb63342014-02-08 00:32:31 +010058 virtual ~Page();
59
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020060 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040061
62public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 virtual int Render(void);
64 virtual int Update(void);
65 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010066 virtual int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +010067 virtual int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -040068 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020069 virtual int NotifyVarChange(std::string varName, std::string value);
70 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040071
72protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 std::string mName;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010074 std::vector<GUIObject*> mObjects;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020075 std::vector<RenderObject*> mRenders;
76 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040077 std::vector<InputObject*> mInputs;
78
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020079 ActionObject* mTouchStart;
80 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040081
82protected:
thatb63e2f92015-06-27 21:35:11 +020083 bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth);
Dees_Troy51a0e822012-09-05 15:24:24 -040084};
85
86class PageSet
87{
88public:
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -050089 PageSet(const char* xmlFile);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020090 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040091
92public:
Ethan Yonker74db1572015-10-28 12:44:49 -050093 int LoadLanguage(char* languageFile, ZipArchive* package);
Ethan Yonker8e5692f2016-01-21 11:21:06 -060094 int Load(ZipArchive* package, char* xmlFile, char* languageFile, char* baseLanguageFile);
Ethan Yonker780cd392014-07-21 15:24:39 -050095 int CheckInclude(ZipArchive* package, xml_document<> *parentDoc);
Dees_Troy51a0e822012-09-05 15:24:24 -040096
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020097 Page* FindPage(std::string name);
98 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040099 int SetOverlay(Page* page);
that74ac6062015-03-04 22:39:34 +0100100 const ResourceManager* GetResources();
Dees_Troy51a0e822012-09-05 15:24:24 -0400101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 // Helper routine for identifing if we're the current page
103 int IsCurrentPage(Page* page);
that10ae24f2015-12-26 20:53:51 +0100104 std::string GetCurrentPage() const;
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 // These are routing routines
107 int Render(void);
108 int Update(void);
109 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100110 int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +0100111 int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400112 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200113 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400114
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600115 std::vector<xml_node<>*> styles;
Ethan Yonker74db1572015-10-28 12:44:49 -0500116 void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600117
Dees_Troy51a0e822012-09-05 15:24:24 -0400118protected:
Ethan Yonker780cd392014-07-21 15:24:39 -0500119 int LoadPages(xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200120 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -0400121
122protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200123 ResourceManager* mResources;
124 std::vector<Page*> mPages;
Ethan Yonker780cd392014-07-21 15:24:39 -0500125 std::vector<xml_node<>*> templates;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200126 Page* mCurrentPage;
Ethan Yonker1c273312015-03-16 12:18:56 -0500127 std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400128};
129
130class PageManager
131{
132public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200133 // Used by GUI
Ethan Yonker561c58d2015-10-05 08:48:22 -0500134 static char* LoadFileToBuffer(std::string filename, ZipArchive* package);
Ethan Yonker74db1572015-10-28 12:44:49 -0500135 static void LoadLanguageList(ZipArchive* package);
136 static void LoadLanguage(std::string filename);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 static int LoadPackage(std::string name, std::string package, std::string startpage);
138 static PageSet* SelectPackage(std::string name);
139 static int ReloadPackage(std::string name, std::string package);
140 static void ReleasePackage(std::string name);
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500141 static int RunReload();
142 static void RequestReload();
Dees_Troy51a0e822012-09-05 15:24:24 -0400143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 // Used for actions and pages
145 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400146 static int ChangeOverlay(std::string name);
that74ac6062015-03-04 22:39:34 +0100147 static const ResourceManager* GetResources();
that10ae24f2015-12-26 20:53:51 +0100148 static std::string GetCurrentPage();
Dees_Troy51a0e822012-09-05 15:24:24 -0400149
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200150 // Helper to identify if a particular page is the active page
151 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400152
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200153 // These are routing routines
154 static int Render(void);
155 static int Update(void);
156 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100157 static int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +0100158 static int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400159 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400161
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100162 static MouseCursor *GetMouseCursor();
163 static void LoadCursorData(xml_node<>* node);
164
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100165 static HardwareKeyboard *GetHardwareKeyboard();
166
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600167 static xml_node<>* FindStyle(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500168 static void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600169
Dees_Troy51a0e822012-09-05 15:24:24 -0400170protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200171 static PageSet* FindPackage(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500172 static void LoadLanguageListDir(std::string dir);
173 static void Translate_Partition(const char* path, const char* resource_name, const char* default_value);
174 static void Translate_Partition(const char* path, const char* resource_name, const char* default_value, const char* storage_resource_name, const char* storage_default_value);
175 static void Translate_Partition_Display_Names();
Dees_Troy51a0e822012-09-05 15:24:24 -0400176
177protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200178 static std::map<std::string, PageSet*> mPageSets;
179 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400180 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100181 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100182 static HardwareKeyboard *mHardwareKeyboard;
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500183 static bool mReloadTheme;
184 static std::string mStartPage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400185};
186
Dees_Troye4a88112012-12-18 21:29:33 +0000187#endif // _PAGES_HEADER_HPP