CursorManager.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platformInput.h"
  23. #include "platform/platformVideo.h"
  24. #include "platform/event.h"
  25. #include "console/console.h"
  26. //------------------------------------------------------------------------------
  27. //*** DAW: Cursor Manager Methods
  28. CursorManager* Input::getCursorManager()
  29. {
  30. return smCursorManager;
  31. }
  32. void CursorManager::pushCursor(S32 cursorID)
  33. {
  34. //*** Place the new cursor shape onto the stack
  35. mCursors.increment();
  36. mCursors.last().mCursorID = cursorID;
  37. //*** Now actually change the shape
  38. changeCursorShape(cursorID);
  39. }
  40. void CursorManager::popCursor()
  41. {
  42. //*** Before poping the stack, make sure we're not trying to remove the last cursor shape
  43. if(mCursors.size() <= 1)
  44. return;
  45. //*** Pop the stack
  46. mCursors.pop_back();
  47. //*** Now set the cursor shape
  48. changeCursorShape(mCursors.last().mCursorID);
  49. }
  50. void CursorManager::refreshCursor()
  51. {
  52. //*** Refresh the cursor's shape
  53. changeCursorShape(mCursors.last().mCursorID);
  54. }
  55. void CursorManager::changeCursorShape(S32 cursorID)
  56. {
  57. if(cursorID >= 0)
  58. Input::setCursorShape((U32)cursorID);
  59. }
  60. static EnumTable::Enums curManagerShapesEnums[] =
  61. {
  62. { CursorManager::curArrow, "Arrow" },
  63. { CursorManager::curWait, "Wait" },
  64. { CursorManager::curPlus, "Plus" },
  65. { CursorManager::curResizeVert, "ResizeVert" },
  66. { CursorManager::curResizeHorz, "ResizeHorz" },
  67. { CursorManager::curResizeAll, "ResizeAll" },
  68. { CursorManager::curIBeam, "ibeam" },
  69. { CursorManager::curResizeNESW, "ResizeNESW" },
  70. { CursorManager::curResizeNWSE, "ResizeNWSE" },
  71. };
  72. static EnumTable gCurManagerShapesTable(8, &curManagerShapesEnums[0]);
  73. //*** Console function to set the current cursor shape given the cursor shape
  74. //*** name as defined in the enum above.
  75. ConsoleFunction( inputPushCursor, void, 2, 2, "(cursorShapeName) Set's the current cursor to one specified"
  76. "@param cursorShapeName Name corresponding to enumerated shape value: \"Arrow\", \"Wait\", \"Plus\", \"ResizeVert\", \"ResizeHorz\", "
  77. "\"ResizeAll\", \"ibeam\", \"ResizeNESW\", \"ResizeNWSE\"\n"
  78. "@return No Return Value")
  79. {
  80. S32 val = 0;
  81. //*** Find the cursor shape
  82. if(argc == 2)
  83. {
  84. for (S32 i = 0; i < gCurManagerShapesTable.size; i++)
  85. {
  86. if (! dStricmp(argv[1], gCurManagerShapesTable.table[i].label))
  87. {
  88. val = gCurManagerShapesTable.table[i].index;
  89. break;
  90. }
  91. }
  92. }
  93. //*** Now set it
  94. CursorManager* cm = Input::getCursorManager();
  95. if(cm)
  96. {
  97. cm->pushCursor(val);
  98. }
  99. }
  100. //*** Function to pop the current cursor shape
  101. ConsoleFunction( inputPopCursor, void, 1, 1, "() Pops the current cursor shape from manager stack\n"
  102. "@return No Return Value.")
  103. {
  104. CursorManager* cm = Input::getCursorManager();
  105. if(cm)
  106. {
  107. cm->popCursor();
  108. }
  109. }