blob: 927f3fc015947a6991b404a5ba10487f0b286411 [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
Xuefercac6ace2016-02-01 02:28:55 +080037inline bool operator < (const language_struct& language1, const language_struct& language2)
38{
39 return language1.displayvalue < language2.displayvalue;
40}
41
Ethan Yonker74db1572015-10-28 12:44:49 -050042extern std::vector<language_struct> Language_List;
43
Dees_Troy51a0e822012-09-05 15:24:24 -040044// Utility Functions
45int ConvertStrToColor(std::string str, COLOR* color);
46int gui_forceRender(void);
47int gui_changePage(std::string newPage);
48int gui_changeOverlay(std::string newPage);
Dees_Troy51a0e822012-09-05 15:24:24 -040049
50class Resource;
51class ResourceManager;
52class RenderObject;
53class ActionObject;
54class InputObject;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010055class MouseCursor;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010056class GUIObject;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010057class HardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -040058
59class Page
60{
61public:
thatb63e2f92015-06-27 21:35:11 +020062 Page(xml_node<>* page, std::vector<xml_node<>*> *templates);
Vojtech Bocekbfb63342014-02-08 00:32:31 +010063 virtual ~Page();
64
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020065 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040066
67public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020068 virtual int Render(void);
69 virtual int Update(void);
70 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010071 virtual int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +010072 virtual int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -040073 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 virtual int NotifyVarChange(std::string varName, std::string value);
75 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040076
77protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 std::string mName;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010079 std::vector<GUIObject*> mObjects;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 std::vector<RenderObject*> mRenders;
81 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040082 std::vector<InputObject*> mInputs;
83
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020084 ActionObject* mTouchStart;
85 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040086
87protected:
thatb63e2f92015-06-27 21:35:11 +020088 bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth);
Dees_Troy51a0e822012-09-05 15:24:24 -040089};
90
91class PageSet
92{
93public:
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -050094 PageSet(const char* xmlFile);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040096
97public:
Ethan Yonker74db1572015-10-28 12:44:49 -050098 int LoadLanguage(char* languageFile, ZipArchive* package);
Ethan Yonker8e5692f2016-01-21 11:21:06 -060099 int Load(ZipArchive* package, char* xmlFile, char* languageFile, char* baseLanguageFile);
Ethan Yonker780cd392014-07-21 15:24:39 -0500100 int CheckInclude(ZipArchive* package, xml_document<> *parentDoc);
Dees_Troy51a0e822012-09-05 15:24:24 -0400101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 Page* FindPage(std::string name);
103 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400104 int SetOverlay(Page* page);
that74ac6062015-03-04 22:39:34 +0100105 const ResourceManager* GetResources();
Dees_Troy51a0e822012-09-05 15:24:24 -0400106
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200107 // Helper routine for identifing if we're the current page
108 int IsCurrentPage(Page* page);
that10ae24f2015-12-26 20:53:51 +0100109 std::string GetCurrentPage() const;
Dees_Troy51a0e822012-09-05 15:24:24 -0400110
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200111 // These are routing routines
112 int Render(void);
113 int Update(void);
114 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100115 int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +0100116 int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400117 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200118 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400119
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600120 std::vector<xml_node<>*> styles;
Ethan Yonker74db1572015-10-28 12:44:49 -0500121 void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600122
Dees_Troy51a0e822012-09-05 15:24:24 -0400123protected:
Ethan Yonker780cd392014-07-21 15:24:39 -0500124 int LoadPages(xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200125 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -0400126
127protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200128 ResourceManager* mResources;
129 std::vector<Page*> mPages;
Ethan Yonker780cd392014-07-21 15:24:39 -0500130 std::vector<xml_node<>*> templates;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200131 Page* mCurrentPage;
Ethan Yonker1c273312015-03-16 12:18:56 -0500132 std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400133};
134
135class PageManager
136{
137public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200138 // Used by GUI
Ethan Yonker561c58d2015-10-05 08:48:22 -0500139 static char* LoadFileToBuffer(std::string filename, ZipArchive* package);
Ethan Yonker74db1572015-10-28 12:44:49 -0500140 static void LoadLanguageList(ZipArchive* package);
141 static void LoadLanguage(std::string filename);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200142 static int LoadPackage(std::string name, std::string package, std::string startpage);
143 static PageSet* SelectPackage(std::string name);
144 static int ReloadPackage(std::string name, std::string package);
145 static void ReleasePackage(std::string name);
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500146 static int RunReload();
147 static void RequestReload();
Ethan Yonkerafde0982016-01-23 08:55:35 -0600148 static void SetStartPage(const std::string& page_name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400149
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200150 // Used for actions and pages
151 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400152 static int ChangeOverlay(std::string name);
that74ac6062015-03-04 22:39:34 +0100153 static const ResourceManager* GetResources();
that10ae24f2015-12-26 20:53:51 +0100154 static std::string GetCurrentPage();
Dees_Troy51a0e822012-09-05 15:24:24 -0400155
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200156 // Helper to identify if a particular page is the active page
157 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400158
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200159 // These are routing routines
160 static int Render(void);
161 static int Update(void);
162 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100163 static int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +0100164 static int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400165 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200166 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400167
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100168 static MouseCursor *GetMouseCursor();
169 static void LoadCursorData(xml_node<>* node);
170
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100171 static HardwareKeyboard *GetHardwareKeyboard();
172
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600173 static xml_node<>* FindStyle(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500174 static void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600175
Dees_Troy51a0e822012-09-05 15:24:24 -0400176protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200177 static PageSet* FindPackage(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500178 static void LoadLanguageListDir(std::string dir);
179 static void Translate_Partition(const char* path, const char* resource_name, const char* default_value);
180 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);
181 static void Translate_Partition_Display_Names();
Dees_Troy51a0e822012-09-05 15:24:24 -0400182
183protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200184 static std::map<std::string, PageSet*> mPageSets;
185 static PageSet* mCurrentSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100186 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100187 static HardwareKeyboard *mHardwareKeyboard;
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500188 static bool mReloadTheme;
189 static std::string mStartPage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400190};
191
Dees_Troye4a88112012-12-18 21:29:33 +0000192#endif // _PAGES_HEADER_HPP