[Drawkit] Minor fix for text selection in DrawDemo
Brad Larson
larson at sonoplot.com
Wed Oct 29 18:54:57 PDT 2008
Don't worry about it. I already let him know.
On Oct 29, 2008, at 4:39 PM, Graham Cox wrote:
> 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.
>
> _______________________________________________
> Drawkit mailing list
> Drawkit at lists.apptree.net
> http://lists.apptree.net/listinfo.cgi/drawkit-apptree.net
______________________
Brad Larson
SonoPlot, Inc.
3030 Laura Lane, Suite 120
Middleton, WI 53562
More information about the Drawkit
mailing list