Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1 | /* |
| 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 Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 18 | |
| 19 | // objects.hpp - Base classes for object manager of GUI |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 20 | |
| 21 | #ifndef _OBJECTS_HEADER |
| 22 | #define _OBJECTS_HEADER |
| 23 | |
| 24 | #include "rapidxml.hpp" |
| 25 | #include <vector> |
| 26 | #include <string> |
| 27 | #include <map> |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 28 | #include <set> |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 29 | #include <time.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 30 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 31 | using namespace rapidxml; |
| 32 | |
| 33 | #include "../data.hpp" |
| 34 | #include "resources.hpp" |
| 35 | #include "pages.hpp" |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 36 | #include "../partitions.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 37 | |
Ethan Yonker | 751a85e | 2014-12-12 16:59:10 -0600 | [diff] [blame] | 38 | #ifndef TW_X_OFFSET |
| 39 | #define TW_X_OFFSET 0 |
| 40 | #endif |
| 41 | #ifndef TW_Y_OFFSET |
| 42 | #define TW_Y_OFFSET 0 |
| 43 | #endif |
| 44 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 45 | class RenderObject |
| 46 | { |
| 47 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 48 | enum Placement { |
| 49 | TOP_LEFT = 0, |
| 50 | TOP_RIGHT = 1, |
| 51 | BOTTOM_LEFT = 2, |
| 52 | BOTTOM_RIGHT = 3, |
| 53 | CENTER = 4, |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 54 | CENTER_X_ONLY = 5, |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 55 | }; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 56 | |
| 57 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 58 | RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; } |
| 59 | virtual ~RenderObject() {} |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 60 | |
| 61 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 62 | // Render - Render the full object to the GL surface |
| 63 | // Return 0 on success, <0 on error |
| 64 | virtual int Render(void) = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 66 | // Update - Update any UI component animations (called <= 30 FPS) |
| 67 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 68 | virtual int Update(void) { return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 69 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 70 | // GetRenderPos - Returns the current position of the object |
| 71 | virtual int GetRenderPos(int& x, int& y, int& w, int& h) { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 72 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 73 | // SetRenderPos - Update the position of the object |
| 74 | // Return 0 on success, <0 on error |
| 75 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0) { mRenderX = x; mRenderY = y; if (w || h) { mRenderW = w; mRenderH = h; } return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 77 | // GetPlacement - Returns the current placement |
| 78 | virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 79 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 80 | // SetPlacement - Update the current placement |
| 81 | virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 82 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 83 | // SetPageFocus - Notify when a page gains or loses focus |
| 84 | virtual void SetPageFocus(int inFocus) { return; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 85 | |
| 86 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 87 | int mRenderX, mRenderY, mRenderW, mRenderH; |
| 88 | Placement mPlacement; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | class ActionObject |
| 92 | { |
| 93 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 94 | ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; } |
| 95 | virtual ~ActionObject() {} |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 96 | |
| 97 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 98 | // NotifyTouch - Notify of a touch event |
| 99 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 100 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 101 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 102 | // NotifyKey - Notify of a key press |
| 103 | // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 104 | virtual int NotifyKey(int key, bool down) { return 1; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 105 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 106 | // GetRenderPos - Returns the current position of the object |
| 107 | virtual int GetActionPos(int& x, int& y, int& w, int& h) { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 108 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 109 | // SetRenderPos - Update the position of the object |
| 110 | // Return 0 on success, <0 on error |
| 111 | virtual int SetActionPos(int x, int y, int w = 0, int h = 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 112 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 113 | // IsInRegion - Checks if the request is handled by this object |
| 114 | // Return 0 if this object handles the request, 1 if not |
| 115 | virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 116 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 117 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 118 | int mActionX, mActionY, mActionW, mActionH; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 119 | }; |
| 120 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 121 | class GUIObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 122 | { |
| 123 | public: |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 124 | GUIObject(xml_node<>* node); |
| 125 | virtual ~GUIObject(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 126 | |
| 127 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 128 | bool IsConditionVariable(std::string var); |
| 129 | bool isConditionTrue(); |
| 130 | bool isConditionValid(); |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 131 | |
| 132 | // NotifyVarChange - Notify of a variable change |
| 133 | // Returns 0 on success, <0 on error |
| 134 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 135 | |
| 136 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 137 | class Condition |
| 138 | { |
| 139 | public: |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 140 | Condition() { |
| 141 | mLastResult = true; |
| 142 | } |
| 143 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 144 | std::string mVar1; |
| 145 | std::string mVar2; |
| 146 | std::string mCompareOp; |
| 147 | std::string mLastVal; |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 148 | bool mLastResult; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 149 | }; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 150 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 151 | std::vector<Condition> mConditions; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 152 | |
| 153 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 154 | bool isMounted(std::string vol); |
| 155 | bool isConditionTrue(Condition* condition); |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 156 | |
| 157 | bool mConditionsResult; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | class InputObject |
| 161 | { |
| 162 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 163 | InputObject() { HasInputFocus = 0; } |
| 164 | virtual ~InputObject() {} |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 165 | |
| 166 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 167 | // NotifyKeyboard - Notify of keyboard input |
| 168 | // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error |
| 169 | virtual int NotifyKeyboard(int key) { return 1; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 170 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 171 | virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 172 | |
| 173 | protected: |
| 174 | int HasInputFocus; |
| 175 | }; |
| 176 | |
| 177 | // Derived Objects |
| 178 | // GUIText - Used for static text |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 179 | class GUIText : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 180 | { |
| 181 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 182 | // w and h may be ignored, in which case, no bounding box is applied |
| 183 | GUIText(xml_node<>* node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 184 | |
| 185 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 186 | // Render - Render the full object to the GL surface |
| 187 | // Return 0 on success, <0 on error |
| 188 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 189 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 190 | // Update - Update any UI component animations (called <= 30 FPS) |
| 191 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 192 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 193 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 194 | // Retrieve the size of the current string (dynamic strings may change per call) |
| 195 | virtual int GetCurrentBounds(int& w, int& h); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 196 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 197 | // Notify of a variable change |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 198 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 199 | |
| 200 | // Set maximum width in pixels |
| 201 | virtual int SetMaxWidth(unsigned width); |
| 202 | |
| 203 | // Set number of characters to skip (for scrolling) |
| 204 | virtual int SkipCharCount(unsigned skip); |
| 205 | |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 206 | public: |
| 207 | bool isHighlighted; |
| 208 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 209 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 210 | std::string mText; |
| 211 | std::string mLastValue; |
| 212 | COLOR mColor; |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 213 | COLOR mHighlightColor; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 214 | Resource* mFont; |
| 215 | int mIsStatic; |
| 216 | int mVarChanged; |
| 217 | int mFontHeight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 218 | unsigned maxWidth; |
| 219 | unsigned charSkip; |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 220 | bool hasHighlightColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 221 | |
| 222 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 223 | std::string parseText(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | // GUIImage - Used for static image |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 227 | class GUIImage : public GUIObject, public RenderObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 228 | { |
| 229 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 230 | GUIImage(xml_node<>* node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 231 | |
| 232 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 233 | // Render - Render the full object to the GL surface |
| 234 | // Return 0 on success, <0 on error |
| 235 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 236 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 237 | // SetRenderPos - Update the position of the object |
| 238 | // Return 0 on success, <0 on error |
| 239 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 240 | |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 241 | public: |
| 242 | bool isHighlighted; |
| 243 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 244 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 245 | Resource* mImage; |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 246 | Resource* mHighlightImage; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | // GUIFill - Used for fill colors |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 250 | class GUIFill : public GUIObject, public RenderObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 251 | { |
| 252 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 253 | GUIFill(xml_node<>* node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 254 | |
| 255 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 256 | // Render - Render the full object to the GL surface |
| 257 | // Return 0 on success, <0 on error |
| 258 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 259 | |
| 260 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | COLOR mColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | // GUIAction - Used for standard actions |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 265 | class GUIAction : public GUIObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 266 | { |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 267 | friend class ActionThread; |
| 268 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 269 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 270 | GUIAction(xml_node<>* node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 271 | |
| 272 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 273 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 274 | virtual int NotifyKey(int key, bool down); |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 275 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 276 | |
| 277 | int doActions(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 278 | |
| 279 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 280 | class Action |
| 281 | { |
| 282 | public: |
| 283 | std::string mFunction; |
| 284 | std::string mArg; |
| 285 | }; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 286 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 287 | std::vector<Action> mActions; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 288 | std::map<int, bool> mKeys; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 289 | |
| 290 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 291 | int getKeyByName(std::string key); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 292 | int doAction(Action action); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 293 | bool needsToRunInSeparateThread(const Action& action); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 294 | void simulate_progress_bar(void); |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 295 | int flash_zip(std::string filename, int* wipe_cache); |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 296 | void reinject_after_flash(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 297 | void operation_start(const string operation_name); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 298 | void operation_end(const int operation_status); |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 299 | time_t Start; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 300 | |
| 301 | // map action name to function pointer |
| 302 | typedef int (GUIAction::*execFunction)(std::string); |
| 303 | typedef std::map<std::string, execFunction> mapFunc; |
| 304 | static mapFunc mf; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 305 | static std::set<std::string> setActionsRunningInCallerThread; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 306 | |
| 307 | // GUI actions |
| 308 | int reboot(std::string arg); |
| 309 | int home(std::string arg); |
| 310 | int key(std::string arg); |
| 311 | int page(std::string arg); |
| 312 | int reload(std::string arg); |
| 313 | int readBackup(std::string arg); |
| 314 | int set(std::string arg); |
| 315 | int clear(std::string arg); |
| 316 | int mount(std::string arg); |
| 317 | int unmount(std::string arg); |
| 318 | int restoredefaultsettings(std::string arg); |
| 319 | int copylog(std::string arg); |
| 320 | int compute(std::string arg); |
| 321 | int setguitimezone(std::string arg); |
| 322 | int overlay(std::string arg); |
| 323 | int queuezip(std::string arg); |
| 324 | int cancelzip(std::string arg); |
| 325 | int queueclear(std::string arg); |
| 326 | int sleep(std::string arg); |
| 327 | int appenddatetobackupname(std::string arg); |
| 328 | int generatebackupname(std::string arg); |
| 329 | int checkpartitionlist(std::string arg); |
| 330 | int getpartitiondetails(std::string arg); |
| 331 | int screenshot(std::string arg); |
| 332 | int setbrightness(std::string arg); |
| 333 | |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 334 | // (originally) threaded actions |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 335 | int fileexists(std::string arg); |
| 336 | int flash(std::string arg); |
| 337 | int wipe(std::string arg); |
| 338 | int refreshsizes(std::string arg); |
| 339 | int nandroid(std::string arg); |
| 340 | int fixpermissions(std::string arg); |
| 341 | int dd(std::string arg); |
| 342 | int partitionsd(std::string arg); |
| 343 | int installhtcdumlock(std::string arg); |
| 344 | int htcdumlockrestoreboot(std::string arg); |
| 345 | int htcdumlockreflashrecovery(std::string arg); |
| 346 | int cmd(std::string arg); |
| 347 | int terminalcommand(std::string arg); |
| 348 | int killterminal(std::string arg); |
| 349 | int reinjecttwrp(std::string arg); |
| 350 | int checkbackupname(std::string arg); |
| 351 | int decrypt(std::string arg); |
| 352 | int adbsideload(std::string arg); |
| 353 | int adbsideloadcancel(std::string arg); |
| 354 | int openrecoveryscript(std::string arg); |
| 355 | int installsu(std::string arg); |
| 356 | int fixsu(std::string arg); |
| 357 | int decrypt_backup(std::string arg); |
| 358 | int repair(std::string arg); |
| 359 | int changefilesystem(std::string arg); |
| 360 | int startmtp(std::string arg); |
| 361 | int stopmtp(std::string arg); |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 362 | int flashimage(std::string arg); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 363 | |
| 364 | int simulate; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 365 | }; |
| 366 | |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 367 | class ActionThread |
| 368 | { |
| 369 | public: |
| 370 | ActionThread(); |
| 371 | ~ActionThread(); |
| 372 | |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 373 | void threadActions(GUIAction *act); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 374 | void run(void *data); |
| 375 | private: |
| 376 | struct ThreadData |
| 377 | { |
| 378 | GUIAction *act; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 379 | }; |
| 380 | |
| 381 | pthread_t m_thread; |
| 382 | bool m_thread_running; |
| 383 | pthread_mutex_t m_act_lock; |
| 384 | }; |
| 385 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 386 | class GUIConsole : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 387 | { |
| 388 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 389 | GUIConsole(xml_node<>* node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 390 | |
| 391 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 392 | // Render - Render the full object to the GL surface |
| 393 | // Return 0 on success, <0 on error |
| 394 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 395 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 396 | // Update - Update any UI component animations (called <= 30 FPS) |
| 397 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 398 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 399 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 400 | // SetRenderPos - Update the position of the object |
| 401 | // Return 0 on success, <0 on error |
| 402 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 403 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 404 | // IsInRegion - Checks if the request is handled by this object |
| 405 | // Return 0 if this object handles the request, 1 if not |
| 406 | virtual int IsInRegion(int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 407 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 408 | // NotifyTouch - Notify of a touch event |
| 409 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers) |
| 410 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 411 | |
| 412 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 413 | enum SlideoutState |
| 414 | { |
| 415 | hidden = 0, |
| 416 | visible, |
| 417 | request_hide, |
| 418 | request_show |
| 419 | }; |
| 420 | |
| 421 | Resource* mFont; |
| 422 | Resource* mSlideoutImage; |
| 423 | COLOR mForegroundColor; |
| 424 | COLOR mBackgroundColor; |
| 425 | COLOR mScrollColor; |
| 426 | unsigned int mFontHeight; |
| 427 | int mCurrentLine; |
| 428 | unsigned int mLastCount; |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 429 | unsigned int RenderCount; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 430 | unsigned int mMaxRows; |
| 431 | int mStartY; |
| 432 | int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH; |
| 433 | int mSlideinX, mSlideinY, mSlideinW, mSlideinH; |
| 434 | int mConsoleX, mConsoleY, mConsoleW, mConsoleH; |
| 435 | int mLastTouchX, mLastTouchY; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 436 | int mSlideout; |
| 437 | SlideoutState mSlideoutState; |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 438 | std::vector<std::string> rConsole; |
Ethan Yonker | bf2cb1c | 2014-07-02 10:15:54 -0500 | [diff] [blame] | 439 | std::vector<std::string> rConsoleColor; |
Dees Troy | 31218ec | 2014-02-25 20:35:56 +0000 | [diff] [blame] | 440 | bool mRender; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 441 | |
| 442 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 443 | virtual int RenderSlideout(void); |
| 444 | virtual int RenderConsole(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 445 | }; |
| 446 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 447 | class GUIButton : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 448 | { |
| 449 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 450 | GUIButton(xml_node<>* node); |
| 451 | virtual ~GUIButton(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 452 | |
| 453 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 454 | // Render - Render the full object to the GL surface |
| 455 | // Return 0 on success, <0 on error |
| 456 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 457 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 458 | // Update - Update any UI component animations (called <= 30 FPS) |
| 459 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 460 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 461 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 462 | // SetPos - Update the position of the render object |
| 463 | // Return 0 on success, <0 on error |
| 464 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 465 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 466 | // NotifyTouch - Notify of a touch event |
| 467 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 468 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 469 | |
| 470 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 471 | GUIImage* mButtonImg; |
| 472 | Resource* mButtonIcon; |
| 473 | GUIText* mButtonLabel; |
| 474 | GUIAction* mAction; |
| 475 | int mTextX, mTextY, mTextW, mTextH; |
| 476 | int mIconX, mIconY, mIconW, mIconH; |
| 477 | bool mRendered; |
Dees_Troy | 1a7a667 | 2013-02-15 09:39:07 -0600 | [diff] [blame] | 478 | bool hasHighlightColor; |
| 479 | bool renderHighlight; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 480 | bool hasFill; |
| 481 | COLOR mFillColor; |
Dees_Troy | 1a7a667 | 2013-02-15 09:39:07 -0600 | [diff] [blame] | 482 | COLOR mHighlightColor; |
Dees Troy | b21cc64 | 2013-09-10 17:36:41 +0000 | [diff] [blame] | 483 | Placement TextPlacement; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 484 | }; |
| 485 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 486 | class GUICheckbox: public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 487 | { |
| 488 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 489 | GUICheckbox(xml_node<>* node); |
| 490 | virtual ~GUICheckbox(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 491 | |
| 492 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 493 | // Render - Render the full object to the GL surface |
| 494 | // Return 0 on success, <0 on error |
| 495 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 496 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 497 | // Update - Update any UI component animations (called <= 30 FPS) |
| 498 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 499 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 500 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 501 | // SetPos - Update the position of the render object |
| 502 | // Return 0 on success, <0 on error |
| 503 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 504 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 505 | // NotifyTouch - Notify of a touch event |
| 506 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 507 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 508 | |
| 509 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 510 | Resource* mChecked; |
| 511 | Resource* mUnchecked; |
| 512 | GUIText* mLabel; |
| 513 | int mTextX, mTextY; |
| 514 | int mCheckX, mCheckY, mCheckW, mCheckH; |
| 515 | int mLastState; |
| 516 | bool mRendered; |
| 517 | std::string mVarName; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 518 | }; |
| 519 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 520 | class GUIFileSelector : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 521 | { |
| 522 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 523 | GUIFileSelector(xml_node<>* node); |
| 524 | virtual ~GUIFileSelector(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 525 | |
| 526 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 527 | // Render - Render the full object to the GL surface |
| 528 | // Return 0 on success, <0 on error |
| 529 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 530 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 531 | // Update - Update any UI component animations (called <= 30 FPS) |
| 532 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 533 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 534 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 535 | // NotifyTouch - Notify of a touch event |
| 536 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 537 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 538 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 539 | // NotifyVarChange - Notify of a variable change |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 540 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 541 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 542 | // SetPos - Update the position of the render object |
| 543 | // Return 0 on success, <0 on error |
| 544 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 545 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 546 | // SetPageFocus - Notify when a page gains or loses focus |
| 547 | virtual void SetPageFocus(int inFocus); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 548 | |
| 549 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 550 | struct FileData { |
| 551 | std::string fileName; |
| 552 | unsigned char fileType; // Uses d_type format from struct dirent |
| 553 | mode_t protection; // Uses mode_t format from stat |
| 554 | uid_t userId; |
| 555 | gid_t groupId; |
| 556 | off_t fileSize; |
| 557 | time_t lastAccess; // Uses time_t format from stat |
| 558 | time_t lastModified; // Uses time_t format from stat |
| 559 | time_t lastStatChange; // Uses time_t format from stat |
| 560 | }; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 561 | |
| 562 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 563 | virtual int GetSelection(int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 564 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 565 | virtual int GetFileList(const std::string folder); |
| 566 | static bool fileSort(FileData d1, FileData d2); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 567 | |
| 568 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 569 | std::vector<FileData> mFolderList; |
| 570 | std::vector<FileData> mFileList; |
| 571 | std::string mPathVar; |
| 572 | std::string mExtn; |
| 573 | std::string mVariable; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 574 | std::string mSortVariable; |
| 575 | std::string mSelection; |
| 576 | std::string mHeaderText; |
| 577 | std::string mLastValue; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 578 | int actualLineHeight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 579 | int mStart; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 580 | int mLineSpacing; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 581 | int mSeparatorH; |
| 582 | int mHeaderSeparatorH; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 583 | int mShowFolders, mShowFiles, mShowNavFolders; |
| 584 | int mUpdate; |
| 585 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 586 | int mHeaderH; |
Vojtech Bocek | 7cc278b | 2013-02-24 01:40:19 +0100 | [diff] [blame] | 587 | int mFastScrollW; |
| 588 | int mFastScrollLineW; |
| 589 | int mFastScrollRectW; |
| 590 | int mFastScrollRectH; |
| 591 | int mFastScrollRectX; |
| 592 | int mFastScrollRectY; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 593 | static int mSortOrder; |
| 594 | int startY; |
| 595 | int scrollingSpeed; |
| 596 | int scrollingY; |
| 597 | int mHeaderIsStatic; |
| 598 | int touchDebounce; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 599 | unsigned mFontHeight; |
| 600 | unsigned mLineHeight; |
| 601 | int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth; |
| 602 | Resource* mHeaderIcon; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 603 | Resource* mFolderIcon; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 604 | Resource* mFileIcon; |
| 605 | Resource* mBackground; |
| 606 | Resource* mFont; |
| 607 | COLOR mBackgroundColor; |
| 608 | COLOR mFontColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 609 | COLOR mHeaderBackgroundColor; |
| 610 | COLOR mHeaderFontColor; |
| 611 | COLOR mSeparatorColor; |
| 612 | COLOR mHeaderSeparatorColor; |
Vojtech Bocek | 7cc278b | 2013-02-24 01:40:19 +0100 | [diff] [blame] | 613 | COLOR mFastScrollLineColor; |
| 614 | COLOR mFastScrollRectColor; |
Dees_Troy | e7585ca | 2013-02-15 11:42:29 -0600 | [diff] [blame] | 615 | bool hasHighlightColor; |
| 616 | bool hasFontHighlightColor; |
| 617 | bool isHighlighted; |
| 618 | COLOR mHighlightColor; |
| 619 | COLOR mFontHighlightColor; |
| 620 | int startSelection; |
Dees_Troy | c0583f5 | 2013-02-28 11:19:57 -0600 | [diff] [blame] | 621 | bool updateFileList; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 622 | }; |
| 623 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 624 | class GUIListBox : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 625 | { |
| 626 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 627 | GUIListBox(xml_node<>* node); |
| 628 | virtual ~GUIListBox(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 629 | |
| 630 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 631 | // Render - Render the full object to the GL surface |
| 632 | // Return 0 on success, <0 on error |
| 633 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 634 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 635 | // Update - Update any UI component animations (called <= 30 FPS) |
| 636 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 637 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 638 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 639 | // NotifyTouch - Notify of a touch event |
| 640 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 641 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 642 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 643 | // NotifyVarChange - Notify of a variable change |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 644 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 645 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 646 | // SetPos - Update the position of the render object |
| 647 | // Return 0 on success, <0 on error |
| 648 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 649 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 650 | // SetPageFocus - Notify when a page gains or loses focus |
| 651 | virtual void SetPageFocus(int inFocus); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 652 | |
| 653 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 654 | struct ListData { |
| 655 | std::string displayName; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 656 | std::string variableValue; |
| 657 | unsigned int selected; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 658 | }; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 659 | |
| 660 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 661 | virtual int GetSelection(int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 662 | |
| 663 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 664 | std::vector<ListData> mList; |
| 665 | std::string mVariable; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 666 | std::string mSelection; |
| 667 | std::string currentValue; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 668 | std::string mHeaderText; |
| 669 | std::string mLastValue; |
| 670 | int actualLineHeight; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 671 | int mStart; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 672 | int startY; |
| 673 | int mSeparatorH, mHeaderSeparatorH; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 674 | int mLineSpacing; |
| 675 | int mUpdate; |
| 676 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH; |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 677 | int mFastScrollW; |
| 678 | int mFastScrollLineW; |
| 679 | int mFastScrollRectW; |
| 680 | int mFastScrollRectH; |
| 681 | int mFastScrollRectX; |
| 682 | int mFastScrollRectY; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 683 | int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth; |
| 684 | int scrollingSpeed; |
| 685 | int scrollingY; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 686 | static int mSortOrder; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 687 | unsigned mFontHeight; |
| 688 | unsigned mLineHeight; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 689 | Resource* mHeaderIcon; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 690 | Resource* mIconSelected; |
| 691 | Resource* mIconUnselected; |
| 692 | Resource* mBackground; |
| 693 | Resource* mFont; |
| 694 | COLOR mBackgroundColor; |
| 695 | COLOR mFontColor; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 696 | COLOR mHeaderBackgroundColor; |
| 697 | COLOR mHeaderFontColor; |
| 698 | COLOR mSeparatorColor; |
| 699 | COLOR mHeaderSeparatorColor; |
Dees_Troy | 58f5cf0 | 2013-02-27 22:21:41 +0000 | [diff] [blame] | 700 | COLOR mFastScrollLineColor; |
| 701 | COLOR mFastScrollRectColor; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 702 | bool hasHighlightColor; |
| 703 | bool hasFontHighlightColor; |
| 704 | bool isHighlighted; |
| 705 | COLOR mHighlightColor; |
| 706 | COLOR mFontHighlightColor; |
| 707 | int mHeaderIsStatic; |
| 708 | int startSelection; |
| 709 | int touchDebounce; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 710 | }; |
| 711 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 712 | class GUIPartitionList : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 713 | { |
| 714 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 715 | GUIPartitionList(xml_node<>* node); |
| 716 | virtual ~GUIPartitionList(); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 717 | |
| 718 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 719 | // Render - Render the full object to the GL surface |
| 720 | // Return 0 on success, <0 on error |
| 721 | virtual int Render(void); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 722 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 723 | // Update - Update any UI component animations (called <= 30 FPS) |
| 724 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 725 | virtual int Update(void); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 726 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 727 | // NotifyTouch - Notify of a touch event |
| 728 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 729 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 730 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 731 | // NotifyVarChange - Notify of a variable change |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 732 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 733 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 734 | // SetPos - Update the position of the render object |
| 735 | // Return 0 on success, <0 on error |
| 736 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 737 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 738 | // SetPageFocus - Notify when a page gains or loses focus |
| 739 | virtual void SetPageFocus(int inFocus); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 740 | |
| 741 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 742 | virtual int GetSelection(int x, int y); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 743 | virtual void MatchList(void); |
| 744 | |
| 745 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 746 | std::vector<PartitionList> mList; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 747 | std::string ListType; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 748 | std::string mVariable; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 749 | std::string selectedList; |
| 750 | std::string currentValue; |
| 751 | std::string mHeaderText; |
| 752 | std::string mLastValue; |
| 753 | int actualLineHeight; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 754 | int mStart; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 755 | int startY; |
| 756 | int mSeparatorH, mHeaderSeparatorH; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 757 | int mLineSpacing; |
| 758 | int mUpdate; |
| 759 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 760 | int mFastScrollW; |
| 761 | int mFastScrollLineW; |
| 762 | int mFastScrollRectW; |
| 763 | int mFastScrollRectH; |
| 764 | int mFastScrollRectX; |
| 765 | int mFastScrollRectY; |
| 766 | int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth; |
| 767 | int scrollingSpeed; |
| 768 | int scrollingY; |
| 769 | static int mSortOrder; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 770 | unsigned mFontHeight; |
| 771 | unsigned mLineHeight; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 772 | Resource* mHeaderIcon; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 773 | Resource* mIconSelected; |
| 774 | Resource* mIconUnselected; |
| 775 | Resource* mBackground; |
| 776 | Resource* mFont; |
| 777 | COLOR mBackgroundColor; |
| 778 | COLOR mFontColor; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 779 | COLOR mHeaderBackgroundColor; |
| 780 | COLOR mHeaderFontColor; |
| 781 | COLOR mSeparatorColor; |
| 782 | COLOR mHeaderSeparatorColor; |
| 783 | COLOR mFastScrollLineColor; |
| 784 | COLOR mFastScrollRectColor; |
| 785 | bool hasHighlightColor; |
| 786 | bool hasFontHighlightColor; |
| 787 | bool isHighlighted; |
| 788 | COLOR mHighlightColor; |
| 789 | COLOR mFontHighlightColor; |
| 790 | int mHeaderIsStatic; |
| 791 | int startSelection; |
| 792 | int touchDebounce; |
| 793 | bool updateList; |
| 794 | }; |
| 795 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 796 | // GUIAnimation - Used for animations |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 797 | class GUIAnimation : public GUIObject, public RenderObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 798 | { |
| 799 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 800 | GUIAnimation(xml_node<>* node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 801 | |
| 802 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 803 | // Render - Render the full object to the GL surface |
| 804 | // Return 0 on success, <0 on error |
| 805 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 806 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 807 | // Update - Update any UI component animations (called <= 30 FPS) |
| 808 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 809 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 810 | |
| 811 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 812 | AnimationResource* mAnimation; |
| 813 | int mFrame; |
| 814 | int mFPS; |
| 815 | int mLoop; |
| 816 | int mRender; |
| 817 | int mUpdateCount; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 818 | }; |
| 819 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 820 | class GUIProgressBar : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 821 | { |
| 822 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 823 | GUIProgressBar(xml_node<>* node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 824 | |
| 825 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 826 | // Render - Render the full object to the GL surface |
| 827 | // Return 0 on success, <0 on error |
| 828 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 829 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 830 | // Update - Update any UI component animations (called <= 30 FPS) |
| 831 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 832 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 833 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 834 | // NotifyVarChange - Notify of a variable change |
| 835 | // Returns 0 on success, <0 on error |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 836 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 837 | |
| 838 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 839 | Resource* mEmptyBar; |
| 840 | Resource* mFullBar; |
| 841 | std::string mMinValVar; |
| 842 | std::string mMaxValVar; |
| 843 | std::string mCurValVar; |
| 844 | float mSlide; |
| 845 | float mSlideInc; |
| 846 | int mSlideFrames; |
| 847 | int mLastPos; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 848 | |
| 849 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 850 | virtual int RenderInternal(void); // Does the actual render |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 851 | }; |
| 852 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 853 | class GUISlider : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 854 | { |
| 855 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 856 | GUISlider(xml_node<>* node); |
| 857 | virtual ~GUISlider(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 858 | |
| 859 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 860 | // Render - Render the full object to the GL surface |
| 861 | // Return 0 on success, <0 on error |
| 862 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 863 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 864 | // Update - Update any UI component animations (called <= 30 FPS) |
| 865 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 866 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 867 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 868 | // NotifyTouch - Notify of a touch event |
| 869 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 870 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 871 | |
| 872 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 873 | GUIAction* sAction; |
| 874 | Resource* sSlider; |
| 875 | Resource* sSliderUsed; |
| 876 | Resource* sTouch; |
| 877 | int sTouchW, sTouchH; |
| 878 | int sCurTouchX; |
| 879 | int sUpdate; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 880 | }; |
| 881 | |
| 882 | #define MAX_KEYBOARD_LAYOUTS 5 |
| 883 | #define MAX_KEYBOARD_ROWS 9 |
| 884 | #define MAX_KEYBOARD_KEYS 20 |
| 885 | #define KEYBOARD_ACTION 253 |
| 886 | #define KEYBOARD_LAYOUT 254 |
| 887 | #define KEYBOARD_SWIPE_LEFT 252 |
| 888 | #define KEYBOARD_SWIPE_RIGHT 251 |
| 889 | #define KEYBOARD_ARROW_LEFT 250 |
| 890 | #define KEYBOARD_ARROW_RIGHT 249 |
| 891 | #define KEYBOARD_HOME 248 |
| 892 | #define KEYBOARD_END 247 |
| 893 | #define KEYBOARD_ARROW_UP 246 |
| 894 | #define KEYBOARD_ARROW_DOWN 245 |
| 895 | #define KEYBOARD_SPECIAL_KEYS 245 |
| 896 | #define KEYBOARD_BACKSPACE 8 |
| 897 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 898 | class GUIKeyboard : public GUIObject, public RenderObject, public ActionObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 899 | { |
| 900 | public: |
| 901 | GUIKeyboard(xml_node<>* node); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 902 | virtual ~GUIKeyboard(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 903 | |
| 904 | public: |
| 905 | virtual int Render(void); |
| 906 | virtual int Update(void); |
| 907 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 908 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 909 | |
| 910 | protected: |
| 911 | virtual int GetSelection(int x, int y); |
| 912 | |
| 913 | protected: |
| 914 | struct keyboard_key_class |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 915 | { |
| 916 | unsigned char key; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 917 | unsigned char longpresskey; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 918 | unsigned int end_x; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 919 | unsigned int layout; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 920 | }; |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 921 | struct capslock_tracking_struct |
| 922 | { |
| 923 | int capslock; |
| 924 | int set_capslock; |
| 925 | int revert_layout; |
| 926 | }; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 927 | |
| 928 | Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS]; |
| 929 | struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS]; |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 930 | struct capslock_tracking_struct caps_tracking[MAX_KEYBOARD_LAYOUTS]; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 931 | bool mRendered; |
| 932 | std::string mVariable; |
| 933 | unsigned int cursorLocation; |
| 934 | unsigned int currentLayout; |
| 935 | unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS]; |
| 936 | unsigned int KeyboardWidth, KeyboardHeight; |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 937 | int rowY, colX, highlightRenderCount, hasHighlight, hasCapsHighlight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 938 | GUIAction* mAction; |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 939 | COLOR mHighlightColor; |
Ethan Yonker | c3120d4 | 2014-02-17 07:55:00 -0600 | [diff] [blame] | 940 | COLOR mCapsHighlightColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 941 | }; |
| 942 | |
| 943 | // GUIInput - Used for keyboard input |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 944 | class GUIInput : public GUIObject, public RenderObject, public ActionObject, public InputObject |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 945 | { |
| 946 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 947 | // w and h may be ignored, in which case, no bounding box is applied |
| 948 | GUIInput(xml_node<>* node); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 949 | virtual ~GUIInput(); |
| 950 | |
| 951 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 952 | // Render - Render the full object to the GL surface |
| 953 | // Return 0 on success, <0 on error |
| 954 | virtual int Render(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 955 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 956 | // Update - Update any UI component animations (called <= 30 FPS) |
| 957 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 958 | virtual int Update(void); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 959 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 960 | // Notify of a variable change |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 961 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 962 | |
| 963 | // NotifyTouch - Notify of a touch event |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 964 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 965 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 966 | |
| 967 | virtual int NotifyKeyboard(int key); |
| 968 | |
| 969 | protected: |
| 970 | virtual int GetSelection(int x, int y); |
| 971 | |
| 972 | // Handles displaying the text properly when chars are added, deleted, or for scrolling |
| 973 | virtual int HandleTextLocation(int x); |
| 974 | |
| 975 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 976 | GUIText* mInputText; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 977 | GUIAction* mAction; |
| 978 | Resource* mBackground; |
| 979 | Resource* mCursor; |
| 980 | Resource* mFont; |
| 981 | std::string mText; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 982 | std::string mLastValue; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 983 | std::string mVariable; |
| 984 | std::string mMask; |
| 985 | std::string mMaskVariable; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 986 | COLOR mBackgroundColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 987 | COLOR mCursorColor; |
| 988 | int scrollingX; |
| 989 | int lastX; |
| 990 | int mCursorLocation; |
| 991 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; |
| 992 | int mFontY; |
| 993 | unsigned skipChars; |
| 994 | unsigned mFontHeight; |
| 995 | unsigned CursorWidth; |
| 996 | bool mRendered; |
| 997 | bool HasMask; |
| 998 | bool DrawCursor; |
| 999 | bool isLocalChange; |
| 1000 | bool HasAllowed; |
| 1001 | bool HasDisabled; |
| 1002 | std::string AllowedList; |
| 1003 | std::string DisabledList; |
| 1004 | unsigned MinLen; |
| 1005 | unsigned MaxLen; |
| 1006 | }; |
| 1007 | |
| 1008 | class HardwareKeyboard |
| 1009 | { |
| 1010 | public: |
| 1011 | HardwareKeyboard(void); |
| 1012 | virtual ~HardwareKeyboard(); |
| 1013 | |
| 1014 | public: |
| 1015 | virtual int KeyDown(int key_code); |
| 1016 | virtual int KeyUp(int key_code); |
| 1017 | virtual int KeyRepeat(void); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 1018 | |
| 1019 | void ConsumeKeyRelease(int key); |
| 1020 | |
| 1021 | private: |
| 1022 | std::set<int> mPressedKeys; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1023 | }; |
| 1024 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 1025 | class GUISliderValue: public GUIObject, public RenderObject, public ActionObject |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 1026 | { |
| 1027 | public: |
| 1028 | GUISliderValue(xml_node<>* node); |
| 1029 | virtual ~GUISliderValue(); |
| 1030 | |
| 1031 | public: |
| 1032 | // Render - Render the full object to the GL surface |
| 1033 | // Return 0 on success, <0 on error |
| 1034 | virtual int Render(void); |
| 1035 | |
| 1036 | // Update - Update any UI component animations (called <= 30 FPS) |
| 1037 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 1038 | virtual int Update(void); |
| 1039 | |
| 1040 | // SetPos - Update the position of the render object |
| 1041 | // Return 0 on success, <0 on error |
| 1042 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 1043 | |
| 1044 | // NotifyTouch - Notify of a touch event |
| 1045 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 1046 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 1047 | |
| 1048 | // Notify of a variable change |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 1049 | virtual int NotifyVarChange(const std::string& varName, const std::string& value); |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 1050 | |
| 1051 | // SetPageFocus - Notify when a page gains or loses focus |
| 1052 | virtual void SetPageFocus(int inFocus); |
| 1053 | |
| 1054 | protected: |
| 1055 | int measureText(const std::string& str); |
| 1056 | int valueFromPct(float pct); |
| 1057 | float pctFromValue(int value); |
| 1058 | void loadValue(bool force = false); |
| 1059 | |
| 1060 | std::string mVariable; |
| 1061 | int mMax; |
| 1062 | int mMin; |
| 1063 | int mValue; |
| 1064 | char *mValueStr; |
| 1065 | float mValuePct; |
| 1066 | std::string mMaxStr; |
| 1067 | std::string mMinStr; |
| 1068 | Resource *mFont; |
| 1069 | GUIText* mLabel; |
| 1070 | int mLabelW; |
| 1071 | COLOR mTextColor; |
| 1072 | COLOR mLineColor; |
| 1073 | COLOR mSliderColor; |
| 1074 | bool mShowRange; |
| 1075 | bool mShowCurr; |
| 1076 | int mLineX; |
| 1077 | int mLineY; |
| 1078 | int mLineH; |
| 1079 | int mLinePadding; |
| 1080 | int mPadding; |
| 1081 | int mSliderY; |
| 1082 | int mSliderW; |
| 1083 | int mSliderH; |
| 1084 | bool mRendered; |
| 1085 | int mFontHeight; |
| 1086 | GUIAction *mAction; |
| 1087 | bool mChangeOnDrag; |
Vojtech Bocek | 18d7c98 | 2014-08-04 17:19:28 +0200 | [diff] [blame] | 1088 | int mLineW; |
| 1089 | bool mDragging; |
| 1090 | Resource *mBackgroundImage; |
| 1091 | Resource *mHandleImage; |
| 1092 | Resource *mHandleHoverImage; |
Vojtech Bocek | 8593234 | 2013-04-01 22:11:33 +0200 | [diff] [blame] | 1093 | }; |
| 1094 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 1095 | class MouseCursor : public RenderObject |
| 1096 | { |
| 1097 | public: |
| 1098 | MouseCursor(int posX, int posY); |
| 1099 | virtual ~MouseCursor(); |
| 1100 | |
| 1101 | virtual int Render(void); |
| 1102 | virtual int Update(void); |
| 1103 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 1104 | |
| 1105 | void Move(int deltaX, int deltaY); |
| 1106 | void GetPos(int& x, int& y); |
| 1107 | void LoadData(xml_node<>* node); |
| 1108 | void ResetData(int resX, int resY); |
| 1109 | |
| 1110 | private: |
| 1111 | int m_resX; |
| 1112 | int m_resY; |
| 1113 | bool m_moved; |
| 1114 | float m_speedMultiplier; |
| 1115 | COLOR m_color; |
| 1116 | Resource *m_image; |
| 1117 | bool m_present; |
| 1118 | }; |
| 1119 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1120 | // Helper APIs |
| 1121 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL); |
| 1122 | |
| 1123 | #endif // _OBJECTS_HEADER |
| 1124 | |