Re: Mouse position from NSEvent starts at (0, 1) ?
Re: Mouse position from NSEvent starts at (0, 1) ?
- Subject: Re: Mouse position from NSEvent starts at (0, 1) ?
- From: Henry McGilton <email@hidden>
- Date: Mon, 21 May 2007 16:09:07 -0700
On May 15, 2007, at 12:30 PM, Mathieu Coursolle wrote:
Hi cocoa developers,
I created a subclass of NSView to draw a 1 pixel thick cross at the
mouse cursor position. However, the cross is offset by one pixel in
the
Y direction.
In the mouseDragged: method, I use the following code to get the view
coordinates:
NSPoint pt = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
Then in drawRect: I draw a cross at that position like so:
- (void)drawRect:(NSRect)rect
{
// Gray background.
[[NSColor colorWithCalibratedRed:0.2 green:0.2 blue:0.2 alpha:
0.2] set];
[NSBezierPath fillRect:[self bounds]];
// Red cross.
[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:
1.0] set];
[NSBezierPath fillRect:NSMakeRect(x, y-100, 1, 200)];
[NSBezierPath fillRect:NSMakeRect(x-100, y, 200, 1)];
}
It seems like the cross is drawn at the position I ask for, but the
mouse cursor position I get is offset.
When I click the bottom left pixel of the view, I get (0, 1)
coordinates
(pt in code above). Shouldn't it be (0, 0)? I have to draw at (0,
0) to
draw that pixel.
I came across an old post describing exactly the same problem:
<http://www.omnigroup.com/mailman/archive/macosx-dev/2000-March/
013028.html>
I can solve the problem by doing something like:
pt.y = pt.y - 1;
but I would like to have an explanation for this. ;)
As far as I know, this is a genuine bug in the Window Server.
I filed a bug on this in June 2003:
Bug ID# 3149337: NSEvent Problem --- Can Not Move Mouse To
Lowest Y Pixel of Screen
I received a very strange response from Apple bug tracking
on 1st July 2003.
The first sentence of the response stated that this behaviour
is 'by design' --- that is, the system is intended to work that
way.
The rest of the response appeared to agree with my contention
that having x coordinates going from 0 to width - 1 but y
coordinates going from 1 to height seemed inconsistent, but
then went on to say the behaviour is consistent.
I have to assume that this bug will never be fixed.
You can check your code by temporarily taking out your fix and
then comparing your application against Pixie, which reports the
bottom pixel of the screen as 0, and if your application is
anything like mine --- sounds like it, as I was doing exactly the
same thing, namely, drawing a cross-hair at the mouse
position --- you should see your application reporting Y as
1 when Pixie reports Y as 0.
Perhaps there is somebody at Apple who could provide the
straight guff on this topic . . .
Cheers,
........ Henry
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden | http://www.trilithon.com
|
===============================+============================
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden