blob: 832569c1d703b45b873247834fb0619ad0fb9a29 [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
Ethan Yonker751a85e2014-12-12 16:59:10 -060038#ifndef TW_X_OFFSET
39#define TW_X_OFFSET 0
40#endif
41#ifndef TW_Y_OFFSET
42#define TW_Y_OFFSET 0
43#endif
44
Dees_Troy51a0e822012-09-05 15:24:24 -040045class RenderObject
46{
47public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 enum Placement {
49 TOP_LEFT = 0,
50 TOP_RIGHT = 1,
51 BOTTOM_LEFT = 2,
52 BOTTOM_RIGHT = 3,
53 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040054 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 };
Dees_Troy51a0e822012-09-05 15:24:24 -040056
57public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020058 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
59 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040060
61public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020062 // Render - Render the full object to the GL surface
63 // Return 0 on success, <0 on error
64 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040065
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020066 // Update - Update any UI component animations (called <= 30 FPS)
67 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
68 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040069
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 // GetRenderPos - Returns the current position of the object
71 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 -040072
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 // SetRenderPos - Update the position of the object
74 // Return 0 on success, <0 on error
75 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 -040076
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 // GetPlacement - Returns the current placement
78 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040079
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 // SetPlacement - Update the current placement
81 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040082
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083 // SetPageFocus - Notify when a page gains or loses focus
84 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040085
86protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020087 int mRenderX, mRenderY, mRenderW, mRenderH;
88 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040089};
90
91class ActionObject
92{
93public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020094 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
95 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040096
97public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020098 // NotifyTouch - Notify of a touch event
99 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
100 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 // NotifyKey - Notify of a key press
103 // 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 +0100104 virtual int NotifyKey(int key, bool down) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 // GetRenderPos - Returns the current position of the object
107 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 -0400108
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 // SetRenderPos - Update the position of the object
110 // Return 0 on success, <0 on error
111 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400112
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200113 // IsInRegion - Checks if the request is handled by this object
114 // Return 0 if this object handles the request, 1 if not
115 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 -0400116
Dees_Troy51a0e822012-09-05 15:24:24 -0400117protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200118 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400119};
120
Vojtech Bocekede51c52014-02-07 23:58:09 +0100121class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400122{
123public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100124 GUIObject(xml_node<>* node);
125 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400126
127public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200128 bool IsConditionVariable(std::string var);
129 bool isConditionTrue();
130 bool isConditionValid();
Vojtech Bocek07220562014-02-08 02:05:33 +0100131
132 // NotifyVarChange - Notify of a variable change
133 // Returns 0 on success, <0 on error
134 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400135
136protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 class Condition
138 {
139 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100140 Condition() {
141 mLastResult = true;
142 }
143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 std::string mVar1;
145 std::string mVar2;
146 std::string mCompareOp;
147 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100148 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400150
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200151 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400152
153protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200154 bool isMounted(std::string vol);
155 bool isConditionTrue(Condition* condition);
Vojtech Bocek07220562014-02-08 02:05:33 +0100156
157 bool mConditionsResult;
Dees_Troy51a0e822012-09-05 15:24:24 -0400158};
159
160class InputObject
161{
162public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200163 InputObject() { HasInputFocus = 0; }
164 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400165
166public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200167 // NotifyKeyboard - Notify of keyboard input
168 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
169 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400170
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200171 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400172
173protected:
174 int HasInputFocus;
175};
176
177// Derived Objects
178// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100179class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400180{
181public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200182 // w and h may be ignored, in which case, no bounding box is applied
183 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400184
185public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200186 // Render - Render the full object to the GL surface
187 // Return 0 on success, <0 on error
188 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400189
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200190 // Update - Update any UI component animations (called <= 30 FPS)
191 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
192 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400193
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200194 // Retrieve the size of the current string (dynamic strings may change per call)
195 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400196
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200197 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100198 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400199
200 // Set maximum width in pixels
201 virtual int SetMaxWidth(unsigned width);
202
203 // Set number of characters to skip (for scrolling)
204 virtual int SkipCharCount(unsigned skip);
205
Dees_Troy4d12f962012-10-19 13:13:15 -0400206public:
207 bool isHighlighted;
208
Dees_Troy51a0e822012-09-05 15:24:24 -0400209protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200210 std::string mText;
211 std::string mLastValue;
212 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400213 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200214 Resource* mFont;
215 int mIsStatic;
216 int mVarChanged;
217 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400218 unsigned maxWidth;
219 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400220 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400221
222protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200223 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400224};
225
226// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100227class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400228{
229public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400231
232public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200233 // Render - Render the full object to the GL surface
234 // Return 0 on success, <0 on error
235 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400236
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200237 // SetRenderPos - Update the position of the object
238 // Return 0 on success, <0 on error
239 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400240
Dees_Troy4d12f962012-10-19 13:13:15 -0400241public:
242 bool isHighlighted;
243
Dees_Troy51a0e822012-09-05 15:24:24 -0400244protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200245 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400246 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400247};
248
249// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100250class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400251{
252public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200253 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400254
255public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200256 // Render - Render the full object to the GL surface
257 // Return 0 on success, <0 on error
258 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400259
260protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200261 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400262};
263
264// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100265class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400266{
thatc6085482015-01-09 22:12:43 +0100267 friend class ActionThread;
268
Dees_Troy51a0e822012-09-05 15:24:24 -0400269public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200270 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400271
272public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200273 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100274 virtual int NotifyKey(int key, bool down);
Vojtech Bocek07220562014-02-08 02:05:33 +0100275 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
that3f7b1ac2014-12-30 11:30:13 +0100276
277 int doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400278
279protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200280 class Action
281 {
282 public:
283 std::string mFunction;
284 std::string mArg;
285 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400286
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200287 std::vector<Action> mActions;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100288 std::map<int, bool> mKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400289
290protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200291 int getKeyByName(std::string key);
that3f7b1ac2014-12-30 11:30:13 +0100292 int doAction(Action action);
thatc6085482015-01-09 22:12:43 +0100293 bool needsToRunInSeparateThread(const Action& action);
Dees_Troy51a0e822012-09-05 15:24:24 -0400294 void simulate_progress_bar(void);
Ethan Yonker0d47eb52015-01-09 11:23:19 -0600295 int flash_zip(std::string filename, int* wipe_cache);
thatcc8ddca2015-01-03 01:59:36 +0100296 void reinject_after_flash();
Dees_Troy51a0e822012-09-05 15:24:24 -0400297 void operation_start(const string operation_name);
that3f7b1ac2014-12-30 11:30:13 +0100298 void operation_end(const int operation_status);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000299 time_t Start;
that3f7b1ac2014-12-30 11:30:13 +0100300
301 // map action name to function pointer
302 typedef int (GUIAction::*execFunction)(std::string);
303 typedef std::map<std::string, execFunction> mapFunc;
304 static mapFunc mf;
thatc6085482015-01-09 22:12:43 +0100305 static std::set<std::string> setActionsRunningInCallerThread;
that3f7b1ac2014-12-30 11:30:13 +0100306
307 // GUI actions
308 int reboot(std::string arg);
309 int home(std::string arg);
310 int key(std::string arg);
311 int page(std::string arg);
312 int reload(std::string arg);
313 int readBackup(std::string arg);
314 int set(std::string arg);
315 int clear(std::string arg);
316 int mount(std::string arg);
317 int unmount(std::string arg);
318 int restoredefaultsettings(std::string arg);
319 int copylog(std::string arg);
320 int compute(std::string arg);
321 int setguitimezone(std::string arg);
322 int overlay(std::string arg);
323 int queuezip(std::string arg);
324 int cancelzip(std::string arg);
325 int queueclear(std::string arg);
326 int sleep(std::string arg);
327 int appenddatetobackupname(std::string arg);
328 int generatebackupname(std::string arg);
329 int checkpartitionlist(std::string arg);
330 int getpartitiondetails(std::string arg);
331 int screenshot(std::string arg);
332 int setbrightness(std::string arg);
333
thatc6085482015-01-09 22:12:43 +0100334 // (originally) threaded actions
that3f7b1ac2014-12-30 11:30:13 +0100335 int fileexists(std::string arg);
336 int flash(std::string arg);
337 int wipe(std::string arg);
338 int refreshsizes(std::string arg);
339 int nandroid(std::string arg);
340 int fixpermissions(std::string arg);
341 int dd(std::string arg);
342 int partitionsd(std::string arg);
343 int installhtcdumlock(std::string arg);
344 int htcdumlockrestoreboot(std::string arg);
345 int htcdumlockreflashrecovery(std::string arg);
346 int cmd(std::string arg);
347 int terminalcommand(std::string arg);
348 int killterminal(std::string arg);
349 int reinjecttwrp(std::string arg);
350 int checkbackupname(std::string arg);
351 int decrypt(std::string arg);
352 int adbsideload(std::string arg);
353 int adbsideloadcancel(std::string arg);
354 int openrecoveryscript(std::string arg);
355 int installsu(std::string arg);
356 int fixsu(std::string arg);
357 int decrypt_backup(std::string arg);
358 int repair(std::string arg);
359 int changefilesystem(std::string arg);
360 int startmtp(std::string arg);
361 int stopmtp(std::string arg);
Ethan Yonker96af84a2015-01-05 14:58:36 -0600362 int flashimage(std::string arg);
bigbiff7abc5fe2015-01-17 16:53:12 -0500363 int cancelbackup(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100364
365 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400366};
367
thatc6085482015-01-09 22:12:43 +0100368class ActionThread
369{
370public:
371 ActionThread();
372 ~ActionThread();
373
that7d3b54f2015-01-09 22:52:51 +0100374 void threadActions(GUIAction *act);
thatc6085482015-01-09 22:12:43 +0100375 void run(void *data);
376private:
377 struct ThreadData
378 {
379 GUIAction *act;
thatc6085482015-01-09 22:12:43 +0100380 };
381
382 pthread_t m_thread;
383 bool m_thread_running;
384 pthread_mutex_t m_act_lock;
385};
386
Vojtech Bocekede51c52014-02-07 23:58:09 +0100387class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400388{
389public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200390 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400391
392public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200393 // Render - Render the full object to the GL surface
394 // Return 0 on success, <0 on error
395 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400396
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200397 // Update - Update any UI component animations (called <= 30 FPS)
398 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
399 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400400
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200401 // SetRenderPos - Update the position of the object
402 // Return 0 on success, <0 on error
403 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400404
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200405 // IsInRegion - Checks if the request is handled by this object
406 // Return 0 if this object handles the request, 1 if not
407 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400408
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200409 // NotifyTouch - Notify of a touch event
410 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
411 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400412
413protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200414 enum SlideoutState
415 {
416 hidden = 0,
417 visible,
418 request_hide,
419 request_show
420 };
421
422 Resource* mFont;
423 Resource* mSlideoutImage;
424 COLOR mForegroundColor;
425 COLOR mBackgroundColor;
426 COLOR mScrollColor;
427 unsigned int mFontHeight;
428 int mCurrentLine;
429 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000430 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200431 unsigned int mMaxRows;
432 int mStartY;
433 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
434 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
435 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
436 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200437 int mSlideout;
438 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000439 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500440 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000441 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400442
443protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200444 virtual int RenderSlideout(void);
445 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400446};
447
Vojtech Bocekede51c52014-02-07 23:58:09 +0100448class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400449{
450public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200451 GUIButton(xml_node<>* node);
452 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400453
454public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200455 // Render - Render the full object to the GL surface
456 // Return 0 on success, <0 on error
457 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400458
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200459 // Update - Update any UI component animations (called <= 30 FPS)
460 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
461 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400462
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200463 // SetPos - Update the position of the render object
464 // Return 0 on success, <0 on error
465 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400466
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200467 // NotifyTouch - Notify of a touch event
468 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
469 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400470
471protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200472 GUIImage* mButtonImg;
473 Resource* mButtonIcon;
474 GUIText* mButtonLabel;
475 GUIAction* mAction;
476 int mTextX, mTextY, mTextW, mTextH;
477 int mIconX, mIconY, mIconW, mIconH;
478 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600479 bool hasHighlightColor;
480 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500481 bool hasFill;
482 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600483 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000484 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400485};
486
Vojtech Bocekede51c52014-02-07 23:58:09 +0100487class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400488{
489public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200490 GUICheckbox(xml_node<>* node);
491 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400492
493public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200494 // Render - Render the full object to the GL surface
495 // Return 0 on success, <0 on error
496 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400497
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200498 // Update - Update any UI component animations (called <= 30 FPS)
499 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
500 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400501
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200502 // SetPos - Update the position of the render object
503 // Return 0 on success, <0 on error
504 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400505
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200506 // NotifyTouch - Notify of a touch event
507 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
508 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400509
510protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200511 Resource* mChecked;
512 Resource* mUnchecked;
513 GUIText* mLabel;
514 int mTextX, mTextY;
515 int mCheckX, mCheckY, mCheckW, mCheckH;
516 int mLastState;
517 bool mRendered;
518 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400519};
520
Vojtech Bocekede51c52014-02-07 23:58:09 +0100521class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400522{
523public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200524 GUIFileSelector(xml_node<>* node);
525 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400526
527public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200528 // Render - Render the full object to the GL surface
529 // Return 0 on success, <0 on error
530 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400531
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200532 // Update - Update any UI component animations (called <= 30 FPS)
533 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
534 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400535
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200536 // NotifyTouch - Notify of a touch event
537 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
538 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400539
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200540 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100541 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400542
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200543 // SetPos - Update the position of the render object
544 // Return 0 on success, <0 on error
545 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400546
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200547 // SetPageFocus - Notify when a page gains or loses focus
548 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400549
550protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200551 struct FileData {
552 std::string fileName;
553 unsigned char fileType; // Uses d_type format from struct dirent
554 mode_t protection; // Uses mode_t format from stat
555 uid_t userId;
556 gid_t groupId;
557 off_t fileSize;
558 time_t lastAccess; // Uses time_t format from stat
559 time_t lastModified; // Uses time_t format from stat
560 time_t lastStatChange; // Uses time_t format from stat
561 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400562
563protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200564 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400565
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200566 virtual int GetFileList(const std::string folder);
567 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400568
569protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200570 std::vector<FileData> mFolderList;
571 std::vector<FileData> mFileList;
572 std::string mPathVar;
573 std::string mExtn;
574 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400575 std::string mSortVariable;
576 std::string mSelection;
577 std::string mHeaderText;
578 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200579 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400580 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200581 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400582 int mSeparatorH;
583 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200584 int mShowFolders, mShowFiles, mShowNavFolders;
585 int mUpdate;
586 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400587 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100588 int mFastScrollW;
589 int mFastScrollLineW;
590 int mFastScrollRectW;
591 int mFastScrollRectH;
592 int mFastScrollRectX;
593 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400594 static int mSortOrder;
595 int startY;
596 int scrollingSpeed;
597 int scrollingY;
598 int mHeaderIsStatic;
599 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200600 unsigned mFontHeight;
601 unsigned mLineHeight;
602 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
603 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400604 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200605 Resource* mFileIcon;
606 Resource* mBackground;
607 Resource* mFont;
608 COLOR mBackgroundColor;
609 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400610 COLOR mHeaderBackgroundColor;
611 COLOR mHeaderFontColor;
612 COLOR mSeparatorColor;
613 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100614 COLOR mFastScrollLineColor;
615 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600616 bool hasHighlightColor;
617 bool hasFontHighlightColor;
618 bool isHighlighted;
619 COLOR mHighlightColor;
620 COLOR mFontHighlightColor;
621 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600622 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400623};
624
Vojtech Bocekede51c52014-02-07 23:58:09 +0100625class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400626{
627public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200628 GUIListBox(xml_node<>* node);
629 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400630
631public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200632 // Render - Render the full object to the GL surface
633 // Return 0 on success, <0 on error
634 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400635
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200636 // Update - Update any UI component animations (called <= 30 FPS)
637 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
638 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400639
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200640 // NotifyTouch - Notify of a touch event
641 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
642 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400643
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200644 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100645 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400646
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200647 // SetPos - Update the position of the render object
648 // Return 0 on success, <0 on error
649 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400650
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200651 // SetPageFocus - Notify when a page gains or loses focus
652 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400653
654protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200655 struct ListData {
656 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400657 std::string variableValue;
658 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200659 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400660
661protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200662 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400663
664protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200665 std::vector<ListData> mList;
666 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400667 std::string mSelection;
668 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600669 std::string mHeaderText;
670 std::string mLastValue;
671 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200672 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600673 int startY;
674 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200675 int mLineSpacing;
676 int mUpdate;
677 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000678 int mFastScrollW;
679 int mFastScrollLineW;
680 int mFastScrollRectW;
681 int mFastScrollRectH;
682 int mFastScrollRectX;
683 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600684 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
685 int scrollingSpeed;
686 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400687 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200688 unsigned mFontHeight;
689 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600690 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200691 Resource* mIconSelected;
692 Resource* mIconUnselected;
693 Resource* mBackground;
694 Resource* mFont;
695 COLOR mBackgroundColor;
696 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600697 COLOR mHeaderBackgroundColor;
698 COLOR mHeaderFontColor;
699 COLOR mSeparatorColor;
700 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000701 COLOR mFastScrollLineColor;
702 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600703 bool hasHighlightColor;
704 bool hasFontHighlightColor;
705 bool isHighlighted;
706 COLOR mHighlightColor;
707 COLOR mFontHighlightColor;
708 int mHeaderIsStatic;
709 int startSelection;
710 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400711};
712
Vojtech Bocekede51c52014-02-07 23:58:09 +0100713class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500714{
715public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200716 GUIPartitionList(xml_node<>* node);
717 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500718
719public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200720 // Render - Render the full object to the GL surface
721 // Return 0 on success, <0 on error
722 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500723
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200724 // Update - Update any UI component animations (called <= 30 FPS)
725 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
726 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500727
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200728 // NotifyTouch - Notify of a touch event
729 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
730 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500731
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200732 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100733 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500734
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200735 // SetPos - Update the position of the render object
736 // Return 0 on success, <0 on error
737 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500738
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200739 // SetPageFocus - Notify when a page gains or loses focus
740 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500741
742protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200743 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500744 virtual void MatchList(void);
745
746protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200747 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500748 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200749 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500750 std::string selectedList;
751 std::string currentValue;
752 std::string mHeaderText;
753 std::string mLastValue;
754 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200755 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500756 int startY;
757 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200758 int mLineSpacing;
759 int mUpdate;
760 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500761 int mFastScrollW;
762 int mFastScrollLineW;
763 int mFastScrollRectW;
764 int mFastScrollRectH;
765 int mFastScrollRectX;
766 int mFastScrollRectY;
767 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
768 int scrollingSpeed;
769 int scrollingY;
770 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200771 unsigned mFontHeight;
772 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500773 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200774 Resource* mIconSelected;
775 Resource* mIconUnselected;
776 Resource* mBackground;
777 Resource* mFont;
778 COLOR mBackgroundColor;
779 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500780 COLOR mHeaderBackgroundColor;
781 COLOR mHeaderFontColor;
782 COLOR mSeparatorColor;
783 COLOR mHeaderSeparatorColor;
784 COLOR mFastScrollLineColor;
785 COLOR mFastScrollRectColor;
786 bool hasHighlightColor;
787 bool hasFontHighlightColor;
788 bool isHighlighted;
789 COLOR mHighlightColor;
790 COLOR mFontHighlightColor;
791 int mHeaderIsStatic;
792 int startSelection;
793 int touchDebounce;
794 bool updateList;
795};
796
Dees_Troy51a0e822012-09-05 15:24:24 -0400797// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100798class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400799{
800public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200801 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400802
803public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200804 // Render - Render the full object to the GL surface
805 // Return 0 on success, <0 on error
806 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400807
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200808 // Update - Update any UI component animations (called <= 30 FPS)
809 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
810 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400811
812protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200813 AnimationResource* mAnimation;
814 int mFrame;
815 int mFPS;
816 int mLoop;
817 int mRender;
818 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400819};
820
Vojtech Bocekede51c52014-02-07 23:58:09 +0100821class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400822{
823public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200824 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400825
826public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200827 // Render - Render the full object to the GL surface
828 // Return 0 on success, <0 on error
829 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400830
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200831 // Update - Update any UI component animations (called <= 30 FPS)
832 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
833 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400834
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200835 // NotifyVarChange - Notify of a variable change
836 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100837 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400838
839protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200840 Resource* mEmptyBar;
841 Resource* mFullBar;
842 std::string mMinValVar;
843 std::string mMaxValVar;
844 std::string mCurValVar;
845 float mSlide;
846 float mSlideInc;
847 int mSlideFrames;
848 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400849
850protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200851 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400852};
853
Vojtech Bocekede51c52014-02-07 23:58:09 +0100854class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400855{
856public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200857 GUISlider(xml_node<>* node);
858 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400859
860public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200861 // Render - Render the full object to the GL surface
862 // Return 0 on success, <0 on error
863 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400864
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200865 // Update - Update any UI component animations (called <= 30 FPS)
866 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
867 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400868
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200869 // NotifyTouch - Notify of a touch event
870 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
871 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400872
873protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200874 GUIAction* sAction;
875 Resource* sSlider;
876 Resource* sSliderUsed;
877 Resource* sTouch;
878 int sTouchW, sTouchH;
879 int sCurTouchX;
880 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400881};
882
883#define MAX_KEYBOARD_LAYOUTS 5
884#define MAX_KEYBOARD_ROWS 9
885#define MAX_KEYBOARD_KEYS 20
886#define KEYBOARD_ACTION 253
887#define KEYBOARD_LAYOUT 254
888#define KEYBOARD_SWIPE_LEFT 252
889#define KEYBOARD_SWIPE_RIGHT 251
890#define KEYBOARD_ARROW_LEFT 250
891#define KEYBOARD_ARROW_RIGHT 249
892#define KEYBOARD_HOME 248
893#define KEYBOARD_END 247
894#define KEYBOARD_ARROW_UP 246
895#define KEYBOARD_ARROW_DOWN 245
896#define KEYBOARD_SPECIAL_KEYS 245
897#define KEYBOARD_BACKSPACE 8
898
Vojtech Bocekede51c52014-02-07 23:58:09 +0100899class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400900{
901public:
902 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200903 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400904
905public:
906 virtual int Render(void);
907 virtual int Update(void);
908 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
909 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
910
911protected:
912 virtual int GetSelection(int x, int y);
913
914protected:
915 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200916 {
917 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400918 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200919 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400920 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200921 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600922 struct capslock_tracking_struct
923 {
924 int capslock;
925 int set_capslock;
926 int revert_layout;
927 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400928
929 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
930 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600931 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400932 bool mRendered;
933 std::string mVariable;
934 unsigned int cursorLocation;
935 unsigned int currentLayout;
936 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
937 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600938 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400939 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400940 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600941 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400942};
943
944// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100945class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400946{
947public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200948 // w and h may be ignored, in which case, no bounding box is applied
949 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400950 virtual ~GUIInput();
951
952public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200953 // Render - Render the full object to the GL surface
954 // Return 0 on success, <0 on error
955 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400956
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200957 // Update - Update any UI component animations (called <= 30 FPS)
958 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
959 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400960
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200961 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100962 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400963
964 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200965 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
966 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400967
968 virtual int NotifyKeyboard(int key);
969
970protected:
971 virtual int GetSelection(int x, int y);
972
973 // Handles displaying the text properly when chars are added, deleted, or for scrolling
974 virtual int HandleTextLocation(int x);
975
976protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200977 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400978 GUIAction* mAction;
979 Resource* mBackground;
980 Resource* mCursor;
981 Resource* mFont;
982 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200983 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400984 std::string mVariable;
985 std::string mMask;
986 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200987 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400988 COLOR mCursorColor;
989 int scrollingX;
990 int lastX;
991 int mCursorLocation;
992 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
993 int mFontY;
994 unsigned skipChars;
995 unsigned mFontHeight;
996 unsigned CursorWidth;
997 bool mRendered;
998 bool HasMask;
999 bool DrawCursor;
1000 bool isLocalChange;
1001 bool HasAllowed;
1002 bool HasDisabled;
1003 std::string AllowedList;
1004 std::string DisabledList;
1005 unsigned MinLen;
1006 unsigned MaxLen;
1007};
1008
1009class HardwareKeyboard
1010{
1011public:
1012 HardwareKeyboard(void);
1013 virtual ~HardwareKeyboard();
1014
1015public:
1016 virtual int KeyDown(int key_code);
1017 virtual int KeyUp(int key_code);
1018 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001019
1020 void ConsumeKeyRelease(int key);
1021
1022private:
1023 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -04001024};
1025
Vojtech Bocekede51c52014-02-07 23:58:09 +01001026class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +02001027{
1028public:
1029 GUISliderValue(xml_node<>* node);
1030 virtual ~GUISliderValue();
1031
1032public:
1033 // Render - Render the full object to the GL surface
1034 // Return 0 on success, <0 on error
1035 virtual int Render(void);
1036
1037 // Update - Update any UI component animations (called <= 30 FPS)
1038 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1039 virtual int Update(void);
1040
1041 // SetPos - Update the position of the render object
1042 // Return 0 on success, <0 on error
1043 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1044
1045 // NotifyTouch - Notify of a touch event
1046 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1047 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1048
1049 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001050 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001051
1052 // SetPageFocus - Notify when a page gains or loses focus
1053 virtual void SetPageFocus(int inFocus);
1054
1055protected:
1056 int measureText(const std::string& str);
1057 int valueFromPct(float pct);
1058 float pctFromValue(int value);
1059 void loadValue(bool force = false);
1060
1061 std::string mVariable;
1062 int mMax;
1063 int mMin;
1064 int mValue;
1065 char *mValueStr;
1066 float mValuePct;
1067 std::string mMaxStr;
1068 std::string mMinStr;
1069 Resource *mFont;
1070 GUIText* mLabel;
1071 int mLabelW;
1072 COLOR mTextColor;
1073 COLOR mLineColor;
1074 COLOR mSliderColor;
1075 bool mShowRange;
1076 bool mShowCurr;
1077 int mLineX;
1078 int mLineY;
1079 int mLineH;
1080 int mLinePadding;
1081 int mPadding;
1082 int mSliderY;
1083 int mSliderW;
1084 int mSliderH;
1085 bool mRendered;
1086 int mFontHeight;
1087 GUIAction *mAction;
1088 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001089 int mLineW;
1090 bool mDragging;
1091 Resource *mBackgroundImage;
1092 Resource *mHandleImage;
1093 Resource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001094};
1095
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001096class MouseCursor : public RenderObject
1097{
1098public:
1099 MouseCursor(int posX, int posY);
1100 virtual ~MouseCursor();
1101
1102 virtual int Render(void);
1103 virtual int Update(void);
1104 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1105
1106 void Move(int deltaX, int deltaY);
1107 void GetPos(int& x, int& y);
1108 void LoadData(xml_node<>* node);
1109 void ResetData(int resX, int resY);
1110
1111private:
1112 int m_resX;
1113 int m_resY;
1114 bool m_moved;
1115 float m_speedMultiplier;
1116 COLOR m_color;
1117 Resource *m_image;
1118 bool m_present;
1119};
1120
Dees_Troy51a0e822012-09-05 15:24:24 -04001121// Helper APIs
1122bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1123
1124#endif // _OBJECTS_HEADER
1125