blob: 1e272b2768e0bac2a60fb35c7bdc11f8790c7c9c [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_Troy51a0e822012-09-05 15:24:24 -040018// objects.h - Base classes for object manager of GUI
19
20#ifndef _OBJECTS_HEADER
21#define _OBJECTS_HEADER
22
23#include "rapidxml.hpp"
24#include <vector>
25#include <string>
26#include <map>
27
28extern "C" {
Dees Troyb7ae0982013-09-10 20:47:35 +000029#ifdef HAVE_SELINUX
Dees_Troy51a0e822012-09-05 15:24:24 -040030#include "../minzip/Zip.h"
Dees Troyb7ae0982013-09-10 20:47:35 +000031#else
32#include "../minzipold/Zip.h"
33#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040034}
35
36using namespace rapidxml;
37
38#include "../data.hpp"
39#include "resources.hpp"
40#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050041#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040042
43class RenderObject
44{
45public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020046 enum Placement {
47 TOP_LEFT = 0,
48 TOP_RIGHT = 1,
49 BOTTOM_LEFT = 2,
50 BOTTOM_RIGHT = 3,
51 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040052 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020053 };
Dees_Troy51a0e822012-09-05 15:24:24 -040054
55public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
57 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040058
59public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020060 // Render - Render the full object to the GL surface
61 // Return 0 on success, <0 on error
62 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040063
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020064 // Update - Update any UI component animations (called <= 30 FPS)
65 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
66 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040067
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020068 // GetRenderPos - Returns the current position of the object
69 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 -040070
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020071 // SetRenderPos - Update the position of the object
72 // Return 0 on success, <0 on error
73 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 -040074
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020075 // GetPlacement - Returns the current placement
76 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040077
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 // SetPlacement - Update the current placement
79 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040080
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 // SetPageFocus - Notify when a page gains or loses focus
82 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040083
84protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 int mRenderX, mRenderY, mRenderW, mRenderH;
86 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040087};
88
89class ActionObject
90{
91public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
93 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040094
95public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096 // NotifyTouch - Notify of a touch event
97 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
98 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040099
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 // NotifyKey - Notify of a key press
101 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
102 virtual int NotifyKey(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400103
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200104 // GetRenderPos - Returns the current position of the object
105 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 -0400106
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200107 // SetRenderPos - Update the position of the object
108 // Return 0 on success, <0 on error
109 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400110
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200111 // IsInRegion - Checks if the request is handled by this object
112 // Return 0 if this object handles the request, 1 if not
113 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 -0400114
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200115 // NotifyVarChange - Notify of a variable change
116 // Returns 0 on success, <0 on error
117 virtual int NotifyVarChange(std::string varName, std::string value) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400118
119protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200120 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400121};
122
123class Conditional
124{
125public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200126 Conditional(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400127
128public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200129 bool IsConditionVariable(std::string var);
130 bool isConditionTrue();
131 bool isConditionValid();
132 void NotifyPageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -0400133
134protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200135 class Condition
136 {
137 public:
138 std::string mVar1;
139 std::string mVar2;
140 std::string mCompareOp;
141 std::string mLastVal;
142 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400145
146protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200147 bool isMounted(std::string vol);
148 bool isConditionTrue(Condition* condition);
Dees_Troy51a0e822012-09-05 15:24:24 -0400149};
150
151class InputObject
152{
153public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200154 InputObject() { HasInputFocus = 0; }
155 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400156
157public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200158 // NotifyKeyboard - Notify of keyboard input
159 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
160 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400161
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200162 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400163
164protected:
165 int HasInputFocus;
166};
167
168// Derived Objects
169// GUIText - Used for static text
170class GUIText : public RenderObject, public ActionObject, public Conditional
Dees_Troy51a0e822012-09-05 15:24:24 -0400171{
172public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200173 // w and h may be ignored, in which case, no bounding box is applied
174 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400175
176public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200177 // Render - Render the full object to the GL surface
178 // Return 0 on success, <0 on error
179 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400180
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200181 // Update - Update any UI component animations (called <= 30 FPS)
182 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
183 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400184
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200185 // Retrieve the size of the current string (dynamic strings may change per call)
186 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400187
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200188 // Notify of a variable change
189 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400190
191 // Set maximum width in pixels
192 virtual int SetMaxWidth(unsigned width);
193
194 // Set number of characters to skip (for scrolling)
195 virtual int SkipCharCount(unsigned skip);
196
Dees_Troy4d12f962012-10-19 13:13:15 -0400197public:
198 bool isHighlighted;
199
Dees_Troy51a0e822012-09-05 15:24:24 -0400200protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200201 std::string mText;
202 std::string mLastValue;
203 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400204 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200205 Resource* mFont;
206 int mIsStatic;
207 int mVarChanged;
208 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400209 unsigned maxWidth;
210 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400211 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400212
213protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200214 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400215};
216
217// GUIImage - Used for static image
218class GUIImage : public RenderObject
219{
220public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200221 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400222
223public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200224 // Render - Render the full object to the GL surface
225 // Return 0 on success, <0 on error
226 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400227
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200228 // SetRenderPos - Update the position of the object
229 // Return 0 on success, <0 on error
230 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400231
Dees_Troy4d12f962012-10-19 13:13:15 -0400232public:
233 bool isHighlighted;
234
Dees_Troy51a0e822012-09-05 15:24:24 -0400235protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200236 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400237 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400238};
239
240// GUIFill - Used for fill colors
241class GUIFill : public RenderObject
242{
243public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200244 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400245
246public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200247 // Render - Render the full object to the GL surface
248 // Return 0 on success, <0 on error
249 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400250
251protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200252 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400253};
254
255// GUIAction - Used for standard actions
256class GUIAction : public ActionObject, public Conditional
257{
258public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200259 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400260
261public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200262 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
263 virtual int NotifyKey(int key);
264 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400265 virtual int doActions();
266
267protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200268 class Action
269 {
270 public:
271 std::string mFunction;
272 std::string mArg;
273 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400274
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200275 std::vector<Action> mActions;
276 int mKey;
Dees_Troy51a0e822012-09-05 15:24:24 -0400277
278protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200279 int getKeyByName(std::string key);
280 virtual int doAction(Action action, int isThreaded = 0);
281 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400282 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200283 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400284 void operation_start(const string operation_name);
285 void operation_end(const int operation_status, const int simulate);
286 static void* command_thread(void *cookie);
287};
288
289class GUIConsole : public RenderObject, public ActionObject
290{
291public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200292 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400293
294public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200295 // Render - Render the full object to the GL surface
296 // Return 0 on success, <0 on error
297 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400298
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200299 // Update - Update any UI component animations (called <= 30 FPS)
300 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
301 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400302
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200303 // SetRenderPos - Update the position of the object
304 // Return 0 on success, <0 on error
305 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400306
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200307 // IsInRegion - Checks if the request is handled by this object
308 // Return 0 if this object handles the request, 1 if not
309 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400310
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200311 // NotifyTouch - Notify of a touch event
312 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
313 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400314
315protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200316 enum SlideoutState
317 {
318 hidden = 0,
319 visible,
320 request_hide,
321 request_show
322 };
323
324 Resource* mFont;
325 Resource* mSlideoutImage;
326 COLOR mForegroundColor;
327 COLOR mBackgroundColor;
328 COLOR mScrollColor;
329 unsigned int mFontHeight;
330 int mCurrentLine;
331 unsigned int mLastCount;
332 unsigned int mMaxRows;
333 int mStartY;
334 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
335 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
336 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
337 int mLastTouchX, mLastTouchY;
338 int mSlideMultiplier;
339 int mSlideout;
340 SlideoutState mSlideoutState;
Dees_Troy51a0e822012-09-05 15:24:24 -0400341
342protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200343 virtual int RenderSlideout(void);
344 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400345};
346
347class GUIButton : public RenderObject, public ActionObject, public Conditional
348{
349public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200350 GUIButton(xml_node<>* node);
351 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400352
353public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200354 // Render - Render the full object to the GL surface
355 // Return 0 on success, <0 on error
356 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400357
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200358 // Update - Update any UI component animations (called <= 30 FPS)
359 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
360 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400361
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200362 // SetPos - Update the position of the render object
363 // Return 0 on success, <0 on error
364 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400365
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200366 // NotifyTouch - Notify of a touch event
367 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
368 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400369
370protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200371 GUIImage* mButtonImg;
372 Resource* mButtonIcon;
373 GUIText* mButtonLabel;
374 GUIAction* mAction;
375 int mTextX, mTextY, mTextW, mTextH;
376 int mIconX, mIconY, mIconW, mIconH;
377 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600378 bool hasHighlightColor;
379 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500380 bool hasFill;
381 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600382 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000383 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400384};
385
386class GUICheckbox: public RenderObject, public ActionObject, public Conditional
387{
388public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200389 GUICheckbox(xml_node<>* node);
390 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400391
392public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200393 // Render - Render the full object to the GL surface
394 // Return 0 on success, <0 on error
395 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400396
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200397 // Update - Update any UI component animations (called <= 30 FPS)
398 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
399 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400400
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200401 // SetPos - Update the position of the render object
402 // Return 0 on success, <0 on error
403 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400404
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200405 // NotifyTouch - Notify of a touch event
406 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
407 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400408
409protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200410 Resource* mChecked;
411 Resource* mUnchecked;
412 GUIText* mLabel;
413 int mTextX, mTextY;
414 int mCheckX, mCheckY, mCheckW, mCheckH;
415 int mLastState;
416 bool mRendered;
417 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400418};
419
420class GUIFileSelector : public RenderObject, public ActionObject
421{
422public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200423 GUIFileSelector(xml_node<>* node);
424 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400425
426public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200427 // Render - Render the full object to the GL surface
428 // Return 0 on success, <0 on error
429 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400430
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200431 // Update - Update any UI component animations (called <= 30 FPS)
432 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
433 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400434
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200435 // NotifyTouch - Notify of a touch event
436 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
437 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400438
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200439 // NotifyVarChange - Notify of a variable change
440 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400441
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200442 // SetPos - Update the position of the render object
443 // Return 0 on success, <0 on error
444 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400445
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200446 // SetPageFocus - Notify when a page gains or loses focus
447 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400448
449protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200450 struct FileData {
451 std::string fileName;
452 unsigned char fileType; // Uses d_type format from struct dirent
453 mode_t protection; // Uses mode_t format from stat
454 uid_t userId;
455 gid_t groupId;
456 off_t fileSize;
457 time_t lastAccess; // Uses time_t format from stat
458 time_t lastModified; // Uses time_t format from stat
459 time_t lastStatChange; // Uses time_t format from stat
460 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400461
462protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200463 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400464
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200465 virtual int GetFileList(const std::string folder);
466 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400467
468protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200469 std::vector<FileData> mFolderList;
470 std::vector<FileData> mFileList;
471 std::string mPathVar;
472 std::string mExtn;
473 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400474 std::string mSortVariable;
475 std::string mSelection;
476 std::string mHeaderText;
477 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200478 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400479 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200480 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400481 int mSeparatorH;
482 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200483 int mShowFolders, mShowFiles, mShowNavFolders;
484 int mUpdate;
485 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400486 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100487 int mFastScrollW;
488 int mFastScrollLineW;
489 int mFastScrollRectW;
490 int mFastScrollRectH;
491 int mFastScrollRectX;
492 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400493 static int mSortOrder;
494 int startY;
495 int scrollingSpeed;
496 int scrollingY;
497 int mHeaderIsStatic;
498 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200499 unsigned mFontHeight;
500 unsigned mLineHeight;
501 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
502 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400503 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200504 Resource* mFileIcon;
505 Resource* mBackground;
506 Resource* mFont;
507 COLOR mBackgroundColor;
508 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400509 COLOR mHeaderBackgroundColor;
510 COLOR mHeaderFontColor;
511 COLOR mSeparatorColor;
512 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100513 COLOR mFastScrollLineColor;
514 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600515 bool hasHighlightColor;
516 bool hasFontHighlightColor;
517 bool isHighlighted;
518 COLOR mHighlightColor;
519 COLOR mFontHighlightColor;
520 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600521 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400522};
523
524class GUIListBox : public RenderObject, public ActionObject
525{
526public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200527 GUIListBox(xml_node<>* node);
528 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400529
530public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200531 // Render - Render the full object to the GL surface
532 // Return 0 on success, <0 on error
533 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400534
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200535 // Update - Update any UI component animations (called <= 30 FPS)
536 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
537 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400538
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200539 // NotifyTouch - Notify of a touch event
540 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
541 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400542
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200543 // NotifyVarChange - Notify of a variable change
544 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400545
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200546 // SetPos - Update the position of the render object
547 // Return 0 on success, <0 on error
548 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400549
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200550 // SetPageFocus - Notify when a page gains or loses focus
551 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400552
553protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200554 struct ListData {
555 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400556 std::string variableValue;
557 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200558 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400559
560protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200561 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400562
563protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200564 std::vector<ListData> mList;
565 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400566 std::string mSelection;
567 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600568 std::string mHeaderText;
569 std::string mLastValue;
570 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200571 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600572 int startY;
573 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200574 int mLineSpacing;
575 int mUpdate;
576 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000577 int mFastScrollW;
578 int mFastScrollLineW;
579 int mFastScrollRectW;
580 int mFastScrollRectH;
581 int mFastScrollRectX;
582 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600583 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
584 int scrollingSpeed;
585 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400586 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200587 unsigned mFontHeight;
588 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600589 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200590 Resource* mIconSelected;
591 Resource* mIconUnselected;
592 Resource* mBackground;
593 Resource* mFont;
594 COLOR mBackgroundColor;
595 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600596 COLOR mHeaderBackgroundColor;
597 COLOR mHeaderFontColor;
598 COLOR mSeparatorColor;
599 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000600 COLOR mFastScrollLineColor;
601 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600602 bool hasHighlightColor;
603 bool hasFontHighlightColor;
604 bool isHighlighted;
605 COLOR mHighlightColor;
606 COLOR mFontHighlightColor;
607 int mHeaderIsStatic;
608 int startSelection;
609 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400610};
611
Dees_Troya13d74f2013-03-24 08:54:55 -0500612class GUIPartitionList : public RenderObject, public ActionObject
613{
614public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200615 GUIPartitionList(xml_node<>* node);
616 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500617
618public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200619 // Render - Render the full object to the GL surface
620 // Return 0 on success, <0 on error
621 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500622
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200623 // Update - Update any UI component animations (called <= 30 FPS)
624 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
625 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500626
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 // NotifyTouch - Notify of a touch event
628 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
629 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500630
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200631 // NotifyVarChange - Notify of a variable change
632 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500633
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200634 // SetPos - Update the position of the render object
635 // Return 0 on success, <0 on error
636 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500637
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200638 // SetPageFocus - Notify when a page gains or loses focus
639 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500640
641protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200642 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500643 virtual void MatchList(void);
644
645protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200646 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500647 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200648 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500649 std::string selectedList;
650 std::string currentValue;
651 std::string mHeaderText;
652 std::string mLastValue;
653 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200654 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500655 int startY;
656 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200657 int mLineSpacing;
658 int mUpdate;
659 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500660 int mFastScrollW;
661 int mFastScrollLineW;
662 int mFastScrollRectW;
663 int mFastScrollRectH;
664 int mFastScrollRectX;
665 int mFastScrollRectY;
666 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
667 int scrollingSpeed;
668 int scrollingY;
669 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200670 unsigned mFontHeight;
671 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500672 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200673 Resource* mIconSelected;
674 Resource* mIconUnselected;
675 Resource* mBackground;
676 Resource* mFont;
677 COLOR mBackgroundColor;
678 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500679 COLOR mHeaderBackgroundColor;
680 COLOR mHeaderFontColor;
681 COLOR mSeparatorColor;
682 COLOR mHeaderSeparatorColor;
683 COLOR mFastScrollLineColor;
684 COLOR mFastScrollRectColor;
685 bool hasHighlightColor;
686 bool hasFontHighlightColor;
687 bool isHighlighted;
688 COLOR mHighlightColor;
689 COLOR mFontHighlightColor;
690 int mHeaderIsStatic;
691 int startSelection;
692 int touchDebounce;
693 bool updateList;
694};
695
Dees_Troy51a0e822012-09-05 15:24:24 -0400696// GUIAnimation - Used for animations
697class GUIAnimation : public RenderObject
698{
699public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200700 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400701
702public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200703 // Render - Render the full object to the GL surface
704 // Return 0 on success, <0 on error
705 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400706
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200707 // Update - Update any UI component animations (called <= 30 FPS)
708 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
709 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400710
711protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200712 AnimationResource* mAnimation;
713 int mFrame;
714 int mFPS;
715 int mLoop;
716 int mRender;
717 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400718};
719
720class GUIProgressBar : public RenderObject, public ActionObject
721{
722public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200723 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400724
725public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200726 // Render - Render the full object to the GL surface
727 // Return 0 on success, <0 on error
728 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400729
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200730 // Update - Update any UI component animations (called <= 30 FPS)
731 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
732 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400733
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200734 // NotifyVarChange - Notify of a variable change
735 // Returns 0 on success, <0 on error
736 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400737
738protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200739 Resource* mEmptyBar;
740 Resource* mFullBar;
741 std::string mMinValVar;
742 std::string mMaxValVar;
743 std::string mCurValVar;
744 float mSlide;
745 float mSlideInc;
746 int mSlideFrames;
747 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400748
749protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200750 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400751};
752
753class GUISlider : public RenderObject, public ActionObject
754{
755public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200756 GUISlider(xml_node<>* node);
757 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400758
759public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200760 // Render - Render the full object to the GL surface
761 // Return 0 on success, <0 on error
762 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400763
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200764 // Update - Update any UI component animations (called <= 30 FPS)
765 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
766 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400767
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200768 // NotifyTouch - Notify of a touch event
769 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
770 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400771
772protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200773 GUIAction* sAction;
774 Resource* sSlider;
775 Resource* sSliderUsed;
776 Resource* sTouch;
777 int sTouchW, sTouchH;
778 int sCurTouchX;
779 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400780};
781
782#define MAX_KEYBOARD_LAYOUTS 5
783#define MAX_KEYBOARD_ROWS 9
784#define MAX_KEYBOARD_KEYS 20
785#define KEYBOARD_ACTION 253
786#define KEYBOARD_LAYOUT 254
787#define KEYBOARD_SWIPE_LEFT 252
788#define KEYBOARD_SWIPE_RIGHT 251
789#define KEYBOARD_ARROW_LEFT 250
790#define KEYBOARD_ARROW_RIGHT 249
791#define KEYBOARD_HOME 248
792#define KEYBOARD_END 247
793#define KEYBOARD_ARROW_UP 246
794#define KEYBOARD_ARROW_DOWN 245
795#define KEYBOARD_SPECIAL_KEYS 245
796#define KEYBOARD_BACKSPACE 8
797
798class GUIKeyboard : public RenderObject, public ActionObject, public Conditional
799{
800public:
801 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200802 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400803
804public:
805 virtual int Render(void);
806 virtual int Update(void);
807 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
808 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
809
810protected:
811 virtual int GetSelection(int x, int y);
812
813protected:
814 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200815 {
816 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400817 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200818 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400819 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200820 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400821
822 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
823 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
824 bool mRendered;
825 std::string mVariable;
826 unsigned int cursorLocation;
827 unsigned int currentLayout;
828 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
829 unsigned int KeyboardWidth, KeyboardHeight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400830 int rowY, colX, highlightRenderCount, hasHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400831 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400832 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400833};
834
835// GUIInput - Used for keyboard input
836class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject
837{
838public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200839 // w and h may be ignored, in which case, no bounding box is applied
840 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400841 virtual ~GUIInput();
842
843public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200844 // Render - Render the full object to the GL surface
845 // Return 0 on success, <0 on error
846 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400847
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200848 // Update - Update any UI component animations (called <= 30 FPS)
849 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
850 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400851
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200852 // Notify of a variable change
853 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400854
855 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200856 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
857 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400858
859 virtual int NotifyKeyboard(int key);
860
861protected:
862 virtual int GetSelection(int x, int y);
863
864 // Handles displaying the text properly when chars are added, deleted, or for scrolling
865 virtual int HandleTextLocation(int x);
866
867protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200868 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400869 GUIAction* mAction;
870 Resource* mBackground;
871 Resource* mCursor;
872 Resource* mFont;
873 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200874 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400875 std::string mVariable;
876 std::string mMask;
877 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200878 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400879 COLOR mCursorColor;
880 int scrollingX;
881 int lastX;
882 int mCursorLocation;
883 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
884 int mFontY;
885 unsigned skipChars;
886 unsigned mFontHeight;
887 unsigned CursorWidth;
888 bool mRendered;
889 bool HasMask;
890 bool DrawCursor;
891 bool isLocalChange;
892 bool HasAllowed;
893 bool HasDisabled;
894 std::string AllowedList;
895 std::string DisabledList;
896 unsigned MinLen;
897 unsigned MaxLen;
898};
899
900class HardwareKeyboard
901{
902public:
903 HardwareKeyboard(void);
904 virtual ~HardwareKeyboard();
905
906public:
907 virtual int KeyDown(int key_code);
908 virtual int KeyUp(int key_code);
909 virtual int KeyRepeat(void);
910};
911
Vojtech Bocek85932342013-04-01 22:11:33 +0200912class GUISliderValue: public RenderObject, public ActionObject, public Conditional
913{
914public:
915 GUISliderValue(xml_node<>* node);
916 virtual ~GUISliderValue();
917
918public:
919 // Render - Render the full object to the GL surface
920 // Return 0 on success, <0 on error
921 virtual int Render(void);
922
923 // Update - Update any UI component animations (called <= 30 FPS)
924 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
925 virtual int Update(void);
926
927 // SetPos - Update the position of the render object
928 // Return 0 on success, <0 on error
929 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
930
931 // NotifyTouch - Notify of a touch event
932 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
933 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
934
935 // Notify of a variable change
936 virtual int NotifyVarChange(std::string varName, std::string value);
937
938 // SetPageFocus - Notify when a page gains or loses focus
939 virtual void SetPageFocus(int inFocus);
940
941protected:
942 int measureText(const std::string& str);
943 int valueFromPct(float pct);
944 float pctFromValue(int value);
945 void loadValue(bool force = false);
946
947 std::string mVariable;
948 int mMax;
949 int mMin;
950 int mValue;
951 char *mValueStr;
952 float mValuePct;
953 std::string mMaxStr;
954 std::string mMinStr;
955 Resource *mFont;
956 GUIText* mLabel;
957 int mLabelW;
958 COLOR mTextColor;
959 COLOR mLineColor;
960 COLOR mSliderColor;
961 bool mShowRange;
962 bool mShowCurr;
963 int mLineX;
964 int mLineY;
965 int mLineH;
966 int mLinePadding;
967 int mPadding;
968 int mSliderY;
969 int mSliderW;
970 int mSliderH;
971 bool mRendered;
972 int mFontHeight;
973 GUIAction *mAction;
974 bool mChangeOnDrag;
975 int lineW;
976};
977
Dees_Troy51a0e822012-09-05 15:24:24 -0400978// Helper APIs
979bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
980
981#endif // _OBJECTS_HEADER
982