blob: 4bfd5b0e5b554e02defa5de7ff9fe29a919576d8 [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
that6a894592016-03-13 17:51:28 +010091struct LoadingContext;
92
Dees_Troy51a0e822012-09-05 15:24:24 -040093class PageSet
94{
95public:
that6a894592016-03-13 17:51:28 +010096 PageSet();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020097 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040098
99public:
that6a894592016-03-13 17:51:28 +0100100 int Load(LoadingContext& ctx, const std::string& filename);
Ethan Yonker74db1572015-10-28 12:44:49 -0500101 int LoadLanguage(char* languageFile, ZipArchive* package);
that6a894592016-03-13 17:51:28 +0100102 void MakeEmergencyConsoleIfNeeded();
Dees_Troy51a0e822012-09-05 15:24:24 -0400103
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200104 Page* FindPage(std::string name);
105 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400106 int SetOverlay(Page* page);
that74ac6062015-03-04 22:39:34 +0100107 const ResourceManager* GetResources();
Dees_Troy51a0e822012-09-05 15:24:24 -0400108
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 // Helper routine for identifing if we're the current page
110 int IsCurrentPage(Page* page);
that10ae24f2015-12-26 20:53:51 +0100111 std::string GetCurrentPage() const;
Dees_Troy51a0e822012-09-05 15:24:24 -0400112
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200113 // These are routing routines
114 int Render(void);
115 int Update(void);
116 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100117 int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +0100118 int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400119 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200120 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400121
Ethan Yonker74db1572015-10-28 12:44:49 -0500122 void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600123
Dees_Troy51a0e822012-09-05 15:24:24 -0400124protected:
that6a894592016-03-13 17:51:28 +0100125 int LoadDetails(LoadingContext& ctx, xml_node<>* root);
126 int LoadPages(LoadingContext& ctx, xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200127 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -0400128
129protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200130 ResourceManager* mResources;
131 std::vector<Page*> mPages;
132 Page* mCurrentPage;
Ethan Yonker1c273312015-03-16 12:18:56 -0500133 std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400134};
135
136class PageManager
137{
138public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200139 // Used by GUI
Ethan Yonker561c58d2015-10-05 08:48:22 -0500140 static char* LoadFileToBuffer(std::string filename, ZipArchive* package);
Ethan Yonker74db1572015-10-28 12:44:49 -0500141 static void LoadLanguageList(ZipArchive* package);
142 static void LoadLanguage(std::string filename);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200143 static int LoadPackage(std::string name, std::string package, std::string startpage);
144 static PageSet* SelectPackage(std::string name);
145 static int ReloadPackage(std::string name, std::string package);
146 static void ReleasePackage(std::string name);
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500147 static int RunReload();
148 static void RequestReload();
Ethan Yonkerafde0982016-01-23 08:55:35 -0600149 static void SetStartPage(const std::string& page_name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400150
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200151 // Used for actions and pages
152 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400153 static int ChangeOverlay(std::string name);
that74ac6062015-03-04 22:39:34 +0100154 static const ResourceManager* GetResources();
that10ae24f2015-12-26 20:53:51 +0100155 static std::string GetCurrentPage();
Dees_Troy51a0e822012-09-05 15:24:24 -0400156
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200157 // Helper to identify if a particular page is the active page
158 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400159
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 // These are routing routines
161 static int Render(void);
162 static int Update(void);
163 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100164 static int NotifyKey(int key, bool down);
that8834a0f2016-01-05 23:29:30 +0100165 static int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400166 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200167 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400168
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100169 static MouseCursor *GetMouseCursor();
170 static void LoadCursorData(xml_node<>* node);
171
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100172 static HardwareKeyboard *GetHardwareKeyboard();
173
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600174 static xml_node<>* FindStyle(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500175 static void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600176
Dees_Troy51a0e822012-09-05 15:24:24 -0400177protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200178 static PageSet* FindPackage(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500179 static void LoadLanguageListDir(std::string dir);
180 static void Translate_Partition(const char* path, const char* resource_name, const char* default_value);
181 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);
182 static void Translate_Partition_Display_Names();
Dees_Troy51a0e822012-09-05 15:24:24 -0400183
184protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200185 static std::map<std::string, PageSet*> mPageSets;
186 static PageSet* mCurrentSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100187 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100188 static HardwareKeyboard *mHardwareKeyboard;
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500189 static bool mReloadTheme;
190 static std::string mStartPage;
that6a894592016-03-13 17:51:28 +0100191 static LoadingContext* currentLoadingContext;
Dees_Troy51a0e822012-09-05 15:24:24 -0400192};
193
Dees_Troye4a88112012-12-18 21:29:33 +0000194#endif // _PAGES_HEADER_HPP