blob: 486e2e704b7a1e3801ea8cc78a0f1ee0beda39aa [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
31extern "C" {
Dees Troyb7ae0982013-09-10 20:47:35 +000032#ifdef HAVE_SELINUX
Dees_Troy51a0e822012-09-05 15:24:24 -040033#include "../minzip/Zip.h"
Dees Troyb7ae0982013-09-10 20:47:35 +000034#else
35#include "../minzipold/Zip.h"
36#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040037}
38
39using namespace rapidxml;
40
41#include "../data.hpp"
42#include "resources.hpp"
43#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050044#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040045
46class RenderObject
47{
48public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 enum Placement {
50 TOP_LEFT = 0,
51 TOP_RIGHT = 1,
52 BOTTOM_LEFT = 2,
53 BOTTOM_RIGHT = 3,
54 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040055 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056 };
Dees_Troy51a0e822012-09-05 15:24:24 -040057
58public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020059 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
60 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040061
62public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 // Render - Render the full object to the GL surface
64 // Return 0 on success, <0 on error
65 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040066
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067 // Update - Update any UI component animations (called <= 30 FPS)
68 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
69 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040070
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020071 // GetRenderPos - Returns the current position of the object
72 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 -040073
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 // SetRenderPos - Update the position of the object
75 // Return 0 on success, <0 on error
76 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 -040077
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 // GetPlacement - Returns the current placement
79 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040080
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 // SetPlacement - Update the current placement
82 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040083
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020084 // SetPageFocus - Notify when a page gains or loses focus
85 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040086
87protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020088 int mRenderX, mRenderY, mRenderW, mRenderH;
89 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040090};
91
92class ActionObject
93{
94public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
96 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040097
98public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020099 // NotifyTouch - Notify of a touch event
100 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
101 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400102
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200103 // NotifyKey - Notify of a key press
104 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100105 virtual int NotifyKey(int key, bool down) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400106
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200107 // GetRenderPos - Returns the current position of the object
108 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 -0400109
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200110 // SetRenderPos - Update the position of the object
111 // Return 0 on success, <0 on error
112 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400113
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200114 // IsInRegion - Checks if the request is handled by this object
115 // Return 0 if this object handles the request, 1 if not
116 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 -0400117
Dees_Troy51a0e822012-09-05 15:24:24 -0400118protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200119 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400120};
121
Vojtech Bocekede51c52014-02-07 23:58:09 +0100122class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400123{
124public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100125 GUIObject(xml_node<>* node);
126 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400127
128public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200129 bool IsConditionVariable(std::string var);
130 bool isConditionTrue();
131 bool isConditionValid();
Vojtech Bocek07220562014-02-08 02:05:33 +0100132
133 // NotifyVarChange - Notify of a variable change
134 // Returns 0 on success, <0 on error
135 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400136
137protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200138 class Condition
139 {
140 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100141 Condition() {
142 mLastResult = true;
143 }
144
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200145 std::string mVar1;
146 std::string mVar2;
147 std::string mCompareOp;
148 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100149 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200150 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400151
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200152 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400153
154protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200155 bool isMounted(std::string vol);
156 bool isConditionTrue(Condition* condition);
Vojtech Bocek07220562014-02-08 02:05:33 +0100157
158 bool mConditionsResult;
Dees_Troy51a0e822012-09-05 15:24:24 -0400159};
160
161class InputObject
162{
163public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200164 InputObject() { HasInputFocus = 0; }
165 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400166
167public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200168 // NotifyKeyboard - Notify of keyboard input
169 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
170 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400171
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200172 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400173
174protected:
175 int HasInputFocus;
176};
177
178// Derived Objects
179// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100180class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400181{
182public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200183 // w and h may be ignored, in which case, no bounding box is applied
184 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400185
186public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200187 // Render - Render the full object to the GL surface
188 // Return 0 on success, <0 on error
189 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400190
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200191 // Update - Update any UI component animations (called <= 30 FPS)
192 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
193 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400194
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200195 // Retrieve the size of the current string (dynamic strings may change per call)
196 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400197
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200198 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100199 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400200
201 // Set maximum width in pixels
202 virtual int SetMaxWidth(unsigned width);
203
204 // Set number of characters to skip (for scrolling)
205 virtual int SkipCharCount(unsigned skip);
206
Dees_Troy4d12f962012-10-19 13:13:15 -0400207public:
208 bool isHighlighted;
209
Dees_Troy51a0e822012-09-05 15:24:24 -0400210protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200211 std::string mText;
212 std::string mLastValue;
213 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400214 COLOR mHighlightColor;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200215 Resource* mFont;
216 int mIsStatic;
217 int mVarChanged;
218 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400219 unsigned maxWidth;
220 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400221 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400222
223protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200224 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400225};
226
227// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100228class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400229{
230public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200231 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400232
233public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200234 // Render - Render the full object to the GL surface
235 // Return 0 on success, <0 on error
236 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400237
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200238 // SetRenderPos - Update the position of the object
239 // Return 0 on success, <0 on error
240 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400241
Dees_Troy4d12f962012-10-19 13:13:15 -0400242public:
243 bool isHighlighted;
244
Dees_Troy51a0e822012-09-05 15:24:24 -0400245protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200246 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400247 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400248};
249
250// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100251class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400252{
253public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200254 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400255
256public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200257 // Render - Render the full object to the GL surface
258 // Return 0 on success, <0 on error
259 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400260
261protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200262 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400263};
264
265// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100266class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400267{
268public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200269 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400270
271public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200272 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100273 virtual int NotifyKey(int key, bool down);
Vojtech Bocek07220562014-02-08 02:05:33 +0100274 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400275 virtual int doActions();
276
277protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200278 class Action
279 {
280 public:
281 std::string mFunction;
282 std::string mArg;
283 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400284
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200285 std::vector<Action> mActions;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100286 std::map<int, bool> mKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400287
288protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200289 int getKeyByName(std::string key);
290 virtual int doAction(Action action, int isThreaded = 0);
291 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400292 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200293 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400294 void operation_start(const string operation_name);
295 void operation_end(const int operation_status, const int simulate);
296 static void* command_thread(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000297 time_t Start;
Dees_Troy51a0e822012-09-05 15:24:24 -0400298};
299
Vojtech Bocekede51c52014-02-07 23:58:09 +0100300class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400301{
302public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200303 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400304
305public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200306 // Render - Render the full object to the GL surface
307 // Return 0 on success, <0 on error
308 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400309
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200310 // Update - Update any UI component animations (called <= 30 FPS)
311 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
312 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400313
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200314 // SetRenderPos - Update the position of the object
315 // Return 0 on success, <0 on error
316 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400317
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200318 // IsInRegion - Checks if the request is handled by this object
319 // Return 0 if this object handles the request, 1 if not
320 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400321
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200322 // NotifyTouch - Notify of a touch event
323 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
324 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400325
326protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200327 enum SlideoutState
328 {
329 hidden = 0,
330 visible,
331 request_hide,
332 request_show
333 };
334
335 Resource* mFont;
336 Resource* mSlideoutImage;
337 COLOR mForegroundColor;
338 COLOR mBackgroundColor;
339 COLOR mScrollColor;
340 unsigned int mFontHeight;
341 int mCurrentLine;
342 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000343 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200344 unsigned int mMaxRows;
345 int mStartY;
346 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
347 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
348 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
349 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200350 int mSlideout;
351 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000352 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500353 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000354 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400355
356protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200357 virtual int RenderSlideout(void);
358 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400359};
360
Vojtech Bocekede51c52014-02-07 23:58:09 +0100361class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400362{
363public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200364 GUIButton(xml_node<>* node);
365 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400366
367public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200368 // Render - Render the full object to the GL surface
369 // Return 0 on success, <0 on error
370 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400371
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200372 // Update - Update any UI component animations (called <= 30 FPS)
373 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
374 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400375
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200376 // SetPos - Update the position of the render object
377 // Return 0 on success, <0 on error
378 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400379
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200380 // NotifyTouch - Notify of a touch event
381 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
382 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400383
384protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200385 GUIImage* mButtonImg;
386 Resource* mButtonIcon;
387 GUIText* mButtonLabel;
388 GUIAction* mAction;
389 int mTextX, mTextY, mTextW, mTextH;
390 int mIconX, mIconY, mIconW, mIconH;
391 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600392 bool hasHighlightColor;
393 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500394 bool hasFill;
395 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600396 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000397 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400398};
399
Vojtech Bocekede51c52014-02-07 23:58:09 +0100400class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400401{
402public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200403 GUICheckbox(xml_node<>* node);
404 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400405
406public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200407 // Render - Render the full object to the GL surface
408 // Return 0 on success, <0 on error
409 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400410
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200411 // Update - Update any UI component animations (called <= 30 FPS)
412 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
413 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400414
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200415 // SetPos - Update the position of the render object
416 // Return 0 on success, <0 on error
417 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400418
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200419 // NotifyTouch - Notify of a touch event
420 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
421 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400422
423protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200424 Resource* mChecked;
425 Resource* mUnchecked;
426 GUIText* mLabel;
427 int mTextX, mTextY;
428 int mCheckX, mCheckY, mCheckW, mCheckH;
429 int mLastState;
430 bool mRendered;
431 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400432};
433
Vojtech Bocekede51c52014-02-07 23:58:09 +0100434class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400435{
436public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200437 GUIFileSelector(xml_node<>* node);
438 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400439
440public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200441 // Render - Render the full object to the GL surface
442 // Return 0 on success, <0 on error
443 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400444
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200445 // Update - Update any UI component animations (called <= 30 FPS)
446 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
447 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400448
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200449 // NotifyTouch - Notify of a touch event
450 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
451 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400452
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200453 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100454 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400455
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200456 // SetPos - Update the position of the render object
457 // Return 0 on success, <0 on error
458 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400459
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200460 // SetPageFocus - Notify when a page gains or loses focus
461 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400462
463protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200464 struct FileData {
465 std::string fileName;
466 unsigned char fileType; // Uses d_type format from struct dirent
467 mode_t protection; // Uses mode_t format from stat
468 uid_t userId;
469 gid_t groupId;
470 off_t fileSize;
471 time_t lastAccess; // Uses time_t format from stat
472 time_t lastModified; // Uses time_t format from stat
473 time_t lastStatChange; // Uses time_t format from stat
474 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400475
476protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200477 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400478
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200479 virtual int GetFileList(const std::string folder);
480 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400481
482protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200483 std::vector<FileData> mFolderList;
484 std::vector<FileData> mFileList;
485 std::string mPathVar;
486 std::string mExtn;
487 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400488 std::string mSortVariable;
489 std::string mSelection;
490 std::string mHeaderText;
491 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200492 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400493 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200494 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400495 int mSeparatorH;
496 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200497 int mShowFolders, mShowFiles, mShowNavFolders;
498 int mUpdate;
499 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400500 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100501 int mFastScrollW;
502 int mFastScrollLineW;
503 int mFastScrollRectW;
504 int mFastScrollRectH;
505 int mFastScrollRectX;
506 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400507 static int mSortOrder;
508 int startY;
509 int scrollingSpeed;
510 int scrollingY;
511 int mHeaderIsStatic;
512 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200513 unsigned mFontHeight;
514 unsigned mLineHeight;
515 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
516 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400517 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200518 Resource* mFileIcon;
519 Resource* mBackground;
520 Resource* mFont;
521 COLOR mBackgroundColor;
522 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400523 COLOR mHeaderBackgroundColor;
524 COLOR mHeaderFontColor;
525 COLOR mSeparatorColor;
526 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100527 COLOR mFastScrollLineColor;
528 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600529 bool hasHighlightColor;
530 bool hasFontHighlightColor;
531 bool isHighlighted;
532 COLOR mHighlightColor;
533 COLOR mFontHighlightColor;
534 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600535 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400536};
537
Vojtech Bocekede51c52014-02-07 23:58:09 +0100538class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400539{
540public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200541 GUIListBox(xml_node<>* node);
542 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400543
544public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200545 // Render - Render the full object to the GL surface
546 // Return 0 on success, <0 on error
547 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400548
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 // Update - Update any UI component animations (called <= 30 FPS)
550 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
551 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400552
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200553 // NotifyTouch - Notify of a touch event
554 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
555 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400556
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200557 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100558 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400559
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200560 // SetPos - Update the position of the render object
561 // Return 0 on success, <0 on error
562 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400563
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200564 // SetPageFocus - Notify when a page gains or loses focus
565 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400566
567protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200568 struct ListData {
569 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400570 std::string variableValue;
571 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200572 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400573
574protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200575 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400576
577protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200578 std::vector<ListData> mList;
579 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400580 std::string mSelection;
581 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600582 std::string mHeaderText;
583 std::string mLastValue;
584 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200585 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600586 int startY;
587 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200588 int mLineSpacing;
589 int mUpdate;
590 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000591 int mFastScrollW;
592 int mFastScrollLineW;
593 int mFastScrollRectW;
594 int mFastScrollRectH;
595 int mFastScrollRectX;
596 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600597 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
598 int scrollingSpeed;
599 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400600 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200601 unsigned mFontHeight;
602 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600603 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200604 Resource* mIconSelected;
605 Resource* mIconUnselected;
606 Resource* mBackground;
607 Resource* mFont;
608 COLOR mBackgroundColor;
609 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600610 COLOR mHeaderBackgroundColor;
611 COLOR mHeaderFontColor;
612 COLOR mSeparatorColor;
613 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000614 COLOR mFastScrollLineColor;
615 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600616 bool hasHighlightColor;
617 bool hasFontHighlightColor;
618 bool isHighlighted;
619 COLOR mHighlightColor;
620 COLOR mFontHighlightColor;
621 int mHeaderIsStatic;
622 int startSelection;
623 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400624};
625
Vojtech Bocekede51c52014-02-07 23:58:09 +0100626class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500627{
628public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200629 GUIPartitionList(xml_node<>* node);
630 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500631
632public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200633 // Render - Render the full object to the GL surface
634 // Return 0 on success, <0 on error
635 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500636
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200637 // Update - Update any UI component animations (called <= 30 FPS)
638 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
639 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500640
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200641 // NotifyTouch - Notify of a touch event
642 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
643 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500644
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200645 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100646 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500647
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200648 // SetPos - Update the position of the render object
649 // Return 0 on success, <0 on error
650 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500651
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200652 // SetPageFocus - Notify when a page gains or loses focus
653 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500654
655protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200656 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500657 virtual void MatchList(void);
658
659protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200660 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500661 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200662 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500663 std::string selectedList;
664 std::string currentValue;
665 std::string mHeaderText;
666 std::string mLastValue;
667 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200668 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500669 int startY;
670 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200671 int mLineSpacing;
672 int mUpdate;
673 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500674 int mFastScrollW;
675 int mFastScrollLineW;
676 int mFastScrollRectW;
677 int mFastScrollRectH;
678 int mFastScrollRectX;
679 int mFastScrollRectY;
680 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
681 int scrollingSpeed;
682 int scrollingY;
683 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200684 unsigned mFontHeight;
685 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500686 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200687 Resource* mIconSelected;
688 Resource* mIconUnselected;
689 Resource* mBackground;
690 Resource* mFont;
691 COLOR mBackgroundColor;
692 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500693 COLOR mHeaderBackgroundColor;
694 COLOR mHeaderFontColor;
695 COLOR mSeparatorColor;
696 COLOR mHeaderSeparatorColor;
697 COLOR mFastScrollLineColor;
698 COLOR mFastScrollRectColor;
699 bool hasHighlightColor;
700 bool hasFontHighlightColor;
701 bool isHighlighted;
702 COLOR mHighlightColor;
703 COLOR mFontHighlightColor;
704 int mHeaderIsStatic;
705 int startSelection;
706 int touchDebounce;
707 bool updateList;
708};
709
Dees_Troy51a0e822012-09-05 15:24:24 -0400710// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100711class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400712{
713public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200714 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400715
716public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200717 // Render - Render the full object to the GL surface
718 // Return 0 on success, <0 on error
719 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400720
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200721 // Update - Update any UI component animations (called <= 30 FPS)
722 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
723 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400724
725protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200726 AnimationResource* mAnimation;
727 int mFrame;
728 int mFPS;
729 int mLoop;
730 int mRender;
731 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400732};
733
Vojtech Bocekede51c52014-02-07 23:58:09 +0100734class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400735{
736public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200737 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400738
739public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200740 // Render - Render the full object to the GL surface
741 // Return 0 on success, <0 on error
742 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400743
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200744 // Update - Update any UI component animations (called <= 30 FPS)
745 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
746 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400747
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200748 // NotifyVarChange - Notify of a variable change
749 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100750 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400751
752protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200753 Resource* mEmptyBar;
754 Resource* mFullBar;
755 std::string mMinValVar;
756 std::string mMaxValVar;
757 std::string mCurValVar;
758 float mSlide;
759 float mSlideInc;
760 int mSlideFrames;
761 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400762
763protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200764 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400765};
766
Vojtech Bocekede51c52014-02-07 23:58:09 +0100767class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400768{
769public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200770 GUISlider(xml_node<>* node);
771 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400772
773public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200774 // Render - Render the full object to the GL surface
775 // Return 0 on success, <0 on error
776 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400777
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200778 // Update - Update any UI component animations (called <= 30 FPS)
779 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
780 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400781
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200782 // NotifyTouch - Notify of a touch event
783 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
784 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400785
786protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200787 GUIAction* sAction;
788 Resource* sSlider;
789 Resource* sSliderUsed;
790 Resource* sTouch;
791 int sTouchW, sTouchH;
792 int sCurTouchX;
793 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400794};
795
796#define MAX_KEYBOARD_LAYOUTS 5
797#define MAX_KEYBOARD_ROWS 9
798#define MAX_KEYBOARD_KEYS 20
799#define KEYBOARD_ACTION 253
800#define KEYBOARD_LAYOUT 254
801#define KEYBOARD_SWIPE_LEFT 252
802#define KEYBOARD_SWIPE_RIGHT 251
803#define KEYBOARD_ARROW_LEFT 250
804#define KEYBOARD_ARROW_RIGHT 249
805#define KEYBOARD_HOME 248
806#define KEYBOARD_END 247
807#define KEYBOARD_ARROW_UP 246
808#define KEYBOARD_ARROW_DOWN 245
809#define KEYBOARD_SPECIAL_KEYS 245
810#define KEYBOARD_BACKSPACE 8
811
Vojtech Bocekede51c52014-02-07 23:58:09 +0100812class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400813{
814public:
815 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200816 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400817
818public:
819 virtual int Render(void);
820 virtual int Update(void);
821 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
822 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
823
824protected:
825 virtual int GetSelection(int x, int y);
826
827protected:
828 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200829 {
830 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400831 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200832 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400833 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200834 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600835 struct capslock_tracking_struct
836 {
837 int capslock;
838 int set_capslock;
839 int revert_layout;
840 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400841
842 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
843 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600844 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400845 bool mRendered;
846 std::string mVariable;
847 unsigned int cursorLocation;
848 unsigned int currentLayout;
849 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
850 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600851 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400852 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400853 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600854 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400855};
856
857// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100858class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400859{
860public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200861 // w and h may be ignored, in which case, no bounding box is applied
862 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400863 virtual ~GUIInput();
864
865public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200866 // Render - Render the full object to the GL surface
867 // Return 0 on success, <0 on error
868 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400869
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200870 // Update - Update any UI component animations (called <= 30 FPS)
871 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
872 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400873
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200874 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100875 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400876
877 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200878 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
879 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400880
881 virtual int NotifyKeyboard(int key);
882
883protected:
884 virtual int GetSelection(int x, int y);
885
886 // Handles displaying the text properly when chars are added, deleted, or for scrolling
887 virtual int HandleTextLocation(int x);
888
889protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200890 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400891 GUIAction* mAction;
892 Resource* mBackground;
893 Resource* mCursor;
894 Resource* mFont;
895 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200896 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400897 std::string mVariable;
898 std::string mMask;
899 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200900 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400901 COLOR mCursorColor;
902 int scrollingX;
903 int lastX;
904 int mCursorLocation;
905 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
906 int mFontY;
907 unsigned skipChars;
908 unsigned mFontHeight;
909 unsigned CursorWidth;
910 bool mRendered;
911 bool HasMask;
912 bool DrawCursor;
913 bool isLocalChange;
914 bool HasAllowed;
915 bool HasDisabled;
916 std::string AllowedList;
917 std::string DisabledList;
918 unsigned MinLen;
919 unsigned MaxLen;
920};
921
922class HardwareKeyboard
923{
924public:
925 HardwareKeyboard(void);
926 virtual ~HardwareKeyboard();
927
928public:
929 virtual int KeyDown(int key_code);
930 virtual int KeyUp(int key_code);
931 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100932
933 void ConsumeKeyRelease(int key);
934
935private:
936 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400937};
938
Vojtech Bocekede51c52014-02-07 23:58:09 +0100939class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200940{
941public:
942 GUISliderValue(xml_node<>* node);
943 virtual ~GUISliderValue();
944
945public:
946 // Render - Render the full object to the GL surface
947 // Return 0 on success, <0 on error
948 virtual int Render(void);
949
950 // Update - Update any UI component animations (called <= 30 FPS)
951 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
952 virtual int Update(void);
953
954 // SetPos - Update the position of the render object
955 // Return 0 on success, <0 on error
956 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
957
958 // NotifyTouch - Notify of a touch event
959 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
960 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
961
962 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100963 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +0200964
965 // SetPageFocus - Notify when a page gains or loses focus
966 virtual void SetPageFocus(int inFocus);
967
968protected:
969 int measureText(const std::string& str);
970 int valueFromPct(float pct);
971 float pctFromValue(int value);
972 void loadValue(bool force = false);
973
974 std::string mVariable;
975 int mMax;
976 int mMin;
977 int mValue;
978 char *mValueStr;
979 float mValuePct;
980 std::string mMaxStr;
981 std::string mMinStr;
982 Resource *mFont;
983 GUIText* mLabel;
984 int mLabelW;
985 COLOR mTextColor;
986 COLOR mLineColor;
987 COLOR mSliderColor;
988 bool mShowRange;
989 bool mShowCurr;
990 int mLineX;
991 int mLineY;
992 int mLineH;
993 int mLinePadding;
994 int mPadding;
995 int mSliderY;
996 int mSliderW;
997 int mSliderH;
998 bool mRendered;
999 int mFontHeight;
1000 GUIAction *mAction;
1001 bool mChangeOnDrag;
1002 int lineW;
1003};
1004
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001005class MouseCursor : public RenderObject
1006{
1007public:
1008 MouseCursor(int posX, int posY);
1009 virtual ~MouseCursor();
1010
1011 virtual int Render(void);
1012 virtual int Update(void);
1013 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1014
1015 void Move(int deltaX, int deltaY);
1016 void GetPos(int& x, int& y);
1017 void LoadData(xml_node<>* node);
1018 void ResetData(int resX, int resY);
1019
1020private:
1021 int m_resX;
1022 int m_resY;
1023 bool m_moved;
1024 float m_speedMultiplier;
1025 COLOR m_color;
1026 Resource *m_image;
1027 bool m_present;
1028};
1029
Dees_Troy51a0e822012-09-05 15:24:24 -04001030// Helper APIs
1031bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1032
1033#endif // _OBJECTS_HEADER
1034