Replaces [_doPath] with calls to [NSGraphicsContext

GSSendBezierPath:].
Added optimisation methods [appendBezierPath:] and
[transformUsingAffineTransform:] on GSBezierPath.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15038 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2002-11-21 20:28:42 +00:00
parent aab03279c4
commit 2aee934b43

View file

@ -55,7 +55,6 @@ static float default_miter_limit = 10.0;
- (void)_invalidateCache; - (void)_invalidateCache;
- (void)_recalculateBounds; - (void)_recalculateBounds;
- (void)_doPath;
@end @end
@ -479,6 +478,8 @@ static float default_miter_limit = 10.0;
// //
- (void)stroke - (void)stroke
{ {
NSGraphicsContext *ctxt = GSCurrentContext();
if(_cachesBezierPath) if(_cachesBezierPath)
{ {
NSRect bounds = [self bounds]; NSRect bounds = [self bounds];
@ -489,22 +490,24 @@ static float default_miter_limit = 10.0;
{ {
_cacheImage = [[NSImage alloc] initWithSize: bounds.size]; _cacheImage = [[NSImage alloc] initWithSize: bounds.size];
[_cacheImage lockFocus]; [_cacheImage lockFocus];
PStranslate(-origin.x, -origin.y); DPStranslate(ctxt, -origin.x, -origin.y);
[self _doPath]; [ctxt GSSendBezierPath: self];
PSstroke(); DPSstroke(ctxt);
[_cacheImage unlockFocus]; [_cacheImage unlockFocus];
} }
[_cacheImage compositeToPoint: origin operation: NSCompositeCopy]; [_cacheImage compositeToPoint: origin operation: NSCompositeCopy];
} }
else else
{ {
[self _doPath]; [ctxt GSSendBezierPath: self];
PSstroke(); DPSstroke(ctxt);
} }
} }
- (void)fill - (void)fill
{ {
NSGraphicsContext *ctxt = GSCurrentContext();
if(_cachesBezierPath) if(_cachesBezierPath)
{ {
NSRect bounds = [self bounds]; NSRect bounds = [self bounds];
@ -515,43 +518,47 @@ static float default_miter_limit = 10.0;
{ {
_cacheImage = [[NSImage alloc] initWithSize: bounds.size]; _cacheImage = [[NSImage alloc] initWithSize: bounds.size];
[_cacheImage lockFocus]; [_cacheImage lockFocus];
PStranslate(-origin.x, -origin.y); DPStranslate(ctxt, -origin.x, -origin.y);
[self _doPath]; [ctxt GSSendBezierPath: self];
if([self windingRule] == NSNonZeroWindingRule) if([self windingRule] == NSNonZeroWindingRule)
PSfill(); DPSfill(ctxt);
else else
PSeofill(); DPSeofill(ctxt);
[_cacheImage unlockFocus]; [_cacheImage unlockFocus];
} }
[_cacheImage compositeToPoint: origin operation: NSCompositeCopy]; [_cacheImage compositeToPoint: origin operation: NSCompositeCopy];
} }
else else
{ {
[self _doPath]; [ctxt GSSendBezierPath: self];
if([self windingRule] == NSNonZeroWindingRule) if([self windingRule] == NSNonZeroWindingRule)
PSfill(); DPSfill(ctxt);
else else
PSeofill(); DPSeofill(ctxt);
} }
} }
- (void)addClip - (void)addClip
{ {
[self _doPath]; NSGraphicsContext *ctxt = GSCurrentContext();
[ctxt GSSendBezierPath: self];
if([self windingRule] == NSNonZeroWindingRule) if([self windingRule] == NSNonZeroWindingRule)
PSclip(); DPSclip(ctxt);
else else
PSeoclip(); DPSeoclip(ctxt);
} }
- (void)setClip - (void)setClip
{ {
PSinitclip(); NSGraphicsContext *ctxt = GSCurrentContext();
[self _doPath];
DPSinitclip(ctxt);
[ctxt GSSendBezierPath: self];
if([self windingRule] == NSNonZeroWindingRule) if([self windingRule] == NSNonZeroWindingRule)
PSclip(); DPSclip(ctxt);
else else
PSeoclip(); DPSeoclip(ctxt);
} }
// //
@ -723,7 +730,6 @@ static float default_miter_limit = 10.0;
INVALIDATE_CACHE(); INVALIDATE_CACHE();
} }
// //
// Path info // Path info
// //
@ -819,7 +825,6 @@ static float default_miter_limit = 10.0;
int i, count; int i, count;
count = [aPath elementCount]; count = [aPath elementCount];
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
type = [aPath elementAtIndex: i associatedPoints: points]; type = [aPath elementAtIndex: i associatedPoints: points];
@ -1396,51 +1401,6 @@ static float default_miter_limit = 10.0;
_shouldRecalculateBounds = NO; _shouldRecalculateBounds = NO;
} }
- (void)_doPath
{
NSGraphicsContext *ctxt = GSCurrentContext();
NSBezierPathElement type;
NSPoint pts[3];
int i, count;
float pattern[10];
float phase;
DPSnewpath(ctxt);
DPSsetlinewidth(ctxt, [self lineWidth]);
DPSsetlinejoin(ctxt, [self lineJoinStyle]);
DPSsetlinecap(ctxt, [self lineCapStyle]);
DPSsetmiterlimit(ctxt, [self miterLimit]);
DPSsetflat(ctxt, [self flatness]);
[self getLineDash: pattern count: &count phase: &phase];
// Always sent the dash pattern. When NULL this will reset to a solid line.
DPSsetdash(ctxt, pattern, count, phase);
count = [self elementCount];
for(i = 0; i < count; i++)
{
type = [self elementAtIndex: i associatedPoints: pts];
switch(type)
{
case NSMoveToBezierPathElement:
DPSmoveto(ctxt, pts[0].x, pts[0].y);
break;
case NSLineToBezierPathElement:
DPSlineto(ctxt, pts[0].x, pts[0].y);
break;
case NSCurveToBezierPathElement:
DPScurveto(ctxt, pts[0].x, pts[0].y,
pts[1].x, pts[1].y, pts[2].x, pts[2].y);
break;
case NSClosePathBezierPathElement:
DPSclosepath(ctxt);
break;
default:
break;
}
}
}
@end @end
@ -1614,6 +1574,64 @@ typedef struct _PathElement
return [super bezierPathByFlatteningPath]; return [super bezierPathByFlatteningPath];
} }
- (void) transformUsingAffineTransform: (NSAffineTransform *)transform
{
NSBezierPathElement type;
int i, count;
PathElement *elments = (PathElement *)GSIArrayItems(pathElements);
SEL transformPointSel = @selector(transformPoint:);
NSPoint (*transformPointImp)(NSAffineTransform*, SEL, NSPoint);
transformPointImp = (NSPoint (*)(NSAffineTransform*, SEL, NSPoint))
[transform methodForSelector: transformPointSel];
count = GSIArrayCount(pathElements);
for(i = 0; i < count; i++)
{
type = elments[i].type;
switch(type)
{
case NSMoveToBezierPathElement:
case NSLineToBezierPathElement:
elments[i].points[0] = (*transformPointImp)(transform,
transformPointSel,
elments[i].points[0]);
break;
case NSCurveToBezierPathElement:
elments[i].points[0] = (*transformPointImp)(transform,
transformPointSel,
elments[i].points[0]);
elments[i].points[1] = (*transformPointImp)(transform,
transformPointSel,
elments[i].points[1]);
elments[i].points[2] = (*transformPointImp)(transform,
transformPointSel,
elments[i].points[2]);
break;
case NSClosePathBezierPathElement:
break;
default:
break;
}
}
INVALIDATE_CACHE();
}
- (void) appendBezierPath: (NSBezierPath *)aPath
{
PathElement elem;
int i, count;
count = [aPath elementCount];
for (i = 0; i < count; i++)
{
elem = GSIArrayItemAtIndex(((GSBezierPath*)aPath)->pathElements, i).ext;
GSIArrayAddItem(pathElements, (GSIArrayItem)elem);
}
INVALIDATE_CACHE();
}
// //
// NSCopying Protocol // NSCopying Protocol
// //