blob: 2a2ef2c32e60b6a918d4e5c57d4fab5a70df34de [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;
Dees_Troy51a0e822012-09-05 15:24:24 -040032
33class Page
34{
35public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020036 virtual ~Page() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040037
38public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020039 Page(xml_node<>* page, xml_node<>* templates = NULL);
40 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040041
42public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020043 virtual int Render(void);
44 virtual int Update(void);
45 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
46 virtual int NotifyKey(int key);
Dees_Troy51a0e822012-09-05 15:24:24 -040047 virtual int NotifyKeyboard(int key);
48 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 virtual int NotifyVarChange(std::string varName, std::string value);
50 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040051
52protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020053 std::string mName;
54 std::vector<RenderObject*> mRenders;
55 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040056 std::vector<InputObject*> mInputs;
57
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020058 ActionObject* mTouchStart;
59 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040060
61protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020062 bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040063};
64
65class PageSet
66{
67public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020068 PageSet(char* xmlFile);
69 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040070
71public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020072 int Load(ZipArchive* package);
Dees_Troy51a0e822012-09-05 15:24:24 -040073
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 Page* FindPage(std::string name);
75 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040076 int SetOverlay(Page* page);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040078
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020079 // Helper routine for identifing if we're the current page
80 int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -040081
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020082 // These are routing routines
83 int Render(void);
84 int Update(void);
85 int NotifyTouch(TOUCH_STATE state, int x, int y);
86 int NotifyKey(int key);
Dees_Troy51a0e822012-09-05 15:24:24 -040087 int NotifyKeyboard(int key);
88 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020089 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -040090
91protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
93 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -040094
95protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096 char* mXmlFile;
97 xml_document<> mDoc;
98 ResourceManager* mResources;
99 std::vector<Page*> mPages;
100 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
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200119 // Used for console-only mode - Can be reverted via ChangePage
120 static int SwitchToConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400121
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200122 // Helper to identify if a particular page is the active page
123 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400124
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200125 // These are routing routines
126 static int Render(void);
127 static int Update(void);
128 static int NotifyTouch(TOUCH_STATE state, int x, int y);
129 static int NotifyKey(int key);
Dees_Troy51a0e822012-09-05 15:24:24 -0400130 static int NotifyKeyboard(int key);
131 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200132 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400133
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100134 static MouseCursor *GetMouseCursor();
135 static void LoadCursorData(xml_node<>* node);
136
Dees_Troy51a0e822012-09-05 15:24:24 -0400137protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200138 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400139
140protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200141 static std::map<std::string, PageSet*> mPageSets;
142 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400143 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100144 static MouseCursor *mMouseCursor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400145};
146
Dees_Troye4a88112012-12-18 21:29:33 +0000147#endif // _PAGES_HEADER_HPP