blob: 42dfb1f09f9d77d194be6a83adbb41e34e6878aa [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
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200117 // NotifyVarChange - Notify of a variable change
118 // Returns 0 on success, <0 on error
119 virtual int NotifyVarChange(std::string varName, std::string value) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400120
121protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200122 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400123};
124
Vojtech Bocekede51c52014-02-07 23:58:09 +0100125class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400126{
127public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100128 GUIObject(xml_node<>* node);
129 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400130
131public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200132 bool IsConditionVariable(std::string var);
133 bool isConditionTrue();
134 bool isConditionValid();
135 void NotifyPageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -0400136
137protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200138 class Condition
139 {
140 public:
141 std::string mVar1;
142 std::string mVar2;
143 std::string mCompareOp;
144 std::string mLastVal;
145 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400146
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200147 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400148
149protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200150 bool isMounted(std::string vol);
151 bool isConditionTrue(Condition* condition);
Dees_Troy51a0e822012-09-05 15:24:24 -0400152};
153
154class InputObject
155{
156public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200157 InputObject() { HasInputFocus = 0; }
158 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400159
160public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200161 // NotifyKeyboard - Notify of keyboard input
162 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
163 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400164
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200165 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400166
167protected:
168 int HasInputFocus;
169};
170
171// Derived Objects
172// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100173class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400174{
175public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200176 // w and h may be ignored, in which case, no bounding box is applied
177 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400178
179public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200180 // Render - Render the full object to the GL surface
181 // Return 0 on success, <0 on error
182 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400183
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200184 // Update - Update any UI component animations (called <= 30 FPS)
185 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
186 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400187
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200188 // Retrieve the size of the current string (dynamic strings may change per call)
189 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400190
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200191 // Notify of a variable change
192 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400193
194 // Set maximum width in pixels
195 virtual int SetMaxWidth(unsigned width);
196
197 // Set number of characters to skip (for scrolling)
198 virtual int SkipCharCount(unsigned skip);
199
Dees_Troy4d12f962012-10-19 13:13:15 -0400200public:
201 bool isHighlighted;
202
Dees_Troy51a0e822012-09-05 15:24:24 -0400203protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200204 std::string mText;
205 std::string mLastValue;
206 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400207 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200208 Resource* mFont;
209 int mIsStatic;
210 int mVarChanged;
211 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400212 unsigned maxWidth;
213 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400214 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400215
216protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200217 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400218};
219
220// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100221class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400222{
223public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200224 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400225
226public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200227 // Render - Render the full object to the GL surface
228 // Return 0 on success, <0 on error
229 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400230
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200231 // SetRenderPos - Update the position of the object
232 // Return 0 on success, <0 on error
233 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400234
Dees_Troy4d12f962012-10-19 13:13:15 -0400235public:
236 bool isHighlighted;
237
Dees_Troy51a0e822012-09-05 15:24:24 -0400238protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200239 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400240 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400241};
242
243// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100244class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400245{
246public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200247 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400248
249public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200250 // Render - Render the full object to the GL surface
251 // Return 0 on success, <0 on error
252 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400253
254protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200255 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400256};
257
258// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100259class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400260{
261public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200262 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400263
264public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200265 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
266 virtual int NotifyKey(int key);
267 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400268 virtual int doActions();
269
270protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200271 class Action
272 {
273 public:
274 std::string mFunction;
275 std::string mArg;
276 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400277
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200278 std::vector<Action> mActions;
279 int mKey;
Dees_Troy51a0e822012-09-05 15:24:24 -0400280
281protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200282 int getKeyByName(std::string key);
283 virtual int doAction(Action action, int isThreaded = 0);
284 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400285 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200286 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400287 void operation_start(const string operation_name);
288 void operation_end(const int operation_status, const int simulate);
289 static void* command_thread(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000290 time_t Start;
Dees_Troy51a0e822012-09-05 15:24:24 -0400291};
292
Vojtech Bocekede51c52014-02-07 23:58:09 +0100293class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400294{
295public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200296 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400297
298public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200299 // Render - Render the full object to the GL surface
300 // Return 0 on success, <0 on error
301 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400302
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200303 // Update - Update any UI component animations (called <= 30 FPS)
304 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
305 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400306
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200307 // SetRenderPos - Update the position of the object
308 // Return 0 on success, <0 on error
309 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400310
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200311 // IsInRegion - Checks if the request is handled by this object
312 // Return 0 if this object handles the request, 1 if not
313 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400314
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200315 // NotifyTouch - Notify of a touch event
316 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
317 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400318
319protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200320 enum SlideoutState
321 {
322 hidden = 0,
323 visible,
324 request_hide,
325 request_show
326 };
327
328 Resource* mFont;
329 Resource* mSlideoutImage;
330 COLOR mForegroundColor;
331 COLOR mBackgroundColor;
332 COLOR mScrollColor;
333 unsigned int mFontHeight;
334 int mCurrentLine;
335 unsigned int mLastCount;
336 unsigned int mMaxRows;
337 int mStartY;
338 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
339 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
340 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
341 int mLastTouchX, mLastTouchY;
342 int mSlideMultiplier;
343 int mSlideout;
344 SlideoutState mSlideoutState;
Dees_Troy51a0e822012-09-05 15:24:24 -0400345
346protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200347 virtual int RenderSlideout(void);
348 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400349};
350
Vojtech Bocekede51c52014-02-07 23:58:09 +0100351class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400352{
353public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200354 GUIButton(xml_node<>* node);
355 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400356
357public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200358 // Render - Render the full object to the GL surface
359 // Return 0 on success, <0 on error
360 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400361
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200362 // Update - Update any UI component animations (called <= 30 FPS)
363 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
364 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400365
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200366 // SetPos - Update the position of the render object
367 // Return 0 on success, <0 on error
368 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400369
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200370 // NotifyTouch - Notify of a touch event
371 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
372 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400373
374protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200375 GUIImage* mButtonImg;
376 Resource* mButtonIcon;
377 GUIText* mButtonLabel;
378 GUIAction* mAction;
379 int mTextX, mTextY, mTextW, mTextH;
380 int mIconX, mIconY, mIconW, mIconH;
381 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600382 bool hasHighlightColor;
383 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500384 bool hasFill;
385 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600386 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000387 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400388};
389
Vojtech Bocekede51c52014-02-07 23:58:09 +0100390class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400391{
392public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200393 GUICheckbox(xml_node<>* node);
394 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400395
396public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200397 // Render - Render the full object to the GL surface
398 // Return 0 on success, <0 on error
399 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400400
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200401 // Update - Update any UI component animations (called <= 30 FPS)
402 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
403 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400404
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200405 // SetPos - Update the position of the render object
406 // Return 0 on success, <0 on error
407 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400408
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200409 // NotifyTouch - Notify of a touch event
410 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
411 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400412
413protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200414 Resource* mChecked;
415 Resource* mUnchecked;
416 GUIText* mLabel;
417 int mTextX, mTextY;
418 int mCheckX, mCheckY, mCheckW, mCheckH;
419 int mLastState;
420 bool mRendered;
421 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400422};
423
Vojtech Bocekede51c52014-02-07 23:58:09 +0100424class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400425{
426public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200427 GUIFileSelector(xml_node<>* node);
428 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400429
430public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200431 // Render - Render the full object to the GL surface
432 // Return 0 on success, <0 on error
433 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400434
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200435 // Update - Update any UI component animations (called <= 30 FPS)
436 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
437 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400438
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200439 // NotifyTouch - Notify of a touch event
440 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
441 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400442
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200443 // NotifyVarChange - Notify of a variable change
444 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400445
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200446 // SetPos - Update the position of the render object
447 // Return 0 on success, <0 on error
448 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400449
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200450 // SetPageFocus - Notify when a page gains or loses focus
451 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400452
453protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200454 struct FileData {
455 std::string fileName;
456 unsigned char fileType; // Uses d_type format from struct dirent
457 mode_t protection; // Uses mode_t format from stat
458 uid_t userId;
459 gid_t groupId;
460 off_t fileSize;
461 time_t lastAccess; // Uses time_t format from stat
462 time_t lastModified; // Uses time_t format from stat
463 time_t lastStatChange; // Uses time_t format from stat
464 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400465
466protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200467 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400468
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200469 virtual int GetFileList(const std::string folder);
470 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400471
472protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200473 std::vector<FileData> mFolderList;
474 std::vector<FileData> mFileList;
475 std::string mPathVar;
476 std::string mExtn;
477 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400478 std::string mSortVariable;
479 std::string mSelection;
480 std::string mHeaderText;
481 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200482 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400483 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200484 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400485 int mSeparatorH;
486 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200487 int mShowFolders, mShowFiles, mShowNavFolders;
488 int mUpdate;
489 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400490 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100491 int mFastScrollW;
492 int mFastScrollLineW;
493 int mFastScrollRectW;
494 int mFastScrollRectH;
495 int mFastScrollRectX;
496 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400497 static int mSortOrder;
498 int startY;
499 int scrollingSpeed;
500 int scrollingY;
501 int mHeaderIsStatic;
502 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200503 unsigned mFontHeight;
504 unsigned mLineHeight;
505 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
506 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400507 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200508 Resource* mFileIcon;
509 Resource* mBackground;
510 Resource* mFont;
511 COLOR mBackgroundColor;
512 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400513 COLOR mHeaderBackgroundColor;
514 COLOR mHeaderFontColor;
515 COLOR mSeparatorColor;
516 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100517 COLOR mFastScrollLineColor;
518 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600519 bool hasHighlightColor;
520 bool hasFontHighlightColor;
521 bool isHighlighted;
522 COLOR mHighlightColor;
523 COLOR mFontHighlightColor;
524 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600525 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400526};
527
Vojtech Bocekede51c52014-02-07 23:58:09 +0100528class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400529{
530public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200531 GUIListBox(xml_node<>* node);
532 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400533
534public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200535 // Render - Render the full object to the GL surface
536 // Return 0 on success, <0 on error
537 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400538
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200539 // Update - Update any UI component animations (called <= 30 FPS)
540 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
541 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400542
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200543 // NotifyTouch - Notify of a touch event
544 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
545 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400546
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200547 // NotifyVarChange - Notify of a variable change
548 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400549
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200550 // SetPos - Update the position of the render object
551 // Return 0 on success, <0 on error
552 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400553
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200554 // SetPageFocus - Notify when a page gains or loses focus
555 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400556
557protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200558 struct ListData {
559 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400560 std::string variableValue;
561 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200562 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400563
564protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200565 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400566
567protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200568 std::vector<ListData> mList;
569 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400570 std::string mSelection;
571 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600572 std::string mHeaderText;
573 std::string mLastValue;
574 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200575 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600576 int startY;
577 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200578 int mLineSpacing;
579 int mUpdate;
580 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000581 int mFastScrollW;
582 int mFastScrollLineW;
583 int mFastScrollRectW;
584 int mFastScrollRectH;
585 int mFastScrollRectX;
586 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600587 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
588 int scrollingSpeed;
589 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400590 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200591 unsigned mFontHeight;
592 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600593 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200594 Resource* mIconSelected;
595 Resource* mIconUnselected;
596 Resource* mBackground;
597 Resource* mFont;
598 COLOR mBackgroundColor;
599 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600600 COLOR mHeaderBackgroundColor;
601 COLOR mHeaderFontColor;
602 COLOR mSeparatorColor;
603 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000604 COLOR mFastScrollLineColor;
605 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600606 bool hasHighlightColor;
607 bool hasFontHighlightColor;
608 bool isHighlighted;
609 COLOR mHighlightColor;
610 COLOR mFontHighlightColor;
611 int mHeaderIsStatic;
612 int startSelection;
613 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400614};
615
Vojtech Bocekede51c52014-02-07 23:58:09 +0100616class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500617{
618public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200619 GUIPartitionList(xml_node<>* node);
620 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500621
622public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200623 // Render - Render the full object to the GL surface
624 // Return 0 on success, <0 on error
625 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500626
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 // Update - Update any UI component animations (called <= 30 FPS)
628 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
629 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500630
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200631 // NotifyTouch - Notify of a touch event
632 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
633 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500634
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200635 // NotifyVarChange - Notify of a variable change
636 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500637
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200638 // SetPos - Update the position of the render object
639 // Return 0 on success, <0 on error
640 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500641
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200642 // SetPageFocus - Notify when a page gains or loses focus
643 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500644
645protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200646 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500647 virtual void MatchList(void);
648
649protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200650 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500651 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200652 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500653 std::string selectedList;
654 std::string currentValue;
655 std::string mHeaderText;
656 std::string mLastValue;
657 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200658 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500659 int startY;
660 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200661 int mLineSpacing;
662 int mUpdate;
663 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500664 int mFastScrollW;
665 int mFastScrollLineW;
666 int mFastScrollRectW;
667 int mFastScrollRectH;
668 int mFastScrollRectX;
669 int mFastScrollRectY;
670 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
671 int scrollingSpeed;
672 int scrollingY;
673 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200674 unsigned mFontHeight;
675 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500676 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200677 Resource* mIconSelected;
678 Resource* mIconUnselected;
679 Resource* mBackground;
680 Resource* mFont;
681 COLOR mBackgroundColor;
682 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500683 COLOR mHeaderBackgroundColor;
684 COLOR mHeaderFontColor;
685 COLOR mSeparatorColor;
686 COLOR mHeaderSeparatorColor;
687 COLOR mFastScrollLineColor;
688 COLOR mFastScrollRectColor;
689 bool hasHighlightColor;
690 bool hasFontHighlightColor;
691 bool isHighlighted;
692 COLOR mHighlightColor;
693 COLOR mFontHighlightColor;
694 int mHeaderIsStatic;
695 int startSelection;
696 int touchDebounce;
697 bool updateList;
698};
699
Dees_Troy51a0e822012-09-05 15:24:24 -0400700// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100701class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400702{
703public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200704 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400705
706public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200707 // Render - Render the full object to the GL surface
708 // Return 0 on success, <0 on error
709 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400710
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200711 // Update - Update any UI component animations (called <= 30 FPS)
712 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
713 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400714
715protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200716 AnimationResource* mAnimation;
717 int mFrame;
718 int mFPS;
719 int mLoop;
720 int mRender;
721 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400722};
723
Vojtech Bocekede51c52014-02-07 23:58:09 +0100724class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400725{
726public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200727 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400728
729public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200730 // Render - Render the full object to the GL surface
731 // Return 0 on success, <0 on error
732 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400733
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200734 // Update - Update any UI component animations (called <= 30 FPS)
735 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
736 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400737
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200738 // NotifyVarChange - Notify of a variable change
739 // Returns 0 on success, <0 on error
740 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400741
742protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200743 Resource* mEmptyBar;
744 Resource* mFullBar;
745 std::string mMinValVar;
746 std::string mMaxValVar;
747 std::string mCurValVar;
748 float mSlide;
749 float mSlideInc;
750 int mSlideFrames;
751 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400752
753protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200754 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400755};
756
Vojtech Bocekede51c52014-02-07 23:58:09 +0100757class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400758{
759public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200760 GUISlider(xml_node<>* node);
761 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400762
763public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200764 // Render - Render the full object to the GL surface
765 // Return 0 on success, <0 on error
766 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400767
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200768 // Update - Update any UI component animations (called <= 30 FPS)
769 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
770 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400771
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200772 // NotifyTouch - Notify of a touch event
773 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
774 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400775
776protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200777 GUIAction* sAction;
778 Resource* sSlider;
779 Resource* sSliderUsed;
780 Resource* sTouch;
781 int sTouchW, sTouchH;
782 int sCurTouchX;
783 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400784};
785
786#define MAX_KEYBOARD_LAYOUTS 5
787#define MAX_KEYBOARD_ROWS 9
788#define MAX_KEYBOARD_KEYS 20
789#define KEYBOARD_ACTION 253
790#define KEYBOARD_LAYOUT 254
791#define KEYBOARD_SWIPE_LEFT 252
792#define KEYBOARD_SWIPE_RIGHT 251
793#define KEYBOARD_ARROW_LEFT 250
794#define KEYBOARD_ARROW_RIGHT 249
795#define KEYBOARD_HOME 248
796#define KEYBOARD_END 247
797#define KEYBOARD_ARROW_UP 246
798#define KEYBOARD_ARROW_DOWN 245
799#define KEYBOARD_SPECIAL_KEYS 245
800#define KEYBOARD_BACKSPACE 8
801
Vojtech Bocekede51c52014-02-07 23:58:09 +0100802class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400803{
804public:
805 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200806 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400807
808public:
809 virtual int Render(void);
810 virtual int Update(void);
811 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
812 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
813
814protected:
815 virtual int GetSelection(int x, int y);
816
817protected:
818 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200819 {
820 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400821 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200822 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400823 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200824 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400825
826 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
827 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
828 bool mRendered;
829 std::string mVariable;
830 unsigned int cursorLocation;
831 unsigned int currentLayout;
832 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
833 unsigned int KeyboardWidth, KeyboardHeight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400834 int rowY, colX, highlightRenderCount, hasHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400835 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400836 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400837};
838
839// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100840class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400841{
842public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200843 // w and h may be ignored, in which case, no bounding box is applied
844 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400845 virtual ~GUIInput();
846
847public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200848 // Render - Render the full object to the GL surface
849 // Return 0 on success, <0 on error
850 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400851
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200852 // Update - Update any UI component animations (called <= 30 FPS)
853 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
854 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400855
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200856 // Notify of a variable change
857 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400858
859 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200860 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
861 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400862
863 virtual int NotifyKeyboard(int key);
864
865protected:
866 virtual int GetSelection(int x, int y);
867
868 // Handles displaying the text properly when chars are added, deleted, or for scrolling
869 virtual int HandleTextLocation(int x);
870
871protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200872 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400873 GUIAction* mAction;
874 Resource* mBackground;
875 Resource* mCursor;
876 Resource* mFont;
877 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200878 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400879 std::string mVariable;
880 std::string mMask;
881 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200882 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400883 COLOR mCursorColor;
884 int scrollingX;
885 int lastX;
886 int mCursorLocation;
887 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
888 int mFontY;
889 unsigned skipChars;
890 unsigned mFontHeight;
891 unsigned CursorWidth;
892 bool mRendered;
893 bool HasMask;
894 bool DrawCursor;
895 bool isLocalChange;
896 bool HasAllowed;
897 bool HasDisabled;
898 std::string AllowedList;
899 std::string DisabledList;
900 unsigned MinLen;
901 unsigned MaxLen;
902};
903
904class HardwareKeyboard
905{
906public:
907 HardwareKeyboard(void);
908 virtual ~HardwareKeyboard();
909
910public:
911 virtual int KeyDown(int key_code);
912 virtual int KeyUp(int key_code);
913 virtual int KeyRepeat(void);
914};
915
Vojtech Bocekede51c52014-02-07 23:58:09 +0100916class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200917{
918public:
919 GUISliderValue(xml_node<>* node);
920 virtual ~GUISliderValue();
921
922public:
923 // Render - Render the full object to the GL surface
924 // Return 0 on success, <0 on error
925 virtual int Render(void);
926
927 // Update - Update any UI component animations (called <= 30 FPS)
928 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
929 virtual int Update(void);
930
931 // SetPos - Update the position of the render object
932 // Return 0 on success, <0 on error
933 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
934
935 // NotifyTouch - Notify of a touch event
936 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
937 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
938
939 // Notify of a variable change
940 virtual int NotifyVarChange(std::string varName, std::string value);
941
942 // SetPageFocus - Notify when a page gains or loses focus
943 virtual void SetPageFocus(int inFocus);
944
945protected:
946 int measureText(const std::string& str);
947 int valueFromPct(float pct);
948 float pctFromValue(int value);
949 void loadValue(bool force = false);
950
951 std::string mVariable;
952 int mMax;
953 int mMin;
954 int mValue;
955 char *mValueStr;
956 float mValuePct;
957 std::string mMaxStr;
958 std::string mMinStr;
959 Resource *mFont;
960 GUIText* mLabel;
961 int mLabelW;
962 COLOR mTextColor;
963 COLOR mLineColor;
964 COLOR mSliderColor;
965 bool mShowRange;
966 bool mShowCurr;
967 int mLineX;
968 int mLineY;
969 int mLineH;
970 int mLinePadding;
971 int mPadding;
972 int mSliderY;
973 int mSliderW;
974 int mSliderH;
975 bool mRendered;
976 int mFontHeight;
977 GUIAction *mAction;
978 bool mChangeOnDrag;
979 int lineW;
980};
981
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100982class MouseCursor : public RenderObject
983{
984public:
985 MouseCursor(int posX, int posY);
986 virtual ~MouseCursor();
987
988 virtual int Render(void);
989 virtual int Update(void);
990 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
991
992 void Move(int deltaX, int deltaY);
993 void GetPos(int& x, int& y);
994 void LoadData(xml_node<>* node);
995 void ResetData(int resX, int resY);
996
997private:
998 int m_resX;
999 int m_resY;
1000 bool m_moved;
1001 float m_speedMultiplier;
1002 COLOR m_color;
1003 Resource *m_image;
1004 bool m_present;
1005};
1006
Dees_Troy51a0e822012-09-05 15:24:24 -04001007// Helper APIs
1008bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1009
1010#endif // _OBJECTS_HEADER
1011