win32CursorController.cpp
Engine/source/windowManager/win32/win32CursorController.cpp
Public Variables
Detailed Description
Public Variables
HCURSOR gCursorShape
U32 id
LPTSTR resourceID
struct @222 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 <windows.h> 25#include <tchar.h> 26#include "core/strings/unicode.h" 27#include "math/mMath.h" 28#include "windowManager/win32/win32Window.h" 29#include "windowManager/win32/win32WindowMgr.h" 30#include "windowManager/win32/winDispatch.h" 31#include "windowManager/win32/win32CursorController.h" 32#include "platform/platformInput.h" 33#include <zmouse.h> 34 35static struct { U32 id; LPTSTR resourceID; } sgCursorShapeMap[]= 36{ 37 { PlatformCursorController::curArrow, IDC_ARROW }, 38 { PlatformCursorController::curWait, IDC_WAIT }, 39 { PlatformCursorController::curPlus, IDC_CROSS }, 40 { PlatformCursorController::curResizeVert, IDC_SIZEWE }, 41 { PlatformCursorController::curResizeHorz, IDC_SIZENS }, 42 { PlatformCursorController::curResizeAll, IDC_SIZEALL }, 43 { PlatformCursorController::curIBeam, IDC_IBEAM }, 44 { PlatformCursorController::curResizeNESW, IDC_SIZENESW }, 45 { PlatformCursorController::curResizeNWSE, IDC_SIZENWSE }, 46 { PlatformCursorController::curHand, IDC_HAND }, 47 { PlatformCursorController::curWaitArrow, IDC_WAIT }, 48 { PlatformCursorController::curNoNo, IDC_NO }, 49}; 50 51//static const EnumTable::Enums curManagerShapesEnums[] = 52//{ 53// { Win32CursorController::curArrow, "Arrow" }, 54// { Win32CursorController::curWait, "Wait" }, 55// { Win32CursorController::curPlus, "Plus" }, 56// { Win32CursorController::curResizeVert, "ResizeVert" }, 57// { Win32CursorController::curResizeHorz, "ResizeHorz" }, 58// { Win32CursorController::curResizeAll, "ResizeAll" }, 59// { Win32CursorController::curIBeam, "ibeam" }, 60// { Win32CursorController::curResizeNESW, "ResizeNESW" }, 61// { Win32CursorController::curResizeNWSE, "ResizeNWSE" }, 62//}; 63// 64//static const EnumTable gCurManagerShapesTable(8, &curManagerShapesEnums[0]); 65 66// CodeReview I've duplicated this 'cache' trick for system settings 67// because they're unlikely to change and calling into the OS for values 68// repeatedly is just silly to begin with. [6/29/2007 justind] 69U32 Win32CursorController::getDoubleClickTime() 70{ 71 static S32 sPlatWinDoubleClicktime = -1; 72 if( sPlatWinDoubleClicktime == -1 ) 73 sPlatWinDoubleClicktime = GetDoubleClickTime(); 74 return sPlatWinDoubleClicktime; 75} 76S32 Win32CursorController::getDoubleClickWidth() 77{ 78 static S32 sPlatWinDoubleClickwidth = -1; 79 if( sPlatWinDoubleClickwidth == -1 ) 80 sPlatWinDoubleClickwidth = GetSystemMetrics(SM_CXDOUBLECLK); 81 return sPlatWinDoubleClickwidth; 82} 83S32 Win32CursorController::getDoubleClickHeight() 84{ 85 static S32 sPlatWinDoubleClickheight = -1; 86 if( sPlatWinDoubleClickheight == -1 ) 87 sPlatWinDoubleClickheight = GetSystemMetrics(SM_CYDOUBLECLK); 88 return sPlatWinDoubleClickheight; 89} 90 91void Win32CursorController::setCursorPosition( S32 x, S32 y ) 92{ 93 ::SetCursorPos(x, y); 94} 95 96void Win32CursorController::getCursorPosition( Point2I &point ) 97{ 98 POINT rPoint; 99 ::GetCursorPos( &rPoint ); 100 101 // Return 102 point.x = rPoint.x; 103 point.y = rPoint.y; 104} 105 106void Win32CursorController::setCursorVisible( bool visible ) 107{ 108 if( visible ) 109 ShowCursor( true ); 110 else 111 while( ShowCursor(false) >= 0 ); 112} 113 114bool Win32CursorController::isCursorVisible() 115{ 116 CURSORINFO rCursorInfo; 117 rCursorInfo.cbSize = sizeof(CURSORINFO); 118 if( !GetCursorInfo( &rCursorInfo ) ) 119 { 120 //DWORD error = GetLastError(); 121 return false; 122 } 123 124 // rCursorInfo.flags values : 125 // 0 == Cursor is hidden 126 // CURSOR_SHOWING == cursor is visible 127 return (bool)(rCursorInfo.flags == CURSOR_SHOWING); 128} 129 130void Win32CursorController::setCursorShape(U32 cursorID) 131{ 132 LPTSTR resourceID = NULL; 133 134 for(S32 i = 0; i < numPlatformCursors; ++i) 135 { 136 if(cursorID == sgCursorShapeMap[i].id) 137 { 138 resourceID = sgCursorShapeMap[i].resourceID; 139 break; 140 } 141 } 142 143 if(resourceID == NULL) 144 return; 145 146 HCURSOR cur = LoadCursor(NULL, resourceID); 147 if(cur) 148 SetCursor(cur); 149} 150 151static HCURSOR gCursorShape = NULL; 152void Win32CursorController::setCursorShape( const UTF8 *fileName, bool reload ) 153{ 154#ifdef UNICODE 155 const UTF16 *lFileName = createUTF16string( fileName ); 156#else 157 const UTF8 *lFileName = fileName; 158#endif 159 160 if ( !gCursorShape || reload ) 161 gCursorShape = LoadCursorFromFile( lFileName ); 162 163 if ( gCursorShape ) 164 SetCursor( gCursorShape ); 165 166#ifdef UNICODE 167 delete[] lFileName; 168#endif 169} 170 171// Console function to set the current cursor shape given the cursor shape 172// name as defined in the enum above. 173//ConsoleFunction( inputPushCursor, void, 2, 2, "inputPushCursor(cursor shape name)" ) 174//{ 175// S32 val = 0; 176// 177// // Find the cursor shape 178// if(argc == 2) 179// { 180// for (S32 i = 0; i < gCurManagerShapesTable.size; i++) 181// { 182// if (! dStricmp(argv[1], gCurManagerShapesTable.table[i].label)) 183// { 184// val = gCurManagerShapesTable.table[i].index; 185// break; 186// } 187// } 188// } 189// 190// // Now set it 191// Win32CursorController* cm = Input::getCursorManager(); 192// if(cm) 193// { 194// cm->pushCursor(val); 195// } 196//} 197//// Function to pop the current cursor shape 198//ConsoleFunction( inputPopCursor, void, 1, 1, "inputPopCursor()" ) 199//{ 200// argc; 201// argv; 202// 203// Win32CursorController* cm = Input::getCursorManager(); 204// if(cm) 205// { 206// cm->popCursor(); 207// } 208//} 209