Re: Hit-detection via NSApp's -sendEvent:
Re: Hit-detection via NSApp's -sendEvent:
- Subject: Re: Hit-detection via NSApp's -sendEvent:
- From: "Michael Ash" <email@hidden>
- Date: Fri, 28 Jul 2006 21:42:10 -0400
On 7/28/06, Keith Blount <email@hidden> wrote:
Hello,
My app has a full screen mode with a tool bar at the
bottom much like the one in iPhoto (or like the Dock
when it is set to hide): if the user places the mouse
at the bottom of the screen, the tool bar pops up;
moving the cursor above 100 pixels from the bottom
causes it to disappear again. Although I looked in to
doing this via tracking rects or via -mouseMoved
events, I eventually decided that the best way of
doing this would be to trap NSMouseMoved events in
-sendEvent: of my NSApplication subclass. I know this
sounds an odd way of doing it, but the problem is that
my app can have other panels shown over the top of the
full screen window that can become key, and the tool
panel should show even if the mouse is dropped to the
bottom of the screen while one of these other panels
has become key.
Anyway, everything works fine until it comes to a
multi-screen set up. Even then, if my program is run
in full screen on the first monitor of a dual screen
set up, everything is fine. The problems occur when my
program is run in full screen on a second or third
screen. In this event, my beta testers inform me, the
tool bottom that should appear at the bottom of the
screen does not. From various tests, we have
established that the problem occurs in my -sendEvent:
subclass code (unfortunately I do not have access to a
dual monitor set up at the moment and so have to rely
on beta testers). This is the relevant code for my hit
testing in my NSApplication subclass:
- (void)sendEvent:(NSEvent *)anEvent
{
SCRMainDocument *mainDocument =
[[NSDocumentController sharedController]
currentDocument];
if ([mainDocument isFullScreen]) // BOOL returned
from mainDocument which works fine
{
if ([anEvent type] == NSMouseMoved &&
NSPointInRect([NSEvent mouseLocation],[[mainDocument
fullScreenWindow] frame]))
{
float cursorHeight = [NSEvent mouseLocation].y;
if (cursorHeight <= 1.0)
[self sendMessageToFullScreenToShowToolsPanel];
else if (cursorHeight > 100.0)
[self sendMessageToFullScreenToHideToolsPanel];
}
}
[super sendEvent:anEvent];
}
If your window is on some other screen, then the origin of its frame
will not be at 0,0. This means that the mouse could be over the bottom
of your window, and yet cursorHeight, being in screen coordinates,
will not be near 0.
To solve this, use [anEvent locationInWindow], or manually transform
[NSEvent mouseLocation] to window coordinates using NSWindow's
convertScreenToBase: method. Then you'll have window-relative
coordinates that you can compare nicely.
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden