blob: d37b43e3bdcc3cea18ab8b9702966b0a486401e0 [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_Troy51a0e822012-09-05 15:24:24 -0400383};
384
385class GUICheckbox: public RenderObject, public ActionObject, public Conditional
386{
387public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200388 GUICheckbox(xml_node<>* node);
389 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400390
391public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200392 // Render - Render the full object to the GL surface
393 // Return 0 on success, <0 on error
394 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400395
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200396 // Update - Update any UI component animations (called <= 30 FPS)
397 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
398 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400399
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200400 // SetPos - Update the position of the render object
401 // Return 0 on success, <0 on error
402 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400403
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200404 // NotifyTouch - Notify of a touch event
405 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
406 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400407
408protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200409 Resource* mChecked;
410 Resource* mUnchecked;
411 GUIText* mLabel;
412 int mTextX, mTextY;
413 int mCheckX, mCheckY, mCheckW, mCheckH;
414 int mLastState;
415 bool mRendered;
416 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400417};
418
419class GUIFileSelector : public RenderObject, public ActionObject
420{
421public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200422 GUIFileSelector(xml_node<>* node);
423 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400424
425public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200426 // Render - Render the full object to the GL surface
427 // Return 0 on success, <0 on error
428 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400429
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200430 // Update - Update any UI component animations (called <= 30 FPS)
431 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
432 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400433
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200434 // NotifyTouch - Notify of a touch event
435 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
436 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400437
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200438 // NotifyVarChange - Notify of a variable change
439 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400440
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200441 // SetPos - Update the position of the render object
442 // Return 0 on success, <0 on error
443 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400444
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200445 // SetPageFocus - Notify when a page gains or loses focus
446 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400447
448protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200449 struct FileData {
450 std::string fileName;
451 unsigned char fileType; // Uses d_type format from struct dirent
452 mode_t protection; // Uses mode_t format from stat
453 uid_t userId;
454 gid_t groupId;
455 off_t fileSize;
456 time_t lastAccess; // Uses time_t format from stat
457 time_t lastModified; // Uses time_t format from stat
458 time_t lastStatChange; // Uses time_t format from stat
459 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400460
461protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200462 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400463
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200464 virtual int GetFileList(const std::string folder);
465 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400466
467protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200468 std::vector<FileData> mFolderList;
469 std::vector<FileData> mFileList;
470 std::string mPathVar;
471 std::string mExtn;
472 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400473 std::string mSortVariable;
474 std::string mSelection;
475 std::string mHeaderText;
476 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200477 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400478 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200479 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400480 int mSeparatorH;
481 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200482 int mShowFolders, mShowFiles, mShowNavFolders;
483 int mUpdate;
484 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400485 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100486 int mFastScrollW;
487 int mFastScrollLineW;
488 int mFastScrollRectW;
489 int mFastScrollRectH;
490 int mFastScrollRectX;
491 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400492 static int mSortOrder;
493 int startY;
494 int scrollingSpeed;
495 int scrollingY;
496 int mHeaderIsStatic;
497 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200498 unsigned mFontHeight;
499 unsigned mLineHeight;
500 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
501 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400502 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200503 Resource* mFileIcon;
504 Resource* mBackground;
505 Resource* mFont;
506 COLOR mBackgroundColor;
507 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400508 COLOR mHeaderBackgroundColor;
509 COLOR mHeaderFontColor;
510 COLOR mSeparatorColor;
511 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100512 COLOR mFastScrollLineColor;
513 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600514 bool hasHighlightColor;
515 bool hasFontHighlightColor;
516 bool isHighlighted;
517 COLOR mHighlightColor;
518 COLOR mFontHighlightColor;
519 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600520 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400521};
522
523class GUIListBox : public RenderObject, public ActionObject
524{
525public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200526 GUIListBox(xml_node<>* node);
527 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400528
529public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200530 // Render - Render the full object to the GL surface
531 // Return 0 on success, <0 on error
532 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400533
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200534 // Update - Update any UI component animations (called <= 30 FPS)
535 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
536 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400537
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200538 // NotifyTouch - Notify of a touch event
539 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
540 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400541
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200542 // NotifyVarChange - Notify of a variable change
543 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400544
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200545 // SetPos - Update the position of the render object
546 // Return 0 on success, <0 on error
547 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400548
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 // SetPageFocus - Notify when a page gains or loses focus
550 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400551
552protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200553 struct ListData {
554 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400555 std::string variableValue;
556 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200557 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400558
559protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200560 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400561
562protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200563 std::vector<ListData> mList;
564 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400565 std::string mSelection;
566 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600567 std::string mHeaderText;
568 std::string mLastValue;
569 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200570 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600571 int startY;
572 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200573 int mLineSpacing;
574 int mUpdate;
575 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000576 int mFastScrollW;
577 int mFastScrollLineW;
578 int mFastScrollRectW;
579 int mFastScrollRectH;
580 int mFastScrollRectX;
581 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600582 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
583 int scrollingSpeed;
584 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400585 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200586 unsigned mFontHeight;
587 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600588 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200589 Resource* mIconSelected;
590 Resource* mIconUnselected;
591 Resource* mBackground;
592 Resource* mFont;
593 COLOR mBackgroundColor;
594 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600595 COLOR mHeaderBackgroundColor;
596 COLOR mHeaderFontColor;
597 COLOR mSeparatorColor;
598 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000599 COLOR mFastScrollLineColor;
600 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600601 bool hasHighlightColor;
602 bool hasFontHighlightColor;
603 bool isHighlighted;
604 COLOR mHighlightColor;
605 COLOR mFontHighlightColor;
606 int mHeaderIsStatic;
607 int startSelection;
608 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400609};
610
Dees_Troya13d74f2013-03-24 08:54:55 -0500611class GUIPartitionList : public RenderObject, public ActionObject
612{
613public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200614 GUIPartitionList(xml_node<>* node);
615 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500616
617public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200618 // Render - Render the full object to the GL surface
619 // Return 0 on success, <0 on error
620 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500621
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200622 // Update - Update any UI component animations (called <= 30 FPS)
623 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
624 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500625
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200626 // NotifyTouch - Notify of a touch event
627 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
628 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500629
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200630 // NotifyVarChange - Notify of a variable change
631 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500632
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200633 // SetPos - Update the position of the render object
634 // Return 0 on success, <0 on error
635 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500636
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200637 // SetPageFocus - Notify when a page gains or loses focus
638 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500639
640protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200641 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500642 virtual void MatchList(void);
643
644protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200645 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500646 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200647 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500648 std::string selectedList;
649 std::string currentValue;
650 std::string mHeaderText;
651 std::string mLastValue;
652 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200653 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500654 int startY;
655 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200656 int mLineSpacing;
657 int mUpdate;
658 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500659 int mFastScrollW;
660 int mFastScrollLineW;
661 int mFastScrollRectW;
662 int mFastScrollRectH;
663 int mFastScrollRectX;
664 int mFastScrollRectY;
665 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
666 int scrollingSpeed;
667 int scrollingY;
668 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200669 unsigned mFontHeight;
670 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500671 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200672 Resource* mIconSelected;
673 Resource* mIconUnselected;
674 Resource* mBackground;
675 Resource* mFont;
676 COLOR mBackgroundColor;
677 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500678 COLOR mHeaderBackgroundColor;
679 COLOR mHeaderFontColor;
680 COLOR mSeparatorColor;
681 COLOR mHeaderSeparatorColor;
682 COLOR mFastScrollLineColor;
683 COLOR mFastScrollRectColor;
684 bool hasHighlightColor;
685 bool hasFontHighlightColor;
686 bool isHighlighted;
687 COLOR mHighlightColor;
688 COLOR mFontHighlightColor;
689 int mHeaderIsStatic;
690 int startSelection;
691 int touchDebounce;
692 bool updateList;
693};
694
Dees_Troy51a0e822012-09-05 15:24:24 -0400695// GUIAnimation - Used for animations
696class GUIAnimation : public RenderObject
697{
698public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200699 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400700
701public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200702 // Render - Render the full object to the GL surface
703 // Return 0 on success, <0 on error
704 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400705
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200706 // Update - Update any UI component animations (called <= 30 FPS)
707 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
708 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400709
710protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200711 AnimationResource* mAnimation;
712 int mFrame;
713 int mFPS;
714 int mLoop;
715 int mRender;
716 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400717};
718
719class GUIProgressBar : public RenderObject, public ActionObject
720{
721public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200722 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400723
724public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200725 // Render - Render the full object to the GL surface
726 // Return 0 on success, <0 on error
727 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400728
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200729 // Update - Update any UI component animations (called <= 30 FPS)
730 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
731 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400732
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200733 // NotifyVarChange - Notify of a variable change
734 // Returns 0 on success, <0 on error
735 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400736
737protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200738 Resource* mEmptyBar;
739 Resource* mFullBar;
740 std::string mMinValVar;
741 std::string mMaxValVar;
742 std::string mCurValVar;
743 float mSlide;
744 float mSlideInc;
745 int mSlideFrames;
746 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400747
748protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200749 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400750};
751
752class GUISlider : public RenderObject, public ActionObject
753{
754public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200755 GUISlider(xml_node<>* node);
756 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400757
758public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200759 // Render - Render the full object to the GL surface
760 // Return 0 on success, <0 on error
761 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400762
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200763 // Update - Update any UI component animations (called <= 30 FPS)
764 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
765 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400766
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200767 // NotifyTouch - Notify of a touch event
768 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
769 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400770
771protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200772 GUIAction* sAction;
773 Resource* sSlider;
774 Resource* sSliderUsed;
775 Resource* sTouch;
776 int sTouchW, sTouchH;
777 int sCurTouchX;
778 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400779};
780
781#define MAX_KEYBOARD_LAYOUTS 5
782#define MAX_KEYBOARD_ROWS 9
783#define MAX_KEYBOARD_KEYS 20
784#define KEYBOARD_ACTION 253
785#define KEYBOARD_LAYOUT 254
786#define KEYBOARD_SWIPE_LEFT 252
787#define KEYBOARD_SWIPE_RIGHT 251
788#define KEYBOARD_ARROW_LEFT 250
789#define KEYBOARD_ARROW_RIGHT 249
790#define KEYBOARD_HOME 248
791#define KEYBOARD_END 247
792#define KEYBOARD_ARROW_UP 246
793#define KEYBOARD_ARROW_DOWN 245
794#define KEYBOARD_SPECIAL_KEYS 245
795#define KEYBOARD_BACKSPACE 8
796
797class GUIKeyboard : public RenderObject, public ActionObject, public Conditional
798{
799public:
800 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200801 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400802
803public:
804 virtual int Render(void);
805 virtual int Update(void);
806 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
807 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
808
809protected:
810 virtual int GetSelection(int x, int y);
811
812protected:
813 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200814 {
815 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400816 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200817 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400818 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200819 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400820
821 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
822 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
823 bool mRendered;
824 std::string mVariable;
825 unsigned int cursorLocation;
826 unsigned int currentLayout;
827 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
828 unsigned int KeyboardWidth, KeyboardHeight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400829 int rowY, colX, highlightRenderCount, hasHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400830 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400831 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400832};
833
834// GUIInput - Used for keyboard input
835class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject
836{
837public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200838 // w and h may be ignored, in which case, no bounding box is applied
839 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400840 virtual ~GUIInput();
841
842public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200843 // Render - Render the full object to the GL surface
844 // Return 0 on success, <0 on error
845 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400846
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200847 // Update - Update any UI component animations (called <= 30 FPS)
848 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
849 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400850
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200851 // Notify of a variable change
852 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400853
854 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200855 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
856 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400857
858 virtual int NotifyKeyboard(int key);
859
860protected:
861 virtual int GetSelection(int x, int y);
862
863 // Handles displaying the text properly when chars are added, deleted, or for scrolling
864 virtual int HandleTextLocation(int x);
865
866protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200867 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400868 GUIAction* mAction;
869 Resource* mBackground;
870 Resource* mCursor;
871 Resource* mFont;
872 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200873 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400874 std::string mVariable;
875 std::string mMask;
876 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200877 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400878 COLOR mCursorColor;
879 int scrollingX;
880 int lastX;
881 int mCursorLocation;
882 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
883 int mFontY;
884 unsigned skipChars;
885 unsigned mFontHeight;
886 unsigned CursorWidth;
887 bool mRendered;
888 bool HasMask;
889 bool DrawCursor;
890 bool isLocalChange;
891 bool HasAllowed;
892 bool HasDisabled;
893 std::string AllowedList;
894 std::string DisabledList;
895 unsigned MinLen;
896 unsigned MaxLen;
897};
898
899class HardwareKeyboard
900{
901public:
902 HardwareKeyboard(void);
903 virtual ~HardwareKeyboard();
904
905public:
906 virtual int KeyDown(int key_code);
907 virtual int KeyUp(int key_code);
908 virtual int KeyRepeat(void);
909};
910
Vojtech Bocek85932342013-04-01 22:11:33 +0200911class GUISliderValue: public RenderObject, public ActionObject, public Conditional
912{
913public:
914 GUISliderValue(xml_node<>* node);
915 virtual ~GUISliderValue();
916
917public:
918 // Render - Render the full object to the GL surface
919 // Return 0 on success, <0 on error
920 virtual int Render(void);
921
922 // Update - Update any UI component animations (called <= 30 FPS)
923 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
924 virtual int Update(void);
925
926 // SetPos - Update the position of the render object
927 // Return 0 on success, <0 on error
928 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
929
930 // NotifyTouch - Notify of a touch event
931 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
932 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
933
934 // Notify of a variable change
935 virtual int NotifyVarChange(std::string varName, std::string value);
936
937 // SetPageFocus - Notify when a page gains or loses focus
938 virtual void SetPageFocus(int inFocus);
939
940protected:
941 int measureText(const std::string& str);
942 int valueFromPct(float pct);
943 float pctFromValue(int value);
944 void loadValue(bool force = false);
945
946 std::string mVariable;
947 int mMax;
948 int mMin;
949 int mValue;
950 char *mValueStr;
951 float mValuePct;
952 std::string mMaxStr;
953 std::string mMinStr;
954 Resource *mFont;
955 GUIText* mLabel;
956 int mLabelW;
957 COLOR mTextColor;
958 COLOR mLineColor;
959 COLOR mSliderColor;
960 bool mShowRange;
961 bool mShowCurr;
962 int mLineX;
963 int mLineY;
964 int mLineH;
965 int mLinePadding;
966 int mPadding;
967 int mSliderY;
968 int mSliderW;
969 int mSliderH;
970 bool mRendered;
971 int mFontHeight;
972 GUIAction *mAction;
973 bool mChangeOnDrag;
974 int lineW;
975};
976
Dees_Troy51a0e822012-09-05 15:24:24 -0400977// Helper APIs
978bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
979
980#endif // _OBJECTS_HEADER
981