blob: 2a95022d33f1aa4af52aa14efae9e2cec0f58905 [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
Dees_Troy51a0e822012-09-05 15:24:24 -040046class RenderObject
47{
48public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
50 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040051
52public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020053 // Render - Render the full object to the GL surface
54 // Return 0 on success, <0 on error
55 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040056
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020057 // Update - Update any UI component animations (called <= 30 FPS)
58 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
59 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040060
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020061 // GetRenderPos - Returns the current position of the object
62 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 -040063
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020064 // SetRenderPos - Update the position of the object
65 // Return 0 on success, <0 on error
66 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 -040067
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020068 // GetPlacement - Returns the current placement
69 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040070
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020071 // SetPlacement - Update the current placement
72 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040073
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 // SetPageFocus - Notify when a page gains or loses focus
that1964d192016-01-07 00:41:03 +010075 // TODO: This should be named NotifyPageFocus for consistency
Ethan Yonkerd0514ba2015-10-22 14:17:47 -050076 virtual void SetPageFocus(int inFocus __unused) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040077
78protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020079 int mRenderX, mRenderY, mRenderW, mRenderH;
80 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040081};
82
83class ActionObject
84{
85public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020086 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
87 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040088
89public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020090 // NotifyTouch - Notify of a touch event
91 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
Ethan Yonkerd0514ba2015-10-22 14:17:47 -050092 virtual int NotifyTouch(TOUCH_STATE state __unused, int x __unused, int y __unused) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040093
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020094 // NotifyKey - Notify of a key press
95 // 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 -050096 virtual int NotifyKey(int key __unused, bool down __unused) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -040097
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020098 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 -040099
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 // Return 0 on success, <0 on error
101 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400102
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200103 // IsInRegion - Checks if the request is handled by this object
thatf8194e22015-01-29 01:05:01 +0100104 // Return 1 if this object handles the request, 0 if not
105 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 -0400106
Dees_Troy51a0e822012-09-05 15:24:24 -0400107protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200108 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400109};
110
Vojtech Bocekede51c52014-02-07 23:58:09 +0100111class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400112{
113public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100114 GUIObject(xml_node<>* node);
115 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400116
117public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200118 bool IsConditionVariable(std::string var);
119 bool isConditionTrue();
120 bool isConditionValid();
Vojtech Bocek07220562014-02-08 02:05:33 +0100121
122 // NotifyVarChange - Notify of a variable change
123 // Returns 0 on success, <0 on error
124 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400125
126protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200127 class Condition
128 {
129 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100130 Condition() {
131 mLastResult = true;
132 }
133
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200134 std::string mVar1;
135 std::string mVar2;
136 std::string mCompareOp;
137 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100138 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200139 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400140
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200141 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400142
143protected:
that20fb95d2015-09-12 11:27:47 +0200144 static void LoadConditions(xml_node<>* node, std::vector<Condition>& conditions);
145 static bool isMounted(std::string vol);
146 static bool isConditionTrue(Condition* condition);
147 static bool UpdateConditions(std::vector<Condition>& conditions, const std::string& varName);
Vojtech Bocek07220562014-02-08 02:05:33 +0100148
149 bool mConditionsResult;
Dees_Troy51a0e822012-09-05 15:24:24 -0400150};
151
152class InputObject
153{
154public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200155 InputObject() { HasInputFocus = 0; }
156 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400157
158public:
that8834a0f2016-01-05 23:29:30 +0100159 // NotifyCharInput - Notify of character input (usually from the onscreen or hardware keyboard)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
that8834a0f2016-01-05 23:29:30 +0100161 virtual int NotifyCharInput(int ch __unused) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400162
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200163 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400164
165protected:
166 int HasInputFocus;
167};
168
169// Derived Objects
170// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100171class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400172{
173public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200174 // w and h may be ignored, in which case, no bounding box is applied
175 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400176
177public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200178 // Render - Render the full object to the GL surface
179 // Return 0 on success, <0 on error
180 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400181
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200182 // Update - Update any UI component animations (called <= 30 FPS)
183 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
184 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400185
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200186 // Retrieve the size of the current string (dynamic strings may change per call)
187 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400188
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200189 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100190 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400191
192 // Set maximum width in pixels
193 virtual int SetMaxWidth(unsigned width);
194
Ethan Yonkera5db7122016-03-14 15:47:09 -0500195 void SetText(string newtext);
Dees_Troy51a0e822012-09-05 15:24:24 -0400196
Dees_Troy4d12f962012-10-19 13:13:15 -0400197public:
198 bool isHighlighted;
Ethan Yonkerb7a54a32015-10-05 10:16:27 -0500199 bool scaleWidth;
200 unsigned maxWidth;
Dees_Troy4d12f962012-10-19 13:13:15 -0400201
Dees_Troy51a0e822012-09-05 15:24:24 -0400202protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200203 std::string mText;
204 std::string mLastValue;
205 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400206 COLOR mHighlightColor;
thatf6ed8fc2015-02-14 20:23:16 +0100207 FontResource* mFont;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200208 int mIsStatic;
209 int mVarChanged;
210 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400211};
212
213// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100214class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400215{
216public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200217 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400218
219public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200220 // Render - Render the full object to the GL surface
221 // Return 0 on success, <0 on error
222 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400223
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200224 // SetRenderPos - Update the position of the object
225 // Return 0 on success, <0 on error
226 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400227
Dees_Troy4d12f962012-10-19 13:13:15 -0400228public:
229 bool isHighlighted;
230
Dees_Troy51a0e822012-09-05 15:24:24 -0400231protected:
thatf6ed8fc2015-02-14 20:23:16 +0100232 ImageResource* mImage;
233 ImageResource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400234};
235
236// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100237class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400238{
239public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200240 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400241
242public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200243 // Render - Render the full object to the GL surface
244 // Return 0 on success, <0 on error
245 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400246
247protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200248 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400249};
250
251// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100252class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400253{
thatc6085482015-01-09 22:12:43 +0100254 friend class ActionThread;
255
Dees_Troy51a0e822012-09-05 15:24:24 -0400256public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200257 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400258
259public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200260 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100261 virtual int NotifyKey(int key, bool down);
Vojtech Bocek07220562014-02-08 02:05:33 +0100262 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
that3f7b1ac2014-12-30 11:30:13 +0100263
264 int doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400265
266protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200267 class Action
268 {
269 public:
270 std::string mFunction;
271 std::string mArg;
272 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400273
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200274 std::vector<Action> mActions;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100275 std::map<int, bool> mKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400276
277protected:
that73a52952015-01-28 23:07:34 +0100278 enum ThreadType { THREAD_NONE, THREAD_ACTION, THREAD_CANCEL };
279
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200280 int getKeyByName(std::string key);
that3f7b1ac2014-12-30 11:30:13 +0100281 int doAction(Action action);
that73a52952015-01-28 23:07:34 +0100282 ThreadType getThreadType(const Action& action);
Dees_Troy51a0e822012-09-05 15:24:24 -0400283 void simulate_progress_bar(void);
Ethan Yonker0d47eb52015-01-09 11:23:19 -0600284 int flash_zip(std::string filename, int* wipe_cache);
thatcc8ddca2015-01-03 01:59:36 +0100285 void reinject_after_flash();
Dees_Troy51a0e822012-09-05 15:24:24 -0400286 void operation_start(const string operation_name);
that3f7b1ac2014-12-30 11:30:13 +0100287 void operation_end(const int operation_status);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000288 time_t Start;
that3f7b1ac2014-12-30 11:30:13 +0100289
290 // map action name to function pointer
291 typedef int (GUIAction::*execFunction)(std::string);
292 typedef std::map<std::string, execFunction> mapFunc;
293 static mapFunc mf;
thatc6085482015-01-09 22:12:43 +0100294 static std::set<std::string> setActionsRunningInCallerThread;
that3f7b1ac2014-12-30 11:30:13 +0100295
296 // GUI actions
297 int reboot(std::string arg);
298 int home(std::string arg);
299 int key(std::string arg);
300 int page(std::string arg);
301 int reload(std::string arg);
302 int readBackup(std::string arg);
303 int set(std::string arg);
304 int clear(std::string arg);
305 int mount(std::string arg);
306 int unmount(std::string arg);
307 int restoredefaultsettings(std::string arg);
308 int copylog(std::string arg);
309 int compute(std::string arg);
310 int setguitimezone(std::string arg);
311 int overlay(std::string arg);
312 int queuezip(std::string arg);
313 int cancelzip(std::string arg);
314 int queueclear(std::string arg);
315 int sleep(std::string arg);
Matt Mower9a2a2052016-05-31 21:31:22 -0500316 int sleepcounter(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100317 int appenddatetobackupname(std::string arg);
318 int generatebackupname(std::string arg);
319 int checkpartitionlist(std::string arg);
320 int getpartitiondetails(std::string arg);
321 int screenshot(std::string arg);
322 int setbrightness(std::string arg);
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -0600323 int checkforapp(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100324
thatc6085482015-01-09 22:12:43 +0100325 // (originally) threaded actions
that3f7b1ac2014-12-30 11:30:13 +0100326 int fileexists(std::string arg);
327 int flash(std::string arg);
328 int wipe(std::string arg);
329 int refreshsizes(std::string arg);
330 int nandroid(std::string arg);
Ethan Yonkerb5fab762016-01-28 14:03:33 -0600331 int fixcontexts(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100332 int fixpermissions(std::string arg);
333 int dd(std::string arg);
334 int partitionsd(std::string arg);
335 int installhtcdumlock(std::string arg);
336 int htcdumlockrestoreboot(std::string arg);
337 int htcdumlockreflashrecovery(std::string arg);
338 int cmd(std::string arg);
339 int terminalcommand(std::string arg);
340 int killterminal(std::string arg);
341 int reinjecttwrp(std::string arg);
342 int checkbackupname(std::string arg);
343 int decrypt(std::string arg);
344 int adbsideload(std::string arg);
345 int adbsideloadcancel(std::string arg);
346 int openrecoveryscript(std::string arg);
347 int installsu(std::string arg);
348 int fixsu(std::string arg);
349 int decrypt_backup(std::string arg);
350 int repair(std::string arg);
Ethan Yonkera2719152015-05-28 09:44:41 -0500351 int resize(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100352 int changefilesystem(std::string arg);
353 int startmtp(std::string arg);
354 int stopmtp(std::string arg);
Ethan Yonker96af84a2015-01-05 14:58:36 -0600355 int flashimage(std::string arg);
bigbiff7abc5fe2015-01-17 16:53:12 -0500356 int cancelbackup(std::string arg);
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500357 int checkpartitionlifetimewrites(std::string arg);
358 int mountsystemtoggle(std::string arg);
Ethan Yonker74db1572015-10-28 12:44:49 -0500359 int setlanguage(std::string arg);
that10ae24f2015-12-26 20:53:51 +0100360 int twcmd(std::string arg);
Ethan Yonker1b190162016-12-05 15:25:19 -0600361 int setbootslot(std::string arg);
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -0600362 int installapp(std::string arg);
that3f7b1ac2014-12-30 11:30:13 +0100363
364 int simulate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400365};
366
Vojtech Bocekede51c52014-02-07 23:58:09 +0100367class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400368{
369public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200370 GUIButton(xml_node<>* node);
371 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400372
373public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200374 // Render - Render the full object to the GL surface
375 // Return 0 on success, <0 on error
376 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400377
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200378 // Update - Update any UI component animations (called <= 30 FPS)
379 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
380 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400381
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200382 // SetPos - Update the position of the render object
383 // Return 0 on success, <0 on error
384 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400385
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200386 // NotifyTouch - Notify of a touch event
387 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
388 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400389
390protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200391 GUIImage* mButtonImg;
thatf6ed8fc2015-02-14 20:23:16 +0100392 ImageResource* mButtonIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200393 GUIText* mButtonLabel;
394 GUIAction* mAction;
395 int mTextX, mTextY, mTextW, mTextH;
396 int mIconX, mIconY, mIconW, mIconH;
397 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600398 bool hasHighlightColor;
399 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500400 bool hasFill;
401 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600402 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000403 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400404};
405
Vojtech Bocekede51c52014-02-07 23:58:09 +0100406class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400407{
408public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200409 GUICheckbox(xml_node<>* node);
410 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400411
412public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200413 // Render - Render the full object to the GL surface
414 // Return 0 on success, <0 on error
415 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400416
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200417 // Update - Update any UI component animations (called <= 30 FPS)
418 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
419 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400420
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200421 // SetPos - Update the position of the render object
422 // Return 0 on success, <0 on error
423 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400424
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200425 // NotifyTouch - Notify of a touch event
426 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
427 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400428
429protected:
thatf6ed8fc2015-02-14 20:23:16 +0100430 ImageResource* mChecked;
431 ImageResource* mUnchecked;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200432 GUIText* mLabel;
433 int mTextX, mTextY;
434 int mCheckX, mCheckY, mCheckW, mCheckH;
435 int mLastState;
436 bool mRendered;
437 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400438};
439
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100440class GUIScrollList : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400441{
442public:
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100443 GUIScrollList(xml_node<>* node);
444 virtual ~GUIScrollList();
Dees_Troy51a0e822012-09-05 15:24:24 -0400445
446public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200447 // Render - Render the full object to the GL surface
448 // Return 0 on success, <0 on error
449 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400450
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200451 // Update - Update any UI component animations (called <= 30 FPS)
452 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
453 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400454
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200455 // NotifyTouch - Notify of a touch event
456 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
457 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400458
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200459 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100460 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
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 // SetPageFocus - Notify when a page gains or loses focus
467 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400468
469protected:
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100470 // derived classes need to implement these
471 // get number of items
472 virtual size_t GetItemCount() { return 0; }
that0af77952015-02-25 08:52:19 +0100473 // render a single item in rect (mRenderX, yPos, mRenderW, actualItemHeight)
474 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100475 // an item was selected
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500476 virtual void NotifySelect(size_t item_selected __unused) {}
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100477
that0af77952015-02-25 08:52:19 +0100478 // render a standard-layout list item with optional icon and text
479 void RenderStdItem(int yPos, bool selected, ImageResource* icon, const char* text, int iconAndTextH = 0);
480
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100481 enum { NO_ITEM = (size_t)-1 };
482 // returns item index at coordinates or NO_ITEM if there is no item there
483 size_t HitTestItem(int x, int y);
484
485 // 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
486 void SetMaxIconSize(int w, int h);
487
488 // This will make sure that the item indicated by list_index is visible on the screen
489 void SetVisibleListLocation(size_t list_index);
490
491 // Handle scrolling changes for drags and kinetic scrolling
492 void HandleScrolling();
493
that9876ac32015-02-15 21:40:59 +0100494 // Returns many full rows the list is capable of displaying
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100495 int GetDisplayItemCount();
496
497 // Returns the size in pixels of a partial item or row size
498 int GetDisplayRemainder();
499
500protected:
501 // Background
502 COLOR mBackgroundColor;
thatf6ed8fc2015-02-14 20:23:16 +0100503 ImageResource* mBackground; // background image, if any, automatically centered
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100504
505 // Header
506 COLOR mHeaderBackgroundColor;
507 COLOR mHeaderFontColor;
508 std::string mHeaderText; // Original header text without parsing any variables
509 std::string mLastHeaderValue; // Header text after parsing variables
that9876ac32015-02-15 21:40:59 +0100510 bool mHeaderIsStatic; // indicates if the header is static (no need to check for changes in NotifyVarChange)
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100511 int mHeaderH; // actual header height including font, icon, padding, and separator heights
thatf6ed8fc2015-02-14 20:23:16 +0100512 ImageResource* mHeaderIcon;
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100513 int mHeaderIconHeight, mHeaderIconWidth; // width and height of the header icon if present
514 int mHeaderSeparatorH; // Height of the separator between header and list items
515 COLOR mHeaderSeparatorColor; // color of the header separator
516
517 // Per-item layout
thatf6ed8fc2015-02-14 20:23:16 +0100518 FontResource* mFont;
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100519 COLOR mFontColor;
that9876ac32015-02-15 21:40:59 +0100520 bool hasHighlightColor; // indicates if a highlight color was set
521 COLOR mHighlightColor; // background row highlight color
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100522 COLOR mFontHighlightColor;
523 int mFontHeight;
524 int actualItemHeight; // Actual height of each item in pixels including max icon size, font size, and padding
525 int maxIconWidth, maxIconHeight; // max icon width and height for the list, set by derived class in SetMaxIconSize
526 int mItemSpacing; // stores the spacing or padding on the y axis, part of the actualItemHeight
527 int mSeparatorH; // Height of the separator between items
528 COLOR mSeparatorColor; // color of the separator that is between items
529
thata9998212015-02-19 22:51:24 +0100530 // Scrollbar
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100531 int mFastScrollW; // width of the fastscroll area
532 int mFastScrollLineW; // width of the line for fastscroll rendering
533 int mFastScrollRectW; // width of the rectangle for fastscroll
thata9998212015-02-19 22:51:24 +0100534 int mFastScrollRectH; // minimum height of the rectangle for fastscroll
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100535 COLOR mFastScrollLineColor;
536 COLOR mFastScrollRectColor;
thata9998212015-02-19 22:51:24 +0100537
538 // Scrolling and dynamic state
539 int mFastScrollRectCurrentY; // current top of fastscroll rect relative to list top
540 int mFastScrollRectCurrentH; // current height of fastscroll rect
541 int mFastScrollRectTouchY; // offset from top of fastscroll rect where the user initially touched
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100542 bool hasScroll; // indicates that we have enough items in the list to scroll
543 int firstDisplayedItem; // this item goes at the top of the display list - may only be partially visible
544 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
545 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 +0100546 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 +0100547 size_t selectedItem; // selected item index after the initial touch, set to -1 if we are scrolling
548 int touchDebounce; // debounce for touches, minimum of 6 pixels but may be larger calculated based actualItemHeight / 3
549 int lastY, last2Y; // last 2 touch locations, used for tracking kinetic scroll speed
550 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
551 int mUpdate; // indicates that a change took place and we need to re-render
Ethan Yonker44925ad2015-07-22 12:33:59 -0500552 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 +0100553};
554
555class GUIFileSelector : public GUIScrollList
556{
557public:
558 GUIFileSelector(xml_node<>* node);
559 virtual ~GUIFileSelector();
560
561public:
562 // Update - Update any UI component animations (called <= 30 FPS)
563 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
564 virtual int Update(void);
565
566 // NotifyVarChange - Notify of a variable change
567 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
568
569 // SetPageFocus - Notify when a page gains or loses focus
570 virtual void SetPageFocus(int inFocus);
571
572 virtual size_t GetItemCount();
that0af77952015-02-25 08:52:19 +0100573 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100574 virtual void NotifySelect(size_t item_selected);
575
576protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200577 struct FileData {
578 std::string fileName;
579 unsigned char fileType; // Uses d_type format from struct dirent
580 mode_t protection; // Uses mode_t format from stat
581 uid_t userId;
582 gid_t groupId;
583 off_t fileSize;
584 time_t lastAccess; // Uses time_t format from stat
585 time_t lastModified; // Uses time_t format from stat
586 time_t lastStatChange; // Uses time_t format from stat
587 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400588
589protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200590 virtual int GetFileList(const std::string folder);
591 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400592
593protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200594 std::vector<FileData> mFolderList;
595 std::vector<FileData> mFileList;
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100596 std::string mPathVar; // current path displayed, saved in the data manager
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600597 std::string mPathDefault; // default value for the path if none is set in mPathVar
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100598 std::string mExtn; // used for filtering the file list, for example, *.zip
599 std::string mVariable; // set when the user selects an item, pull path like /path/to/foo
600 std::string mSortVariable; // data manager variable used to change the sorting of files
601 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
602 int mShowFolders, mShowFiles; // indicates if the list should show folders and/or files
603 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)
604 static int mSortOrder; // must be static because it is used by the static function fileSort
thatf6ed8fc2015-02-14 20:23:16 +0100605 ImageResource* mFolderIcon;
606 ImageResource* mFileIcon;
Dees_Troyc0583f52013-02-28 11:19:57 -0600607 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400608};
609
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100610class GUIListBox : public GUIScrollList
Dees_Troy51a0e822012-09-05 15:24:24 -0400611{
612public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200613 GUIListBox(xml_node<>* node);
614 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400615
616public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200617 // Update - Update any UI component animations (called <= 30 FPS)
618 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
619 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400620
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200621 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100622 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400623
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200624 // SetPageFocus - Notify when a page gains or loses focus
625 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400626
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100627 virtual size_t GetItemCount();
that0af77952015-02-25 08:52:19 +0100628 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100629 virtual void NotifySelect(size_t item_selected);
630
Dees_Troy51a0e822012-09-05 15:24:24 -0400631protected:
that8ab5c132015-09-13 23:00:54 +0200632 struct ListItem {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200633 std::string displayName;
Ethan Yonker56ce3322015-07-30 15:04:32 -0500634 std::string variableName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400635 std::string variableValue;
636 unsigned int selected;
thatc01391c2015-07-09 00:19:58 +0200637 GUIAction* action;
that8ab5c132015-09-13 23:00:54 +0200638 std::vector<Condition> mConditions;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200639 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400640
641protected:
that8ab5c132015-09-13 23:00:54 +0200642 std::vector<ListItem> mListItems;
643 std::vector<size_t> mVisibleItems; // contains indexes in mListItems of visible items only
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200644 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400645 std::string currentValue;
thatf6ed8fc2015-02-14 20:23:16 +0100646 ImageResource* mIconSelected;
647 ImageResource* mIconUnselected;
Ethan Yonker56ce3322015-07-30 15:04:32 -0500648 bool isCheckList;
Ethan Yonkerdedbb7f2016-01-17 18:17:38 -0600649 bool isTextParsed;
Dees_Troy51a0e822012-09-05 15:24:24 -0400650};
651
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100652class GUIPartitionList : public GUIScrollList
Dees_Troya13d74f2013-03-24 08:54:55 -0500653{
654public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200655 GUIPartitionList(xml_node<>* node);
656 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500657
658public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200659 // Update - Update any UI component animations (called <= 30 FPS)
660 // 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 +0100661 virtual int Update();
Dees_Troya13d74f2013-03-24 08:54:55 -0500662
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200663 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100664 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500665
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200666 // SetPageFocus - Notify when a page gains or loses focus
667 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500668
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100669 virtual size_t GetItemCount();
that0af77952015-02-25 08:52:19 +0100670 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100671 virtual void NotifySelect(size_t item_selected);
672
Dees_Troya13d74f2013-03-24 08:54:55 -0500673protected:
Ethan Yonker0a3a98f2015-02-05 00:48:28 +0100674 void MatchList();
Ethan Yonkercfd65092015-02-14 10:39:21 -0600675 void SetPosition();
Dees_Troya13d74f2013-03-24 08:54:55 -0500676
677protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200678 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500679 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200680 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500681 std::string selectedList;
682 std::string currentValue;
Dees_Troya13d74f2013-03-24 08:54:55 -0500683 std::string mLastValue;
thatf6ed8fc2015-02-14 20:23:16 +0100684 ImageResource* mIconSelected;
685 ImageResource* mIconUnselected;
Dees_Troya13d74f2013-03-24 08:54:55 -0500686 bool updateList;
687};
688
Ethan Yonker44925ad2015-07-22 12:33:59 -0500689class GUITextBox : public GUIScrollList
690{
691public:
692 GUITextBox(xml_node<>* node);
693
694public:
695 // Update - Update any UI component animations (called <= 30 FPS)
696 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
697 virtual int Update(void);
698
699 // NotifyVarChange - Notify of a variable change
700 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
701
702 // ScrollList interface
703 virtual size_t GetItemCount();
704 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
705 virtual void NotifySelect(size_t item_selected);
706protected:
707
708 size_t mLastCount;
709 bool mIsStatic;
710 std::vector<std::string> mLastValue; // Parsed text - parsed for variables but not word wrapped
711 std::vector<std::string> mText; // Original text - not parsed for variables and not word wrapped
712 std::vector<std::string> rText; // Rendered text - what we actually see
713
714};
715
that8d46c092015-02-26 01:30:04 +0100716class GUIConsole : public GUIScrollList
717{
718public:
719 GUIConsole(xml_node<>* node);
720
721public:
722 // Render - Render the full object to the GL surface
723 // Return 0 on success, <0 on error
724 virtual int Render(void);
725
726 // Update - Update any UI component animations (called <= 30 FPS)
727 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
728 virtual int Update(void);
729
730 // IsInRegion - Checks if the request is handled by this object
731 // Return 1 if this object handles the request, 0 if not
732 virtual int IsInRegion(int x, int y);
733
734 // NotifyTouch - Notify of a touch event
735 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
736 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
737
738 // ScrollList interface
739 virtual size_t GetItemCount();
740 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
741 virtual void NotifySelect(size_t item_selected);
Ethan Yonker74db1572015-10-28 12:44:49 -0500742 static void Translate_Now();
that8d46c092015-02-26 01:30:04 +0100743protected:
744 enum SlideoutState
745 {
746 hidden = 0,
747 visible,
748 request_hide,
749 request_show
750 };
751
752 ImageResource* mSlideoutImage;
753 size_t mLastCount; // lines from gConsole that are already split and copied into rConsole
754 bool scrollToEnd; // true if we want to keep tracking the last line
755 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
756 int mSlideout;
757 SlideoutState mSlideoutState;
758 std::vector<std::string> rConsole;
759 std::vector<std::string> rConsoleColor;
760
761protected:
that8d46c092015-02-26 01:30:04 +0100762 int RenderSlideout(void);
763 int RenderConsole(void);
764};
765
that1964d192016-01-07 00:41:03 +0100766class TerminalEngine;
767class GUITerminal : public GUIScrollList, public InputObject
768{
769public:
770 GUITerminal(xml_node<>* node);
771
772public:
773 // Update - Update any UI component animations (called <= 30 FPS)
774 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
775 virtual int Update(void);
776
777 // NotifyTouch - Notify of a touch event
778 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
779 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
780
781 // NotifyKey - Notify of a key press
782 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
783 virtual int NotifyKey(int key, bool down);
784
785 // character input
786 virtual int NotifyCharInput(int ch);
787
788 // SetPageFocus - Notify when a page gains or loses focus
789 virtual void SetPageFocus(int inFocus);
790
791 // ScrollList interface
792 virtual size_t GetItemCount();
793 virtual void RenderItem(size_t itemindex, int yPos, bool selected);
794 virtual void NotifySelect(size_t item_selected);
795protected:
796 void InitAndResize();
797
798 TerminalEngine* engine; // non-visual parts of the terminal (text buffer etc.), not owned
799 int updateCounter; // to track if anything changed in the back-end
800 bool lastCondition; // to track if the condition became true and we might need to resize the terminal engine
801};
802
Dees_Troy51a0e822012-09-05 15:24:24 -0400803// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100804class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400805{
806public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200807 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400808
809public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200810 // Render - Render the full object to the GL surface
811 // Return 0 on success, <0 on error
812 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400813
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200814 // Update - Update any UI component animations (called <= 30 FPS)
815 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
816 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400817
818protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200819 AnimationResource* mAnimation;
820 int mFrame;
821 int mFPS;
822 int mLoop;
823 int mRender;
824 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400825};
826
Vojtech Bocekede51c52014-02-07 23:58:09 +0100827class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400828{
829public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200830 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400831
832public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200833 // Render - Render the full object to the GL surface
834 // Return 0 on success, <0 on error
835 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400836
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200837 // Update - Update any UI component animations (called <= 30 FPS)
838 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
839 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400840
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200841 // NotifyVarChange - Notify of a variable change
842 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100843 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400844
845protected:
thatf6ed8fc2015-02-14 20:23:16 +0100846 ImageResource* mEmptyBar;
847 ImageResource* mFullBar;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200848 std::string mMinValVar;
849 std::string mMaxValVar;
850 std::string mCurValVar;
851 float mSlide;
852 float mSlideInc;
853 int mSlideFrames;
854 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400855
856protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200857 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400858};
859
Vojtech Bocekede51c52014-02-07 23:58:09 +0100860class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400861{
862public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200863 GUISlider(xml_node<>* node);
864 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400865
866public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200867 // Render - Render the full object to the GL surface
868 // Return 0 on success, <0 on error
869 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400870
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200871 // Update - Update any UI component animations (called <= 30 FPS)
872 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
873 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400874
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200875 // NotifyTouch - Notify of a touch event
876 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
877 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400878
879protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200880 GUIAction* sAction;
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600881 GUIText* sSliderLabel;
thatf6ed8fc2015-02-14 20:23:16 +0100882 ImageResource* sSlider;
883 ImageResource* sSliderUsed;
884 ImageResource* sTouch;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200885 int sTouchW, sTouchH;
886 int sCurTouchX;
887 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400888};
889
that8834a0f2016-01-05 23:29:30 +0100890// these are ASCII codes reported via NotifyCharInput
891// other special keys (arrows etc.) are reported via NotifyKey
892#define KEYBOARD_ACTION 13 // CR
893#define KEYBOARD_BACKSPACE 8 // Backspace
894#define KEYBOARD_TAB 9 // Tab
895#define KEYBOARD_SWIPE_LEFT 21 // Ctrl+U to delete line, same as in readline (used by shell etc.)
896#define KEYBOARD_SWIPE_RIGHT 11 // Ctrl+K, same as in readline
Dees_Troy51a0e822012-09-05 15:24:24 -0400897
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);
that8834a0f2016-01-05 23:29:30 +0100909 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400910
911protected:
thate79878b2015-03-14 23:07:23 +0100912 struct Key
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200913 {
that8834a0f2016-01-05 23:29:30 +0100914 int key; // positive: ASCII/Unicode code; negative: Linux key code (KEY_*)
915 int longpresskey;
that1a7ba972015-02-01 19:48:19 +0100916 int end_x;
917 int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200918 };
thate79878b2015-03-14 23:07:23 +0100919 int ParseKey(const char* keyinfo, Key& key, int& Xindex, int keyWidth, bool longpress);
thatf256b722015-05-23 20:44:12 +0200920 void LoadKeyLabels(xml_node<>* parent, int layout);
thatf6b20662015-06-25 21:51:37 +0200921 void DrawKey(Key& key, int keyX, int keyY, int keyW, int keyH);
that8834a0f2016-01-05 23:29:30 +0100922 int KeyCharToCtrlChar(int key);
thatd86f49d2015-03-15 00:56:57 +0100923
924 enum {
925 MAX_KEYBOARD_LAYOUTS = 5,
926 MAX_KEYBOARD_ROWS = 9,
927 MAX_KEYBOARD_KEYS = 20
928 };
929 struct Layout
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600930 {
thatd86f49d2015-03-15 00:56:57 +0100931 ImageResource* keyboardImg;
that8834a0f2016-01-05 23:29:30 +0100932 Key keys[MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
thatd86f49d2015-03-15 00:56:57 +0100933 int row_end_y[MAX_KEYBOARD_ROWS];
934 bool is_caps;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600935 int revert_layout;
936 };
thatd86f49d2015-03-15 00:56:57 +0100937 Layout layouts[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400938
thatf256b722015-05-23 20:44:12 +0200939 struct KeyLabel
940 {
that8834a0f2016-01-05 23:29:30 +0100941 int key; // same as in struct Key
thatf256b722015-05-23 20:44:12 +0200942 int layout_from; // 1-based; 0 for labels that apply to all layouts
943 int layout_to; // same as Key.layout
944 string text; // key label text
945 ImageResource* image; // image (overrides text if defined)
946 };
947 std::vector<KeyLabel> mKeyLabels;
948
thate79878b2015-03-14 23:07:23 +0100949 // Find key at screen coordinates
950 Key* HitTestKey(int x, int y);
951
Dees_Troy51a0e822012-09-05 15:24:24 -0400952 bool mRendered;
953 std::string mVariable;
that1a7ba972015-02-01 19:48:19 +0100954 int currentLayout;
thatd86f49d2015-03-15 00:56:57 +0100955 bool CapsLockOn;
that8834a0f2016-01-05 23:29:30 +0100956 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 +0200957 int highlightRenderCount;
958 Key* currentKey;
that8834a0f2016-01-05 23:29:30 +0100959 bool hasHighlight, hasCapsHighlight, hasCtrlHighlight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400960 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600961 COLOR mCapsHighlightColor;
that8834a0f2016-01-05 23:29:30 +0100962 COLOR mCtrlHighlightColor;
thatf256b722015-05-23 20:44:12 +0200963 COLOR mFontColor; // for centered key labels
964 COLOR mFontColorSmall; // for centered key labels
965 FontResource* mFont; // for main key labels
966 FontResource* mSmallFont; // for key labels like "?123"
967 FontResource* mLongpressFont; // for the small longpress label in the upper right corner
thatf6b20662015-06-25 21:51:37 +0200968 int longpressOffsetX, longpressOffsetY; // distance of the longpress label from the key corner
thatf256b722015-05-23 20:44:12 +0200969 COLOR mLongpressFontColor;
970 COLOR mBackgroundColor; // keyboard background color
971 COLOR mKeyColorAlphanumeric; // key background color
972 COLOR mKeyColorOther; // key background color
973 int mKeyMarginX, mKeyMarginY; // space around key boxes - applied to left/right and top/bottom
Dees_Troy51a0e822012-09-05 15:24:24 -0400974};
975
976// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100977class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400978{
979public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200980 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400981 virtual ~GUIInput();
982
983public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200984 // Render - Render the full object to the GL surface
985 // Return 0 on success, <0 on error
986 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400987
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200988 // Update - Update any UI component animations (called <= 30 FPS)
989 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
990 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400991
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200992 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100993 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400994
995 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200996 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
997 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400998
that8834a0f2016-01-05 23:29:30 +0100999 virtual int NotifyKey(int key, bool down);
1000 virtual int NotifyCharInput(int ch);
Dees_Troy51a0e822012-09-05 15:24:24 -04001001
1002protected:
1003 virtual int GetSelection(int x, int y);
1004
1005 // Handles displaying the text properly when chars are added, deleted, or for scrolling
Ethan Yonkera5db7122016-03-14 15:47:09 -05001006 void HandleTextLocation(int x);
Sultan Qasim Khan14138d92016-04-04 04:11:25 -04001007 void UpdateDisplayText();
Ethan Yonkera5db7122016-03-14 15:47:09 -05001008 void HandleCursorByTouch(int x);
1009 void HandleCursorByText();
Dees_Troy51a0e822012-09-05 15:24:24 -04001010
1011protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001012 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -04001013 GUIAction* mAction;
thatf6ed8fc2015-02-14 20:23:16 +01001014 ImageResource* mBackground;
1015 ImageResource* mCursor;
1016 FontResource* mFont;
Dees_Troy51a0e822012-09-05 15:24:24 -04001017 std::string mVariable;
1018 std::string mMask;
Sultan Qasim Khan14138d92016-04-04 04:11:25 -04001019 std::string mValue;
Ethan Yonkera5db7122016-03-14 15:47:09 -05001020 std::string displayValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001021 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -04001022 COLOR mCursorColor;
1023 int scrollingX;
Sultan Qasim Khan14138d92016-04-04 04:11:25 -04001024 int cursorX; // actual x axis location of the cursor
Dees_Troy51a0e822012-09-05 15:24:24 -04001025 int lastX;
1026 int mCursorLocation;
1027 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
1028 int mFontY;
Ethan Yonkera5db7122016-03-14 15:47:09 -05001029 int textWidth;
Dees_Troy51a0e822012-09-05 15:24:24 -04001030 unsigned mFontHeight;
1031 unsigned CursorWidth;
1032 bool mRendered;
1033 bool HasMask;
1034 bool DrawCursor;
1035 bool isLocalChange;
1036 bool HasAllowed;
1037 bool HasDisabled;
1038 std::string AllowedList;
1039 std::string DisabledList;
1040 unsigned MinLen;
1041 unsigned MaxLen;
1042};
1043
1044class HardwareKeyboard
1045{
1046public:
thatf37aec22015-02-01 13:38:35 +01001047 HardwareKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -04001048 virtual ~HardwareKeyboard();
1049
1050public:
thatf37aec22015-02-01 13:38:35 +01001051 // called by the input handler for key events
1052 int KeyDown(int key_code);
1053 int KeyUp(int key_code);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001054
thatf37aec22015-02-01 13:38:35 +01001055 // called by the input handler when holding a key down
1056 int KeyRepeat();
1057
1058 // called by multi-key actions to suppress key-release notifications
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001059 void ConsumeKeyRelease(int key);
1060
that8834a0f2016-01-05 23:29:30 +01001061 bool IsKeyDown(int key_code);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001062private:
that8834a0f2016-01-05 23:29:30 +01001063 int mLastKey;
thatf37aec22015-02-01 13:38:35 +01001064 int mLastKeyChar;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +01001065 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -04001066};
1067
Vojtech Bocekede51c52014-02-07 23:58:09 +01001068class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +02001069{
1070public:
1071 GUISliderValue(xml_node<>* node);
1072 virtual ~GUISliderValue();
1073
1074public:
1075 // Render - Render the full object to the GL surface
1076 // Return 0 on success, <0 on error
1077 virtual int Render(void);
1078
1079 // Update - Update any UI component animations (called <= 30 FPS)
1080 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
1081 virtual int Update(void);
1082
1083 // SetPos - Update the position of the render object
1084 // Return 0 on success, <0 on error
1085 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1086
1087 // NotifyTouch - Notify of a touch event
1088 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
1089 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
1090
1091 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +01001092 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +02001093
1094 // SetPageFocus - Notify when a page gains or loses focus
1095 virtual void SetPageFocus(int inFocus);
1096
1097protected:
1098 int measureText(const std::string& str);
1099 int valueFromPct(float pct);
1100 float pctFromValue(int value);
1101 void loadValue(bool force = false);
1102
1103 std::string mVariable;
1104 int mMax;
1105 int mMin;
1106 int mValue;
1107 char *mValueStr;
1108 float mValuePct;
1109 std::string mMaxStr;
1110 std::string mMinStr;
thatf6ed8fc2015-02-14 20:23:16 +01001111 FontResource *mFont;
Vojtech Bocek85932342013-04-01 22:11:33 +02001112 GUIText* mLabel;
1113 int mLabelW;
1114 COLOR mTextColor;
1115 COLOR mLineColor;
1116 COLOR mSliderColor;
1117 bool mShowRange;
1118 bool mShowCurr;
1119 int mLineX;
1120 int mLineY;
1121 int mLineH;
1122 int mLinePadding;
1123 int mPadding;
1124 int mSliderY;
1125 int mSliderW;
1126 int mSliderH;
1127 bool mRendered;
1128 int mFontHeight;
1129 GUIAction *mAction;
1130 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +02001131 int mLineW;
1132 bool mDragging;
thatf6ed8fc2015-02-14 20:23:16 +01001133 ImageResource *mBackgroundImage;
1134 ImageResource *mHandleImage;
1135 ImageResource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +02001136};
1137
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001138class MouseCursor : public RenderObject
1139{
1140public:
1141 MouseCursor(int posX, int posY);
1142 virtual ~MouseCursor();
1143
1144 virtual int Render(void);
1145 virtual int Update(void);
1146 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1147
1148 void Move(int deltaX, int deltaY);
1149 void GetPos(int& x, int& y);
1150 void LoadData(xml_node<>* node);
1151 void ResetData(int resX, int resY);
1152
1153private:
1154 int m_resX;
1155 int m_resY;
1156 bool m_moved;
1157 float m_speedMultiplier;
1158 COLOR m_color;
thatf6ed8fc2015-02-14 20:23:16 +01001159 ImageResource *m_image;
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001160 bool m_present;
1161};
1162
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001163class GUIPatternPassword : public GUIObject, public RenderObject, public ActionObject
1164{
1165public:
1166 GUIPatternPassword(xml_node<>* node);
1167 virtual ~GUIPatternPassword();
1168
1169public:
1170 virtual int Render(void);
1171 virtual int Update(void);
1172 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Aleksa Saraib25a1832015-12-31 17:36:00 +01001173 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001174 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1175
1176protected:
1177 void CalculateDotPositions();
1178 void ResetActiveDots();
1179 void ConnectDot(int dot_idx);
1180 void ConnectIntermediateDots(int dot_idx);
Aleksa Saraib25a1832015-12-31 17:36:00 +01001181 void Resize(size_t size);
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001182 int InDot(int x, int y);
1183 bool DotUsed(int dot_idx);
Aleksa Saraib25a1832015-12-31 17:36:00 +01001184 std::string GeneratePassphrase();
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001185 void PatternDrawn();
1186
1187 struct Dot {
1188 int x;
1189 int y;
1190 bool active;
1191 };
1192
Aleksa Saraib25a1832015-12-31 17:36:00 +01001193 std::string mSizeVar;
1194 size_t mGridSize;
1195
1196 Dot* mDots;
1197 int* mConnectedDots;
Vojtech Bocek7e11ac52015-03-05 23:21:49 +01001198 size_t mConnectedDotsLen;
1199 int mCurLineX;
1200 int mCurLineY;
1201 bool mTrackingTouch;
1202 bool mNeedRender;
1203
1204 COLOR mDotColor;
1205 COLOR mActiveDotColor;
1206 COLOR mLineColor;
1207 ImageResource *mDotImage;
1208 ImageResource *mActiveDotImage;
1209 gr_surface mDotCircle;
1210 gr_surface mActiveDotCircle;
1211 int mDotRadius;
1212 int mLineWidth;
1213
1214 std::string mPassVar;
1215 GUIAction *mAction;
1216 int mUpdate;
1217};
1218
1219
Dees_Troy51a0e822012-09-05 15:24:24 -04001220// Helper APIs
Ethan Yonker21ff02a2015-02-18 14:35:00 -06001221xml_node<>* FindNode(xml_node<>* parent, const char* nodename, int depth = 0);
thatf6ed8fc2015-02-14 20:23:16 +01001222std::string LoadAttrString(xml_node<>* element, const char* attrname, const char* defaultvalue = "");
1223int LoadAttrInt(xml_node<>* element, const char* attrname, int defaultvalue = 0);
1224int LoadAttrIntScaleX(xml_node<>* element, const char* attrname, int defaultvalue = 0);
1225int LoadAttrIntScaleY(xml_node<>* element, const char* attrname, int defaultvalue = 0);
Ethan Yonker21ff02a2015-02-18 14:35:00 -06001226COLOR LoadAttrColor(xml_node<>* element, const char* attrname, bool* found_color, COLOR defaultvalue = COLOR(0,0,0,0));
thatf6ed8fc2015-02-14 20:23:16 +01001227COLOR LoadAttrColor(xml_node<>* element, const char* attrname, COLOR defaultvalue = COLOR(0,0,0,0));
1228FontResource* LoadAttrFont(xml_node<>* element, const char* attrname);
1229ImageResource* LoadAttrImage(xml_node<>* element, const char* attrname);
1230AnimationResource* LoadAttrAnimation(xml_node<>* element, const char* attrname);
1231
Ethan Yonkerb7a54a32015-10-05 10:16:27 -05001232bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, Placement* placement = NULL);
Dees_Troy51a0e822012-09-05 15:24:24 -04001233
1234#endif // _OBJECTS_HEADER
1235