blob: 02417154a41374d006e37890519970f1bbaf3750 [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>
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010028#include <set>
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +000029#include <time.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040030
31extern "C" {
Dees Troyb7ae0982013-09-10 20:47:35 +000032#ifdef HAVE_SELINUX
Dees_Troy51a0e822012-09-05 15:24:24 -040033#include "../minzip/Zip.h"
Dees Troyb7ae0982013-09-10 20:47:35 +000034#else
35#include "../minzipold/Zip.h"
36#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040037}
38
39using namespace rapidxml;
40
41#include "../data.hpp"
42#include "resources.hpp"
43#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050044#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040045
46class RenderObject
47{
48public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 enum Placement {
50 TOP_LEFT = 0,
51 TOP_RIGHT = 1,
52 BOTTOM_LEFT = 2,
53 BOTTOM_RIGHT = 3,
54 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040055 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056 };
Dees_Troy51a0e822012-09-05 15:24:24 -040057
58public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020059 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
60 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040061
62public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 // Render - Render the full object to the GL surface
64 // Return 0 on success, <0 on error
65 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040066
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067 // Update - Update any UI component animations (called <= 30 FPS)
68 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
69 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040070
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020071 // GetRenderPos - Returns the current position of the object
72 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 -040073
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 // SetRenderPos - Update the position of the object
75 // Return 0 on success, <0 on error
76 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 -040077
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 // GetPlacement - Returns the current placement
79 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040080
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 // SetPlacement - Update the current placement
82 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040083
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020084 // SetPageFocus - Notify when a page gains or loses focus
85 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040086
87protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020088 int mRenderX, mRenderY, mRenderW, mRenderH;
89 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040090};
91
92class ActionObject
93{
94public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
96 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040097
98public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020099 // NotifyTouch - Notify of a touch event
100 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
101 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400102
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200103 // NotifyKey - Notify of a key press
104 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100105 virtual int NotifyKey(int key, bool down) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400106
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200107 // GetRenderPos - Returns the current position of the object
108 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 -0400109
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200110 // SetRenderPos - Update the position of the object
111 // Return 0 on success, <0 on error
112 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400113
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200114 // IsInRegion - Checks if the request is handled by this object
115 // Return 0 if this object handles the request, 1 if not
116 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 -0400117
Dees_Troy51a0e822012-09-05 15:24:24 -0400118protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200119 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400120};
121
Vojtech Bocekede51c52014-02-07 23:58:09 +0100122class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400123{
124public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100125 GUIObject(xml_node<>* node);
126 virtual ~GUIObject();
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();
Vojtech Bocek07220562014-02-08 02:05:33 +0100132
133 // NotifyVarChange - Notify of a variable change
134 // Returns 0 on success, <0 on error
135 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400136
137protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200138 class Condition
139 {
140 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100141 Condition() {
142 mLastResult = true;
143 }
144
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200145 std::string mVar1;
146 std::string mVar2;
147 std::string mCompareOp;
148 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100149 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200150 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400151
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200152 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400153
154protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200155 bool isMounted(std::string vol);
156 bool isConditionTrue(Condition* condition);
Vojtech Bocek07220562014-02-08 02:05:33 +0100157
158 bool mConditionsResult;
Dees_Troy51a0e822012-09-05 15:24:24 -0400159};
160
161class InputObject
162{
163public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200164 InputObject() { HasInputFocus = 0; }
165 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400166
167public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200168 // NotifyKeyboard - Notify of keyboard input
169 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
170 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400171
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200172 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400173
174protected:
175 int HasInputFocus;
176};
177
178// Derived Objects
179// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100180class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400181{
182public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200183 // w and h may be ignored, in which case, no bounding box is applied
184 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400185
186public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200187 // Render - Render the full object to the GL surface
188 // Return 0 on success, <0 on error
189 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400190
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200191 // Update - Update any UI component animations (called <= 30 FPS)
192 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
193 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400194
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200195 // Retrieve the size of the current string (dynamic strings may change per call)
196 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400197
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200198 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100199 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400200
201 // Set maximum width in pixels
202 virtual int SetMaxWidth(unsigned width);
203
204 // Set number of characters to skip (for scrolling)
205 virtual int SkipCharCount(unsigned skip);
206
Dees_Troy4d12f962012-10-19 13:13:15 -0400207public:
208 bool isHighlighted;
209
Dees_Troy51a0e822012-09-05 15:24:24 -0400210protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200211 std::string mText;
212 std::string mLastValue;
213 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400214 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200215 Resource* mFont;
216 int mIsStatic;
217 int mVarChanged;
218 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400219 unsigned maxWidth;
220 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400221 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400222
223protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200224 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400225};
226
227// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100228class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400229{
230public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200231 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400232
233public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200234 // Render - Render the full object to the GL surface
235 // Return 0 on success, <0 on error
236 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400237
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200238 // SetRenderPos - Update the position of the object
239 // Return 0 on success, <0 on error
240 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400241
Dees_Troy4d12f962012-10-19 13:13:15 -0400242public:
243 bool isHighlighted;
244
Dees_Troy51a0e822012-09-05 15:24:24 -0400245protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200246 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400247 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400248};
249
250// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100251class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400252{
253public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200254 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400255
256public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200257 // Render - Render the full object to the GL surface
258 // Return 0 on success, <0 on error
259 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400260
261protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200262 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400263};
264
265// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100266class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400267{
268public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200269 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400270
271public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200272 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100273 virtual int NotifyKey(int key, bool down);
Vojtech Bocek07220562014-02-08 02:05:33 +0100274 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400275 virtual int doActions();
276
277protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200278 class Action
279 {
280 public:
281 std::string mFunction;
282 std::string mArg;
283 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400284
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200285 std::vector<Action> mActions;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100286 std::map<int, bool> mKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400287
288protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200289 int getKeyByName(std::string key);
290 virtual int doAction(Action action, int isThreaded = 0);
291 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400292 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200293 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400294 void operation_start(const string operation_name);
295 void operation_end(const int operation_status, const int simulate);
296 static void* command_thread(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000297 time_t Start;
Dees_Troy51a0e822012-09-05 15:24:24 -0400298};
299
Vojtech Bocekede51c52014-02-07 23:58:09 +0100300class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400301{
302public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200303 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400304
305public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200306 // Render - Render the full object to the GL surface
307 // Return 0 on success, <0 on error
308 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400309
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200310 // Update - Update any UI component animations (called <= 30 FPS)
311 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
312 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400313
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200314 // SetRenderPos - Update the position of the object
315 // Return 0 on success, <0 on error
316 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400317
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200318 // IsInRegion - Checks if the request is handled by this object
319 // Return 0 if this object handles the request, 1 if not
320 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400321
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200322 // NotifyTouch - Notify of a touch event
323 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
324 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400325
326protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200327 enum SlideoutState
328 {
329 hidden = 0,
330 visible,
331 request_hide,
332 request_show
333 };
334
335 Resource* mFont;
336 Resource* mSlideoutImage;
337 COLOR mForegroundColor;
338 COLOR mBackgroundColor;
339 COLOR mScrollColor;
340 unsigned int mFontHeight;
341 int mCurrentLine;
342 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000343 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200344 unsigned int mMaxRows;
345 int mStartY;
346 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
347 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
348 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
349 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200350 int mSlideout;
351 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000352 std::vector<std::string> rConsole;
353 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400354
355protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200356 virtual int RenderSlideout(void);
357 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400358};
359
Vojtech Bocekede51c52014-02-07 23:58:09 +0100360class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400361{
362public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200363 GUIButton(xml_node<>* node);
364 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400365
366public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200367 // Render - Render the full object to the GL surface
368 // Return 0 on success, <0 on error
369 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400370
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200371 // Update - Update any UI component animations (called <= 30 FPS)
372 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
373 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400374
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200375 // SetPos - Update the position of the render object
376 // Return 0 on success, <0 on error
377 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400378
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200379 // NotifyTouch - Notify of a touch event
380 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
381 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400382
383protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200384 GUIImage* mButtonImg;
385 Resource* mButtonIcon;
386 GUIText* mButtonLabel;
387 GUIAction* mAction;
388 int mTextX, mTextY, mTextW, mTextH;
389 int mIconX, mIconY, mIconW, mIconH;
390 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600391 bool hasHighlightColor;
392 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500393 bool hasFill;
394 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600395 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000396 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400397};
398
Vojtech Bocekede51c52014-02-07 23:58:09 +0100399class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400400{
401public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200402 GUICheckbox(xml_node<>* node);
403 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400404
405public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200406 // Render - Render the full object to the GL surface
407 // Return 0 on success, <0 on error
408 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400409
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200410 // Update - Update any UI component animations (called <= 30 FPS)
411 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
412 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400413
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200414 // SetPos - Update the position of the render object
415 // Return 0 on success, <0 on error
416 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400417
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200418 // NotifyTouch - Notify of a touch event
419 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
420 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400421
422protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200423 Resource* mChecked;
424 Resource* mUnchecked;
425 GUIText* mLabel;
426 int mTextX, mTextY;
427 int mCheckX, mCheckY, mCheckW, mCheckH;
428 int mLastState;
429 bool mRendered;
430 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400431};
432
Vojtech Bocekede51c52014-02-07 23:58:09 +0100433class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400434{
435public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200436 GUIFileSelector(xml_node<>* node);
437 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400438
439public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200440 // Render - Render the full object to the GL surface
441 // Return 0 on success, <0 on error
442 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400443
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200444 // Update - Update any UI component animations (called <= 30 FPS)
445 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
446 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400447
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200448 // NotifyTouch - Notify of a touch event
449 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
450 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400451
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200452 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100453 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400454
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200455 // SetPos - Update the position of the render object
456 // Return 0 on success, <0 on error
457 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400458
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200459 // SetPageFocus - Notify when a page gains or loses focus
460 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400461
462protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200463 struct FileData {
464 std::string fileName;
465 unsigned char fileType; // Uses d_type format from struct dirent
466 mode_t protection; // Uses mode_t format from stat
467 uid_t userId;
468 gid_t groupId;
469 off_t fileSize;
470 time_t lastAccess; // Uses time_t format from stat
471 time_t lastModified; // Uses time_t format from stat
472 time_t lastStatChange; // Uses time_t format from stat
473 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400474
475protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200476 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400477
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200478 virtual int GetFileList(const std::string folder);
479 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400480
481protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200482 std::vector<FileData> mFolderList;
483 std::vector<FileData> mFileList;
484 std::string mPathVar;
485 std::string mExtn;
486 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400487 std::string mSortVariable;
488 std::string mSelection;
489 std::string mHeaderText;
490 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200491 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400492 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200493 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400494 int mSeparatorH;
495 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200496 int mShowFolders, mShowFiles, mShowNavFolders;
497 int mUpdate;
498 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400499 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100500 int mFastScrollW;
501 int mFastScrollLineW;
502 int mFastScrollRectW;
503 int mFastScrollRectH;
504 int mFastScrollRectX;
505 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400506 static int mSortOrder;
507 int startY;
508 int scrollingSpeed;
509 int scrollingY;
510 int mHeaderIsStatic;
511 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200512 unsigned mFontHeight;
513 unsigned mLineHeight;
514 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
515 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400516 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200517 Resource* mFileIcon;
518 Resource* mBackground;
519 Resource* mFont;
520 COLOR mBackgroundColor;
521 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400522 COLOR mHeaderBackgroundColor;
523 COLOR mHeaderFontColor;
524 COLOR mSeparatorColor;
525 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100526 COLOR mFastScrollLineColor;
527 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600528 bool hasHighlightColor;
529 bool hasFontHighlightColor;
530 bool isHighlighted;
531 COLOR mHighlightColor;
532 COLOR mFontHighlightColor;
533 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600534 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400535};
536
Vojtech Bocekede51c52014-02-07 23:58:09 +0100537class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400538{
539public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200540 GUIListBox(xml_node<>* node);
541 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400542
543public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200544 // Render - Render the full object to the GL surface
545 // Return 0 on success, <0 on error
546 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400547
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200548 // Update - Update any UI component animations (called <= 30 FPS)
549 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
550 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400551
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200552 // NotifyTouch - Notify of a touch event
553 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
554 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400555
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200556 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100557 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400558
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200559 // SetPos - Update the position of the render object
560 // Return 0 on success, <0 on error
561 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400562
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200563 // SetPageFocus - Notify when a page gains or loses focus
564 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400565
566protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200567 struct ListData {
568 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400569 std::string variableValue;
570 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200571 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400572
573protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200574 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400575
576protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200577 std::vector<ListData> mList;
578 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400579 std::string mSelection;
580 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600581 std::string mHeaderText;
582 std::string mLastValue;
583 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200584 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600585 int startY;
586 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200587 int mLineSpacing;
588 int mUpdate;
589 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000590 int mFastScrollW;
591 int mFastScrollLineW;
592 int mFastScrollRectW;
593 int mFastScrollRectH;
594 int mFastScrollRectX;
595 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600596 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
597 int scrollingSpeed;
598 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400599 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200600 unsigned mFontHeight;
601 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600602 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200603 Resource* mIconSelected;
604 Resource* mIconUnselected;
605 Resource* mBackground;
606 Resource* mFont;
607 COLOR mBackgroundColor;
608 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600609 COLOR mHeaderBackgroundColor;
610 COLOR mHeaderFontColor;
611 COLOR mSeparatorColor;
612 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000613 COLOR mFastScrollLineColor;
614 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600615 bool hasHighlightColor;
616 bool hasFontHighlightColor;
617 bool isHighlighted;
618 COLOR mHighlightColor;
619 COLOR mFontHighlightColor;
620 int mHeaderIsStatic;
621 int startSelection;
622 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400623};
624
Vojtech Bocekede51c52014-02-07 23:58:09 +0100625class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500626{
627public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200628 GUIPartitionList(xml_node<>* node);
629 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500630
631public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200632 // Render - Render the full object to the GL surface
633 // Return 0 on success, <0 on error
634 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500635
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200636 // Update - Update any UI component animations (called <= 30 FPS)
637 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
638 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500639
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200640 // NotifyTouch - Notify of a touch event
641 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
642 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500643
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200644 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100645 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500646
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200647 // SetPos - Update the position of the render object
648 // Return 0 on success, <0 on error
649 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500650
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200651 // SetPageFocus - Notify when a page gains or loses focus
652 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500653
654protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200655 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500656 virtual void MatchList(void);
657
658protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200659 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500660 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200661 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500662 std::string selectedList;
663 std::string currentValue;
664 std::string mHeaderText;
665 std::string mLastValue;
666 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200667 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500668 int startY;
669 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200670 int mLineSpacing;
671 int mUpdate;
672 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500673 int mFastScrollW;
674 int mFastScrollLineW;
675 int mFastScrollRectW;
676 int mFastScrollRectH;
677 int mFastScrollRectX;
678 int mFastScrollRectY;
679 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
680 int scrollingSpeed;
681 int scrollingY;
682 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200683 unsigned mFontHeight;
684 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500685 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200686 Resource* mIconSelected;
687 Resource* mIconUnselected;
688 Resource* mBackground;
689 Resource* mFont;
690 COLOR mBackgroundColor;
691 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500692 COLOR mHeaderBackgroundColor;
693 COLOR mHeaderFontColor;
694 COLOR mSeparatorColor;
695 COLOR mHeaderSeparatorColor;
696 COLOR mFastScrollLineColor;
697 COLOR mFastScrollRectColor;
698 bool hasHighlightColor;
699 bool hasFontHighlightColor;
700 bool isHighlighted;
701 COLOR mHighlightColor;
702 COLOR mFontHighlightColor;
703 int mHeaderIsStatic;
704 int startSelection;
705 int touchDebounce;
706 bool updateList;
707};
708
Dees_Troy51a0e822012-09-05 15:24:24 -0400709// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100710class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400711{
712public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200713 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400714
715public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200716 // Render - Render the full object to the GL surface
717 // Return 0 on success, <0 on error
718 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400719
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200720 // Update - Update any UI component animations (called <= 30 FPS)
721 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
722 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400723
724protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200725 AnimationResource* mAnimation;
726 int mFrame;
727 int mFPS;
728 int mLoop;
729 int mRender;
730 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400731};
732
Vojtech Bocekede51c52014-02-07 23:58:09 +0100733class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400734{
735public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200736 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400737
738public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200739 // Render - Render the full object to the GL surface
740 // Return 0 on success, <0 on error
741 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400742
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200743 // Update - Update any UI component animations (called <= 30 FPS)
744 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
745 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400746
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200747 // NotifyVarChange - Notify of a variable change
748 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100749 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400750
751protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200752 Resource* mEmptyBar;
753 Resource* mFullBar;
754 std::string mMinValVar;
755 std::string mMaxValVar;
756 std::string mCurValVar;
757 float mSlide;
758 float mSlideInc;
759 int mSlideFrames;
760 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400761
762protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200763 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400764};
765
Vojtech Bocekede51c52014-02-07 23:58:09 +0100766class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400767{
768public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200769 GUISlider(xml_node<>* node);
770 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400771
772public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200773 // Render - Render the full object to the GL surface
774 // Return 0 on success, <0 on error
775 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400776
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200777 // Update - Update any UI component animations (called <= 30 FPS)
778 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
779 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400780
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200781 // NotifyTouch - Notify of a touch event
782 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
783 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400784
785protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200786 GUIAction* sAction;
787 Resource* sSlider;
788 Resource* sSliderUsed;
789 Resource* sTouch;
790 int sTouchW, sTouchH;
791 int sCurTouchX;
792 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400793};
794
795#define MAX_KEYBOARD_LAYOUTS 5
796#define MAX_KEYBOARD_ROWS 9
797#define MAX_KEYBOARD_KEYS 20
798#define KEYBOARD_ACTION 253
799#define KEYBOARD_LAYOUT 254
800#define KEYBOARD_SWIPE_LEFT 252
801#define KEYBOARD_SWIPE_RIGHT 251
802#define KEYBOARD_ARROW_LEFT 250
803#define KEYBOARD_ARROW_RIGHT 249
804#define KEYBOARD_HOME 248
805#define KEYBOARD_END 247
806#define KEYBOARD_ARROW_UP 246
807#define KEYBOARD_ARROW_DOWN 245
808#define KEYBOARD_SPECIAL_KEYS 245
809#define KEYBOARD_BACKSPACE 8
810
Vojtech Bocekede51c52014-02-07 23:58:09 +0100811class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400812{
813public:
814 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200815 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400816
817public:
818 virtual int Render(void);
819 virtual int Update(void);
820 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
821 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
822
823protected:
824 virtual int GetSelection(int x, int y);
825
826protected:
827 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200828 {
829 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400830 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200831 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400832 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200833 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600834 struct capslock_tracking_struct
835 {
836 int capslock;
837 int set_capslock;
838 int revert_layout;
839 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400840
841 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
842 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600843 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400844 bool mRendered;
845 std::string mVariable;
846 unsigned int cursorLocation;
847 unsigned int currentLayout;
848 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
849 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600850 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400851 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400852 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600853 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400854};
855
856// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100857class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400858{
859public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200860 // w and h may be ignored, in which case, no bounding box is applied
861 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400862 virtual ~GUIInput();
863
864public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200865 // Render - Render the full object to the GL surface
866 // Return 0 on success, <0 on error
867 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400868
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200869 // Update - Update any UI component animations (called <= 30 FPS)
870 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
871 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400872
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200873 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100874 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400875
876 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200877 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
878 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400879
880 virtual int NotifyKeyboard(int key);
881
882protected:
883 virtual int GetSelection(int x, int y);
884
885 // Handles displaying the text properly when chars are added, deleted, or for scrolling
886 virtual int HandleTextLocation(int x);
887
888protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200889 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400890 GUIAction* mAction;
891 Resource* mBackground;
892 Resource* mCursor;
893 Resource* mFont;
894 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200895 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400896 std::string mVariable;
897 std::string mMask;
898 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200899 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400900 COLOR mCursorColor;
901 int scrollingX;
902 int lastX;
903 int mCursorLocation;
904 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
905 int mFontY;
906 unsigned skipChars;
907 unsigned mFontHeight;
908 unsigned CursorWidth;
909 bool mRendered;
910 bool HasMask;
911 bool DrawCursor;
912 bool isLocalChange;
913 bool HasAllowed;
914 bool HasDisabled;
915 std::string AllowedList;
916 std::string DisabledList;
917 unsigned MinLen;
918 unsigned MaxLen;
919};
920
921class HardwareKeyboard
922{
923public:
924 HardwareKeyboard(void);
925 virtual ~HardwareKeyboard();
926
927public:
928 virtual int KeyDown(int key_code);
929 virtual int KeyUp(int key_code);
930 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100931
932 void ConsumeKeyRelease(int key);
933
934private:
935 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400936};
937
Vojtech Bocekede51c52014-02-07 23:58:09 +0100938class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200939{
940public:
941 GUISliderValue(xml_node<>* node);
942 virtual ~GUISliderValue();
943
944public:
945 // Render - Render the full object to the GL surface
946 // Return 0 on success, <0 on error
947 virtual int Render(void);
948
949 // Update - Update any UI component animations (called <= 30 FPS)
950 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
951 virtual int Update(void);
952
953 // SetPos - Update the position of the render object
954 // Return 0 on success, <0 on error
955 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
956
957 // NotifyTouch - Notify of a touch event
958 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
959 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
960
961 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100962 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +0200963
964 // SetPageFocus - Notify when a page gains or loses focus
965 virtual void SetPageFocus(int inFocus);
966
967protected:
968 int measureText(const std::string& str);
969 int valueFromPct(float pct);
970 float pctFromValue(int value);
971 void loadValue(bool force = false);
972
973 std::string mVariable;
974 int mMax;
975 int mMin;
976 int mValue;
977 char *mValueStr;
978 float mValuePct;
979 std::string mMaxStr;
980 std::string mMinStr;
981 Resource *mFont;
982 GUIText* mLabel;
983 int mLabelW;
984 COLOR mTextColor;
985 COLOR mLineColor;
986 COLOR mSliderColor;
987 bool mShowRange;
988 bool mShowCurr;
989 int mLineX;
990 int mLineY;
991 int mLineH;
992 int mLinePadding;
993 int mPadding;
994 int mSliderY;
995 int mSliderW;
996 int mSliderH;
997 bool mRendered;
998 int mFontHeight;
999 GUIAction *mAction;
1000 bool mChangeOnDrag;
1001 int lineW;
1002};
1003
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001004class MouseCursor : public RenderObject
1005{
1006public:
1007 MouseCursor(int posX, int posY);
1008 virtual ~MouseCursor();
1009
1010 virtual int Render(void);
1011 virtual int Update(void);
1012 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1013
1014 void Move(int deltaX, int deltaY);
1015 void GetPos(int& x, int& y);
1016 void LoadData(xml_node<>* node);
1017 void ResetData(int resX, int resY);
1018
1019private:
1020 int m_resX;
1021 int m_resY;
1022 bool m_moved;
1023 float m_speedMultiplier;
1024 COLOR m_color;
1025 Resource *m_image;
1026 bool m_present;
1027};
1028
Dees_Troy51a0e822012-09-05 15:24:24 -04001029// Helper APIs
1030bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1031
1032#endif // _OBJECTS_HEADER
1033