Torque3D Documentation / _generateds / win32CursorController.cpp

win32CursorController.cpp

Engine/source/windowManager/win32/win32CursorController.cpp

More...

Public Variables

HCURSOR
LPTSTR
struct @169

Detailed Description

Public Variables

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