blob: a89f4868045cc9c109769a5b04985123bd57a183 [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{
thatc6085482015-01-09 22:12:43 +0100260 friend class ActionThread;
261
Dees_Troy51a0e822012-09-05 15:24:24 -0400262public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200263 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400264
265public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200266 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100267 virtual int NotifyKey(int key, bool down);
Vojtech Bocek07220562014-02-08 02:05:33 +0100268 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
that3f7b1ac2014-12-30 11:30:13 +0100269
270 int doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400271
272protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200273 class Action
274 {
275 public:
276 std::string mFunction;
277 std::string mArg;
278 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400279
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200280 std::vector<Action> mActions;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100281 std::map<int, bool> mKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400282
283protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200284 int getKeyByName(std::string key);
that3f7b1ac2014-12-30 11:30:13 +0100285 int doAction(Action action);
thatc6085482015-01-09 22:12:43 +0100286 bool needsToRunInSeparateThread(const Action& action);
Dees_Troy51a0e822012-09-05 15:24:24 -0400287 void simulate_progress_bar(void);
Ethan Yonker0d47eb52015-01-09 11:23:19 -0600288 int flash_zip(std::string filename, int* wipe_cache);
thatcc8ddca2015-01-03 01:59:36 +0100289 void reinject_after_flash();
Dees_Troy51a0e822012-09-05 15:24:24 -0400290 void operation_start(const string operation_name);
that3f7b1ac2014-12-30 11:30:13 +0100291 void operation_end(const int operation_status);
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;
thatc6085482015-01-09 22:12:43 +0100298 static std::set<std::string> setActionsRunningInCallerThread;
that3f7b1ac2014-12-30 11:30:13 +0100299
300 // GUI actions
301 int reboot(std::string arg);
302 int home(std::string arg);
303 int key(std::string arg);
304 int page(std::string arg);
305 int reload(std::string arg);
306 int readBackup(std::string arg);
307 int set(std::string arg);
308 int clear(std::string arg);
309 int mount(std::string arg);
310 int unmount(std::string arg);
311 int restoredefaultsettings(std::string arg);
312 int copylog(std::string arg);
313 int compute(std::string arg);
314 int setguitimezone(std::string arg);
315 int overlay(std::string arg);
316 int queuezip(std::string arg);
317 int cancelzip(std::string arg);
318 int queueclear(std::string arg);
319 int sleep(std::string arg);
320 int appenddatetobackupname(std::string arg);
321 int generatebackupname(std::string arg);
322 int checkpartitionlist(std::string arg);
323 int getpartitiondetails(std::string arg);
324 int screenshot(std::string arg);
325 int setbrightness(std::string arg);
326
thatc6085482015-01-09 22:12:43 +0100327 // (originally) threaded actions
that3f7b1ac2014-12-30 11:30:13 +0100328 int fileexists(std::string arg);
329 int flash(std::string arg);
330 int wipe(std::string arg);
331 int refreshsizes(std::string arg);
332 int nandroid(std::string arg);
333 int fixpermissions(std::string arg);
334 int dd(std::string arg);
335 int partitionsd(std::string arg);
336 int installhtcdumlock(std::string arg);
337 int htcdumlockrestoreboot(std::string arg);
338 int htcdumlockreflashrecovery(std::string arg);
339 int cmd(std::string arg);
340 int terminalcommand(std::string arg);
341 int killterminal(std::string arg);
342 int reinjecttwrp(std::string arg);
343 int checkbackupname(std::string arg);
344 int decrypt(std::string arg);
345 int adbsideload(std::string arg);
346 int adbsideloadcancel(std::string arg);
347 int openrecoveryscript(std::string arg);
348 int installsu(std::string arg);
349 int fixsu(std::string arg);
350 int decrypt_backup(std::string arg);
351 int repair(std::string arg);
352 int changefilesystem(std::string arg);
353 int startmtp(std::string arg);
354 int stopmtp(std::string arg);
Ethan Yonker96af84a2015-01-05 14:58:36 -0600355 int flashimage(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100356
357 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400358};
359
thatc6085482015-01-09 22:12:43 +0100360class ActionThread
361{
362public:
363 ActionThread();
364 ~ActionThread();
365
that7d3b54f2015-01-09 22:52:51 +0100366 void threadActions(GUIAction *act);
thatc6085482015-01-09 22:12:43 +0100367 void run(void *data);
368private:
369 struct ThreadData
370 {
371 GUIAction *act;
thatc6085482015-01-09 22:12:43 +0100372 };
373
374 pthread_t m_thread;
375 bool m_thread_running;
376 pthread_mutex_t m_act_lock;
377};
378
Vojtech Bocekede51c52014-02-07 23:58:09 +0100379class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400380{
381public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200382 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400383
384public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200385 // Render - Render the full object to the GL surface
386 // Return 0 on success, <0 on error
387 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400388
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200389 // Update - Update any UI component animations (called <= 30 FPS)
390 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
391 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400392
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200393 // SetRenderPos - Update the position of the object
394 // Return 0 on success, <0 on error
395 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400396
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200397 // IsInRegion - Checks if the request is handled by this object
398 // Return 0 if this object handles the request, 1 if not
399 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400400
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200401 // NotifyTouch - Notify of a touch event
402 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
403 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400404
405protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200406 enum SlideoutState
407 {
408 hidden = 0,
409 visible,
410 request_hide,
411 request_show
412 };
413
414 Resource* mFont;
415 Resource* mSlideoutImage;
416 COLOR mForegroundColor;
417 COLOR mBackgroundColor;
418 COLOR mScrollColor;
419 unsigned int mFontHeight;
420 int mCurrentLine;
421 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000422 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200423 unsigned int mMaxRows;
424 int mStartY;
425 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
426 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
427 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
428 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200429 int mSlideout;
430 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000431 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500432 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000433 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400434
435protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200436 virtual int RenderSlideout(void);
437 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400438};
439
Vojtech Bocekede51c52014-02-07 23:58:09 +0100440class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400441{
442public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200443 GUIButton(xml_node<>* node);
444 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400445
446public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200447 // Render - Render the full object to the GL surface
448 // Return 0 on success, <0 on error
449 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400450
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200451 // Update - Update any UI component animations (called <= 30 FPS)
452 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
453 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400454
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200455 // SetPos - Update the position of the render object
456 // Return 0 on success, <0 on error
457 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400458
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200459 // NotifyTouch - Notify of a touch event
460 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
461 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400462
463protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200464 GUIImage* mButtonImg;
465 Resource* mButtonIcon;
466 GUIText* mButtonLabel;
467 GUIAction* mAction;
468 int mTextX, mTextY, mTextW, mTextH;
469 int mIconX, mIconY, mIconW, mIconH;
470 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600471 bool hasHighlightColor;
472 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500473 bool hasFill;
474 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600475 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000476 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400477};
478
Vojtech Bocekede51c52014-02-07 23:58:09 +0100479class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400480{
481public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200482 GUICheckbox(xml_node<>* node);
483 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400484
485public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200486 // Render - Render the full object to the GL surface
487 // Return 0 on success, <0 on error
488 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400489
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200490 // Update - Update any UI component animations (called <= 30 FPS)
491 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
492 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400493
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200494 // SetPos - Update the position of the render object
495 // Return 0 on success, <0 on error
496 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400497
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200498 // NotifyTouch - Notify of a touch event
499 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
500 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400501
502protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200503 Resource* mChecked;
504 Resource* mUnchecked;
505 GUIText* mLabel;
506 int mTextX, mTextY;
507 int mCheckX, mCheckY, mCheckW, mCheckH;
508 int mLastState;
509 bool mRendered;
510 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400511};
512
Vojtech Bocekede51c52014-02-07 23:58:09 +0100513class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400514{
515public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200516 GUIFileSelector(xml_node<>* node);
517 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400518
519public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200520 // Render - Render the full object to the GL surface
521 // Return 0 on success, <0 on error
522 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400523
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200524 // Update - Update any UI component animations (called <= 30 FPS)
525 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
526 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400527
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200528 // NotifyTouch - Notify of a touch event
529 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
530 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400531
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200532 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100533 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400534
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200535 // SetPos - Update the position of the render object
536 // Return 0 on success, <0 on error
537 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400538
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200539 // SetPageFocus - Notify when a page gains or loses focus
540 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400541
542protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200543 struct FileData {
544 std::string fileName;
545 unsigned char fileType; // Uses d_type format from struct dirent
546 mode_t protection; // Uses mode_t format from stat
547 uid_t userId;
548 gid_t groupId;
549 off_t fileSize;
550 time_t lastAccess; // Uses time_t format from stat
551 time_t lastModified; // Uses time_t format from stat
552 time_t lastStatChange; // Uses time_t format from stat
553 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400554
555protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200556 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400557
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200558 virtual int GetFileList(const std::string folder);
559 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400560
561protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200562 std::vector<FileData> mFolderList;
563 std::vector<FileData> mFileList;
564 std::string mPathVar;
565 std::string mExtn;
566 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400567 std::string mSortVariable;
568 std::string mSelection;
569 std::string mHeaderText;
570 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200571 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400572 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200573 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400574 int mSeparatorH;
575 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200576 int mShowFolders, mShowFiles, mShowNavFolders;
577 int mUpdate;
578 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400579 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100580 int mFastScrollW;
581 int mFastScrollLineW;
582 int mFastScrollRectW;
583 int mFastScrollRectH;
584 int mFastScrollRectX;
585 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400586 static int mSortOrder;
587 int startY;
588 int scrollingSpeed;
589 int scrollingY;
590 int mHeaderIsStatic;
591 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200592 unsigned mFontHeight;
593 unsigned mLineHeight;
594 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
595 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400596 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200597 Resource* mFileIcon;
598 Resource* mBackground;
599 Resource* mFont;
600 COLOR mBackgroundColor;
601 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400602 COLOR mHeaderBackgroundColor;
603 COLOR mHeaderFontColor;
604 COLOR mSeparatorColor;
605 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100606 COLOR mFastScrollLineColor;
607 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600608 bool hasHighlightColor;
609 bool hasFontHighlightColor;
610 bool isHighlighted;
611 COLOR mHighlightColor;
612 COLOR mFontHighlightColor;
613 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600614 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400615};
616
Vojtech Bocekede51c52014-02-07 23:58:09 +0100617class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400618{
619public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200620 GUIListBox(xml_node<>* node);
621 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400622
623public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200624 // Render - Render the full object to the GL surface
625 // Return 0 on success, <0 on error
626 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400627
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200628 // Update - Update any UI component animations (called <= 30 FPS)
629 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
630 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400631
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200632 // NotifyTouch - Notify of a touch event
633 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
634 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400635
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200636 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100637 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400638
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200639 // SetPos - Update the position of the render object
640 // Return 0 on success, <0 on error
641 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400642
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200643 // SetPageFocus - Notify when a page gains or loses focus
644 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400645
646protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200647 struct ListData {
648 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400649 std::string variableValue;
650 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200651 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400652
653protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200654 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400655
656protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200657 std::vector<ListData> mList;
658 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400659 std::string mSelection;
660 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600661 std::string mHeaderText;
662 std::string mLastValue;
663 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200664 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600665 int startY;
666 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200667 int mLineSpacing;
668 int mUpdate;
669 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000670 int mFastScrollW;
671 int mFastScrollLineW;
672 int mFastScrollRectW;
673 int mFastScrollRectH;
674 int mFastScrollRectX;
675 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600676 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
677 int scrollingSpeed;
678 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400679 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200680 unsigned mFontHeight;
681 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600682 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200683 Resource* mIconSelected;
684 Resource* mIconUnselected;
685 Resource* mBackground;
686 Resource* mFont;
687 COLOR mBackgroundColor;
688 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600689 COLOR mHeaderBackgroundColor;
690 COLOR mHeaderFontColor;
691 COLOR mSeparatorColor;
692 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000693 COLOR mFastScrollLineColor;
694 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600695 bool hasHighlightColor;
696 bool hasFontHighlightColor;
697 bool isHighlighted;
698 COLOR mHighlightColor;
699 COLOR mFontHighlightColor;
700 int mHeaderIsStatic;
701 int startSelection;
702 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400703};
704
Vojtech Bocekede51c52014-02-07 23:58:09 +0100705class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500706{
707public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200708 GUIPartitionList(xml_node<>* node);
709 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500710
711public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200712 // Render - Render the full object to the GL surface
713 // Return 0 on success, <0 on error
714 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500715
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200716 // Update - Update any UI component animations (called <= 30 FPS)
717 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
718 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500719
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200720 // NotifyTouch - Notify of a touch event
721 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
722 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500723
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200724 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100725 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500726
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200727 // SetPos - Update the position of the render object
728 // Return 0 on success, <0 on error
729 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500730
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200731 // SetPageFocus - Notify when a page gains or loses focus
732 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500733
734protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200735 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500736 virtual void MatchList(void);
737
738protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200739 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500740 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200741 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500742 std::string selectedList;
743 std::string currentValue;
744 std::string mHeaderText;
745 std::string mLastValue;
746 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200747 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500748 int startY;
749 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200750 int mLineSpacing;
751 int mUpdate;
752 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500753 int mFastScrollW;
754 int mFastScrollLineW;
755 int mFastScrollRectW;
756 int mFastScrollRectH;
757 int mFastScrollRectX;
758 int mFastScrollRectY;
759 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
760 int scrollingSpeed;
761 int scrollingY;
762 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200763 unsigned mFontHeight;
764 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500765 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200766 Resource* mIconSelected;
767 Resource* mIconUnselected;
768 Resource* mBackground;
769 Resource* mFont;
770 COLOR mBackgroundColor;
771 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500772 COLOR mHeaderBackgroundColor;
773 COLOR mHeaderFontColor;
774 COLOR mSeparatorColor;
775 COLOR mHeaderSeparatorColor;
776 COLOR mFastScrollLineColor;
777 COLOR mFastScrollRectColor;
778 bool hasHighlightColor;
779 bool hasFontHighlightColor;
780 bool isHighlighted;
781 COLOR mHighlightColor;
782 COLOR mFontHighlightColor;
783 int mHeaderIsStatic;
784 int startSelection;
785 int touchDebounce;
786 bool updateList;
787};
788
Dees_Troy51a0e822012-09-05 15:24:24 -0400789// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100790class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400791{
792public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200793 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400794
795public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200796 // Render - Render the full object to the GL surface
797 // Return 0 on success, <0 on error
798 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400799
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200800 // Update - Update any UI component animations (called <= 30 FPS)
801 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
802 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400803
804protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200805 AnimationResource* mAnimation;
806 int mFrame;
807 int mFPS;
808 int mLoop;
809 int mRender;
810 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400811};
812
Vojtech Bocekede51c52014-02-07 23:58:09 +0100813class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400814{
815public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200816 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400817
818public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200819 // Render - Render the full object to the GL surface
820 // Return 0 on success, <0 on error
821 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400822
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200823 // Update - Update any UI component animations (called <= 30 FPS)
824 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
825 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400826
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200827 // NotifyVarChange - Notify of a variable change
828 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100829 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400830
831protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200832 Resource* mEmptyBar;
833 Resource* mFullBar;
834 std::string mMinValVar;
835 std::string mMaxValVar;
836 std::string mCurValVar;
837 float mSlide;
838 float mSlideInc;
839 int mSlideFrames;
840 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400841
842protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200843 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400844};
845
Vojtech Bocekede51c52014-02-07 23:58:09 +0100846class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400847{
848public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200849 GUISlider(xml_node<>* node);
850 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400851
852public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200853 // Render - Render the full object to the GL surface
854 // Return 0 on success, <0 on error
855 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400856
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200857 // Update - Update any UI component animations (called <= 30 FPS)
858 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
859 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400860
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200861 // NotifyTouch - Notify of a touch event
862 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
863 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400864
865protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200866 GUIAction* sAction;
867 Resource* sSlider;
868 Resource* sSliderUsed;
869 Resource* sTouch;
870 int sTouchW, sTouchH;
871 int sCurTouchX;
872 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400873};
874
875#define MAX_KEYBOARD_LAYOUTS 5
876#define MAX_KEYBOARD_ROWS 9
877#define MAX_KEYBOARD_KEYS 20
878#define KEYBOARD_ACTION 253
879#define KEYBOARD_LAYOUT 254
880#define KEYBOARD_SWIPE_LEFT 252
881#define KEYBOARD_SWIPE_RIGHT 251
882#define KEYBOARD_ARROW_LEFT 250
883#define KEYBOARD_ARROW_RIGHT 249
884#define KEYBOARD_HOME 248
885#define KEYBOARD_END 247
886#define KEYBOARD_ARROW_UP 246
887#define KEYBOARD_ARROW_DOWN 245
888#define KEYBOARD_SPECIAL_KEYS 245
889#define KEYBOARD_BACKSPACE 8
890
Vojtech Bocekede51c52014-02-07 23:58:09 +0100891class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400892{
893public:
894 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200895 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400896
897public:
898 virtual int Render(void);
899 virtual int Update(void);
900 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
901 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
902
903protected:
904 virtual int GetSelection(int x, int y);
905
906protected:
907 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200908 {
909 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400910 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200911 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400912 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200913 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600914 struct capslock_tracking_struct
915 {
916 int capslock;
917 int set_capslock;
918 int revert_layout;
919 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400920
921 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
922 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600923 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400924 bool mRendered;
925 std::string mVariable;
926 unsigned int cursorLocation;
927 unsigned int currentLayout;
928 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
929 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600930 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400931 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400932 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600933 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400934};
935
936// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100937class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400938{
939public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200940 // w and h may be ignored, in which case, no bounding box is applied
941 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400942 virtual ~GUIInput();
943
944public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200945 // Render - Render the full object to the GL surface
946 // Return 0 on success, <0 on error
947 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400948
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200949 // Update - Update any UI component animations (called <= 30 FPS)
950 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
951 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400952
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200953 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100954 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400955
956 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200957 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
958 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400959
960 virtual int NotifyKeyboard(int key);
961
962protected:
963 virtual int GetSelection(int x, int y);
964
965 // Handles displaying the text properly when chars are added, deleted, or for scrolling
966 virtual int HandleTextLocation(int x);
967
968protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200969 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400970 GUIAction* mAction;
971 Resource* mBackground;
972 Resource* mCursor;
973 Resource* mFont;
974 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200975 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400976 std::string mVariable;
977 std::string mMask;
978 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200979 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400980 COLOR mCursorColor;
981 int scrollingX;
982 int lastX;
983 int mCursorLocation;
984 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
985 int mFontY;
986 unsigned skipChars;
987 unsigned mFontHeight;
988 unsigned CursorWidth;
989 bool mRendered;
990 bool HasMask;
991 bool DrawCursor;
992 bool isLocalChange;
993 bool HasAllowed;
994 bool HasDisabled;
995 std::string AllowedList;
996 std::string DisabledList;
997 unsigned MinLen;
998 unsigned MaxLen;
999};
1000
1001class HardwareKeyboard
1002{
1003public:
1004 HardwareKeyboard(void);
1005 virtual ~HardwareKeyboard();
1006
1007public:
1008 virtual int KeyDown(int key_code);
1009 virtual int KeyUp(int key_code);
1010 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001011
1012 void ConsumeKeyRelease(int key);
1013
1014private:
1015 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -04001016};
1017
Vojtech Bocekede51c52014-02-07 23:58:09 +01001018class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +02001019{
1020public:
1021 GUISliderValue(xml_node<>* node);
1022 virtual ~GUISliderValue();
1023
1024public:
1025 // Render - Render the full object to the GL surface
1026 // Return 0 on success, <0 on error
1027 virtual int Render(void);
1028
1029 // Update - Update any UI component animations (called <= 30 FPS)
1030 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1031 virtual int Update(void);
1032
1033 // SetPos - Update the position of the render object
1034 // Return 0 on success, <0 on error
1035 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1036
1037 // NotifyTouch - Notify of a touch event
1038 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1039 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1040
1041 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001042 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001043
1044 // SetPageFocus - Notify when a page gains or loses focus
1045 virtual void SetPageFocus(int inFocus);
1046
1047protected:
1048 int measureText(const std::string& str);
1049 int valueFromPct(float pct);
1050 float pctFromValue(int value);
1051 void loadValue(bool force = false);
1052
1053 std::string mVariable;
1054 int mMax;
1055 int mMin;
1056 int mValue;
1057 char *mValueStr;
1058 float mValuePct;
1059 std::string mMaxStr;
1060 std::string mMinStr;
1061 Resource *mFont;
1062 GUIText* mLabel;
1063 int mLabelW;
1064 COLOR mTextColor;
1065 COLOR mLineColor;
1066 COLOR mSliderColor;
1067 bool mShowRange;
1068 bool mShowCurr;
1069 int mLineX;
1070 int mLineY;
1071 int mLineH;
1072 int mLinePadding;
1073 int mPadding;
1074 int mSliderY;
1075 int mSliderW;
1076 int mSliderH;
1077 bool mRendered;
1078 int mFontHeight;
1079 GUIAction *mAction;
1080 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001081 int mLineW;
1082 bool mDragging;
1083 Resource *mBackgroundImage;
1084 Resource *mHandleImage;
1085 Resource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001086};
1087
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001088class MouseCursor : public RenderObject
1089{
1090public:
1091 MouseCursor(int posX, int posY);
1092 virtual ~MouseCursor();
1093
1094 virtual int Render(void);
1095 virtual int Update(void);
1096 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1097
1098 void Move(int deltaX, int deltaY);
1099 void GetPos(int& x, int& y);
1100 void LoadData(xml_node<>* node);
1101 void ResetData(int resX, int resY);
1102
1103private:
1104 int m_resX;
1105 int m_resY;
1106 bool m_moved;
1107 float m_speedMultiplier;
1108 COLOR m_color;
1109 Resource *m_image;
1110 bool m_present;
1111};
1112
Dees_Troy51a0e822012-09-05 15:24:24 -04001113// Helper APIs
1114bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1115
1116#endif // _OBJECTS_HEADER
1117