Torque3D Documentation / _generateds / sdlCursorController.cpp

sdlCursorController.cpp

Engine/source/windowManager/sdl/sdlCursorController.cpp

More...

Public Variables

SDL_Cursor *
SDL_SystemCursor
struct @221

Detailed Description

Public Variables

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