iDevGames Forums
Converting mouse coordinates in fullscreen context? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Converting mouse coordinates in fullscreen context? (/thread-7278.html)



Converting mouse coordinates in fullscreen context? - arekkusu - Feb 25, 2003 12:05 AM

(This is a Cocoa/CG question... I posted this to mac-opengl last week, no replies. So cross-posting here now in hopes of more eyes looking at it...)


I need to get the mouse coordinates in a fullscreen game context. Unrelated factors (minification, etc) have steered my event handling approach to:
1) controller is subclass of NSResponder, and implements mouseDown: etc for normal windowed mode.
2) window is created programatically and has the controller as nextResponder during windowed mode (for keystroke handling.)
3) window's first responder is swapped to the controller when in fullscreen mode, so all events (escape key, mouse) are caught. The event handler just passes relevant events to the normal mouseDown: etc handlers.

Here's my problem: in windowed mode I am getting sensible mouse coordinates via:

- (void) mouseDown:(NSEvent*)event{
NSPoint loc = [viewport convertPoint:[event locationInWindow] fromView:nil];
NSLog(@"mouse down (%@): (%f, %f)", event, loc.x, loc.y);
}

e.g. from (0,0) to (639,399) in a 640x400 window (although the resize widget obscures one corner, as expected.)

But, in a fullscreen context, 896x600 for example, the same function reports mouse coordinates from (0, -454) to (895, 145).
The vertical coordinates change depending on how big the (windowed mode) window is, but they always include some negative values.

Looking at the event, winNum is changing each time I enter fullscreen mode; I guess it's a temporary shielding window CG creates? How can I get the fullscreen window's coordinate system to make sense?

My view returns YES for isFlipped, if that makes any difference. The coordinates are totally screwed up when my fullscreen context is on a second display; they look more like global coordinates, as if convertPoint: hasn't done anything.

The convertPoint docs say:
"Converts aPoint from the coordinate system of aView to that of the receiver. If aView is nil, this method instead converts from window base coordinates. Both aView and the receiver must belong to the same NSWindow."

OK, so maybe my view is no longer in the right window after CG has taken over the screen with it's temporary shielding window, and that's my problem. If so, how do I fix it?


Converting mouse coordinates in fullscreen context? - OneSadCookie - Feb 25, 2003 01:52 AM

Why not use CoreGraphics to either get the mouse position directly, or get the deltas. Won't deltas be more use to you anyway?


Converting mouse coordinates in fullscreen context? - arekkusu - Feb 25, 2003 03:56 AM

Quote:Originally posted by OneSadCookie
Why not use CoreGraphics to either get the mouse position directly, or get the deltas.


Because I'd like to reuse all my code which is set up for normal window coordinates, and there *ought* to be a way to get the windowing system to treat the fullscreen GL context's dimensions as window coordinates.

Quote:Won't deltas be more use to you anyway?


No. I already have all my code for windowed mode expecting mousedown/up/drag events in window coordinates, not deltas.


So, can you suggest a way to translate the CG shielding window coordinates? I don't see any API to translate the CG window ID back into an NSWindow... or how to reassign the GL context to a different window once it's been set to fullscreen. Sad


Converting mouse coordinates in fullscreen context? - kelvin - Feb 25, 2003 11:20 AM

this problem was discussed here:thread 1461

my solution was this:
Code:
NSPoint mouseLoc = [NSEvent mouseLocation];
    CGRect screenBounds = CGDisplayBounds(kCGDirectMainDisplay);
    mouseLoc.y += screenBounds.size.height;
    mouseLoc.y -= ([[NSScreen mainScreen] frame].size.height + 1);

hope that helps


Converting mouse coordinates in fullscreen context? - arekkusu - Feb 26, 2003 02:40 AM

Quote:Originally posted by kelvin
this problem was discussed here:thread 1461


Ah, that is very good information, thanks.

Not what I wanted, but at least it is some confirmation (from OSC/wally) of a bug between CGDirectDisplay and NSScreen.

I ended up doing the conversion myself, similarly to how you show, except I have a flipped coordinate system and work with multiple displays.

-alex