sdlCursorController.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 "core/strings/unicode.h"
  23. #include "math/mMath.h"
  24. #include "windowManager/sdl/sdlWindow.h"
  25. #include "windowManager/sdl/sdlWindowMgr.h"
  26. #include "windowManager/sdl/sdlCursorController.h"
  27. #include "platform/platformInput.h"
  28. #include "SDL.h"
  29. static struct { U32 id; SDL_SystemCursor resourceID; SDL_Cursor *cursor;} sgCursorShapeMap[]=
  30. {
  31. { PlatformCursorController::curArrow, SDL_SYSTEM_CURSOR_ARROW , NULL },
  32. { PlatformCursorController::curWait, SDL_SYSTEM_CURSOR_WAIT, NULL },
  33. { PlatformCursorController::curPlus, SDL_SYSTEM_CURSOR_CROSSHAIR, NULL },
  34. { PlatformCursorController::curResizeVert, SDL_SYSTEM_CURSOR_SIZEWE, NULL },
  35. { PlatformCursorController::curResizeHorz, SDL_SYSTEM_CURSOR_SIZENS, NULL },
  36. { PlatformCursorController::curResizeAll, SDL_SYSTEM_CURSOR_SIZEALL, NULL },
  37. { PlatformCursorController::curIBeam, SDL_SYSTEM_CURSOR_IBEAM, NULL },
  38. { PlatformCursorController::curResizeNESW, SDL_SYSTEM_CURSOR_SIZENESW, NULL },
  39. { PlatformCursorController::curResizeNWSE, SDL_SYSTEM_CURSOR_SIZENWSE, NULL },
  40. { PlatformCursorController::curHand, SDL_SYSTEM_CURSOR_HAND, NULL },
  41. { PlatformCursorController::curWaitArrow, SDL_SYSTEM_CURSOR_WAITARROW, NULL },
  42. { PlatformCursorController::curNoNo, SDL_SYSTEM_CURSOR_NO, NULL },
  43. };
  44. U32 PlatformCursorControllerSDL::getDoubleClickTime()
  45. {
  46. // TODO SDL
  47. return 500;
  48. }
  49. S32 PlatformCursorControllerSDL::getDoubleClickWidth()
  50. {
  51. // TODO SDL
  52. return 32;
  53. }
  54. S32 PlatformCursorControllerSDL::getDoubleClickHeight()
  55. {
  56. // TODO SDL
  57. return 32;
  58. }
  59. void PlatformCursorControllerSDL::setCursorPosition( S32 x, S32 y )
  60. {
  61. SDL_WarpMouseGlobal(x, y);
  62. }
  63. void PlatformCursorControllerSDL::getCursorPosition( Point2I &point )
  64. {
  65. SDL_GetGlobalMouseState( &point.x, &point.y );
  66. }
  67. void PlatformCursorControllerSDL::setCursorVisible( bool visible )
  68. {
  69. SDL_ShowCursor( visible );
  70. }
  71. bool PlatformCursorControllerSDL::isCursorVisible()
  72. {
  73. return SDL_ShowCursor( -1 );;
  74. }
  75. void PlatformCursorControllerSDL::setCursorShape(U32 cursorID)
  76. {
  77. SDL_Cursor* cursor = NULL;
  78. for(S32 i = 0; i < numPlatformCursors; ++i)
  79. {
  80. if(cursorID == sgCursorShapeMap[i].id)
  81. {
  82. if( !sgCursorShapeMap[i].cursor )
  83. sgCursorShapeMap[i].cursor = SDL_CreateSystemCursor( sgCursorShapeMap[i].resourceID );
  84. cursor = sgCursorShapeMap[i].cursor;
  85. break;
  86. }
  87. }
  88. if( !cursor )
  89. return;
  90. SDL_SetCursor(cursor);
  91. }
  92. void PlatformCursorControllerSDL::setCursorShape( const UTF8 *fileName, bool reload )
  93. {
  94. // TODO SDL
  95. AssertWarn(0, "PlatformCursorControllerSDL::setCursorShape - Not implemented");
  96. }