blob: a37cdb9f2e6efa41a4d143f3dbceb95c54934c87 [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;
31
32class Page
33{
34public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020035 virtual ~Page() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040036
37public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020038 Page(xml_node<>* page, xml_node<>* templates = NULL);
39 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040040
41public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020042 virtual int Render(void);
43 virtual int Update(void);
44 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
45 virtual int NotifyKey(int key);
Dees_Troy51a0e822012-09-05 15:24:24 -040046 virtual int NotifyKeyboard(int key);
47 virtual int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 virtual int NotifyVarChange(std::string varName, std::string value);
49 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -040050
51protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020052 std::string mName;
53 std::vector<RenderObject*> mRenders;
54 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040055 std::vector<InputObject*> mInputs;
56
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020057 ActionObject* mTouchStart;
58 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040059
60protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020061 bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040062};
63
64class PageSet
65{
66public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067 PageSet(char* xmlFile);
68 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040069
70public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020071 int Load(ZipArchive* package);
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);
85 int NotifyKey(int key);
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:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020091 int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
92 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;
99 Page* mCurrentPage;
100 Page* mOverlayPage; // This is a special case, used for "locking" the screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400101};
102
103class PageManager
104{
105public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 // Used by GUI
107 static int LoadPackage(std::string name, std::string package, std::string startpage);
108 static PageSet* SelectPackage(std::string name);
109 static int ReloadPackage(std::string name, std::string package);
110 static void ReleasePackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400111
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200112 // Used for actions and pages
113 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400114 static int ChangeOverlay(std::string name);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200115 static Resource* FindResource(std::string name);
116 static Resource* FindResource(std::string package, std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400117
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200118 // Used for console-only mode - Can be reverted via ChangePage
119 static int SwitchToConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400120
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200121 // Helper to identify if a particular page is the active page
122 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400123
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200124 // These are routing routines
125 static int Render(void);
126 static int Update(void);
127 static int NotifyTouch(TOUCH_STATE state, int x, int y);
128 static int NotifyKey(int key);
Dees_Troy51a0e822012-09-05 15:24:24 -0400129 static int NotifyKeyboard(int key);
130 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200131 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400132
133protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200134 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400135
136protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 static std::map<std::string, PageSet*> mPageSets;
138 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400139 static PageSet* mBaseSet;
140};
141
Dees_Troye4a88112012-12-18 21:29:33 +0000142#endif // _PAGES_HEADER_HPP