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); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 67 | virtual int NotifyKeyboard(int key); |
| 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); |
| 94 | int Load(ZipArchive* package, char* xmlFile, char* languageFile); |
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); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 104 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 105 | // These are routing routines |
| 106 | int Render(void); |
| 107 | int Update(void); |
| 108 | int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 109 | int NotifyKey(int key, bool down); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 110 | int NotifyKeyboard(int key); |
| 111 | int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 112 | int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 113 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 114 | std::vector<xml_node<>*> styles; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 115 | 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] | 116 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 117 | protected: |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 118 | int LoadPages(xml_node<>* pages); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 119 | int LoadVariables(xml_node<>* vars); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 120 | |
| 121 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 122 | ResourceManager* mResources; |
| 123 | std::vector<Page*> mPages; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 124 | std::vector<xml_node<>*> templates; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 125 | Page* mCurrentPage; |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 126 | 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] | 127 | }; |
| 128 | |
| 129 | class PageManager |
| 130 | { |
| 131 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 132 | // Used by GUI |
Ethan Yonker | 561c58d | 2015-10-05 08:48:22 -0500 | [diff] [blame] | 133 | static char* LoadFileToBuffer(std::string filename, ZipArchive* package); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 134 | static void LoadLanguageList(ZipArchive* package); |
| 135 | static void LoadLanguage(std::string filename); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 136 | 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 Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 140 | static int RunReload(); |
| 141 | static void RequestReload(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 142 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 143 | // Used for actions and pages |
| 144 | static int ChangePage(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 145 | static int ChangeOverlay(std::string name); |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 146 | static const ResourceManager* GetResources(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 147 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 148 | // Used for console-only mode |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 149 | static int SwitchToConsole(void); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 150 | static int EndConsole(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 151 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 152 | // Helper to identify if a particular page is the active page |
| 153 | static int IsCurrentPage(Page* page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 154 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 155 | // 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 Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 159 | static int NotifyKey(int key, bool down); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 160 | static int NotifyKeyboard(int key); |
| 161 | static int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 162 | static int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 163 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 164 | static MouseCursor *GetMouseCursor(); |
| 165 | static void LoadCursorData(xml_node<>* node); |
| 166 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 167 | static HardwareKeyboard *GetHardwareKeyboard(); |
| 168 | |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 169 | static xml_node<>* FindStyle(std::string name); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 170 | 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] | 171 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 172 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 173 | static PageSet* FindPackage(std::string name); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 174 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 178 | |
| 179 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 180 | static std::map<std::string, PageSet*> mPageSets; |
| 181 | static PageSet* mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 182 | static PageSet* mBaseSet; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 183 | static MouseCursor *mMouseCursor; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 184 | static HardwareKeyboard *mHardwareKeyboard; |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 185 | static bool mReloadTheme; |
| 186 | static std::string mStartPage; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 187 | }; |
| 188 | |
Dees_Troy | e4a8811 | 2012-12-18 21:29:33 +0000 | [diff] [blame] | 189 | #endif // _PAGES_HEADER_HPP |