blob: 4942cd7e60c914eaa26f638e343d8074e464ecc1 [file] [log] [blame]
Dees_Troya13d74f2013-03-24 08:54:55 -05001/*
2 Copyright 2013 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
Dees Troy3be70a82013-10-22 14:25:12 +000018
19// objects.hpp - Base classes for object manager of GUI
Dees_Troy51a0e822012-09-05 15:24:24 -040020
21#ifndef _OBJECTS_HEADER
22#define _OBJECTS_HEADER
23
24#include "rapidxml.hpp"
25#include <vector>
26#include <string>
27#include <map>
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +000028#include <time.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040029
30extern "C" {
Dees Troyb7ae0982013-09-10 20:47:35 +000031#ifdef HAVE_SELINUX
Dees_Troy51a0e822012-09-05 15:24:24 -040032#include "../minzip/Zip.h"
Dees Troyb7ae0982013-09-10 20:47:35 +000033#else
34#include "../minzipold/Zip.h"
35#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040036}
37
38using namespace rapidxml;
39
40#include "../data.hpp"
41#include "resources.hpp"
42#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050043#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040044
45class RenderObject
46{
47public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 enum Placement {
49 TOP_LEFT = 0,
50 TOP_RIGHT = 1,
51 BOTTOM_LEFT = 2,
52 BOTTOM_RIGHT = 3,
53 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040054 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 };
Dees_Troy51a0e822012-09-05 15:24:24 -040056
57public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020058 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
59 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040060
61public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020062 // Render - Render the full object to the GL surface
63 // Return 0 on success, <0 on error
64 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040065
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020066 // Update - Update any UI component animations (called <= 30 FPS)
67 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
68 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040069
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 // GetRenderPos - Returns the current position of the object
71 virtual int GetRenderPos(int& x, int& y, int& w, int& h) { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040072
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 // SetRenderPos - Update the position of the object
74 // Return 0 on success, <0 on error
75 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0) { mRenderX = x; mRenderY = y; if (w || h) { mRenderW = w; mRenderH = h; } return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040076
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 // GetPlacement - Returns the current placement
78 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040079
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 // SetPlacement - Update the current placement
81 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040082
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083 // SetPageFocus - Notify when a page gains or loses focus
84 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040085
86protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020087 int mRenderX, mRenderY, mRenderW, mRenderH;
88 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040089};
90
91class ActionObject
92{
93public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020094 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
95 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040096
97public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020098 // NotifyTouch - Notify of a touch event
99 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
100 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 // NotifyKey - Notify of a key press
103 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
104 virtual int NotifyKey(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 // GetRenderPos - Returns the current position of the object
107 virtual int GetActionPos(int& x, int& y, int& w, int& h) { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400108
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 // SetRenderPos - Update the position of the object
110 // Return 0 on success, <0 on error
111 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400112
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200113 // IsInRegion - Checks if the request is handled by this object
114 // Return 0 if this object handles the request, 1 if not
115 virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); }
Dees_Troy51a0e822012-09-05 15:24:24 -0400116
Dees_Troy51a0e822012-09-05 15:24:24 -0400117protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200118 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400119};
120
Vojtech Bocekede51c52014-02-07 23:58:09 +0100121class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400122{
123public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100124 GUIObject(xml_node<>* node);
125 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400126
127public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200128 bool IsConditionVariable(std::string var);
129 bool isConditionTrue();
130 bool isConditionValid();
Vojtech Bocek07220562014-02-08 02:05:33 +0100131
132 // NotifyVarChange - Notify of a variable change
133 // Returns 0 on success, <0 on error
134 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400135
136protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 class Condition
138 {
139 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100140 Condition() {
141 mLastResult = true;
142 }
143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 std::string mVar1;
145 std::string mVar2;
146 std::string mCompareOp;
147 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100148 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400150
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200151 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400152
153protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200154 bool isMounted(std::string vol);
155 bool isConditionTrue(Condition* condition);
Vojtech Bocek07220562014-02-08 02:05:33 +0100156
157 bool mConditionsResult;
Dees_Troy51a0e822012-09-05 15:24:24 -0400158};
159
160class InputObject
161{
162public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200163 InputObject() { HasInputFocus = 0; }
164 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400165
166public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200167 // NotifyKeyboard - Notify of keyboard input
168 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
169 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400170
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200171 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400172
173protected:
174 int HasInputFocus;
175};
176
177// Derived Objects
178// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100179class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400180{
181public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200182 // w and h may be ignored, in which case, no bounding box is applied
183 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400184
185public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200186 // Render - Render the full object to the GL surface
187 // Return 0 on success, <0 on error
188 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400189
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200190 // Update - Update any UI component animations (called <= 30 FPS)
191 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
192 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400193
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200194 // Retrieve the size of the current string (dynamic strings may change per call)
195 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400196
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200197 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100198 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400199
200 // Set maximum width in pixels
201 virtual int SetMaxWidth(unsigned width);
202
203 // Set number of characters to skip (for scrolling)
204 virtual int SkipCharCount(unsigned skip);
205
Dees_Troy4d12f962012-10-19 13:13:15 -0400206public:
207 bool isHighlighted;
208
Dees_Troy51a0e822012-09-05 15:24:24 -0400209protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200210 std::string mText;
211 std::string mLastValue;
212 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400213 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200214 Resource* mFont;
215 int mIsStatic;
216 int mVarChanged;
217 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400218 unsigned maxWidth;
219 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400220 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400221
222protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200223 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400224};
225
226// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100227class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400228{
229public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400231
232public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200233 // Render - Render the full object to the GL surface
234 // Return 0 on success, <0 on error
235 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400236
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200237 // SetRenderPos - Update the position of the object
238 // Return 0 on success, <0 on error
239 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400240
Dees_Troy4d12f962012-10-19 13:13:15 -0400241public:
242 bool isHighlighted;
243
Dees_Troy51a0e822012-09-05 15:24:24 -0400244protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200245 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400246 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400247};
248
249// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100250class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400251{
252public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200253 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400254
255public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200256 // Render - Render the full object to the GL surface
257 // Return 0 on success, <0 on error
258 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400259
260protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200261 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400262};
263
264// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100265class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400266{
267public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200268 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400269
270public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200271 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
272 virtual int NotifyKey(int key);
Vojtech Bocek07220562014-02-08 02:05:33 +0100273 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400274 virtual int doActions();
275
276protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200277 class Action
278 {
279 public:
280 std::string mFunction;
281 std::string mArg;
282 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400283
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200284 std::vector<Action> mActions;
285 int mKey;
Dees_Troy51a0e822012-09-05 15:24:24 -0400286
287protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200288 int getKeyByName(std::string key);
289 virtual int doAction(Action action, int isThreaded = 0);
290 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400291 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200292 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400293 void operation_start(const string operation_name);
294 void operation_end(const int operation_status, const int simulate);
295 static void* command_thread(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000296 time_t Start;
Dees_Troy51a0e822012-09-05 15:24:24 -0400297};
298
Vojtech Bocekede51c52014-02-07 23:58:09 +0100299class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400300{
301public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200302 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400303
304public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200305 // Render - Render the full object to the GL surface
306 // Return 0 on success, <0 on error
307 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400308
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200309 // Update - Update any UI component animations (called <= 30 FPS)
310 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
311 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400312
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200313 // SetRenderPos - Update the position of the object
314 // Return 0 on success, <0 on error
315 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400316
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200317 // IsInRegion - Checks if the request is handled by this object
318 // Return 0 if this object handles the request, 1 if not
319 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400320
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200321 // NotifyTouch - Notify of a touch event
322 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
323 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400324
325protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200326 enum SlideoutState
327 {
328 hidden = 0,
329 visible,
330 request_hide,
331 request_show
332 };
333
334 Resource* mFont;
335 Resource* mSlideoutImage;
336 COLOR mForegroundColor;
337 COLOR mBackgroundColor;
338 COLOR mScrollColor;
339 unsigned int mFontHeight;
340 int mCurrentLine;
341 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000342 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200343 unsigned int mMaxRows;
344 int mStartY;
345 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
346 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
347 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
348 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200349 int mSlideout;
350 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000351 std::vector<std::string> rConsole;
352 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400353
354protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200355 virtual int RenderSlideout(void);
356 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400357};
358
Vojtech Bocekede51c52014-02-07 23:58:09 +0100359class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400360{
361public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200362 GUIButton(xml_node<>* node);
363 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400364
365public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200366 // Render - Render the full object to the GL surface
367 // Return 0 on success, <0 on error
368 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400369
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200370 // Update - Update any UI component animations (called <= 30 FPS)
371 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
372 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400373
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200374 // SetPos - Update the position of the render object
375 // Return 0 on success, <0 on error
376 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400377
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200378 // NotifyTouch - Notify of a touch event
379 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
380 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400381
382protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200383 GUIImage* mButtonImg;
384 Resource* mButtonIcon;
385 GUIText* mButtonLabel;
386 GUIAction* mAction;
387 int mTextX, mTextY, mTextW, mTextH;
388 int mIconX, mIconY, mIconW, mIconH;
389 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600390 bool hasHighlightColor;
391 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500392 bool hasFill;
393 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600394 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000395 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400396};
397
Vojtech Bocekede51c52014-02-07 23:58:09 +0100398class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400399{
400public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200401 GUICheckbox(xml_node<>* node);
402 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400403
404public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200405 // Render - Render the full object to the GL surface
406 // Return 0 on success, <0 on error
407 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400408
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200409 // Update - Update any UI component animations (called <= 30 FPS)
410 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
411 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400412
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200413 // SetPos - Update the position of the render object
414 // Return 0 on success, <0 on error
415 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400416
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200417 // NotifyTouch - Notify of a touch event
418 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
419 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400420
421protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200422 Resource* mChecked;
423 Resource* mUnchecked;
424 GUIText* mLabel;
425 int mTextX, mTextY;
426 int mCheckX, mCheckY, mCheckW, mCheckH;
427 int mLastState;
428 bool mRendered;
429 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400430};
431
Vojtech Bocekede51c52014-02-07 23:58:09 +0100432class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400433{
434public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200435 GUIFileSelector(xml_node<>* node);
436 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400437
438public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200439 // Render - Render the full object to the GL surface
440 // Return 0 on success, <0 on error
441 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400442
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200443 // Update - Update any UI component animations (called <= 30 FPS)
444 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
445 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400446
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200447 // NotifyTouch - Notify of a touch event
448 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
449 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400450
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200451 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100452 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400453
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200454 // SetPos - Update the position of the render object
455 // Return 0 on success, <0 on error
456 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400457
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200458 // SetPageFocus - Notify when a page gains or loses focus
459 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400460
461protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200462 struct FileData {
463 std::string fileName;
464 unsigned char fileType; // Uses d_type format from struct dirent
465 mode_t protection; // Uses mode_t format from stat
466 uid_t userId;
467 gid_t groupId;
468 off_t fileSize;
469 time_t lastAccess; // Uses time_t format from stat
470 time_t lastModified; // Uses time_t format from stat
471 time_t lastStatChange; // Uses time_t format from stat
472 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400473
474protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200475 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400476
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200477 virtual int GetFileList(const std::string folder);
478 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400479
480protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200481 std::vector<FileData> mFolderList;
482 std::vector<FileData> mFileList;
483 std::string mPathVar;
484 std::string mExtn;
485 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400486 std::string mSortVariable;
487 std::string mSelection;
488 std::string mHeaderText;
489 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200490 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400491 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200492 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400493 int mSeparatorH;
494 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200495 int mShowFolders, mShowFiles, mShowNavFolders;
496 int mUpdate;
497 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400498 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100499 int mFastScrollW;
500 int mFastScrollLineW;
501 int mFastScrollRectW;
502 int mFastScrollRectH;
503 int mFastScrollRectX;
504 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400505 static int mSortOrder;
506 int startY;
507 int scrollingSpeed;
508 int scrollingY;
509 int mHeaderIsStatic;
510 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200511 unsigned mFontHeight;
512 unsigned mLineHeight;
513 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
514 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400515 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200516 Resource* mFileIcon;
517 Resource* mBackground;
518 Resource* mFont;
519 COLOR mBackgroundColor;
520 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400521 COLOR mHeaderBackgroundColor;
522 COLOR mHeaderFontColor;
523 COLOR mSeparatorColor;
524 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100525 COLOR mFastScrollLineColor;
526 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600527 bool hasHighlightColor;
528 bool hasFontHighlightColor;
529 bool isHighlighted;
530 COLOR mHighlightColor;
531 COLOR mFontHighlightColor;
532 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600533 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400534};
535
Vojtech Bocekede51c52014-02-07 23:58:09 +0100536class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400537{
538public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200539 GUIListBox(xml_node<>* node);
540 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400541
542public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200543 // Render - Render the full object to the GL surface
544 // Return 0 on success, <0 on error
545 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400546
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200547 // Update - Update any UI component animations (called <= 30 FPS)
548 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
549 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400550
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200551 // NotifyTouch - Notify of a touch event
552 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
553 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400554
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200555 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100556 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400557
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200558 // SetPos - Update the position of the render object
559 // Return 0 on success, <0 on error
560 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400561
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200562 // SetPageFocus - Notify when a page gains or loses focus
563 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400564
565protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200566 struct ListData {
567 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400568 std::string variableValue;
569 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200570 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400571
572protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200573 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400574
575protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200576 std::vector<ListData> mList;
577 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400578 std::string mSelection;
579 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600580 std::string mHeaderText;
581 std::string mLastValue;
582 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200583 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600584 int startY;
585 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200586 int mLineSpacing;
587 int mUpdate;
588 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000589 int mFastScrollW;
590 int mFastScrollLineW;
591 int mFastScrollRectW;
592 int mFastScrollRectH;
593 int mFastScrollRectX;
594 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600595 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
596 int scrollingSpeed;
597 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400598 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200599 unsigned mFontHeight;
600 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600601 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200602 Resource* mIconSelected;
603 Resource* mIconUnselected;
604 Resource* mBackground;
605 Resource* mFont;
606 COLOR mBackgroundColor;
607 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600608 COLOR mHeaderBackgroundColor;
609 COLOR mHeaderFontColor;
610 COLOR mSeparatorColor;
611 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000612 COLOR mFastScrollLineColor;
613 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600614 bool hasHighlightColor;
615 bool hasFontHighlightColor;
616 bool isHighlighted;
617 COLOR mHighlightColor;
618 COLOR mFontHighlightColor;
619 int mHeaderIsStatic;
620 int startSelection;
621 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400622};
623
Vojtech Bocekede51c52014-02-07 23:58:09 +0100624class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500625{
626public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 GUIPartitionList(xml_node<>* node);
628 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500629
630public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200631 // Render - Render the full object to the GL surface
632 // Return 0 on success, <0 on error
633 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500634
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200635 // Update - Update any UI component animations (called <= 30 FPS)
636 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
637 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500638
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200639 // NotifyTouch - Notify of a touch event
640 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
641 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500642
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200643 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100644 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500645
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200646 // SetPos - Update the position of the render object
647 // Return 0 on success, <0 on error
648 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500649
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200650 // SetPageFocus - Notify when a page gains or loses focus
651 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500652
653protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200654 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500655 virtual void MatchList(void);
656
657protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200658 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500659 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200660 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500661 std::string selectedList;
662 std::string currentValue;
663 std::string mHeaderText;
664 std::string mLastValue;
665 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200666 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500667 int startY;
668 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200669 int mLineSpacing;
670 int mUpdate;
671 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500672 int mFastScrollW;
673 int mFastScrollLineW;
674 int mFastScrollRectW;
675 int mFastScrollRectH;
676 int mFastScrollRectX;
677 int mFastScrollRectY;
678 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
679 int scrollingSpeed;
680 int scrollingY;
681 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200682 unsigned mFontHeight;
683 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500684 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200685 Resource* mIconSelected;
686 Resource* mIconUnselected;
687 Resource* mBackground;
688 Resource* mFont;
689 COLOR mBackgroundColor;
690 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500691 COLOR mHeaderBackgroundColor;
692 COLOR mHeaderFontColor;
693 COLOR mSeparatorColor;
694 COLOR mHeaderSeparatorColor;
695 COLOR mFastScrollLineColor;
696 COLOR mFastScrollRectColor;
697 bool hasHighlightColor;
698 bool hasFontHighlightColor;
699 bool isHighlighted;
700 COLOR mHighlightColor;
701 COLOR mFontHighlightColor;
702 int mHeaderIsStatic;
703 int startSelection;
704 int touchDebounce;
705 bool updateList;
706};
707
Dees_Troy51a0e822012-09-05 15:24:24 -0400708// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100709class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400710{
711public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200712 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400713
714public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200715 // Render - Render the full object to the GL surface
716 // Return 0 on success, <0 on error
717 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400718
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200719 // Update - Update any UI component animations (called <= 30 FPS)
720 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
721 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400722
723protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200724 AnimationResource* mAnimation;
725 int mFrame;
726 int mFPS;
727 int mLoop;
728 int mRender;
729 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400730};
731
Vojtech Bocekede51c52014-02-07 23:58:09 +0100732class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400733{
734public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200735 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400736
737public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200738 // Render - Render the full object to the GL surface
739 // Return 0 on success, <0 on error
740 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400741
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200742 // Update - Update any UI component animations (called <= 30 FPS)
743 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
744 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400745
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200746 // NotifyVarChange - Notify of a variable change
747 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100748 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400749
750protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200751 Resource* mEmptyBar;
752 Resource* mFullBar;
753 std::string mMinValVar;
754 std::string mMaxValVar;
755 std::string mCurValVar;
756 float mSlide;
757 float mSlideInc;
758 int mSlideFrames;
759 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400760
761protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200762 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400763};
764
Vojtech Bocekede51c52014-02-07 23:58:09 +0100765class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400766{
767public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200768 GUISlider(xml_node<>* node);
769 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400770
771public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200772 // Render - Render the full object to the GL surface
773 // Return 0 on success, <0 on error
774 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400775
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200776 // Update - Update any UI component animations (called <= 30 FPS)
777 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
778 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400779
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200780 // NotifyTouch - Notify of a touch event
781 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
782 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400783
784protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200785 GUIAction* sAction;
786 Resource* sSlider;
787 Resource* sSliderUsed;
788 Resource* sTouch;
789 int sTouchW, sTouchH;
790 int sCurTouchX;
791 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400792};
793
794#define MAX_KEYBOARD_LAYOUTS 5
795#define MAX_KEYBOARD_ROWS 9
796#define MAX_KEYBOARD_KEYS 20
797#define KEYBOARD_ACTION 253
798#define KEYBOARD_LAYOUT 254
799#define KEYBOARD_SWIPE_LEFT 252
800#define KEYBOARD_SWIPE_RIGHT 251
801#define KEYBOARD_ARROW_LEFT 250
802#define KEYBOARD_ARROW_RIGHT 249
803#define KEYBOARD_HOME 248
804#define KEYBOARD_END 247
805#define KEYBOARD_ARROW_UP 246
806#define KEYBOARD_ARROW_DOWN 245
807#define KEYBOARD_SPECIAL_KEYS 245
808#define KEYBOARD_BACKSPACE 8
809
Vojtech Bocekede51c52014-02-07 23:58:09 +0100810class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400811{
812public:
813 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200814 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400815
816public:
817 virtual int Render(void);
818 virtual int Update(void);
819 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
820 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
821
822protected:
823 virtual int GetSelection(int x, int y);
824
825protected:
826 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200827 {
828 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400829 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200830 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400831 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200832 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600833 struct capslock_tracking_struct
834 {
835 int capslock;
836 int set_capslock;
837 int revert_layout;
838 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400839
840 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
841 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600842 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400843 bool mRendered;
844 std::string mVariable;
845 unsigned int cursorLocation;
846 unsigned int currentLayout;
847 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
848 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600849 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400850 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400851 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600852 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400853};
854
855// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100856class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400857{
858public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200859 // w and h may be ignored, in which case, no bounding box is applied
860 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400861 virtual ~GUIInput();
862
863public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200864 // Render - Render the full object to the GL surface
865 // Return 0 on success, <0 on error
866 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400867
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200868 // Update - Update any UI component animations (called <= 30 FPS)
869 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
870 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400871
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200872 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100873 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400874
875 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200876 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
877 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400878
879 virtual int NotifyKeyboard(int key);
880
881protected:
882 virtual int GetSelection(int x, int y);
883
884 // Handles displaying the text properly when chars are added, deleted, or for scrolling
885 virtual int HandleTextLocation(int x);
886
887protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200888 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400889 GUIAction* mAction;
890 Resource* mBackground;
891 Resource* mCursor;
892 Resource* mFont;
893 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200894 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400895 std::string mVariable;
896 std::string mMask;
897 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200898 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400899 COLOR mCursorColor;
900 int scrollingX;
901 int lastX;
902 int mCursorLocation;
903 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
904 int mFontY;
905 unsigned skipChars;
906 unsigned mFontHeight;
907 unsigned CursorWidth;
908 bool mRendered;
909 bool HasMask;
910 bool DrawCursor;
911 bool isLocalChange;
912 bool HasAllowed;
913 bool HasDisabled;
914 std::string AllowedList;
915 std::string DisabledList;
916 unsigned MinLen;
917 unsigned MaxLen;
918};
919
920class HardwareKeyboard
921{
922public:
923 HardwareKeyboard(void);
924 virtual ~HardwareKeyboard();
925
926public:
927 virtual int KeyDown(int key_code);
928 virtual int KeyUp(int key_code);
929 virtual int KeyRepeat(void);
930};
931
Vojtech Bocekede51c52014-02-07 23:58:09 +0100932class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200933{
934public:
935 GUISliderValue(xml_node<>* node);
936 virtual ~GUISliderValue();
937
938public:
939 // Render - Render the full object to the GL surface
940 // Return 0 on success, <0 on error
941 virtual int Render(void);
942
943 // Update - Update any UI component animations (called <= 30 FPS)
944 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
945 virtual int Update(void);
946
947 // SetPos - Update the position of the render object
948 // Return 0 on success, <0 on error
949 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
950
951 // NotifyTouch - Notify of a touch event
952 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
953 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
954
955 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100956 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +0200957
958 // SetPageFocus - Notify when a page gains or loses focus
959 virtual void SetPageFocus(int inFocus);
960
961protected:
962 int measureText(const std::string& str);
963 int valueFromPct(float pct);
964 float pctFromValue(int value);
965 void loadValue(bool force = false);
966
967 std::string mVariable;
968 int mMax;
969 int mMin;
970 int mValue;
971 char *mValueStr;
972 float mValuePct;
973 std::string mMaxStr;
974 std::string mMinStr;
975 Resource *mFont;
976 GUIText* mLabel;
977 int mLabelW;
978 COLOR mTextColor;
979 COLOR mLineColor;
980 COLOR mSliderColor;
981 bool mShowRange;
982 bool mShowCurr;
983 int mLineX;
984 int mLineY;
985 int mLineH;
986 int mLinePadding;
987 int mPadding;
988 int mSliderY;
989 int mSliderW;
990 int mSliderH;
991 bool mRendered;
992 int mFontHeight;
993 GUIAction *mAction;
994 bool mChangeOnDrag;
995 int lineW;
996};
997
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100998class MouseCursor : public RenderObject
999{
1000public:
1001 MouseCursor(int posX, int posY);
1002 virtual ~MouseCursor();
1003
1004 virtual int Render(void);
1005 virtual int Update(void);
1006 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1007
1008 void Move(int deltaX, int deltaY);
1009 void GetPos(int& x, int& y);
1010 void LoadData(xml_node<>* node);
1011 void ResetData(int resX, int resY);
1012
1013private:
1014 int m_resX;
1015 int m_resY;
1016 bool m_moved;
1017 float m_speedMultiplier;
1018 COLOR m_color;
1019 Resource *m_image;
1020 bool m_present;
1021};
1022
Dees_Troy51a0e822012-09-05 15:24:24 -04001023// Helper APIs
1024bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1025
1026#endif // _OBJECTS_HEADER
1027