sdlCursorController.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. { 0, SDL_SYSTEM_CURSOR_NO, NULL },
  42. };
  43. U32 PlatformCursorControllerSDL::getDoubleClickTime()
  44. {
  45. // TODO SDL
  46. return 500;
  47. }
  48. S32 PlatformCursorControllerSDL::getDoubleClickWidth()
  49. {
  50. // TODO SDL
  51. return 32;
  52. }
  53. S32 PlatformCursorControllerSDL::getDoubleClickHeight()
  54. {
  55. // TODO SDL
  56. return 32;
  57. }
  58. void PlatformCursorControllerSDL::setCursorPosition( S32 x, S32 y )
  59. {
  60. if( PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow() )
  61. {
  62. AssertFatal( dynamic_cast<PlatformWindowSDL*>( PlatformWindowManager::get()->getFirstWindow() ), "");
  63. PlatformWindowSDL *window = static_cast<PlatformWindowSDL*>( PlatformWindowManager::get()->getFirstWindow() );
  64. SDL_WarpMouseInWindow(window->getSDLWindow(), x, y);
  65. }
  66. }
  67. void PlatformCursorControllerSDL::getCursorPosition( Point2I &point )
  68. {
  69. SDL_GetMouseState( &point.x, &point.y );
  70. }
  71. void PlatformCursorControllerSDL::setCursorVisible( bool visible )
  72. {
  73. SDL_ShowCursor( visible );
  74. }
  75. bool PlatformCursorControllerSDL::isCursorVisible()
  76. {
  77. return SDL_ShowCursor( -1 );;
  78. }
  79. void PlatformCursorControllerSDL::setCursorShape(U32 cursorID)
  80. {
  81. SDL_Cursor* cursor = NULL;
  82. for(S32 i = 0; sgCursorShapeMap[i].resourceID != SDL_SYSTEM_CURSOR_NO; ++i)
  83. {
  84. if(cursorID == sgCursorShapeMap[i].id)
  85. {
  86. if( !sgCursorShapeMap[i].cursor )
  87. sgCursorShapeMap[i].cursor = SDL_CreateSystemCursor( sgCursorShapeMap[i].resourceID );
  88. cursor = sgCursorShapeMap[i].cursor;
  89. break;
  90. }
  91. }
  92. if( !cursor )
  93. return;
  94. SDL_SetCursor(cursor);
  95. }
  96. void PlatformCursorControllerSDL::setCursorShape( const UTF8 *fileName, bool reload )
  97. {
  98. // TODO SDL
  99. AssertWarn(0, "PlatformCursorControllerSDL::setCursorShape - Not implemented");
  100. }