Added implementation for dashes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9967 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2001-05-18 20:58:27 +00:00
parent 7963aeece0
commit c0baa7afdb

View file

@ -43,6 +43,13 @@
static void flatten(NSPoint coeff[], float flatness, NSBezierPath *path); static void flatten(NSPoint coeff[], float flatness, NSBezierPath *path);
static Class NSBezierPath_concrete_class = nil; static Class NSBezierPath_concrete_class = nil;
static NSWindingRule default_winding_rule = NSNonZeroWindingRule;
static float default_line_width = 1.0;
static float default_flatness = 1.0;
static NSLineJoinStyle default_line_join_style = NSMiterLineJoinStyle;
static NSLineCapStyle default_line_cap_style = NSButtLineCapStyle;
static float default_miter_limit = 10.0;
@interface NSBezierPath (PrivateMethods) @interface NSBezierPath (PrivateMethods)
- (void)_invalidateCache; - (void)_invalidateCache;
@ -191,103 +198,101 @@ static Class NSBezierPath_concrete_class = nil;
// //
+ (void)setDefaultMiterLimit:(float)limit + (void)setDefaultMiterLimit:(float)limit
{ {
default_miter_limit = limit;
// Do we need this?
PSsetmiterlimit(limit); PSsetmiterlimit(limit);
} }
+ (float)defaultMiterLimit + (float)defaultMiterLimit
{ {
float limit; return default_miter_limit;
PScurrentmiterlimit(&limit);
return limit;
} }
+ (void)setDefaultFlatness:(float)flatness + (void)setDefaultFlatness:(float)flatness
{ {
default_flatness = flatness;
PSsetflat(flatness); PSsetflat(flatness);
} }
+ (float)defaultFlatness + (float)defaultFlatness
{ {
float flatness; return default_flatness;
PScurrentflat(&flatness);
return flatness;
} }
+ (void)setDefaultWindingRule:(NSWindingRule)windingRule + (void)setDefaultWindingRule:(NSWindingRule)windingRule
{ {
// TODO default_winding_rule = windingRule;
} }
+ (NSWindingRule)defaultWindingRule + (NSWindingRule)defaultWindingRule
{ {
// TODO return default_winding_rule;
return NSNonZeroWindingRule;
} }
+ (void)setDefaultLineCapStyle:(NSLineCapStyle)lineCapStyle + (void)setDefaultLineCapStyle:(NSLineCapStyle)lineCapStyle
{ {
default_line_cap_style = lineCapStyle;
PSsetlinecap(lineCapStyle); PSsetlinecap(lineCapStyle);
} }
+ (NSLineCapStyle)defaultLineCapStyle + (NSLineCapStyle)defaultLineCapStyle
{ {
int lineCapStyle; return default_line_cap_style;
PScurrentlinecap(&lineCapStyle);
return lineCapStyle;
} }
+ (void)setDefaultLineJoinStyle:(NSLineJoinStyle)lineJoinStyle + (void)setDefaultLineJoinStyle:(NSLineJoinStyle)lineJoinStyle
{ {
default_line_join_style = lineJoinStyle;
PSsetlinejoin(lineJoinStyle); PSsetlinejoin(lineJoinStyle);
} }
+ (NSLineJoinStyle)defaultLineJoinStyle + (NSLineJoinStyle)defaultLineJoinStyle
{ {
int lineJoinStyle; return default_line_join_style;
PScurrentlinejoin(&lineJoinStyle);
return lineJoinStyle;
} }
+ (void)setDefaultLineWidth:(float)lineWidth + (void)setDefaultLineWidth:(float)lineWidth
{ {
default_line_width = lineWidth;
PSsetlinewidth(lineWidth); PSsetlinewidth(lineWidth);
} }
+ (float)defaultLineWidth + (float)defaultLineWidth
{ {
float lineWidth; return default_line_width;
PScurrentlinewidth(&lineWidth);
return lineWidth;
} }
- (id) init - (id) init
{ {
[super init]; [super init];
// FIXME: Should those values come from the default? // Those values come from the default.
[self setLineWidth: 1]; [self setLineWidth: default_line_width];
[self setFlatness: 1]; [self setFlatness: default_flatness];
[self setLineCapStyle: NSButtLineCapStyle]; [self setLineCapStyle: default_line_cap_style];
[self setLineJoinStyle: NSMiterLineJoinStyle]; [self setLineJoinStyle: default_line_join_style];
[self setWindingRule: NSNonZeroWindingRule]; [self setMiterLimit: default_miter_limit];
[self setWindingRule: default_winding_rule];
// Set by allocation // Set by allocation
//_bounds = NSZeroRect; //_bounds = NSZeroRect;
//_controlPointBounds = NSZeroRect; //_controlPointBounds = NSZeroRect;
//_cachesBezierPath = NO; //_cachesBezierPath = NO;
//_cacheImage = nil; //_cacheImage = nil;
//_dash_count = 0;
//_dash_phase = 0;
//_dash_pattern = NULL;
return self; return self;
} }
- (void) dealloc - (void) dealloc
{ {
if(_cacheImage) if(_cacheImage != nil)
RELEASE(_cacheImage); RELEASE(_cacheImage);
if (_dash_pattern != NULL)
NSZoneFree([self zone], _dash_pattern);
[super dealloc]; [super dealloc];
} }
@ -424,12 +429,36 @@ static Class NSBezierPath_concrete_class = nil;
- (void)getLineDash:(float *)pattern count:(int *)count phase:(float *)phase - (void)getLineDash:(float *)pattern count:(int *)count phase:(float *)phase
{ {
// TODO // FIXME: How big is the pattern array?
// We assume that this value is in count!
if (count != NULL)
{
if (*count < _dash_count)
{
*count = _dash_count;
return;
}
*count = _dash_count;
}
if (phase != NULL)
*phase = _dash_phase;
memcpy(pattern, _dash_pattern, _dash_count * sizeof(float));
} }
- (void)setLineDash:(const float *)pattern count:(int)count phase:(float)phase - (void)setLineDash:(const float *)pattern count:(int)count phase:(float)phase
{ {
// TODO NSZone *myZone = [self zone];
if ( _dash_pattern == NULL)
_dash_pattern = NSZoneMalloc(myZone, count * sizeof(float));
else
NSZoneRealloc(myZone, _dash_pattern, count * sizeof(float));
_dash_count = count;
_dash_phase = phase;
memcpy(_dash_pattern, pattern, _dash_count * sizeof(float));
} }
// //
@ -1115,6 +1144,15 @@ static Class NSBezierPath_concrete_class = nil;
if(_cachesBezierPath && _cacheImage) if(_cachesBezierPath && _cacheImage)
path->_cacheImage = [_cacheImage copy]; path->_cacheImage = [_cacheImage copy];
if (_dash_pattern != NULL)
{
float *pattern = NSZoneMalloc(zone, _dash_count * sizeof(float));
memcpy(pattern, _dash_pattern, _dash_count * sizeof(float));
_dash_pattern = pattern;
}
return path; return path;
} }
@ -1250,6 +1288,8 @@ static Class NSBezierPath_concrete_class = nil;
NSBezierPathElement type; NSBezierPathElement type;
NSPoint pts[3]; NSPoint pts[3];
int i, count; int i, count;
float pattern[10];
float phase;
DPSnewpath(ctxt); DPSnewpath(ctxt);
DPSsetlinewidth(ctxt, [self lineWidth]); DPSsetlinewidth(ctxt, [self lineWidth]);
@ -1258,6 +1298,10 @@ static Class NSBezierPath_concrete_class = nil;
DPSsetmiterlimit(ctxt, [self miterLimit]); DPSsetmiterlimit(ctxt, [self miterLimit]);
DPSsetflat(ctxt, [self flatness]); DPSsetflat(ctxt, [self flatness]);
[self getLineDash: pattern count: &count phase: &phase];
if (count != 0 && count < 10)
DPSsetdash(ctxt, pattern, count, phase);
count = [self elementCount]; count = [self elementCount];
for(i = 0; i < count; i++) for(i = 0; i < count; i++)
{ {