blob: ff5429a9cf6efbd7b8ada06c167ab0bc36f8e086 [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_Troy51a0e822012-09-05 15:24:24 -040018// objects.h - Base classes for object manager of GUI
19
20#ifndef _OBJECTS_HEADER
21#define _OBJECTS_HEADER
22
23#include "rapidxml.hpp"
24#include <vector>
25#include <string>
26#include <map>
27
28extern "C" {
29#include "../minzip/Zip.h"
30}
31
32using namespace rapidxml;
33
34#include "../data.hpp"
35#include "resources.hpp"
36#include "pages.hpp"
Dees_Troya13d74f2013-03-24 08:54:55 -050037#include "../partitions.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040038
39class RenderObject
40{
41public:
42 enum Placement {
43 TOP_LEFT = 0,
44 TOP_RIGHT = 1,
45 BOTTOM_LEFT = 2,
46 BOTTOM_RIGHT = 3,
47 CENTER = 4,
48 CENTER_X_ONLY = 5,
49 };
50
51public:
52 RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; }
53 virtual ~RenderObject() {}
54
55public:
56 // Render - Render the full object to the GL surface
57 // Return 0 on success, <0 on error
58 virtual int Render(void) = 0;
59
60 // Update - Update any UI component animations (called <= 30 FPS)
61 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
62 virtual int Update(void) { return 0; }
63
64 // GetRenderPos - Returns the current position of the object
65 virtual int GetRenderPos(int& x, int& y, int& w, int& h) { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; }
66
67 // SetRenderPos - Update the position of the object
68 // Return 0 on success, <0 on error
69 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; }
70
71 // GetPlacement - Returns the current placement
72 virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; }
73
74 // SetPlacement - Update the current placement
75 virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; }
76
77 // SetPageFocus - Notify when a page gains or loses focus
78 virtual void SetPageFocus(int inFocus) { return; }
79
80protected:
81 int mRenderX, mRenderY, mRenderW, mRenderH;
82 Placement mPlacement;
83};
84
85class ActionObject
86{
87public:
88 ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; }
89 virtual ~ActionObject() {}
90
91public:
92 // NotifyTouch - Notify of a touch event
93 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
94 virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; }
95
96 // NotifyKey - Notify of a key press
97 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
98 virtual int NotifyKey(int key) { return 1; }
99
100 // GetRenderPos - Returns the current position of the object
101 virtual int GetActionPos(int& x, int& y, int& w, int& h) { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; }
102
103 // SetRenderPos - Update the position of the object
104 // Return 0 on success, <0 on error
105 virtual int SetActionPos(int x, int y, int w = 0, int h = 0);
106
107 // IsInRegion - Checks if the request is handled by this object
108 // Return 0 if this object handles the request, 1 if not
109 virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); }
110
111 // NotifyVarChange - Notify of a variable change
112 // Returns 0 on success, <0 on error
113 virtual int NotifyVarChange(std::string varName, std::string value) { return 0; }
114
115protected:
116 int mActionX, mActionY, mActionW, mActionH;
117};
118
119class Conditional
120{
121public:
122 Conditional(xml_node<>* node);
123
124public:
125 bool IsConditionVariable(std::string var);
126 bool isConditionTrue();
127 bool isConditionValid();
128 void NotifyPageSet();
129
130protected:
131 class Condition
132 {
133 public:
134 std::string mVar1;
135 std::string mVar2;
136 std::string mCompareOp;
137 std::string mLastVal;
138 };
139
140 std::vector<Condition> mConditions;
141
142protected:
143 bool isMounted(std::string vol);
144 bool isConditionTrue(Condition* condition);
145
146};
147
148class InputObject
149{
150public:
151 InputObject() { HasInputFocus = 0; }
152 virtual ~InputObject() {}
153
154public:
155 // NotifyKeyboard - Notify of keyboard input
156 // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error
157 virtual int NotifyKeyboard(int key) { return 1; }
158
159 virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; }
160
161protected:
162 int HasInputFocus;
163};
164
165// Derived Objects
166// GUIText - Used for static text
167class GUIText : public RenderObject, public ActionObject, public Conditional
168
169{
170public:
171 // w and h may be ignored, in which case, no bounding box is applied
172 GUIText(xml_node<>* node);
173
174public:
175 // Render - Render the full object to the GL surface
176 // Return 0 on success, <0 on error
177 virtual int Render(void);
178
179 // Update - Update any UI component animations (called <= 30 FPS)
180 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
181 virtual int Update(void);
182
183 // Retrieve the size of the current string (dynamic strings may change per call)
184 virtual int GetCurrentBounds(int& w, int& h);
185
186 // Notify of a variable change
187 virtual int NotifyVarChange(std::string varName, std::string value);
188
189 // Set maximum width in pixels
190 virtual int SetMaxWidth(unsigned width);
191
192 // Set number of characters to skip (for scrolling)
193 virtual int SkipCharCount(unsigned skip);
194
Dees_Troy4d12f962012-10-19 13:13:15 -0400195public:
196 bool isHighlighted;
197
Dees_Troy51a0e822012-09-05 15:24:24 -0400198protected:
199 std::string mText;
200 std::string mLastValue;
201 COLOR mColor;
Dees_Troy4d12f962012-10-19 13:13:15 -0400202 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400203 Resource* mFont;
204 int mIsStatic;
205 int mVarChanged;
206 int mFontHeight;
207 unsigned maxWidth;
208 unsigned charSkip;
Dees_Troy4d12f962012-10-19 13:13:15 -0400209 bool hasHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400210
211protected:
212 std::string parseText(void);
213};
214
215// GUIImage - Used for static image
216class GUIImage : public RenderObject
217{
218public:
219 GUIImage(xml_node<>* node);
220
221public:
222 // Render - Render the full object to the GL surface
223 // Return 0 on success, <0 on error
224 virtual int Render(void);
225
226 // SetRenderPos - Update the position of the object
227 // Return 0 on success, <0 on error
228 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
229
Dees_Troy4d12f962012-10-19 13:13:15 -0400230public:
231 bool isHighlighted;
232
Dees_Troy51a0e822012-09-05 15:24:24 -0400233protected:
234 Resource* mImage;
Dees_Troy4d12f962012-10-19 13:13:15 -0400235 Resource* mHighlightImage;
Dees_Troy51a0e822012-09-05 15:24:24 -0400236};
237
238// GUIFill - Used for fill colors
239class GUIFill : public RenderObject
240{
241public:
242 GUIFill(xml_node<>* node);
243
244public:
245 // Render - Render the full object to the GL surface
246 // Return 0 on success, <0 on error
247 virtual int Render(void);
248
249protected:
250 COLOR mColor;
251};
252
253// GUIAction - Used for standard actions
254class GUIAction : public ActionObject, public Conditional
255{
256public:
257 GUIAction(xml_node<>* node);
258
259public:
260 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
261 virtual int NotifyKey(int key);
262 virtual int NotifyVarChange(std::string varName, std::string value);
263 virtual int doActions();
264
265protected:
266 class Action
267 {
268 public:
269 std::string mFunction;
270 std::string mArg;
271 };
272
273 std::vector<Action> mActions;
274 int mKey;
275
276protected:
277 int getKeyByName(std::string key);
278 virtual int doAction(Action action, int isThreaded = 0);
279 static void* thread_start(void *cookie);
280 void simulate_progress_bar(void);
Dees_Troy657c3092012-09-10 20:32:10 -0400281 int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400282 void operation_start(const string operation_name);
283 void operation_end(const int operation_status, const int simulate);
284 static void* command_thread(void *cookie);
285};
286
287class GUIConsole : public RenderObject, public ActionObject
288{
289public:
290 GUIConsole(xml_node<>* node);
291
292public:
293 // Render - Render the full object to the GL surface
294 // Return 0 on success, <0 on error
295 virtual int Render(void);
296
297 // Update - Update any UI component animations (called <= 30 FPS)
298 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
299 virtual int Update(void);
300
301 // SetRenderPos - Update the position of the object
302 // Return 0 on success, <0 on error
303 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
304
305 // IsInRegion - Checks if the request is handled by this object
306 // Return 0 if this object handles the request, 1 if not
307 virtual int IsInRegion(int x, int y);
308
309 // NotifyTouch - Notify of a touch event
310 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers)
311 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
312
313protected:
314 enum SlideoutState
315 {
316 hidden = 0,
317 visible,
318 request_hide,
319 request_show
320 };
321 Resource* mFont;
322 Resource* mSlideoutImage;
323 COLOR mForegroundColor;
324 COLOR mBackgroundColor;
325 COLOR mScrollColor;
326 unsigned int mFontHeight;
327 int mCurrentLine;
328 unsigned int mLastCount;
329 unsigned int mMaxRows;
330 int mStartY;
331 int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH;
332 int mSlideinX, mSlideinY, mSlideinW, mSlideinH;
333 int mConsoleX, mConsoleY, mConsoleW, mConsoleH;
334 int mLastTouchX, mLastTouchY;
335 int mSlideMultiplier;
336 int mSlideout;
337 SlideoutState mSlideoutState;
338
339protected:
340 virtual int RenderSlideout(void);
341 virtual int RenderConsole(void);
342
343};
344
345class GUIButton : public RenderObject, public ActionObject, public Conditional
346{
347public:
348 GUIButton(xml_node<>* node);
349 virtual ~GUIButton();
350
351public:
352 // Render - Render the full object to the GL surface
353 // Return 0 on success, <0 on error
354 virtual int Render(void);
355
356 // Update - Update any UI component animations (called <= 30 FPS)
357 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
358 virtual int Update(void);
359
360 // SetPos - Update the position of the render object
361 // Return 0 on success, <0 on error
362 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
363
364 // NotifyTouch - Notify of a touch event
365 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
366 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
367
368protected:
369 GUIImage* mButtonImg;
370 Resource* mButtonIcon;
371 GUIText* mButtonLabel;
372 GUIAction* mAction;
373 int mTextX, mTextY, mTextW, mTextH;
374 int mIconX, mIconY, mIconW, mIconH;
375 bool mRendered;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600376 bool hasHighlightColor;
377 bool renderHighlight;
Dees_Troya13d74f2013-03-24 08:54:55 -0500378 bool hasFill;
379 COLOR mFillColor;
Dees_Troy1a7a6672013-02-15 09:39:07 -0600380 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400381};
382
383class GUICheckbox: public RenderObject, public ActionObject, public Conditional
384{
385public:
386 GUICheckbox(xml_node<>* node);
387 virtual ~GUICheckbox();
388
389public:
390 // Render - Render the full object to the GL surface
391 // Return 0 on success, <0 on error
392 virtual int Render(void);
393
394 // Update - Update any UI component animations (called <= 30 FPS)
395 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
396 virtual int Update(void);
397
398 // SetPos - Update the position of the render object
399 // Return 0 on success, <0 on error
400 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
401
402 // NotifyTouch - Notify of a touch event
403 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
404 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
405
406protected:
407 Resource* mChecked;
408 Resource* mUnchecked;
409 GUIText* mLabel;
410 int mTextX, mTextY;
411 int mCheckX, mCheckY, mCheckW, mCheckH;
412 int mLastState;
413 bool mRendered;
414 std::string mVarName;
415};
416
417class GUIFileSelector : public RenderObject, public ActionObject
418{
419public:
420 GUIFileSelector(xml_node<>* node);
421 virtual ~GUIFileSelector();
422
423public:
424 // Render - Render the full object to the GL surface
425 // Return 0 on success, <0 on error
426 virtual int Render(void);
427
428 // Update - Update any UI component animations (called <= 30 FPS)
429 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
430 virtual int Update(void);
431
432 // NotifyTouch - Notify of a touch event
433 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
434 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
435
436 // NotifyVarChange - Notify of a variable change
437 virtual int NotifyVarChange(std::string varName, std::string value);
438
439 // SetPos - Update the position of the render object
440 // Return 0 on success, <0 on error
441 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
442
443 // SetPageFocus - Notify when a page gains or loses focus
444 virtual void SetPageFocus(int inFocus);
445
446protected:
447 struct FileData {
448 std::string fileName;
449 unsigned char fileType; // Uses d_type format from struct dirent
450 mode_t protection; // Uses mode_t format from stat
451 uid_t userId;
452 gid_t groupId;
453 off_t fileSize;
454 time_t lastAccess; // Uses time_t format from stat
455 time_t lastModified; // Uses time_t format from stat
456 time_t lastStatChange; // Uses time_t format from stat
457 };
458
459protected:
460 virtual int GetSelection(int x, int y);
461
462 virtual int GetFileList(const std::string folder);
463 static bool fileSort(FileData d1, FileData d2);
464
465protected:
466 std::vector<FileData> mFolderList;
467 std::vector<FileData> mFileList;
468 std::string mPathVar;
469 std::string mExtn;
470 std::string mVariable;
471 std::string mSortVariable;
472 std::string mSelection;
473 std::string mHeaderText;
474 std::string mLastValue;
475 int actualLineHeight;
476 int mStart;
477 int mLineSpacing;
478 int mSeparatorH;
479 int mHeaderSeparatorH;
480 int mShowFolders, mShowFiles, mShowNavFolders;
481 int mUpdate;
482 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
483 int mHeaderH;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100484 int mFastScrollW;
485 int mFastScrollLineW;
486 int mFastScrollRectW;
487 int mFastScrollRectH;
488 int mFastScrollRectX;
489 int mFastScrollRectY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400490 static int mSortOrder;
491 int startY;
492 int scrollingSpeed;
493 int scrollingY;
494 int mHeaderIsStatic;
495 int touchDebounce;
496 unsigned mFontHeight;
497 unsigned mLineHeight;
498 int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth;
499 Resource* mHeaderIcon;
500 Resource* mFolderIcon;
501 Resource* mFileIcon;
502 Resource* mBackground;
503 Resource* mFont;
504 COLOR mBackgroundColor;
505 COLOR mFontColor;
506 COLOR mHeaderBackgroundColor;
507 COLOR mHeaderFontColor;
508 COLOR mSeparatorColor;
509 COLOR mHeaderSeparatorColor;
Vojtech Bocek7cc278b2013-02-24 01:40:19 +0100510 COLOR mFastScrollLineColor;
511 COLOR mFastScrollRectColor;
Dees_Troye7585ca2013-02-15 11:42:29 -0600512 bool hasHighlightColor;
513 bool hasFontHighlightColor;
514 bool isHighlighted;
515 COLOR mHighlightColor;
516 COLOR mFontHighlightColor;
517 int startSelection;
Dees_Troyc0583f52013-02-28 11:19:57 -0600518 bool updateFileList;
Dees_Troy51a0e822012-09-05 15:24:24 -0400519};
520
521class GUIListBox : public RenderObject, public ActionObject
522{
523public:
524 GUIListBox(xml_node<>* node);
525 virtual ~GUIListBox();
526
527public:
528 // Render - Render the full object to the GL surface
529 // Return 0 on success, <0 on error
530 virtual int Render(void);
531
532 // Update - Update any UI component animations (called <= 30 FPS)
533 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
534 virtual int Update(void);
535
536 // NotifyTouch - Notify of a touch event
537 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
538 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
539
540 // NotifyVarChange - Notify of a variable change
541 virtual int NotifyVarChange(std::string varName, std::string value);
542
543 // SetPos - Update the position of the render object
544 // Return 0 on success, <0 on error
545 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
546
547 // SetPageFocus - Notify when a page gains or loses focus
548 virtual void SetPageFocus(int inFocus);
549
550protected:
551 struct ListData {
552 std::string displayName;
553 std::string variableValue;
554 unsigned int selected;
555 };
556
557protected:
558 virtual int GetSelection(int x, int y);
559
560protected:
561 std::vector<ListData> mList;
562 std::string mVariable;
563 std::string mSelection;
564 std::string currentValue;
Dees_Troyeead9852013-02-15 14:31:06 -0600565 std::string mHeaderText;
566 std::string mLastValue;
567 int actualLineHeight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400568 int mStart;
Dees_Troyeead9852013-02-15 14:31:06 -0600569 int startY;
570 int mSeparatorH, mHeaderSeparatorH;
Dees_Troy51a0e822012-09-05 15:24:24 -0400571 int mLineSpacing;
572 int mUpdate;
Dees_Troyeead9852013-02-15 14:31:06 -0600573 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000574 int mFastScrollW;
575 int mFastScrollLineW;
576 int mFastScrollRectW;
577 int mFastScrollRectH;
578 int mFastScrollRectX;
579 int mFastScrollRectY;
Dees_Troyeead9852013-02-15 14:31:06 -0600580 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
581 int scrollingSpeed;
582 int scrollingY;
Dees_Troy51a0e822012-09-05 15:24:24 -0400583 static int mSortOrder;
584 unsigned mFontHeight;
585 unsigned mLineHeight;
Dees_Troyeead9852013-02-15 14:31:06 -0600586 Resource* mHeaderIcon;
Dees_Troy51a0e822012-09-05 15:24:24 -0400587 Resource* mIconSelected;
588 Resource* mIconUnselected;
589 Resource* mBackground;
590 Resource* mFont;
591 COLOR mBackgroundColor;
592 COLOR mFontColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600593 COLOR mHeaderBackgroundColor;
594 COLOR mHeaderFontColor;
595 COLOR mSeparatorColor;
596 COLOR mHeaderSeparatorColor;
Dees_Troy58f5cf02013-02-27 22:21:41 +0000597 COLOR mFastScrollLineColor;
598 COLOR mFastScrollRectColor;
Dees_Troyeead9852013-02-15 14:31:06 -0600599 bool hasHighlightColor;
600 bool hasFontHighlightColor;
601 bool isHighlighted;
602 COLOR mHighlightColor;
603 COLOR mFontHighlightColor;
604 int mHeaderIsStatic;
605 int startSelection;
606 int touchDebounce;
Dees_Troy51a0e822012-09-05 15:24:24 -0400607};
608
Dees_Troya13d74f2013-03-24 08:54:55 -0500609class GUIPartitionList : public RenderObject, public ActionObject
610{
611public:
612 GUIPartitionList(xml_node<>* node);
613 virtual ~GUIPartitionList();
614
615public:
616 // Render - Render the full object to the GL surface
617 // Return 0 on success, <0 on error
618 virtual int Render(void);
619
620 // Update - Update any UI component animations (called <= 30 FPS)
621 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
622 virtual int Update(void);
623
624 // NotifyTouch - Notify of a touch event
625 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
626 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
627
628 // NotifyVarChange - Notify of a variable change
629 virtual int NotifyVarChange(std::string varName, std::string value);
630
631 // SetPos - Update the position of the render object
632 // Return 0 on success, <0 on error
633 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
634
635 // SetPageFocus - Notify when a page gains or loses focus
636 virtual void SetPageFocus(int inFocus);
637
638protected:
639
640protected:
641 virtual int GetSelection(int x, int y);
642 virtual void MatchList(void);
643
644protected:
645 std::vector<PartitionList> mList;
646 std::string ListType;
647 std::string mVariable;
648 std::string selectedList;
649 std::string currentValue;
650 std::string mHeaderText;
651 std::string mLastValue;
652 int actualLineHeight;
653 int mStart;
654 int startY;
655 int mSeparatorH, mHeaderSeparatorH;
656 int mLineSpacing;
657 int mUpdate;
658 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH;
659 int mFastScrollW;
660 int mFastScrollLineW;
661 int mFastScrollRectW;
662 int mFastScrollRectH;
663 int mFastScrollRectX;
664 int mFastScrollRectY;
665 int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth;
666 int scrollingSpeed;
667 int scrollingY;
668 static int mSortOrder;
669 unsigned mFontHeight;
670 unsigned mLineHeight;
671 Resource* mHeaderIcon;
672 Resource* mIconSelected;
673 Resource* mIconUnselected;
674 Resource* mBackground;
675 Resource* mFont;
676 COLOR mBackgroundColor;
677 COLOR mFontColor;
678 COLOR mHeaderBackgroundColor;
679 COLOR mHeaderFontColor;
680 COLOR mSeparatorColor;
681 COLOR mHeaderSeparatorColor;
682 COLOR mFastScrollLineColor;
683 COLOR mFastScrollRectColor;
684 bool hasHighlightColor;
685 bool hasFontHighlightColor;
686 bool isHighlighted;
687 COLOR mHighlightColor;
688 COLOR mFontHighlightColor;
689 int mHeaderIsStatic;
690 int startSelection;
691 int touchDebounce;
692 bool updateList;
693};
694
Dees_Troy51a0e822012-09-05 15:24:24 -0400695// GUIAnimation - Used for animations
696class GUIAnimation : public RenderObject
697{
698public:
699 GUIAnimation(xml_node<>* node);
700
701public:
702 // Render - Render the full object to the GL surface
703 // Return 0 on success, <0 on error
704 virtual int Render(void);
705
706 // Update - Update any UI component animations (called <= 30 FPS)
707 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
708 virtual int Update(void);
709
710protected:
711 AnimationResource* mAnimation;
712 int mFrame;
713 int mFPS;
714 int mLoop;
715 int mRender;
716 int mUpdateCount;
717};
718
719class GUIProgressBar : public RenderObject, public ActionObject
720{
721public:
722 GUIProgressBar(xml_node<>* node);
723
724public:
725 // Render - Render the full object to the GL surface
726 // Return 0 on success, <0 on error
727 virtual int Render(void);
728
729 // Update - Update any UI component animations (called <= 30 FPS)
730 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
731 virtual int Update(void);
732
733 // NotifyVarChange - Notify of a variable change
734 // Returns 0 on success, <0 on error
735 virtual int NotifyVarChange(std::string varName, std::string value);
736
737protected:
738 Resource* mEmptyBar;
739 Resource* mFullBar;
740 std::string mMinValVar;
741 std::string mMaxValVar;
742 std::string mCurValVar;
743 float mSlide;
744 float mSlideInc;
745 int mSlideFrames;
746 int mLastPos;
747
748protected:
749 virtual int RenderInternal(void); // Does the actual render
750
751};
752
753class GUISlider : public RenderObject, public ActionObject
754{
755public:
756 GUISlider(xml_node<>* node);
757 virtual ~GUISlider();
758
759public:
760 // Render - Render the full object to the GL surface
761 // Return 0 on success, <0 on error
762 virtual int Render(void);
763
764 // Update - Update any UI component animations (called <= 30 FPS)
765 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
766 virtual int Update(void);
767
768 // NotifyTouch - Notify of a touch event
769 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
770 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
771
772protected:
773 GUIAction* sAction;
774 Resource* sSlider;
775 Resource* sSliderUsed;
776 Resource* sTouch;
777 int sTouchW, sTouchH;
778 int sCurTouchX;
779 int sUpdate;
780};
781
782#define MAX_KEYBOARD_LAYOUTS 5
783#define MAX_KEYBOARD_ROWS 9
784#define MAX_KEYBOARD_KEYS 20
785#define KEYBOARD_ACTION 253
786#define KEYBOARD_LAYOUT 254
787#define KEYBOARD_SWIPE_LEFT 252
788#define KEYBOARD_SWIPE_RIGHT 251
789#define KEYBOARD_ARROW_LEFT 250
790#define KEYBOARD_ARROW_RIGHT 249
791#define KEYBOARD_HOME 248
792#define KEYBOARD_END 247
793#define KEYBOARD_ARROW_UP 246
794#define KEYBOARD_ARROW_DOWN 245
795#define KEYBOARD_SPECIAL_KEYS 245
796#define KEYBOARD_BACKSPACE 8
797
798class GUIKeyboard : public RenderObject, public ActionObject, public Conditional
799{
800public:
801 GUIKeyboard(xml_node<>* node);
802 virtual ~GUIKeyboard();
803
804public:
805 virtual int Render(void);
806 virtual int Update(void);
807 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
808 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
809
810protected:
811 virtual int GetSelection(int x, int y);
812
813protected:
814 struct keyboard_key_class
815 {
816 unsigned char key;
817 unsigned char longpresskey;
818 unsigned int end_x;
819 unsigned int layout;
820 };
821
822 Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS];
823 struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS];
824 bool mRendered;
825 std::string mVariable;
826 unsigned int cursorLocation;
827 unsigned int currentLayout;
828 unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS];
829 unsigned int KeyboardWidth, KeyboardHeight;
Dees_Troy30b962e2012-10-19 20:48:59 -0400830 int rowY, colX, highlightRenderCount, hasHighlight;
Dees_Troy51a0e822012-09-05 15:24:24 -0400831 GUIAction* mAction;
Dees_Troy30b962e2012-10-19 20:48:59 -0400832 COLOR mHighlightColor;
Dees_Troy51a0e822012-09-05 15:24:24 -0400833};
834
835// GUIInput - Used for keyboard input
836class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject
837{
838public:
839 // w and h may be ignored, in which case, no bounding box is applied
840 GUIInput(xml_node<>* node);
841 virtual ~GUIInput();
842
843public:
844 // Render - Render the full object to the GL surface
845 // Return 0 on success, <0 on error
846 virtual int Render(void);
847
848 // Update - Update any UI component animations (called <= 30 FPS)
849 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
850 virtual int Update(void);
851
852 // Notify of a variable change
853 virtual int NotifyVarChange(std::string varName, std::string value);
854
855 // NotifyTouch - Notify of a touch event
856 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
857 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
858
859 virtual int NotifyKeyboard(int key);
860
861protected:
862 virtual int GetSelection(int x, int y);
863
864 // Handles displaying the text properly when chars are added, deleted, or for scrolling
865 virtual int HandleTextLocation(int x);
866
867protected:
868 GUIText* mInputText;
869 GUIAction* mAction;
870 Resource* mBackground;
871 Resource* mCursor;
872 Resource* mFont;
873 std::string mText;
874 std::string mLastValue;
875 std::string mVariable;
876 std::string mMask;
877 std::string mMaskVariable;
878 COLOR mBackgroundColor;
879 COLOR mCursorColor;
880 int scrollingX;
881 int lastX;
882 int mCursorLocation;
883 int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH;
884 int mFontY;
885 unsigned skipChars;
886 unsigned mFontHeight;
887 unsigned CursorWidth;
888 bool mRendered;
889 bool HasMask;
890 bool DrawCursor;
891 bool isLocalChange;
892 bool HasAllowed;
893 bool HasDisabled;
894 std::string AllowedList;
895 std::string DisabledList;
896 unsigned MinLen;
897 unsigned MaxLen;
898};
899
900class HardwareKeyboard
901{
902public:
903 HardwareKeyboard(void);
904 virtual ~HardwareKeyboard();
905
906public:
907 virtual int KeyDown(int key_code);
908 virtual int KeyUp(int key_code);
909 virtual int KeyRepeat(void);
910};
911
Vojtech Bocek85932342013-04-01 22:11:33 +0200912class GUISliderValue: public RenderObject, public ActionObject, public Conditional
913{
914public:
915 GUISliderValue(xml_node<>* node);
916 virtual ~GUISliderValue();
917
918public:
919 // Render - Render the full object to the GL surface
920 // Return 0 on success, <0 on error
921 virtual int Render(void);
922
923 // Update - Update any UI component animations (called <= 30 FPS)
924 // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error
925 virtual int Update(void);
926
927 // SetPos - Update the position of the render object
928 // Return 0 on success, <0 on error
929 virtual int SetRenderPos(int x, int y, int w = 0, int h = 0);
930
931 // NotifyTouch - Notify of a touch event
932 // Return 0 on success, >0 to ignore remainder of touch, and <0 on error
933 virtual int NotifyTouch(TOUCH_STATE state, int x, int y);
934
935 // Notify of a variable change
936 virtual int NotifyVarChange(std::string varName, std::string value);
937
938 // SetPageFocus - Notify when a page gains or loses focus
939 virtual void SetPageFocus(int inFocus);
940
941protected:
942 int measureText(const std::string& str);
943 int valueFromPct(float pct);
944 float pctFromValue(int value);
945 void loadValue(bool force = false);
946
947 std::string mVariable;
948 int mMax;
949 int mMin;
950 int mValue;
951 char *mValueStr;
952 float mValuePct;
953 std::string mMaxStr;
954 std::string mMinStr;
955 Resource *mFont;
956 GUIText* mLabel;
957 int mLabelW;
958 COLOR mTextColor;
959 COLOR mLineColor;
960 COLOR mSliderColor;
961 bool mShowRange;
962 bool mShowCurr;
963 int mLineX;
964 int mLineY;
965 int mLineH;
966 int mLinePadding;
967 int mPadding;
968 int mSliderY;
969 int mSliderW;
970 int mSliderH;
971 bool mRendered;
972 int mFontHeight;
973 GUIAction *mAction;
974 bool mChangeOnDrag;
975 int lineW;
976};
977
Dees_Troy51a0e822012-09-05 15:24:24 -0400978// Helper APIs
979bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL);
980
981#endif // _OBJECTS_HEADER
982