blob: e7bb2a0ee16bfc3e85db14fcf5473291878b1a9b [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>
28
29extern "C" {
Dees Troyb7ae0982013-09-10 20:47:35 +000030#ifdef HAVE_SELINUX
Dees_Troy51a0e822012-09-05 15:24:24 -040031#include "../minzip/Zip.h"
Dees Troyb7ae0982013-09-10 20:47:35 +000032#else
33#include "../minzipold/Zip.h"
34#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040035}
36
37using namespace rapidxml;
38
39#include "../data.hpp"
40#include "resources.hpp"
41#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050042#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040043
44class RenderObject
45{
46public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020047 enum Placement {
48 TOP_LEFT = 0,
49 TOP_RIGHT = 1,
50 BOTTOM_LEFT = 2,
51 BOTTOM_RIGHT = 3,
52 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040053 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020054 };
Dees_Troy51a0e822012-09-05 15:24:24 -040055
56public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020057 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
58 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040059
60public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020061 // Render - Render the full object to the GL surface
62 // Return 0 on success, <0 on error
63 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040064
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020065 // Update - Update any UI component animations (called <= 30 FPS)
66 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
67 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040068
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020069 // GetRenderPos - Returns the current position of the object
70 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 -040071
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020072 // SetRenderPos - Update the position of the object
73 // Return 0 on success, <0 on error
74 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 -040075
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020076 // GetPlacement - Returns the current placement
77 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040078
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020079 // SetPlacement - Update the current placement
80 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040081
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020082 // SetPageFocus - Notify when a page gains or loses focus
83 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040084
85protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020086 int mRenderX, mRenderY, mRenderW, mRenderH;
87 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040088};
89
90class ActionObject
91{
92public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020093 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
94 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040095
96public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020097 // NotifyTouch - Notify of a touch event
98 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
99 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400100
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200101 // NotifyKey - Notify of a key press
102 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
103 virtual int NotifyKey(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400104
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200105 // GetRenderPos - Returns the current position of the object
106 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 -0400107
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200108 // SetRenderPos - Update the position of the object
109 // Return 0 on success, <0 on error
110 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400111
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200112 // IsInRegion - Checks if the request is handled by this object
113 // Return 0 if this object handles the request, 1 if not
114 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 -0400115
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200116 // NotifyVarChange - Notify of a variable change
117 // Returns 0 on success, <0 on error
118 virtual int NotifyVarChange(std::string varName, std::string value) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400119
120protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200121 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400122};
123
124class Conditional
125{
126public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200127 Conditional(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400128
129public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200130 bool IsConditionVariable(std::string var);
131 bool isConditionTrue();
132 bool isConditionValid();
133 void NotifyPageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -0400134
135protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200136 class Condition
137 {
138 public:
139 std::string mVar1;
140 std::string mVar2;
141 std::string mCompareOp;
142 std::string mLastVal;
143 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400144
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200145 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400146
147protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200148 bool isMounted(std::string vol);
149 bool isConditionTrue(Condition* condition);
Dees_Troy51a0e822012-09-05 15:24:24 -0400150};
151
152class InputObject
153{
154public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200155 InputObject() { HasInputFocus = 0; }
156 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400157
158public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200159 // NotifyKeyboard - Notify of keyboard input
160 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
161 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400162
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200163 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400164
165protected:
166 int HasInputFocus;
167};
168
169// Derived Objects
170// GUIText - Used for static text
171class GUIText : public RenderObject, public ActionObject, public Conditional
Dees_Troy51a0e822012-09-05 15:24:24 -0400172{
173public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200174 // w and h may be ignored, in which case, no bounding box is applied
175 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400176
177public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200178 // Render - Render the full object to the GL surface
179 // Return 0 on success, <0 on error
180 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400181
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200182 // Update - Update any UI component animations (called <= 30 FPS)
183 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
184 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400185
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200186 // Retrieve the size of the current string (dynamic strings may change per call)
187 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400188
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200189 // Notify of a variable change
190 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400191
192 // Set maximum width in pixels
193 virtual int SetMaxWidth(unsigned width);
194
195 // Set number of characters to skip (for scrolling)
196 virtual int SkipCharCount(unsigned skip);
197
Dees_Troy4d12f962012-10-19 13:13:15 -0400198public:
199 bool isHighlighted;
200
Dees_Troy51a0e822012-09-05 15:24:24 -0400201protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200202 std::string mText;
203 std::string mLastValue;
204 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400205 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200206 Resource* mFont;
207 int mIsStatic;
208 int mVarChanged;
209 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400210 unsigned maxWidth;
211 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400212 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400213
214protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200215 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400216};
217
218// GUIImage - Used for static image
Vojtech Bocek6041a782013-10-11 14:40:01 +0200219class GUIImage : public RenderObject, public Conditional
Dees_Troy51a0e822012-09-05 15:24:24 -0400220{
221public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200222 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400223
224public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200225 // Render - Render the full object to the GL surface
226 // Return 0 on success, <0 on error
227 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400228
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200229 // SetRenderPos - Update the position of the object
230 // Return 0 on success, <0 on error
231 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400232
Dees_Troy4d12f962012-10-19 13:13:15 -0400233public:
234 bool isHighlighted;
235
Dees_Troy51a0e822012-09-05 15:24:24 -0400236protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200237 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400238 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400239};
240
241// GUIFill - Used for fill colors
242class GUIFill : public RenderObject
243{
244public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200245 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400246
247public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200248 // Render - Render the full object to the GL surface
249 // Return 0 on success, <0 on error
250 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400251
252protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200253 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400254};
255
256// GUIAction - Used for standard actions
257class GUIAction : public ActionObject, public Conditional
258{
259public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200260 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400261
262public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200263 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
264 virtual int NotifyKey(int key);
265 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400266 virtual int doActions();
267
268protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200269 class Action
270 {
271 public:
272 std::string mFunction;
273 std::string mArg;
274 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400275
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200276 std::vector<Action> mActions;
277 int mKey;
Dees_Troy51a0e822012-09-05 15:24:24 -0400278
279protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200280 int getKeyByName(std::string key);
281 virtual int doAction(Action action, int isThreaded = 0);
282 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400283 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200284 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400285 void operation_start(const string operation_name);
286 void operation_end(const int operation_status, const int simulate);
287 static void* command_thread(void *cookie);
288};
289
290class GUIConsole : public RenderObject, public ActionObject
291{
292public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200293 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400294
295public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200296 // Render - Render the full object to the GL surface
297 // Return 0 on success, <0 on error
298 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400299
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200300 // Update - Update any UI component animations (called <= 30 FPS)
301 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
302 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400303
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200304 // SetRenderPos - Update the position of the object
305 // Return 0 on success, <0 on error
306 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400307
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200308 // IsInRegion - Checks if the request is handled by this object
309 // Return 0 if this object handles the request, 1 if not
310 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400311
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200312 // NotifyTouch - Notify of a touch event
313 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
314 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400315
316protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200317 enum SlideoutState
318 {
319 hidden = 0,
320 visible,
321 request_hide,
322 request_show
323 };
324
325 Resource* mFont;
326 Resource* mSlideoutImage;
327 COLOR mForegroundColor;
328 COLOR mBackgroundColor;
329 COLOR mScrollColor;
330 unsigned int mFontHeight;
331 int mCurrentLine;
332 unsigned int mLastCount;
333 unsigned int mMaxRows;
334 int mStartY;
335 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
336 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
337 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
338 int mLastTouchX, mLastTouchY;
339 int mSlideMultiplier;
340 int mSlideout;
341 SlideoutState mSlideoutState;
Dees_Troy51a0e822012-09-05 15:24:24 -0400342
343protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200344 virtual int RenderSlideout(void);
345 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400346};
347
348class GUIButton : public RenderObject, public ActionObject, public Conditional
349{
350public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200351 GUIButton(xml_node<>* node);
352 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400353
354public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200355 // Render - Render the full object to the GL surface
356 // Return 0 on success, <0 on error
357 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400358
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200359 // Update - Update any UI component animations (called <= 30 FPS)
360 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
361 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400362
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200363 // SetPos - Update the position of the render object
364 // Return 0 on success, <0 on error
365 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400366
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200367 // NotifyTouch - Notify of a touch event
368 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
369 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400370
371protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200372 GUIImage* mButtonImg;
373 Resource* mButtonIcon;
374 GUIText* mButtonLabel;
375 GUIAction* mAction;
376 int mTextX, mTextY, mTextW, mTextH;
377 int mIconX, mIconY, mIconW, mIconH;
378 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600379 bool hasHighlightColor;
380 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500381 bool hasFill;
382 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600383 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000384 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400385};
386
387class GUICheckbox: public RenderObject, public ActionObject, public Conditional
388{
389public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200390 GUICheckbox(xml_node<>* node);
391 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400392
393public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200394 // Render - Render the full object to the GL surface
395 // Return 0 on success, <0 on error
396 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400397
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200398 // Update - Update any UI component animations (called <= 30 FPS)
399 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
400 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400401
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200402 // SetPos - Update the position of the render object
403 // Return 0 on success, <0 on error
404 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400405
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200406 // NotifyTouch - Notify of a touch event
407 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
408 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400409
410protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200411 Resource* mChecked;
412 Resource* mUnchecked;
413 GUIText* mLabel;
414 int mTextX, mTextY;
415 int mCheckX, mCheckY, mCheckW, mCheckH;
416 int mLastState;
417 bool mRendered;
418 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400419};
420
421class GUIFileSelector : public RenderObject, public ActionObject
422{
423public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200424 GUIFileSelector(xml_node<>* node);
425 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400426
427public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200428 // Render - Render the full object to the GL surface
429 // Return 0 on success, <0 on error
430 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400431
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200432 // Update - Update any UI component animations (called <= 30 FPS)
433 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
434 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400435
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200436 // NotifyTouch - Notify of a touch event
437 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
438 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400439
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200440 // NotifyVarChange - Notify of a variable change
441 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400442
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200443 // SetPos - Update the position of the render object
444 // Return 0 on success, <0 on error
445 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400446
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200447 // SetPageFocus - Notify when a page gains or loses focus
448 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400449
450protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200451 struct FileData {
452 std::string fileName;
453 unsigned char fileType; // Uses d_type format from struct dirent
454 mode_t protection; // Uses mode_t format from stat
455 uid_t userId;
456 gid_t groupId;
457 off_t fileSize;
458 time_t lastAccess; // Uses time_t format from stat
459 time_t lastModified; // Uses time_t format from stat
460 time_t lastStatChange; // Uses time_t format from stat
461 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400462
463protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200464 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400465
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200466 virtual int GetFileList(const std::string folder);
467 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400468
469protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200470 std::vector<FileData> mFolderList;
471 std::vector<FileData> mFileList;
472 std::string mPathVar;
473 std::string mExtn;
474 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400475 std::string mSortVariable;
476 std::string mSelection;
477 std::string mHeaderText;
478 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200479 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400480 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200481 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400482 int mSeparatorH;
483 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200484 int mShowFolders, mShowFiles, mShowNavFolders;
485 int mUpdate;
486 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400487 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100488 int mFastScrollW;
489 int mFastScrollLineW;
490 int mFastScrollRectW;
491 int mFastScrollRectH;
492 int mFastScrollRectX;
493 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400494 static int mSortOrder;
495 int startY;
496 int scrollingSpeed;
497 int scrollingY;
498 int mHeaderIsStatic;
499 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200500 unsigned mFontHeight;
501 unsigned mLineHeight;
502 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
503 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400504 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200505 Resource* mFileIcon;
506 Resource* mBackground;
507 Resource* mFont;
508 COLOR mBackgroundColor;
509 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400510 COLOR mHeaderBackgroundColor;
511 COLOR mHeaderFontColor;
512 COLOR mSeparatorColor;
513 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100514 COLOR mFastScrollLineColor;
515 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600516 bool hasHighlightColor;
517 bool hasFontHighlightColor;
518 bool isHighlighted;
519 COLOR mHighlightColor;
520 COLOR mFontHighlightColor;
521 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600522 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400523};
524
525class GUIListBox : public RenderObject, public ActionObject
526{
527public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200528 GUIListBox(xml_node<>* node);
529 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400530
531public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200532 // Render - Render the full object to the GL surface
533 // Return 0 on success, <0 on error
534 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400535
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200536 // Update - Update any UI component animations (called <= 30 FPS)
537 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
538 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400539
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200540 // NotifyTouch - Notify of a touch event
541 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
542 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400543
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200544 // NotifyVarChange - Notify of a variable change
545 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400546
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200547 // SetPos - Update the position of the render object
548 // Return 0 on success, <0 on error
549 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400550
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200551 // SetPageFocus - Notify when a page gains or loses focus
552 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400553
554protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200555 struct ListData {
556 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400557 std::string variableValue;
558 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200559 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400560
561protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200562 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400563
564protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200565 std::vector<ListData> mList;
566 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400567 std::string mSelection;
568 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600569 std::string mHeaderText;
570 std::string mLastValue;
571 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200572 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600573 int startY;
574 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200575 int mLineSpacing;
576 int mUpdate;
577 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000578 int mFastScrollW;
579 int mFastScrollLineW;
580 int mFastScrollRectW;
581 int mFastScrollRectH;
582 int mFastScrollRectX;
583 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600584 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
585 int scrollingSpeed;
586 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400587 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200588 unsigned mFontHeight;
589 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600590 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200591 Resource* mIconSelected;
592 Resource* mIconUnselected;
593 Resource* mBackground;
594 Resource* mFont;
595 COLOR mBackgroundColor;
596 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600597 COLOR mHeaderBackgroundColor;
598 COLOR mHeaderFontColor;
599 COLOR mSeparatorColor;
600 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000601 COLOR mFastScrollLineColor;
602 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600603 bool hasHighlightColor;
604 bool hasFontHighlightColor;
605 bool isHighlighted;
606 COLOR mHighlightColor;
607 COLOR mFontHighlightColor;
608 int mHeaderIsStatic;
609 int startSelection;
610 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400611};
612
Dees_Troya13d74f2013-03-24 08:54:55 -0500613class GUIPartitionList : public RenderObject, public ActionObject
614{
615public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200616 GUIPartitionList(xml_node<>* node);
617 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500618
619public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200620 // Render - Render the full object to the GL surface
621 // Return 0 on success, <0 on error
622 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500623
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200624 // Update - Update any UI component animations (called <= 30 FPS)
625 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
626 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500627
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200628 // NotifyTouch - Notify of a touch event
629 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
630 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500631
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200632 // NotifyVarChange - Notify of a variable change
633 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500634
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200635 // SetPos - Update the position of the render object
636 // Return 0 on success, <0 on error
637 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500638
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200639 // SetPageFocus - Notify when a page gains or loses focus
640 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500641
642protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200643 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500644 virtual void MatchList(void);
645
646protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200647 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500648 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200649 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500650 std::string selectedList;
651 std::string currentValue;
652 std::string mHeaderText;
653 std::string mLastValue;
654 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200655 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500656 int startY;
657 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200658 int mLineSpacing;
659 int mUpdate;
660 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500661 int mFastScrollW;
662 int mFastScrollLineW;
663 int mFastScrollRectW;
664 int mFastScrollRectH;
665 int mFastScrollRectX;
666 int mFastScrollRectY;
667 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
668 int scrollingSpeed;
669 int scrollingY;
670 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200671 unsigned mFontHeight;
672 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500673 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200674 Resource* mIconSelected;
675 Resource* mIconUnselected;
676 Resource* mBackground;
677 Resource* mFont;
678 COLOR mBackgroundColor;
679 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500680 COLOR mHeaderBackgroundColor;
681 COLOR mHeaderFontColor;
682 COLOR mSeparatorColor;
683 COLOR mHeaderSeparatorColor;
684 COLOR mFastScrollLineColor;
685 COLOR mFastScrollRectColor;
686 bool hasHighlightColor;
687 bool hasFontHighlightColor;
688 bool isHighlighted;
689 COLOR mHighlightColor;
690 COLOR mFontHighlightColor;
691 int mHeaderIsStatic;
692 int startSelection;
693 int touchDebounce;
694 bool updateList;
695};
696
Dees_Troy51a0e822012-09-05 15:24:24 -0400697// GUIAnimation - Used for animations
698class GUIAnimation : public RenderObject
699{
700public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200701 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400702
703public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200704 // Render - Render the full object to the GL surface
705 // Return 0 on success, <0 on error
706 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400707
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200708 // Update - Update any UI component animations (called <= 30 FPS)
709 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
710 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400711
712protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200713 AnimationResource* mAnimation;
714 int mFrame;
715 int mFPS;
716 int mLoop;
717 int mRender;
718 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400719};
720
721class GUIProgressBar : public RenderObject, public ActionObject
722{
723public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200724 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400725
726public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200727 // Render - Render the full object to the GL surface
728 // Return 0 on success, <0 on error
729 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400730
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200731 // Update - Update any UI component animations (called <= 30 FPS)
732 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
733 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400734
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200735 // NotifyVarChange - Notify of a variable change
736 // Returns 0 on success, <0 on error
737 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400738
739protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200740 Resource* mEmptyBar;
741 Resource* mFullBar;
742 std::string mMinValVar;
743 std::string mMaxValVar;
744 std::string mCurValVar;
745 float mSlide;
746 float mSlideInc;
747 int mSlideFrames;
748 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400749
750protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200751 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400752};
753
754class GUISlider : public RenderObject, public ActionObject
755{
756public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200757 GUISlider(xml_node<>* node);
758 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400759
760public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200761 // Render - Render the full object to the GL surface
762 // Return 0 on success, <0 on error
763 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400764
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200765 // Update - Update any UI component animations (called <= 30 FPS)
766 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
767 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400768
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200769 // NotifyTouch - Notify of a touch event
770 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
771 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400772
773protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200774 GUIAction* sAction;
775 Resource* sSlider;
776 Resource* sSliderUsed;
777 Resource* sTouch;
778 int sTouchW, sTouchH;
779 int sCurTouchX;
780 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400781};
782
783#define MAX_KEYBOARD_LAYOUTS 5
784#define MAX_KEYBOARD_ROWS 9
785#define MAX_KEYBOARD_KEYS 20
786#define KEYBOARD_ACTION 253
787#define KEYBOARD_LAYOUT 254
788#define KEYBOARD_SWIPE_LEFT 252
789#define KEYBOARD_SWIPE_RIGHT 251
790#define KEYBOARD_ARROW_LEFT 250
791#define KEYBOARD_ARROW_RIGHT 249
792#define KEYBOARD_HOME 248
793#define KEYBOARD_END 247
794#define KEYBOARD_ARROW_UP 246
795#define KEYBOARD_ARROW_DOWN 245
796#define KEYBOARD_SPECIAL_KEYS 245
797#define KEYBOARD_BACKSPACE 8
798
799class GUIKeyboard : public RenderObject, public ActionObject, public Conditional
800{
801public:
802 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200803 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400804
805public:
806 virtual int Render(void);
807 virtual int Update(void);
808 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
809 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
810
811protected:
812 virtual int GetSelection(int x, int y);
813
814protected:
815 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200816 {
817 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400818 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200819 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400820 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200821 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400822
823 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
824 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
825 bool mRendered;
826 std::string mVariable;
827 unsigned int cursorLocation;
828 unsigned int currentLayout;
829 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
830 unsigned int KeyboardWidth, KeyboardHeight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400831 int rowY, colX, highlightRenderCount, hasHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400832 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400833 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400834};
835
836// GUIInput - Used for keyboard input
837class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject
838{
839public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200840 // w and h may be ignored, in which case, no bounding box is applied
841 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400842 virtual ~GUIInput();
843
844public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200845 // Render - Render the full object to the GL surface
846 // Return 0 on success, <0 on error
847 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400848
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200849 // Update - Update any UI component animations (called <= 30 FPS)
850 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
851 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400852
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200853 // Notify of a variable change
854 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400855
856 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200857 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
858 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400859
860 virtual int NotifyKeyboard(int key);
861
862protected:
863 virtual int GetSelection(int x, int y);
864
865 // Handles displaying the text properly when chars are added, deleted, or for scrolling
866 virtual int HandleTextLocation(int x);
867
868protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200869 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400870 GUIAction* mAction;
871 Resource* mBackground;
872 Resource* mCursor;
873 Resource* mFont;
874 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200875 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400876 std::string mVariable;
877 std::string mMask;
878 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200879 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400880 COLOR mCursorColor;
881 int scrollingX;
882 int lastX;
883 int mCursorLocation;
884 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
885 int mFontY;
886 unsigned skipChars;
887 unsigned mFontHeight;
888 unsigned CursorWidth;
889 bool mRendered;
890 bool HasMask;
891 bool DrawCursor;
892 bool isLocalChange;
893 bool HasAllowed;
894 bool HasDisabled;
895 std::string AllowedList;
896 std::string DisabledList;
897 unsigned MinLen;
898 unsigned MaxLen;
899};
900
901class HardwareKeyboard
902{
903public:
904 HardwareKeyboard(void);
905 virtual ~HardwareKeyboard();
906
907public:
908 virtual int KeyDown(int key_code);
909 virtual int KeyUp(int key_code);
910 virtual int KeyRepeat(void);
911};
912
Vojtech Bocek85932342013-04-01 22:11:33 +0200913class GUISliderValue: public RenderObject, public ActionObject, public Conditional
914{
915public:
916 GUISliderValue(xml_node<>* node);
917 virtual ~GUISliderValue();
918
919public:
920 // Render - Render the full object to the GL surface
921 // Return 0 on success, <0 on error
922 virtual int Render(void);
923
924 // Update - Update any UI component animations (called <= 30 FPS)
925 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
926 virtual int Update(void);
927
928 // SetPos - Update the position of the render object
929 // Return 0 on success, <0 on error
930 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
931
932 // NotifyTouch - Notify of a touch event
933 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
934 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
935
936 // Notify of a variable change
937 virtual int NotifyVarChange(std::string varName, std::string value);
938
939 // SetPageFocus - Notify when a page gains or loses focus
940 virtual void SetPageFocus(int inFocus);
941
942protected:
943 int measureText(const std::string& str);
944 int valueFromPct(float pct);
945 float pctFromValue(int value);
946 void loadValue(bool force = false);
947
948 std::string mVariable;
949 int mMax;
950 int mMin;
951 int mValue;
952 char *mValueStr;
953 float mValuePct;
954 std::string mMaxStr;
955 std::string mMinStr;
956 Resource *mFont;
957 GUIText* mLabel;
958 int mLabelW;
959 COLOR mTextColor;
960 COLOR mLineColor;
961 COLOR mSliderColor;
962 bool mShowRange;
963 bool mShowCurr;
964 int mLineX;
965 int mLineY;
966 int mLineH;
967 int mLinePadding;
968 int mPadding;
969 int mSliderY;
970 int mSliderW;
971 int mSliderH;
972 bool mRendered;
973 int mFontHeight;
974 GUIAction *mAction;
975 bool mChangeOnDrag;
976 int lineW;
977};
978
Dees_Troy51a0e822012-09-05 15:24:24 -0400979// Helper APIs
980bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
981
982#endif // _OBJECTS_HEADER
983