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 | |
| 37 | extern std::vector<language_struct> Language_List; |
| 38 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 39 | // Utility Functions |
| 40 | int ConvertStrToColor(std::string str, COLOR* color); |
| 41 | int gui_forceRender(void); |
| 42 | int gui_changePage(std::string newPage); |
| 43 | int gui_changeOverlay(std::string newPage); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 44 | |
| 45 | class Resource; |
| 46 | class ResourceManager; |
| 47 | class RenderObject; |
| 48 | class ActionObject; |
| 49 | class InputObject; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 50 | class MouseCursor; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 51 | class GUIObject; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 52 | class HardwareKeyboard; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 53 | |
| 54 | class Page |
| 55 | { |
| 56 | public: |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 57 | Page(xml_node<>* page, std::vector<xml_node<>*> *templates); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 58 | virtual ~Page(); |
| 59 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 60 | std::string GetName(void) { return mName; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 61 | |
| 62 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 63 | virtual int Render(void); |
| 64 | virtual int Update(void); |
| 65 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 66 | virtual int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 67 | virtual int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 68 | virtual int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 69 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 70 | virtual void SetPageFocus(int inFocus); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 71 | |
| 72 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 73 | std::string mName; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 74 | std::vector<GUIObject*> mObjects; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 75 | std::vector<RenderObject*> mRenders; |
| 76 | std::vector<ActionObject*> mActions; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 77 | std::vector<InputObject*> mInputs; |
| 78 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 79 | ActionObject* mTouchStart; |
| 80 | COLOR mBackground; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 81 | |
| 82 | protected: |
that | b63e2f9 | 2015-06-27 21:35:11 +0200 | [diff] [blame] | 83 | bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates, int depth); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | class PageSet |
| 87 | { |
| 88 | public: |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 89 | PageSet(const char* xmlFile); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 90 | virtual ~PageSet(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 91 | |
| 92 | public: |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 93 | int LoadLanguage(char* languageFile, ZipArchive* package); |
Ethan Yonker | 8e5692f | 2016-01-21 11:21:06 -0600 | [diff] [blame] | 94 | int Load(ZipArchive* package, char* xmlFile, char* languageFile, char* baseLanguageFile); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 95 | int CheckInclude(ZipArchive* package, xml_document<> *parentDoc); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 96 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 97 | Page* FindPage(std::string name); |
| 98 | int SetPage(std::string page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 99 | int SetOverlay(Page* page); |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 100 | const ResourceManager* GetResources(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 101 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 102 | // Helper routine for identifing if we're the current page |
| 103 | int IsCurrentPage(Page* page); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 104 | std::string GetCurrentPage() const; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 105 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 106 | // These are routing routines |
| 107 | int Render(void); |
| 108 | int Update(void); |
| 109 | int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 110 | int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 111 | int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 112 | int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 113 | int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 114 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 115 | std::vector<xml_node<>*> styles; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 116 | 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] | 117 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 118 | protected: |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 119 | int LoadPages(xml_node<>* pages); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 120 | int LoadVariables(xml_node<>* vars); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 121 | |
| 122 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 123 | ResourceManager* mResources; |
| 124 | std::vector<Page*> mPages; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 125 | std::vector<xml_node<>*> templates; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 126 | Page* mCurrentPage; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 127 | 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] | 128 | }; |
| 129 | |
| 130 | class PageManager |
| 131 | { |
| 132 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 133 | // Used by GUI |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 134 | static char* LoadFileToBuffer(std::string filename, ZipArchive* package); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 135 | static void LoadLanguageList(ZipArchive* package); |
| 136 | static void LoadLanguage(std::string filename); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 137 | 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 Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 141 | static int RunReload(); |
| 142 | static void RequestReload(); |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 143 | static void SetStartPage(const std::string& page_name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 144 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 145 | // Used for actions and pages |
| 146 | static int ChangePage(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 147 | static int ChangeOverlay(std::string name); |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 148 | static const ResourceManager* GetResources(); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 149 | static std::string GetCurrentPage(); |
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 | // Helper to identify if a particular page is the active page |
| 152 | static int IsCurrentPage(Page* page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 153 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 154 | // These are routing routines |
| 155 | static int Render(void); |
| 156 | static int Update(void); |
| 157 | static int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 158 | static int NotifyKey(int key, bool down); |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 159 | static int NotifyCharInput(int ch); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 160 | static int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 161 | static int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 162 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 163 | static MouseCursor *GetMouseCursor(); |
| 164 | static void LoadCursorData(xml_node<>* node); |
| 165 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 166 | static HardwareKeyboard *GetHardwareKeyboard(); |
| 167 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 168 | static xml_node<>* FindStyle(std::string name); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 169 | 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] | 170 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 171 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 172 | static PageSet* FindPackage(std::string name); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 173 | static void LoadLanguageListDir(std::string dir); |
| 174 | static void Translate_Partition(const char* path, const char* resource_name, const char* default_value); |
| 175 | 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); |
| 176 | static void Translate_Partition_Display_Names(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 177 | |
| 178 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 179 | static std::map<std::string, PageSet*> mPageSets; |
| 180 | static PageSet* mCurrentSet; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 181 | static MouseCursor *mMouseCursor; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 182 | static HardwareKeyboard *mHardwareKeyboard; |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 183 | static bool mReloadTheme; |
| 184 | static std::string mStartPage; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 185 | }; |
| 186 | |
Dees_Troy | e4a8811 | 2012-12-18 21:29:33 +0000 | [diff] [blame] | 187 | #endif // _PAGES_HEADER_HPP |