[Drawkit] Minor fix for text selection in DrawDemo

Graham Cox graham.cox at bigpond.com
Wed Oct 29 14:39:07 PDT 2008


Hi Brad, Thanks for that, I'll pass it on to Daniel Jalkut, who wrote  
it. Funnily enough I had already flagged up this problem to him but  
neither of us had the time to work out a fix, so it'll be nice to be  
able to pass this along as well as fix up the demo (and my app, which  
also has the same problem).

cheers, Graham



On 30 Oct 2008, at 4:03 am, Brad Larson wrote:

> I had lifted some code from the DrawDemo application to add an  
> inspector to our drawing program when I noticed that one of the text  
> cells wasn't properly responding to mouse selection of the text.  In  
> the drawing layer inspector, the custom  
> RSVerticallyCenteredTextFieldCell is used to provide vertically  
> aligned text within the layer table.  However, the hit testing in  
> that custom cell is still using the traditional top-aligned text  
> location, which causes some frustration when you're trying to edit  
> the cell.
>
> To fix this, you can add the following to  
> RSVerticallyCenteredTextFieldCell's implementation:
>
> - (NSUInteger)hitTestForEvent:(NSEvent *)event inRect: 
> (NSRect)cellFrame ofView:(NSView *)controlView
> {
> 	NSRect newRect = [super drawingRectForBounds:cellFrame];
>
> 	// Get our ideal size for current text
> 	NSSize textSize = [self cellSizeForBounds:cellFrame];
> 	
> 	// Center that in the proposed rect
> 	float heightDelta = newRect.size.height - textSize.height;	
> 	if (heightDelta > 0)
> 	{
> 		newRect.size.height -= heightDelta;
> 		newRect.origin.y += (heightDelta / 2);
> 	}
> 	
> 	return [super hitTestForEvent:event inRect:newRect  
> ofView:controlView];
> }
>
> This is not strictly DrawKit-related, but it does affect the  
> DrawDemo sample application.



More information about the Drawkit mailing list