sdlCursorController.cpp
Engine/source/windowManager/sdl/sdlCursorController.cpp
Public Variables
Detailed Description
Public Variables
SDL_Cursor * cursor
U32 id
SDL_SystemCursor resourceID
struct @168 sgCursorShapeMap []
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "core/strings/unicode.h" 25#include "math/mMath.h" 26#include "windowManager/sdl/sdlWindow.h" 27#include "windowManager/sdl/sdlWindowMgr.h" 28#include "windowManager/sdl/sdlCursorController.h" 29#include "platform/platformInput.h" 30 31#include "SDL.h" 32 33static struct { U32 id; SDL_SystemCursor resourceID; SDL_Cursor *cursor;} sgCursorShapeMap[]= 34{ 35 { PlatformCursorController::curArrow, SDL_SYSTEM_CURSOR_ARROW , NULL }, 36 { PlatformCursorController::curWait, SDL_SYSTEM_CURSOR_WAIT, NULL }, 37 { PlatformCursorController::curPlus, SDL_SYSTEM_CURSOR_CROSSHAIR, NULL }, 38 { PlatformCursorController::curResizeVert, SDL_SYSTEM_CURSOR_SIZEWE, NULL }, 39 { PlatformCursorController::curResizeHorz, SDL_SYSTEM_CURSOR_SIZENS, NULL }, 40 { PlatformCursorController::curResizeAll, SDL_SYSTEM_CURSOR_SIZEALL, NULL }, 41 { PlatformCursorController::curIBeam, SDL_SYSTEM_CURSOR_IBEAM, NULL }, 42 { PlatformCursorController::curResizeNESW, SDL_SYSTEM_CURSOR_SIZENESW, NULL }, 43 { PlatformCursorController::curResizeNWSE, SDL_SYSTEM_CURSOR_SIZENWSE, NULL }, 44 { PlatformCursorController::curHand, SDL_SYSTEM_CURSOR_HAND, NULL }, 45 { 0, SDL_SYSTEM_CURSOR_NO, NULL }, 46}; 47 48 49U32 PlatformCursorControllerSDL::getDoubleClickTime() 50{ 51 // TODO SDL 52 return 500; 53} 54S32 PlatformCursorControllerSDL::getDoubleClickWidth() 55{ 56 // TODO SDL 57 return 32; 58} 59S32 PlatformCursorControllerSDL::getDoubleClickHeight() 60{ 61 // TODO SDL 62 return 32; 63} 64 65void PlatformCursorControllerSDL::setCursorPosition( S32 x, S32 y ) 66{ 67 if( PlatformWindowManager::get() && PlatformWindowManager::get()->getFirstWindow() ) 68 { 69 AssertFatal( dynamic_cast<PlatformWindowSDL*>( PlatformWindowManager::get()->getFirstWindow() ), ""); 70 PlatformWindowSDL *window = static_cast<PlatformWindowSDL*>( PlatformWindowManager::get()->getFirstWindow() ); 71 SDL_WarpMouseInWindow(window->getSDLWindow(), x, y); 72 } 73} 74 75void PlatformCursorControllerSDL::getCursorPosition( Point2I &point ) 76{ 77 SDL_GetMouseState( &point.x, &point.y ); 78} 79 80void PlatformCursorControllerSDL::setCursorVisible( bool visible ) 81{ 82 SDL_ShowCursor( visible ); 83} 84 85bool PlatformCursorControllerSDL::isCursorVisible() 86{ 87 return SDL_ShowCursor( -1 );; 88} 89 90void PlatformCursorControllerSDL::setCursorShape(U32 cursorID) 91{ 92 SDL_Cursor* cursor = NULL; 93 94 for(S32 i = 0; sgCursorShapeMap[i].resourceID != SDL_SYSTEM_CURSOR_NO; ++i) 95 { 96 if(cursorID == sgCursorShapeMap[i].id) 97 { 98 if( !sgCursorShapeMap[i].cursor ) 99 sgCursorShapeMap[i].cursor = SDL_CreateSystemCursor( sgCursorShapeMap[i].resourceID ); 100 101 cursor = sgCursorShapeMap[i].cursor; 102 break; 103 } 104 } 105 106 if( !cursor ) 107 return; 108 109 SDL_SetCursor(cursor); 110} 111 112 113void PlatformCursorControllerSDL::setCursorShape( const UTF8 *fileName, bool reload ) 114{ 115 // TODO SDL 116 AssertWarn(0, "PlatformCursorControllerSDL::setCursorShape - Not implemented"); 117} 118
