View Full Version : Mouse Position In Fullscreen...
thaeez
2004.11.03, 09:52 PM
I am having a lot of troule getting the mouse position when in fullscreen. I am using CoreGraphics to capture the display (and switch to a new resolution) with a custom run loop that handles mouseMotion, mouseUp, keyDown, etc. events for my app.
When in windowed mode, I can easily get the location of the mouse (for mouse clicks, rollover buttons, etc.) using:
[[_myCustomOpenGLView window] mouseLocationOutsideOfEventStream];
This does not work in fullscreen (ie. it gives inaccurate positions).
I've also tried to use:
[_myCustomOpenGLView convertPoint: fromView:]
[NSEvent mouseLocation]
and [theEvent locationInWindow]
but they all give the wrong position. It seems like the convertPoint method should help me but I can't get it to do anything useful...
What am I doing wrong!? Is my custom event loop not notifying the system of something that it needs to get the mouse position? Is CoreGraphics the problem? I am on a tight time schedule and am starting to panic a bit about this so any help or suggestions would be really appreciated.
thaeez
OneSadCookie
2004.11.03, 09:56 PM
NSScreen doesn't update when the screen is captured, so the mouse positions returned are correct for the old resolution, not the new.
You can look in the SDL source code for a way to hack NSScreen, or you can use a CoreGraphics function to get the mouse location.
arekkusu
2004.11.03, 10:14 PM
Untima converted the mouse location using the size of the screen and the fullscreen resolution, like this
- (void) mouseDown:(NSEvent*)event {
NSPoint loc = [event locationInWindow];
if (!fullscreen) {
loc = [self convertPoint:loc fromView:nil];
//NSLog(@"viewport win mouse down: %@: (%f, %f)", event, loc.x, loc.y);
}
else {
loc.y = (screendim.size.height - loc.y + fulldim.origin.y);
loc.x -= (fulldim.origin.x);
//NSLog(@"viewport full mouse down: %@: (%f, %f)", event, loc.x, loc.y);
//NSLog(@"viewport full size %f %f %f %f", fulldim.origin.x, fulldim.origin.y, fulldim.size.width, fulldim.size.height);
//NSLog(@"viewport scrn size %f %f %f %f", screendim.origin.x, screendim.origin.y, screendim.size.width, screendim.size.height);
}
<process event...>
But CoreGraphics is probably easier.
thaeez
2004.11.03, 10:49 PM
Thanks for the replys - what CoreGraphics functions do you mean (all I could find was CGGetLastMouseDelta which is probably not going to help much)?
And jsut to clarify, arekkusu what is the difference between fulldim and screendim (Is fulldim the new screen size and screenDim the old or viseVersa?)
Thanks again,
thaeez
OneSadCookie
2004.11.04, 02:22 AM
wow, you're right. I could have sworn there was a CG function to get the mouse position, but it seems that any such function is at least private. Guess you're stuck with the Cocoa mess or a Carbon call then...
arekkusu
2004.11.05, 06:25 AM
CGGetLastMouseDelta works fine in the case where you're doing your own cursor management (textured GL quad...) but no, there's no CG function to poll the current mouse position. You might try Carbon's GetMouse but I'm not sure how well that works with fullscreen GL contexts.
Otherwise, you can fudge the coordinates like I did. fulldim = the fullscreen resolution. screendim = the original screen resolution. Also, I found that code didn't work under 10.2 with CGDisplayCapture, but it did with CGCaptureAllDisplays. Not an issue under 10.3 since CGDisplayCapture isn't supported any more.
thaeez
2004.11.05, 05:38 PM
Thanks again for the replys, I found a NSScreen hack that adds an accessor to the NSScreen frame - anyways, I have it working fine like this:
mousePoint = [theEvent locationInWindow];
mousePoint.x += [[theEvent window] frame].origin.x;
mousePoint.y += [[theEvent window] frame].origin.y;
But before the above code will work, you have to do the NSScreen hack:
@implementation NSScreen (NSScreenAccess)
- (void) setFrame: (NSRect) frame
{
_frame = frame;
}
and call the following whenever you switch to FS:
NSRect screenRect = NSMakeRect(0, 0, contextWidth, contextHeight);
[[NSScreen mainScreen] setFrame: screenRect];
thaeez
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.