mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-30 07:35:59 +00:00
Changed: #947 fixed mouse position setting on non main monitor
This commit is contained in:
parent
b939982a97
commit
9cd04ec436
1 changed files with 11 additions and 31 deletions
|
@ -388,43 +388,23 @@ void showCursor(bool b)
|
||||||
|
|
||||||
void setMousePos(float x, float y)
|
void setMousePos(float x, float y)
|
||||||
{
|
{
|
||||||
/*
|
// CG wants absolute coordinates related to first screen's top left
|
||||||
TODO FIXME for windows placed on non primary monitor
|
|
||||||
*/
|
|
||||||
|
|
||||||
// CG wants absolute coordinates related to screen top left
|
// get the first screen's (conaints menubar) rect (this is not mainScreen)
|
||||||
CGFloat fromScreenLeft = 0.0;
|
NSRect firstScreenRect = [[[NSScreen screens] objectAtIndex:0] frame];
|
||||||
CGFloat fromScreenTop = 0.0;
|
|
||||||
|
// get the rect (position, size) of the window
|
||||||
|
NSRect windowRect = [g_window frame];
|
||||||
|
|
||||||
// get the gl view's rect for height and width
|
// get the gl view's rect for height and width
|
||||||
NSRect viewRect = [g_glview frame];
|
NSRect viewRect = [g_glview frame];
|
||||||
|
|
||||||
// if the view is not fullscreen, window top left is needed as offset
|
// set the cursor position
|
||||||
if(![g_glview isInFullScreenMode])
|
|
||||||
{
|
|
||||||
// get the rect (position, size) of the screen
|
|
||||||
NSRect screenRect = [[g_window screen] frame];
|
|
||||||
|
|
||||||
// get the rect (position, size) of the window
|
|
||||||
NSRect windowRect = [g_window frame];
|
|
||||||
|
|
||||||
// window's x is ok
|
|
||||||
fromScreenLeft = windowRect.origin.x;
|
|
||||||
|
|
||||||
// TODO this code assumes, that the view fills the window
|
|
||||||
|
|
||||||
// map window bottom to view top
|
|
||||||
fromScreenTop = screenRect.size.height -
|
|
||||||
viewRect.size.height - windowRect.origin.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// position inside the view
|
|
||||||
fromScreenLeft += (viewRect.size.width * x);
|
|
||||||
fromScreenTop += (viewRect.size.height * (1 - y));
|
|
||||||
|
|
||||||
// actually set the mouse position
|
|
||||||
CGDisplayErr error = CGDisplayMoveCursorToPoint(
|
CGDisplayErr error = CGDisplayMoveCursorToPoint(
|
||||||
kCGDirectMainDisplay, CGPointMake(fromScreenLeft, fromScreenTop));
|
kCGDirectMainDisplay, CGPointMake(
|
||||||
|
windowRect.origin.x + (viewRect.size.width * x),
|
||||||
|
firstScreenRect.size.height - windowRect.origin.y -
|
||||||
|
viewRect.size.height + ((1.0 - y) * viewRect.size.height)));
|
||||||
|
|
||||||
if(error != kCGErrorSuccess)
|
if(error != kCGErrorSuccess)
|
||||||
nlerror("cannot set mouse position");
|
nlerror("cannot set mouse position");
|
||||||
|
|
Loading…
Reference in a new issue