blob: 124c9264d0d1dae42347c89a8d4bb8fce8c077d7 [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);
Ethan Yonker24e7eb72015-01-03 16:13:06 -0600291 static void* openrecoveryscript_thread_fn(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000292 time_t Start;
that3f7b1ac2014-12-30 11:30:13 +0100293
294 // map action name to function pointer
295 typedef int (GUIAction::*execFunction)(std::string);
296 typedef std::map<std::string, execFunction> mapFunc;
297 static mapFunc mf;
298
299 // GUI actions
300 int reboot(std::string arg);
301 int home(std::string arg);
302 int key(std::string arg);
303 int page(std::string arg);
304 int reload(std::string arg);
305 int readBackup(std::string arg);
306 int set(std::string arg);
307 int clear(std::string arg);
308 int mount(std::string arg);
309 int unmount(std::string arg);
310 int restoredefaultsettings(std::string arg);
311 int copylog(std::string arg);
312 int compute(std::string arg);
313 int setguitimezone(std::string arg);
314 int overlay(std::string arg);
315 int queuezip(std::string arg);
316 int cancelzip(std::string arg);
317 int queueclear(std::string arg);
318 int sleep(std::string arg);
319 int appenddatetobackupname(std::string arg);
320 int generatebackupname(std::string arg);
321 int checkpartitionlist(std::string arg);
322 int getpartitiondetails(std::string arg);
323 int screenshot(std::string arg);
324 int setbrightness(std::string arg);
325
326 // threaded actions
327 int fileexists(std::string arg);
328 int flash(std::string arg);
329 int wipe(std::string arg);
330 int refreshsizes(std::string arg);
331 int nandroid(std::string arg);
332 int fixpermissions(std::string arg);
333 int dd(std::string arg);
334 int partitionsd(std::string arg);
335 int installhtcdumlock(std::string arg);
336 int htcdumlockrestoreboot(std::string arg);
337 int htcdumlockreflashrecovery(std::string arg);
338 int cmd(std::string arg);
339 int terminalcommand(std::string arg);
340 int killterminal(std::string arg);
341 int reinjecttwrp(std::string arg);
342 int checkbackupname(std::string arg);
343 int decrypt(std::string arg);
344 int adbsideload(std::string arg);
345 int adbsideloadcancel(std::string arg);
346 int openrecoveryscript(std::string arg);
347 int installsu(std::string arg);
348 int fixsu(std::string arg);
349 int decrypt_backup(std::string arg);
350 int repair(std::string arg);
351 int changefilesystem(std::string arg);
352 int startmtp(std::string arg);
353 int stopmtp(std::string arg);
354
355 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400356};
357
Vojtech Bocekede51c52014-02-07 23:58:09 +0100358class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400359{
360public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200361 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400362
363public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200364 // Render - Render the full object to the GL surface
365 // Return 0 on success, <0 on error
366 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400367
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200368 // Update - Update any UI component animations (called <= 30 FPS)
369 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
370 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400371
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200372 // SetRenderPos - Update the position of the object
373 // Return 0 on success, <0 on error
374 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400375
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200376 // IsInRegion - Checks if the request is handled by this object
377 // Return 0 if this object handles the request, 1 if not
378 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400379
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200380 // NotifyTouch - Notify of a touch event
381 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
382 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400383
384protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200385 enum SlideoutState
386 {
387 hidden = 0,
388 visible,
389 request_hide,
390 request_show
391 };
392
393 Resource* mFont;
394 Resource* mSlideoutImage;
395 COLOR mForegroundColor;
396 COLOR mBackgroundColor;
397 COLOR mScrollColor;
398 unsigned int mFontHeight;
399 int mCurrentLine;
400 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000401 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200402 unsigned int mMaxRows;
403 int mStartY;
404 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
405 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
406 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
407 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200408 int mSlideout;
409 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000410 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500411 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000412 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400413
414protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200415 virtual int RenderSlideout(void);
416 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400417};
418
Vojtech Bocekede51c52014-02-07 23:58:09 +0100419class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400420{
421public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200422 GUIButton(xml_node<>* node);
423 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400424
425public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200426 // Render - Render the full object to the GL surface
427 // Return 0 on success, <0 on error
428 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400429
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200430 // Update - Update any UI component animations (called <= 30 FPS)
431 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
432 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400433
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200434 // SetPos - Update the position of the render object
435 // Return 0 on success, <0 on error
436 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400437
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200438 // NotifyTouch - Notify of a touch event
439 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
440 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400441
442protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200443 GUIImage* mButtonImg;
444 Resource* mButtonIcon;
445 GUIText* mButtonLabel;
446 GUIAction* mAction;
447 int mTextX, mTextY, mTextW, mTextH;
448 int mIconX, mIconY, mIconW, mIconH;
449 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600450 bool hasHighlightColor;
451 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500452 bool hasFill;
453 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600454 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000455 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400456};
457
Vojtech Bocekede51c52014-02-07 23:58:09 +0100458class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400459{
460public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200461 GUICheckbox(xml_node<>* node);
462 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400463
464public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200465 // Render - Render the full object to the GL surface
466 // Return 0 on success, <0 on error
467 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400468
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200469 // Update - Update any UI component animations (called <= 30 FPS)
470 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
471 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400472
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200473 // SetPos - Update the position of the render object
474 // Return 0 on success, <0 on error
475 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400476
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200477 // NotifyTouch - Notify of a touch event
478 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
479 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400480
481protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200482 Resource* mChecked;
483 Resource* mUnchecked;
484 GUIText* mLabel;
485 int mTextX, mTextY;
486 int mCheckX, mCheckY, mCheckW, mCheckH;
487 int mLastState;
488 bool mRendered;
489 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400490};
491
Vojtech Bocekede51c52014-02-07 23:58:09 +0100492class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400493{
494public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200495 GUIFileSelector(xml_node<>* node);
496 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400497
498public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200499 // Render - Render the full object to the GL surface
500 // Return 0 on success, <0 on error
501 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400502
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200503 // Update - Update any UI component animations (called <= 30 FPS)
504 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
505 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400506
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200507 // NotifyTouch - Notify of a touch event
508 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
509 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400510
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200511 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100512 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400513
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200514 // SetPos - Update the position of the render object
515 // Return 0 on success, <0 on error
516 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400517
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200518 // SetPageFocus - Notify when a page gains or loses focus
519 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400520
521protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200522 struct FileData {
523 std::string fileName;
524 unsigned char fileType; // Uses d_type format from struct dirent
525 mode_t protection; // Uses mode_t format from stat
526 uid_t userId;
527 gid_t groupId;
528 off_t fileSize;
529 time_t lastAccess; // Uses time_t format from stat
530 time_t lastModified; // Uses time_t format from stat
531 time_t lastStatChange; // Uses time_t format from stat
532 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400533
534protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200535 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400536
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200537 virtual int GetFileList(const std::string folder);
538 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400539
540protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200541 std::vector<FileData> mFolderList;
542 std::vector<FileData> mFileList;
543 std::string mPathVar;
544 std::string mExtn;
545 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400546 std::string mSortVariable;
547 std::string mSelection;
548 std::string mHeaderText;
549 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200550 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400551 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200552 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400553 int mSeparatorH;
554 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200555 int mShowFolders, mShowFiles, mShowNavFolders;
556 int mUpdate;
557 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400558 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100559 int mFastScrollW;
560 int mFastScrollLineW;
561 int mFastScrollRectW;
562 int mFastScrollRectH;
563 int mFastScrollRectX;
564 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400565 static int mSortOrder;
566 int startY;
567 int scrollingSpeed;
568 int scrollingY;
569 int mHeaderIsStatic;
570 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200571 unsigned mFontHeight;
572 unsigned mLineHeight;
573 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
574 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400575 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200576 Resource* mFileIcon;
577 Resource* mBackground;
578 Resource* mFont;
579 COLOR mBackgroundColor;
580 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400581 COLOR mHeaderBackgroundColor;
582 COLOR mHeaderFontColor;
583 COLOR mSeparatorColor;
584 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100585 COLOR mFastScrollLineColor;
586 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600587 bool hasHighlightColor;
588 bool hasFontHighlightColor;
589 bool isHighlighted;
590 COLOR mHighlightColor;
591 COLOR mFontHighlightColor;
592 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600593 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400594};
595
Vojtech Bocekede51c52014-02-07 23:58:09 +0100596class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400597{
598public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200599 GUIListBox(xml_node<>* node);
600 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400601
602public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200603 // Render - Render the full object to the GL surface
604 // Return 0 on success, <0 on error
605 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400606
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200607 // Update - Update any UI component animations (called <= 30 FPS)
608 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
609 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400610
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200611 // NotifyTouch - Notify of a touch event
612 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
613 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400614
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200615 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100616 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400617
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200618 // SetPos - Update the position of the render object
619 // Return 0 on success, <0 on error
620 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400621
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200622 // SetPageFocus - Notify when a page gains or loses focus
623 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400624
625protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200626 struct ListData {
627 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400628 std::string variableValue;
629 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200630 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400631
632protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200633 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400634
635protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200636 std::vector<ListData> mList;
637 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400638 std::string mSelection;
639 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600640 std::string mHeaderText;
641 std::string mLastValue;
642 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200643 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600644 int startY;
645 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200646 int mLineSpacing;
647 int mUpdate;
648 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000649 int mFastScrollW;
650 int mFastScrollLineW;
651 int mFastScrollRectW;
652 int mFastScrollRectH;
653 int mFastScrollRectX;
654 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600655 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
656 int scrollingSpeed;
657 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400658 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200659 unsigned mFontHeight;
660 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600661 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200662 Resource* mIconSelected;
663 Resource* mIconUnselected;
664 Resource* mBackground;
665 Resource* mFont;
666 COLOR mBackgroundColor;
667 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600668 COLOR mHeaderBackgroundColor;
669 COLOR mHeaderFontColor;
670 COLOR mSeparatorColor;
671 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000672 COLOR mFastScrollLineColor;
673 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600674 bool hasHighlightColor;
675 bool hasFontHighlightColor;
676 bool isHighlighted;
677 COLOR mHighlightColor;
678 COLOR mFontHighlightColor;
679 int mHeaderIsStatic;
680 int startSelection;
681 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400682};
683
Vojtech Bocekede51c52014-02-07 23:58:09 +0100684class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500685{
686public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200687 GUIPartitionList(xml_node<>* node);
688 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500689
690public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200691 // Render - Render the full object to the GL surface
692 // Return 0 on success, <0 on error
693 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500694
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200695 // Update - Update any UI component animations (called <= 30 FPS)
696 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
697 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500698
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200699 // NotifyTouch - Notify of a touch event
700 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
701 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500702
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200703 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100704 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500705
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200706 // SetPos - Update the position of the render object
707 // Return 0 on success, <0 on error
708 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500709
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200710 // SetPageFocus - Notify when a page gains or loses focus
711 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500712
713protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200714 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500715 virtual void MatchList(void);
716
717protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200718 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500719 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200720 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500721 std::string selectedList;
722 std::string currentValue;
723 std::string mHeaderText;
724 std::string mLastValue;
725 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200726 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500727 int startY;
728 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200729 int mLineSpacing;
730 int mUpdate;
731 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500732 int mFastScrollW;
733 int mFastScrollLineW;
734 int mFastScrollRectW;
735 int mFastScrollRectH;
736 int mFastScrollRectX;
737 int mFastScrollRectY;
738 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
739 int scrollingSpeed;
740 int scrollingY;
741 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200742 unsigned mFontHeight;
743 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500744 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200745 Resource* mIconSelected;
746 Resource* mIconUnselected;
747 Resource* mBackground;
748 Resource* mFont;
749 COLOR mBackgroundColor;
750 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500751 COLOR mHeaderBackgroundColor;
752 COLOR mHeaderFontColor;
753 COLOR mSeparatorColor;
754 COLOR mHeaderSeparatorColor;
755 COLOR mFastScrollLineColor;
756 COLOR mFastScrollRectColor;
757 bool hasHighlightColor;
758 bool hasFontHighlightColor;
759 bool isHighlighted;
760 COLOR mHighlightColor;
761 COLOR mFontHighlightColor;
762 int mHeaderIsStatic;
763 int startSelection;
764 int touchDebounce;
765 bool updateList;
766};
767
Dees_Troy51a0e822012-09-05 15:24:24 -0400768// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100769class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400770{
771public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200772 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400773
774public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200775 // Render - Render the full object to the GL surface
776 // Return 0 on success, <0 on error
777 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400778
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200779 // Update - Update any UI component animations (called <= 30 FPS)
780 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
781 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400782
783protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200784 AnimationResource* mAnimation;
785 int mFrame;
786 int mFPS;
787 int mLoop;
788 int mRender;
789 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400790};
791
Vojtech Bocekede51c52014-02-07 23:58:09 +0100792class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400793{
794public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200795 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400796
797public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200798 // Render - Render the full object to the GL surface
799 // Return 0 on success, <0 on error
800 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400801
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200802 // Update - Update any UI component animations (called <= 30 FPS)
803 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
804 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400805
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200806 // NotifyVarChange - Notify of a variable change
807 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100808 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400809
810protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200811 Resource* mEmptyBar;
812 Resource* mFullBar;
813 std::string mMinValVar;
814 std::string mMaxValVar;
815 std::string mCurValVar;
816 float mSlide;
817 float mSlideInc;
818 int mSlideFrames;
819 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400820
821protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200822 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400823};
824
Vojtech Bocekede51c52014-02-07 23:58:09 +0100825class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400826{
827public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200828 GUISlider(xml_node<>* node);
829 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400830
831public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200832 // Render - Render the full object to the GL surface
833 // Return 0 on success, <0 on error
834 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400835
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200836 // Update - Update any UI component animations (called <= 30 FPS)
837 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
838 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400839
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200840 // NotifyTouch - Notify of a touch event
841 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
842 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400843
844protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200845 GUIAction* sAction;
846 Resource* sSlider;
847 Resource* sSliderUsed;
848 Resource* sTouch;
849 int sTouchW, sTouchH;
850 int sCurTouchX;
851 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400852};
853
854#define MAX_KEYBOARD_LAYOUTS 5
855#define MAX_KEYBOARD_ROWS 9
856#define MAX_KEYBOARD_KEYS 20
857#define KEYBOARD_ACTION 253
858#define KEYBOARD_LAYOUT 254
859#define KEYBOARD_SWIPE_LEFT 252
860#define KEYBOARD_SWIPE_RIGHT 251
861#define KEYBOARD_ARROW_LEFT 250
862#define KEYBOARD_ARROW_RIGHT 249
863#define KEYBOARD_HOME 248
864#define KEYBOARD_END 247
865#define KEYBOARD_ARROW_UP 246
866#define KEYBOARD_ARROW_DOWN 245
867#define KEYBOARD_SPECIAL_KEYS 245
868#define KEYBOARD_BACKSPACE 8
869
Vojtech Bocekede51c52014-02-07 23:58:09 +0100870class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400871{
872public:
873 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200874 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400875
876public:
877 virtual int Render(void);
878 virtual int Update(void);
879 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
880 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
881
882protected:
883 virtual int GetSelection(int x, int y);
884
885protected:
886 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200887 {
888 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400889 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200890 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400891 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200892 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600893 struct capslock_tracking_struct
894 {
895 int capslock;
896 int set_capslock;
897 int revert_layout;
898 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400899
900 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
901 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600902 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400903 bool mRendered;
904 std::string mVariable;
905 unsigned int cursorLocation;
906 unsigned int currentLayout;
907 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
908 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600909 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400910 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400911 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600912 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400913};
914
915// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100916class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400917{
918public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200919 // w and h may be ignored, in which case, no bounding box is applied
920 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400921 virtual ~GUIInput();
922
923public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200924 // Render - Render the full object to the GL surface
925 // Return 0 on success, <0 on error
926 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400927
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200928 // Update - Update any UI component animations (called <= 30 FPS)
929 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
930 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400931
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200932 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100933 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400934
935 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200936 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
937 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400938
939 virtual int NotifyKeyboard(int key);
940
941protected:
942 virtual int GetSelection(int x, int y);
943
944 // Handles displaying the text properly when chars are added, deleted, or for scrolling
945 virtual int HandleTextLocation(int x);
946
947protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200948 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400949 GUIAction* mAction;
950 Resource* mBackground;
951 Resource* mCursor;
952 Resource* mFont;
953 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200954 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400955 std::string mVariable;
956 std::string mMask;
957 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200958 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400959 COLOR mCursorColor;
960 int scrollingX;
961 int lastX;
962 int mCursorLocation;
963 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
964 int mFontY;
965 unsigned skipChars;
966 unsigned mFontHeight;
967 unsigned CursorWidth;
968 bool mRendered;
969 bool HasMask;
970 bool DrawCursor;
971 bool isLocalChange;
972 bool HasAllowed;
973 bool HasDisabled;
974 std::string AllowedList;
975 std::string DisabledList;
976 unsigned MinLen;
977 unsigned MaxLen;
978};
979
980class HardwareKeyboard
981{
982public:
983 HardwareKeyboard(void);
984 virtual ~HardwareKeyboard();
985
986public:
987 virtual int KeyDown(int key_code);
988 virtual int KeyUp(int key_code);
989 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100990
991 void ConsumeKeyRelease(int key);
992
993private:
994 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400995};
996
Vojtech Bocekede51c52014-02-07 23:58:09 +0100997class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200998{
999public:
1000 GUISliderValue(xml_node<>* node);
1001 virtual ~GUISliderValue();
1002
1003public:
1004 // Render - Render the full object to the GL surface
1005 // Return 0 on success, <0 on error
1006 virtual int Render(void);
1007
1008 // Update - Update any UI component animations (called <= 30 FPS)
1009 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1010 virtual int Update(void);
1011
1012 // SetPos - Update the position of the render object
1013 // Return 0 on success, <0 on error
1014 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1015
1016 // NotifyTouch - Notify of a touch event
1017 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1018 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1019
1020 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001021 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001022
1023 // SetPageFocus - Notify when a page gains or loses focus
1024 virtual void SetPageFocus(int inFocus);
1025
1026protected:
1027 int measureText(const std::string& str);
1028 int valueFromPct(float pct);
1029 float pctFromValue(int value);
1030 void loadValue(bool force = false);
1031
1032 std::string mVariable;
1033 int mMax;
1034 int mMin;
1035 int mValue;
1036 char *mValueStr;
1037 float mValuePct;
1038 std::string mMaxStr;
1039 std::string mMinStr;
1040 Resource *mFont;
1041 GUIText* mLabel;
1042 int mLabelW;
1043 COLOR mTextColor;
1044 COLOR mLineColor;
1045 COLOR mSliderColor;
1046 bool mShowRange;
1047 bool mShowCurr;
1048 int mLineX;
1049 int mLineY;
1050 int mLineH;
1051 int mLinePadding;
1052 int mPadding;
1053 int mSliderY;
1054 int mSliderW;
1055 int mSliderH;
1056 bool mRendered;
1057 int mFontHeight;
1058 GUIAction *mAction;
1059 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001060 int mLineW;
1061 bool mDragging;
1062 Resource *mBackgroundImage;
1063 Resource *mHandleImage;
1064 Resource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001065};
1066
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001067class MouseCursor : public RenderObject
1068{
1069public:
1070 MouseCursor(int posX, int posY);
1071 virtual ~MouseCursor();
1072
1073 virtual int Render(void);
1074 virtual int Update(void);
1075 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1076
1077 void Move(int deltaX, int deltaY);
1078 void GetPos(int& x, int& y);
1079 void LoadData(xml_node<>* node);
1080 void ResetData(int resX, int resY);
1081
1082private:
1083 int m_resX;
1084 int m_resY;
1085 bool m_moved;
1086 float m_speedMultiplier;
1087 COLOR m_color;
1088 Resource *m_image;
1089 bool m_present;
1090};
1091
Dees_Troy51a0e822012-09-05 15:24:24 -04001092// Helper APIs
1093bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1094
1095#endif // _OBJECTS_HEADER
1096