Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | // objects.h - Base classes for object manager of GUI |
| 2 | |
| 3 | #ifndef _OBJECTS_HEADER |
| 4 | #define _OBJECTS_HEADER |
| 5 | |
| 6 | #include "rapidxml.hpp" |
| 7 | #include <vector> |
| 8 | #include <string> |
| 9 | #include <map> |
| 10 | |
| 11 | extern "C" { |
| 12 | #include "../minzip/Zip.h" |
| 13 | } |
| 14 | |
| 15 | using namespace rapidxml; |
| 16 | |
| 17 | #include "../data.hpp" |
| 18 | #include "resources.hpp" |
| 19 | #include "pages.hpp" |
| 20 | |
| 21 | class RenderObject |
| 22 | { |
| 23 | public: |
| 24 | enum Placement { |
| 25 | TOP_LEFT = 0, |
| 26 | TOP_RIGHT = 1, |
| 27 | BOTTOM_LEFT = 2, |
| 28 | BOTTOM_RIGHT = 3, |
| 29 | CENTER = 4, |
| 30 | CENTER_X_ONLY = 5, |
| 31 | }; |
| 32 | |
| 33 | public: |
| 34 | RenderObject() { mRenderX = 0; mRenderY = 0; mRenderW = 0; mRenderH = 0; mPlacement = TOP_LEFT; } |
| 35 | virtual ~RenderObject() {} |
| 36 | |
| 37 | public: |
| 38 | // Render - Render the full object to the GL surface |
| 39 | // Return 0 on success, <0 on error |
| 40 | virtual int Render(void) = 0; |
| 41 | |
| 42 | // Update - Update any UI component animations (called <= 30 FPS) |
| 43 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 44 | virtual int Update(void) { return 0; } |
| 45 | |
| 46 | // GetRenderPos - Returns the current position of the object |
| 47 | virtual int GetRenderPos(int& x, int& y, int& w, int& h) { x = mRenderX; y = mRenderY; w = mRenderW; h = mRenderH; return 0; } |
| 48 | |
| 49 | // SetRenderPos - Update the position of the object |
| 50 | // Return 0 on success, <0 on error |
| 51 | 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; } |
| 52 | |
| 53 | // GetPlacement - Returns the current placement |
| 54 | virtual int GetPlacement(Placement& placement) { placement = mPlacement; return 0; } |
| 55 | |
| 56 | // SetPlacement - Update the current placement |
| 57 | virtual int SetPlacement(Placement placement) { mPlacement = placement; return 0; } |
| 58 | |
| 59 | // SetPageFocus - Notify when a page gains or loses focus |
| 60 | virtual void SetPageFocus(int inFocus) { return; } |
| 61 | |
| 62 | protected: |
| 63 | int mRenderX, mRenderY, mRenderW, mRenderH; |
| 64 | Placement mPlacement; |
| 65 | }; |
| 66 | |
| 67 | class ActionObject |
| 68 | { |
| 69 | public: |
| 70 | ActionObject() { mActionX = 0; mActionY = 0; mActionW = 0; mActionH = 0; } |
| 71 | virtual ~ActionObject() {} |
| 72 | |
| 73 | public: |
| 74 | // NotifyTouch - Notify of a touch event |
| 75 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 76 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y) { return 0; } |
| 77 | |
| 78 | // NotifyKey - Notify of a key press |
| 79 | // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error |
| 80 | virtual int NotifyKey(int key) { return 1; } |
| 81 | |
| 82 | // GetRenderPos - Returns the current position of the object |
| 83 | virtual int GetActionPos(int& x, int& y, int& w, int& h) { x = mActionX; y = mActionY; w = mActionW; h = mActionH; return 0; } |
| 84 | |
| 85 | // SetRenderPos - Update the position of the object |
| 86 | // Return 0 on success, <0 on error |
| 87 | virtual int SetActionPos(int x, int y, int w = 0, int h = 0); |
| 88 | |
| 89 | // IsInRegion - Checks if the request is handled by this object |
| 90 | // Return 0 if this object handles the request, 1 if not |
| 91 | virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); } |
| 92 | |
| 93 | // NotifyVarChange - Notify of a variable change |
| 94 | // Returns 0 on success, <0 on error |
| 95 | virtual int NotifyVarChange(std::string varName, std::string value) { return 0; } |
| 96 | |
| 97 | protected: |
| 98 | int mActionX, mActionY, mActionW, mActionH; |
| 99 | }; |
| 100 | |
| 101 | class Conditional |
| 102 | { |
| 103 | public: |
| 104 | Conditional(xml_node<>* node); |
| 105 | |
| 106 | public: |
| 107 | bool IsConditionVariable(std::string var); |
| 108 | bool isConditionTrue(); |
| 109 | bool isConditionValid(); |
| 110 | void NotifyPageSet(); |
| 111 | |
| 112 | protected: |
| 113 | class Condition |
| 114 | { |
| 115 | public: |
| 116 | std::string mVar1; |
| 117 | std::string mVar2; |
| 118 | std::string mCompareOp; |
| 119 | std::string mLastVal; |
| 120 | }; |
| 121 | |
| 122 | std::vector<Condition> mConditions; |
| 123 | |
| 124 | protected: |
| 125 | bool isMounted(std::string vol); |
| 126 | bool isConditionTrue(Condition* condition); |
| 127 | |
| 128 | }; |
| 129 | |
| 130 | class InputObject |
| 131 | { |
| 132 | public: |
| 133 | InputObject() { HasInputFocus = 0; } |
| 134 | virtual ~InputObject() {} |
| 135 | |
| 136 | public: |
| 137 | // NotifyKeyboard - Notify of keyboard input |
| 138 | // Return 0 on success (and consume key), >0 to pass key to next handler, and <0 on error |
| 139 | virtual int NotifyKeyboard(int key) { return 1; } |
| 140 | |
| 141 | virtual int SetInputFocus(int focus) { HasInputFocus = focus; return 1; } |
| 142 | |
| 143 | protected: |
| 144 | int HasInputFocus; |
| 145 | }; |
| 146 | |
| 147 | // Derived Objects |
| 148 | // GUIText - Used for static text |
| 149 | class GUIText : public RenderObject, public ActionObject, public Conditional |
| 150 | |
| 151 | { |
| 152 | public: |
| 153 | // w and h may be ignored, in which case, no bounding box is applied |
| 154 | GUIText(xml_node<>* node); |
| 155 | |
| 156 | public: |
| 157 | // Render - Render the full object to the GL surface |
| 158 | // Return 0 on success, <0 on error |
| 159 | virtual int Render(void); |
| 160 | |
| 161 | // Update - Update any UI component animations (called <= 30 FPS) |
| 162 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 163 | virtual int Update(void); |
| 164 | |
| 165 | // Retrieve the size of the current string (dynamic strings may change per call) |
| 166 | virtual int GetCurrentBounds(int& w, int& h); |
| 167 | |
| 168 | // Notify of a variable change |
| 169 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 170 | |
| 171 | // Set maximum width in pixels |
| 172 | virtual int SetMaxWidth(unsigned width); |
| 173 | |
| 174 | // Set number of characters to skip (for scrolling) |
| 175 | virtual int SkipCharCount(unsigned skip); |
| 176 | |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 177 | public: |
| 178 | bool isHighlighted; |
| 179 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 180 | protected: |
| 181 | std::string mText; |
| 182 | std::string mLastValue; |
| 183 | COLOR mColor; |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 184 | COLOR mHighlightColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 185 | Resource* mFont; |
| 186 | int mIsStatic; |
| 187 | int mVarChanged; |
| 188 | int mFontHeight; |
| 189 | unsigned maxWidth; |
| 190 | unsigned charSkip; |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 191 | bool hasHighlightColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 192 | |
| 193 | protected: |
| 194 | std::string parseText(void); |
| 195 | }; |
| 196 | |
| 197 | // GUIImage - Used for static image |
| 198 | class GUIImage : public RenderObject |
| 199 | { |
| 200 | public: |
| 201 | GUIImage(xml_node<>* node); |
| 202 | |
| 203 | public: |
| 204 | // Render - Render the full object to the GL surface |
| 205 | // Return 0 on success, <0 on error |
| 206 | virtual int Render(void); |
| 207 | |
| 208 | // SetRenderPos - Update the position of the object |
| 209 | // Return 0 on success, <0 on error |
| 210 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 211 | |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 212 | public: |
| 213 | bool isHighlighted; |
| 214 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 215 | protected: |
| 216 | Resource* mImage; |
Dees_Troy | 4d12f96 | 2012-10-19 13:13:15 -0400 | [diff] [blame] | 217 | Resource* mHighlightImage; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | // GUIFill - Used for fill colors |
| 221 | class GUIFill : public RenderObject |
| 222 | { |
| 223 | public: |
| 224 | GUIFill(xml_node<>* node); |
| 225 | |
| 226 | public: |
| 227 | // Render - Render the full object to the GL surface |
| 228 | // Return 0 on success, <0 on error |
| 229 | virtual int Render(void); |
| 230 | |
| 231 | protected: |
| 232 | COLOR mColor; |
| 233 | }; |
| 234 | |
| 235 | // GUIAction - Used for standard actions |
| 236 | class GUIAction : public ActionObject, public Conditional |
| 237 | { |
| 238 | public: |
| 239 | GUIAction(xml_node<>* node); |
| 240 | |
| 241 | public: |
| 242 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 243 | virtual int NotifyKey(int key); |
| 244 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 245 | virtual int doActions(); |
| 246 | |
| 247 | protected: |
| 248 | class Action |
| 249 | { |
| 250 | public: |
| 251 | std::string mFunction; |
| 252 | std::string mArg; |
| 253 | }; |
| 254 | |
| 255 | std::vector<Action> mActions; |
| 256 | int mKey; |
| 257 | |
| 258 | protected: |
| 259 | int getKeyByName(std::string key); |
| 260 | virtual int doAction(Action action, int isThreaded = 0); |
| 261 | static void* thread_start(void *cookie); |
| 262 | void simulate_progress_bar(void); |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 263 | int flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 264 | void operation_start(const string operation_name); |
| 265 | void operation_end(const int operation_status, const int simulate); |
| 266 | static void* command_thread(void *cookie); |
| 267 | }; |
| 268 | |
| 269 | class GUIConsole : public RenderObject, public ActionObject |
| 270 | { |
| 271 | public: |
| 272 | GUIConsole(xml_node<>* node); |
| 273 | |
| 274 | public: |
| 275 | // Render - Render the full object to the GL surface |
| 276 | // Return 0 on success, <0 on error |
| 277 | virtual int Render(void); |
| 278 | |
| 279 | // Update - Update any UI component animations (called <= 30 FPS) |
| 280 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 281 | virtual int Update(void); |
| 282 | |
| 283 | // SetRenderPos - Update the position of the object |
| 284 | // Return 0 on success, <0 on error |
| 285 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 286 | |
| 287 | // IsInRegion - Checks if the request is handled by this object |
| 288 | // Return 0 if this object handles the request, 1 if not |
| 289 | virtual int IsInRegion(int x, int y); |
| 290 | |
| 291 | // NotifyTouch - Notify of a touch event |
| 292 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers) |
| 293 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 294 | |
| 295 | protected: |
| 296 | enum SlideoutState |
| 297 | { |
| 298 | hidden = 0, |
| 299 | visible, |
| 300 | request_hide, |
| 301 | request_show |
| 302 | }; |
| 303 | Resource* mFont; |
| 304 | Resource* mSlideoutImage; |
| 305 | COLOR mForegroundColor; |
| 306 | COLOR mBackgroundColor; |
| 307 | COLOR mScrollColor; |
| 308 | unsigned int mFontHeight; |
| 309 | int mCurrentLine; |
| 310 | unsigned int mLastCount; |
| 311 | unsigned int mMaxRows; |
| 312 | int mStartY; |
| 313 | int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH; |
| 314 | int mSlideinX, mSlideinY, mSlideinW, mSlideinH; |
| 315 | int mConsoleX, mConsoleY, mConsoleW, mConsoleH; |
| 316 | int mLastTouchX, mLastTouchY; |
| 317 | int mSlideMultiplier; |
| 318 | int mSlideout; |
| 319 | SlideoutState mSlideoutState; |
| 320 | |
| 321 | protected: |
| 322 | virtual int RenderSlideout(void); |
| 323 | virtual int RenderConsole(void); |
| 324 | |
| 325 | }; |
| 326 | |
| 327 | class GUIButton : public RenderObject, public ActionObject, public Conditional |
| 328 | { |
| 329 | public: |
| 330 | GUIButton(xml_node<>* node); |
| 331 | virtual ~GUIButton(); |
| 332 | |
| 333 | public: |
| 334 | // Render - Render the full object to the GL surface |
| 335 | // Return 0 on success, <0 on error |
| 336 | virtual int Render(void); |
| 337 | |
| 338 | // Update - Update any UI component animations (called <= 30 FPS) |
| 339 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 340 | virtual int Update(void); |
| 341 | |
| 342 | // SetPos - Update the position of the render object |
| 343 | // Return 0 on success, <0 on error |
| 344 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 345 | |
| 346 | // NotifyTouch - Notify of a touch event |
| 347 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 348 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 349 | |
| 350 | protected: |
| 351 | GUIImage* mButtonImg; |
| 352 | Resource* mButtonIcon; |
| 353 | GUIText* mButtonLabel; |
| 354 | GUIAction* mAction; |
| 355 | int mTextX, mTextY, mTextW, mTextH; |
| 356 | int mIconX, mIconY, mIconW, mIconH; |
| 357 | bool mRendered; |
Dees_Troy | 1a7a667 | 2013-02-15 09:39:07 -0600 | [diff] [blame] | 358 | bool hasHighlightColor; |
| 359 | bool renderHighlight; |
| 360 | COLOR mHighlightColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | class GUICheckbox: public RenderObject, public ActionObject, public Conditional |
| 364 | { |
| 365 | public: |
| 366 | GUICheckbox(xml_node<>* node); |
| 367 | virtual ~GUICheckbox(); |
| 368 | |
| 369 | public: |
| 370 | // Render - Render the full object to the GL surface |
| 371 | // Return 0 on success, <0 on error |
| 372 | virtual int Render(void); |
| 373 | |
| 374 | // Update - Update any UI component animations (called <= 30 FPS) |
| 375 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 376 | virtual int Update(void); |
| 377 | |
| 378 | // SetPos - Update the position of the render object |
| 379 | // Return 0 on success, <0 on error |
| 380 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 381 | |
| 382 | // NotifyTouch - Notify of a touch event |
| 383 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 384 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 385 | |
| 386 | protected: |
| 387 | Resource* mChecked; |
| 388 | Resource* mUnchecked; |
| 389 | GUIText* mLabel; |
| 390 | int mTextX, mTextY; |
| 391 | int mCheckX, mCheckY, mCheckW, mCheckH; |
| 392 | int mLastState; |
| 393 | bool mRendered; |
| 394 | std::string mVarName; |
| 395 | }; |
| 396 | |
| 397 | class GUIFileSelector : public RenderObject, public ActionObject |
| 398 | { |
| 399 | public: |
| 400 | GUIFileSelector(xml_node<>* node); |
| 401 | virtual ~GUIFileSelector(); |
| 402 | |
| 403 | public: |
| 404 | // Render - Render the full object to the GL surface |
| 405 | // Return 0 on success, <0 on error |
| 406 | virtual int Render(void); |
| 407 | |
| 408 | // Update - Update any UI component animations (called <= 30 FPS) |
| 409 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 410 | virtual int Update(void); |
| 411 | |
| 412 | // NotifyTouch - Notify of a touch event |
| 413 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 414 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 415 | |
| 416 | // NotifyVarChange - Notify of a variable change |
| 417 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 418 | |
| 419 | // SetPos - Update the position of the render object |
| 420 | // Return 0 on success, <0 on error |
| 421 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 422 | |
| 423 | // SetPageFocus - Notify when a page gains or loses focus |
| 424 | virtual void SetPageFocus(int inFocus); |
| 425 | |
| 426 | protected: |
| 427 | struct FileData { |
| 428 | std::string fileName; |
| 429 | unsigned char fileType; // Uses d_type format from struct dirent |
| 430 | mode_t protection; // Uses mode_t format from stat |
| 431 | uid_t userId; |
| 432 | gid_t groupId; |
| 433 | off_t fileSize; |
| 434 | time_t lastAccess; // Uses time_t format from stat |
| 435 | time_t lastModified; // Uses time_t format from stat |
| 436 | time_t lastStatChange; // Uses time_t format from stat |
| 437 | }; |
| 438 | |
| 439 | protected: |
| 440 | virtual int GetSelection(int x, int y); |
| 441 | |
| 442 | virtual int GetFileList(const std::string folder); |
| 443 | static bool fileSort(FileData d1, FileData d2); |
| 444 | |
| 445 | protected: |
| 446 | std::vector<FileData> mFolderList; |
| 447 | std::vector<FileData> mFileList; |
| 448 | std::string mPathVar; |
| 449 | std::string mExtn; |
| 450 | std::string mVariable; |
| 451 | std::string mSortVariable; |
| 452 | std::string mSelection; |
| 453 | std::string mHeaderText; |
| 454 | std::string mLastValue; |
| 455 | int actualLineHeight; |
| 456 | int mStart; |
| 457 | int mLineSpacing; |
| 458 | int mSeparatorH; |
| 459 | int mHeaderSeparatorH; |
| 460 | int mShowFolders, mShowFiles, mShowNavFolders; |
| 461 | int mUpdate; |
| 462 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; |
| 463 | int mHeaderH; |
| 464 | static int mSortOrder; |
| 465 | int startY; |
| 466 | int scrollingSpeed; |
| 467 | int scrollingY; |
| 468 | int mHeaderIsStatic; |
| 469 | int touchDebounce; |
| 470 | unsigned mFontHeight; |
| 471 | unsigned mLineHeight; |
| 472 | int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth; |
| 473 | Resource* mHeaderIcon; |
| 474 | Resource* mFolderIcon; |
| 475 | Resource* mFileIcon; |
| 476 | Resource* mBackground; |
| 477 | Resource* mFont; |
| 478 | COLOR mBackgroundColor; |
| 479 | COLOR mFontColor; |
| 480 | COLOR mHeaderBackgroundColor; |
| 481 | COLOR mHeaderFontColor; |
| 482 | COLOR mSeparatorColor; |
| 483 | COLOR mHeaderSeparatorColor; |
Dees_Troy | e7585ca | 2013-02-15 11:42:29 -0600 | [diff] [blame] | 484 | bool hasHighlightColor; |
| 485 | bool hasFontHighlightColor; |
| 486 | bool isHighlighted; |
| 487 | COLOR mHighlightColor; |
| 488 | COLOR mFontHighlightColor; |
| 489 | int startSelection; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 490 | }; |
| 491 | |
| 492 | class GUIListBox : public RenderObject, public ActionObject |
| 493 | { |
| 494 | public: |
| 495 | GUIListBox(xml_node<>* node); |
| 496 | virtual ~GUIListBox(); |
| 497 | |
| 498 | public: |
| 499 | // Render - Render the full object to the GL surface |
| 500 | // Return 0 on success, <0 on error |
| 501 | virtual int Render(void); |
| 502 | |
| 503 | // Update - Update any UI component animations (called <= 30 FPS) |
| 504 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 505 | virtual int Update(void); |
| 506 | |
| 507 | // NotifyTouch - Notify of a touch event |
| 508 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 509 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 510 | |
| 511 | // NotifyVarChange - Notify of a variable change |
| 512 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 513 | |
| 514 | // SetPos - Update the position of the render object |
| 515 | // Return 0 on success, <0 on error |
| 516 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 517 | |
| 518 | // SetPageFocus - Notify when a page gains or loses focus |
| 519 | virtual void SetPageFocus(int inFocus); |
| 520 | |
| 521 | protected: |
| 522 | struct ListData { |
| 523 | std::string displayName; |
| 524 | std::string variableValue; |
| 525 | unsigned int selected; |
| 526 | }; |
| 527 | |
| 528 | protected: |
| 529 | virtual int GetSelection(int x, int y); |
| 530 | |
| 531 | protected: |
| 532 | std::vector<ListData> mList; |
| 533 | std::string mVariable; |
| 534 | std::string mSelection; |
| 535 | std::string currentValue; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 536 | std::string mHeaderText; |
| 537 | std::string mLastValue; |
| 538 | int actualLineHeight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 539 | int mStart; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 540 | int startY; |
| 541 | int mSeparatorH, mHeaderSeparatorH; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 542 | int mLineSpacing; |
| 543 | int mUpdate; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 544 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH, mHeaderH; |
| 545 | int mIconWidth, mIconHeight, mSelectedIconWidth, mSelectedIconHeight, mUnselectedIconWidth, mUnselectedIconHeight, mHeaderIconHeight, mHeaderIconWidth; |
| 546 | int scrollingSpeed; |
| 547 | int scrollingY; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 548 | static int mSortOrder; |
| 549 | unsigned mFontHeight; |
| 550 | unsigned mLineHeight; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 551 | Resource* mHeaderIcon; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 552 | Resource* mIconSelected; |
| 553 | Resource* mIconUnselected; |
| 554 | Resource* mBackground; |
| 555 | Resource* mFont; |
| 556 | COLOR mBackgroundColor; |
| 557 | COLOR mFontColor; |
Dees_Troy | eead985 | 2013-02-15 14:31:06 -0600 | [diff] [blame] | 558 | COLOR mHeaderBackgroundColor; |
| 559 | COLOR mHeaderFontColor; |
| 560 | COLOR mSeparatorColor; |
| 561 | COLOR mHeaderSeparatorColor; |
| 562 | bool hasHighlightColor; |
| 563 | bool hasFontHighlightColor; |
| 564 | bool isHighlighted; |
| 565 | COLOR mHighlightColor; |
| 566 | COLOR mFontHighlightColor; |
| 567 | int mHeaderIsStatic; |
| 568 | int startSelection; |
| 569 | int touchDebounce; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | // GUIAnimation - Used for animations |
| 573 | class GUIAnimation : public RenderObject |
| 574 | { |
| 575 | public: |
| 576 | GUIAnimation(xml_node<>* node); |
| 577 | |
| 578 | public: |
| 579 | // Render - Render the full object to the GL surface |
| 580 | // Return 0 on success, <0 on error |
| 581 | virtual int Render(void); |
| 582 | |
| 583 | // Update - Update any UI component animations (called <= 30 FPS) |
| 584 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 585 | virtual int Update(void); |
| 586 | |
| 587 | protected: |
| 588 | AnimationResource* mAnimation; |
| 589 | int mFrame; |
| 590 | int mFPS; |
| 591 | int mLoop; |
| 592 | int mRender; |
| 593 | int mUpdateCount; |
| 594 | }; |
| 595 | |
| 596 | class GUIProgressBar : public RenderObject, public ActionObject |
| 597 | { |
| 598 | public: |
| 599 | GUIProgressBar(xml_node<>* node); |
| 600 | |
| 601 | public: |
| 602 | // Render - Render the full object to the GL surface |
| 603 | // Return 0 on success, <0 on error |
| 604 | virtual int Render(void); |
| 605 | |
| 606 | // Update - Update any UI component animations (called <= 30 FPS) |
| 607 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 608 | virtual int Update(void); |
| 609 | |
| 610 | // NotifyVarChange - Notify of a variable change |
| 611 | // Returns 0 on success, <0 on error |
| 612 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 613 | |
| 614 | protected: |
| 615 | Resource* mEmptyBar; |
| 616 | Resource* mFullBar; |
| 617 | std::string mMinValVar; |
| 618 | std::string mMaxValVar; |
| 619 | std::string mCurValVar; |
| 620 | float mSlide; |
| 621 | float mSlideInc; |
| 622 | int mSlideFrames; |
| 623 | int mLastPos; |
| 624 | |
| 625 | protected: |
| 626 | virtual int RenderInternal(void); // Does the actual render |
| 627 | |
| 628 | }; |
| 629 | |
| 630 | class GUISlider : public RenderObject, public ActionObject |
| 631 | { |
| 632 | public: |
| 633 | GUISlider(xml_node<>* node); |
| 634 | virtual ~GUISlider(); |
| 635 | |
| 636 | public: |
| 637 | // Render - Render the full object to the GL surface |
| 638 | // Return 0 on success, <0 on error |
| 639 | virtual int Render(void); |
| 640 | |
| 641 | // Update - Update any UI component animations (called <= 30 FPS) |
| 642 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 643 | virtual int Update(void); |
| 644 | |
| 645 | // NotifyTouch - Notify of a touch event |
| 646 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 647 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 648 | |
| 649 | protected: |
| 650 | GUIAction* sAction; |
| 651 | Resource* sSlider; |
| 652 | Resource* sSliderUsed; |
| 653 | Resource* sTouch; |
| 654 | int sTouchW, sTouchH; |
| 655 | int sCurTouchX; |
| 656 | int sUpdate; |
| 657 | }; |
| 658 | |
| 659 | #define MAX_KEYBOARD_LAYOUTS 5 |
| 660 | #define MAX_KEYBOARD_ROWS 9 |
| 661 | #define MAX_KEYBOARD_KEYS 20 |
| 662 | #define KEYBOARD_ACTION 253 |
| 663 | #define KEYBOARD_LAYOUT 254 |
| 664 | #define KEYBOARD_SWIPE_LEFT 252 |
| 665 | #define KEYBOARD_SWIPE_RIGHT 251 |
| 666 | #define KEYBOARD_ARROW_LEFT 250 |
| 667 | #define KEYBOARD_ARROW_RIGHT 249 |
| 668 | #define KEYBOARD_HOME 248 |
| 669 | #define KEYBOARD_END 247 |
| 670 | #define KEYBOARD_ARROW_UP 246 |
| 671 | #define KEYBOARD_ARROW_DOWN 245 |
| 672 | #define KEYBOARD_SPECIAL_KEYS 245 |
| 673 | #define KEYBOARD_BACKSPACE 8 |
| 674 | |
| 675 | class GUIKeyboard : public RenderObject, public ActionObject, public Conditional |
| 676 | { |
| 677 | public: |
| 678 | GUIKeyboard(xml_node<>* node); |
| 679 | virtual ~GUIKeyboard(); |
| 680 | |
| 681 | public: |
| 682 | virtual int Render(void); |
| 683 | virtual int Update(void); |
| 684 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 685 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 686 | |
| 687 | protected: |
| 688 | virtual int GetSelection(int x, int y); |
| 689 | |
| 690 | protected: |
| 691 | struct keyboard_key_class |
| 692 | { |
| 693 | unsigned char key; |
| 694 | unsigned char longpresskey; |
| 695 | unsigned int end_x; |
| 696 | unsigned int layout; |
| 697 | }; |
| 698 | |
| 699 | Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS]; |
| 700 | struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS]; |
| 701 | bool mRendered; |
| 702 | std::string mVariable; |
| 703 | unsigned int cursorLocation; |
| 704 | unsigned int currentLayout; |
| 705 | unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS]; |
| 706 | unsigned int KeyboardWidth, KeyboardHeight; |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 707 | int rowY, colX, highlightRenderCount, hasHighlight; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 708 | GUIAction* mAction; |
Dees_Troy | 30b962e | 2012-10-19 20:48:59 -0400 | [diff] [blame] | 709 | COLOR mHighlightColor; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 710 | }; |
| 711 | |
| 712 | // GUIInput - Used for keyboard input |
| 713 | class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject |
| 714 | { |
| 715 | public: |
| 716 | // w and h may be ignored, in which case, no bounding box is applied |
| 717 | GUIInput(xml_node<>* node); |
| 718 | virtual ~GUIInput(); |
| 719 | |
| 720 | public: |
| 721 | // Render - Render the full object to the GL surface |
| 722 | // Return 0 on success, <0 on error |
| 723 | virtual int Render(void); |
| 724 | |
| 725 | // Update - Update any UI component animations (called <= 30 FPS) |
| 726 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 727 | virtual int Update(void); |
| 728 | |
| 729 | // Notify of a variable change |
| 730 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 731 | |
| 732 | // NotifyTouch - Notify of a touch event |
| 733 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 734 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 735 | |
| 736 | virtual int NotifyKeyboard(int key); |
| 737 | |
| 738 | protected: |
| 739 | virtual int GetSelection(int x, int y); |
| 740 | |
| 741 | // Handles displaying the text properly when chars are added, deleted, or for scrolling |
| 742 | virtual int HandleTextLocation(int x); |
| 743 | |
| 744 | protected: |
| 745 | GUIText* mInputText; |
| 746 | GUIAction* mAction; |
| 747 | Resource* mBackground; |
| 748 | Resource* mCursor; |
| 749 | Resource* mFont; |
| 750 | std::string mText; |
| 751 | std::string mLastValue; |
| 752 | std::string mVariable; |
| 753 | std::string mMask; |
| 754 | std::string mMaskVariable; |
| 755 | COLOR mBackgroundColor; |
| 756 | COLOR mCursorColor; |
| 757 | int scrollingX; |
| 758 | int lastX; |
| 759 | int mCursorLocation; |
| 760 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; |
| 761 | int mFontY; |
| 762 | unsigned skipChars; |
| 763 | unsigned mFontHeight; |
| 764 | unsigned CursorWidth; |
| 765 | bool mRendered; |
| 766 | bool HasMask; |
| 767 | bool DrawCursor; |
| 768 | bool isLocalChange; |
| 769 | bool HasAllowed; |
| 770 | bool HasDisabled; |
| 771 | std::string AllowedList; |
| 772 | std::string DisabledList; |
| 773 | unsigned MinLen; |
| 774 | unsigned MaxLen; |
| 775 | }; |
| 776 | |
| 777 | class HardwareKeyboard |
| 778 | { |
| 779 | public: |
| 780 | HardwareKeyboard(void); |
| 781 | virtual ~HardwareKeyboard(); |
| 782 | |
| 783 | public: |
| 784 | virtual int KeyDown(int key_code); |
| 785 | virtual int KeyUp(int key_code); |
| 786 | virtual int KeyRepeat(void); |
| 787 | }; |
| 788 | |
| 789 | // Helper APIs |
| 790 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL); |
| 791 | |
| 792 | #endif // _OBJECTS_HEADER |
| 793 | |