Mouse Position In Fullscreen...

thaeez
Unregistered
 
Post: #1
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
Untima converted the mouse location using the size of the screen and the fullscreen resolution, like this
Code:
- (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.
Quote this message in a reply
thaeez
Unregistered
 
Post: #4
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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...
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
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.
Quote this message in a reply
thaeez
Unregistered
 
Post: #7
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SDL. Current music position e40pud 0 2,303 Mar 9, 2010 08:46 AM
Last Post: e40pud
  Tip: Fullscreen mouse event gotcha Fenris 3 3,152 Feb 13, 2006 07:41 PM
Last Post: AnotherJake
  Mouse coordinates in fullscreen TomorrowPlusX 9 5,763 Aug 26, 2005 09:03 PM
Last Post: arekkusu
  Object position after rotation charon 11 6,816 Mar 2, 2005 11:33 AM
Last Post: hangt5
  Put a Auto-cam in Top Position alert 5 4,079 Dec 15, 2004 05:37 AM
Last Post: Fenris