mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:50:48 +00:00
Fixed how angles are managed when drawing arcs: do it postscript-like
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9308 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bb5d3f6310
commit
fe734480f2
1 changed files with 41 additions and 37 deletions
|
@ -570,7 +570,7 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSBezierPath *)bezierPathByReversingPath
|
- (NSBezierPath *) bezierPathByReversingPath
|
||||||
{
|
{
|
||||||
NSBezierPath *path = [isa bezierPath];
|
NSBezierPath *path = [isa bezierPath];
|
||||||
NSBezierPathElement type, last_type;
|
NSBezierPathElement type, last_type;
|
||||||
|
@ -649,7 +649,7 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
//
|
//
|
||||||
// Applying transformations.
|
// Applying transformations.
|
||||||
//
|
//
|
||||||
- (void)transformUsingAffineTransform:(NSAffineTransform *)transform
|
- (void) transformUsingAffineTransform: (NSAffineTransform *)transform
|
||||||
{
|
{
|
||||||
NSBezierPathElement type;
|
NSBezierPathElement type;
|
||||||
NSPoint pts[3];
|
NSPoint pts[3];
|
||||||
|
@ -685,12 +685,12 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
//
|
//
|
||||||
// Path info
|
// Path info
|
||||||
//
|
//
|
||||||
- (BOOL)isEmpty
|
- (BOOL) isEmpty
|
||||||
{
|
{
|
||||||
return ([self elementCount] == 0);
|
return ([self elementCount] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSPoint)currentPoint
|
- (NSPoint) currentPoint
|
||||||
{
|
{
|
||||||
NSBezierPathElement type;
|
NSBezierPathElement type;
|
||||||
NSPoint points[3];
|
NSPoint points[3];
|
||||||
|
@ -727,14 +727,14 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
return NSZeroPoint;
|
return NSZeroPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRect)controlPointBounds
|
- (NSRect) controlPointBounds
|
||||||
{
|
{
|
||||||
if (_shouldRecalculateBounds)
|
if (_shouldRecalculateBounds)
|
||||||
[self _recalculateBounds];
|
[self _recalculateBounds];
|
||||||
return _controlPointBounds;
|
return _controlPointBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRect)bounds
|
- (NSRect) bounds
|
||||||
{
|
{
|
||||||
if (_shouldRecalculateBounds)
|
if (_shouldRecalculateBounds)
|
||||||
[self _recalculateBounds];
|
[self _recalculateBounds];
|
||||||
|
@ -744,20 +744,20 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
//
|
//
|
||||||
// Elements
|
// Elements
|
||||||
//
|
//
|
||||||
- (int)elementCount
|
- (int) elementCount
|
||||||
{
|
{
|
||||||
[self subclassResponsibility:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSBezierPathElement)elementAtIndex:(int)index
|
- (NSBezierPathElement) elementAtIndex: (int)index
|
||||||
associatedPoints:(NSPoint *)points
|
associatedPoints: (NSPoint *)points
|
||||||
{
|
{
|
||||||
[self subclassResponsibility:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSBezierPathElement)elementAtIndex:(int)index
|
- (NSBezierPathElement) elementAtIndex: (int)index
|
||||||
{
|
{
|
||||||
return [self elementAtIndex: index associatedPoints: NULL];
|
return [self elementAtIndex: index associatedPoints: NULL];
|
||||||
}
|
}
|
||||||
|
@ -770,7 +770,7 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
//
|
//
|
||||||
// Appending common paths
|
// Appending common paths
|
||||||
//
|
//
|
||||||
- (void)appendBezierPath:(NSBezierPath *)aPath
|
- (void) appendBezierPath: (NSBezierPath *)aPath
|
||||||
{
|
{
|
||||||
NSBezierPathElement type;
|
NSBezierPathElement type;
|
||||||
NSPoint points[3];
|
NSPoint points[3];
|
||||||
|
@ -833,7 +833,7 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
[self appendBezierPath: [isa bezierPathWithOvalInRect: aRect]];
|
[self appendBezierPath: [isa bezierPathWithOvalInRect: aRect]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* startAngle and endAngle are in degrees, counterclockwise, from the
|
/* startAngle and endAngle are in degrees, counterclockwise, from the
|
||||||
x axis */
|
x axis */
|
||||||
- (void) appendBezierPathWithArcWithCenter: (NSPoint)center
|
- (void) appendBezierPathWithArcWithCenter: (NSPoint)center
|
||||||
radius: (float)radius
|
radius: (float)radius
|
||||||
|
@ -844,15 +844,36 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
float startAngle_rad, endAngle_rad, diff;
|
float startAngle_rad, endAngle_rad, diff;
|
||||||
NSPoint p0, p1, p2, p3;
|
NSPoint p0, p1, p2, p3;
|
||||||
|
|
||||||
while (startAngle < 0)
|
/* We use the Postscript prescription for managing the angles and
|
||||||
startAngle = startAngle + 360;
|
drawing the arc. See the documentation for `arc' and `arcn' in
|
||||||
while (startAngle > 360)
|
the Postscript Reference. */
|
||||||
startAngle = startAngle - 360;
|
|
||||||
|
|
||||||
while (endAngle < 0)
|
if (clockwise)
|
||||||
endAngle = endAngle + 360;
|
{
|
||||||
while (endAngle > 360)
|
/* This modification of the angles is the postscript
|
||||||
endAngle = endAngle - 360;
|
prescription. */
|
||||||
|
while (startAngle < endAngle)
|
||||||
|
endAngle -= 360;
|
||||||
|
|
||||||
|
/* This is used when we draw a clockwise quarter of
|
||||||
|
circumference. By adding diff at the starting angle of the
|
||||||
|
quarter, we get the ending angle. diff is negative because
|
||||||
|
we draw clockwise. */
|
||||||
|
diff = - PI / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* This modification of the angles is the postscript
|
||||||
|
prescription. */
|
||||||
|
while (endAngle < startAngle)
|
||||||
|
endAngle += 360;
|
||||||
|
|
||||||
|
/* This is used when we draw a counterclockwise quarter of
|
||||||
|
circumference. By adding diff at the starting angle of the
|
||||||
|
quarter, we get the ending angle. diff is positive because
|
||||||
|
we draw counterclockwise. */
|
||||||
|
diff = PI / 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* Convert the angles to radians */
|
/* Convert the angles to radians */
|
||||||
startAngle_rad = PI * startAngle / 180;
|
startAngle_rad = PI * startAngle / 180;
|
||||||
|
@ -863,23 +884,6 @@ static Class NSBezierPath_concrete_class = nil;
|
||||||
center.y + radius * sin (startAngle_rad));
|
center.y + radius * sin (startAngle_rad));
|
||||||
[self moveToPoint: p0];
|
[self moveToPoint: p0];
|
||||||
|
|
||||||
if (clockwise)
|
|
||||||
{
|
|
||||||
diff = -PI / 2;
|
|
||||||
if (startAngle_rad < endAngle_rad)
|
|
||||||
{
|
|
||||||
startAngle_rad += 2 * PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
diff = PI / 2;
|
|
||||||
if (startAngle_rad > endAngle_rad)
|
|
||||||
{
|
|
||||||
startAngle_rad -= 2 * PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((clockwise) ? (startAngle_rad > endAngle_rad)
|
while ((clockwise) ? (startAngle_rad > endAngle_rad)
|
||||||
: (startAngle_rad < endAngle_rad))
|
: (startAngle_rad < endAngle_rad))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue