blob: 5dcc9e0b52451f8601ad3206b3f6782ff0ce55ad [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);
Dees_Troy51a0e822012-09-05 15:24:24 -040067 virtual int NotifyKeyboard(int key);
68 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);
94 int Load(ZipArchive* package, char* xmlFile, char* languageFile);
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);
Dees_Troy51a0e822012-09-05 15:24:24 -0400104
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200105 // These are routing routines
106 int Render(void);
107 int Update(void);
108 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100109 int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400110 int NotifyKeyboard(int key);
111 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200112 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400113
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600114 std::vector<xml_node<>*> styles;
Ethan Yonker74db1572015-10-28 12:44:49 -0500115 void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600116
Dees_Troy51a0e822012-09-05 15:24:24 -0400117protected:
Ethan Yonker780cd392014-07-21 15:24:39 -0500118 int LoadPages(xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200119 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -0400120
121protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200122 ResourceManager* mResources;
123 std::vector<Page*> mPages;
Ethan Yonker780cd392014-07-21 15:24:39 -0500124 std::vector<xml_node<>*> templates;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200125 Page* mCurrentPage;
Ethan Yonker1c273312015-03-16 12:18:56 -0500126 std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400127};
128
129class PageManager
130{
131public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200132 // Used by GUI
Ethan Yonker561c58d2015-10-05 08:48:22 -0500133 static char* LoadFileToBuffer(std::string filename, ZipArchive* package);
Ethan Yonker74db1572015-10-28 12:44:49 -0500134 static void LoadLanguageList(ZipArchive* package);
135 static void LoadLanguage(std::string filename);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200136 static int LoadPackage(std::string name, std::string package, std::string startpage);
137 static PageSet* SelectPackage(std::string name);
138 static int ReloadPackage(std::string name, std::string package);
139 static void ReleasePackage(std::string name);
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500140 static int RunReload();
141 static void RequestReload();
Dees_Troy51a0e822012-09-05 15:24:24 -0400142
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200143 // Used for actions and pages
144 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400145 static int ChangeOverlay(std::string name);
that74ac6062015-03-04 22:39:34 +0100146 static const ResourceManager* GetResources();
Dees_Troy51a0e822012-09-05 15:24:24 -0400147
Ethan Yonker03a42f62014-08-08 11:03:51 -0500148 // Used for console-only mode
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 static int SwitchToConsole(void);
Ethan Yonker03a42f62014-08-08 11:03:51 -0500150 static int EndConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400151
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200152 // Helper to identify if a particular page is the active page
153 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400154
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200155 // These are routing routines
156 static int Render(void);
157 static int Update(void);
158 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100159 static int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400160 static int NotifyKeyboard(int key);
161 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200162 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400163
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100164 static MouseCursor *GetMouseCursor();
165 static void LoadCursorData(xml_node<>* node);
166
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100167 static HardwareKeyboard *GetHardwareKeyboard();
168
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600169 static xml_node<>* FindStyle(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500170 static void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600171
Dees_Troy51a0e822012-09-05 15:24:24 -0400172protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200173 static PageSet* FindPackage(std::string name);
Ethan Yonker74db1572015-10-28 12:44:49 -0500174 static void LoadLanguageListDir(std::string dir);
175 static void Translate_Partition(const char* path, const char* resource_name, const char* default_value);
176 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);
177 static void Translate_Partition_Display_Names();
Dees_Troy51a0e822012-09-05 15:24:24 -0400178
179protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200180 static std::map<std::string, PageSet*> mPageSets;
181 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400182 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100183 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100184 static HardwareKeyboard *mHardwareKeyboard;
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500185 static bool mReloadTheme;
186 static std::string mStartPage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400187};
188
Dees_Troye4a88112012-12-18 21:29:33 +0000189#endif // _PAGES_HEADER_HPP