blob: 3f12ea7f7f139587e1929ab5d92a1b7669720cb8 [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);
Dees_Troy51a0e822012-09-05 15:24:24 -0400286 void operation_start(const string operation_name);
that3f7b1ac2014-12-30 11:30:13 +0100287 void operation_end(const int operation_status);
Dees_Troy51a0e822012-09-05 15:24:24 -0400288 static void* command_thread(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000289 time_t Start;
that3f7b1ac2014-12-30 11:30:13 +0100290
291 // map action name to function pointer
292 typedef int (GUIAction::*execFunction)(std::string);
293 typedef std::map<std::string, execFunction> mapFunc;
294 static mapFunc mf;
295
296 // GUI actions
297 int reboot(std::string arg);
298 int home(std::string arg);
299 int key(std::string arg);
300 int page(std::string arg);
301 int reload(std::string arg);
302 int readBackup(std::string arg);
303 int set(std::string arg);
304 int clear(std::string arg);
305 int mount(std::string arg);
306 int unmount(std::string arg);
307 int restoredefaultsettings(std::string arg);
308 int copylog(std::string arg);
309 int compute(std::string arg);
310 int setguitimezone(std::string arg);
311 int overlay(std::string arg);
312 int queuezip(std::string arg);
313 int cancelzip(std::string arg);
314 int queueclear(std::string arg);
315 int sleep(std::string arg);
316 int appenddatetobackupname(std::string arg);
317 int generatebackupname(std::string arg);
318 int checkpartitionlist(std::string arg);
319 int getpartitiondetails(std::string arg);
320 int screenshot(std::string arg);
321 int setbrightness(std::string arg);
322
323 // threaded actions
324 int fileexists(std::string arg);
325 int flash(std::string arg);
326 int wipe(std::string arg);
327 int refreshsizes(std::string arg);
328 int nandroid(std::string arg);
329 int fixpermissions(std::string arg);
330 int dd(std::string arg);
331 int partitionsd(std::string arg);
332 int installhtcdumlock(std::string arg);
333 int htcdumlockrestoreboot(std::string arg);
334 int htcdumlockreflashrecovery(std::string arg);
335 int cmd(std::string arg);
336 int terminalcommand(std::string arg);
337 int killterminal(std::string arg);
338 int reinjecttwrp(std::string arg);
339 int checkbackupname(std::string arg);
340 int decrypt(std::string arg);
341 int adbsideload(std::string arg);
342 int adbsideloadcancel(std::string arg);
343 int openrecoveryscript(std::string arg);
344 int installsu(std::string arg);
345 int fixsu(std::string arg);
346 int decrypt_backup(std::string arg);
347 int repair(std::string arg);
348 int changefilesystem(std::string arg);
349 int startmtp(std::string arg);
350 int stopmtp(std::string arg);
351
352 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400353};
354
Vojtech Bocekede51c52014-02-07 23:58:09 +0100355class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400356{
357public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200358 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400359
360public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200361 // Render - Render the full object to the GL surface
362 // Return 0 on success, <0 on error
363 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400364
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200365 // Update - Update any UI component animations (called <= 30 FPS)
366 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
367 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400368
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200369 // SetRenderPos - Update the position of the object
370 // Return 0 on success, <0 on error
371 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400372
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200373 // IsInRegion - Checks if the request is handled by this object
374 // Return 0 if this object handles the request, 1 if not
375 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400376
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200377 // NotifyTouch - Notify of a touch event
378 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
379 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400380
381protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200382 enum SlideoutState
383 {
384 hidden = 0,
385 visible,
386 request_hide,
387 request_show
388 };
389
390 Resource* mFont;
391 Resource* mSlideoutImage;
392 COLOR mForegroundColor;
393 COLOR mBackgroundColor;
394 COLOR mScrollColor;
395 unsigned int mFontHeight;
396 int mCurrentLine;
397 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000398 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200399 unsigned int mMaxRows;
400 int mStartY;
401 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
402 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
403 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
404 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200405 int mSlideout;
406 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000407 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500408 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000409 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400410
411protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200412 virtual int RenderSlideout(void);
413 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400414};
415
Vojtech Bocekede51c52014-02-07 23:58:09 +0100416class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400417{
418public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200419 GUIButton(xml_node<>* node);
420 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400421
422public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200423 // Render - Render the full object to the GL surface
424 // Return 0 on success, <0 on error
425 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400426
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200427 // Update - Update any UI component animations (called <= 30 FPS)
428 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
429 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400430
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200431 // SetPos - Update the position of the render object
432 // Return 0 on success, <0 on error
433 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400434
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200435 // NotifyTouch - Notify of a touch event
436 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
437 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400438
439protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200440 GUIImage* mButtonImg;
441 Resource* mButtonIcon;
442 GUIText* mButtonLabel;
443 GUIAction* mAction;
444 int mTextX, mTextY, mTextW, mTextH;
445 int mIconX, mIconY, mIconW, mIconH;
446 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600447 bool hasHighlightColor;
448 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500449 bool hasFill;
450 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600451 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000452 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400453};
454
Vojtech Bocekede51c52014-02-07 23:58:09 +0100455class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400456{
457public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200458 GUICheckbox(xml_node<>* node);
459 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400460
461public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200462 // Render - Render the full object to the GL surface
463 // Return 0 on success, <0 on error
464 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400465
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200466 // Update - Update any UI component animations (called <= 30 FPS)
467 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
468 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400469
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200470 // SetPos - Update the position of the render object
471 // Return 0 on success, <0 on error
472 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400473
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200474 // NotifyTouch - Notify of a touch event
475 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
476 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400477
478protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200479 Resource* mChecked;
480 Resource* mUnchecked;
481 GUIText* mLabel;
482 int mTextX, mTextY;
483 int mCheckX, mCheckY, mCheckW, mCheckH;
484 int mLastState;
485 bool mRendered;
486 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400487};
488
Vojtech Bocekede51c52014-02-07 23:58:09 +0100489class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400490{
491public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200492 GUIFileSelector(xml_node<>* node);
493 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400494
495public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200496 // Render - Render the full object to the GL surface
497 // Return 0 on success, <0 on error
498 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400499
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200500 // Update - Update any UI component animations (called <= 30 FPS)
501 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
502 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400503
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200504 // NotifyTouch - Notify of a touch event
505 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
506 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400507
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200508 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100509 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400510
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200511 // SetPos - Update the position of the render object
512 // Return 0 on success, <0 on error
513 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400514
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200515 // SetPageFocus - Notify when a page gains or loses focus
516 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400517
518protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200519 struct FileData {
520 std::string fileName;
521 unsigned char fileType; // Uses d_type format from struct dirent
522 mode_t protection; // Uses mode_t format from stat
523 uid_t userId;
524 gid_t groupId;
525 off_t fileSize;
526 time_t lastAccess; // Uses time_t format from stat
527 time_t lastModified; // Uses time_t format from stat
528 time_t lastStatChange; // Uses time_t format from stat
529 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400530
531protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200532 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400533
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200534 virtual int GetFileList(const std::string folder);
535 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400536
537protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200538 std::vector<FileData> mFolderList;
539 std::vector<FileData> mFileList;
540 std::string mPathVar;
541 std::string mExtn;
542 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400543 std::string mSortVariable;
544 std::string mSelection;
545 std::string mHeaderText;
546 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200547 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400548 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400550 int mSeparatorH;
551 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200552 int mShowFolders, mShowFiles, mShowNavFolders;
553 int mUpdate;
554 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400555 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100556 int mFastScrollW;
557 int mFastScrollLineW;
558 int mFastScrollRectW;
559 int mFastScrollRectH;
560 int mFastScrollRectX;
561 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400562 static int mSortOrder;
563 int startY;
564 int scrollingSpeed;
565 int scrollingY;
566 int mHeaderIsStatic;
567 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200568 unsigned mFontHeight;
569 unsigned mLineHeight;
570 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
571 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400572 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200573 Resource* mFileIcon;
574 Resource* mBackground;
575 Resource* mFont;
576 COLOR mBackgroundColor;
577 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400578 COLOR mHeaderBackgroundColor;
579 COLOR mHeaderFontColor;
580 COLOR mSeparatorColor;
581 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100582 COLOR mFastScrollLineColor;
583 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600584 bool hasHighlightColor;
585 bool hasFontHighlightColor;
586 bool isHighlighted;
587 COLOR mHighlightColor;
588 COLOR mFontHighlightColor;
589 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600590 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400591};
592
Vojtech Bocekede51c52014-02-07 23:58:09 +0100593class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400594{
595public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200596 GUIListBox(xml_node<>* node);
597 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400598
599public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200600 // Render - Render the full object to the GL surface
601 // Return 0 on success, <0 on error
602 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400603
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200604 // Update - Update any UI component animations (called <= 30 FPS)
605 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
606 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400607
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200608 // NotifyTouch - Notify of a touch event
609 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
610 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400611
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200612 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100613 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400614
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200615 // SetPos - Update the position of the render object
616 // Return 0 on success, <0 on error
617 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400618
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200619 // SetPageFocus - Notify when a page gains or loses focus
620 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400621
622protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200623 struct ListData {
624 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400625 std::string variableValue;
626 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400628
629protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200630 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400631
632protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200633 std::vector<ListData> mList;
634 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400635 std::string mSelection;
636 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600637 std::string mHeaderText;
638 std::string mLastValue;
639 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200640 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600641 int startY;
642 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200643 int mLineSpacing;
644 int mUpdate;
645 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000646 int mFastScrollW;
647 int mFastScrollLineW;
648 int mFastScrollRectW;
649 int mFastScrollRectH;
650 int mFastScrollRectX;
651 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600652 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
653 int scrollingSpeed;
654 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400655 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200656 unsigned mFontHeight;
657 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600658 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200659 Resource* mIconSelected;
660 Resource* mIconUnselected;
661 Resource* mBackground;
662 Resource* mFont;
663 COLOR mBackgroundColor;
664 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600665 COLOR mHeaderBackgroundColor;
666 COLOR mHeaderFontColor;
667 COLOR mSeparatorColor;
668 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000669 COLOR mFastScrollLineColor;
670 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600671 bool hasHighlightColor;
672 bool hasFontHighlightColor;
673 bool isHighlighted;
674 COLOR mHighlightColor;
675 COLOR mFontHighlightColor;
676 int mHeaderIsStatic;
677 int startSelection;
678 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400679};
680
Vojtech Bocekede51c52014-02-07 23:58:09 +0100681class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500682{
683public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200684 GUIPartitionList(xml_node<>* node);
685 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500686
687public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200688 // Render - Render the full object to the GL surface
689 // Return 0 on success, <0 on error
690 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500691
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200692 // Update - Update any UI component animations (called <= 30 FPS)
693 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
694 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500695
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200696 // NotifyTouch - Notify of a touch event
697 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
698 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500699
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200700 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100701 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500702
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200703 // SetPos - Update the position of the render object
704 // Return 0 on success, <0 on error
705 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500706
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200707 // SetPageFocus - Notify when a page gains or loses focus
708 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500709
710protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200711 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500712 virtual void MatchList(void);
713
714protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200715 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500716 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200717 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500718 std::string selectedList;
719 std::string currentValue;
720 std::string mHeaderText;
721 std::string mLastValue;
722 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200723 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500724 int startY;
725 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200726 int mLineSpacing;
727 int mUpdate;
728 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500729 int mFastScrollW;
730 int mFastScrollLineW;
731 int mFastScrollRectW;
732 int mFastScrollRectH;
733 int mFastScrollRectX;
734 int mFastScrollRectY;
735 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
736 int scrollingSpeed;
737 int scrollingY;
738 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200739 unsigned mFontHeight;
740 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500741 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200742 Resource* mIconSelected;
743 Resource* mIconUnselected;
744 Resource* mBackground;
745 Resource* mFont;
746 COLOR mBackgroundColor;
747 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500748 COLOR mHeaderBackgroundColor;
749 COLOR mHeaderFontColor;
750 COLOR mSeparatorColor;
751 COLOR mHeaderSeparatorColor;
752 COLOR mFastScrollLineColor;
753 COLOR mFastScrollRectColor;
754 bool hasHighlightColor;
755 bool hasFontHighlightColor;
756 bool isHighlighted;
757 COLOR mHighlightColor;
758 COLOR mFontHighlightColor;
759 int mHeaderIsStatic;
760 int startSelection;
761 int touchDebounce;
762 bool updateList;
763};
764
Dees_Troy51a0e822012-09-05 15:24:24 -0400765// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100766class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400767{
768public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200769 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400770
771public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200772 // Render - Render the full object to the GL surface
773 // Return 0 on success, <0 on error
774 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400775
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200776 // Update - Update any UI component animations (called <= 30 FPS)
777 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
778 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400779
780protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200781 AnimationResource* mAnimation;
782 int mFrame;
783 int mFPS;
784 int mLoop;
785 int mRender;
786 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400787};
788
Vojtech Bocekede51c52014-02-07 23:58:09 +0100789class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400790{
791public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200792 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400793
794public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200795 // Render - Render the full object to the GL surface
796 // Return 0 on success, <0 on error
797 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400798
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200799 // Update - Update any UI component animations (called <= 30 FPS)
800 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
801 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400802
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200803 // NotifyVarChange - Notify of a variable change
804 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100805 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400806
807protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200808 Resource* mEmptyBar;
809 Resource* mFullBar;
810 std::string mMinValVar;
811 std::string mMaxValVar;
812 std::string mCurValVar;
813 float mSlide;
814 float mSlideInc;
815 int mSlideFrames;
816 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400817
818protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200819 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400820};
821
Vojtech Bocekede51c52014-02-07 23:58:09 +0100822class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400823{
824public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200825 GUISlider(xml_node<>* node);
826 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400827
828public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200829 // Render - Render the full object to the GL surface
830 // Return 0 on success, <0 on error
831 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400832
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200833 // Update - Update any UI component animations (called <= 30 FPS)
834 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
835 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400836
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200837 // NotifyTouch - Notify of a touch event
838 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
839 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400840
841protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200842 GUIAction* sAction;
843 Resource* sSlider;
844 Resource* sSliderUsed;
845 Resource* sTouch;
846 int sTouchW, sTouchH;
847 int sCurTouchX;
848 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400849};
850
851#define MAX_KEYBOARD_LAYOUTS 5
852#define MAX_KEYBOARD_ROWS 9
853#define MAX_KEYBOARD_KEYS 20
854#define KEYBOARD_ACTION 253
855#define KEYBOARD_LAYOUT 254
856#define KEYBOARD_SWIPE_LEFT 252
857#define KEYBOARD_SWIPE_RIGHT 251
858#define KEYBOARD_ARROW_LEFT 250
859#define KEYBOARD_ARROW_RIGHT 249
860#define KEYBOARD_HOME 248
861#define KEYBOARD_END 247
862#define KEYBOARD_ARROW_UP 246
863#define KEYBOARD_ARROW_DOWN 245
864#define KEYBOARD_SPECIAL_KEYS 245
865#define KEYBOARD_BACKSPACE 8
866
Vojtech Bocekede51c52014-02-07 23:58:09 +0100867class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400868{
869public:
870 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200871 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400872
873public:
874 virtual int Render(void);
875 virtual int Update(void);
876 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
877 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
878
879protected:
880 virtual int GetSelection(int x, int y);
881
882protected:
883 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200884 {
885 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400886 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200887 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400888 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200889 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600890 struct capslock_tracking_struct
891 {
892 int capslock;
893 int set_capslock;
894 int revert_layout;
895 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400896
897 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
898 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600899 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400900 bool mRendered;
901 std::string mVariable;
902 unsigned int cursorLocation;
903 unsigned int currentLayout;
904 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
905 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600906 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400907 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400908 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600909 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400910};
911
912// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100913class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400914{
915public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200916 // w and h may be ignored, in which case, no bounding box is applied
917 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400918 virtual ~GUIInput();
919
920public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200921 // Render - Render the full object to the GL surface
922 // Return 0 on success, <0 on error
923 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400924
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200925 // Update - Update any UI component animations (called <= 30 FPS)
926 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
927 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400928
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200929 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100930 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400931
932 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200933 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
934 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400935
936 virtual int NotifyKeyboard(int key);
937
938protected:
939 virtual int GetSelection(int x, int y);
940
941 // Handles displaying the text properly when chars are added, deleted, or for scrolling
942 virtual int HandleTextLocation(int x);
943
944protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200945 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400946 GUIAction* mAction;
947 Resource* mBackground;
948 Resource* mCursor;
949 Resource* mFont;
950 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200951 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400952 std::string mVariable;
953 std::string mMask;
954 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200955 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400956 COLOR mCursorColor;
957 int scrollingX;
958 int lastX;
959 int mCursorLocation;
960 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
961 int mFontY;
962 unsigned skipChars;
963 unsigned mFontHeight;
964 unsigned CursorWidth;
965 bool mRendered;
966 bool HasMask;
967 bool DrawCursor;
968 bool isLocalChange;
969 bool HasAllowed;
970 bool HasDisabled;
971 std::string AllowedList;
972 std::string DisabledList;
973 unsigned MinLen;
974 unsigned MaxLen;
975};
976
977class HardwareKeyboard
978{
979public:
980 HardwareKeyboard(void);
981 virtual ~HardwareKeyboard();
982
983public:
984 virtual int KeyDown(int key_code);
985 virtual int KeyUp(int key_code);
986 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100987
988 void ConsumeKeyRelease(int key);
989
990private:
991 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400992};
993
Vojtech Bocekede51c52014-02-07 23:58:09 +0100994class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200995{
996public:
997 GUISliderValue(xml_node<>* node);
998 virtual ~GUISliderValue();
999
1000public:
1001 // Render - Render the full object to the GL surface
1002 // Return 0 on success, <0 on error
1003 virtual int Render(void);
1004
1005 // Update - Update any UI component animations (called <= 30 FPS)
1006 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1007 virtual int Update(void);
1008
1009 // SetPos - Update the position of the render object
1010 // Return 0 on success, <0 on error
1011 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1012
1013 // NotifyTouch - Notify of a touch event
1014 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1015 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1016
1017 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001018 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001019
1020 // SetPageFocus - Notify when a page gains or loses focus
1021 virtual void SetPageFocus(int inFocus);
1022
1023protected:
1024 int measureText(const std::string& str);
1025 int valueFromPct(float pct);
1026 float pctFromValue(int value);
1027 void loadValue(bool force = false);
1028
1029 std::string mVariable;
1030 int mMax;
1031 int mMin;
1032 int mValue;
1033 char *mValueStr;
1034 float mValuePct;
1035 std::string mMaxStr;
1036 std::string mMinStr;
1037 Resource *mFont;
1038 GUIText* mLabel;
1039 int mLabelW;
1040 COLOR mTextColor;
1041 COLOR mLineColor;
1042 COLOR mSliderColor;
1043 bool mShowRange;
1044 bool mShowCurr;
1045 int mLineX;
1046 int mLineY;
1047 int mLineH;
1048 int mLinePadding;
1049 int mPadding;
1050 int mSliderY;
1051 int mSliderW;
1052 int mSliderH;
1053 bool mRendered;
1054 int mFontHeight;
1055 GUIAction *mAction;
1056 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001057 int mLineW;
1058 bool mDragging;
1059 Resource *mBackgroundImage;
1060 Resource *mHandleImage;
1061 Resource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001062};
1063
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001064class MouseCursor : public RenderObject
1065{
1066public:
1067 MouseCursor(int posX, int posY);
1068 virtual ~MouseCursor();
1069
1070 virtual int Render(void);
1071 virtual int Update(void);
1072 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1073
1074 void Move(int deltaX, int deltaY);
1075 void GetPos(int& x, int& y);
1076 void LoadData(xml_node<>* node);
1077 void ResetData(int resX, int resY);
1078
1079private:
1080 int m_resX;
1081 int m_resY;
1082 bool m_moved;
1083 float m_speedMultiplier;
1084 COLOR m_color;
1085 Resource *m_image;
1086 bool m_present;
1087};
1088
Dees_Troy51a0e822012-09-05 15:24:24 -04001089// Helper APIs
1090bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1091
1092#endif // _OBJECTS_HEADER
1093