blob: 8f6f9bbf6295cb2e7e5b109e9f60ebcedeff728e [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" {
29#include "../minzip/Zip.h"
30}
31
32using namespace rapidxml;
33
34#include "../data.hpp"
35#include "resources.hpp"
36#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050037#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040038
39class RenderObject
40{
41public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020042 enum Placement {
43 TOP_LEFT = 0,
44 TOP_RIGHT = 1,
45 BOTTOM_LEFT = 2,
46 BOTTOM_RIGHT = 3,
47 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040048 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 };
Dees_Troy51a0e822012-09-05 15:24:24 -040050
51public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020052 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
53 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040054
55public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056 // Render - Render the full object to the GL surface
57 // Return 0 on success, <0 on error
58 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040059
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020060 // Update - Update any UI component animations (called <= 30 FPS)
61 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
62 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040063
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020064 // GetRenderPos - Returns the current position of the object
65 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 -040066
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067 // SetRenderPos - Update the position of the object
68 // Return 0 on success, <0 on error
69 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 -040070
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020071 // GetPlacement - Returns the current placement
72 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040073
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 // SetPlacement - Update the current placement
75 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040076
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 // SetPageFocus - Notify when a page gains or loses focus
78 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040079
80protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 int mRenderX, mRenderY, mRenderW, mRenderH;
82 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040083};
84
85class ActionObject
86{
87public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020088 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
89 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040090
91public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 // NotifyTouch - Notify of a touch event
93 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
94 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040095
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096 // NotifyKey - Notify of a key press
97 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
98 virtual int NotifyKey(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -040099
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 // GetRenderPos - Returns the current position of the object
101 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 -0400102
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200103 // SetRenderPos - Update the position of the object
104 // Return 0 on success, <0 on error
105 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400106
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200107 // IsInRegion - Checks if the request is handled by this object
108 // Return 0 if this object handles the request, 1 if not
109 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 -0400110
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200111 // NotifyVarChange - Notify of a variable change
112 // Returns 0 on success, <0 on error
113 virtual int NotifyVarChange(std::string varName, std::string value) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400114
115protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200116 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400117};
118
119class Conditional
120{
121public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200122 Conditional(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400123
124public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200125 bool IsConditionVariable(std::string var);
126 bool isConditionTrue();
127 bool isConditionValid();
128 void NotifyPageSet();
Dees_Troy51a0e822012-09-05 15:24:24 -0400129
130protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200131 class Condition
132 {
133 public:
134 std::string mVar1;
135 std::string mVar2;
136 std::string mCompareOp;
137 std::string mLastVal;
138 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400139
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200140 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400141
142protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200143 bool isMounted(std::string vol);
144 bool isConditionTrue(Condition* condition);
Dees_Troy51a0e822012-09-05 15:24:24 -0400145};
146
147class InputObject
148{
149public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200150 InputObject() { HasInputFocus = 0; }
151 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400152
153public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200154 // NotifyKeyboard - Notify of keyboard input
155 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
156 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400157
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200158 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400159
160protected:
161 int HasInputFocus;
162};
163
164// Derived Objects
165// GUIText - Used for static text
166class GUIText : public RenderObject, public ActionObject, public Conditional
Dees_Troy51a0e822012-09-05 15:24:24 -0400167{
168public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200169 // w and h may be ignored, in which case, no bounding box is applied
170 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400171
172public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200173 // Render - Render the full object to the GL surface
174 // Return 0 on success, <0 on error
175 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400176
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200177 // Update - Update any UI component animations (called <= 30 FPS)
178 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
179 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400180
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200181 // Retrieve the size of the current string (dynamic strings may change per call)
182 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400183
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200184 // Notify of a variable change
185 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400186
187 // Set maximum width in pixels
188 virtual int SetMaxWidth(unsigned width);
189
190 // Set number of characters to skip (for scrolling)
191 virtual int SkipCharCount(unsigned skip);
192
Dees_Troy4d12f962012-10-19 13:13:15 -0400193public:
194 bool isHighlighted;
195
Dees_Troy51a0e822012-09-05 15:24:24 -0400196protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200197 std::string mText;
198 std::string mLastValue;
199 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400200 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200201 Resource* mFont;
202 int mIsStatic;
203 int mVarChanged;
204 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400205 unsigned maxWidth;
206 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400207 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400208
209protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200210 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400211};
212
213// GUIImage - Used for static image
214class GUIImage : public RenderObject
215{
216public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200217 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400218
219public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200220 // Render - Render the full object to the GL surface
221 // Return 0 on success, <0 on error
222 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400223
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200224 // SetRenderPos - Update the position of the object
225 // Return 0 on success, <0 on error
226 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400227
Dees_Troy4d12f962012-10-19 13:13:15 -0400228public:
229 bool isHighlighted;
230
Dees_Troy51a0e822012-09-05 15:24:24 -0400231protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200232 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400233 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400234};
235
236// GUIFill - Used for fill colors
237class GUIFill : public RenderObject
238{
239public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200240 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400241
242public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200243 // Render - Render the full object to the GL surface
244 // Return 0 on success, <0 on error
245 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400246
247protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200248 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400249};
250
251// GUIAction - Used for standard actions
252class GUIAction : public ActionObject, public Conditional
253{
254public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200255 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400256
257public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200258 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
259 virtual int NotifyKey(int key);
260 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400261 virtual int doActions();
262
263protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200264 class Action
265 {
266 public:
267 std::string mFunction;
268 std::string mArg;
269 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400270
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200271 std::vector<Action> mActions;
272 int mKey;
Dees_Troy51a0e822012-09-05 15:24:24 -0400273
274protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200275 int getKeyByName(std::string key);
276 virtual int doAction(Action action, int isThreaded = 0);
277 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400278 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200279 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400280 void operation_start(const string operation_name);
281 void operation_end(const int operation_status, const int simulate);
282 static void* command_thread(void *cookie);
283};
284
285class GUIConsole : public RenderObject, public ActionObject
286{
287public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200288 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400289
290public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200291 // Render - Render the full object to the GL surface
292 // Return 0 on success, <0 on error
293 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400294
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200295 // Update - Update any UI component animations (called <= 30 FPS)
296 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
297 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400298
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200299 // SetRenderPos - Update the position of the object
300 // Return 0 on success, <0 on error
301 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400302
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200303 // IsInRegion - Checks if the request is handled by this object
304 // Return 0 if this object handles the request, 1 if not
305 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400306
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200307 // NotifyTouch - Notify of a touch event
308 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
309 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400310
311protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200312 enum SlideoutState
313 {
314 hidden = 0,
315 visible,
316 request_hide,
317 request_show
318 };
319
320 Resource* mFont;
321 Resource* mSlideoutImage;
322 COLOR mForegroundColor;
323 COLOR mBackgroundColor;
324 COLOR mScrollColor;
325 unsigned int mFontHeight;
326 int mCurrentLine;
327 unsigned int mLastCount;
328 unsigned int mMaxRows;
329 int mStartY;
330 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
331 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
332 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
333 int mLastTouchX, mLastTouchY;
334 int mSlideMultiplier;
335 int mSlideout;
336 SlideoutState mSlideoutState;
Dees_Troy51a0e822012-09-05 15:24:24 -0400337
338protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200339 virtual int RenderSlideout(void);
340 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400341};
342
343class GUIButton : public RenderObject, public ActionObject, public Conditional
344{
345public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200346 GUIButton(xml_node<>* node);
347 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400348
349public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200350 // Render - Render the full object to the GL surface
351 // Return 0 on success, <0 on error
352 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400353
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200354 // Update - Update any UI component animations (called <= 30 FPS)
355 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
356 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400357
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200358 // SetPos - Update the position of the render object
359 // Return 0 on success, <0 on error
360 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400361
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200362 // NotifyTouch - Notify of a touch event
363 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
364 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400365
366protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200367 GUIImage* mButtonImg;
368 Resource* mButtonIcon;
369 GUIText* mButtonLabel;
370 GUIAction* mAction;
371 int mTextX, mTextY, mTextW, mTextH;
372 int mIconX, mIconY, mIconW, mIconH;
373 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600374 bool hasHighlightColor;
375 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500376 bool hasFill;
377 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600378 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400379};
380
381class GUICheckbox: public RenderObject, public ActionObject, public Conditional
382{
383public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200384 GUICheckbox(xml_node<>* node);
385 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400386
387public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200388 // Render - Render the full object to the GL surface
389 // Return 0 on success, <0 on error
390 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400391
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200392 // Update - Update any UI component animations (called <= 30 FPS)
393 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
394 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400395
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200396 // SetPos - Update the position of the render object
397 // Return 0 on success, <0 on error
398 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400399
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200400 // NotifyTouch - Notify of a touch event
401 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
402 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400403
404protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200405 Resource* mChecked;
406 Resource* mUnchecked;
407 GUIText* mLabel;
408 int mTextX, mTextY;
409 int mCheckX, mCheckY, mCheckW, mCheckH;
410 int mLastState;
411 bool mRendered;
412 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400413};
414
415class GUIFileSelector : public RenderObject, public ActionObject
416{
417public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200418 GUIFileSelector(xml_node<>* node);
419 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400420
421public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200422 // Render - Render the full object to the GL surface
423 // Return 0 on success, <0 on error
424 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400425
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200426 // Update - Update any UI component animations (called <= 30 FPS)
427 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
428 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400429
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200430 // NotifyTouch - Notify of a touch event
431 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
432 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400433
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200434 // NotifyVarChange - Notify of a variable change
435 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400436
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200437 // SetPos - Update the position of the render object
438 // Return 0 on success, <0 on error
439 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400440
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200441 // SetPageFocus - Notify when a page gains or loses focus
442 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400443
444protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200445 struct FileData {
446 std::string fileName;
447 unsigned char fileType; // Uses d_type format from struct dirent
448 mode_t protection; // Uses mode_t format from stat
449 uid_t userId;
450 gid_t groupId;
451 off_t fileSize;
452 time_t lastAccess; // Uses time_t format from stat
453 time_t lastModified; // Uses time_t format from stat
454 time_t lastStatChange; // Uses time_t format from stat
455 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400456
457protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200458 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400459
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200460 virtual int GetFileList(const std::string folder);
461 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400462
463protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200464 std::vector<FileData> mFolderList;
465 std::vector<FileData> mFileList;
466 std::string mPathVar;
467 std::string mExtn;
468 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400469 std::string mSortVariable;
470 std::string mSelection;
471 std::string mHeaderText;
472 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200473 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400474 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200475 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400476 int mSeparatorH;
477 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200478 int mShowFolders, mShowFiles, mShowNavFolders;
479 int mUpdate;
480 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400481 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100482 int mFastScrollW;
483 int mFastScrollLineW;
484 int mFastScrollRectW;
485 int mFastScrollRectH;
486 int mFastScrollRectX;
487 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400488 static int mSortOrder;
489 int startY;
490 int scrollingSpeed;
491 int scrollingY;
492 int mHeaderIsStatic;
493 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200494 unsigned mFontHeight;
495 unsigned mLineHeight;
496 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
497 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400498 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200499 Resource* mFileIcon;
500 Resource* mBackground;
501 Resource* mFont;
502 COLOR mBackgroundColor;
503 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400504 COLOR mHeaderBackgroundColor;
505 COLOR mHeaderFontColor;
506 COLOR mSeparatorColor;
507 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100508 COLOR mFastScrollLineColor;
509 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600510 bool hasHighlightColor;
511 bool hasFontHighlightColor;
512 bool isHighlighted;
513 COLOR mHighlightColor;
514 COLOR mFontHighlightColor;
515 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600516 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400517};
518
519class GUIListBox : public RenderObject, public ActionObject
520{
521public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200522 GUIListBox(xml_node<>* node);
523 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400524
525public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200526 // Render - Render the full object to the GL surface
527 // Return 0 on success, <0 on error
528 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400529
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200530 // Update - Update any UI component animations (called <= 30 FPS)
531 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
532 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400533
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200534 // NotifyTouch - Notify of a touch event
535 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
536 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400537
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200538 // NotifyVarChange - Notify of a variable change
539 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400540
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200541 // SetPos - Update the position of the render object
542 // Return 0 on success, <0 on error
543 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400544
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200545 // SetPageFocus - Notify when a page gains or loses focus
546 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400547
548protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 struct ListData {
550 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400551 std::string variableValue;
552 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200553 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400554
555protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200556 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400557
558protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200559 std::vector<ListData> mList;
560 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400561 std::string mSelection;
562 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600563 std::string mHeaderText;
564 std::string mLastValue;
565 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200566 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600567 int startY;
568 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200569 int mLineSpacing;
570 int mUpdate;
571 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000572 int mFastScrollW;
573 int mFastScrollLineW;
574 int mFastScrollRectW;
575 int mFastScrollRectH;
576 int mFastScrollRectX;
577 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600578 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
579 int scrollingSpeed;
580 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400581 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200582 unsigned mFontHeight;
583 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600584 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200585 Resource* mIconSelected;
586 Resource* mIconUnselected;
587 Resource* mBackground;
588 Resource* mFont;
589 COLOR mBackgroundColor;
590 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600591 COLOR mHeaderBackgroundColor;
592 COLOR mHeaderFontColor;
593 COLOR mSeparatorColor;
594 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000595 COLOR mFastScrollLineColor;
596 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600597 bool hasHighlightColor;
598 bool hasFontHighlightColor;
599 bool isHighlighted;
600 COLOR mHighlightColor;
601 COLOR mFontHighlightColor;
602 int mHeaderIsStatic;
603 int startSelection;
604 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400605};
606
Dees_Troya13d74f2013-03-24 08:54:55 -0500607class GUIPartitionList : public RenderObject, public ActionObject
608{
609public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200610 GUIPartitionList(xml_node<>* node);
611 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500612
613public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200614 // Render - Render the full object to the GL surface
615 // Return 0 on success, <0 on error
616 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500617
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200618 // Update - Update any UI component animations (called <= 30 FPS)
619 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
620 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500621
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200622 // NotifyTouch - Notify of a touch event
623 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
624 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500625
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200626 // NotifyVarChange - Notify of a variable change
627 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500628
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200629 // SetPos - Update the position of the render object
630 // Return 0 on success, <0 on error
631 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500632
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200633 // SetPageFocus - Notify when a page gains or loses focus
634 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500635
636protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200637 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500638 virtual void MatchList(void);
639
640protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200641 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500642 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200643 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500644 std::string selectedList;
645 std::string currentValue;
646 std::string mHeaderText;
647 std::string mLastValue;
648 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200649 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500650 int startY;
651 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200652 int mLineSpacing;
653 int mUpdate;
654 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500655 int mFastScrollW;
656 int mFastScrollLineW;
657 int mFastScrollRectW;
658 int mFastScrollRectH;
659 int mFastScrollRectX;
660 int mFastScrollRectY;
661 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
662 int scrollingSpeed;
663 int scrollingY;
664 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200665 unsigned mFontHeight;
666 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500667 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200668 Resource* mIconSelected;
669 Resource* mIconUnselected;
670 Resource* mBackground;
671 Resource* mFont;
672 COLOR mBackgroundColor;
673 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500674 COLOR mHeaderBackgroundColor;
675 COLOR mHeaderFontColor;
676 COLOR mSeparatorColor;
677 COLOR mHeaderSeparatorColor;
678 COLOR mFastScrollLineColor;
679 COLOR mFastScrollRectColor;
680 bool hasHighlightColor;
681 bool hasFontHighlightColor;
682 bool isHighlighted;
683 COLOR mHighlightColor;
684 COLOR mFontHighlightColor;
685 int mHeaderIsStatic;
686 int startSelection;
687 int touchDebounce;
688 bool updateList;
689};
690
Dees_Troy51a0e822012-09-05 15:24:24 -0400691// GUIAnimation - Used for animations
692class GUIAnimation : public RenderObject
693{
694public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200695 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400696
697public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200698 // Render - Render the full object to the GL surface
699 // Return 0 on success, <0 on error
700 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400701
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200702 // Update - Update any UI component animations (called <= 30 FPS)
703 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
704 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400705
706protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200707 AnimationResource* mAnimation;
708 int mFrame;
709 int mFPS;
710 int mLoop;
711 int mRender;
712 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400713};
714
715class GUIProgressBar : public RenderObject, public ActionObject
716{
717public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200718 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400719
720public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200721 // Render - Render the full object to the GL surface
722 // Return 0 on success, <0 on error
723 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400724
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200725 // Update - Update any UI component animations (called <= 30 FPS)
726 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
727 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400728
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200729 // NotifyVarChange - Notify of a variable change
730 // Returns 0 on success, <0 on error
731 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400732
733protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200734 Resource* mEmptyBar;
735 Resource* mFullBar;
736 std::string mMinValVar;
737 std::string mMaxValVar;
738 std::string mCurValVar;
739 float mSlide;
740 float mSlideInc;
741 int mSlideFrames;
742 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400743
744protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200745 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400746};
747
748class GUISlider : public RenderObject, public ActionObject
749{
750public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200751 GUISlider(xml_node<>* node);
752 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400753
754public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200755 // Render - Render the full object to the GL surface
756 // Return 0 on success, <0 on error
757 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400758
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200759 // Update - Update any UI component animations (called <= 30 FPS)
760 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
761 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400762
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200763 // NotifyTouch - Notify of a touch event
764 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
765 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400766
767protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200768 GUIAction* sAction;
769 Resource* sSlider;
770 Resource* sSliderUsed;
771 Resource* sTouch;
772 int sTouchW, sTouchH;
773 int sCurTouchX;
774 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400775};
776
777#define MAX_KEYBOARD_LAYOUTS 5
778#define MAX_KEYBOARD_ROWS 9
779#define MAX_KEYBOARD_KEYS 20
780#define KEYBOARD_ACTION 253
781#define KEYBOARD_LAYOUT 254
782#define KEYBOARD_SWIPE_LEFT 252
783#define KEYBOARD_SWIPE_RIGHT 251
784#define KEYBOARD_ARROW_LEFT 250
785#define KEYBOARD_ARROW_RIGHT 249
786#define KEYBOARD_HOME 248
787#define KEYBOARD_END 247
788#define KEYBOARD_ARROW_UP 246
789#define KEYBOARD_ARROW_DOWN 245
790#define KEYBOARD_SPECIAL_KEYS 245
791#define KEYBOARD_BACKSPACE 8
792
793class GUIKeyboard : public RenderObject, public ActionObject, public Conditional
794{
795public:
796 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200797 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400798
799public:
800 virtual int Render(void);
801 virtual int Update(void);
802 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
803 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
804
805protected:
806 virtual int GetSelection(int x, int y);
807
808protected:
809 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200810 {
811 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400812 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200813 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400814 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200815 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400816
817 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
818 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
819 bool mRendered;
820 std::string mVariable;
821 unsigned int cursorLocation;
822 unsigned int currentLayout;
823 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
824 unsigned int KeyboardWidth, KeyboardHeight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400825 int rowY, colX, highlightRenderCount, hasHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400826 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400827 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400828};
829
830// GUIInput - Used for keyboard input
831class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject
832{
833public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200834 // w and h may be ignored, in which case, no bounding box is applied
835 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400836 virtual ~GUIInput();
837
838public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200839 // Render - Render the full object to the GL surface
840 // Return 0 on success, <0 on error
841 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400842
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200843 // Update - Update any UI component animations (called <= 30 FPS)
844 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
845 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400846
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200847 // Notify of a variable change
848 virtual int NotifyVarChange(std::string varName, std::string value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400849
850 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200851 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
852 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400853
854 virtual int NotifyKeyboard(int key);
855
856protected:
857 virtual int GetSelection(int x, int y);
858
859 // Handles displaying the text properly when chars are added, deleted, or for scrolling
860 virtual int HandleTextLocation(int x);
861
862protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200863 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400864 GUIAction* mAction;
865 Resource* mBackground;
866 Resource* mCursor;
867 Resource* mFont;
868 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200869 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400870 std::string mVariable;
871 std::string mMask;
872 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200873 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400874 COLOR mCursorColor;
875 int scrollingX;
876 int lastX;
877 int mCursorLocation;
878 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
879 int mFontY;
880 unsigned skipChars;
881 unsigned mFontHeight;
882 unsigned CursorWidth;
883 bool mRendered;
884 bool HasMask;
885 bool DrawCursor;
886 bool isLocalChange;
887 bool HasAllowed;
888 bool HasDisabled;
889 std::string AllowedList;
890 std::string DisabledList;
891 unsigned MinLen;
892 unsigned MaxLen;
893};
894
895class HardwareKeyboard
896{
897public:
898 HardwareKeyboard(void);
899 virtual ~HardwareKeyboard();
900
901public:
902 virtual int KeyDown(int key_code);
903 virtual int KeyUp(int key_code);
904 virtual int KeyRepeat(void);
905};
906
Vojtech Bocek85932342013-04-01 22:11:33 +0200907class GUISliderValue: public RenderObject, public ActionObject, public Conditional
908{
909public:
910 GUISliderValue(xml_node<>* node);
911 virtual ~GUISliderValue();
912
913public:
914 // Render - Render the full object to the GL surface
915 // Return 0 on success, <0 on error
916 virtual int Render(void);
917
918 // Update - Update any UI component animations (called <= 30 FPS)
919 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
920 virtual int Update(void);
921
922 // SetPos - Update the position of the render object
923 // Return 0 on success, <0 on error
924 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
925
926 // NotifyTouch - Notify of a touch event
927 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
928 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
929
930 // Notify of a variable change
931 virtual int NotifyVarChange(std::string varName, std::string value);
932
933 // SetPageFocus - Notify when a page gains or loses focus
934 virtual void SetPageFocus(int inFocus);
935
936protected:
937 int measureText(const std::string& str);
938 int valueFromPct(float pct);
939 float pctFromValue(int value);
940 void loadValue(bool force = false);
941
942 std::string mVariable;
943 int mMax;
944 int mMin;
945 int mValue;
946 char *mValueStr;
947 float mValuePct;
948 std::string mMaxStr;
949 std::string mMinStr;
950 Resource *mFont;
951 GUIText* mLabel;
952 int mLabelW;
953 COLOR mTextColor;
954 COLOR mLineColor;
955 COLOR mSliderColor;
956 bool mShowRange;
957 bool mShowCurr;
958 int mLineX;
959 int mLineY;
960 int mLineH;
961 int mLinePadding;
962 int mPadding;
963 int mSliderY;
964 int mSliderW;
965 int mSliderH;
966 bool mRendered;
967 int mFontHeight;
968 GUIAction *mAction;
969 bool mChangeOnDrag;
970 int lineW;
971};
972
Dees_Troy51a0e822012-09-05 15:24:24 -0400973// Helper APIs
974bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
975
976#endif // _OBJECTS_HEADER
977