blob: 23ceee9c893b28a90b57ab2bb88b56d40a2737f6 [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;
Dees_Troy51a0e822012-09-05 15:24:24 -040033
34class Page
35{
36public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020037 Page(xml_node<>* page, xml_node<>* templates = NULL);
Vojtech Bocekbfb63342014-02-08 00:32:31 +010038 virtual ~Page();
39
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020040 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;
Vojtech Bocekbfb63342014-02-08 00:32:31 +010054 std::vector<GUIObject*> mObjects;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 std::vector<RenderObject*> mRenders;
56 std::vector<ActionObject*> mActions;
Dees_Troy51a0e822012-09-05 15:24:24 -040057 std::vector<InputObject*> mInputs;
58
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020059 ActionObject* mTouchStart;
60 COLOR mBackground;
Dees_Troy51a0e822012-09-05 15:24:24 -040061
62protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 bool ProcessNode(xml_node<>* page, xml_node<>* templates = NULL, int depth = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040064};
65
66class PageSet
67{
68public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020069 PageSet(char* xmlFile);
70 virtual ~PageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -040071
72public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 int Load(ZipArchive* package);
Dees_Troy51a0e822012-09-05 15:24:24 -040074
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020075 Page* FindPage(std::string name);
76 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040077 int SetOverlay(Page* page);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040079
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 // Helper routine for identifing if we're the current page
81 int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -040082
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083 // These are routing routines
84 int Render(void);
85 int Update(void);
86 int NotifyTouch(TOUCH_STATE state, int x, int y);
87 int NotifyKey(int key);
Dees_Troy51a0e822012-09-05 15:24:24 -040088 int NotifyKeyboard(int key);
89 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020090 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -040091
92protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020093 int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
94 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -040095
96protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020097 char* mXmlFile;
98 xml_document<> mDoc;
99 ResourceManager* mResources;
100 std::vector<Page*> mPages;
101 Page* mCurrentPage;
102 Page* mOverlayPage; // This is a special case, used for "locking" the screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400103};
104
105class PageManager
106{
107public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200108 // Used by GUI
109 static int LoadPackage(std::string name, std::string package, std::string startpage);
110 static PageSet* SelectPackage(std::string name);
111 static int ReloadPackage(std::string name, std::string package);
112 static void ReleasePackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400113
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200114 // Used for actions and pages
115 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400116 static int ChangeOverlay(std::string name);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200117 static Resource* FindResource(std::string name);
118 static Resource* FindResource(std::string package, std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400119
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200120 // Used for console-only mode - Can be reverted via ChangePage
121 static int SwitchToConsole(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);
130 static int NotifyKey(int key);
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
Dees_Troy51a0e822012-09-05 15:24:24 -0400138protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200139 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400140
141protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200142 static std::map<std::string, PageSet*> mPageSets;
143 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400144 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100145 static MouseCursor *mMouseCursor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400146};
147
Dees_Troye4a88112012-12-18 21:29:33 +0000148#endif // _PAGES_HEADER_HPP