[Drawkit] Styling line end caps
Brad Larson
larson at sonoplot.com
Mon Jun 23 15:03:41 PDT 2008
Thanks for the pointer. For the record, I was able to achieve what I
wanted using
DKStyle* featureStyle = [[DKStyle alloc] init];
DKFill* featureFill = [DKFill fillWithColour:[[NSColor blackColor]
colorWithAlphaComponent:0.25]];
[featureStyle addRenderer:featureFill];
DKStroke* featureStroke = [DKStroke strokeWithWidth:lineWidth colour:
[NSColor blackColor]];
[featureStroke setLineCapStyle:NSRoundLineCapStyle];
[featureStroke setLineJoinStyle:NSRoundLineJoinStyle];
[featureStyle addRenderer:featureStroke];
and then a
[currentPath setStyle:featureStyle];
on the desired paths.
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.
On May 29, 2008, at 6:15 PM, Graham Cox wrote:
> The end cap is set up as a property of the DKStroke rasterizer,
> which is part of the style. The end cap set on the object's path
> will have no effect as the style takes priority.
>
> Depending on how you are setting up the style, you'll need to grab
> the DKStroke component and set the line cap parameter there.
>
>
> cheers, Graham
>
>
>
>
> On 30 May 2008, at 8:08 am, Brad Larson wrote:
>
>> How do you style line end caps? I don't see an entry in DKStyle
>> for them. Other places in the framework, lines are styled by
>> styling the underlying NSBezierPath, but when I try
>>
>> [currentBezierPath moveToPoint:point1];
>> [currentBezierPath lineToPoint:point2];
>> [currentBezierPath setLineCapStyle:NSRoundLineCapStyle];
>> DKDrawablePath* currentPath = [[DKDrawablePath alloc]
>> initWithBezierPath:currentBezierPath];
>>
>> during the programmatic generation of a path, the path does not
>> seem to use the rounded cap style. I'm just starting to get into
>> the styles, so there may be something I'm missing.
>
> _______________________________________________
> 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