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

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


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


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


  • Follow-Ups:
    • Re: mouseDown Event Position Accuracy (was: NSString drawAtPoint and vertical font alignment)
      • From: Steven Degutis <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>)

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