[Drawkit] Styling line end caps
Graham Cox
graham.cox at bigpond.com
Mon Jun 23 17:57:11 PDT 2008
Hi Brad,
I guess you could have a convenience constructor for almost
everything. The problem is where do you draw the line? I tend to
provide convenience constructors for the most obvious usage of an
object, (usually intended to get you started, or to accomplish a
common chore) but not for every single feature. In this case *my* view
is that caps and join styles are a relatively minor property, or
perhaps one that comes into play only once you've scratched the
surface and want to go a bit deeper. YMMV!
You can of course very easily add these types of convenience
constructors using a category.
cheers, Graham
On 24 Jun 2008, at 8:03 am, Brad Larson wrote:
> While this works just fine, there are convenience constructors for
> creating a DKStyle with a certain fill and line width. Maybe adding
> cap and join properties onto another DKStyle convenience constructor
> might make the process more intuitive. Something like
>
> + (DKStyle*) styleWithFillColour:(NSColor*) fc strokeColour:
> (NSColor*) sc strokeWidth:(float) sw strokeCapStyle:(NSLineCapStyle)
> cs strokeJoinStyle:(NSLineJoinStyle) js
> {
> if( fc == nil && sc == nil )
> [NSException raise:NSInvalidArgumentException format:@"bad
> argument to [DKStyle styleWithFillColour:strokeColour:] - both
> colours are nil"];
>
> DKStyle* style = [[DKStyle alloc] init];
>
> if ( fc )
> {
> DKFill* fill = [DKFill fillWithColour:fc];
> [style addRenderer:fill];
> }
>
> if ( sc )
> {
> DKStroke* stroke = [DKStroke strokeWithWidth:sw colour:sc];
> [stroke setLineCapStyle:cs];
> [stroke setLineJoinStyle:js];
> [style addRenderer:stroke];
> }
>
> return [style autorelease];
> }
>
> might do the trick. Anyway, just a suggestion.
More information about the Drawkit
mailing list