Game Development Community

T3D 1.1 Beta 3 - GuiCanvas::setCursorPos sets incorrect position - RESOLVED

by Dennis Trevillyan · in Torque 3D Professional · 03/27/2011 (8:32 am) · 3 replies

Build: Torque 3D 1.1 Beta 3 Pro

Platform: Windows XP SP3 32 bit

Target: calls to GuiCanvas::setCursorPos() during game execution with cursor on and not locked to screen.

Issues: setCursorPos sets position relative to display top left corner and not the canvas (game window) top left corner. Setting position (0,0) should be top left corner of canvas but is set at top left of display. Granted, when the cursor is not locked to the screen the platform cursor (Windows cursor) is being used. To further complicate matters if the cursor is locked to the screen then GuiCanvas::setCursorPos() does not actually set the cursor position. You need to directly set GuiCanvas::mCursorPt.

Steps to Repeat: Turn on mouse cursor and setup a mouse event in gameTSCtrl.cpp where a breakpoint can be created to see cursor position.

void GameTSCtrl::onMouseDown( const GuiEvent &evt) {
	Point2I p1(200, 300);
	getRoot()->setCursorPos(p1);
}

Suggested Fix: the following works for a cursor that is not locked. This is from the first reply to this forum thread www.garagegames.com/community/forums/viewthread/98433/1

void GuiCanvas::setCursorPos(const Point2I &pt)   
{
   AssertISV(mPlatformWindow, "GuiCanvas::setCursorPos - no window present!");
   POINT topleft;  
   topleft.x = 0;
   topleft.y = 0;

   Win32Window* w = dynamic_cast<Win32Window*>(mPlatformWindow);  
   
   if(w != NULL)  
      ClientToScreen(w->getHWND(), &topleft);  
  
   mPlatformWindow->setCursorPosition( topleft.x + pt.x, topleft.y + pt.y ); 
}

If the cursor is locked to the screen then use:

void GuiCanvas::setCursorPos(const Point2I &pt)   
{
   mCursorPt.x = S32( pt.x );
   mCursorPt.y = S32( pt.y );
}

Link to Console Log: None

#1
03/30/2011 (12:37 am)
I apparently never call setCursorPos so I can't test this right now, but this compiles:

void GuiCanvas::setCursorPos(const Point2I &pt)   
{
   AssertISV(mPlatformWindow, "GuiCanvas::setCursorPos - no window present!");

   Point2I topleft( 0, 0 );
   topleft = mPlatformWindow->getPosition();

   mPlatformWindow->setCursorPosition( topleft.x + pt.x, topleft.y + pt.y );
}
#2
03/31/2011 (10:58 am)
Logged as THREED-1538.
#3
05/06/2011 (5:28 pm)
Fixed in 1.1 Final.