blob: 310ba4e2648de64e71ec70661466094eb406e8c6 [file] [log] [blame]
Dees_Troya13d74f2013-03-24 08:54:55 -05001/*
2 Copyright 2013 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
Dees Troy3be70a82013-10-22 14:25:12 +000018
19// objects.hpp - Base classes for object manager of GUI
Dees_Troy51a0e822012-09-05 15:24:24 -040020
21#ifndef _OBJECTS_HEADER
22#define _OBJECTS_HEADER
23
24#include "rapidxml.hpp"
25#include <vector>
26#include <string>
27#include <map>
Vojtech Bocek0b7fe502014-03-13 17:36:52 +010028#include <set>
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +000029#include <time.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040030
Dees_Troy51a0e822012-09-05 15:24:24 -040031using namespace rapidxml;
32
33#include "../data.hpp"
34#include "resources.hpp"
35#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050036#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040037
38class RenderObject
39{
40public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020041 enum Placement {
42 TOP_LEFT = 0,
43 TOP_RIGHT = 1,
44 BOTTOM_LEFT = 2,
45 BOTTOM_RIGHT = 3,
46 CENTER = 4,
Dees_Troy51a0e822012-09-05 15:24:24 -040047 CENTER_X_ONLY = 5,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 };
Dees_Troy51a0e822012-09-05 15:24:24 -040049
50public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020051 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
52 virtual ~RenderObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040053
54public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 // Render - Render the full object to the GL surface
56 // Return 0 on success, <0 on error
57 virtual int Render(void) = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -040058
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020059 // Update - Update any UI component animations (called <= 30 FPS)
60 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
61 virtual int Update(void) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040062
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 // GetRenderPos - Returns the current position of the object
64 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 -040065
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020066 // SetRenderPos - Update the position of the object
67 // Return 0 on success, <0 on error
68 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 -040069
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 // GetPlacement - Returns the current placement
71 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040072
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 // SetPlacement - Update the current placement
74 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040075
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020076 // SetPageFocus - Notify when a page gains or loses focus
77 virtual void SetPageFocus(int inFocus) { return; }
Dees_Troy51a0e822012-09-05 15:24:24 -040078
79protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 int mRenderX, mRenderY, mRenderW, mRenderH;
81 Placement mPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -040082};
83
84class ActionObject
85{
86public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020087 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
88 virtual ~ActionObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040089
90public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020091 // NotifyTouch - Notify of a touch event
92 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
93 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
Dees_Troy51a0e822012-09-05 15:24:24 -040094
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 // NotifyKey - Notify of a key press
96 // 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 +010097 virtual int NotifyKey(int key, bool down) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -040098
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020099 // GetRenderPos - Returns the current position of the object
100 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 -0400101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 // SetRenderPos - Update the position of the object
103 // Return 0 on success, <0 on error
104 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400105
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200106 // IsInRegion - Checks if the request is handled by this object
107 // Return 0 if this object handles the request, 1 if not
108 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 -0400109
Dees_Troy51a0e822012-09-05 15:24:24 -0400110protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200111 int mActionX, mActionY, mActionW, mActionH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400112};
113
Vojtech Bocekede51c52014-02-07 23:58:09 +0100114class GUIObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400115{
116public:
Vojtech Bocekede51c52014-02-07 23:58:09 +0100117 GUIObject(xml_node<>* node);
118 virtual ~GUIObject();
Dees_Troy51a0e822012-09-05 15:24:24 -0400119
120public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200121 bool IsConditionVariable(std::string var);
122 bool isConditionTrue();
123 bool isConditionValid();
Vojtech Bocek07220562014-02-08 02:05:33 +0100124
125 // NotifyVarChange - Notify of a variable change
126 // Returns 0 on success, <0 on error
127 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400128
129protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200130 class Condition
131 {
132 public:
Vojtech Bocek07220562014-02-08 02:05:33 +0100133 Condition() {
134 mLastResult = true;
135 }
136
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200137 std::string mVar1;
138 std::string mVar2;
139 std::string mCompareOp;
140 std::string mLastVal;
Vojtech Bocek07220562014-02-08 02:05:33 +0100141 bool mLastResult;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200142 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400143
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200144 std::vector<Condition> mConditions;
Dees_Troy51a0e822012-09-05 15:24:24 -0400145
146protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200147 bool isMounted(std::string vol);
148 bool isConditionTrue(Condition* condition);
Vojtech Bocek07220562014-02-08 02:05:33 +0100149
150 bool mConditionsResult;
Dees_Troy51a0e822012-09-05 15:24:24 -0400151};
152
153class InputObject
154{
155public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200156 InputObject() { HasInputFocus = 0; }
157 virtual ~InputObject() {}
Dees_Troy51a0e822012-09-05 15:24:24 -0400158
159public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 // NotifyKeyboard - Notify of keyboard input
161 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
162 virtual int NotifyKeyboard(int key) { return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400163
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200164 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
Dees_Troy51a0e822012-09-05 15:24:24 -0400165
166protected:
167 int HasInputFocus;
168};
169
170// Derived Objects
171// GUIText - Used for static text
Vojtech Bocekede51c52014-02-07 23:58:09 +0100172class GUIText : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400173{
174public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200175 // w and h may be ignored, in which case, no bounding box is applied
176 GUIText(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400177
178public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200179 // Render - Render the full object to the GL surface
180 // Return 0 on success, <0 on error
181 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400182
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200183 // Update - Update any UI component animations (called <= 30 FPS)
184 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
185 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400186
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200187 // Retrieve the size of the current string (dynamic strings may change per call)
188 virtual int GetCurrentBounds(int& w, int& h);
Dees_Troy51a0e822012-09-05 15:24:24 -0400189
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200190 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100191 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400192
193 // Set maximum width in pixels
194 virtual int SetMaxWidth(unsigned width);
195
196 // Set number of characters to skip (for scrolling)
197 virtual int SkipCharCount(unsigned skip);
198
Dees_Troy4d12f962012-10-19 13:13:15 -0400199public:
200 bool isHighlighted;
201
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;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200207 Resource* mFont;
208 int mIsStatic;
209 int mVarChanged;
210 int mFontHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400211 unsigned maxWidth;
212 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400213 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400214
215protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200216 std::string parseText(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400217};
218
219// GUIImage - Used for static image
Vojtech Bocekede51c52014-02-07 23:58:09 +0100220class GUIImage : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400221{
222public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200223 GUIImage(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400224
225public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200226 // Render - Render the full object to the GL surface
227 // Return 0 on success, <0 on error
228 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400229
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200230 // SetRenderPos - Update the position of the object
231 // Return 0 on success, <0 on error
232 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400233
Dees_Troy4d12f962012-10-19 13:13:15 -0400234public:
235 bool isHighlighted;
236
Dees_Troy51a0e822012-09-05 15:24:24 -0400237protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200238 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400239 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400240};
241
242// GUIFill - Used for fill colors
Vojtech Bocekede51c52014-02-07 23:58:09 +0100243class GUIFill : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400244{
245public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200246 GUIFill(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400247
248public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200249 // Render - Render the full object to the GL surface
250 // Return 0 on success, <0 on error
251 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400252
253protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200254 COLOR mColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400255};
256
257// GUIAction - Used for standard actions
Vojtech Bocekede51c52014-02-07 23:58:09 +0100258class GUIAction : public GUIObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400259{
260public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200261 GUIAction(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400262
263public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200264 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100265 virtual int NotifyKey(int key, bool down);
Vojtech Bocek07220562014-02-08 02:05:33 +0100266 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400267 virtual int doActions();
268
269protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200270 class Action
271 {
272 public:
273 std::string mFunction;
274 std::string mArg;
275 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400276
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200277 std::vector<Action> mActions;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100278 std::map<int, bool> mKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400279
280protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200281 int getKeyByName(std::string key);
282 virtual int doAction(Action action, int isThreaded = 0);
283 static void* thread_start(void *cookie);
Dees_Troy51a0e822012-09-05 15:24:24 -0400284 void simulate_progress_bar(void);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200285 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400286 void operation_start(const string operation_name);
287 void operation_end(const int operation_status, const int simulate);
288 static void* command_thread(void *cookie);
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000289 time_t Start;
Dees_Troy51a0e822012-09-05 15:24:24 -0400290};
291
Vojtech Bocekede51c52014-02-07 23:58:09 +0100292class GUIConsole : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400293{
294public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200295 GUIConsole(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400296
297public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200298 // Render - Render the full object to the GL surface
299 // Return 0 on success, <0 on error
300 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400301
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200302 // Update - Update any UI component animations (called <= 30 FPS)
303 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
304 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400305
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200306 // SetRenderPos - Update the position of the object
307 // Return 0 on success, <0 on error
308 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400309
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200310 // IsInRegion - Checks if the request is handled by this object
311 // Return 0 if this object handles the request, 1 if not
312 virtual int IsInRegion(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400313
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200314 // NotifyTouch - Notify of a touch event
315 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
316 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400317
318protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200319 enum SlideoutState
320 {
321 hidden = 0,
322 visible,
323 request_hide,
324 request_show
325 };
326
327 Resource* mFont;
328 Resource* mSlideoutImage;
329 COLOR mForegroundColor;
330 COLOR mBackgroundColor;
331 COLOR mScrollColor;
332 unsigned int mFontHeight;
333 int mCurrentLine;
334 unsigned int mLastCount;
Dees Troy31218ec2014-02-25 20:35:56 +0000335 unsigned int RenderCount;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200336 unsigned int mMaxRows;
337 int mStartY;
338 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
339 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
340 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
341 int mLastTouchX, mLastTouchY;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200342 int mSlideout;
343 SlideoutState mSlideoutState;
Dees Troy31218ec2014-02-25 20:35:56 +0000344 std::vector<std::string> rConsole;
Ethan Yonkerbf2cb1c2014-07-02 10:15:54 -0500345 std::vector<std::string> rConsoleColor;
Dees Troy31218ec2014-02-25 20:35:56 +0000346 bool mRender;
Dees_Troy51a0e822012-09-05 15:24:24 -0400347
348protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200349 virtual int RenderSlideout(void);
350 virtual int RenderConsole(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400351};
352
Vojtech Bocekede51c52014-02-07 23:58:09 +0100353class GUIButton : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400354{
355public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200356 GUIButton(xml_node<>* node);
357 virtual ~GUIButton();
Dees_Troy51a0e822012-09-05 15:24:24 -0400358
359public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200360 // Render - Render the full object to the GL surface
361 // Return 0 on success, <0 on error
362 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400363
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200364 // Update - Update any UI component animations (called <= 30 FPS)
365 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
366 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400367
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200368 // SetPos - Update the position of the render object
369 // Return 0 on success, <0 on error
370 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400371
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200372 // NotifyTouch - Notify of a touch event
373 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
374 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400375
376protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200377 GUIImage* mButtonImg;
378 Resource* mButtonIcon;
379 GUIText* mButtonLabel;
380 GUIAction* mAction;
381 int mTextX, mTextY, mTextW, mTextH;
382 int mIconX, mIconY, mIconW, mIconH;
383 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600384 bool hasHighlightColor;
385 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500386 bool hasFill;
387 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600388 COLOR mHighlightColor;
Dees Troyb21cc642013-09-10 17:36:41 +0000389 Placement TextPlacement;
Dees_Troy51a0e822012-09-05 15:24:24 -0400390};
391
Vojtech Bocekede51c52014-02-07 23:58:09 +0100392class GUICheckbox: public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400393{
394public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200395 GUICheckbox(xml_node<>* node);
396 virtual ~GUICheckbox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400397
398public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200399 // Render - Render the full object to the GL surface
400 // Return 0 on success, <0 on error
401 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400402
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200403 // Update - Update any UI component animations (called <= 30 FPS)
404 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
405 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400406
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200407 // SetPos - Update the position of the render object
408 // Return 0 on success, <0 on error
409 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400410
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200411 // NotifyTouch - Notify of a touch event
412 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
413 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400414
415protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200416 Resource* mChecked;
417 Resource* mUnchecked;
418 GUIText* mLabel;
419 int mTextX, mTextY;
420 int mCheckX, mCheckY, mCheckW, mCheckH;
421 int mLastState;
422 bool mRendered;
423 std::string mVarName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400424};
425
Vojtech Bocekede51c52014-02-07 23:58:09 +0100426class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400427{
428public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200429 GUIFileSelector(xml_node<>* node);
430 virtual ~GUIFileSelector();
Dees_Troy51a0e822012-09-05 15:24:24 -0400431
432public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200433 // Render - Render the full object to the GL surface
434 // Return 0 on success, <0 on error
435 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400436
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200437 // Update - Update any UI component animations (called <= 30 FPS)
438 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
439 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400440
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200441 // NotifyTouch - Notify of a touch event
442 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
443 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400444
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200445 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100446 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400447
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200448 // SetPos - Update the position of the render object
449 // Return 0 on success, <0 on error
450 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400451
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200452 // SetPageFocus - Notify when a page gains or loses focus
453 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400454
455protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200456 struct FileData {
457 std::string fileName;
458 unsigned char fileType; // Uses d_type format from struct dirent
459 mode_t protection; // Uses mode_t format from stat
460 uid_t userId;
461 gid_t groupId;
462 off_t fileSize;
463 time_t lastAccess; // Uses time_t format from stat
464 time_t lastModified; // Uses time_t format from stat
465 time_t lastStatChange; // Uses time_t format from stat
466 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400467
468protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200469 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400470
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200471 virtual int GetFileList(const std::string folder);
472 static bool fileSort(FileData d1, FileData d2);
Dees_Troy51a0e822012-09-05 15:24:24 -0400473
474protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200475 std::vector<FileData> mFolderList;
476 std::vector<FileData> mFileList;
477 std::string mPathVar;
478 std::string mExtn;
479 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400480 std::string mSortVariable;
481 std::string mSelection;
482 std::string mHeaderText;
483 std::string mLastValue;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200484 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400485 int mStart;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200486 int mLineSpacing;
Dees_Troy51a0e822012-09-05 15:24:24 -0400487 int mSeparatorH;
488 int mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200489 int mShowFolders, mShowFiles, mShowNavFolders;
490 int mUpdate;
491 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400492 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100493 int mFastScrollW;
494 int mFastScrollLineW;
495 int mFastScrollRectW;
496 int mFastScrollRectH;
497 int mFastScrollRectX;
498 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400499 static int mSortOrder;
500 int startY;
501 int scrollingSpeed;
502 int scrollingY;
503 int mHeaderIsStatic;
504 int touchDebounce;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200505 unsigned mFontHeight;
506 unsigned mLineHeight;
507 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
508 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400509 Resource* mFolderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200510 Resource* mFileIcon;
511 Resource* mBackground;
512 Resource* mFont;
513 COLOR mBackgroundColor;
514 COLOR mFontColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400515 COLOR mHeaderBackgroundColor;
516 COLOR mHeaderFontColor;
517 COLOR mSeparatorColor;
518 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100519 COLOR mFastScrollLineColor;
520 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600521 bool hasHighlightColor;
522 bool hasFontHighlightColor;
523 bool isHighlighted;
524 COLOR mHighlightColor;
525 COLOR mFontHighlightColor;
526 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600527 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400528};
529
Vojtech Bocekede51c52014-02-07 23:58:09 +0100530class GUIListBox : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400531{
532public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200533 GUIListBox(xml_node<>* node);
534 virtual ~GUIListBox();
Dees_Troy51a0e822012-09-05 15:24:24 -0400535
536public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200537 // Render - Render the full object to the GL surface
538 // Return 0 on success, <0 on error
539 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400540
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200541 // Update - Update any UI component animations (called <= 30 FPS)
542 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
543 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400544
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200545 // NotifyTouch - Notify of a touch event
546 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
547 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400548
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200549 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100550 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400551
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200552 // SetPos - Update the position of the render object
553 // Return 0 on success, <0 on error
554 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400555
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200556 // SetPageFocus - Notify when a page gains or loses focus
557 virtual void SetPageFocus(int inFocus);
Dees_Troy51a0e822012-09-05 15:24:24 -0400558
559protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200560 struct ListData {
561 std::string displayName;
Dees_Troy51a0e822012-09-05 15:24:24 -0400562 std::string variableValue;
563 unsigned int selected;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200564 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400565
566protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200567 virtual int GetSelection(int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400568
569protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200570 std::vector<ListData> mList;
571 std::string mVariable;
Dees_Troy51a0e822012-09-05 15:24:24 -0400572 std::string mSelection;
573 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600574 std::string mHeaderText;
575 std::string mLastValue;
576 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200577 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600578 int startY;
579 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200580 int mLineSpacing;
581 int mUpdate;
582 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000583 int mFastScrollW;
584 int mFastScrollLineW;
585 int mFastScrollRectW;
586 int mFastScrollRectH;
587 int mFastScrollRectX;
588 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600589 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
590 int scrollingSpeed;
591 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400592 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200593 unsigned mFontHeight;
594 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600595 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200596 Resource* mIconSelected;
597 Resource* mIconUnselected;
598 Resource* mBackground;
599 Resource* mFont;
600 COLOR mBackgroundColor;
601 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600602 COLOR mHeaderBackgroundColor;
603 COLOR mHeaderFontColor;
604 COLOR mSeparatorColor;
605 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000606 COLOR mFastScrollLineColor;
607 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600608 bool hasHighlightColor;
609 bool hasFontHighlightColor;
610 bool isHighlighted;
611 COLOR mHighlightColor;
612 COLOR mFontHighlightColor;
613 int mHeaderIsStatic;
614 int startSelection;
615 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400616};
617
Vojtech Bocekede51c52014-02-07 23:58:09 +0100618class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject
Dees_Troya13d74f2013-03-24 08:54:55 -0500619{
620public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200621 GUIPartitionList(xml_node<>* node);
622 virtual ~GUIPartitionList();
Dees_Troya13d74f2013-03-24 08:54:55 -0500623
624public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200625 // Render - Render the full object to the GL surface
626 // Return 0 on success, <0 on error
627 virtual int Render(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500628
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200629 // Update - Update any UI component animations (called <= 30 FPS)
630 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
631 virtual int Update(void);
Dees_Troya13d74f2013-03-24 08:54:55 -0500632
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200633 // NotifyTouch - Notify of a touch event
634 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
635 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500636
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200637 // NotifyVarChange - Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100638 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troya13d74f2013-03-24 08:54:55 -0500639
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200640 // SetPos - Update the position of the render object
641 // Return 0 on success, <0 on error
642 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
Dees_Troya13d74f2013-03-24 08:54:55 -0500643
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200644 // SetPageFocus - Notify when a page gains or loses focus
645 virtual void SetPageFocus(int inFocus);
Dees_Troya13d74f2013-03-24 08:54:55 -0500646
647protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200648 virtual int GetSelection(int x, int y);
Dees_Troya13d74f2013-03-24 08:54:55 -0500649 virtual void MatchList(void);
650
651protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200652 std::vector<PartitionList> mList;
Dees_Troya13d74f2013-03-24 08:54:55 -0500653 std::string ListType;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200654 std::string mVariable;
Dees_Troya13d74f2013-03-24 08:54:55 -0500655 std::string selectedList;
656 std::string currentValue;
657 std::string mHeaderText;
658 std::string mLastValue;
659 int actualLineHeight;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200660 int mStart;
Dees_Troya13d74f2013-03-24 08:54:55 -0500661 int startY;
662 int mSeparatorH, mHeaderSeparatorH;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200663 int mLineSpacing;
664 int mUpdate;
665 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troya13d74f2013-03-24 08:54:55 -0500666 int mFastScrollW;
667 int mFastScrollLineW;
668 int mFastScrollRectW;
669 int mFastScrollRectH;
670 int mFastScrollRectX;
671 int mFastScrollRectY;
672 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
673 int scrollingSpeed;
674 int scrollingY;
675 static int mSortOrder;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200676 unsigned mFontHeight;
677 unsigned mLineHeight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500678 Resource* mHeaderIcon;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200679 Resource* mIconSelected;
680 Resource* mIconUnselected;
681 Resource* mBackground;
682 Resource* mFont;
683 COLOR mBackgroundColor;
684 COLOR mFontColor;
Dees_Troya13d74f2013-03-24 08:54:55 -0500685 COLOR mHeaderBackgroundColor;
686 COLOR mHeaderFontColor;
687 COLOR mSeparatorColor;
688 COLOR mHeaderSeparatorColor;
689 COLOR mFastScrollLineColor;
690 COLOR mFastScrollRectColor;
691 bool hasHighlightColor;
692 bool hasFontHighlightColor;
693 bool isHighlighted;
694 COLOR mHighlightColor;
695 COLOR mFontHighlightColor;
696 int mHeaderIsStatic;
697 int startSelection;
698 int touchDebounce;
699 bool updateList;
700};
701
Dees_Troy51a0e822012-09-05 15:24:24 -0400702// GUIAnimation - Used for animations
Vojtech Bocekede51c52014-02-07 23:58:09 +0100703class GUIAnimation : public GUIObject, public RenderObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400704{
705public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200706 GUIAnimation(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400707
708public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200709 // Render - Render the full object to the GL surface
710 // Return 0 on success, <0 on error
711 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400712
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200713 // Update - Update any UI component animations (called <= 30 FPS)
714 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
715 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400716
717protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200718 AnimationResource* mAnimation;
719 int mFrame;
720 int mFPS;
721 int mLoop;
722 int mRender;
723 int mUpdateCount;
Dees_Troy51a0e822012-09-05 15:24:24 -0400724};
725
Vojtech Bocekede51c52014-02-07 23:58:09 +0100726class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400727{
728public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200729 GUIProgressBar(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400730
731public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200732 // Render - Render the full object to the GL surface
733 // Return 0 on success, <0 on error
734 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400735
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200736 // Update - Update any UI component animations (called <= 30 FPS)
737 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
738 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400739
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200740 // NotifyVarChange - Notify of a variable change
741 // Returns 0 on success, <0 on error
Vojtech Bocek07220562014-02-08 02:05:33 +0100742 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400743
744protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200745 Resource* mEmptyBar;
746 Resource* mFullBar;
747 std::string mMinValVar;
748 std::string mMaxValVar;
749 std::string mCurValVar;
750 float mSlide;
751 float mSlideInc;
752 int mSlideFrames;
753 int mLastPos;
Dees_Troy51a0e822012-09-05 15:24:24 -0400754
755protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200756 virtual int RenderInternal(void); // Does the actual render
Dees_Troy51a0e822012-09-05 15:24:24 -0400757};
758
Vojtech Bocekede51c52014-02-07 23:58:09 +0100759class GUISlider : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400760{
761public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200762 GUISlider(xml_node<>* node);
763 virtual ~GUISlider();
Dees_Troy51a0e822012-09-05 15:24:24 -0400764
765public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200766 // Render - Render the full object to the GL surface
767 // Return 0 on success, <0 on error
768 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400769
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200770 // Update - Update any UI component animations (called <= 30 FPS)
771 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
772 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400773
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200774 // NotifyTouch - Notify of a touch event
775 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
776 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400777
778protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200779 GUIAction* sAction;
780 Resource* sSlider;
781 Resource* sSliderUsed;
782 Resource* sTouch;
783 int sTouchW, sTouchH;
784 int sCurTouchX;
785 int sUpdate;
Dees_Troy51a0e822012-09-05 15:24:24 -0400786};
787
788#define MAX_KEYBOARD_LAYOUTS 5
789#define MAX_KEYBOARD_ROWS 9
790#define MAX_KEYBOARD_KEYS 20
791#define KEYBOARD_ACTION 253
792#define KEYBOARD_LAYOUT 254
793#define KEYBOARD_SWIPE_LEFT 252
794#define KEYBOARD_SWIPE_RIGHT 251
795#define KEYBOARD_ARROW_LEFT 250
796#define KEYBOARD_ARROW_RIGHT 249
797#define KEYBOARD_HOME 248
798#define KEYBOARD_END 247
799#define KEYBOARD_ARROW_UP 246
800#define KEYBOARD_ARROW_DOWN 245
801#define KEYBOARD_SPECIAL_KEYS 245
802#define KEYBOARD_BACKSPACE 8
803
Vojtech Bocekede51c52014-02-07 23:58:09 +0100804class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400805{
806public:
807 GUIKeyboard(xml_node<>* node);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200808 virtual ~GUIKeyboard();
Dees_Troy51a0e822012-09-05 15:24:24 -0400809
810public:
811 virtual int Render(void);
812 virtual int Update(void);
813 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
814 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
815
816protected:
817 virtual int GetSelection(int x, int y);
818
819protected:
820 struct keyboard_key_class
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200821 {
822 unsigned char key;
Dees_Troy51a0e822012-09-05 15:24:24 -0400823 unsigned char longpresskey;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200824 unsigned int end_x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400825 unsigned int layout;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200826 };
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600827 struct capslock_tracking_struct
828 {
829 int capslock;
830 int set_capslock;
831 int revert_layout;
832 };
Dees_Troy51a0e822012-09-05 15:24:24 -0400833
834 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
835 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600836 struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS];
Dees_Troy51a0e822012-09-05 15:24:24 -0400837 bool mRendered;
838 std::string mVariable;
839 unsigned int cursorLocation;
840 unsigned int currentLayout;
841 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
842 unsigned int KeyboardWidth, KeyboardHeight;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600843 int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400844 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400845 COLOR mHighlightColor;
Ethan Yonkerc3120d42014-02-17 07:55:00 -0600846 COLOR mCapsHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400847};
848
849// GUIInput - Used for keyboard input
Vojtech Bocekede51c52014-02-07 23:58:09 +0100850class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject
Dees_Troy51a0e822012-09-05 15:24:24 -0400851{
852public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200853 // w and h may be ignored, in which case, no bounding box is applied
854 GUIInput(xml_node<>* node);
Dees_Troy51a0e822012-09-05 15:24:24 -0400855 virtual ~GUIInput();
856
857public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200858 // Render - Render the full object to the GL surface
859 // Return 0 on success, <0 on error
860 virtual int Render(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400861
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200862 // Update - Update any UI component animations (called <= 30 FPS)
863 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
864 virtual int Update(void);
Dees_Troy51a0e822012-09-05 15:24:24 -0400865
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200866 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100867 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400868
869 // NotifyTouch - Notify of a touch event
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200870 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
871 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400872
873 virtual int NotifyKeyboard(int key);
874
875protected:
876 virtual int GetSelection(int x, int y);
877
878 // Handles displaying the text properly when chars are added, deleted, or for scrolling
879 virtual int HandleTextLocation(int x);
880
881protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200882 GUIText* mInputText;
Dees_Troy51a0e822012-09-05 15:24:24 -0400883 GUIAction* mAction;
884 Resource* mBackground;
885 Resource* mCursor;
886 Resource* mFont;
887 std::string mText;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200888 std::string mLastValue;
Dees_Troy51a0e822012-09-05 15:24:24 -0400889 std::string mVariable;
890 std::string mMask;
891 std::string mMaskVariable;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200892 COLOR mBackgroundColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400893 COLOR mCursorColor;
894 int scrollingX;
895 int lastX;
896 int mCursorLocation;
897 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
898 int mFontY;
899 unsigned skipChars;
900 unsigned mFontHeight;
901 unsigned CursorWidth;
902 bool mRendered;
903 bool HasMask;
904 bool DrawCursor;
905 bool isLocalChange;
906 bool HasAllowed;
907 bool HasDisabled;
908 std::string AllowedList;
909 std::string DisabledList;
910 unsigned MinLen;
911 unsigned MaxLen;
912};
913
914class HardwareKeyboard
915{
916public:
917 HardwareKeyboard(void);
918 virtual ~HardwareKeyboard();
919
920public:
921 virtual int KeyDown(int key_code);
922 virtual int KeyUp(int key_code);
923 virtual int KeyRepeat(void);
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100924
925 void ConsumeKeyRelease(int key);
926
927private:
928 std::set<int> mPressedKeys;
Dees_Troy51a0e822012-09-05 15:24:24 -0400929};
930
Vojtech Bocekede51c52014-02-07 23:58:09 +0100931class GUISliderValue: public GUIObject, public RenderObject, public ActionObject
Vojtech Bocek85932342013-04-01 22:11:33 +0200932{
933public:
934 GUISliderValue(xml_node<>* node);
935 virtual ~GUISliderValue();
936
937public:
938 // Render - Render the full object to the GL surface
939 // Return 0 on success, <0 on error
940 virtual int Render(void);
941
942 // Update - Update any UI component animations (called <= 30 FPS)
943 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
944 virtual int Update(void);
945
946 // SetPos - Update the position of the render object
947 // Return 0 on success, <0 on error
948 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
949
950 // NotifyTouch - Notify of a touch event
951 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
952 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
953
954 // Notify of a variable change
Vojtech Bocek07220562014-02-08 02:05:33 +0100955 virtual int NotifyVarChange(const std::string& varName, const std::string& value);
Vojtech Bocek85932342013-04-01 22:11:33 +0200956
957 // SetPageFocus - Notify when a page gains or loses focus
958 virtual void SetPageFocus(int inFocus);
959
960protected:
961 int measureText(const std::string& str);
962 int valueFromPct(float pct);
963 float pctFromValue(int value);
964 void loadValue(bool force = false);
965
966 std::string mVariable;
967 int mMax;
968 int mMin;
969 int mValue;
970 char *mValueStr;
971 float mValuePct;
972 std::string mMaxStr;
973 std::string mMinStr;
974 Resource *mFont;
975 GUIText* mLabel;
976 int mLabelW;
977 COLOR mTextColor;
978 COLOR mLineColor;
979 COLOR mSliderColor;
980 bool mShowRange;
981 bool mShowCurr;
982 int mLineX;
983 int mLineY;
984 int mLineH;
985 int mLinePadding;
986 int mPadding;
987 int mSliderY;
988 int mSliderW;
989 int mSliderH;
990 bool mRendered;
991 int mFontHeight;
992 GUIAction *mAction;
993 bool mChangeOnDrag;
Vojtech Bocek18d7c982014-08-04 17:19:28 +0200994 int mLineW;
995 bool mDragging;
996 Resource *mBackgroundImage;
997 Resource *mHandleImage;
998 Resource *mHandleHoverImage;
Vojtech Bocek85932342013-04-01 22:11:33 +0200999};
1000
Vojtech Bocek1fc30fc2014-01-29 18:37:19 +01001001class MouseCursor : public RenderObject
1002{
1003public:
1004 MouseCursor(int posX, int posY);
1005 virtual ~MouseCursor();
1006
1007 virtual int Render(void);
1008 virtual int Update(void);
1009 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
1010
1011 void Move(int deltaX, int deltaY);
1012 void GetPos(int& x, int& y);
1013 void LoadData(xml_node<>* node);
1014 void ResetData(int resX, int resY);
1015
1016private:
1017 int m_resX;
1018 int m_resY;
1019 bool m_moved;
1020 float m_speedMultiplier;
1021 COLOR m_color;
1022 Resource *m_image;
1023 bool m_present;
1024};
1025
Dees_Troy51a0e822012-09-05 15:24:24 -04001026// Helper APIs
1027bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
1028
1029#endif // _OBJECTS_HEADER
1030