Removing or ignoring "lineWidth" property of an NSBezierPath instance
Removing or ignoring "lineWidth" property of an NSBezierPath instance
- Subject: Removing or ignoring "lineWidth" property of an NSBezierPath instance
- From: Tobias Zimmerman <email@hidden>
- Date: Wed, 22 Apr 2009 17:19:22 -0400
- Thread-topic: Removing or ignoring "lineWidth" property of an NSBezierPath instance
I am trying to find a way to ensure that a series of NSBezierPaths are drawn
using [NSBezierPath defaultLineWidth] value. However, contrary to
documentation and expectation, my paths seem to automatically assign
themselves the value 1.0 for their own lineWidth property.
First, the documentation for NSBezierPath¹s -(CGFloat)lineWidth method
states that: "If no value was set explicitly for the receiver, this method
returns the default line width." This suggests that a newly created
NSBezierPath should have no value set for lineWidth.
The following custom view class demonstrates the problem:
@interface AppView : NSView {
NSMutableArray *pathsToDraw;
}
@end
@implementation AppView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
pathsToDraw = [NSMutableArray array];
[pathsToDraw retain];
//Creates a series of 10 overlapping boxes stored in an array
CGFloat boxWidth = 15.0;
CGFloat boxHeight = 12.0;
for (int i = 0; i < 10; i++) {
NSBezierPath *newPath = [NSBezierPath
bezierPathWithRect:NSMakeRect(i * (boxWidth + 1.0), i * (boxHeight + 1.0), i
* boxWidth, i * boxHeight)];
[pathsToDraw addObject:newPath];
//Note, we never call [newPath setLineWidth], so none of the paths should
have its lineWidth property set
}
}
return self;
}
- (void)drawRect:(NSRect)rect {
[[NSColor blackColor] set];
//set default to an arbitrary number other than 1.0 This is the width we
want the paths to be drawn with.
[NSBezierPath setDefaultLineWidth:4.0];
for (NSBezierPath *path in pathsToDraw) {
/* The following line logs the specific and default line widths. Since we
never set any lineWidth for any of the paths in the array, these values
should be identical, or, at least that¹s what the documentation suggests.
*/
NSLog(@"Path width = %0.3f; default width = %0.3f", [path
lineWidth], [NSBezierPath defaultLineWidth]);
[path stroke];
}
// The following line proves that the defaultLineWidth class property of
NSBezierPath is functioning, as the resulting box is drawn at the correct
thickness
[NSBezierPath strokeRect:[self bounds]];
}
@end
The output from the NSLog statement is the following line (10 times):
> 2009-04-22 16:30:21.640 BezPathLineWidthTester[7347:10b] Path width = 1.000;
> default width = 4.000
Changing the value passed to [NSBezierPath setDefaultLineWidth:] has no
effect on the boxes drawn out of the array, although it does effect the
³anonymous² path created by the strokeRect command.
So, my question(s): is there a way to remove or ignore an NSBezierPath¹s
individual lineWidth property in favor of the default? (Note that setting
the individual path¹s lineWidth property to 0.0 will not work because a
lineWidth of 0.0 has a specific meaning to the drawing system. Since this
property is a float, it can¹t be set to nil). Is this indeed a bug (either
in NSBezierPath or in the documentation), or am I overlooking something?
(By way of further explanation, the project this arises in involves a set of
bezier paths that are generated in one program and archived for use in a
separate program. I would like the lineWidth and other drawing specifics
such as line/fill colors to be controlled by the view where the reusable
paths are drawn, rather than a property of the paths themselves).
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden