Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | // pages.hpp - Base classes for page manager of GUI |
| 2 | |
Dees_Troy | e4a8811 | 2012-12-18 21:29:33 +0000 | [diff] [blame] | 3 | #ifndef _PAGES_HEADER_HPP |
| 4 | #define _PAGES_HEADER_HPP |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 5 | |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 6 | #include "../minzip/Zip.h" |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 7 | #include <vector> |
| 8 | #include <map> |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 9 | #include <string> |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 10 | #include "rapidxml.hpp" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 11 | #include "gui.hpp" |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 12 | using namespace rapidxml; |
| 13 | |
| 14 | enum TOUCH_STATE { |
| 15 | TOUCH_START = 0, |
| 16 | TOUCH_DRAG = 1, |
| 17 | TOUCH_RELEASE = 2, |
| 18 | TOUCH_HOLD = 3, |
| 19 | TOUCH_REPEAT = 4 |
| 20 | }; |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 21 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 22 | struct COLOR { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 23 | unsigned char red; |
| 24 | unsigned char green; |
| 25 | unsigned char blue; |
| 26 | unsigned char alpha; |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 27 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 31 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 32 | struct language_struct { |
| 33 | std::string filename; |
| 34 | std::string displayvalue; |
| 35 | }; |
| 36 | |
Xuefer | cac6ace | 2016-02-01 02:28:55 +0800 | [diff] [blame] | 37 | inline bool operator < (const language_struct& language1, const language_struct& language2) |
| 38 | { |
| 39 | return language1.displayvalue < language2.displayvalue; |
| 40 | } |
| 41 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 42 | extern std::vector<language_struct> Language_List; |
| 43 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 44 | // Utility Functions |
| 45 | int ConvertStrToColor(std::string str, COLOR* color); |
| 46 | int gui_forceRender(void); |
| 47 | int gui_changePage(std::string newPage); |
| 48 | int gui_changeOverlay(std::string newPage); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | |
| 50 | class Resource; |
| 51 | class ResourceManager; |
| 52 | class RenderObject; |
| 53 | class ActionObject; |
| 54 | class InputObject; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 55 | class MouseCursor; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 56 | class GUIObject; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 57 | class HardwareKeyboard; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 58 | |
| 59 | class Page |
| 60 | { |
| 61 | public: |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 62 | Page(xml_node<>* page, std::vector<xml_node<>*> *templates); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 63 | virtual ~Page(); |
| 64 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 65 | std::string GetName(void) { return mName; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 66 | |
| 67 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 68 | virtual int Render(void); |
| 69 | virtual int Update(void); |
| 70 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 71 | virtual int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 72 | virtual int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 73 | virtual int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 74 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 75 | virtual void SetPageFocus(int inFocus); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | |
| 77 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 78 | std::string mName; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 79 | std::vector<GUIObject*> mObjects; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 80 | std::vector<RenderObject*> mRenders; |
| 81 | std::vector<ActionObject*> mActions; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 82 | std::vector<InputObject*> mInputs; |
| 83 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 84 | ActionObject* mTouchStart; |
| 85 | COLOR mBackground; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 86 | |
| 87 | protected: |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 88 | bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 89 | }; |
| 90 | |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 91 | struct LoadingContext; |
| 92 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 93 | class PageSet |
| 94 | { |
| 95 | public: |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 96 | PageSet(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 97 | virtual ~PageSet(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 98 | |
| 99 | public: |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 100 | int Load(LoadingContext& ctx, const std::string& filename); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 101 | int LoadLanguage(char* languageFile, ZipArchive* package); |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 102 | void MakeEmergencyConsoleIfNeeded(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 103 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 104 | Page* FindPage(std::string name); |
| 105 | int SetPage(std::string page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 106 | int SetOverlay(Page* page); |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 107 | const ResourceManager* GetResources(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 108 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 109 | // Helper routine for identifing if we're the current page |
| 110 | int IsCurrentPage(Page* page); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 111 | std::string GetCurrentPage() const; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 112 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 113 | // These are routing routines |
| 114 | int Render(void); |
| 115 | int Update(void); |
| 116 | int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 117 | int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 118 | int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 119 | int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 120 | int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 121 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 122 | void AddStringResource(std::string resource_source, std::string resource_name, std::string value); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 123 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 124 | protected: |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 125 | int LoadDetails(LoadingContext& ctx, xml_node<>* root); |
| 126 | int LoadPages(LoadingContext& ctx, xml_node<>* pages); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 127 | int LoadVariables(xml_node<>* vars); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 128 | |
| 129 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 130 | ResourceManager* mResources; |
| 131 | std::vector<Page*> mPages; |
| 132 | Page* mCurrentPage; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 133 | std::vector<Page*> mOverlays; // Special case for popup dialogs and the lock screen |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | class PageManager |
| 137 | { |
| 138 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 139 | // Used by GUI |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 140 | static char* LoadFileToBuffer(std::string filename, ZipArchive* package); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 141 | static void LoadLanguageList(ZipArchive* package); |
| 142 | static void LoadLanguage(std::string filename); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 143 | 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 Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 147 | static int RunReload(); |
| 148 | static void RequestReload(); |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 149 | static void SetStartPage(const std::string& page_name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 150 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 151 | // Used for actions and pages |
| 152 | static int ChangePage(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 153 | static int ChangeOverlay(std::string name); |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 154 | static const ResourceManager* GetResources(); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 155 | static std::string GetCurrentPage(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 156 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 157 | // Helper to identify if a particular page is the active page |
| 158 | static int IsCurrentPage(Page* page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 159 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 160 | // 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 Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 164 | static int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 165 | static int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 166 | static int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 167 | static int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 168 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 169 | static MouseCursor *GetMouseCursor(); |
| 170 | static void LoadCursorData(xml_node<>* node); |
| 171 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 172 | static HardwareKeyboard *GetHardwareKeyboard(); |
| 173 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 174 | static xml_node<>* FindStyle(std::string name); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 175 | static void AddStringResource(std::string resource_source, std::string resource_name, std::string value); |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 176 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 177 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 178 | static PageSet* FindPackage(std::string name); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 179 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 183 | |
| 184 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 185 | static std::map<std::string, PageSet*> mPageSets; |
| 186 | static PageSet* mCurrentSet; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 187 | static MouseCursor *mMouseCursor; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 188 | static HardwareKeyboard *mHardwareKeyboard; |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 189 | static bool mReloadTheme; |
| 190 | static std::string mStartPage; |
that | 6a89459 | 2016-03-13 17:51:28 +0100 | [diff] [blame] | 191 | static LoadingContext* currentLoadingContext; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 192 | }; |
| 193 | |
Dees_Troy | e4a8811 | 2012-12-18 21:29:33 +0000 | [diff] [blame] | 194 | #endif // _PAGES_HEADER_HPP |