• 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: mouseDown Event Position Accuracy (was: NSString drawAtPoint and vertical font alignment)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mouseDown Event Position Accuracy (was: NSString drawAtPoint and vertical font alignment)


  • Subject: Re: mouseDown Event Position Accuracy (was: NSString drawAtPoint and vertical font alignment)
  • From: Stephen Blinkhorn <email@hidden>
  • Date: Mon, 7 Sep 2009 10:52:21 -0600

Astonishing... that is the problem. I thought the default hot spot for the default cursor would be the tip of the arrow. Obviously not. OK, custom cursors it is then.

Many thanks,
Stephen

On 7 Sep 2009, at 10:24, Steven Degutis wrote:

Stephen,

The most obvious reason that comes to mind, is that your cursor's exact point is not located on the exact top of the default + [NSCursor arrowCursor]. It's actually located a little lower. Try changing your cursor to the crosshair cursor, or a custom cursor if you'd prefer, and see if it is acting "as expected" at that point, by appearing to register clicks inside the bounds and not outside.

--
Steven Degutis
http://www.thoughtfultree.com/
http://www.degutis.org/


On Mon, Sep 7, 2009 at 11:19 AM, Stephen Blinkhorn <email@hidden > wrote:


On 7 Sep 2009, at 01:09, Quincey Morris wrote:

On Sep 6, 2009, at 23:38, Stephen Blinkhorn wrote:

I make a custom view (really a NSControl subclass) and I use a place holder in IB to position it on screen. I also set it's size to be say 50 wide by 22 high.

If I draw the view by simply filling the rect returned by [self bounds] then it looks fine and in the same place as the IB placeholder. However, the view responds to mouse events outside of its visual frame at the top edge and only registers mouse events inside the bottom edge once the cursor is about 3-4 pixels inside the frame. Whilst only small the inaccuracy feels very wrong after a while.

I don't understand is the mouse event part. I am filling the bounds rectangle via NSRectFill but mouse events visibly outside the filled rectangle are apparently happening inside the bounds rectangle. I use this to get the event position:

NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil];

There's not enough information here to suggest an answer. Is there a placeholder view that you *replace* with a NSControl subclass? Is this a subclass of NSControl directly, or of a specific control (e.g. NSButton)?

I am using a direct subclass of NSControl. I create a CustomView placeholder in IB and assign it to my custom control class.

You'll probably need to post some code to get an answer, but it's not even clear which code.

I'd suggest you start by putting a breakpoint on the line after the line you showed above, and then start poking around the view hierarchy until you find out what numbers aren't what you expect them to be. It could be a coordinate system snafu, or it could be something more intimately related to control behavior.

Everything looks OK in the debugger. I have managed to whittle the code down to this tiny test case. Presented like this it looks like I'm needlessly fussing over a 3 pixel area at the bottom of the view that doesn't respond to mouse events but with medium and small sized controls and switches those 3 pixels become relevant :)

Thanks again,
Stephen


#import <Cocoa/Cocoa.h>

@interface AS_TestControl : NSControl <NSCoding>
{
       NSRect                          viewRect;
       BOOL                            selected;
}

@end


#import "AS_TestControl.h"

@implementation AS_TestControl

-(id)initWithCoder:(NSCoder*)coder
{
       if (self = [super initWithCoder:coder])
       {
               selected = NO;
       };
       return self;
}

-(void)encodeWithCoder:(NSCoder*)coder
{
       [super encodeWithCoder:coder];
}

-(void)dealloc
{
       [super dealloc];
}

-(BOOL)isFlipped
{
       return NO;
}

+(Class)cellClass
{
       return [NSActionCell class];
}


#pragma mark Drawing

- (void)drawRect:(NSRect)rect
{
       if(selected == YES) {
               [[NSColor greenColor] set];
       } else {
               [[NSColor blackColor] set];
       };

       NSRectFill([self bounds]);
}


#pragma mark Events

-(void)mouseDown:(NSEvent*)theEvent
{
NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil];
if(NSPointInRect(p, [self bounds])) {
selected = YES;
[self setNeedsDisplay:YES];
};
}


-(void)mouseUp:(NSEvent*)theEvent
{
       selected = NO;
       [self setNeedsDisplay:YES];
}

@end


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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)

Please 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: 
 >NSString drawAtPoint and vertical font alignment (From: Stephen Blinkhorn <email@hidden>)
 >Re: NSString drawAtPoint and vertical font alignment (From: Quincey Morris <email@hidden>)
 >Re: NSString drawAtPoint and vertical font alignment (From: Stephen Blinkhorn <email@hidden>)
 >Re: NSString drawAtPoint and vertical font alignment (From: Quincey Morris <email@hidden>)
 >Re: NSString drawAtPoint and vertical font alignment (From: Stephen Blinkhorn <email@hidden>)
 >Re: NSString drawAtPoint and vertical font alignment (From: Quincey Morris <email@hidden>)
 >mouseDown Event Position Accuracy (was: NSString drawAtPoint and vertical font alignment) (From: Stephen Blinkhorn <email@hidden>)
 >Re: mouseDown Event Position Accuracy (was: NSString drawAtPoint and vertical font alignment) (From: Steven Degutis <email@hidden>)

  • Prev by Date: Re: Making an NSAlert be displayed when the User attempts to delete a row from an NSOutlineView when it has children.
  • Next by Date: Re: Sending the "value" message to an object typed "id"
  • Previous by thread: Re: mouseDown Event Position Accuracy (was: NSString drawAtPoint and vertical font alignment)
  • Next by thread: Re: Does Mac OS X support interior pointers?
  • Index(es):
    • Date
    • Thread