blob: 76dbb4625891742a4a72840414f2057950eeab80 [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);
that3f7b1ac2014-12-30 11:30:13 +0100288 int flash_zip(std::string filename, std::string pageName, 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);
355
356 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400357};
358
thatc6085482015-01-09 22:12:43 +0100359class ActionThread
360{
361public:
362 ActionThread();
363 ~ActionThread();
364
that7d3b54f2015-01-09 22:52:51 +0100365 void threadActions(GUIAction *act);
thatc6085482015-01-09 22:12:43 +0100366 void run(void *data);
367private:
368 struct ThreadData
369 {
370 GUIAction *act;
thatc6085482015-01-09 22:12:43 +0100371 };
372
373 pthread_t m_thread;
374 bool m_thread_running;
375 pthread_mutex_t m_act_lock;
376};
377
Vojtech Bocekede51c52014-02-07 23:58:09 +0100378class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400379{
380public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200381 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400382
383public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200384 // Render - Render the full object to the GL surface
385 // Return 0 on success, <0 on error
386 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400387
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200388 // Update - Update any UI component animations (called <= 30 FPS)
389 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
390 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400391
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200392 // SetRenderPos - Update the position of the object
393 // Return 0 on success, <0 on error
394 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400395
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200396 // IsInRegion - Checks if the request is handled by this object
397 // Return 0 if this object handles the request, 1 if not
398 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400399
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200400 // NotifyTouch - Notify of a touch event
401 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
402 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400403
404protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200405 enum SlideoutState
406 {
407 hidden = 0,
408 visible,
409 request_hide,
410 request_show
411 };
412
413 Resource* mFont;
414 Resource* mSlideoutImage;
415 COLOR mForegroundColor;
416 COLOR mBackgroundColor;
417 COLOR mScrollColor;
418 unsigned int mFontHeight;
419 int mCurrentLine;
420 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000421 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200422 unsigned int mMaxRows;
423 int mStartY;
424 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
425 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
426 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
427 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200428 int mSlideout;
429 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000430 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500431 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000432 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400433
434protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200435 virtual int RenderSlideout(void);
436 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400437};
438
Vojtech Bocekede51c52014-02-07 23:58:09 +0100439class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400440{
441public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200442 GUIButton(xml_node<>* node);
443 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400444
445public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200446 // Render - Render the full object to the GL surface
447 // Return 0 on success, <0 on error
448 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400449
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200450 // Update - Update any UI component animations (called <= 30 FPS)
451 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
452 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400453
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200454 // SetPos - Update the position of the render object
455 // Return 0 on success, <0 on error
456 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400457
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200458 // NotifyTouch - Notify of a touch event
459 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
460 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400461
462protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200463 GUIImage* mButtonImg;
464 Resource* mButtonIcon;
465 GUIText* mButtonLabel;
466 GUIAction* mAction;
467 int mTextX, mTextY, mTextW, mTextH;
468 int mIconX, mIconY, mIconW, mIconH;
469 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600470 bool hasHighlightColor;
471 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500472 bool hasFill;
473 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600474 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000475 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400476};
477
Vojtech Bocekede51c52014-02-07 23:58:09 +0100478class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400479{
480public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200481 GUICheckbox(xml_node<>* node);
482 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400483
484public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200485 // Render - Render the full object to the GL surface
486 // Return 0 on success, <0 on error
487 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400488
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200489 // Update - Update any UI component animations (called <= 30 FPS)
490 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
491 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400492
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200493 // SetPos - Update the position of the render object
494 // Return 0 on success, <0 on error
495 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400496
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200497 // NotifyTouch - Notify of a touch event
498 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
499 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400500
501protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200502 Resource* mChecked;
503 Resource* mUnchecked;
504 GUIText* mLabel;
505 int mTextX, mTextY;
506 int mCheckX, mCheckY, mCheckW, mCheckH;
507 int mLastState;
508 bool mRendered;
509 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400510};
511
Vojtech Bocekede51c52014-02-07 23:58:09 +0100512class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400513{
514public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200515 GUIFileSelector(xml_node<>* node);
516 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400517
518public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200519 // Render - Render the full object to the GL surface
520 // Return 0 on success, <0 on error
521 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400522
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200523 // Update - Update any UI component animations (called <= 30 FPS)
524 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
525 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400526
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200527 // NotifyTouch - Notify of a touch event
528 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
529 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400530
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200531 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100532 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400533
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200534 // SetPos - Update the position of the render object
535 // Return 0 on success, <0 on error
536 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400537
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200538 // SetPageFocus - Notify when a page gains or loses focus
539 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400540
541protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200542 struct FileData {
543 std::string fileName;
544 unsigned char fileType; // Uses d_type format from struct dirent
545 mode_t protection; // Uses mode_t format from stat
546 uid_t userId;
547 gid_t groupId;
548 off_t fileSize;
549 time_t lastAccess; // Uses time_t format from stat
550 time_t lastModified; // Uses time_t format from stat
551 time_t lastStatChange; // Uses time_t format from stat
552 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400553
554protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200555 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400556
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200557 virtual int GetFileList(const std::string folder);
558 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400559
560protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200561 std::vector<FileData> mFolderList;
562 std::vector<FileData> mFileList;
563 std::string mPathVar;
564 std::string mExtn;
565 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400566 std::string mSortVariable;
567 std::string mSelection;
568 std::string mHeaderText;
569 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200570 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400571 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200572 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400573 int mSeparatorH;
574 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200575 int mShowFolders, mShowFiles, mShowNavFolders;
576 int mUpdate;
577 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400578 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100579 int mFastScrollW;
580 int mFastScrollLineW;
581 int mFastScrollRectW;
582 int mFastScrollRectH;
583 int mFastScrollRectX;
584 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400585 static int mSortOrder;
586 int startY;
587 int scrollingSpeed;
588 int scrollingY;
589 int mHeaderIsStatic;
590 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200591 unsigned mFontHeight;
592 unsigned mLineHeight;
593 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
594 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400595 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200596 Resource* mFileIcon;
597 Resource* mBackground;
598 Resource* mFont;
599 COLOR mBackgroundColor;
600 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400601 COLOR mHeaderBackgroundColor;
602 COLOR mHeaderFontColor;
603 COLOR mSeparatorColor;
604 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100605 COLOR mFastScrollLineColor;
606 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600607 bool hasHighlightColor;
608 bool hasFontHighlightColor;
609 bool isHighlighted;
610 COLOR mHighlightColor;
611 COLOR mFontHighlightColor;
612 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600613 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400614};
615
Vojtech Bocekede51c52014-02-07 23:58:09 +0100616class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400617{
618public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200619 GUIListBox(xml_node<>* node);
620 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400621
622public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200623 // Render - Render the full object to the GL surface
624 // Return 0 on success, <0 on error
625 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400626
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 // Update - Update any UI component animations (called <= 30 FPS)
628 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
629 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400630
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200631 // NotifyTouch - Notify of a touch event
632 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
633 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400634
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200635 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100636 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400637
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200638 // SetPos - Update the position of the render object
639 // Return 0 on success, <0 on error
640 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400641
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200642 // SetPageFocus - Notify when a page gains or loses focus
643 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400644
645protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200646 struct ListData {
647 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400648 std::string variableValue;
649 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200650 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400651
652protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200653 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400654
655protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200656 std::vector<ListData> mList;
657 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400658 std::string mSelection;
659 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600660 std::string mHeaderText;
661 std::string mLastValue;
662 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200663 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600664 int startY;
665 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200666 int mLineSpacing;
667 int mUpdate;
668 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000669 int mFastScrollW;
670 int mFastScrollLineW;
671 int mFastScrollRectW;
672 int mFastScrollRectH;
673 int mFastScrollRectX;
674 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600675 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
676 int scrollingSpeed;
677 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400678 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200679 unsigned mFontHeight;
680 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600681 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200682 Resource* mIconSelected;
683 Resource* mIconUnselected;
684 Resource* mBackground;
685 Resource* mFont;
686 COLOR mBackgroundColor;
687 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600688 COLOR mHeaderBackgroundColor;
689 COLOR mHeaderFontColor;
690 COLOR mSeparatorColor;
691 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000692 COLOR mFastScrollLineColor;
693 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600694 bool hasHighlightColor;
695 bool hasFontHighlightColor;
696 bool isHighlighted;
697 COLOR mHighlightColor;
698 COLOR mFontHighlightColor;
699 int mHeaderIsStatic;
700 int startSelection;
701 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400702};
703
Vojtech Bocekede51c52014-02-07 23:58:09 +0100704class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500705{
706public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200707 GUIPartitionList(xml_node<>* node);
708 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500709
710public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200711 // Render - Render the full object to the GL surface
712 // Return 0 on success, <0 on error
713 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500714
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200715 // Update - Update any UI component animations (called <= 30 FPS)
716 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
717 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500718
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200719 // NotifyTouch - Notify of a touch event
720 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
721 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500722
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200723 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100724 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500725
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200726 // SetPos - Update the position of the render object
727 // Return 0 on success, <0 on error
728 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500729
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200730 // SetPageFocus - Notify when a page gains or loses focus
731 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500732
733protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200734 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500735 virtual void MatchList(void);
736
737protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200738 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500739 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200740 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500741 std::string selectedList;
742 std::string currentValue;
743 std::string mHeaderText;
744 std::string mLastValue;
745 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200746 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500747 int startY;
748 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200749 int mLineSpacing;
750 int mUpdate;
751 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500752 int mFastScrollW;
753 int mFastScrollLineW;
754 int mFastScrollRectW;
755 int mFastScrollRectH;
756 int mFastScrollRectX;
757 int mFastScrollRectY;
758 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
759 int scrollingSpeed;
760 int scrollingY;
761 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200762 unsigned mFontHeight;
763 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500764 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200765 Resource* mIconSelected;
766 Resource* mIconUnselected;
767 Resource* mBackground;
768 Resource* mFont;
769 COLOR mBackgroundColor;
770 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500771 COLOR mHeaderBackgroundColor;
772 COLOR mHeaderFontColor;
773 COLOR mSeparatorColor;
774 COLOR mHeaderSeparatorColor;
775 COLOR mFastScrollLineColor;
776 COLOR mFastScrollRectColor;
777 bool hasHighlightColor;
778 bool hasFontHighlightColor;
779 bool isHighlighted;
780 COLOR mHighlightColor;
781 COLOR mFontHighlightColor;
782 int mHeaderIsStatic;
783 int startSelection;
784 int touchDebounce;
785 bool updateList;
786};
787
Dees_Troy51a0e822012-09-05 15:24:24 -0400788// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100789class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400790{
791public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200792 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400793
794public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200795 // Render - Render the full object to the GL surface
796 // Return 0 on success, <0 on error
797 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400798
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200799 // Update - Update any UI component animations (called <= 30 FPS)
800 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
801 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400802
803protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200804 AnimationResource* mAnimation;
805 int mFrame;
806 int mFPS;
807 int mLoop;
808 int mRender;
809 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400810};
811
Vojtech Bocekede51c52014-02-07 23:58:09 +0100812class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400813{
814public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200815 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400816
817public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200818 // Render - Render the full object to the GL surface
819 // Return 0 on success, <0 on error
820 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400821
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200822 // Update - Update any UI component animations (called <= 30 FPS)
823 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
824 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400825
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200826 // NotifyVarChange - Notify of a variable change
827 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100828 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400829
830protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200831 Resource* mEmptyBar;
832 Resource* mFullBar;
833 std::string mMinValVar;
834 std::string mMaxValVar;
835 std::string mCurValVar;
836 float mSlide;
837 float mSlideInc;
838 int mSlideFrames;
839 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400840
841protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200842 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400843};
844
Vojtech Bocekede51c52014-02-07 23:58:09 +0100845class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400846{
847public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200848 GUISlider(xml_node<>* node);
849 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400850
851public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200852 // Render - Render the full object to the GL surface
853 // Return 0 on success, <0 on error
854 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400855
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200856 // Update - Update any UI component animations (called <= 30 FPS)
857 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
858 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400859
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200860 // NotifyTouch - Notify of a touch event
861 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
862 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400863
864protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200865 GUIAction* sAction;
866 Resource* sSlider;
867 Resource* sSliderUsed;
868 Resource* sTouch;
869 int sTouchW, sTouchH;
870 int sCurTouchX;
871 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400872};
873
874#define MAX_KEYBOARD_LAYOUTS 5
875#define MAX_KEYBOARD_ROWS 9
876#define MAX_KEYBOARD_KEYS 20
877#define KEYBOARD_ACTION 253
878#define KEYBOARD_LAYOUT 254
879#define KEYBOARD_SWIPE_LEFT 252
880#define KEYBOARD_SWIPE_RIGHT 251
881#define KEYBOARD_ARROW_LEFT 250
882#define KEYBOARD_ARROW_RIGHT 249
883#define KEYBOARD_HOME 248
884#define KEYBOARD_END 247
885#define KEYBOARD_ARROW_UP 246
886#define KEYBOARD_ARROW_DOWN 245
887#define KEYBOARD_SPECIAL_KEYS 245
888#define KEYBOARD_BACKSPACE 8
889
Vojtech Bocekede51c52014-02-07 23:58:09 +0100890class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400891{
892public:
893 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200894 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400895
896public:
897 virtual int Render(void);
898 virtual int Update(void);
899 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
900 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
901
902protected:
903 virtual int GetSelection(int x, int y);
904
905protected:
906 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200907 {
908 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400909 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200910 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400911 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200912 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600913 struct capslock_tracking_struct
914 {
915 int capslock;
916 int set_capslock;
917 int revert_layout;
918 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400919
920 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
921 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600922 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400923 bool mRendered;
924 std::string mVariable;
925 unsigned int cursorLocation;
926 unsigned int currentLayout;
927 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
928 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600929 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400930 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400931 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600932 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400933};
934
935// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100936class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400937{
938public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200939 // w and h may be ignored, in which case, no bounding box is applied
940 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400941 virtual ~GUIInput();
942
943public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200944 // Render - Render the full object to the GL surface
945 // Return 0 on success, <0 on error
946 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400947
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200948 // Update - Update any UI component animations (called <= 30 FPS)
949 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
950 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400951
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200952 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100953 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400954
955 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200956 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
957 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400958
959 virtual int NotifyKeyboard(int key);
960
961protected:
962 virtual int GetSelection(int x, int y);
963
964 // Handles displaying the text properly when chars are added, deleted, or for scrolling
965 virtual int HandleTextLocation(int x);
966
967protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200968 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400969 GUIAction* mAction;
970 Resource* mBackground;
971 Resource* mCursor;
972 Resource* mFont;
973 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200974 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400975 std::string mVariable;
976 std::string mMask;
977 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200978 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400979 COLOR mCursorColor;
980 int scrollingX;
981 int lastX;
982 int mCursorLocation;
983 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
984 int mFontY;
985 unsigned skipChars;
986 unsigned mFontHeight;
987 unsigned CursorWidth;
988 bool mRendered;
989 bool HasMask;
990 bool DrawCursor;
991 bool isLocalChange;
992 bool HasAllowed;
993 bool HasDisabled;
994 std::string AllowedList;
995 std::string DisabledList;
996 unsigned MinLen;
997 unsigned MaxLen;
998};
999
1000class HardwareKeyboard
1001{
1002public:
1003 HardwareKeyboard(void);
1004 virtual ~HardwareKeyboard();
1005
1006public:
1007 virtual int KeyDown(int key_code);
1008 virtual int KeyUp(int key_code);
1009 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001010
1011 void ConsumeKeyRelease(int key);
1012
1013private:
1014 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -04001015};
1016
Vojtech Bocekede51c52014-02-07 23:58:09 +01001017class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +02001018{
1019public:
1020 GUISliderValue(xml_node<>* node);
1021 virtual ~GUISliderValue();
1022
1023public:
1024 // Render - Render the full object to the GL surface
1025 // Return 0 on success, <0 on error
1026 virtual int Render(void);
1027
1028 // Update - Update any UI component animations (called <= 30 FPS)
1029 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1030 virtual int Update(void);
1031
1032 // SetPos - Update the position of the render object
1033 // Return 0 on success, <0 on error
1034 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1035
1036 // NotifyTouch - Notify of a touch event
1037 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1038 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1039
1040 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001041 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001042
1043 // SetPageFocus - Notify when a page gains or loses focus
1044 virtual void SetPageFocus(int inFocus);
1045
1046protected:
1047 int measureText(const std::string& str);
1048 int valueFromPct(float pct);
1049 float pctFromValue(int value);
1050 void loadValue(bool force = false);
1051
1052 std::string mVariable;
1053 int mMax;
1054 int mMin;
1055 int mValue;
1056 char *mValueStr;
1057 float mValuePct;
1058 std::string mMaxStr;
1059 std::string mMinStr;
1060 Resource *mFont;
1061 GUIText* mLabel;
1062 int mLabelW;
1063 COLOR mTextColor;
1064 COLOR mLineColor;
1065 COLOR mSliderColor;
1066 bool mShowRange;
1067 bool mShowCurr;
1068 int mLineX;
1069 int mLineY;
1070 int mLineH;
1071 int mLinePadding;
1072 int mPadding;
1073 int mSliderY;
1074 int mSliderW;
1075 int mSliderH;
1076 bool mRendered;
1077 int mFontHeight;
1078 GUIAction *mAction;
1079 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001080 int mLineW;
1081 bool mDragging;
1082 Resource *mBackgroundImage;
1083 Resource *mHandleImage;
1084 Resource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001085};
1086
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001087class MouseCursor : public RenderObject
1088{
1089public:
1090 MouseCursor(int posX, int posY);
1091 virtual ~MouseCursor();
1092
1093 virtual int Render(void);
1094 virtual int Update(void);
1095 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1096
1097 void Move(int deltaX, int deltaY);
1098 void GetPos(int& x, int& y);
1099 void LoadData(xml_node<>* node);
1100 void ResetData(int resX, int resY);
1101
1102private:
1103 int m_resX;
1104 int m_resY;
1105 bool m_moved;
1106 float m_speedMultiplier;
1107 COLOR m_color;
1108 Resource *m_image;
1109 bool m_present;
1110};
1111
Dees_Troy51a0e822012-09-05 15:24:24 -04001112// Helper APIs
1113bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1114
1115#endif // _OBJECTS_HEADER
1116