Added a parameter for negative arcs.

This commit is contained in:
Pietro Gagliardi 2015-10-11 21:15:08 -04:00
parent b09cdb5137
commit 15c00330d6
2 changed files with 74 additions and 38 deletions

View File

@ -80,14 +80,16 @@ static void drawOriginal(uiAreaDrawParams *p)
400, 100, 400, 100,
50, 50,
30. * (M_PI / 180.), 30. * (M_PI / 180.),
300. * (M_PI / 180.)); 300. * (M_PI / 180.),
0);
// the sweep test below doubles as a clockwise test so a checkbox isn't needed anymore // the sweep test below doubles as a clockwise test so a checkbox isn't needed anymore
uiDrawPathLineTo(path, 400, 100); uiDrawPathLineTo(path, 400, 100);
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
510, 100, 510, 100,
50, 50,
30. * (M_PI / 180.), 30. * (M_PI / 180.),
300. * (M_PI / 180.)); 300. * (M_PI / 180.),
0);
uiDrawPathCloseFigure(path); uiDrawPathCloseFigure(path);
// and now with 330 to make sure sweeps work properly // and now with 330 to make sure sweeps work properly
uiDrawPathNewFigure(path, 400, 210); uiDrawPathNewFigure(path, 400, 210);
@ -95,13 +97,15 @@ static void drawOriginal(uiAreaDrawParams *p)
400, 210, 400, 210,
50, 50,
30. * (M_PI / 180.), 30. * (M_PI / 180.),
330. * (M_PI / 180.)); 330. * (M_PI / 180.),
0);
uiDrawPathLineTo(path, 400, 210); uiDrawPathLineTo(path, 400, 210);
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
510, 210, 510, 210,
50, 50,
30. * (M_PI / 180.), 30. * (M_PI / 180.),
330. * (M_PI / 180.)); 330. * (M_PI / 180.),
0);
uiDrawPathCloseFigure(path); uiDrawPathCloseFigure(path);
uiDrawPathEnd(path); uiDrawPathEnd(path);
sp.Cap = uiDrawLineCapFlat; sp.Cap = uiDrawLineCapFlat;
@ -155,7 +159,8 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
x, y, x, y,
rad, rad,
0, angle); 0, angle,
0);
angle += add; angle += add;
x += 2 * rad + step; x += 2 * rad + step;
} }
@ -168,7 +173,8 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathArcTo(path, uiDrawPathArcTo(path,
x, y, x, y,
rad, rad,
0, angle); 0, angle,
0);
angle += add; angle += add;
x += 2 * rad + step; x += 2 * rad + step;
} }
@ -180,7 +186,8 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
x, y, x, y,
rad, rad,
(M_PI / 4), angle); (M_PI / 4), angle,
0);
angle += add; angle += add;
x += 2 * rad + step; x += 2 * rad + step;
} }
@ -193,7 +200,8 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathArcTo(path, uiDrawPathArcTo(path,
x, y, x, y,
rad, rad,
(M_PI / 4), angle); (M_PI / 4), angle,
0);
angle += add; angle += add;
x += 2 * rad + step; x += 2 * rad + step;
} }
@ -205,7 +213,8 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
x, y, x, y,
rad, rad,
M_PI + (M_PI / 5), angle); M_PI + (M_PI / 5), angle,
0);
angle += add; angle += add;
x += 2 * rad + step; x += 2 * rad + step;
} }
@ -218,7 +227,8 @@ static void drawArcs(uiAreaDrawParams *p)
uiDrawPathArcTo(path, uiDrawPathArcTo(path,
x, y, x, y,
rad, rad,
M_PI + (M_PI / 5), angle); M_PI + (M_PI / 5), angle,
0);
angle += add; angle += add;
x += 2 * rad + step; x += 2 * rad + step;
} }
@ -483,7 +493,8 @@ static void drawD2DRadialBrush(uiAreaDrawParams *p)
75, 75, 75, 75,
75, 75,
0, 0,
2 * M_PI); 2 * M_PI,
0);
uiDrawPathEnd(path); uiDrawPathEnd(path);
uiDrawFill(p->Context, path, &gradient); uiDrawFill(p->Context, path, &gradient);
@ -555,7 +566,8 @@ static void drawD2DPathGeometries(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(sun, uiDrawPathNewFigureWithArc(sun,
(440.0 - 270.0) / 2 + 270.0, 255, (440.0 - 270.0) / 2 + 270.0, 255,
85, 85,
0, M_PI); 0, M_PI,
0);
uiDrawPathCloseFigure(sun); uiDrawPathCloseFigure(sun);
uiDrawPathEnd(sun); uiDrawPathEnd(sun);
@ -684,38 +696,46 @@ static void drawD2DGeometryGroup(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(alternate, uiDrawPathNewFigureWithArc(alternate,
105, 105, 105, 105,
25, 25,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathNewFigureWithArc(alternate, uiDrawPathNewFigureWithArc(alternate,
105, 105, 105, 105,
50, 50,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathNewFigureWithArc(alternate, uiDrawPathNewFigureWithArc(alternate,
105, 105, 105, 105,
75, 75,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathNewFigureWithArc(alternate, uiDrawPathNewFigureWithArc(alternate,
105, 105, 105, 105,
100, 100,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathEnd(alternate); uiDrawPathEnd(alternate);
winding = uiDrawNewPath(uiDrawFillModeWinding); winding = uiDrawNewPath(uiDrawFillModeWinding);
uiDrawPathNewFigureWithArc(winding, uiDrawPathNewFigureWithArc(winding,
105, 105, 105, 105,
25, 25,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathNewFigureWithArc(winding, uiDrawPathNewFigureWithArc(winding,
105, 105, 105, 105,
50, 50,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathNewFigureWithArc(winding, uiDrawPathNewFigureWithArc(winding,
105, 105, 105, 105,
75, 75,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathNewFigureWithArc(winding, uiDrawPathNewFigureWithArc(winding,
105, 105, 105, 105,
100, 100,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathEnd(winding); uiDrawPathEnd(winding);
d2dClear(p, d2dWhite, 1.0); d2dClear(p, d2dWhite, 1.0);
@ -875,7 +895,8 @@ static void drawCSArc(uiAreaDrawParams *p)
xc, yc, xc, yc,
radius, radius,
angle2, angle2,
M_PI - angle1); M_PI - angle1,
0);
uiDrawPathEnd(path); uiDrawPathEnd(path);
uiDrawStroke(p->Context, path, &source, &sp); uiDrawStroke(p->Context, path, &source, &sp);
uiDrawFreePath(path); uiDrawFreePath(path);
@ -887,7 +908,8 @@ static void drawCSArc(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
xc, yc, xc, yc,
10.0, 10.0,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathEnd(path); uiDrawPathEnd(path);
uiDrawFill(p->Context, path, &source); uiDrawFill(p->Context, path, &source);
uiDrawFreePath(path); uiDrawFreePath(path);
@ -896,12 +918,14 @@ static void drawCSArc(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
xc, yc, xc, yc,
radius, radius,
(M_PI - angle1) + angle2, 0); (M_PI - angle1) + angle2, 0,
0);
uiDrawPathLineTo(path, xc, yc); uiDrawPathLineTo(path, xc, yc);
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
xc, yc, xc, yc,
radius, radius,
angle2, 0); angle2, 0,
0);
uiDrawPathLineTo(path, xc, yc); uiDrawPathLineTo(path, xc, yc);
uiDrawPathEnd(path); uiDrawPathEnd(path);
uiDrawStroke(p->Context, path, &source, &sp); uiDrawStroke(p->Context, path, &source, &sp);
@ -932,7 +956,8 @@ static void drawCSArcNegative(uiAreaDrawParams *p)
xc, yc, xc, yc,
radius, radius,
-angle1, -angle1,
angle1 + angle2); angle1 + angle2,
0);
uiDrawPathEnd(path); uiDrawPathEnd(path);
uiDrawStroke(p->Context, path, &source, &sp); uiDrawStroke(p->Context, path, &source, &sp);
uiDrawFreePath(path); uiDrawFreePath(path);
@ -944,7 +969,8 @@ static void drawCSArcNegative(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
xc, yc, xc, yc,
10.0, 10.0,
0, 2 * M_PI); 0, 2 * M_PI,
0);
uiDrawPathEnd(path); uiDrawPathEnd(path);
uiDrawFill(p->Context, path, &source); uiDrawFill(p->Context, path, &source);
uiDrawFreePath(path); uiDrawFreePath(path);
@ -953,12 +979,14 @@ static void drawCSArcNegative(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
xc, yc, xc, yc,
radius, radius,
(M_PI - angle1) + angle2, 0); (M_PI - angle1) + angle2, 0,
0);
uiDrawPathLineTo(path, xc, yc); uiDrawPathLineTo(path, xc, yc);
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
xc, yc, xc, yc,
radius, radius,
angle2, 0); angle2, 0,
0);
uiDrawPathLineTo(path, xc, yc); uiDrawPathLineTo(path, xc, yc);
uiDrawPathEnd(path); uiDrawPathEnd(path);
uiDrawStroke(p->Context, path, &source, &sp); uiDrawStroke(p->Context, path, &source, &sp);
@ -1136,11 +1164,13 @@ static void drawCSFillStyle(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
64, 64, 64, 64,
40, 40,
0, 2*M_PI); 0, 2*M_PI,
0);
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
192, 64, 192, 64,
40, 40,
0, 2*M_PI); 0, 2*M_PI,
0);
uiDrawPathEnd(path); uiDrawPathEnd(path);
crsourcergba(&source, 0, 0.7, 0, 1); crsourcergba(&source, 0, 0.7, 0, 1);
@ -1159,11 +1189,13 @@ static void drawCSFillStyle(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
64, 64, 64, 64,
40, 40,
0, 2*M_PI); 0, 2*M_PI,
0);
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
192, 64, 192, 64,
40, 40,
0, 2*M_PI); 0, 2*M_PI,
0);
uiDrawPathEnd(path); uiDrawPathEnd(path);
crsourcergba(&source, 0, 0, 0.9, 1); crsourcergba(&source, 0, 0, 0.9, 1);
@ -1239,22 +1271,26 @@ static void drawCSRoundRect(uiAreaDrawParams *p)
uiDrawPathNewFigureWithArc(path, uiDrawPathNewFigureWithArc(path,
x + width - radius, y + radius, x + width - radius, y + radius,
radius, radius,
0 * degrees, 90 * degrees); 0 * degrees, 90 * degrees,
0);
// top left corner // top left corner
uiDrawPathArcTo(path, uiDrawPathArcTo(path,
x + radius, y + radius, x + radius, y + radius,
radius, radius,
90 * degrees, 90 * degrees); 90 * degrees, 90 * degrees,
0);
// bottom left corner // bottom left corner
uiDrawPathArcTo(path, uiDrawPathArcTo(path,
x + radius, y + height - radius, x + radius, y + height - radius,
radius, radius,
180 * degrees, 90 * degrees); 180 * degrees, 90 * degrees,
0);
// bottom right corner // bottom right corner
uiDrawPathArcTo(path, uiDrawPathArcTo(path,
x + width - radius, y + height - radius, x + width - radius, y + height - radius,
radius, radius,
270 * degrees, 90 * degrees); 270 * degrees, 90 * degrees,
0);
uiDrawPathCloseFigure(path); uiDrawPathCloseFigure(path);
uiDrawPathEnd(path); uiDrawPathEnd(path);

4
ui.h
View File

@ -389,12 +389,12 @@ _UI_EXTERN uiDrawPath *uiDrawNewPath(uiDrawFillMode fillMode);
_UI_EXTERN void uiDrawFreePath(uiDrawPath *p); _UI_EXTERN void uiDrawFreePath(uiDrawPath *p);
_UI_EXTERN void uiDrawPathNewFigure(uiDrawPath *p, double x, double y); _UI_EXTERN void uiDrawPathNewFigure(uiDrawPath *p, double x, double y);
_UI_EXTERN void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep); _UI_EXTERN void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative);
_UI_EXTERN void uiDrawPathLineTo(uiDrawPath *p, double x, double y); _UI_EXTERN void uiDrawPathLineTo(uiDrawPath *p, double x, double y);
// notes: angles are both relative to 0 and go counterclockwise // notes: angles are both relative to 0 and go counterclockwise
// TODO is the initial line segment on cairo and OS X a proper join? // TODO is the initial line segment on cairo and OS X a proper join?
// TODO what if sweep < 0? // TODO what if sweep < 0?
_UI_EXTERN void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep); _UI_EXTERN void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative);
_UI_EXTERN void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY); _UI_EXTERN void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY);
// TODO quadratic bezier // TODO quadratic bezier
_UI_EXTERN void uiDrawPathCloseFigure(uiDrawPath *p); _UI_EXTERN void uiDrawPathCloseFigure(uiDrawPath *p);