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 | |
| 177 | protected: |
| 178 | std::string mText; |
| 179 | std::string mLastValue; |
| 180 | COLOR mColor; |
| 181 | Resource* mFont; |
| 182 | int mIsStatic; |
| 183 | int mVarChanged; |
| 184 | int mFontHeight; |
| 185 | unsigned maxWidth; |
| 186 | unsigned charSkip; |
| 187 | |
| 188 | protected: |
| 189 | std::string parseText(void); |
| 190 | }; |
| 191 | |
| 192 | // GUIImage - Used for static image |
| 193 | class GUIImage : public RenderObject |
| 194 | { |
| 195 | public: |
| 196 | GUIImage(xml_node<>* node); |
| 197 | |
| 198 | public: |
| 199 | // Render - Render the full object to the GL surface |
| 200 | // Return 0 on success, <0 on error |
| 201 | virtual int Render(void); |
| 202 | |
| 203 | // SetRenderPos - Update the position of the object |
| 204 | // Return 0 on success, <0 on error |
| 205 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 206 | |
| 207 | protected: |
| 208 | Resource* mImage; |
| 209 | }; |
| 210 | |
| 211 | // GUIFill - Used for fill colors |
| 212 | class GUIFill : public RenderObject |
| 213 | { |
| 214 | public: |
| 215 | GUIFill(xml_node<>* node); |
| 216 | |
| 217 | public: |
| 218 | // Render - Render the full object to the GL surface |
| 219 | // Return 0 on success, <0 on error |
| 220 | virtual int Render(void); |
| 221 | |
| 222 | protected: |
| 223 | COLOR mColor; |
| 224 | }; |
| 225 | |
| 226 | // GUIAction - Used for standard actions |
| 227 | class GUIAction : public ActionObject, public Conditional |
| 228 | { |
| 229 | public: |
| 230 | GUIAction(xml_node<>* node); |
| 231 | |
| 232 | public: |
| 233 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 234 | virtual int NotifyKey(int key); |
| 235 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 236 | virtual int doActions(); |
| 237 | |
| 238 | protected: |
| 239 | class Action |
| 240 | { |
| 241 | public: |
| 242 | std::string mFunction; |
| 243 | std::string mArg; |
| 244 | }; |
| 245 | |
| 246 | std::vector<Action> mActions; |
| 247 | int mKey; |
| 248 | |
| 249 | protected: |
| 250 | int getKeyByName(std::string key); |
| 251 | virtual int doAction(Action action, int isThreaded = 0); |
| 252 | static void* thread_start(void *cookie); |
| 253 | void simulate_progress_bar(void); |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 254 | 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] | 255 | void operation_start(const string operation_name); |
| 256 | void operation_end(const int operation_status, const int simulate); |
| 257 | static void* command_thread(void *cookie); |
| 258 | }; |
| 259 | |
| 260 | class GUIConsole : public RenderObject, public ActionObject |
| 261 | { |
| 262 | public: |
| 263 | GUIConsole(xml_node<>* node); |
| 264 | |
| 265 | public: |
| 266 | // Render - Render the full object to the GL surface |
| 267 | // Return 0 on success, <0 on error |
| 268 | virtual int Render(void); |
| 269 | |
| 270 | // Update - Update any UI component animations (called <= 30 FPS) |
| 271 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 272 | virtual int Update(void); |
| 273 | |
| 274 | // SetRenderPos - Update the position of the object |
| 275 | // Return 0 on success, <0 on error |
| 276 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 277 | |
| 278 | // IsInRegion - Checks if the request is handled by this object |
| 279 | // Return 0 if this object handles the request, 1 if not |
| 280 | virtual int IsInRegion(int x, int y); |
| 281 | |
| 282 | // NotifyTouch - Notify of a touch event |
| 283 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error (Return error to allow other handlers) |
| 284 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 285 | |
| 286 | protected: |
| 287 | enum SlideoutState |
| 288 | { |
| 289 | hidden = 0, |
| 290 | visible, |
| 291 | request_hide, |
| 292 | request_show |
| 293 | }; |
| 294 | Resource* mFont; |
| 295 | Resource* mSlideoutImage; |
| 296 | COLOR mForegroundColor; |
| 297 | COLOR mBackgroundColor; |
| 298 | COLOR mScrollColor; |
| 299 | unsigned int mFontHeight; |
| 300 | int mCurrentLine; |
| 301 | unsigned int mLastCount; |
| 302 | unsigned int mMaxRows; |
| 303 | int mStartY; |
| 304 | int mSlideoutX, mSlideoutY, mSlideoutW, mSlideoutH; |
| 305 | int mSlideinX, mSlideinY, mSlideinW, mSlideinH; |
| 306 | int mConsoleX, mConsoleY, mConsoleW, mConsoleH; |
| 307 | int mLastTouchX, mLastTouchY; |
| 308 | int mSlideMultiplier; |
| 309 | int mSlideout; |
| 310 | SlideoutState mSlideoutState; |
| 311 | |
| 312 | protected: |
| 313 | virtual int RenderSlideout(void); |
| 314 | virtual int RenderConsole(void); |
| 315 | |
| 316 | }; |
| 317 | |
| 318 | class GUIButton : public RenderObject, public ActionObject, public Conditional |
| 319 | { |
| 320 | public: |
| 321 | GUIButton(xml_node<>* node); |
| 322 | virtual ~GUIButton(); |
| 323 | |
| 324 | public: |
| 325 | // Render - Render the full object to the GL surface |
| 326 | // Return 0 on success, <0 on error |
| 327 | virtual int Render(void); |
| 328 | |
| 329 | // Update - Update any UI component animations (called <= 30 FPS) |
| 330 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 331 | virtual int Update(void); |
| 332 | |
| 333 | // SetPos - Update the position of the render object |
| 334 | // Return 0 on success, <0 on error |
| 335 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 336 | |
| 337 | // NotifyTouch - Notify of a touch event |
| 338 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 339 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 340 | |
| 341 | protected: |
| 342 | GUIImage* mButtonImg; |
| 343 | Resource* mButtonIcon; |
| 344 | GUIText* mButtonLabel; |
| 345 | GUIAction* mAction; |
| 346 | int mTextX, mTextY, mTextW, mTextH; |
| 347 | int mIconX, mIconY, mIconW, mIconH; |
| 348 | bool mRendered; |
| 349 | }; |
| 350 | |
| 351 | class GUICheckbox: public RenderObject, public ActionObject, public Conditional |
| 352 | { |
| 353 | public: |
| 354 | GUICheckbox(xml_node<>* node); |
| 355 | virtual ~GUICheckbox(); |
| 356 | |
| 357 | public: |
| 358 | // Render - Render the full object to the GL surface |
| 359 | // Return 0 on success, <0 on error |
| 360 | virtual int Render(void); |
| 361 | |
| 362 | // Update - Update any UI component animations (called <= 30 FPS) |
| 363 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 364 | virtual int Update(void); |
| 365 | |
| 366 | // SetPos - Update the position of the render object |
| 367 | // Return 0 on success, <0 on error |
| 368 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 369 | |
| 370 | // NotifyTouch - Notify of a touch event |
| 371 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 372 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 373 | |
| 374 | protected: |
| 375 | Resource* mChecked; |
| 376 | Resource* mUnchecked; |
| 377 | GUIText* mLabel; |
| 378 | int mTextX, mTextY; |
| 379 | int mCheckX, mCheckY, mCheckW, mCheckH; |
| 380 | int mLastState; |
| 381 | bool mRendered; |
| 382 | std::string mVarName; |
| 383 | }; |
| 384 | |
| 385 | class GUIFileSelector : public RenderObject, public ActionObject |
| 386 | { |
| 387 | public: |
| 388 | GUIFileSelector(xml_node<>* node); |
| 389 | virtual ~GUIFileSelector(); |
| 390 | |
| 391 | public: |
| 392 | // Render - Render the full object to the GL surface |
| 393 | // Return 0 on success, <0 on error |
| 394 | virtual int Render(void); |
| 395 | |
| 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); |
| 399 | |
| 400 | // NotifyTouch - Notify of a touch event |
| 401 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 402 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 403 | |
| 404 | // NotifyVarChange - Notify of a variable change |
| 405 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 406 | |
| 407 | // SetPos - Update the position of the render object |
| 408 | // Return 0 on success, <0 on error |
| 409 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 410 | |
| 411 | // SetPageFocus - Notify when a page gains or loses focus |
| 412 | virtual void SetPageFocus(int inFocus); |
| 413 | |
| 414 | protected: |
| 415 | struct FileData { |
| 416 | std::string fileName; |
| 417 | unsigned char fileType; // Uses d_type format from struct dirent |
| 418 | mode_t protection; // Uses mode_t format from stat |
| 419 | uid_t userId; |
| 420 | gid_t groupId; |
| 421 | off_t fileSize; |
| 422 | time_t lastAccess; // Uses time_t format from stat |
| 423 | time_t lastModified; // Uses time_t format from stat |
| 424 | time_t lastStatChange; // Uses time_t format from stat |
| 425 | }; |
| 426 | |
| 427 | protected: |
| 428 | virtual int GetSelection(int x, int y); |
| 429 | |
| 430 | virtual int GetFileList(const std::string folder); |
| 431 | static bool fileSort(FileData d1, FileData d2); |
| 432 | |
| 433 | protected: |
| 434 | std::vector<FileData> mFolderList; |
| 435 | std::vector<FileData> mFileList; |
| 436 | std::string mPathVar; |
| 437 | std::string mExtn; |
| 438 | std::string mVariable; |
| 439 | std::string mSortVariable; |
| 440 | std::string mSelection; |
| 441 | std::string mHeaderText; |
| 442 | std::string mLastValue; |
| 443 | int actualLineHeight; |
| 444 | int mStart; |
| 445 | int mLineSpacing; |
| 446 | int mSeparatorH; |
| 447 | int mHeaderSeparatorH; |
| 448 | int mShowFolders, mShowFiles, mShowNavFolders; |
| 449 | int mUpdate; |
| 450 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; |
| 451 | int mHeaderH; |
| 452 | static int mSortOrder; |
| 453 | int startY; |
| 454 | int scrollingSpeed; |
| 455 | int scrollingY; |
| 456 | int mHeaderIsStatic; |
| 457 | int touchDebounce; |
| 458 | unsigned mFontHeight; |
| 459 | unsigned mLineHeight; |
| 460 | int mIconWidth, mIconHeight, mFolderIconHeight, mFileIconHeight, mFolderIconWidth, mFileIconWidth, mHeaderIconHeight, mHeaderIconWidth; |
| 461 | Resource* mHeaderIcon; |
| 462 | Resource* mFolderIcon; |
| 463 | Resource* mFileIcon; |
| 464 | Resource* mBackground; |
| 465 | Resource* mFont; |
| 466 | COLOR mBackgroundColor; |
| 467 | COLOR mFontColor; |
| 468 | COLOR mHeaderBackgroundColor; |
| 469 | COLOR mHeaderFontColor; |
| 470 | COLOR mSeparatorColor; |
| 471 | COLOR mHeaderSeparatorColor; |
| 472 | }; |
| 473 | |
| 474 | class GUIListBox : public RenderObject, public ActionObject |
| 475 | { |
| 476 | public: |
| 477 | GUIListBox(xml_node<>* node); |
| 478 | virtual ~GUIListBox(); |
| 479 | |
| 480 | public: |
| 481 | // Render - Render the full object to the GL surface |
| 482 | // Return 0 on success, <0 on error |
| 483 | virtual int Render(void); |
| 484 | |
| 485 | // Update - Update any UI component animations (called <= 30 FPS) |
| 486 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 487 | virtual int Update(void); |
| 488 | |
| 489 | // NotifyTouch - Notify of a touch event |
| 490 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 491 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 492 | |
| 493 | // NotifyVarChange - Notify of a variable change |
| 494 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 495 | |
| 496 | // SetPos - Update the position of the render object |
| 497 | // Return 0 on success, <0 on error |
| 498 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 499 | |
| 500 | // SetPageFocus - Notify when a page gains or loses focus |
| 501 | virtual void SetPageFocus(int inFocus); |
| 502 | |
| 503 | protected: |
| 504 | struct ListData { |
| 505 | std::string displayName; |
| 506 | std::string variableValue; |
| 507 | unsigned int selected; |
| 508 | }; |
| 509 | |
| 510 | protected: |
| 511 | virtual int GetSelection(int x, int y); |
| 512 | |
| 513 | protected: |
| 514 | std::vector<ListData> mList; |
| 515 | std::string mVariable; |
| 516 | std::string mSelection; |
| 517 | std::string currentValue; |
| 518 | int mStart; |
| 519 | int mLineSpacing; |
| 520 | int mUpdate; |
| 521 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; |
| 522 | static int mSortOrder; |
| 523 | unsigned mFontHeight; |
| 524 | unsigned mLineHeight; |
| 525 | int mIconWidth, mIconHeight; |
| 526 | Resource* mIconSelected; |
| 527 | Resource* mIconUnselected; |
| 528 | Resource* mBackground; |
| 529 | Resource* mFont; |
| 530 | COLOR mBackgroundColor; |
| 531 | COLOR mFontColor; |
| 532 | }; |
| 533 | |
| 534 | // GUIAnimation - Used for animations |
| 535 | class GUIAnimation : public RenderObject |
| 536 | { |
| 537 | public: |
| 538 | GUIAnimation(xml_node<>* node); |
| 539 | |
| 540 | public: |
| 541 | // Render - Render the full object to the GL surface |
| 542 | // Return 0 on success, <0 on error |
| 543 | virtual int Render(void); |
| 544 | |
| 545 | // Update - Update any UI component animations (called <= 30 FPS) |
| 546 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 547 | virtual int Update(void); |
| 548 | |
| 549 | protected: |
| 550 | AnimationResource* mAnimation; |
| 551 | int mFrame; |
| 552 | int mFPS; |
| 553 | int mLoop; |
| 554 | int mRender; |
| 555 | int mUpdateCount; |
| 556 | }; |
| 557 | |
| 558 | class GUIProgressBar : public RenderObject, public ActionObject |
| 559 | { |
| 560 | public: |
| 561 | GUIProgressBar(xml_node<>* node); |
| 562 | |
| 563 | public: |
| 564 | // Render - Render the full object to the GL surface |
| 565 | // Return 0 on success, <0 on error |
| 566 | virtual int Render(void); |
| 567 | |
| 568 | // Update - Update any UI component animations (called <= 30 FPS) |
| 569 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 570 | virtual int Update(void); |
| 571 | |
| 572 | // NotifyVarChange - Notify of a variable change |
| 573 | // Returns 0 on success, <0 on error |
| 574 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 575 | |
| 576 | protected: |
| 577 | Resource* mEmptyBar; |
| 578 | Resource* mFullBar; |
| 579 | std::string mMinValVar; |
| 580 | std::string mMaxValVar; |
| 581 | std::string mCurValVar; |
| 582 | float mSlide; |
| 583 | float mSlideInc; |
| 584 | int mSlideFrames; |
| 585 | int mLastPos; |
| 586 | |
| 587 | protected: |
| 588 | virtual int RenderInternal(void); // Does the actual render |
| 589 | |
| 590 | }; |
| 591 | |
| 592 | class GUISlider : public RenderObject, public ActionObject |
| 593 | { |
| 594 | public: |
| 595 | GUISlider(xml_node<>* node); |
| 596 | virtual ~GUISlider(); |
| 597 | |
| 598 | public: |
| 599 | // Render - Render the full object to the GL surface |
| 600 | // Return 0 on success, <0 on error |
| 601 | virtual int Render(void); |
| 602 | |
| 603 | // Update - Update any UI component animations (called <= 30 FPS) |
| 604 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 605 | virtual int Update(void); |
| 606 | |
| 607 | // NotifyTouch - Notify of a touch event |
| 608 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 609 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 610 | |
| 611 | protected: |
| 612 | GUIAction* sAction; |
| 613 | Resource* sSlider; |
| 614 | Resource* sSliderUsed; |
| 615 | Resource* sTouch; |
| 616 | int sTouchW, sTouchH; |
| 617 | int sCurTouchX; |
| 618 | int sUpdate; |
| 619 | }; |
| 620 | |
| 621 | #define MAX_KEYBOARD_LAYOUTS 5 |
| 622 | #define MAX_KEYBOARD_ROWS 9 |
| 623 | #define MAX_KEYBOARD_KEYS 20 |
| 624 | #define KEYBOARD_ACTION 253 |
| 625 | #define KEYBOARD_LAYOUT 254 |
| 626 | #define KEYBOARD_SWIPE_LEFT 252 |
| 627 | #define KEYBOARD_SWIPE_RIGHT 251 |
| 628 | #define KEYBOARD_ARROW_LEFT 250 |
| 629 | #define KEYBOARD_ARROW_RIGHT 249 |
| 630 | #define KEYBOARD_HOME 248 |
| 631 | #define KEYBOARD_END 247 |
| 632 | #define KEYBOARD_ARROW_UP 246 |
| 633 | #define KEYBOARD_ARROW_DOWN 245 |
| 634 | #define KEYBOARD_SPECIAL_KEYS 245 |
| 635 | #define KEYBOARD_BACKSPACE 8 |
| 636 | |
| 637 | class GUIKeyboard : public RenderObject, public ActionObject, public Conditional |
| 638 | { |
| 639 | public: |
| 640 | GUIKeyboard(xml_node<>* node); |
| 641 | virtual ~GUIKeyboard(); |
| 642 | |
| 643 | public: |
| 644 | virtual int Render(void); |
| 645 | virtual int Update(void); |
| 646 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 647 | virtual int SetRenderPos(int x, int y, int w = 0, int h = 0); |
| 648 | |
| 649 | protected: |
| 650 | virtual int GetSelection(int x, int y); |
| 651 | |
| 652 | protected: |
| 653 | struct keyboard_key_class |
| 654 | { |
| 655 | unsigned char key; |
| 656 | unsigned char longpresskey; |
| 657 | unsigned int end_x; |
| 658 | unsigned int layout; |
| 659 | }; |
| 660 | |
| 661 | Resource* keyboardImg[MAX_KEYBOARD_LAYOUTS]; |
| 662 | struct keyboard_key_class keyboard_keys[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS][MAX_KEYBOARD_KEYS]; |
| 663 | bool mRendered; |
| 664 | std::string mVariable; |
| 665 | unsigned int cursorLocation; |
| 666 | unsigned int currentLayout; |
| 667 | unsigned int row_heights[MAX_KEYBOARD_LAYOUTS][MAX_KEYBOARD_ROWS]; |
| 668 | unsigned int KeyboardWidth, KeyboardHeight; |
| 669 | GUIAction* mAction; |
| 670 | }; |
| 671 | |
| 672 | // GUIInput - Used for keyboard input |
| 673 | class GUIInput : public RenderObject, public ActionObject, public Conditional, public InputObject |
| 674 | { |
| 675 | public: |
| 676 | // w and h may be ignored, in which case, no bounding box is applied |
| 677 | GUIInput(xml_node<>* node); |
| 678 | virtual ~GUIInput(); |
| 679 | |
| 680 | public: |
| 681 | // Render - Render the full object to the GL surface |
| 682 | // Return 0 on success, <0 on error |
| 683 | virtual int Render(void); |
| 684 | |
| 685 | // Update - Update any UI component animations (called <= 30 FPS) |
| 686 | // Return 0 if nothing to update, 1 on success and contiue, >1 if full render required, and <0 on error |
| 687 | virtual int Update(void); |
| 688 | |
| 689 | // Notify of a variable change |
| 690 | virtual int NotifyVarChange(std::string varName, std::string value); |
| 691 | |
| 692 | // NotifyTouch - Notify of a touch event |
| 693 | // Return 0 on success, >0 to ignore remainder of touch, and <0 on error |
| 694 | virtual int NotifyTouch(TOUCH_STATE state, int x, int y); |
| 695 | |
| 696 | virtual int NotifyKeyboard(int key); |
| 697 | |
| 698 | protected: |
| 699 | virtual int GetSelection(int x, int y); |
| 700 | |
| 701 | // Handles displaying the text properly when chars are added, deleted, or for scrolling |
| 702 | virtual int HandleTextLocation(int x); |
| 703 | |
| 704 | protected: |
| 705 | GUIText* mInputText; |
| 706 | GUIAction* mAction; |
| 707 | Resource* mBackground; |
| 708 | Resource* mCursor; |
| 709 | Resource* mFont; |
| 710 | std::string mText; |
| 711 | std::string mLastValue; |
| 712 | std::string mVariable; |
| 713 | std::string mMask; |
| 714 | std::string mMaskVariable; |
| 715 | COLOR mBackgroundColor; |
| 716 | COLOR mCursorColor; |
| 717 | int scrollingX; |
| 718 | int lastX; |
| 719 | int mCursorLocation; |
| 720 | int mBackgroundX, mBackgroundY, mBackgroundW, mBackgroundH; |
| 721 | int mFontY; |
| 722 | unsigned skipChars; |
| 723 | unsigned mFontHeight; |
| 724 | unsigned CursorWidth; |
| 725 | bool mRendered; |
| 726 | bool HasMask; |
| 727 | bool DrawCursor; |
| 728 | bool isLocalChange; |
| 729 | bool HasAllowed; |
| 730 | bool HasDisabled; |
| 731 | std::string AllowedList; |
| 732 | std::string DisabledList; |
| 733 | unsigned MinLen; |
| 734 | unsigned MaxLen; |
| 735 | }; |
| 736 | |
| 737 | class HardwareKeyboard |
| 738 | { |
| 739 | public: |
| 740 | HardwareKeyboard(void); |
| 741 | virtual ~HardwareKeyboard(); |
| 742 | |
| 743 | public: |
| 744 | virtual int KeyDown(int key_code); |
| 745 | virtual int KeyUp(int key_code); |
| 746 | virtual int KeyRepeat(void); |
| 747 | }; |
| 748 | |
| 749 | // Helper APIs |
| 750 | bool LoadPlacement(xml_node<>* node, int* x, int* y, int* w = NULL, int* h = NULL, RenderObject::Placement* placement = NULL); |
| 751 | |
| 752 | #endif // _OBJECTS_HEADER |
| 753 | |