blob: a9cc0c1d046d376172389ad8b40150d60d2402bd [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:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020038 Page(xml_node<>* page, 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:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020064 bool ProcessNode(xml_node<>* page, 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);
Dees_Troy51a0e822012-09-05 15:24:24 -040075
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020076 Page* FindPage(std::string name);
77 int SetPage(std::string page);
Dees_Troy51a0e822012-09-05 15:24:24 -040078 int SetOverlay(Page* page);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020079 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040080
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 // Helper routine for identifing if we're the current page
82 int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -040083
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020084 // These are routing routines
85 int Render(void);
86 int Update(void);
87 int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010088 int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -040089 int NotifyKeyboard(int key);
90 int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020091 int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -040092
93protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020094 int LoadPages(xml_node<>* pages, xml_node<>* templates = NULL);
95 int LoadVariables(xml_node<>* vars);
Dees_Troy51a0e822012-09-05 15:24:24 -040096
97protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020098 char* mXmlFile;
99 xml_document<> mDoc;
100 ResourceManager* mResources;
101 std::vector<Page*> mPages;
102 Page* mCurrentPage;
103 Page* mOverlayPage; // This is a special case, used for "locking" the screen
Dees_Troy51a0e822012-09-05 15:24:24 -0400104};
105
106class PageManager
107{
108public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 // Used by GUI
110 static int LoadPackage(std::string name, std::string package, std::string startpage);
111 static PageSet* SelectPackage(std::string name);
112 static int ReloadPackage(std::string name, std::string package);
113 static void ReleasePackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400114
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200115 // Used for actions and pages
116 static int ChangePage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400117 static int ChangeOverlay(std::string name);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200118 static Resource* FindResource(std::string name);
119 static Resource* FindResource(std::string package, std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400120
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200121 // Used for console-only mode - Can be reverted via ChangePage
122 static int SwitchToConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400123
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200124 // Helper to identify if a particular page is the active page
125 static int IsCurrentPage(Page* page);
Dees_Troy51a0e822012-09-05 15:24:24 -0400126
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200127 // These are routing routines
128 static int Render(void);
129 static int Update(void);
130 static int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100131 static int NotifyKey(int key, bool down);
Dees_Troy51a0e822012-09-05 15:24:24 -0400132 static int NotifyKeyboard(int key);
133 static int SetKeyBoardFocus(int inFocus);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200134 static int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400135
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100136 static MouseCursor *GetMouseCursor();
137 static void LoadCursorData(xml_node<>* node);
138
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100139 static HardwareKeyboard *GetHardwareKeyboard();
140
Dees_Troy51a0e822012-09-05 15:24:24 -0400141protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200142 static PageSet* FindPackage(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400143
144protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200145 static std::map<std::string, PageSet*> mPageSets;
146 static PageSet* mCurrentSet;
Dees_Troy51a0e822012-09-05 15:24:24 -0400147 static PageSet* mBaseSet;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100148 static MouseCursor *mMouseCursor;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100149 static HardwareKeyboard *mHardwareKeyboard;
Dees_Troy51a0e822012-09-05 15:24:24 -0400150};
151
Dees_Troye4a88112012-12-18 21:29:33 +0000152#endif // _PAGES_HEADER_HPP