[Drawkit] Hit testing at high scale factor
Graham Cox
graham.cox at bigpond.com
Mon Jun 30 21:28:20 PDT 2008
Indeed, this code is incorrect. I have changed it to:
- (NSRect) bounds
{
// get the true knob size so we can factor that in accurately
NSRect kr = [[[self layer] knobs] controlKnobRectAtPoint:NSZeroPoint
ofType:kDKOnPathKnobType];
float kbs = kr.size.width * 0.5f;
NSRect r = NSInsetRect( [[self renderingPath] controlPointBounds], -
kbs, -kbs );
// factor in style allowance
NSSize allow = [self extraSpaceNeeded];
r = NSInsetRect( r, -allow.width, -allow.height );
return r;
}
It needs to factor in the size of the knobs so they are always within
the bounds, but should not assume their size since it varies with view
scale. This code still makes the assumption that the knobs are the
same size regardless of type, but that is true for a path object.
cheers, Graham
On 1 Jul 2008, at 10:05 am, Brad Larson wrote:
> In terms of the overlarge bounds that were being returned, I saw
> this in DKDrawablePath:
>
> - (NSRect) bounds
> {
> NSRect r = NSInsetRect( [[self renderingPath] controlPointBounds],
> -3, -3 );
>
> which would make the bounds wider and taller by 6.0 points, the size
> difference I'm seeing. What does this provide cushioning for in the
> path: the knobs? Later on in the bounds method, it looks like the
> width of the style is taken into account. In any case, it's an
> absolute value, not a scaled one. Converting this to be
>
> NSRect r = [[self renderingPath] controlPointBounds];
>
> fixes the selection rectangle issues that I was seeing with my
> custom point subclass of DKDrawablePath, as well as the
> DKDrawablePath lines I'm using.
More information about the Drawkit
mailing list