blob: 1053113bdd89423230476cb438e142100b5db631 [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
125class Conditional
126{
127public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200128 Conditional(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400129
130public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200131 bool IsConditionVariable(std::string var);
132 bool isConditionTrue();
133 bool isConditionValid();
134 void NotifyPageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -0400135
136protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 class Condition
138 {
139 public:
140 std::string mVar1;
141 std::string mVar2;
142 std::string mCompareOp;
143 std::string mLastVal;
144 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400145
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200146 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400147
148protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 bool isMounted(std::string vol);
150 bool isConditionTrue(Condition* condition);
Dees_Troy51a0e822012-09-05 15:24:24 -0400151};
152
153class InputObject
154{
155public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200156 InputObject() { HasInputFocus = 0; }
157 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400158
159public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 // NotifyKeyboard - Notify of keyboard input
161 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
162 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400163
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200164 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400165
166protected:
167 int HasInputFocus;
168};
169
170// Derived Objects
171// GUIText - Used for static text
172class GUIText : public RenderObject, public ActionObject, public Conditional
Dees_Troy51a0e822012-09-05 15:24:24 -0400173{
174public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200175 // w and h may be ignored, in which case, no bounding box is applied
176 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400177
178public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200179 // Render - Render the full object to the GL surface
180 // Return 0 on success, <0 on error
181 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400182
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200183 // Update - Update any UI component animations (called <= 30 FPS)
184 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
185 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400186
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200187 // Retrieve the size of the current string (dynamic strings may change per call)
188 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400189
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200190 // Notify of a variable change
191 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400192
193 // Set maximum width in pixels
194 virtual int SetMaxWidth(unsigned width);
195
196 // Set number of characters to skip (for scrolling)
197 virtual int SkipCharCount(unsigned skip);
198
Dees_Troy4d12f962012-10-19 13:13:15 -0400199public:
200 bool isHighlighted;
201
Dees_Troy51a0e822012-09-05 15:24:24 -0400202protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200203 std::string mText;
204 std::string mLastValue;
205 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400206 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200207 Resource* mFont;
208 int mIsStatic;
209 int mVarChanged;
210 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400211 unsigned maxWidth;
212 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400213 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400214
215protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200216 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400217};
218
219// GUIImage - Used for static image
Vojtech Bocek6041a782013-10-11 14:40:01 +0200220class GUIImage : public RenderObject, public Conditional
Dees_Troy51a0e822012-09-05 15:24:24 -0400221{
222public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200223 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400224
225public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200226 // Render - Render the full object to the GL surface
227 // Return 0 on success, <0 on error
228 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400229
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 // SetRenderPos - Update the position of the object
231 // Return 0 on success, <0 on error
232 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400233
Dees_Troy4d12f962012-10-19 13:13:15 -0400234public:
235 bool isHighlighted;
236
Dees_Troy51a0e822012-09-05 15:24:24 -0400237protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200238 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400239 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400240};
241
242// GUIFill - Used for fill colors
243class GUIFill : public RenderObject
244{
245public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200246 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400247
248public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200249 // Render - Render the full object to the GL surface
250 // Return 0 on success, <0 on error
251 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400252
253protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200254 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400255};
256
257// GUIAction - Used for standard actions
258class GUIAction : public ActionObject, public Conditional
259{
260public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200261 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400262
263public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200264 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
265 virtual int NotifyKey(int key);
266 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400267 virtual int doActions();
268
269protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200270 class Action
271 {
272 public:
273 std::string mFunction;
274 std::string mArg;
275 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400276
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200277 std::vector<Action> mActions;
278 int mKey;
Dees_Troy51a0e822012-09-05 15:24:24 -0400279
280protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200281 int getKeyByName(std::string key);
282 virtual int doAction(Action action, int isThreaded = 0);
283 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400284 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200285 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400286 void operation_start(const string operation_name);
287 void operation_end(const int operation_status, const int simulate);
288 static void* command_thread(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000289 time_t Start;
Dees_Troy51a0e822012-09-05 15:24:24 -0400290};
291
292class GUIConsole : public RenderObject, public ActionObject
293{
294public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200295 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400296
297public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200298 // Render - Render the full object to the GL surface
299 // Return 0 on success, <0 on error
300 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400301
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200302 // Update - Update any UI component animations (called <= 30 FPS)
303 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
304 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400305
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200306 // SetRenderPos - Update the position of the object
307 // Return 0 on success, <0 on error
308 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400309
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200310 // IsInRegion - Checks if the request is handled by this object
311 // Return 0 if this object handles the request, 1 if not
312 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400313
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200314 // NotifyTouch - Notify of a touch event
315 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
316 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400317
318protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200319 enum SlideoutState
320 {
321 hidden = 0,
322 visible,
323 request_hide,
324 request_show
325 };
326
327 Resource* mFont;
328 Resource* mSlideoutImage;
329 COLOR mForegroundColor;
330 COLOR mBackgroundColor;
331 COLOR mScrollColor;
332 unsigned int mFontHeight;
333 int mCurrentLine;
334 unsigned int mLastCount;
335 unsigned int mMaxRows;
336 int mStartY;
337 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
338 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
339 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
340 int mLastTouchX, mLastTouchY;
341 int mSlideMultiplier;
342 int mSlideout;
343 SlideoutState mSlideoutState;
Dees_Troy51a0e822012-09-05 15:24:24 -0400344
345protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200346 virtual int RenderSlideout(void);
347 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400348};
349
350class GUIButton : public RenderObject, public ActionObject, public Conditional
351{
352public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200353 GUIButton(xml_node<>* node);
354 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400355
356public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200357 // Render - Render the full object to the GL surface
358 // Return 0 on success, <0 on error
359 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400360
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200361 // Update - Update any UI component animations (called <= 30 FPS)
362 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
363 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400364
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200365 // SetPos - Update the position of the render object
366 // Return 0 on success, <0 on error
367 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400368
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200369 // NotifyTouch - Notify of a touch event
370 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
371 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400372
373protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200374 GUIImage* mButtonImg;
375 Resource* mButtonIcon;
376 GUIText* mButtonLabel;
377 GUIAction* mAction;
378 int mTextX, mTextY, mTextW, mTextH;
379 int mIconX, mIconY, mIconW, mIconH;
380 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600381 bool hasHighlightColor;
382 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500383 bool hasFill;
384 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600385 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000386 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400387};
388
389class GUICheckbox: public RenderObject, public ActionObject, public Conditional
390{
391public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200392 GUICheckbox(xml_node<>* node);
393 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400394
395public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200396 // Render - Render the full object to the GL surface
397 // Return 0 on success, <0 on error
398 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400399
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200400 // Update - Update any UI component animations (called <= 30 FPS)
401 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
402 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400403
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200404 // SetPos - Update the position of the render object
405 // Return 0 on success, <0 on error
406 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400407
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200408 // NotifyTouch - Notify of a touch event
409 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
410 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400411
412protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200413 Resource* mChecked;
414 Resource* mUnchecked;
415 GUIText* mLabel;
416 int mTextX, mTextY;
417 int mCheckX, mCheckY, mCheckW, mCheckH;
418 int mLastState;
419 bool mRendered;
420 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400421};
422
423class GUIFileSelector : public RenderObject, public ActionObject
424{
425public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200426 GUIFileSelector(xml_node<>* node);
427 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400428
429public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200430 // Render - Render the full object to the GL surface
431 // Return 0 on success, <0 on error
432 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400433
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200434 // Update - Update any UI component animations (called <= 30 FPS)
435 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
436 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400437
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200438 // NotifyTouch - Notify of a touch event
439 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
440 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400441
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200442 // NotifyVarChange - Notify of a variable change
443 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400444
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200445 // SetPos - Update the position of the render object
446 // Return 0 on success, <0 on error
447 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400448
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200449 // SetPageFocus - Notify when a page gains or loses focus
450 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400451
452protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200453 struct FileData {
454 std::string fileName;
455 unsigned char fileType; // Uses d_type format from struct dirent
456 mode_t protection; // Uses mode_t format from stat
457 uid_t userId;
458 gid_t groupId;
459 off_t fileSize;
460 time_t lastAccess; // Uses time_t format from stat
461 time_t lastModified; // Uses time_t format from stat
462 time_t lastStatChange; // Uses time_t format from stat
463 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400464
465protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200466 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400467
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200468 virtual int GetFileList(const std::string folder);
469 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400470
471protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200472 std::vector<FileData> mFolderList;
473 std::vector<FileData> mFileList;
474 std::string mPathVar;
475 std::string mExtn;
476 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400477 std::string mSortVariable;
478 std::string mSelection;
479 std::string mHeaderText;
480 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200481 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400482 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200483 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400484 int mSeparatorH;
485 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200486 int mShowFolders, mShowFiles, mShowNavFolders;
487 int mUpdate;
488 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400489 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100490 int mFastScrollW;
491 int mFastScrollLineW;
492 int mFastScrollRectW;
493 int mFastScrollRectH;
494 int mFastScrollRectX;
495 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400496 static int mSortOrder;
497 int startY;
498 int scrollingSpeed;
499 int scrollingY;
500 int mHeaderIsStatic;
501 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200502 unsigned mFontHeight;
503 unsigned mLineHeight;
504 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
505 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400506 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200507 Resource* mFileIcon;
508 Resource* mBackground;
509 Resource* mFont;
510 COLOR mBackgroundColor;
511 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400512 COLOR mHeaderBackgroundColor;
513 COLOR mHeaderFontColor;
514 COLOR mSeparatorColor;
515 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100516 COLOR mFastScrollLineColor;
517 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600518 bool hasHighlightColor;
519 bool hasFontHighlightColor;
520 bool isHighlighted;
521 COLOR mHighlightColor;
522 COLOR mFontHighlightColor;
523 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600524 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400525};
526
527class GUIListBox : public RenderObject, public ActionObject
528{
529public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200530 GUIListBox(xml_node<>* node);
531 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400532
533public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200534 // Render - Render the full object to the GL surface
535 // Return 0 on success, <0 on error
536 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400537
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200538 // Update - Update any UI component animations (called <= 30 FPS)
539 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
540 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400541
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200542 // NotifyTouch - Notify of a touch event
543 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
544 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400545
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200546 // NotifyVarChange - Notify of a variable change
547 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400548
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 // SetPos - Update the position of the render object
550 // Return 0 on success, <0 on error
551 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400552
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200553 // SetPageFocus - Notify when a page gains or loses focus
554 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400555
556protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200557 struct ListData {
558 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400559 std::string variableValue;
560 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200561 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400562
563protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200564 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400565
566protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200567 std::vector<ListData> mList;
568 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400569 std::string mSelection;
570 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600571 std::string mHeaderText;
572 std::string mLastValue;
573 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200574 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600575 int startY;
576 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200577 int mLineSpacing;
578 int mUpdate;
579 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000580 int mFastScrollW;
581 int mFastScrollLineW;
582 int mFastScrollRectW;
583 int mFastScrollRectH;
584 int mFastScrollRectX;
585 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600586 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
587 int scrollingSpeed;
588 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400589 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200590 unsigned mFontHeight;
591 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600592 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200593 Resource* mIconSelected;
594 Resource* mIconUnselected;
595 Resource* mBackground;
596 Resource* mFont;
597 COLOR mBackgroundColor;
598 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600599 COLOR mHeaderBackgroundColor;
600 COLOR mHeaderFontColor;
601 COLOR mSeparatorColor;
602 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000603 COLOR mFastScrollLineColor;
604 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600605 bool hasHighlightColor;
606 bool hasFontHighlightColor;
607 bool isHighlighted;
608 COLOR mHighlightColor;
609 COLOR mFontHighlightColor;
610 int mHeaderIsStatic;
611 int startSelection;
612 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400613};
614
Dees_Troya13d74f2013-03-24 08:54:55 -0500615class GUIPartitionList : public RenderObject, public ActionObject
616{
617public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200618 GUIPartitionList(xml_node<>* node);
619 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500620
621public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200622 // Render - Render the full object to the GL surface
623 // Return 0 on success, <0 on error
624 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500625
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200626 // Update - Update any UI component animations (called <= 30 FPS)
627 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
628 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500629
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200630 // NotifyTouch - Notify of a touch event
631 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
632 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500633
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200634 // NotifyVarChange - Notify of a variable change
635 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500636
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200637 // SetPos - Update the position of the render object
638 // Return 0 on success, <0 on error
639 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500640
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200641 // SetPageFocus - Notify when a page gains or loses focus
642 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500643
644protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200645 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500646 virtual void MatchList(void);
647
648protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200649 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500650 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200651 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500652 std::string selectedList;
653 std::string currentValue;
654 std::string mHeaderText;
655 std::string mLastValue;
656 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200657 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500658 int startY;
659 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200660 int mLineSpacing;
661 int mUpdate;
662 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500663 int mFastScrollW;
664 int mFastScrollLineW;
665 int mFastScrollRectW;
666 int mFastScrollRectH;
667 int mFastScrollRectX;
668 int mFastScrollRectY;
669 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
670 int scrollingSpeed;
671 int scrollingY;
672 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200673 unsigned mFontHeight;
674 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500675 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200676 Resource* mIconSelected;
677 Resource* mIconUnselected;
678 Resource* mBackground;
679 Resource* mFont;
680 COLOR mBackgroundColor;
681 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500682 COLOR mHeaderBackgroundColor;
683 COLOR mHeaderFontColor;
684 COLOR mSeparatorColor;
685 COLOR mHeaderSeparatorColor;
686 COLOR mFastScrollLineColor;
687 COLOR mFastScrollRectColor;
688 bool hasHighlightColor;
689 bool hasFontHighlightColor;
690 bool isHighlighted;
691 COLOR mHighlightColor;
692 COLOR mFontHighlightColor;
693 int mHeaderIsStatic;
694 int startSelection;
695 int touchDebounce;
696 bool updateList;
697};
698
Dees_Troy51a0e822012-09-05 15:24:24 -0400699// GUIAnimation - Used for animations
700class GUIAnimation : public RenderObject
701{
702public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200703 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400704
705public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200706 // Render - Render the full object to the GL surface
707 // Return 0 on success, <0 on error
708 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400709
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200710 // Update - Update any UI component animations (called <= 30 FPS)
711 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
712 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400713
714protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200715 AnimationResource* mAnimation;
716 int mFrame;
717 int mFPS;
718 int mLoop;
719 int mRender;
720 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400721};
722
723class GUIProgressBar : public RenderObject, public ActionObject
724{
725public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200726 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400727
728public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200729 // Render - Render the full object to the GL surface
730 // Return 0 on success, <0 on error
731 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400732
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200733 // Update - Update any UI component animations (called <= 30 FPS)
734 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
735 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400736
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200737 // NotifyVarChange - Notify of a variable change
738 // Returns 0 on success, <0 on error
739 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400740
741protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200742 Resource* mEmptyBar;
743 Resource* mFullBar;
744 std::string mMinValVar;
745 std::string mMaxValVar;
746 std::string mCurValVar;
747 float mSlide;
748 float mSlideInc;
749 int mSlideFrames;
750 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400751
752protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200753 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400754};
755
756class GUISlider : public RenderObject, public ActionObject
757{
758public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200759 GUISlider(xml_node<>* node);
760 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400761
762public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200763 // Render - Render the full object to the GL surface
764 // Return 0 on success, <0 on error
765 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400766
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200767 // Update - Update any UI component animations (called <= 30 FPS)
768 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
769 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400770
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200771 // NotifyTouch - Notify of a touch event
772 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
773 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400774
775protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200776 GUIAction* sAction;
777 Resource* sSlider;
778 Resource* sSliderUsed;
779 Resource* sTouch;
780 int sTouchW, sTouchH;
781 int sCurTouchX;
782 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400783};
784
785#define MAX_KEYBOARD_LAYOUTS 5
786#define MAX_KEYBOARD_ROWS 9
787#define MAX_KEYBOARD_KEYS 20
788#define KEYBOARD_ACTION 253
789#define KEYBOARD_LAYOUT 254
790#define KEYBOARD_SWIPE_LEFT 252
791#define KEYBOARD_SWIPE_RIGHT 251
792#define KEYBOARD_ARROW_LEFT 250
793#define KEYBOARD_ARROW_RIGHT 249
794#define KEYBOARD_HOME 248
795#define KEYBOARD_END 247
796#define KEYBOARD_ARROW_UP 246
797#define KEYBOARD_ARROW_DOWN 245
798#define KEYBOARD_SPECIAL_KEYS 245
799#define KEYBOARD_BACKSPACE 8
800
801class GUIKeyboard : public RenderObject, public ActionObject, public Conditional
802{
803public:
804 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200805 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400806
807public:
808 virtual int Render(void);
809 virtual int Update(void);
810 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
811 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
812
813protected:
814 virtual int GetSelection(int x, int y);
815
816protected:
817 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200818 {
819 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400820 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200821 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400822 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200823 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400824
825 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
826 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
827 bool mRendered;
828 std::string mVariable;
829 unsigned int cursorLocation;
830 unsigned int currentLayout;
831 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
832 unsigned int KeyboardWidth, KeyboardHeight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400833 int rowY, colX, highlightRenderCount, hasHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400834 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400835 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400836};
837
838// GUIInput - Used for keyboard input
839class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject
840{
841public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200842 // w and h may be ignored, in which case, no bounding box is applied
843 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400844 virtual ~GUIInput();
845
846public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200847 // Render - Render the full object to the GL surface
848 // Return 0 on success, <0 on error
849 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400850
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200851 // Update - Update any UI component animations (called <= 30 FPS)
852 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
853 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400854
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200855 // Notify of a variable change
856 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400857
858 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200859 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
860 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400861
862 virtual int NotifyKeyboard(int key);
863
864protected:
865 virtual int GetSelection(int x, int y);
866
867 // Handles displaying the text properly when chars are added, deleted, or for scrolling
868 virtual int HandleTextLocation(int x);
869
870protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200871 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400872 GUIAction* mAction;
873 Resource* mBackground;
874 Resource* mCursor;
875 Resource* mFont;
876 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200877 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400878 std::string mVariable;
879 std::string mMask;
880 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200881 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400882 COLOR mCursorColor;
883 int scrollingX;
884 int lastX;
885 int mCursorLocation;
886 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
887 int mFontY;
888 unsigned skipChars;
889 unsigned mFontHeight;
890 unsigned CursorWidth;
891 bool mRendered;
892 bool HasMask;
893 bool DrawCursor;
894 bool isLocalChange;
895 bool HasAllowed;
896 bool HasDisabled;
897 std::string AllowedList;
898 std::string DisabledList;
899 unsigned MinLen;
900 unsigned MaxLen;
901};
902
903class HardwareKeyboard
904{
905public:
906 HardwareKeyboard(void);
907 virtual ~HardwareKeyboard();
908
909public:
910 virtual int KeyDown(int key_code);
911 virtual int KeyUp(int key_code);
912 virtual int KeyRepeat(void);
913};
914
Vojtech Bocek85932342013-04-01 22:11:33 +0200915class GUISliderValue: public RenderObject, public ActionObject, public Conditional
916{
917public:
918 GUISliderValue(xml_node<>* node);
919 virtual ~GUISliderValue();
920
921public:
922 // Render - Render the full object to the GL surface
923 // Return 0 on success, <0 on error
924 virtual int Render(void);
925
926 // Update - Update any UI component animations (called <= 30 FPS)
927 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
928 virtual int Update(void);
929
930 // SetPos - Update the position of the render object
931 // Return 0 on success, <0 on error
932 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
933
934 // NotifyTouch - Notify of a touch event
935 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
936 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
937
938 // Notify of a variable change
939 virtual int NotifyVarChange(std::string varName, std::string value);
940
941 // SetPageFocus - Notify when a page gains or loses focus
942 virtual void SetPageFocus(int inFocus);
943
944protected:
945 int measureText(const std::string& str);
946 int valueFromPct(float pct);
947 float pctFromValue(int value);
948 void loadValue(bool force = false);
949
950 std::string mVariable;
951 int mMax;
952 int mMin;
953 int mValue;
954 char *mValueStr;
955 float mValuePct;
956 std::string mMaxStr;
957 std::string mMinStr;
958 Resource *mFont;
959 GUIText* mLabel;
960 int mLabelW;
961 COLOR mTextColor;
962 COLOR mLineColor;
963 COLOR mSliderColor;
964 bool mShowRange;
965 bool mShowCurr;
966 int mLineX;
967 int mLineY;
968 int mLineH;
969 int mLinePadding;
970 int mPadding;
971 int mSliderY;
972 int mSliderW;
973 int mSliderH;
974 bool mRendered;
975 int mFontHeight;
976 GUIAction *mAction;
977 bool mChangeOnDrag;
978 int lineW;
979};
980
Dees_Troy51a0e822012-09-05 15:24:24 -0400981// Helper APIs
982bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
983
984#endif // _OBJECTS_HEADER
985