• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Mouse position from NSEvent starts at (0, 1) ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mouse position from NSEvent starts at (0, 1) ?


  • Subject: Mouse position from NSEvent starts at (0, 1) ?
  • From: "Mathieu Coursolle" <email@hidden>
  • Date: Tue, 15 May 2007 15:30:04 -0400
  • Organization: Rogue Research

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. ;)

Anyone can explain this behaviour?

Thank you.

Mathieu






_______________________________________________

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

  • Follow-Ups:
    • Re: Mouse position from NSEvent starts at (0, 1) ?
      • From: Henry McGilton <email@hidden>
    • Re: Mouse position from NSEvent starts at (0, 1) ?
      • From: Uli Kusterer <email@hidden>
    • Re: Mouse position from NSEvent starts at (0, 1) ?
      • From: Dominik Pich <email@hidden>
  • Prev by Date: RE: US/non-US localization problem
  • Next by Date: Re: US/non-US localization problem
  • Previous by thread: RE: US/non-US localization problem
  • Next by thread: Re: Mouse position from NSEvent starts at (0, 1) ?
  • Index(es):
    • Date
    • Thread