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 | |
| 6 | typedef struct { |
| 7 | unsigned char red; |
| 8 | unsigned char green; |
| 9 | unsigned char blue; |
| 10 | unsigned char alpha; |
| 11 | } COLOR; |
| 12 | |
| 13 | // Utility Functions |
| 14 | int ConvertStrToColor(std::string str, COLOR* color); |
| 15 | int gui_forceRender(void); |
| 16 | int gui_changePage(std::string newPage); |
| 17 | int gui_changeOverlay(std::string newPage); |
| 18 | std::string gui_parse_text(string inText); |
| 19 | |
| 20 | class Resource; |
| 21 | class ResourceManager; |
| 22 | class RenderObject; |
| 23 | class ActionObject; |
| 24 | class InputObject; |
| 25 | |
| 26 | class Page |
| 27 | { |
| 28 | public: |
| 29 | virtual ~Page() {} |
| 30 | |
| 31 | public: |
| 32 | Page(xml_node<>* page, xml_node<>* templates = NULL); |
| 33 | std::string GetName(void) { return mName; } |
| 34 | |
| 35 | public: |
| 36 | virtual int Render(void); |
| 37 | virtual int Update(void); |
| 38 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 39 | virtual int NotifyKey(int key); |
| 40 | virtual int NotifyKeyboard(int key); |
| 41 | virtual int SetKeyBoardFocus(int inFocus); |
| 42 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 43 | virtual void SetPageFocus(int inFocus); |
| 44 | |
| 45 | protected: |
| 46 | std::string mName; |
| 47 | std::vector<RenderObject*> mRenders; |
| 48 | std::vector<ActionObject*> mActions; |
| 49 | std::vector<InputObject*> mInputs; |
| 50 | |
| 51 | ActionObject* mTouchStart; |
| 52 | COLOR mBackground; |
| 53 | |
| 54 | protected: |
| 55 | bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0); |
| 56 | }; |
| 57 | |
| 58 | class PageSet |
| 59 | { |
| 60 | public: |
| 61 | PageSet(char* xmlFile); |
| 62 | virtual ~PageSet(); |
| 63 | |
| 64 | public: |
| 65 | int Load(ZipArchive* package); |
| 66 | |
| 67 | Page* FindPage(std::string name); |
| 68 | int SetPage(std::string page); |
| 69 | int SetOverlay(Page* page); |
| 70 | Resource* FindResource(std::string name); |
| 71 | |
| 72 | // Helper routine for identifing if we're the current page |
| 73 | int IsCurrentPage(Page* page); |
| 74 | |
| 75 | // These are routing routines |
| 76 | int Render(void); |
| 77 | int Update(void); |
| 78 | int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 79 | int NotifyKey(int key); |
| 80 | int NotifyKeyboard(int key); |
| 81 | int SetKeyBoardFocus(int inFocus); |
| 82 | int NotifyVarChange(std::string varName, std::string value); |
| 83 | |
| 84 | protected: |
| 85 | int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL); |
| 86 | int LoadVariables(xml_node<>* vars); |
| 87 | |
| 88 | protected: |
| 89 | char* mXmlFile; |
| 90 | xml_document<> mDoc; |
| 91 | ResourceManager* mResources; |
| 92 | std::vector<Page*> mPages; |
| 93 | Page* mCurrentPage; |
| 94 | Page* mOverlayPage; // This is a special case, used for "locking" the screen |
| 95 | }; |
| 96 | |
| 97 | class PageManager |
| 98 | { |
| 99 | public: |
| 100 | // Used by GUI |
| 101 | static int LoadPackage(std::string name, std::string package, std::string startpage); |
| 102 | static PageSet* SelectPackage(std::string name); |
| 103 | static int ReloadPackage(std::string name, std::string package); |
| 104 | static void ReleasePackage(std::string name); |
| 105 | |
| 106 | // Used for actions and pages |
| 107 | static int ChangePage(std::string name); |
| 108 | static int ChangeOverlay(std::string name); |
| 109 | static Resource* FindResource(std::string name); |
| 110 | static Resource* FindResource(std::string package, std::string name); |
| 111 | |
| 112 | // Used for console-only mode - Can be reverted via ChangePage |
| 113 | static int SwitchToConsole(void); |
| 114 | |
| 115 | // Helper to identify if a particular page is the active page |
| 116 | static int IsCurrentPage(Page* page); |
| 117 | |
| 118 | // These are routing routines |
| 119 | static int Render(void); |
| 120 | static int Update(void); |
| 121 | static int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 122 | static int NotifyKey(int key); |
| 123 | static int NotifyKeyboard(int key); |
| 124 | static int SetKeyBoardFocus(int inFocus); |
| 125 | static int NotifyVarChange(std::string varName, std::string value); |
| 126 | |
| 127 | protected: |
| 128 | static PageSet* FindPackage(std::string name); |
| 129 | |
| 130 | protected: |
| 131 | static std::map<std::string, PageSet*> mPageSets; |
| 132 | static PageSet* mCurrentSet; |
| 133 | static PageSet* mBaseSet; |
| 134 | }; |
| 135 | |
Dees_Troy | e4a8811 | 2012-12-18 21:29:33 +0000 | [diff] [blame] | 136 | #endif // _PAGES_HEADER_HPP |