blob: c384cf0d79d881af3859bdbdf9dddf01a1fbb903 [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#ifdef HAVE_SELINUX
7#include "../minzip/Zip.h"
8#else
9#include "../minzipold/Zip.h"
10#endif
11
Dees_Troy51a0e822012-09-05 15:24:24 -040012typedef struct {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020013 unsigned char red;
14 unsigned char green;
15 unsigned char blue;
16 unsigned char alpha;
Dees_Troy51a0e822012-09-05 15:24:24 -040017} COLOR;
18
19// Utility Functions
20int ConvertStrToColor(std::string str, COLOR* color);
21int gui_forceRender(void);
22int gui_changePage(std::string newPage);
23int gui_changeOverlay(std::string newPage);
24std::string gui_parse_text(string inText);
25
26class Resource;
27class ResourceManager;
28class RenderObject;
29class ActionObject;
30class InputObject;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +010031class MouseCursor;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010032class GUIObject;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010033class HardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -040034
35class Page
36{
37public:
Ethan Yonker780cd392014-07-21 15:24:39 -050038 Page(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL);
Vojtech Bocekbfb63342014-02-08 00:32:31 +010039 virtual ~Page();
40
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020041 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040042
43public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020044 virtual int Render(void);
45 virtual int Update(void);
46 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010047 virtual int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -040048 virtual int NotifyKeyboard(int key);
49 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020050 virtual int NotifyVarChange(std::string varName, std::string value);
51 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040052
53protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020054 std::string mName;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010055 std::vector<GUIObject*> mObjects;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056 std::vector<RenderObject*> mRenders;
57 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040058 std::vector<InputObject*> mInputs;
59
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020060 ActionObject* mTouchStart;
61 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040062
63protected:
Ethan Yonker780cd392014-07-21 15:24:39 -050064 bool ProcessNode(xml_node<>* page, std::vector<xml_node<>*> *templates = NULL, int depth = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040065};
66
67class PageSet
68{
69public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 PageSet(char* xmlFile);
71 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040072
73public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 int Load(ZipArchive* package);
Ethan Yonker780cd392014-07-21 15:24:39 -050075 int CheckInclude(ZipArchive* package, xml_document<> *parentDoc);
Dees_Troy51a0e822012-09-05 15:24:24 -040076
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 Page* FindPage(std::string name);
78 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040079 int SetOverlay(Page* page);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040081
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020082 // Helper routine for identifing if we're the current page
83 int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -040084
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 // These are routing routines
86 int Render(void);
87 int Update(void);
88 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010089 int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -040090 int NotifyKeyboard(int key);
91 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -040093
94protected:
Ethan Yonker780cd392014-07-21 15:24:39 -050095 int LoadPages(xml_node<>* pages);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -040097
98protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020099 char* mXmlFile;
100 xml_document<> mDoc;
101 ResourceManager* mResources;
102 std::vector<Page*> mPages;
Ethan Yonker780cd392014-07-21 15:24:39 -0500103 std::vector<xml_node<>*> templates;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200104 Page* mCurrentPage;
105 Page* mOverlayPage; // This is a special case, used for "locking" the screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400106};
107
108class PageManager
109{
110public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200111 // Used by GUI
112 static int LoadPackage(std::string name, std::string package, std::string startpage);
113 static PageSet* SelectPackage(std::string name);
114 static int ReloadPackage(std::string name, std::string package);
115 static void ReleasePackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400116
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200117 // Used for actions and pages
118 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400119 static int ChangeOverlay(std::string name);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200120 static Resource* FindResource(std::string name);
121 static Resource* FindResource(std::string package, std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400122
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200123 // Used for console-only mode - Can be reverted via ChangePage
124 static int SwitchToConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400125
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200126 // Helper to identify if a particular page is the active page
127 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400128
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200129 // These are routing routines
130 static int Render(void);
131 static int Update(void);
132 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100133 static int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400134 static int NotifyKeyboard(int key);
135 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200136 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400137
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100138 static MouseCursor *GetMouseCursor();
139 static void LoadCursorData(xml_node<>* node);
140
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100141 static HardwareKeyboard *GetHardwareKeyboard();
142
Dees_Troy51a0e822012-09-05 15:24:24 -0400143protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400145
146protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200147 static std::map<std::string, PageSet*> mPageSets;
148 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400149 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100150 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100151 static HardwareKeyboard *mHardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -0400152};
153
Dees_Troye4a88112012-12-18 21:29:33 +0000154#endif // _PAGES_HEADER_HPP