blob: f1179f53ee51b5d9e52569b26acff5a6100c01fd [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001// pages.hpp - Base classes for page manager of GUI
2
Dees_Troye4a88112012-12-18 21:29:33 +00003#ifndef _PAGES_HEADER_HPP
4#define _PAGES_HEADER_HPP
Dees_Troy51a0e822012-09-05 15:24:24 -04005
Dees Troyb7ae0982013-09-10 20:47:35 +00006#include "../minzip/Zip.h"
Dees Troyb7ae0982013-09-10 20:47:35 +00007
Dees_Troy51a0e822012-09-05 15:24:24 -04008typedef struct {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02009 unsigned char red;
10 unsigned char green;
11 unsigned char blue;
12 unsigned char alpha;
Dees_Troy51a0e822012-09-05 15:24:24 -040013} COLOR;
14
15// Utility Functions
16int ConvertStrToColor(std::string str, COLOR* color);
17int gui_forceRender(void);
18int gui_changePage(std::string newPage);
19int gui_changeOverlay(std::string newPage);
20std::string gui_parse_text(string inText);
21
22class Resource;
23class ResourceManager;
24class RenderObject;
25class ActionObject;
26class InputObject;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010027class MouseCursor;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010028class GUIObject;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010029class HardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -040030
31class Page
32{
33public:
Ethan Yonker780cd392014-07-21 15:24:39 -050034 Page(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL);
Vojtech Bocekbfb63342014-02-08 00:32:31 +010035 virtual ~Page();
36
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020037 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040038
39public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020040 virtual int Render(void);
41 virtual int Update(void);
42 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010043 virtual int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -040044 virtual int NotifyKeyboard(int key);
45 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020046 virtual int NotifyVarChange(std::string varName, std::string value);
47 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040048
49protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020050 std::string mName;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010051 std::vector<GUIObject*> mObjects;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020052 std::vector<RenderObject*> mRenders;
53 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040054 std::vector<InputObject*> mInputs;
55
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056 ActionObject* mTouchStart;
57 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040058
59protected:
Ethan Yonker780cd392014-07-21 15:24:39 -050060 bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL, int depth = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040061};
62
63class PageSet
64{
65public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020066 PageSet(char* xmlFile);
67 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040068
69public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 int Load(ZipArchive* package);
Ethan Yonker780cd392014-07-21 15:24:39 -050071 int CheckInclude(ZipArchive* package, xml_document<> *parentDoc);
Dees_Troy51a0e822012-09-05 15:24:24 -040072
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 Page* FindPage(std::string name);
74 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040075 int SetOverlay(Page* page);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020076 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040077
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 // Helper routine for identifing if we're the current page
79 int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -040080
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 // These are routing routines
82 int Render(void);
83 int Update(void);
84 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010085 int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -040086 int NotifyKeyboard(int key);
87 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020088 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -040089
90protected:
Ethan Yonker780cd392014-07-21 15:24:39 -050091 int LoadPages(xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -040093
94protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 char* mXmlFile;
96 xml_document<> mDoc;
97 ResourceManager* mResources;
98 std::vector<Page*> mPages;
Ethan Yonker780cd392014-07-21 15:24:39 -050099 std::vector<xml_node<>*> templates;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 Page* mCurrentPage;
101 Page* mOverlayPage; // This is a special case, used for "locking" the screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400102};
103
104class PageManager
105{
106public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200107 // Used by GUI
108 static int LoadPackage(std::string name, std::string package, std::string startpage);
109 static PageSet* SelectPackage(std::string name);
110 static int ReloadPackage(std::string name, std::string package);
111 static void ReleasePackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400112
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200113 // Used for actions and pages
114 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400115 static int ChangeOverlay(std::string name);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200116 static Resource* FindResource(std::string name);
117 static Resource* FindResource(std::string package, std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400118
Ethan Yonker03a42f62014-08-08 11:03:51 -0500119 // Used for console-only mode
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200120 static int SwitchToConsole(void);
Ethan Yonker03a42f62014-08-08 11:03:51 -0500121 static int EndConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400122
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200123 // Helper to identify if a particular page is the active page
124 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400125
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200126 // These are routing routines
127 static int Render(void);
128 static int Update(void);
129 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100130 static int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400131 static int NotifyKeyboard(int key);
132 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200133 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400134
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100135 static MouseCursor *GetMouseCursor();
136 static void LoadCursorData(xml_node<>* node);
137
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100138 static HardwareKeyboard *GetHardwareKeyboard();
139
Dees_Troy51a0e822012-09-05 15:24:24 -0400140protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200141 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400142
143protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 static std::map<std::string, PageSet*> mPageSets;
145 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400146 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100147 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100148 static HardwareKeyboard *mHardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -0400149};
150
Dees_Troye4a88112012-12-18 21:29:33 +0000151#endif // _PAGES_HEADER_HPP