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> |
| 9 | #include "rapidxml.hpp" |
| 10 | using namespace rapidxml; |
| 11 | |
| 12 | enum TOUCH_STATE { |
| 13 | TOUCH_START = 0, |
| 14 | TOUCH_DRAG = 1, |
| 15 | TOUCH_RELEASE = 2, |
| 16 | TOUCH_HOLD = 3, |
| 17 | TOUCH_REPEAT = 4 |
| 18 | }; |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 19 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 20 | struct COLOR { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 21 | unsigned char red; |
| 22 | unsigned char green; |
| 23 | unsigned char blue; |
| 24 | unsigned char alpha; |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 25 | COLOR() : red(0), green(0), blue(0), alpha(0) {} |
| 26 | COLOR(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255) |
| 27 | : red(r), green(g), blue(b), alpha(a) {} |
| 28 | }; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 29 | |
| 30 | // Utility Functions |
| 31 | int ConvertStrToColor(std::string str, COLOR* color); |
| 32 | int gui_forceRender(void); |
| 33 | int gui_changePage(std::string newPage); |
| 34 | int gui_changeOverlay(std::string newPage); |
| 35 | std::string gui_parse_text(string inText); |
| 36 | |
| 37 | class Resource; |
| 38 | class ResourceManager; |
| 39 | class RenderObject; |
| 40 | class ActionObject; |
| 41 | class InputObject; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 42 | class MouseCursor; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 43 | class GUIObject; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 44 | class HardwareKeyboard; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 45 | |
| 46 | class Page |
| 47 | { |
| 48 | public: |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 49 | Page(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL); |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 50 | virtual ~Page(); |
| 51 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 52 | std::string GetName(void) { return mName; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 53 | |
| 54 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 55 | virtual int Render(void); |
| 56 | virtual int Update(void); |
| 57 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 58 | virtual int NotifyKey(int key, bool down); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | virtual int NotifyKeyboard(int key); |
| 60 | virtual int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 61 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 62 | virtual void SetPageFocus(int inFocus); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 63 | |
| 64 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 65 | std::string mName; |
Vojtech Bocek | bfb6334 | 2014-02-08 00:32:31 +0100 | [diff] [blame] | 66 | std::vector<GUIObject*> mObjects; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 67 | std::vector<RenderObject*> mRenders; |
| 68 | std::vector<ActionObject*> mActions; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 69 | std::vector<InputObject*> mInputs; |
| 70 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 71 | ActionObject* mTouchStart; |
| 72 | COLOR mBackground; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 73 | |
| 74 | protected: |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 75 | bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL, int depth = 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | class PageSet |
| 79 | { |
| 80 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 81 | PageSet(char* xmlFile); |
| 82 | virtual ~PageSet(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 83 | |
| 84 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 85 | int Load(ZipArchive* package); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 86 | int CheckInclude(ZipArchive* package, xml_document<> *parentDoc); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 87 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 88 | Page* FindPage(std::string name); |
| 89 | int SetPage(std::string page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 90 | int SetOverlay(Page* page); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 91 | Resource* FindResource(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 92 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 93 | // Helper routine for identifing if we're the current page |
| 94 | int IsCurrentPage(Page* page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 95 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 96 | // These are routing routines |
| 97 | int Render(void); |
| 98 | int Update(void); |
| 99 | int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 100 | int NotifyKey(int key, bool down); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 101 | int NotifyKeyboard(int key); |
| 102 | int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 103 | int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 104 | |
| 105 | protected: |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 106 | int LoadPages(xml_node<>* pages); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 107 | int LoadVariables(xml_node<>* vars); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 108 | |
| 109 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 110 | char* mXmlFile; |
| 111 | xml_document<> mDoc; |
| 112 | ResourceManager* mResources; |
| 113 | std::vector<Page*> mPages; |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 114 | std::vector<xml_node<>*> templates; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 115 | Page* mCurrentPage; |
| 116 | Page* mOverlayPage; // This is a special case, used for "locking" the screen |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 117 | std::vector<xml_document<>*> mIncludedDocs; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | class PageManager |
| 121 | { |
| 122 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 123 | // Used by GUI |
| 124 | static int LoadPackage(std::string name, std::string package, std::string startpage); |
| 125 | static PageSet* SelectPackage(std::string name); |
| 126 | static int ReloadPackage(std::string name, std::string package); |
| 127 | static void ReleasePackage(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 128 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 129 | // Used for actions and pages |
| 130 | static int ChangePage(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 131 | static int ChangeOverlay(std::string name); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 132 | static Resource* FindResource(std::string name); |
| 133 | static Resource* FindResource(std::string package, std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 134 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 135 | // Used for console-only mode |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 136 | static int SwitchToConsole(void); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 137 | static int EndConsole(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 138 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 139 | // Helper to identify if a particular page is the active page |
| 140 | static int IsCurrentPage(Page* page); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 141 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 142 | // These are routing routines |
| 143 | static int Render(void); |
| 144 | static int Update(void); |
| 145 | static int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 146 | static int NotifyKey(int key, bool down); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 147 | static int NotifyKeyboard(int key); |
| 148 | static int SetKeyBoardFocus(int inFocus); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 149 | static int NotifyVarChange(std::string varName, std::string value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 150 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 151 | static MouseCursor *GetMouseCursor(); |
| 152 | static void LoadCursorData(xml_node<>* node); |
| 153 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 154 | static HardwareKeyboard *GetHardwareKeyboard(); |
| 155 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 156 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 157 | static PageSet* FindPackage(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 158 | |
| 159 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 160 | static std::map<std::string, PageSet*> mPageSets; |
| 161 | static PageSet* mCurrentSet; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 162 | static PageSet* mBaseSet; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 163 | static MouseCursor *mMouseCursor; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 164 | static HardwareKeyboard *mHardwareKeyboard; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 165 | }; |
| 166 | |
Dees_Troy | e4a8811 | 2012-12-18 21:29:33 +0000 | [diff] [blame] | 167 | #endif // _PAGES_HEADER_HPP |