• 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
Re: Mouse position from NSEvent starts at (0, 1) ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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

However, I experience the offset for every mouse positions.

I am always drawing the cross one pixel too far in the Y direction.

Thanks.

>I'd say it is a rounding issue...
>the mouse might be at 0.7!?
>
>On May 15, 2007, at 9: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. ;)
>>
>> 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
>>
>
>


_______________________________________________

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

References: 
 >Mouse position from NSEvent starts at (0, 1) ? (From: "Mathieu Coursolle" <email@hidden>)
 >Re: Mouse position from NSEvent starts at (0, 1) ? (From: Dominik Pich <email@hidden>)

  • Prev by Date: Re: Mouse position from NSEvent starts at (0, 1) ?
  • Next by Date: Re: US/non-US localization problem
  • Previous by thread: Re: Mouse position from NSEvent starts at (0, 1) ?
  • Next by thread: Re: Mouse position from NSEvent starts at (0, 1) ?
  • Index(es):
    • Date
    • Thread