View Full Version : mouse location woes
kelvin
2002.11.29, 11:48 PM
In Cocoa I used
newMode = CGDisplayBestModeForParameters(kCGDirectMainDispla y, 24, width, height, 0);
CGDisplaySwitchToMode(kCGDirectMainDisplay, newMode);
to change to a full screen context.
How do I get the mouse location on the screen?
When I do:
NSPoint mouseLoc = [NSEvent mouseLocation];
I get a Point that is x pixels too high, where x is the old screen height - the new screen height + 1. (289 in my case 768-480+1)
Does anyone know a fix or another way to get the mouse location?
(I don't have a nsview or nswindow btw, as I am drawing direct to the screen.)
geezusfreeek
2002.11.29, 11:54 PM
I don't know what the problem is with the way you're doing it, but, just in case this may work for your purposes, this returns the mouse position change associated with the last mouse move event received by this application.
void CGGetLastMouseDelta(
CGMouseDelta * deltaX,
CGMouseDelta * deltaY );
I'd love to find a cleaner way than:
NSPoint mouseLoc;
Point carbonPoint;
GetMouse( &carbonPoint );
mouseLoc.x = carbonPoint.h;
mouseLoc.y = [ self bounds ].size.height - carbonPoint.v;
but when in full screen, this is the best I've found. Of course, if you just need deltas, geezusfreeek's method is the way to go.
OneSadCookie
2002.11.30, 12:54 AM
I seem to recall that there's a bug in the communication between CGDirectDisplay and NSScreen. I think there's a (hack) fix which involves playing directly with NSScreen's internals.
Personally, if I was already using CG for full-screen, I'd probably be tempted to use CG to get the mouse movement, as others have suggested. Just store the mouse's current position, and manually update it by calling CGGetLastMouseDelta or whatever it's called when you receive a mouse moved event.
wally
2002.12.06, 07:50 PM
Originally posted by OneSadCookie
I seem to recall that there's a bug in the communication between CGDirectDisplay and NSScreen. I think there's a (hack) fix which involves playing directly with NSScreen's internals.
And here's the hack (from SDL)
/*
Add methods to get at private members of NSScreen.
Since there is a bug in Apple's screen switching code
that does not update this variable when switching
to fullscreen, we'll set it manually (but only for the
main screen).
*/
@interface NSScreen (NSScreenAccess)
- (void) setFrame:(NSRect)frame;
@end
@implementation NSScreen (NSScreenAccess)
- (void) setFrame:(NSRect)frame;
{
_frame = frame;
}
@end
Now, when you set the new resolution, use this:
NSRect screen_rect = NSMakeRect(0,0,width,height);
[ [ NSScreen mainScreen ] setFrame:screen_rect ];
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.