blob: 99b58550772ff694baa41033658abf4dad071bde [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);
that3f7b1ac2014-12-30 11:30:13 +0100363
364 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400365};
366
thatc6085482015-01-09 22:12:43 +0100367class ActionThread
368{
369public:
370 ActionThread();
371 ~ActionThread();
372
that7d3b54f2015-01-09 22:52:51 +0100373 void threadActions(GUIAction *act);
thatc6085482015-01-09 22:12:43 +0100374 void run(void *data);
375private:
376 struct ThreadData
377 {
378 GUIAction *act;
thatc6085482015-01-09 22:12:43 +0100379 };
380
381 pthread_t m_thread;
382 bool m_thread_running;
383 pthread_mutex_t m_act_lock;
384};
385
Vojtech Bocekede51c52014-02-07 23:58:09 +0100386class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400387{
388public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200389 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400390
391public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200392 // Render - Render the full object to the GL surface
393 // Return 0 on success, <0 on error
394 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400395
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200396 // Update - Update any UI component animations (called <= 30 FPS)
397 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
398 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400399
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200400 // SetRenderPos - Update the position of the object
401 // Return 0 on success, <0 on error
402 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400403
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200404 // IsInRegion - Checks if the request is handled by this object
405 // Return 0 if this object handles the request, 1 if not
406 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400407
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200408 // NotifyTouch - Notify of a touch event
409 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
410 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400411
412protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200413 enum SlideoutState
414 {
415 hidden = 0,
416 visible,
417 request_hide,
418 request_show
419 };
420
421 Resource* mFont;
422 Resource* mSlideoutImage;
423 COLOR mForegroundColor;
424 COLOR mBackgroundColor;
425 COLOR mScrollColor;
426 unsigned int mFontHeight;
427 int mCurrentLine;
428 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000429 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200430 unsigned int mMaxRows;
431 int mStartY;
432 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
433 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
434 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
435 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200436 int mSlideout;
437 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000438 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500439 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000440 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400441
442protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200443 virtual int RenderSlideout(void);
444 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400445};
446
Vojtech Bocekede51c52014-02-07 23:58:09 +0100447class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400448{
449public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200450 GUIButton(xml_node<>* node);
451 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400452
453public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200454 // Render - Render the full object to the GL surface
455 // Return 0 on success, <0 on error
456 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400457
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200458 // Update - Update any UI component animations (called <= 30 FPS)
459 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
460 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400461
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200462 // SetPos - Update the position of the render object
463 // Return 0 on success, <0 on error
464 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400465
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200466 // NotifyTouch - Notify of a touch event
467 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
468 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400469
470protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200471 GUIImage* mButtonImg;
472 Resource* mButtonIcon;
473 GUIText* mButtonLabel;
474 GUIAction* mAction;
475 int mTextX, mTextY, mTextW, mTextH;
476 int mIconX, mIconY, mIconW, mIconH;
477 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600478 bool hasHighlightColor;
479 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500480 bool hasFill;
481 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600482 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000483 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400484};
485
Vojtech Bocekede51c52014-02-07 23:58:09 +0100486class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400487{
488public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200489 GUICheckbox(xml_node<>* node);
490 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400491
492public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200493 // Render - Render the full object to the GL surface
494 // Return 0 on success, <0 on error
495 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400496
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200497 // Update - Update any UI component animations (called <= 30 FPS)
498 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
499 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400500
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200501 // SetPos - Update the position of the render object
502 // Return 0 on success, <0 on error
503 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400504
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200505 // NotifyTouch - Notify of a touch event
506 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
507 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400508
509protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200510 Resource* mChecked;
511 Resource* mUnchecked;
512 GUIText* mLabel;
513 int mTextX, mTextY;
514 int mCheckX, mCheckY, mCheckW, mCheckH;
515 int mLastState;
516 bool mRendered;
517 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400518};
519
Vojtech Bocekede51c52014-02-07 23:58:09 +0100520class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400521{
522public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200523 GUIFileSelector(xml_node<>* node);
524 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400525
526public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200527 // Render - Render the full object to the GL surface
528 // Return 0 on success, <0 on error
529 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400530
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200531 // Update - Update any UI component animations (called <= 30 FPS)
532 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
533 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400534
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200535 // NotifyTouch - Notify of a touch event
536 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
537 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400538
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200539 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100540 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400541
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200542 // SetPos - Update the position of the render object
543 // Return 0 on success, <0 on error
544 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400545
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200546 // SetPageFocus - Notify when a page gains or loses focus
547 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400548
549protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200550 struct FileData {
551 std::string fileName;
552 unsigned char fileType; // Uses d_type format from struct dirent
553 mode_t protection; // Uses mode_t format from stat
554 uid_t userId;
555 gid_t groupId;
556 off_t fileSize;
557 time_t lastAccess; // Uses time_t format from stat
558 time_t lastModified; // Uses time_t format from stat
559 time_t lastStatChange; // Uses time_t format from stat
560 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400561
562protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200563 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400564
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200565 virtual int GetFileList(const std::string folder);
566 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400567
568protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200569 std::vector<FileData> mFolderList;
570 std::vector<FileData> mFileList;
571 std::string mPathVar;
572 std::string mExtn;
573 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400574 std::string mSortVariable;
575 std::string mSelection;
576 std::string mHeaderText;
577 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200578 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400579 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200580 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400581 int mSeparatorH;
582 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200583 int mShowFolders, mShowFiles, mShowNavFolders;
584 int mUpdate;
585 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400586 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100587 int mFastScrollW;
588 int mFastScrollLineW;
589 int mFastScrollRectW;
590 int mFastScrollRectH;
591 int mFastScrollRectX;
592 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400593 static int mSortOrder;
594 int startY;
595 int scrollingSpeed;
596 int scrollingY;
597 int mHeaderIsStatic;
598 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200599 unsigned mFontHeight;
600 unsigned mLineHeight;
601 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
602 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400603 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200604 Resource* mFileIcon;
605 Resource* mBackground;
606 Resource* mFont;
607 COLOR mBackgroundColor;
608 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400609 COLOR mHeaderBackgroundColor;
610 COLOR mHeaderFontColor;
611 COLOR mSeparatorColor;
612 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100613 COLOR mFastScrollLineColor;
614 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600615 bool hasHighlightColor;
616 bool hasFontHighlightColor;
617 bool isHighlighted;
618 COLOR mHighlightColor;
619 COLOR mFontHighlightColor;
620 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600621 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400622};
623
Vojtech Bocekede51c52014-02-07 23:58:09 +0100624class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400625{
626public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200627 GUIListBox(xml_node<>* node);
628 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400629
630public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200631 // Render - Render the full object to the GL surface
632 // Return 0 on success, <0 on error
633 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400634
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200635 // Update - Update any UI component animations (called <= 30 FPS)
636 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
637 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400638
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200639 // NotifyTouch - Notify of a touch event
640 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
641 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400642
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200643 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100644 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400645
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200646 // SetPos - Update the position of the render object
647 // Return 0 on success, <0 on error
648 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400649
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200650 // SetPageFocus - Notify when a page gains or loses focus
651 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400652
653protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200654 struct ListData {
655 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400656 std::string variableValue;
657 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200658 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400659
660protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200661 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400662
663protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200664 std::vector<ListData> mList;
665 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400666 std::string mSelection;
667 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600668 std::string mHeaderText;
669 std::string mLastValue;
670 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200671 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600672 int startY;
673 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200674 int mLineSpacing;
675 int mUpdate;
676 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000677 int mFastScrollW;
678 int mFastScrollLineW;
679 int mFastScrollRectW;
680 int mFastScrollRectH;
681 int mFastScrollRectX;
682 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600683 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
684 int scrollingSpeed;
685 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400686 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200687 unsigned mFontHeight;
688 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600689 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200690 Resource* mIconSelected;
691 Resource* mIconUnselected;
692 Resource* mBackground;
693 Resource* mFont;
694 COLOR mBackgroundColor;
695 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600696 COLOR mHeaderBackgroundColor;
697 COLOR mHeaderFontColor;
698 COLOR mSeparatorColor;
699 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000700 COLOR mFastScrollLineColor;
701 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600702 bool hasHighlightColor;
703 bool hasFontHighlightColor;
704 bool isHighlighted;
705 COLOR mHighlightColor;
706 COLOR mFontHighlightColor;
707 int mHeaderIsStatic;
708 int startSelection;
709 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400710};
711
Vojtech Bocekede51c52014-02-07 23:58:09 +0100712class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500713{
714public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200715 GUIPartitionList(xml_node<>* node);
716 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500717
718public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200719 // Render - Render the full object to the GL surface
720 // Return 0 on success, <0 on error
721 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500722
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200723 // Update - Update any UI component animations (called <= 30 FPS)
724 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
725 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500726
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200727 // NotifyTouch - Notify of a touch event
728 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
729 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500730
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200731 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100732 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500733
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200734 // SetPos - Update the position of the render object
735 // Return 0 on success, <0 on error
736 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500737
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200738 // SetPageFocus - Notify when a page gains or loses focus
739 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500740
741protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200742 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500743 virtual void MatchList(void);
744
745protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200746 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500747 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200748 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500749 std::string selectedList;
750 std::string currentValue;
751 std::string mHeaderText;
752 std::string mLastValue;
753 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200754 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500755 int startY;
756 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200757 int mLineSpacing;
758 int mUpdate;
759 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500760 int mFastScrollW;
761 int mFastScrollLineW;
762 int mFastScrollRectW;
763 int mFastScrollRectH;
764 int mFastScrollRectX;
765 int mFastScrollRectY;
766 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
767 int scrollingSpeed;
768 int scrollingY;
769 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200770 unsigned mFontHeight;
771 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500772 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200773 Resource* mIconSelected;
774 Resource* mIconUnselected;
775 Resource* mBackground;
776 Resource* mFont;
777 COLOR mBackgroundColor;
778 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500779 COLOR mHeaderBackgroundColor;
780 COLOR mHeaderFontColor;
781 COLOR mSeparatorColor;
782 COLOR mHeaderSeparatorColor;
783 COLOR mFastScrollLineColor;
784 COLOR mFastScrollRectColor;
785 bool hasHighlightColor;
786 bool hasFontHighlightColor;
787 bool isHighlighted;
788 COLOR mHighlightColor;
789 COLOR mFontHighlightColor;
790 int mHeaderIsStatic;
791 int startSelection;
792 int touchDebounce;
793 bool updateList;
794};
795
Dees_Troy51a0e822012-09-05 15:24:24 -0400796// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100797class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400798{
799public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200800 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400801
802public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200803 // Render - Render the full object to the GL surface
804 // Return 0 on success, <0 on error
805 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400806
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200807 // Update - Update any UI component animations (called <= 30 FPS)
808 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
809 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400810
811protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200812 AnimationResource* mAnimation;
813 int mFrame;
814 int mFPS;
815 int mLoop;
816 int mRender;
817 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400818};
819
Vojtech Bocekede51c52014-02-07 23:58:09 +0100820class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400821{
822public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200823 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400824
825public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200826 // Render - Render the full object to the GL surface
827 // Return 0 on success, <0 on error
828 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400829
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200830 // Update - Update any UI component animations (called <= 30 FPS)
831 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
832 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400833
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200834 // NotifyVarChange - Notify of a variable change
835 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100836 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400837
838protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200839 Resource* mEmptyBar;
840 Resource* mFullBar;
841 std::string mMinValVar;
842 std::string mMaxValVar;
843 std::string mCurValVar;
844 float mSlide;
845 float mSlideInc;
846 int mSlideFrames;
847 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400848
849protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200850 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400851};
852
Vojtech Bocekede51c52014-02-07 23:58:09 +0100853class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400854{
855public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200856 GUISlider(xml_node<>* node);
857 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400858
859public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200860 // Render - Render the full object to the GL surface
861 // Return 0 on success, <0 on error
862 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400863
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200864 // Update - Update any UI component animations (called <= 30 FPS)
865 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
866 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400867
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200868 // NotifyTouch - Notify of a touch event
869 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
870 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400871
872protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200873 GUIAction* sAction;
874 Resource* sSlider;
875 Resource* sSliderUsed;
876 Resource* sTouch;
877 int sTouchW, sTouchH;
878 int sCurTouchX;
879 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400880};
881
882#define MAX_KEYBOARD_LAYOUTS 5
883#define MAX_KEYBOARD_ROWS 9
884#define MAX_KEYBOARD_KEYS 20
885#define KEYBOARD_ACTION 253
886#define KEYBOARD_LAYOUT 254
887#define KEYBOARD_SWIPE_LEFT 252
888#define KEYBOARD_SWIPE_RIGHT 251
889#define KEYBOARD_ARROW_LEFT 250
890#define KEYBOARD_ARROW_RIGHT 249
891#define KEYBOARD_HOME 248
892#define KEYBOARD_END 247
893#define KEYBOARD_ARROW_UP 246
894#define KEYBOARD_ARROW_DOWN 245
895#define KEYBOARD_SPECIAL_KEYS 245
896#define KEYBOARD_BACKSPACE 8
897
Vojtech Bocekede51c52014-02-07 23:58:09 +0100898class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400899{
900public:
901 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200902 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400903
904public:
905 virtual int Render(void);
906 virtual int Update(void);
907 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
908 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
909
910protected:
911 virtual int GetSelection(int x, int y);
912
913protected:
914 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200915 {
916 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400917 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200918 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400919 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200920 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600921 struct capslock_tracking_struct
922 {
923 int capslock;
924 int set_capslock;
925 int revert_layout;
926 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400927
928 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
929 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600930 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400931 bool mRendered;
932 std::string mVariable;
933 unsigned int cursorLocation;
934 unsigned int currentLayout;
935 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
936 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600937 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400938 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400939 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600940 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400941};
942
943// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100944class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400945{
946public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200947 // w and h may be ignored, in which case, no bounding box is applied
948 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400949 virtual ~GUIInput();
950
951public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200952 // Render - Render the full object to the GL surface
953 // Return 0 on success, <0 on error
954 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400955
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200956 // Update - Update any UI component animations (called <= 30 FPS)
957 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
958 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400959
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200960 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100961 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400962
963 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200964 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
965 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400966
967 virtual int NotifyKeyboard(int key);
968
969protected:
970 virtual int GetSelection(int x, int y);
971
972 // Handles displaying the text properly when chars are added, deleted, or for scrolling
973 virtual int HandleTextLocation(int x);
974
975protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200976 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400977 GUIAction* mAction;
978 Resource* mBackground;
979 Resource* mCursor;
980 Resource* mFont;
981 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200982 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400983 std::string mVariable;
984 std::string mMask;
985 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200986 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400987 COLOR mCursorColor;
988 int scrollingX;
989 int lastX;
990 int mCursorLocation;
991 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
992 int mFontY;
993 unsigned skipChars;
994 unsigned mFontHeight;
995 unsigned CursorWidth;
996 bool mRendered;
997 bool HasMask;
998 bool DrawCursor;
999 bool isLocalChange;
1000 bool HasAllowed;
1001 bool HasDisabled;
1002 std::string AllowedList;
1003 std::string DisabledList;
1004 unsigned MinLen;
1005 unsigned MaxLen;
1006};
1007
1008class HardwareKeyboard
1009{
1010public:
1011 HardwareKeyboard(void);
1012 virtual ~HardwareKeyboard();
1013
1014public:
1015 virtual int KeyDown(int key_code);
1016 virtual int KeyUp(int key_code);
1017 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001018
1019 void ConsumeKeyRelease(int key);
1020
1021private:
1022 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -04001023};
1024
Vojtech Bocekede51c52014-02-07 23:58:09 +01001025class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +02001026{
1027public:
1028 GUISliderValue(xml_node<>* node);
1029 virtual ~GUISliderValue();
1030
1031public:
1032 // Render - Render the full object to the GL surface
1033 // Return 0 on success, <0 on error
1034 virtual int Render(void);
1035
1036 // Update - Update any UI component animations (called <= 30 FPS)
1037 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1038 virtual int Update(void);
1039
1040 // SetPos - Update the position of the render object
1041 // Return 0 on success, <0 on error
1042 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1043
1044 // NotifyTouch - Notify of a touch event
1045 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1046 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1047
1048 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001049 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001050
1051 // SetPageFocus - Notify when a page gains or loses focus
1052 virtual void SetPageFocus(int inFocus);
1053
1054protected:
1055 int measureText(const std::string& str);
1056 int valueFromPct(float pct);
1057 float pctFromValue(int value);
1058 void loadValue(bool force = false);
1059
1060 std::string mVariable;
1061 int mMax;
1062 int mMin;
1063 int mValue;
1064 char *mValueStr;
1065 float mValuePct;
1066 std::string mMaxStr;
1067 std::string mMinStr;
1068 Resource *mFont;
1069 GUIText* mLabel;
1070 int mLabelW;
1071 COLOR mTextColor;
1072 COLOR mLineColor;
1073 COLOR mSliderColor;
1074 bool mShowRange;
1075 bool mShowCurr;
1076 int mLineX;
1077 int mLineY;
1078 int mLineH;
1079 int mLinePadding;
1080 int mPadding;
1081 int mSliderY;
1082 int mSliderW;
1083 int mSliderH;
1084 bool mRendered;
1085 int mFontHeight;
1086 GUIAction *mAction;
1087 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001088 int mLineW;
1089 bool mDragging;
1090 Resource *mBackgroundImage;
1091 Resource *mHandleImage;
1092 Resource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001093};
1094
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001095class MouseCursor : public RenderObject
1096{
1097public:
1098 MouseCursor(int posX, int posY);
1099 virtual ~MouseCursor();
1100
1101 virtual int Render(void);
1102 virtual int Update(void);
1103 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1104
1105 void Move(int deltaX, int deltaY);
1106 void GetPos(int& x, int& y);
1107 void LoadData(xml_node<>* node);
1108 void ResetData(int resX, int resY);
1109
1110private:
1111 int m_resX;
1112 int m_resY;
1113 bool m_moved;
1114 float m_speedMultiplier;
1115 COLOR m_color;
1116 Resource *m_image;
1117 bool m_present;
1118};
1119
Dees_Troy51a0e822012-09-05 15:24:24 -04001120// Helper APIs
1121bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1122
1123#endif // _OBJECTS_HEADER
1124