blob: f8a4e8ca8e96faf9cc7332600c9296af6936e090 [file] [log] [blame]
Dees_Troya13d74f2013-03-24 08:54:55 -05001/*
2 Copyright 2013 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
Dees Troy3be70a82013-10-22 14:25:12 +000018
19// objects.hpp - Base classes for object manager of GUI
Dees_Troy51a0e822012-09-05 15:24:24 -040020
21#ifndef _OBJECTS_HEADER
22#define _OBJECTS_HEADER
23
24#include "rapidxml.hpp"
25#include <vector>
26#include <string>
27#include <map>
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +000028#include <time.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040029
30extern "C" {
Dees Troyb7ae0982013-09-10 20:47:35 +000031#ifdef HAVE_SELINUX
Dees_Troy51a0e822012-09-05 15:24:24 -040032#include "../minzip/Zip.h"
Dees Troyb7ae0982013-09-10 20:47:35 +000033#else
34#include "../minzipold/Zip.h"
35#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040036}
37
38using namespace rapidxml;
39
40#include "../data.hpp"
41#include "resources.hpp"
42#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050043#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040044
45class RenderObject
46{
47public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 enum Placement {
49 TOP_LEFT = 0,
50 TOP_RIGHT = 1,
51 BOTTOM_LEFT = 2,
52 BOTTOM_RIGHT = 3,
53 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040054 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 };
Dees_Troy51a0e822012-09-05 15:24:24 -040056
57public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020058 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
59 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040060
61public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020062 // Render - Render the full object to the GL surface
63 // Return 0 on success, <0 on error
64 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040065
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020066 // Update - Update any UI component animations (called <= 30 FPS)
67 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
68 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040069
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 // GetRenderPos - Returns the current position of the object
71 virtual int GetRenderPos(int& x, int& y, int& w, int& h) { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040072
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 // SetRenderPos - Update the position of the object
74 // Return 0 on success, <0 on error
75 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0) { mRenderX = x; mRenderY = y; if (w || h) { mRenderW = w; mRenderH = h; } return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040076
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 // GetPlacement - Returns the current placement
78 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040079
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 // SetPlacement - Update the current placement
81 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040082
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083 // SetPageFocus - Notify when a page gains or loses focus
84 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040085
86protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020087 int mRenderX, mRenderY, mRenderW, mRenderH;
88 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040089};
90
91class ActionObject
92{
93public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020094 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
95 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040096
97public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020098 // NotifyTouch - Notify of a touch event
99 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
100 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 // NotifyKey - Notify of a key press
103 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
104 virtual int NotifyKey(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 // GetRenderPos - Returns the current position of the object
107 virtual int GetActionPos(int& x, int& y, int& w, int& h) { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400108
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 // SetRenderPos - Update the position of the object
110 // Return 0 on success, <0 on error
111 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400112
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200113 // IsInRegion - Checks if the request is handled by this object
114 // Return 0 if this object handles the request, 1 if not
115 virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); }
Dees_Troy51a0e822012-09-05 15:24:24 -0400116
Dees_Troy51a0e822012-09-05 15:24:24 -0400117protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200118 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400119};
120
Vojtech Bocekede51c52014-02-07 23:58:09 +0100121class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400122{
123public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100124 GUIObject(xml_node<>* node);
125 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400126
127public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200128 bool IsConditionVariable(std::string var);
129 bool isConditionTrue();
130 bool isConditionValid();
Vojtech Bocek07220562014-02-08 02:05:33 +0100131
132 // NotifyVarChange - Notify of a variable change
133 // Returns 0 on success, <0 on error
134 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400135
136protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 class Condition
138 {
139 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100140 Condition() {
141 mLastResult = true;
142 }
143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 std::string mVar1;
145 std::string mVar2;
146 std::string mCompareOp;
147 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100148 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400150
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200151 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400152
153protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200154 bool isMounted(std::string vol);
155 bool isConditionTrue(Condition* condition);
Vojtech Bocek07220562014-02-08 02:05:33 +0100156
157 bool mConditionsResult;
Dees_Troy51a0e822012-09-05 15:24:24 -0400158};
159
160class InputObject
161{
162public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200163 InputObject() { HasInputFocus = 0; }
164 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400165
166public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200167 // NotifyKeyboard - Notify of keyboard input
168 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
169 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400170
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200171 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400172
173protected:
174 int HasInputFocus;
175};
176
177// Derived Objects
178// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100179class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400180{
181public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200182 // w and h may be ignored, in which case, no bounding box is applied
183 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400184
185public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200186 // Render - Render the full object to the GL surface
187 // Return 0 on success, <0 on error
188 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400189
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200190 // Update - Update any UI component animations (called <= 30 FPS)
191 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
192 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400193
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200194 // Retrieve the size of the current string (dynamic strings may change per call)
195 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400196
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200197 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100198 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400199
200 // Set maximum width in pixels
201 virtual int SetMaxWidth(unsigned width);
202
203 // Set number of characters to skip (for scrolling)
204 virtual int SkipCharCount(unsigned skip);
205
Dees_Troy4d12f962012-10-19 13:13:15 -0400206public:
207 bool isHighlighted;
208
Dees_Troy51a0e822012-09-05 15:24:24 -0400209protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200210 std::string mText;
211 std::string mLastValue;
212 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400213 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200214 Resource* mFont;
215 int mIsStatic;
216 int mVarChanged;
217 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400218 unsigned maxWidth;
219 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400220 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400221
222protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200223 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400224};
225
226// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100227class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400228{
229public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400231
232public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200233 // Render - Render the full object to the GL surface
234 // Return 0 on success, <0 on error
235 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400236
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200237 // SetRenderPos - Update the position of the object
238 // Return 0 on success, <0 on error
239 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400240
Dees_Troy4d12f962012-10-19 13:13:15 -0400241public:
242 bool isHighlighted;
243
Dees_Troy51a0e822012-09-05 15:24:24 -0400244protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200245 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400246 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400247};
248
249// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100250class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400251{
252public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200253 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400254
255public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200256 // Render - Render the full object to the GL surface
257 // Return 0 on success, <0 on error
258 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400259
260protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200261 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400262};
263
264// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100265class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400266{
267public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200268 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400269
270public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200271 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
272 virtual int NotifyKey(int key);
Vojtech Bocek07220562014-02-08 02:05:33 +0100273 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400274 virtual int doActions();
275
276protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200277 class Action
278 {
279 public:
280 std::string mFunction;
281 std::string mArg;
282 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400283
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200284 std::vector<Action> mActions;
285 int mKey;
Dees_Troy51a0e822012-09-05 15:24:24 -0400286
287protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200288 int getKeyByName(std::string key);
289 virtual int doAction(Action action, int isThreaded = 0);
290 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400291 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200292 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400293 void operation_start(const string operation_name);
294 void operation_end(const int operation_status, const int simulate);
295 static void* command_thread(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000296 time_t Start;
Dees_Troy51a0e822012-09-05 15:24:24 -0400297};
298
Vojtech Bocekede51c52014-02-07 23:58:09 +0100299class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400300{
301public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200302 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400303
304public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200305 // Render - Render the full object to the GL surface
306 // Return 0 on success, <0 on error
307 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400308
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200309 // Update - Update any UI component animations (called <= 30 FPS)
310 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
311 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400312
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200313 // SetRenderPos - Update the position of the object
314 // Return 0 on success, <0 on error
315 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400316
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200317 // IsInRegion - Checks if the request is handled by this object
318 // Return 0 if this object handles the request, 1 if not
319 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400320
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200321 // NotifyTouch - Notify of a touch event
322 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
323 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400324
325protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200326 enum SlideoutState
327 {
328 hidden = 0,
329 visible,
330 request_hide,
331 request_show
332 };
333
334 Resource* mFont;
335 Resource* mSlideoutImage;
336 COLOR mForegroundColor;
337 COLOR mBackgroundColor;
338 COLOR mScrollColor;
339 unsigned int mFontHeight;
340 int mCurrentLine;
341 unsigned int mLastCount;
342 unsigned int mMaxRows;
343 int mStartY;
344 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
345 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
346 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
347 int mLastTouchX, mLastTouchY;
348 int mSlideMultiplier;
349 int mSlideout;
350 SlideoutState mSlideoutState;
Dees_Troy51a0e822012-09-05 15:24:24 -0400351
352protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200353 virtual int RenderSlideout(void);
354 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400355};
356
Vojtech Bocekede51c52014-02-07 23:58:09 +0100357class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400358{
359public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200360 GUIButton(xml_node<>* node);
361 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400362
363public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200364 // Render - Render the full object to the GL surface
365 // Return 0 on success, <0 on error
366 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400367
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200368 // Update - Update any UI component animations (called <= 30 FPS)
369 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
370 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400371
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200372 // SetPos - Update the position of the render object
373 // Return 0 on success, <0 on error
374 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400375
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200376 // NotifyTouch - Notify of a touch event
377 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
378 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400379
380protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200381 GUIImage* mButtonImg;
382 Resource* mButtonIcon;
383 GUIText* mButtonLabel;
384 GUIAction* mAction;
385 int mTextX, mTextY, mTextW, mTextH;
386 int mIconX, mIconY, mIconW, mIconH;
387 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600388 bool hasHighlightColor;
389 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500390 bool hasFill;
391 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600392 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000393 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400394};
395
Vojtech Bocekede51c52014-02-07 23:58:09 +0100396class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400397{
398public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200399 GUICheckbox(xml_node<>* node);
400 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400401
402public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200403 // Render - Render the full object to the GL surface
404 // Return 0 on success, <0 on error
405 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400406
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200407 // Update - Update any UI component animations (called <= 30 FPS)
408 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
409 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400410
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200411 // SetPos - Update the position of the render object
412 // Return 0 on success, <0 on error
413 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400414
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200415 // NotifyTouch - Notify of a touch event
416 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
417 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400418
419protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200420 Resource* mChecked;
421 Resource* mUnchecked;
422 GUIText* mLabel;
423 int mTextX, mTextY;
424 int mCheckX, mCheckY, mCheckW, mCheckH;
425 int mLastState;
426 bool mRendered;
427 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400428};
429
Vojtech Bocekede51c52014-02-07 23:58:09 +0100430class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400431{
432public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200433 GUIFileSelector(xml_node<>* node);
434 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400435
436public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200437 // Render - Render the full object to the GL surface
438 // Return 0 on success, <0 on error
439 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400440
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200441 // Update - Update any UI component animations (called <= 30 FPS)
442 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
443 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400444
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200445 // NotifyTouch - Notify of a touch event
446 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
447 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400448
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200449 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100450 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400451
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200452 // SetPos - Update the position of the render object
453 // Return 0 on success, <0 on error
454 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400455
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200456 // SetPageFocus - Notify when a page gains or loses focus
457 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400458
459protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200460 struct FileData {
461 std::string fileName;
462 unsigned char fileType; // Uses d_type format from struct dirent
463 mode_t protection; // Uses mode_t format from stat
464 uid_t userId;
465 gid_t groupId;
466 off_t fileSize;
467 time_t lastAccess; // Uses time_t format from stat
468 time_t lastModified; // Uses time_t format from stat
469 time_t lastStatChange; // Uses time_t format from stat
470 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400471
472protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200473 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400474
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200475 virtual int GetFileList(const std::string folder);
476 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400477
478protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200479 std::vector<FileData> mFolderList;
480 std::vector<FileData> mFileList;
481 std::string mPathVar;
482 std::string mExtn;
483 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400484 std::string mSortVariable;
485 std::string mSelection;
486 std::string mHeaderText;
487 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200488 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400489 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200490 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400491 int mSeparatorH;
492 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200493 int mShowFolders, mShowFiles, mShowNavFolders;
494 int mUpdate;
495 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400496 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100497 int mFastScrollW;
498 int mFastScrollLineW;
499 int mFastScrollRectW;
500 int mFastScrollRectH;
501 int mFastScrollRectX;
502 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400503 static int mSortOrder;
504 int startY;
505 int scrollingSpeed;
506 int scrollingY;
507 int mHeaderIsStatic;
508 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200509 unsigned mFontHeight;
510 unsigned mLineHeight;
511 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
512 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400513 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200514 Resource* mFileIcon;
515 Resource* mBackground;
516 Resource* mFont;
517 COLOR mBackgroundColor;
518 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400519 COLOR mHeaderBackgroundColor;
520 COLOR mHeaderFontColor;
521 COLOR mSeparatorColor;
522 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100523 COLOR mFastScrollLineColor;
524 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600525 bool hasHighlightColor;
526 bool hasFontHighlightColor;
527 bool isHighlighted;
528 COLOR mHighlightColor;
529 COLOR mFontHighlightColor;
530 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600531 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400532};
533
Vojtech Bocekede51c52014-02-07 23:58:09 +0100534class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400535{
536public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200537 GUIListBox(xml_node<>* node);
538 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400539
540public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200541 // Render - Render the full object to the GL surface
542 // Return 0 on success, <0 on error
543 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400544
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200545 // Update - Update any UI component animations (called <= 30 FPS)
546 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
547 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400548
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 // NotifyTouch - Notify of a touch event
550 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
551 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400552
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200553 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100554 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400555
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200556 // SetPos - Update the position of the render object
557 // Return 0 on success, <0 on error
558 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400559
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200560 // SetPageFocus - Notify when a page gains or loses focus
561 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400562
563protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200564 struct ListData {
565 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400566 std::string variableValue;
567 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200568 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400569
570protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200571 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400572
573protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200574 std::vector<ListData> mList;
575 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400576 std::string mSelection;
577 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600578 std::string mHeaderText;
579 std::string mLastValue;
580 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200581 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600582 int startY;
583 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200584 int mLineSpacing;
585 int mUpdate;
586 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000587 int mFastScrollW;
588 int mFastScrollLineW;
589 int mFastScrollRectW;
590 int mFastScrollRectH;
591 int mFastScrollRectX;
592 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600593 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
594 int scrollingSpeed;
595 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400596 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200597 unsigned mFontHeight;
598 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600599 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200600 Resource* mIconSelected;
601 Resource* mIconUnselected;
602 Resource* mBackground;
603 Resource* mFont;
604 COLOR mBackgroundColor;
605 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600606 COLOR mHeaderBackgroundColor;
607 COLOR mHeaderFontColor;
608 COLOR mSeparatorColor;
609 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000610 COLOR mFastScrollLineColor;
611 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600612 bool hasHighlightColor;
613 bool hasFontHighlightColor;
614 bool isHighlighted;
615 COLOR mHighlightColor;
616 COLOR mFontHighlightColor;
617 int mHeaderIsStatic;
618 int startSelection;
619 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400620};
621
Vojtech Bocekede51c52014-02-07 23:58:09 +0100622class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500623{
624public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200625 GUIPartitionList(xml_node<>* node);
626 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500627
628public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200629 // Render - Render the full object to the GL surface
630 // Return 0 on success, <0 on error
631 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500632
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200633 // Update - Update any UI component animations (called <= 30 FPS)
634 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
635 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500636
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200637 // NotifyTouch - Notify of a touch event
638 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
639 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500640
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200641 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100642 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500643
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200644 // SetPos - Update the position of the render object
645 // Return 0 on success, <0 on error
646 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500647
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200648 // SetPageFocus - Notify when a page gains or loses focus
649 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500650
651protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200652 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500653 virtual void MatchList(void);
654
655protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200656 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500657 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200658 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500659 std::string selectedList;
660 std::string currentValue;
661 std::string mHeaderText;
662 std::string mLastValue;
663 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200664 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500665 int startY;
666 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200667 int mLineSpacing;
668 int mUpdate;
669 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500670 int mFastScrollW;
671 int mFastScrollLineW;
672 int mFastScrollRectW;
673 int mFastScrollRectH;
674 int mFastScrollRectX;
675 int mFastScrollRectY;
676 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
677 int scrollingSpeed;
678 int scrollingY;
679 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200680 unsigned mFontHeight;
681 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500682 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200683 Resource* mIconSelected;
684 Resource* mIconUnselected;
685 Resource* mBackground;
686 Resource* mFont;
687 COLOR mBackgroundColor;
688 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500689 COLOR mHeaderBackgroundColor;
690 COLOR mHeaderFontColor;
691 COLOR mSeparatorColor;
692 COLOR mHeaderSeparatorColor;
693 COLOR mFastScrollLineColor;
694 COLOR mFastScrollRectColor;
695 bool hasHighlightColor;
696 bool hasFontHighlightColor;
697 bool isHighlighted;
698 COLOR mHighlightColor;
699 COLOR mFontHighlightColor;
700 int mHeaderIsStatic;
701 int startSelection;
702 int touchDebounce;
703 bool updateList;
704};
705
Dees_Troy51a0e822012-09-05 15:24:24 -0400706// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100707class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400708{
709public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200710 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400711
712public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200713 // Render - Render the full object to the GL surface
714 // Return 0 on success, <0 on error
715 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400716
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200717 // Update - Update any UI component animations (called <= 30 FPS)
718 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
719 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400720
721protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200722 AnimationResource* mAnimation;
723 int mFrame;
724 int mFPS;
725 int mLoop;
726 int mRender;
727 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400728};
729
Vojtech Bocekede51c52014-02-07 23:58:09 +0100730class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400731{
732public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200733 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400734
735public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200736 // Render - Render the full object to the GL surface
737 // Return 0 on success, <0 on error
738 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400739
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200740 // Update - Update any UI component animations (called <= 30 FPS)
741 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
742 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400743
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200744 // NotifyVarChange - Notify of a variable change
745 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100746 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400747
748protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200749 Resource* mEmptyBar;
750 Resource* mFullBar;
751 std::string mMinValVar;
752 std::string mMaxValVar;
753 std::string mCurValVar;
754 float mSlide;
755 float mSlideInc;
756 int mSlideFrames;
757 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400758
759protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200760 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400761};
762
Vojtech Bocekede51c52014-02-07 23:58:09 +0100763class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400764{
765public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200766 GUISlider(xml_node<>* node);
767 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400768
769public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200770 // Render - Render the full object to the GL surface
771 // Return 0 on success, <0 on error
772 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400773
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200774 // Update - Update any UI component animations (called <= 30 FPS)
775 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
776 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400777
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200778 // NotifyTouch - Notify of a touch event
779 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
780 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400781
782protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200783 GUIAction* sAction;
784 Resource* sSlider;
785 Resource* sSliderUsed;
786 Resource* sTouch;
787 int sTouchW, sTouchH;
788 int sCurTouchX;
789 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400790};
791
792#define MAX_KEYBOARD_LAYOUTS 5
793#define MAX_KEYBOARD_ROWS 9
794#define MAX_KEYBOARD_KEYS 20
795#define KEYBOARD_ACTION 253
796#define KEYBOARD_LAYOUT 254
797#define KEYBOARD_SWIPE_LEFT 252
798#define KEYBOARD_SWIPE_RIGHT 251
799#define KEYBOARD_ARROW_LEFT 250
800#define KEYBOARD_ARROW_RIGHT 249
801#define KEYBOARD_HOME 248
802#define KEYBOARD_END 247
803#define KEYBOARD_ARROW_UP 246
804#define KEYBOARD_ARROW_DOWN 245
805#define KEYBOARD_SPECIAL_KEYS 245
806#define KEYBOARD_BACKSPACE 8
807
Vojtech Bocekede51c52014-02-07 23:58:09 +0100808class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400809{
810public:
811 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200812 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400813
814public:
815 virtual int Render(void);
816 virtual int Update(void);
817 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
818 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
819
820protected:
821 virtual int GetSelection(int x, int y);
822
823protected:
824 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200825 {
826 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400827 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200828 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400829 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200830 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600831 struct capslock_tracking_struct
832 {
833 int capslock;
834 int set_capslock;
835 int revert_layout;
836 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400837
838 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
839 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600840 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400841 bool mRendered;
842 std::string mVariable;
843 unsigned int cursorLocation;
844 unsigned int currentLayout;
845 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
846 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600847 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400848 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400849 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600850 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400851};
852
853// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100854class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400855{
856public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200857 // w and h may be ignored, in which case, no bounding box is applied
858 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400859 virtual ~GUIInput();
860
861public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200862 // Render - Render the full object to the GL surface
863 // Return 0 on success, <0 on error
864 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400865
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200866 // Update - Update any UI component animations (called <= 30 FPS)
867 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
868 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400869
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200870 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100871 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400872
873 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200874 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
875 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400876
877 virtual int NotifyKeyboard(int key);
878
879protected:
880 virtual int GetSelection(int x, int y);
881
882 // Handles displaying the text properly when chars are added, deleted, or for scrolling
883 virtual int HandleTextLocation(int x);
884
885protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200886 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400887 GUIAction* mAction;
888 Resource* mBackground;
889 Resource* mCursor;
890 Resource* mFont;
891 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200892 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400893 std::string mVariable;
894 std::string mMask;
895 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200896 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400897 COLOR mCursorColor;
898 int scrollingX;
899 int lastX;
900 int mCursorLocation;
901 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
902 int mFontY;
903 unsigned skipChars;
904 unsigned mFontHeight;
905 unsigned CursorWidth;
906 bool mRendered;
907 bool HasMask;
908 bool DrawCursor;
909 bool isLocalChange;
910 bool HasAllowed;
911 bool HasDisabled;
912 std::string AllowedList;
913 std::string DisabledList;
914 unsigned MinLen;
915 unsigned MaxLen;
916};
917
918class HardwareKeyboard
919{
920public:
921 HardwareKeyboard(void);
922 virtual ~HardwareKeyboard();
923
924public:
925 virtual int KeyDown(int key_code);
926 virtual int KeyUp(int key_code);
927 virtual int KeyRepeat(void);
928};
929
Vojtech Bocekede51c52014-02-07 23:58:09 +0100930class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200931{
932public:
933 GUISliderValue(xml_node<>* node);
934 virtual ~GUISliderValue();
935
936public:
937 // Render - Render the full object to the GL surface
938 // Return 0 on success, <0 on error
939 virtual int Render(void);
940
941 // Update - Update any UI component animations (called <= 30 FPS)
942 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
943 virtual int Update(void);
944
945 // SetPos - Update the position of the render object
946 // Return 0 on success, <0 on error
947 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
948
949 // NotifyTouch - Notify of a touch event
950 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
951 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
952
953 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100954 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +0200955
956 // SetPageFocus - Notify when a page gains or loses focus
957 virtual void SetPageFocus(int inFocus);
958
959protected:
960 int measureText(const std::string& str);
961 int valueFromPct(float pct);
962 float pctFromValue(int value);
963 void loadValue(bool force = false);
964
965 std::string mVariable;
966 int mMax;
967 int mMin;
968 int mValue;
969 char *mValueStr;
970 float mValuePct;
971 std::string mMaxStr;
972 std::string mMinStr;
973 Resource *mFont;
974 GUIText* mLabel;
975 int mLabelW;
976 COLOR mTextColor;
977 COLOR mLineColor;
978 COLOR mSliderColor;
979 bool mShowRange;
980 bool mShowCurr;
981 int mLineX;
982 int mLineY;
983 int mLineH;
984 int mLinePadding;
985 int mPadding;
986 int mSliderY;
987 int mSliderW;
988 int mSliderH;
989 bool mRendered;
990 int mFontHeight;
991 GUIAction *mAction;
992 bool mChangeOnDrag;
993 int lineW;
994};
995
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +0100996class MouseCursor : public RenderObject
997{
998public:
999 MouseCursor(int posX, int posY);
1000 virtual ~MouseCursor();
1001
1002 virtual int Render(void);
1003 virtual int Update(void);
1004 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1005
1006 void Move(int deltaX, int deltaY);
1007 void GetPos(int& x, int& y);
1008 void LoadData(xml_node<>* node);
1009 void ResetData(int resX, int resY);
1010
1011private:
1012 int m_resX;
1013 int m_resY;
1014 bool m_moved;
1015 float m_speedMultiplier;
1016 COLOR m_color;
1017 Resource *m_image;
1018 bool m_present;
1019};
1020
Dees_Troy51a0e822012-09-05 15:24:24 -04001021// Helper APIs
1022bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1023
1024#endif // _OBJECTS_HEADER
1025