blob: 5e0960777c7e06086e034a2bab91be0b021c9191 [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"
Ethan Yonkerb7a54a32015-10-05 10:16:27 -050037#include "placement.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040038
Ethan Yonker751a85e2014-12-12 16:59:10 -060039#ifndef TW_X_OFFSET
40#define TW_X_OFFSET 0
41#endif
42#ifndef TW_Y_OFFSET
43#define TW_Y_OFFSET 0
44#endif
45
Ethan Yonker74db1572015-10-28 12:44:49 -050046struct translate_later_struct {
47 std::string resource_name; // Name of the string resource for looking up
48 std::string default_value; // Default in case we don't find the string resource
49 std::string color; // Color for the console... normal, highlight, warning, error
50 std::string format; // Formatted extra variables like %i, %s
51 std::string text; // Final, translated, formatted text
52 bool inline_format; // Indicates if the final text includes an inlined format variable
53};
54
Dees_Troy51a0e822012-09-05 15:24:24 -040055class RenderObject
56{
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
Ethan Yonkerd0514ba2015-10-22 14:17:47 -050084 virtual void SetPageFocus(int inFocus __unused) { 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
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500100 virtual int NotifyTouch(TOUCH_STATE state __unused, int x __unused, int y __unused) { 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
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500104 virtual int NotifyKey(int key __unused, bool down __unused) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 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 -0400107
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200108 // Return 0 on success, <0 on error
109 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400110
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200111 // IsInRegion - Checks if the request is handled by this object
thatf8194e22015-01-29 01:05:01 +0100112 // Return 1 if this object handles the request, 0 if not
113 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 -0400114
Dees_Troy51a0e822012-09-05 15:24:24 -0400115protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200116 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400117};
118
Vojtech Bocekede51c52014-02-07 23:58:09 +0100119class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400120{
121public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100122 GUIObject(xml_node<>* node);
123 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400124
125public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200126 bool IsConditionVariable(std::string var);
127 bool isConditionTrue();
128 bool isConditionValid();
Vojtech Bocek07220562014-02-08 02:05:33 +0100129
130 // NotifyVarChange - Notify of a variable change
131 // Returns 0 on success, <0 on error
132 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400133
134protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200135 class Condition
136 {
137 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100138 Condition() {
139 mLastResult = true;
140 }
141
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200142 std::string mVar1;
143 std::string mVar2;
144 std::string mCompareOp;
145 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100146 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200147 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400148
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400150
151protected:
that20fb95d2015-09-12 11:27:47 +0200152 static void LoadConditions(xml_node<>* node, std::vector<Condition>& conditions);
153 static bool isMounted(std::string vol);
154 static bool isConditionTrue(Condition* condition);
155 static bool UpdateConditions(std::vector<Condition>& conditions, const std::string& varName);
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:
that8834a0f2016-01-05 23:29:30 +0100167 // NotifyCharInput - Notify of character input (usually from the onscreen or hardware keyboard)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200168 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
that8834a0f2016-01-05 23:29:30 +0100169 virtual int NotifyCharInput(int ch __unused) { 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;
Ethan Yonkerb7a54a32015-10-05 10:16:27 -0500208 bool scaleWidth;
209 unsigned maxWidth;
Dees_Troy4d12f962012-10-19 13:13:15 -0400210
Dees_Troy51a0e822012-09-05 15:24:24 -0400211protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200212 std::string mText;
213 std::string mLastValue;
214 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400215 COLOR mHighlightColor;
thatf6ed8fc2015-02-14 20:23:16 +0100216 FontResource* mFont;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200217 int mIsStatic;
218 int mVarChanged;
219 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400220 unsigned charSkip;
Dees_Troy51a0e822012-09-05 15:24:24 -0400221};
222
223// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100224class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400225{
226public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200227 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400228
229public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 // Render - Render the full object to the GL surface
231 // Return 0 on success, <0 on error
232 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400233
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200234 // SetRenderPos - Update the position of the object
235 // Return 0 on success, <0 on error
236 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400237
Dees_Troy4d12f962012-10-19 13:13:15 -0400238public:
239 bool isHighlighted;
240
Dees_Troy51a0e822012-09-05 15:24:24 -0400241protected:
thatf6ed8fc2015-02-14 20:23:16 +0100242 ImageResource* mImage;
243 ImageResource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400244};
245
246// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100247class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400248{
249public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200250 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400251
252public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200253 // Render - Render the full object to the GL surface
254 // Return 0 on success, <0 on error
255 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400256
257protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200258 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400259};
260
261// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100262class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400263{
thatc6085482015-01-09 22:12:43 +0100264 friend class ActionThread;
265
Dees_Troy51a0e822012-09-05 15:24:24 -0400266public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200267 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400268
269public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200270 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100271 virtual int NotifyKey(int key, bool down);
Vojtech Bocek07220562014-02-08 02:05:33 +0100272 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
that3f7b1ac2014-12-30 11:30:13 +0100273
274 int doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400275
276protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200277 class Action
278 {
279 public:
280 std::string mFunction;
281 std::string mArg;
282 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400283
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200284 std::vector<Action> mActions;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100285 std::map<int, bool> mKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400286
287protected:
that73a52952015-01-28 23:07:34 +0100288 enum ThreadType { THREAD_NONE, THREAD_ACTION, THREAD_CANCEL };
289
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200290 int getKeyByName(std::string key);
that3f7b1ac2014-12-30 11:30:13 +0100291 int doAction(Action action);
that73a52952015-01-28 23:07:34 +0100292 ThreadType getThreadType(const Action& action);
Dees_Troy51a0e822012-09-05 15:24:24 -0400293 void simulate_progress_bar(void);
Ethan Yonker0d47eb52015-01-09 11:23:19 -0600294 int flash_zip(std::string filename, int* wipe_cache);
thatcc8ddca2015-01-03 01:59:36 +0100295 void reinject_after_flash();
Dees_Troy51a0e822012-09-05 15:24:24 -0400296 void operation_start(const string operation_name);
that3f7b1ac2014-12-30 11:30:13 +0100297 void operation_end(const int operation_status);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000298 time_t Start;
that3f7b1ac2014-12-30 11:30:13 +0100299
300 // map action name to function pointer
301 typedef int (GUIAction::*execFunction)(std::string);
302 typedef std::map<std::string, execFunction> mapFunc;
303 static mapFunc mf;
thatc6085482015-01-09 22:12:43 +0100304 static std::set<std::string> setActionsRunningInCallerThread;
that3f7b1ac2014-12-30 11:30:13 +0100305
306 // GUI actions
307 int reboot(std::string arg);
308 int home(std::string arg);
309 int key(std::string arg);
310 int page(std::string arg);
311 int reload(std::string arg);
312 int readBackup(std::string arg);
313 int set(std::string arg);
314 int clear(std::string arg);
315 int mount(std::string arg);
316 int unmount(std::string arg);
317 int restoredefaultsettings(std::string arg);
318 int copylog(std::string arg);
319 int compute(std::string arg);
320 int setguitimezone(std::string arg);
321 int overlay(std::string arg);
322 int queuezip(std::string arg);
323 int cancelzip(std::string arg);
324 int queueclear(std::string arg);
325 int sleep(std::string arg);
326 int appenddatetobackupname(std::string arg);
327 int generatebackupname(std::string arg);
328 int checkpartitionlist(std::string arg);
329 int getpartitiondetails(std::string arg);
330 int screenshot(std::string arg);
331 int setbrightness(std::string arg);
332
thatc6085482015-01-09 22:12:43 +0100333 // (originally) threaded actions
that3f7b1ac2014-12-30 11:30:13 +0100334 int fileexists(std::string arg);
335 int flash(std::string arg);
336 int wipe(std::string arg);
337 int refreshsizes(std::string arg);
338 int nandroid(std::string arg);
339 int fixpermissions(std::string arg);
340 int dd(std::string arg);
341 int partitionsd(std::string arg);
342 int installhtcdumlock(std::string arg);
343 int htcdumlockrestoreboot(std::string arg);
344 int htcdumlockreflashrecovery(std::string arg);
345 int cmd(std::string arg);
346 int terminalcommand(std::string arg);
347 int killterminal(std::string arg);
348 int reinjecttwrp(std::string arg);
349 int checkbackupname(std::string arg);
350 int decrypt(std::string arg);
351 int adbsideload(std::string arg);
352 int adbsideloadcancel(std::string arg);
353 int openrecoveryscript(std::string arg);
354 int installsu(std::string arg);
355 int fixsu(std::string arg);
356 int decrypt_backup(std::string arg);
357 int repair(std::string arg);
Ethan Yonkera2719152015-05-28 09:44:41 -0500358 int resize(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100359 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);
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500364 int checkpartitionlifetimewrites(std::string arg);
365 int mountsystemtoggle(std::string arg);
Ethan Yonker74db1572015-10-28 12:44:49 -0500366 int setlanguage(std::string arg);
that10ae24f2015-12-26 20:53:51 +0100367 int twcmd(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100368
369 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400370};
371
Vojtech Bocekede51c52014-02-07 23:58:09 +0100372class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400373{
374public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200375 GUIButton(xml_node<>* node);
376 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400377
378public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200379 // Render - Render the full object to the GL surface
380 // Return 0 on success, <0 on error
381 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400382
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200383 // Update - Update any UI component animations (called <= 30 FPS)
384 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
385 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400386
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200387 // SetPos - Update the position of the render object
388 // Return 0 on success, <0 on error
389 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400390
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200391 // NotifyTouch - Notify of a touch event
392 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
393 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400394
395protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200396 GUIImage* mButtonImg;
thatf6ed8fc2015-02-14 20:23:16 +0100397 ImageResource* mButtonIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200398 GUIText* mButtonLabel;
399 GUIAction* mAction;
400 int mTextX, mTextY, mTextW, mTextH;
401 int mIconX, mIconY, mIconW, mIconH;
402 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600403 bool hasHighlightColor;
404 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500405 bool hasFill;
406 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600407 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000408 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400409};
410
Vojtech Bocekede51c52014-02-07 23:58:09 +0100411class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400412{
413public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200414 GUICheckbox(xml_node<>* node);
415 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400416
417public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200418 // Render - Render the full object to the GL surface
419 // Return 0 on success, <0 on error
420 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400421
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200422 // Update - Update any UI component animations (called <= 30 FPS)
423 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
424 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400425
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200426 // SetPos - Update the position of the render object
427 // Return 0 on success, <0 on error
428 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400429
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200430 // NotifyTouch - Notify of a touch event
431 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
432 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400433
434protected:
thatf6ed8fc2015-02-14 20:23:16 +0100435 ImageResource* mChecked;
436 ImageResource* mUnchecked;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200437 GUIText* mLabel;
438 int mTextX, mTextY;
439 int mCheckX, mCheckY, mCheckW, mCheckH;
440 int mLastState;
441 bool mRendered;
442 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400443};
444
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100445class GUIScrollList : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400446{
447public:
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100448 GUIScrollList(xml_node<>* node);
449 virtual ~GUIScrollList();
Dees_Troy51a0e822012-09-05 15:24:24 -0400450
451public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200452 // Render - Render the full object to the GL surface
453 // Return 0 on success, <0 on error
454 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400455
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200456 // Update - Update any UI component animations (called <= 30 FPS)
457 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
458 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400459
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200460 // NotifyTouch - Notify of a touch event
461 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
462 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400463
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200464 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100465 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400466
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200467 // SetPos - Update the position of the render object
468 // Return 0 on success, <0 on error
469 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400470
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200471 // SetPageFocus - Notify when a page gains or loses focus
472 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400473
474protected:
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100475 // derived classes need to implement these
476 // get number of items
477 virtual size_t GetItemCount() { return 0; }
that0af77952015-02-25 08:52:19 +0100478 // render a single item in rect (mRenderX, yPos, mRenderW, actualItemHeight)
479 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100480 // an item was selected
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500481 virtual void NotifySelect(size_t item_selected __unused) {}
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100482
that0af77952015-02-25 08:52:19 +0100483 // render a standard-layout list item with optional icon and text
484 void RenderStdItem(int yPos, bool selected, ImageResource* icon, const char* text, int iconAndTextH = 0);
485
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100486 enum { NO_ITEM = (size_t)-1 };
487 // returns item index at coordinates or NO_ITEM if there is no item there
488 size_t HitTestItem(int x, int y);
489
490 // Called by the derived class to set the max icon size so we can calculate the proper actualItemHeight and center smaller icons if the icon size varies
491 void SetMaxIconSize(int w, int h);
492
493 // This will make sure that the item indicated by list_index is visible on the screen
494 void SetVisibleListLocation(size_t list_index);
495
496 // Handle scrolling changes for drags and kinetic scrolling
497 void HandleScrolling();
498
that9876ac32015-02-15 21:40:59 +0100499 // Returns many full rows the list is capable of displaying
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100500 int GetDisplayItemCount();
501
502 // Returns the size in pixels of a partial item or row size
503 int GetDisplayRemainder();
504
505protected:
506 // Background
507 COLOR mBackgroundColor;
thatf6ed8fc2015-02-14 20:23:16 +0100508 ImageResource* mBackground; // background image, if any, automatically centered
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100509
510 // Header
511 COLOR mHeaderBackgroundColor;
512 COLOR mHeaderFontColor;
513 std::string mHeaderText; // Original header text without parsing any variables
514 std::string mLastHeaderValue; // Header text after parsing variables
that9876ac32015-02-15 21:40:59 +0100515 bool mHeaderIsStatic; // indicates if the header is static (no need to check for changes in NotifyVarChange)
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100516 int mHeaderH; // actual header height including font, icon, padding, and separator heights
thatf6ed8fc2015-02-14 20:23:16 +0100517 ImageResource* mHeaderIcon;
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100518 int mHeaderIconHeight, mHeaderIconWidth; // width and height of the header icon if present
519 int mHeaderSeparatorH; // Height of the separator between header and list items
520 COLOR mHeaderSeparatorColor; // color of the header separator
521
522 // Per-item layout
thatf6ed8fc2015-02-14 20:23:16 +0100523 FontResource* mFont;
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100524 COLOR mFontColor;
that9876ac32015-02-15 21:40:59 +0100525 bool hasHighlightColor; // indicates if a highlight color was set
526 COLOR mHighlightColor; // background row highlight color
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100527 COLOR mFontHighlightColor;
528 int mFontHeight;
529 int actualItemHeight; // Actual height of each item in pixels including max icon size, font size, and padding
530 int maxIconWidth, maxIconHeight; // max icon width and height for the list, set by derived class in SetMaxIconSize
531 int mItemSpacing; // stores the spacing or padding on the y axis, part of the actualItemHeight
532 int mSeparatorH; // Height of the separator between items
533 COLOR mSeparatorColor; // color of the separator that is between items
534
thata9998212015-02-19 22:51:24 +0100535 // Scrollbar
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100536 int mFastScrollW; // width of the fastscroll area
537 int mFastScrollLineW; // width of the line for fastscroll rendering
538 int mFastScrollRectW; // width of the rectangle for fastscroll
thata9998212015-02-19 22:51:24 +0100539 int mFastScrollRectH; // minimum height of the rectangle for fastscroll
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100540 COLOR mFastScrollLineColor;
541 COLOR mFastScrollRectColor;
thata9998212015-02-19 22:51:24 +0100542
543 // Scrolling and dynamic state
544 int mFastScrollRectCurrentY; // current top of fastscroll rect relative to list top
545 int mFastScrollRectCurrentH; // current height of fastscroll rect
546 int mFastScrollRectTouchY; // offset from top of fastscroll rect where the user initially touched
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100547 bool hasScroll; // indicates that we have enough items in the list to scroll
548 int firstDisplayedItem; // this item goes at the top of the display list - may only be partially visible
549 int scrollingSpeed; // on a touch release, this is set based on the difference in the y-axis between the last 2 touches and indicates how fast the kinetic scrolling will go
550 int y_offset; // this is how many pixels offset in the y axis for per pixel scrolling, is always <= 0 and should never be < -actualItemHeight
that8d46c092015-02-26 01:30:04 +0100551 bool allowSelection; // true if touched item can be selected, false for pure read-only lists and the console
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100552 size_t selectedItem; // selected item index after the initial touch, set to -1 if we are scrolling
553 int touchDebounce; // debounce for touches, minimum of 6 pixels but may be larger calculated based actualItemHeight / 3
554 int lastY, last2Y; // last 2 touch locations, used for tracking kinetic scroll speed
555 int fastScroll; // indicates that the inital touch was inside the fastscroll region - makes for easier fast scrolling as the touches don't have to stay within the fast scroll region and you drag your finger
556 int mUpdate; // indicates that a change took place and we need to re-render
Ethan Yonker44925ad2015-07-22 12:33:59 -0500557 bool AddLines(std::vector<std::string>* origText, std::vector<std::string>* origColor, size_t* lastCount, std::vector<std::string>* rText, std::vector<std::string>* rColor);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100558};
559
560class GUIFileSelector : public GUIScrollList
561{
562public:
563 GUIFileSelector(xml_node<>* node);
564 virtual ~GUIFileSelector();
565
566public:
567 // Update - Update any UI component animations (called <= 30 FPS)
568 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
569 virtual int Update(void);
570
571 // NotifyVarChange - Notify of a variable change
572 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
573
574 // SetPageFocus - Notify when a page gains or loses focus
575 virtual void SetPageFocus(int inFocus);
576
577 virtual size_t GetItemCount();
that0af77952015-02-25 08:52:19 +0100578 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100579 virtual void NotifySelect(size_t item_selected);
580
581protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200582 struct FileData {
583 std::string fileName;
584 unsigned char fileType; // Uses d_type format from struct dirent
585 mode_t protection; // Uses mode_t format from stat
586 uid_t userId;
587 gid_t groupId;
588 off_t fileSize;
589 time_t lastAccess; // Uses time_t format from stat
590 time_t lastModified; // Uses time_t format from stat
591 time_t lastStatChange; // Uses time_t format from stat
592 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400593
594protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200595 virtual int GetFileList(const std::string folder);
596 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400597
598protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200599 std::vector<FileData> mFolderList;
600 std::vector<FileData> mFileList;
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100601 std::string mPathVar; // current path displayed, saved in the data manager
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600602 std::string mPathDefault; // default value for the path if none is set in mPathVar
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100603 std::string mExtn; // used for filtering the file list, for example, *.zip
604 std::string mVariable; // set when the user selects an item, pull path like /path/to/foo
605 std::string mSortVariable; // data manager variable used to change the sorting of files
606 std::string mSelection; // set when the user selects an item without the full path like selecting /path/to/foo would just be set to foo
607 int mShowFolders, mShowFiles; // indicates if the list should show folders and/or files
608 int mShowNavFolders; // indicates if the list should include the "up a level" item and allow you to traverse folders (nav folders are disabled for the restore list, for instance)
609 static int mSortOrder; // must be static because it is used by the static function fileSort
thatf6ed8fc2015-02-14 20:23:16 +0100610 ImageResource* mFolderIcon;
611 ImageResource* mFileIcon;
Dees_Troyc0583f52013-02-28 11:19:57 -0600612 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400613};
614
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100615class GUIListBox : public GUIScrollList
Dees_Troy51a0e822012-09-05 15:24:24 -0400616{
617public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200618 GUIListBox(xml_node<>* node);
619 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400620
621public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200622 // Update - Update any UI component animations (called <= 30 FPS)
623 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
624 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400625
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200626 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100627 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400628
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200629 // SetPageFocus - Notify when a page gains or loses focus
630 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400631
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100632 virtual size_t GetItemCount();
that0af77952015-02-25 08:52:19 +0100633 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100634 virtual void NotifySelect(size_t item_selected);
635
Dees_Troy51a0e822012-09-05 15:24:24 -0400636protected:
that8ab5c132015-09-13 23:00:54 +0200637 struct ListItem {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200638 std::string displayName;
Ethan Yonker56ce3322015-07-30 15:04:32 -0500639 std::string variableName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400640 std::string variableValue;
641 unsigned int selected;
thatc01391c2015-07-09 00:19:58 +0200642 GUIAction* action;
that8ab5c132015-09-13 23:00:54 +0200643 std::vector<Condition> mConditions;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200644 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400645
646protected:
that8ab5c132015-09-13 23:00:54 +0200647 std::vector<ListItem> mListItems;
648 std::vector<size_t> mVisibleItems; // contains indexes in mListItems of visible items only
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200649 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400650 std::string currentValue;
thatf6ed8fc2015-02-14 20:23:16 +0100651 ImageResource* mIconSelected;
652 ImageResource* mIconUnselected;
Ethan Yonker56ce3322015-07-30 15:04:32 -0500653 bool isCheckList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400654};
655
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100656class GUIPartitionList : public GUIScrollList
Dees_Troya13d74f2013-03-24 08:54:55 -0500657{
658public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200659 GUIPartitionList(xml_node<>* node);
660 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500661
662public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200663 // Update - Update any UI component animations (called <= 30 FPS)
664 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100665 virtual int Update();
Dees_Troya13d74f2013-03-24 08:54:55 -0500666
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200667 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100668 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500669
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200670 // SetPageFocus - Notify when a page gains or loses focus
671 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500672
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100673 virtual size_t GetItemCount();
that0af77952015-02-25 08:52:19 +0100674 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100675 virtual void NotifySelect(size_t item_selected);
676
Dees_Troya13d74f2013-03-24 08:54:55 -0500677protected:
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100678 void MatchList();
Ethan Yonkercfd65092015-02-14 10:39:21 -0600679 void SetPosition();
Dees_Troya13d74f2013-03-24 08:54:55 -0500680
681protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200682 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500683 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200684 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500685 std::string selectedList;
686 std::string currentValue;
Dees_Troya13d74f2013-03-24 08:54:55 -0500687 std::string mLastValue;
thatf6ed8fc2015-02-14 20:23:16 +0100688 ImageResource* mIconSelected;
689 ImageResource* mIconUnselected;
Dees_Troya13d74f2013-03-24 08:54:55 -0500690 bool updateList;
691};
692
Ethan Yonker44925ad2015-07-22 12:33:59 -0500693class GUITextBox : public GUIScrollList
694{
695public:
696 GUITextBox(xml_node<>* node);
697
698public:
699 // Update - Update any UI component animations (called <= 30 FPS)
700 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
701 virtual int Update(void);
702
703 // NotifyVarChange - Notify of a variable change
704 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
705
706 // ScrollList interface
707 virtual size_t GetItemCount();
708 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
709 virtual void NotifySelect(size_t item_selected);
710protected:
711
712 size_t mLastCount;
713 bool mIsStatic;
714 std::vector<std::string> mLastValue; // Parsed text - parsed for variables but not word wrapped
715 std::vector<std::string> mText; // Original text - not parsed for variables and not word wrapped
716 std::vector<std::string> rText; // Rendered text - what we actually see
717
718};
719
that8d46c092015-02-26 01:30:04 +0100720class GUIConsole : public GUIScrollList
721{
722public:
723 GUIConsole(xml_node<>* node);
724
725public:
726 // Render - Render the full object to the GL surface
727 // Return 0 on success, <0 on error
728 virtual int Render(void);
729
730 // Update - Update any UI component animations (called <= 30 FPS)
731 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
732 virtual int Update(void);
733
734 // IsInRegion - Checks if the request is handled by this object
735 // Return 1 if this object handles the request, 0 if not
736 virtual int IsInRegion(int x, int y);
737
738 // NotifyTouch - Notify of a touch event
739 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
740 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
741
742 // ScrollList interface
743 virtual size_t GetItemCount();
744 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
745 virtual void NotifySelect(size_t item_selected);
Ethan Yonker74db1572015-10-28 12:44:49 -0500746 static void Translate_Now();
that8d46c092015-02-26 01:30:04 +0100747protected:
748 enum SlideoutState
749 {
750 hidden = 0,
751 visible,
752 request_hide,
753 request_show
754 };
755
756 ImageResource* mSlideoutImage;
757 size_t mLastCount; // lines from gConsole that are already split and copied into rConsole
758 bool scrollToEnd; // true if we want to keep tracking the last line
759 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
760 int mSlideout;
761 SlideoutState mSlideoutState;
762 std::vector<std::string> rConsole;
763 std::vector<std::string> rConsoleColor;
764
765protected:
that8d46c092015-02-26 01:30:04 +0100766 int RenderSlideout(void);
767 int RenderConsole(void);
768};
769
Dees_Troy51a0e822012-09-05 15:24:24 -0400770// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100771class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400772{
773public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200774 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400775
776public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200777 // Render - Render the full object to the GL surface
778 // Return 0 on success, <0 on error
779 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400780
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200781 // Update - Update any UI component animations (called <= 30 FPS)
782 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
783 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400784
785protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200786 AnimationResource* mAnimation;
787 int mFrame;
788 int mFPS;
789 int mLoop;
790 int mRender;
791 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400792};
793
Vojtech Bocekede51c52014-02-07 23:58:09 +0100794class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400795{
796public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200797 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400798
799public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200800 // Render - Render the full object to the GL surface
801 // Return 0 on success, <0 on error
802 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400803
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200804 // Update - Update any UI component animations (called <= 30 FPS)
805 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
806 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400807
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200808 // NotifyVarChange - Notify of a variable change
809 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100810 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400811
812protected:
thatf6ed8fc2015-02-14 20:23:16 +0100813 ImageResource* mEmptyBar;
814 ImageResource* mFullBar;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200815 std::string mMinValVar;
816 std::string mMaxValVar;
817 std::string mCurValVar;
818 float mSlide;
819 float mSlideInc;
820 int mSlideFrames;
821 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400822
823protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200824 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400825};
826
Vojtech Bocekede51c52014-02-07 23:58:09 +0100827class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400828{
829public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200830 GUISlider(xml_node<>* node);
831 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400832
833public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200834 // Render - Render the full object to the GL surface
835 // Return 0 on success, <0 on error
836 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400837
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200838 // Update - Update any UI component animations (called <= 30 FPS)
839 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
840 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400841
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200842 // NotifyTouch - Notify of a touch event
843 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
844 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400845
846protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200847 GUIAction* sAction;
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600848 GUIText* sSliderLabel;
thatf6ed8fc2015-02-14 20:23:16 +0100849 ImageResource* sSlider;
850 ImageResource* sSliderUsed;
851 ImageResource* sTouch;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200852 int sTouchW, sTouchH;
853 int sCurTouchX;
854 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400855};
856
that8834a0f2016-01-05 23:29:30 +0100857// these are ASCII codes reported via NotifyCharInput
858// other special keys (arrows etc.) are reported via NotifyKey
859#define KEYBOARD_ACTION 13 // CR
860#define KEYBOARD_BACKSPACE 8 // Backspace
861#define KEYBOARD_TAB 9 // Tab
862#define KEYBOARD_SWIPE_LEFT 21 // Ctrl+U to delete line, same as in readline (used by shell etc.)
863#define KEYBOARD_SWIPE_RIGHT 11 // Ctrl+K, same as in readline
Dees_Troy51a0e822012-09-05 15:24:24 -0400864
Vojtech Bocekede51c52014-02-07 23:58:09 +0100865class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400866{
867public:
868 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200869 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400870
871public:
872 virtual int Render(void);
873 virtual int Update(void);
874 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
875 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
that8834a0f2016-01-05 23:29:30 +0100876 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400877
878protected:
thate79878b2015-03-14 23:07:23 +0100879 struct Key
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200880 {
that8834a0f2016-01-05 23:29:30 +0100881 int key; // positive: ASCII/Unicode code; negative: Linux key code (KEY_*)
882 int longpresskey;
that1a7ba972015-02-01 19:48:19 +0100883 int end_x;
884 int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200885 };
thate79878b2015-03-14 23:07:23 +0100886 int ParseKey(const char* keyinfo, Key& key, int& Xindex, int keyWidth, bool longpress);
thatf256b722015-05-23 20:44:12 +0200887 void LoadKeyLabels(xml_node<>* parent, int layout);
thatf6b20662015-06-25 21:51:37 +0200888 void DrawKey(Key& key, int keyX, int keyY, int keyW, int keyH);
that8834a0f2016-01-05 23:29:30 +0100889 int KeyCharToCtrlChar(int key);
thatd86f49d2015-03-15 00:56:57 +0100890
891 enum {
892 MAX_KEYBOARD_LAYOUTS = 5,
893 MAX_KEYBOARD_ROWS = 9,
894 MAX_KEYBOARD_KEYS = 20
895 };
896 struct Layout
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600897 {
thatd86f49d2015-03-15 00:56:57 +0100898 ImageResource* keyboardImg;
that8834a0f2016-01-05 23:29:30 +0100899 Key keys[MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
thatd86f49d2015-03-15 00:56:57 +0100900 int row_end_y[MAX_KEYBOARD_ROWS];
901 bool is_caps;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600902 int revert_layout;
903 };
thatd86f49d2015-03-15 00:56:57 +0100904 Layout layouts[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400905
thatf256b722015-05-23 20:44:12 +0200906 struct KeyLabel
907 {
that8834a0f2016-01-05 23:29:30 +0100908 int key; // same as in struct Key
thatf256b722015-05-23 20:44:12 +0200909 int layout_from; // 1-based; 0 for labels that apply to all layouts
910 int layout_to; // same as Key.layout
911 string text; // key label text
912 ImageResource* image; // image (overrides text if defined)
913 };
914 std::vector<KeyLabel> mKeyLabels;
915
thate79878b2015-03-14 23:07:23 +0100916 // Find key at screen coordinates
917 Key* HitTestKey(int x, int y);
918
Dees_Troy51a0e822012-09-05 15:24:24 -0400919 bool mRendered;
920 std::string mVariable;
that1a7ba972015-02-01 19:48:19 +0100921 int currentLayout;
thatd86f49d2015-03-15 00:56:57 +0100922 bool CapsLockOn;
that8834a0f2016-01-05 23:29:30 +0100923 static bool CtrlActive; // all keyboards share a common Control key state so that the Control key can be on a separate keyboard instance
thatf6b20662015-06-25 21:51:37 +0200924 int highlightRenderCount;
925 Key* currentKey;
that8834a0f2016-01-05 23:29:30 +0100926 bool hasHighlight, hasCapsHighlight, hasCtrlHighlight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400927 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600928 COLOR mCapsHighlightColor;
that8834a0f2016-01-05 23:29:30 +0100929 COLOR mCtrlHighlightColor;
thatf256b722015-05-23 20:44:12 +0200930 COLOR mFontColor; // for centered key labels
931 COLOR mFontColorSmall; // for centered key labels
932 FontResource* mFont; // for main key labels
933 FontResource* mSmallFont; // for key labels like "?123"
934 FontResource* mLongpressFont; // for the small longpress label in the upper right corner
thatf6b20662015-06-25 21:51:37 +0200935 int longpressOffsetX, longpressOffsetY; // distance of the longpress label from the key corner
thatf256b722015-05-23 20:44:12 +0200936 COLOR mLongpressFontColor;
937 COLOR mBackgroundColor; // keyboard background color
938 COLOR mKeyColorAlphanumeric; // key background color
939 COLOR mKeyColorOther; // key background color
940 int mKeyMarginX, mKeyMarginY; // space around key boxes - applied to left/right and top/bottom
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 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400948 virtual ~GUIInput();
949
950public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200951 // Render - Render the full object to the GL surface
952 // Return 0 on success, <0 on error
953 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400954
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200955 // Update - Update any UI component animations (called <= 30 FPS)
956 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
957 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400958
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200959 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100960 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400961
962 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200963 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
964 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400965
that8834a0f2016-01-05 23:29:30 +0100966 virtual int NotifyKey(int key, bool down);
967 virtual int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -0400968
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;
thatf6ed8fc2015-02-14 20:23:16 +0100978 ImageResource* mBackground;
979 ImageResource* mCursor;
980 FontResource* mFont;
Dees_Troy51a0e822012-09-05 15:24:24 -0400981 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:
thatf37aec22015-02-01 13:38:35 +01001011 HardwareKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -04001012 virtual ~HardwareKeyboard();
1013
1014public:
thatf37aec22015-02-01 13:38:35 +01001015 // called by the input handler for key events
1016 int KeyDown(int key_code);
1017 int KeyUp(int key_code);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001018
thatf37aec22015-02-01 13:38:35 +01001019 // called by the input handler when holding a key down
1020 int KeyRepeat();
1021
1022 // called by multi-key actions to suppress key-release notifications
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001023 void ConsumeKeyRelease(int key);
1024
that8834a0f2016-01-05 23:29:30 +01001025 bool IsKeyDown(int key_code);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001026private:
that8834a0f2016-01-05 23:29:30 +01001027 int mLastKey;
thatf37aec22015-02-01 13:38:35 +01001028 int mLastKeyChar;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001029 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -04001030};
1031
Vojtech Bocekede51c52014-02-07 23:58:09 +01001032class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +02001033{
1034public:
1035 GUISliderValue(xml_node<>* node);
1036 virtual ~GUISliderValue();
1037
1038public:
1039 // Render - Render the full object to the GL surface
1040 // Return 0 on success, <0 on error
1041 virtual int Render(void);
1042
1043 // Update - Update any UI component animations (called <= 30 FPS)
1044 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1045 virtual int Update(void);
1046
1047 // SetPos - Update the position of the render object
1048 // Return 0 on success, <0 on error
1049 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1050
1051 // NotifyTouch - Notify of a touch event
1052 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1053 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1054
1055 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001056 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001057
1058 // SetPageFocus - Notify when a page gains or loses focus
1059 virtual void SetPageFocus(int inFocus);
1060
1061protected:
1062 int measureText(const std::string& str);
1063 int valueFromPct(float pct);
1064 float pctFromValue(int value);
1065 void loadValue(bool force = false);
1066
1067 std::string mVariable;
1068 int mMax;
1069 int mMin;
1070 int mValue;
1071 char *mValueStr;
1072 float mValuePct;
1073 std::string mMaxStr;
1074 std::string mMinStr;
thatf6ed8fc2015-02-14 20:23:16 +01001075 FontResource *mFont;
Vojtech Bocek85932342013-04-01 22:11:33 +02001076 GUIText* mLabel;
1077 int mLabelW;
1078 COLOR mTextColor;
1079 COLOR mLineColor;
1080 COLOR mSliderColor;
1081 bool mShowRange;
1082 bool mShowCurr;
1083 int mLineX;
1084 int mLineY;
1085 int mLineH;
1086 int mLinePadding;
1087 int mPadding;
1088 int mSliderY;
1089 int mSliderW;
1090 int mSliderH;
1091 bool mRendered;
1092 int mFontHeight;
1093 GUIAction *mAction;
1094 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001095 int mLineW;
1096 bool mDragging;
thatf6ed8fc2015-02-14 20:23:16 +01001097 ImageResource *mBackgroundImage;
1098 ImageResource *mHandleImage;
1099 ImageResource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001100};
1101
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001102class MouseCursor : public RenderObject
1103{
1104public:
1105 MouseCursor(int posX, int posY);
1106 virtual ~MouseCursor();
1107
1108 virtual int Render(void);
1109 virtual int Update(void);
1110 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1111
1112 void Move(int deltaX, int deltaY);
1113 void GetPos(int& x, int& y);
1114 void LoadData(xml_node<>* node);
1115 void ResetData(int resX, int resY);
1116
1117private:
1118 int m_resX;
1119 int m_resY;
1120 bool m_moved;
1121 float m_speedMultiplier;
1122 COLOR m_color;
thatf6ed8fc2015-02-14 20:23:16 +01001123 ImageResource *m_image;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001124 bool m_present;
1125};
1126
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001127class GUIPatternPassword : public GUIObject, public RenderObject, public ActionObject
1128{
1129public:
1130 GUIPatternPassword(xml_node<>* node);
1131 virtual ~GUIPatternPassword();
1132
1133public:
1134 virtual int Render(void);
1135 virtual int Update(void);
1136 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Aleksa Saraib25a1832015-12-31 17:36:00 +01001137 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001138 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1139
1140protected:
1141 void CalculateDotPositions();
1142 void ResetActiveDots();
1143 void ConnectDot(int dot_idx);
1144 void ConnectIntermediateDots(int dot_idx);
Aleksa Saraib25a1832015-12-31 17:36:00 +01001145 void Resize(size_t size);
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001146 int InDot(int x, int y);
1147 bool DotUsed(int dot_idx);
Aleksa Saraib25a1832015-12-31 17:36:00 +01001148 std::string GeneratePassphrase();
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001149 void PatternDrawn();
1150
1151 struct Dot {
1152 int x;
1153 int y;
1154 bool active;
1155 };
1156
Aleksa Saraib25a1832015-12-31 17:36:00 +01001157 std::string mSizeVar;
1158 size_t mGridSize;
1159
1160 Dot* mDots;
1161 int* mConnectedDots;
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001162 size_t mConnectedDotsLen;
1163 int mCurLineX;
1164 int mCurLineY;
1165 bool mTrackingTouch;
1166 bool mNeedRender;
1167
1168 COLOR mDotColor;
1169 COLOR mActiveDotColor;
1170 COLOR mLineColor;
1171 ImageResource *mDotImage;
1172 ImageResource *mActiveDotImage;
1173 gr_surface mDotCircle;
1174 gr_surface mActiveDotCircle;
1175 int mDotRadius;
1176 int mLineWidth;
1177
1178 std::string mPassVar;
1179 GUIAction *mAction;
1180 int mUpdate;
1181};
1182
1183
Dees_Troy51a0e822012-09-05 15:24:24 -04001184// Helper APIs
Ethan Yonker21ff02a2015-02-18 14:35:00 -06001185xml_node<>* FindNode(xml_node<>* parent, const char* nodename, int depth = 0);
thatf6ed8fc2015-02-14 20:23:16 +01001186std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue = "");
1187int LoadAttrInt(xml_node<>* element, const char* attrname, int defaultvalue = 0);
1188int LoadAttrIntScaleX(xml_node<>* element, const char* attrname, int defaultvalue = 0);
1189int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalue = 0);
Ethan Yonker21ff02a2015-02-18 14:35:00 -06001190COLOR LoadAttrColor(xml_node<>* element, const char* attrname, bool* found_color, COLOR defaultvalue = COLOR(0,0,0,0));
thatf6ed8fc2015-02-14 20:23:16 +01001191COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue = COLOR(0,0,0,0));
1192FontResource* LoadAttrFont(xml_node<>* element, const char* attrname);
1193ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname);
1194AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname);
1195
Ethan Yonkerb7a54a32015-10-05 10:16:27 -05001196bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, Placement* placement = NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -04001197
1198#endif // _OBJECTS_HEADER
1199