blob: bf07c86bc4be8147f195ca128046fa7173a0b0de [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
Dees_Troy51a0e822012-09-05 15:24:24 -040031using namespace rapidxml;
32
33#include "../data.hpp"
34#include "resources.hpp"
35#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050036#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040037
38class RenderObject
39{
40public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020041 enum Placement {
42 TOP_LEFT = 0,
43 TOP_RIGHT = 1,
44 BOTTOM_LEFT = 2,
45 BOTTOM_RIGHT = 3,
46 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040047 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 };
Dees_Troy51a0e822012-09-05 15:24:24 -040049
50public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020051 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
52 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040053
54public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 // Render - Render the full object to the GL surface
56 // Return 0 on success, <0 on error
57 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040058
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020059 // Update - Update any UI component animations (called <= 30 FPS)
60 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
61 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040062
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 // GetRenderPos - Returns the current position of the object
64 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 -040065
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020066 // SetRenderPos - Update the position of the object
67 // Return 0 on success, <0 on error
68 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 -040069
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 // GetPlacement - Returns the current placement
71 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040072
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 // SetPlacement - Update the current placement
74 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040075
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020076 // SetPageFocus - Notify when a page gains or loses focus
77 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040078
79protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 int mRenderX, mRenderY, mRenderW, mRenderH;
81 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040082};
83
84class ActionObject
85{
86public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020087 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
88 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040089
90public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020091 // NotifyTouch - Notify of a touch event
92 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
93 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040094
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 // NotifyKey - Notify of a key press
96 // 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 +010097 virtual int NotifyKey(int key, bool down) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -040098
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020099 // GetRenderPos - Returns the current position of the object
100 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 -0400101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 // SetRenderPos - Update the position of the object
103 // Return 0 on success, <0 on error
104 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 // IsInRegion - Checks if the request is handled by this object
107 // Return 0 if this object handles the request, 1 if not
108 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 -0400109
Dees_Troy51a0e822012-09-05 15:24:24 -0400110protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200111 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400112};
113
Vojtech Bocekede51c52014-02-07 23:58:09 +0100114class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400115{
116public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100117 GUIObject(xml_node<>* node);
118 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400119
120public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200121 bool IsConditionVariable(std::string var);
122 bool isConditionTrue();
123 bool isConditionValid();
Vojtech Bocek07220562014-02-08 02:05:33 +0100124
125 // NotifyVarChange - Notify of a variable change
126 // Returns 0 on success, <0 on error
127 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400128
129protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200130 class Condition
131 {
132 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100133 Condition() {
134 mLastResult = true;
135 }
136
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 std::string mVar1;
138 std::string mVar2;
139 std::string mCompareOp;
140 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100141 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200142 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400145
146protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200147 bool isMounted(std::string vol);
148 bool isConditionTrue(Condition* condition);
Vojtech Bocek07220562014-02-08 02:05:33 +0100149
150 bool mConditionsResult;
Dees_Troy51a0e822012-09-05 15:24:24 -0400151};
152
153class InputObject
154{
155public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200156 InputObject() { HasInputFocus = 0; }
157 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400158
159public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 // NotifyKeyboard - Notify of keyboard input
161 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
162 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400163
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200164 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400165
166protected:
167 int HasInputFocus;
168};
169
170// Derived Objects
171// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100172class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400173{
174public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200175 // w and h may be ignored, in which case, no bounding box is applied
176 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400177
178public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200179 // Render - Render the full object to the GL surface
180 // Return 0 on success, <0 on error
181 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400182
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200183 // Update - Update any UI component animations (called <= 30 FPS)
184 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
185 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400186
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200187 // Retrieve the size of the current string (dynamic strings may change per call)
188 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400189
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200190 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100191 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400192
193 // Set maximum width in pixels
194 virtual int SetMaxWidth(unsigned width);
195
196 // Set number of characters to skip (for scrolling)
197 virtual int SkipCharCount(unsigned skip);
198
Dees_Troy4d12f962012-10-19 13:13:15 -0400199public:
200 bool isHighlighted;
201
Dees_Troy51a0e822012-09-05 15:24:24 -0400202protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200203 std::string mText;
204 std::string mLastValue;
205 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400206 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200207 Resource* mFont;
208 int mIsStatic;
209 int mVarChanged;
210 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400211 unsigned maxWidth;
212 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400213 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400214
215protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200216 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400217};
218
219// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100220class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400221{
222public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200223 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400224
225public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200226 // Render - Render the full object to the GL surface
227 // Return 0 on success, <0 on error
228 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400229
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 // SetRenderPos - Update the position of the object
231 // Return 0 on success, <0 on error
232 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400233
Dees_Troy4d12f962012-10-19 13:13:15 -0400234public:
235 bool isHighlighted;
236
Dees_Troy51a0e822012-09-05 15:24:24 -0400237protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200238 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400239 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400240};
241
242// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100243class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400244{
245public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200246 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400247
248public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200249 // Render - Render the full object to the GL surface
250 // Return 0 on success, <0 on error
251 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400252
253protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200254 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400255};
256
257// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100258class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400259{
260public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200261 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400262
263public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200264 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100265 virtual int NotifyKey(int key, bool down);
Vojtech Bocek07220562014-02-08 02:05:33 +0100266 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
that3f7b1ac2014-12-30 11:30:13 +0100267
268 int doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400269
270protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200271 class Action
272 {
273 public:
274 std::string mFunction;
275 std::string mArg;
276 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400277
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200278 std::vector<Action> mActions;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100279 std::map<int, bool> mKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400280
281protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200282 int getKeyByName(std::string key);
that3f7b1ac2014-12-30 11:30:13 +0100283 int doAction(Action action);
Dees_Troy51a0e822012-09-05 15:24:24 -0400284 void simulate_progress_bar(void);
that3f7b1ac2014-12-30 11:30:13 +0100285 int flash_zip(std::string filename, std::string pageName, int* wipe_cache);
thatcc8ddca2015-01-03 01:59:36 +0100286 void reinject_after_flash();
Dees_Troy51a0e822012-09-05 15:24:24 -0400287 void operation_start(const string operation_name);
that3f7b1ac2014-12-30 11:30:13 +0100288 void operation_end(const int operation_status);
Dees_Troy51a0e822012-09-05 15:24:24 -0400289 static void* command_thread(void *cookie);
thatcc8ddca2015-01-03 01:59:36 +0100290 static void* sideload_thread_fn(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000291 time_t Start;
that3f7b1ac2014-12-30 11:30:13 +0100292
293 // map action name to function pointer
294 typedef int (GUIAction::*execFunction)(std::string);
295 typedef std::map<std::string, execFunction> mapFunc;
296 static mapFunc mf;
297
298 // GUI actions
299 int reboot(std::string arg);
300 int home(std::string arg);
301 int key(std::string arg);
302 int page(std::string arg);
303 int reload(std::string arg);
304 int readBackup(std::string arg);
305 int set(std::string arg);
306 int clear(std::string arg);
307 int mount(std::string arg);
308 int unmount(std::string arg);
309 int restoredefaultsettings(std::string arg);
310 int copylog(std::string arg);
311 int compute(std::string arg);
312 int setguitimezone(std::string arg);
313 int overlay(std::string arg);
314 int queuezip(std::string arg);
315 int cancelzip(std::string arg);
316 int queueclear(std::string arg);
317 int sleep(std::string arg);
318 int appenddatetobackupname(std::string arg);
319 int generatebackupname(std::string arg);
320 int checkpartitionlist(std::string arg);
321 int getpartitiondetails(std::string arg);
322 int screenshot(std::string arg);
323 int setbrightness(std::string arg);
324
325 // threaded actions
326 int fileexists(std::string arg);
327 int flash(std::string arg);
328 int wipe(std::string arg);
329 int refreshsizes(std::string arg);
330 int nandroid(std::string arg);
331 int fixpermissions(std::string arg);
332 int dd(std::string arg);
333 int partitionsd(std::string arg);
334 int installhtcdumlock(std::string arg);
335 int htcdumlockrestoreboot(std::string arg);
336 int htcdumlockreflashrecovery(std::string arg);
337 int cmd(std::string arg);
338 int terminalcommand(std::string arg);
339 int killterminal(std::string arg);
340 int reinjecttwrp(std::string arg);
341 int checkbackupname(std::string arg);
342 int decrypt(std::string arg);
343 int adbsideload(std::string arg);
344 int adbsideloadcancel(std::string arg);
345 int openrecoveryscript(std::string arg);
346 int installsu(std::string arg);
347 int fixsu(std::string arg);
348 int decrypt_backup(std::string arg);
349 int repair(std::string arg);
350 int changefilesystem(std::string arg);
351 int startmtp(std::string arg);
352 int stopmtp(std::string arg);
353
354 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400355};
356
Vojtech Bocekede51c52014-02-07 23:58:09 +0100357class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400358{
359public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200360 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400361
362public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200363 // Render - Render the full object to the GL surface
364 // Return 0 on success, <0 on error
365 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400366
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200367 // Update - Update any UI component animations (called <= 30 FPS)
368 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
369 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400370
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200371 // SetRenderPos - Update the position of the object
372 // Return 0 on success, <0 on error
373 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400374
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200375 // IsInRegion - Checks if the request is handled by this object
376 // Return 0 if this object handles the request, 1 if not
377 virtual int IsInRegion(int x, int y);
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 (Return error to allow other handlers)
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 enum SlideoutState
385 {
386 hidden = 0,
387 visible,
388 request_hide,
389 request_show
390 };
391
392 Resource* mFont;
393 Resource* mSlideoutImage;
394 COLOR mForegroundColor;
395 COLOR mBackgroundColor;
396 COLOR mScrollColor;
397 unsigned int mFontHeight;
398 int mCurrentLine;
399 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000400 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200401 unsigned int mMaxRows;
402 int mStartY;
403 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
404 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
405 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
406 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200407 int mSlideout;
408 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000409 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500410 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000411 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400412
413protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200414 virtual int RenderSlideout(void);
415 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400416};
417
Vojtech Bocekede51c52014-02-07 23:58:09 +0100418class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400419{
420public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200421 GUIButton(xml_node<>* node);
422 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400423
424public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200425 // Render - Render the full object to the GL surface
426 // Return 0 on success, <0 on error
427 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400428
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200429 // Update - Update any UI component animations (called <= 30 FPS)
430 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
431 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400432
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200433 // SetPos - Update the position of the render object
434 // Return 0 on success, <0 on error
435 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400436
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200437 // NotifyTouch - Notify of a touch event
438 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
439 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400440
441protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200442 GUIImage* mButtonImg;
443 Resource* mButtonIcon;
444 GUIText* mButtonLabel;
445 GUIAction* mAction;
446 int mTextX, mTextY, mTextW, mTextH;
447 int mIconX, mIconY, mIconW, mIconH;
448 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600449 bool hasHighlightColor;
450 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500451 bool hasFill;
452 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600453 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000454 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400455};
456
Vojtech Bocekede51c52014-02-07 23:58:09 +0100457class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400458{
459public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200460 GUICheckbox(xml_node<>* node);
461 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400462
463public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200464 // Render - Render the full object to the GL surface
465 // Return 0 on success, <0 on error
466 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400467
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200468 // Update - Update any UI component animations (called <= 30 FPS)
469 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
470 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400471
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200472 // SetPos - Update the position of the render object
473 // Return 0 on success, <0 on error
474 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400475
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200476 // NotifyTouch - Notify of a touch event
477 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
478 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400479
480protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200481 Resource* mChecked;
482 Resource* mUnchecked;
483 GUIText* mLabel;
484 int mTextX, mTextY;
485 int mCheckX, mCheckY, mCheckW, mCheckH;
486 int mLastState;
487 bool mRendered;
488 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400489};
490
Vojtech Bocekede51c52014-02-07 23:58:09 +0100491class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400492{
493public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200494 GUIFileSelector(xml_node<>* node);
495 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400496
497public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200498 // Render - Render the full object to the GL surface
499 // Return 0 on success, <0 on error
500 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400501
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200502 // Update - Update any UI component animations (called <= 30 FPS)
503 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
504 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400505
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200506 // NotifyTouch - Notify of a touch event
507 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
508 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400509
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200510 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100511 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400512
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200513 // SetPos - Update the position of the render object
514 // Return 0 on success, <0 on error
515 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400516
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200517 // SetPageFocus - Notify when a page gains or loses focus
518 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400519
520protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200521 struct FileData {
522 std::string fileName;
523 unsigned char fileType; // Uses d_type format from struct dirent
524 mode_t protection; // Uses mode_t format from stat
525 uid_t userId;
526 gid_t groupId;
527 off_t fileSize;
528 time_t lastAccess; // Uses time_t format from stat
529 time_t lastModified; // Uses time_t format from stat
530 time_t lastStatChange; // Uses time_t format from stat
531 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400532
533protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200534 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400535
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200536 virtual int GetFileList(const std::string folder);
537 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400538
539protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200540 std::vector<FileData> mFolderList;
541 std::vector<FileData> mFileList;
542 std::string mPathVar;
543 std::string mExtn;
544 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400545 std::string mSortVariable;
546 std::string mSelection;
547 std::string mHeaderText;
548 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400550 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200551 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400552 int mSeparatorH;
553 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200554 int mShowFolders, mShowFiles, mShowNavFolders;
555 int mUpdate;
556 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400557 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100558 int mFastScrollW;
559 int mFastScrollLineW;
560 int mFastScrollRectW;
561 int mFastScrollRectH;
562 int mFastScrollRectX;
563 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400564 static int mSortOrder;
565 int startY;
566 int scrollingSpeed;
567 int scrollingY;
568 int mHeaderIsStatic;
569 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200570 unsigned mFontHeight;
571 unsigned mLineHeight;
572 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
573 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400574 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200575 Resource* mFileIcon;
576 Resource* mBackground;
577 Resource* mFont;
578 COLOR mBackgroundColor;
579 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400580 COLOR mHeaderBackgroundColor;
581 COLOR mHeaderFontColor;
582 COLOR mSeparatorColor;
583 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100584 COLOR mFastScrollLineColor;
585 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600586 bool hasHighlightColor;
587 bool hasFontHighlightColor;
588 bool isHighlighted;
589 COLOR mHighlightColor;
590 COLOR mFontHighlightColor;
591 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600592 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400593};
594
Vojtech Bocekede51c52014-02-07 23:58:09 +0100595class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400596{
597public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200598 GUIListBox(xml_node<>* node);
599 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400600
601public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200602 // Render - Render the full object to the GL surface
603 // Return 0 on success, <0 on error
604 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400605
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200606 // Update - Update any UI component animations (called <= 30 FPS)
607 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
608 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400609
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200610 // NotifyTouch - Notify of a touch event
611 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
612 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400613
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200614 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100615 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400616
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200617 // SetPos - Update the position of the render object
618 // Return 0 on success, <0 on error
619 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400620
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200621 // SetPageFocus - Notify when a page gains or loses focus
622 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400623
624protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200625 struct ListData {
626 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400627 std::string variableValue;
628 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200629 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400630
631protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200632 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400633
634protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200635 std::vector<ListData> mList;
636 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400637 std::string mSelection;
638 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600639 std::string mHeaderText;
640 std::string mLastValue;
641 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200642 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600643 int startY;
644 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200645 int mLineSpacing;
646 int mUpdate;
647 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000648 int mFastScrollW;
649 int mFastScrollLineW;
650 int mFastScrollRectW;
651 int mFastScrollRectH;
652 int mFastScrollRectX;
653 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600654 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
655 int scrollingSpeed;
656 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400657 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200658 unsigned mFontHeight;
659 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600660 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200661 Resource* mIconSelected;
662 Resource* mIconUnselected;
663 Resource* mBackground;
664 Resource* mFont;
665 COLOR mBackgroundColor;
666 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600667 COLOR mHeaderBackgroundColor;
668 COLOR mHeaderFontColor;
669 COLOR mSeparatorColor;
670 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000671 COLOR mFastScrollLineColor;
672 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600673 bool hasHighlightColor;
674 bool hasFontHighlightColor;
675 bool isHighlighted;
676 COLOR mHighlightColor;
677 COLOR mFontHighlightColor;
678 int mHeaderIsStatic;
679 int startSelection;
680 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400681};
682
Vojtech Bocekede51c52014-02-07 23:58:09 +0100683class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500684{
685public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200686 GUIPartitionList(xml_node<>* node);
687 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500688
689public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200690 // Render - Render the full object to the GL surface
691 // Return 0 on success, <0 on error
692 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500693
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200694 // Update - Update any UI component animations (called <= 30 FPS)
695 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
696 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500697
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200698 // NotifyTouch - Notify of a touch event
699 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
700 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500701
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200702 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100703 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500704
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200705 // SetPos - Update the position of the render object
706 // Return 0 on success, <0 on error
707 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500708
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200709 // SetPageFocus - Notify when a page gains or loses focus
710 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500711
712protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200713 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500714 virtual void MatchList(void);
715
716protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200717 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500718 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200719 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500720 std::string selectedList;
721 std::string currentValue;
722 std::string mHeaderText;
723 std::string mLastValue;
724 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200725 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500726 int startY;
727 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200728 int mLineSpacing;
729 int mUpdate;
730 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500731 int mFastScrollW;
732 int mFastScrollLineW;
733 int mFastScrollRectW;
734 int mFastScrollRectH;
735 int mFastScrollRectX;
736 int mFastScrollRectY;
737 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
738 int scrollingSpeed;
739 int scrollingY;
740 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200741 unsigned mFontHeight;
742 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500743 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200744 Resource* mIconSelected;
745 Resource* mIconUnselected;
746 Resource* mBackground;
747 Resource* mFont;
748 COLOR mBackgroundColor;
749 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500750 COLOR mHeaderBackgroundColor;
751 COLOR mHeaderFontColor;
752 COLOR mSeparatorColor;
753 COLOR mHeaderSeparatorColor;
754 COLOR mFastScrollLineColor;
755 COLOR mFastScrollRectColor;
756 bool hasHighlightColor;
757 bool hasFontHighlightColor;
758 bool isHighlighted;
759 COLOR mHighlightColor;
760 COLOR mFontHighlightColor;
761 int mHeaderIsStatic;
762 int startSelection;
763 int touchDebounce;
764 bool updateList;
765};
766
Dees_Troy51a0e822012-09-05 15:24:24 -0400767// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100768class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400769{
770public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200771 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400772
773public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200774 // Render - Render the full object to the GL surface
775 // Return 0 on success, <0 on error
776 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400777
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200778 // Update - Update any UI component animations (called <= 30 FPS)
779 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
780 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400781
782protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200783 AnimationResource* mAnimation;
784 int mFrame;
785 int mFPS;
786 int mLoop;
787 int mRender;
788 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400789};
790
Vojtech Bocekede51c52014-02-07 23:58:09 +0100791class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400792{
793public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200794 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400795
796public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200797 // Render - Render the full object to the GL surface
798 // Return 0 on success, <0 on error
799 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400800
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200801 // Update - Update any UI component animations (called <= 30 FPS)
802 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
803 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400804
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200805 // NotifyVarChange - Notify of a variable change
806 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100807 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400808
809protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200810 Resource* mEmptyBar;
811 Resource* mFullBar;
812 std::string mMinValVar;
813 std::string mMaxValVar;
814 std::string mCurValVar;
815 float mSlide;
816 float mSlideInc;
817 int mSlideFrames;
818 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400819
820protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200821 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400822};
823
Vojtech Bocekede51c52014-02-07 23:58:09 +0100824class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400825{
826public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200827 GUISlider(xml_node<>* node);
828 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400829
830public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200831 // Render - Render the full object to the GL surface
832 // Return 0 on success, <0 on error
833 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400834
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200835 // Update - Update any UI component animations (called <= 30 FPS)
836 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
837 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400838
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200839 // NotifyTouch - Notify of a touch event
840 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
841 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400842
843protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200844 GUIAction* sAction;
845 Resource* sSlider;
846 Resource* sSliderUsed;
847 Resource* sTouch;
848 int sTouchW, sTouchH;
849 int sCurTouchX;
850 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400851};
852
853#define MAX_KEYBOARD_LAYOUTS 5
854#define MAX_KEYBOARD_ROWS 9
855#define MAX_KEYBOARD_KEYS 20
856#define KEYBOARD_ACTION 253
857#define KEYBOARD_LAYOUT 254
858#define KEYBOARD_SWIPE_LEFT 252
859#define KEYBOARD_SWIPE_RIGHT 251
860#define KEYBOARD_ARROW_LEFT 250
861#define KEYBOARD_ARROW_RIGHT 249
862#define KEYBOARD_HOME 248
863#define KEYBOARD_END 247
864#define KEYBOARD_ARROW_UP 246
865#define KEYBOARD_ARROW_DOWN 245
866#define KEYBOARD_SPECIAL_KEYS 245
867#define KEYBOARD_BACKSPACE 8
868
Vojtech Bocekede51c52014-02-07 23:58:09 +0100869class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400870{
871public:
872 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200873 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400874
875public:
876 virtual int Render(void);
877 virtual int Update(void);
878 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
879 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
880
881protected:
882 virtual int GetSelection(int x, int y);
883
884protected:
885 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200886 {
887 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400888 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200889 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400890 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200891 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600892 struct capslock_tracking_struct
893 {
894 int capslock;
895 int set_capslock;
896 int revert_layout;
897 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400898
899 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
900 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600901 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400902 bool mRendered;
903 std::string mVariable;
904 unsigned int cursorLocation;
905 unsigned int currentLayout;
906 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
907 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600908 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400909 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400910 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600911 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400912};
913
914// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100915class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400916{
917public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200918 // w and h may be ignored, in which case, no bounding box is applied
919 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400920 virtual ~GUIInput();
921
922public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200923 // Render - Render the full object to the GL surface
924 // Return 0 on success, <0 on error
925 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400926
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200927 // Update - Update any UI component animations (called <= 30 FPS)
928 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
929 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400930
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200931 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100932 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400933
934 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200935 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
936 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400937
938 virtual int NotifyKeyboard(int key);
939
940protected:
941 virtual int GetSelection(int x, int y);
942
943 // Handles displaying the text properly when chars are added, deleted, or for scrolling
944 virtual int HandleTextLocation(int x);
945
946protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200947 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400948 GUIAction* mAction;
949 Resource* mBackground;
950 Resource* mCursor;
951 Resource* mFont;
952 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200953 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400954 std::string mVariable;
955 std::string mMask;
956 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200957 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400958 COLOR mCursorColor;
959 int scrollingX;
960 int lastX;
961 int mCursorLocation;
962 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
963 int mFontY;
964 unsigned skipChars;
965 unsigned mFontHeight;
966 unsigned CursorWidth;
967 bool mRendered;
968 bool HasMask;
969 bool DrawCursor;
970 bool isLocalChange;
971 bool HasAllowed;
972 bool HasDisabled;
973 std::string AllowedList;
974 std::string DisabledList;
975 unsigned MinLen;
976 unsigned MaxLen;
977};
978
979class HardwareKeyboard
980{
981public:
982 HardwareKeyboard(void);
983 virtual ~HardwareKeyboard();
984
985public:
986 virtual int KeyDown(int key_code);
987 virtual int KeyUp(int key_code);
988 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100989
990 void ConsumeKeyRelease(int key);
991
992private:
993 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400994};
995
Vojtech Bocekede51c52014-02-07 23:58:09 +0100996class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200997{
998public:
999 GUISliderValue(xml_node<>* node);
1000 virtual ~GUISliderValue();
1001
1002public:
1003 // Render - Render the full object to the GL surface
1004 // Return 0 on success, <0 on error
1005 virtual int Render(void);
1006
1007 // Update - Update any UI component animations (called <= 30 FPS)
1008 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1009 virtual int Update(void);
1010
1011 // SetPos - Update the position of the render object
1012 // Return 0 on success, <0 on error
1013 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1014
1015 // NotifyTouch - Notify of a touch event
1016 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1017 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1018
1019 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001020 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001021
1022 // SetPageFocus - Notify when a page gains or loses focus
1023 virtual void SetPageFocus(int inFocus);
1024
1025protected:
1026 int measureText(const std::string& str);
1027 int valueFromPct(float pct);
1028 float pctFromValue(int value);
1029 void loadValue(bool force = false);
1030
1031 std::string mVariable;
1032 int mMax;
1033 int mMin;
1034 int mValue;
1035 char *mValueStr;
1036 float mValuePct;
1037 std::string mMaxStr;
1038 std::string mMinStr;
1039 Resource *mFont;
1040 GUIText* mLabel;
1041 int mLabelW;
1042 COLOR mTextColor;
1043 COLOR mLineColor;
1044 COLOR mSliderColor;
1045 bool mShowRange;
1046 bool mShowCurr;
1047 int mLineX;
1048 int mLineY;
1049 int mLineH;
1050 int mLinePadding;
1051 int mPadding;
1052 int mSliderY;
1053 int mSliderW;
1054 int mSliderH;
1055 bool mRendered;
1056 int mFontHeight;
1057 GUIAction *mAction;
1058 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001059 int mLineW;
1060 bool mDragging;
1061 Resource *mBackgroundImage;
1062 Resource *mHandleImage;
1063 Resource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001064};
1065
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001066class MouseCursor : public RenderObject
1067{
1068public:
1069 MouseCursor(int posX, int posY);
1070 virtual ~MouseCursor();
1071
1072 virtual int Render(void);
1073 virtual int Update(void);
1074 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1075
1076 void Move(int deltaX, int deltaY);
1077 void GetPos(int& x, int& y);
1078 void LoadData(xml_node<>* node);
1079 void ResetData(int resX, int resY);
1080
1081private:
1082 int m_resX;
1083 int m_resY;
1084 bool m_moved;
1085 float m_speedMultiplier;
1086 COLOR m_color;
1087 Resource *m_image;
1088 bool m_present;
1089};
1090
Dees_Troy51a0e822012-09-05 15:24:24 -04001091// Helper APIs
1092bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1093
1094#endif // _OBJECTS_HEADER
1095