mouse location woes
In Cocoa I used
to change to a full screen context.
How do I get the mouse location on the screen?
When I do:
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.)
Code:
newMode = CGDisplayBestModeForParameters(kCGDirectMainDisplay, 24, width, height, 0);
CGDisplaySwitchToMode(kCGDirectMainDisplay, newMode);
How do I get the mouse location on the screen?
When I do:
Code:
NSPoint mouseLoc = [NSEvent mouseLocation];
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.)
---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
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.
Code:
void CGGetLastMouseDelta(
CGMouseDelta * deltaX,
CGMouseDelta * deltaY );
I'd love to find a cleaner way than:
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.
Code:
NSPoint mouseLoc;
Point carbonPoint;
GetMouse( &carbonPoint );
mouseLoc.x = carbonPoint.h;
mouseLoc.y = [ self bounds ].size.height - carbonPoint.v;
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.
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.
Quote: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)
Code:
/*
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
Code:
NSRect screen_rect = NSMakeRect(0,0,width,height);
[ [ NSScreen mainScreen ] setFrame:screen_rect ];
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
ending location from angle and speed | Kazooless | 5 | 6,913 |
Apr 3, 2009 02:40 PM Last Post: Gillissie |
|
polling mouse location? | alloca | 1 | 3,627 |
Jan 22, 2009 04:14 PM Last Post: ThemsAllTook |
|
Cocoa: Mouse location while dragging window | Fenris | 4 | 7,103 |
Jul 14, 2005 04:46 PM Last Post: Fenris |
|
Getting mouse location | Steven | 25 | 12,787 |
Aug 3, 2003 07:24 PM Last Post: OneSadCookie |
|
Setting the mouse location | Michael | 6 | 6,033 |
Jun 22, 2003 03:39 AM Last Post: reubert |