Re: Hit-detection via NSApp's -sendEvent:
Re: Hit-detection via NSApp's -sendEvent:
- Subject: Re: Hit-detection via NSApp's -sendEvent:
- From: Keith Blount <email@hidden>
- Date: Tue, 1 Aug 2006 16:09:32 -0700 (PDT)
Many thanks for the reply (I've been away from my
computer or a couple of days so haven't been able to
thank you sooner :) ).
Unfortunately, I am still having the same problem. I
changed:
float cursorHeight = [NSEvent mouseLocation].y
to:
float cursorHeight = [[mainDocument fullScreenWindow]
mouseLocationOutsideOfEventStream].y;
This should return the mouse co-ordinates in the full
screen window's co-ordinates, which means that
checking that cursorHeight < 1.0 should work and cause
the tool panel to pop up when the cursor goes to the
bottom of the screen. However, it is still not
working.
Notably, this only fails when the second monitor is
smaller than the first one, so it does still seem to
be a co-ordinates issue...
Anyway, thanks for trying to help. If anyone can see
what I'm doing wrong, I would be very grateful.
Many thanks,
Keith
--- ORIGINAL MESSAGE ---
FROM : Michael Ash
DATE : Sat Jul 29 03:42:10 2006
On 7/28/06, Keith Blount <<email_removed>> 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 You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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