Kinda sorta maybe fixed arcs??

This commit is contained in:
Pietro Gagliardi 2015-10-07 11:43:51 -04:00
parent 4f1219213d
commit 34d699cc29
2 changed files with 61 additions and 33 deletions

View File

@ -143,19 +143,20 @@ static void arcStartXY(double xCenter, double yCenter, double radius, double sta
*startY = yCenter + radius * sinStart; *startY = yCenter + radius * sinStart;
} }
// TODO this is a mess.
static void doDrawArc(ID2D1GeometrySink *sink, double xCenter, double yCenter, double radius, double startAngle, double endAngle) static void doDrawArc(ID2D1GeometrySink *sink, double xCenter, double yCenter, double radius, double startAngle, double endAngle)
{ {
double delta; double delta;
double add; int negative;
D2D1_ARC_SEGMENT as; D2D1_ARC_SEGMENT as;
double endX, endY; double endX, endY;
delta = endAngle - startAngle; delta = endAngle - startAngle;
add = M_PI; negative = 1;
// TODO why do I have to do this? if delta == 360 nothing gets drawn regardless of parameter values // TODO why do I have to do this? if delta == 360 nothing gets drawn regardless of parameter values
while (delta > M_PI) { while (delta > M_PI) {
// this line alternates between getting the 180 degree and 360 degree point; the add variable does the alternating // this line alternates between getting the 180 degree and 360 degree point; the negative variable does the alternating
arcStartXY(xCenter, yCenter, radius, startAngle + add, &endX, &endY); arcStartXY(xCenter, yCenter, radius, startAngle + (negative * M_PI), &endX, &endY);
as.point.x = endX; as.point.x = endX;
as.point.y = endY; as.point.y = endY;
as.size.width = radius; as.size.width = radius;
@ -165,7 +166,10 @@ static void doDrawArc(ID2D1GeometrySink *sink, double xCenter, double yCenter, d
as.arcSize = D2D1_ARC_SIZE_SMALL; as.arcSize = D2D1_ARC_SIZE_SMALL;
ID2D1GeometrySink_AddArc(sink, &as); ID2D1GeometrySink_AddArc(sink, &as);
delta -= M_PI; delta -= M_PI;
add += M_PI; if (negative == 0)
negative = 1;
else
negative = 0;
} }
arcStartXY(xCenter, yCenter, radius, endAngle, &endX, &endY); arcStartXY(xCenter, yCenter, radius, endAngle, &endX, &endY);
@ -175,12 +179,16 @@ static void doDrawArc(ID2D1GeometrySink *sink, double xCenter, double yCenter, d
as.size.height = radius; as.size.height = radius;
// Direct2D expects degrees // Direct2D expects degrees
as.rotationAngle = delta * (180.0 / M_PI); as.rotationAngle = delta * (180.0 / M_PI);
if (!negative)
as.rotationAngle += 180;
as.sweepDirection = D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE; as.sweepDirection = D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE;
as.arcSize = D2D1_ARC_SIZE_SMALL; as.arcSize = D2D1_ARC_SIZE_SMALL;
if (!negative)
as.arcSize = D2D1_ARC_SIZE_LARGE;
ID2D1GeometrySink_AddArc(sink, &as); ID2D1GeometrySink_AddArc(sink, &as);
} }
void uiDrawPathNewFigureWIthArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double endAngle) void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double endAngle)
{ {
double startX, startY; double startX, startY;
@ -324,6 +332,7 @@ static ID2D1Brush *makeBrush(uiDrawBrush *b, ID2D1RenderTarget *rt)
return NULL; // make compiler happy return NULL; // make compiler happy
} }
// TODO use stroke params
void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeParams *sp) void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeParams *sp)
{ {
ID2D1Brush *brush; ID2D1Brush *brush;

View File

@ -36,56 +36,75 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
sp.MiterLimit = uiDrawDefaultMiterLimit; sp.MiterLimit = uiDrawDefaultMiterLimit;
uiDrawStroke(p->Context, path, &brush, &sp); uiDrawStroke(p->Context, path, &brush, &sp);
uiDrawFreePath(path); uiDrawFreePath(path);
/*
uiDrawBeginPathRGB(p->Context, 0x00, 0x00, 0xC0); brush.R = 0;
uiDrawMoveTo(p->Context, p->ClipX, p->ClipY); brush.G = 0;
uiDrawLineTo(p->Context, p->ClipX + p->ClipWidth, p->ClipY); brush.B = 0.75;
uiDrawLineTo(p->Context, 50, 150); path = uiDrawNewPath(uiDrawFillModeWinding);
uiDrawLineTo(p->Context, 50, 50); uiDrawPathNewFigure(path, p->ClipX, p->ClipY);
uiDrawCloseFigure(p->Context); uiDrawPathLineTo(path, p->ClipX + p->ClipWidth, p->ClipY);
uiDrawPathLineTo(path, 50, 150);
uiDrawPathLineTo(path, 50, 50);
uiDrawPathCloseFigure(path);
uiDrawPathEnd(path);
sp.Cap = uiDrawLineCapFlat; sp.Cap = uiDrawLineCapFlat;
sp.Join = uiDrawLineJoinRound; sp.Join = uiDrawLineJoinRound;
sp.Thickness = 5; sp.Thickness = 5;
uiDrawStroke(p->Context, &sp); uiDrawStroke(p->Context, path, &brush, &sp);
uiDrawFreePath(path);
uiDrawBeginPathRGBA(p->Context, 0x00, 0xC0, 0x00, 0x80); brush.R = 0;
uiDrawRectangle(p->Context, 120, 80, 50, 50); brush.G = 0.75;
uiDrawFill(p->Context, uiDrawFillModeWinding); brush.B = 0;
brush.A = 0.5;
path = uiDrawNewPath(uiDrawFillModeWinding);
//TODO uiDrawRectangle(path, 120, 80, 50, 50);
uiDrawPathEnd(path);
// uiDrawFill(p->Context, path, &brush);
uiDrawFreePath(path);
brush.A = 1;
uiDrawBeginPathRGB(p->Context, 0x00, 0x80, 0x00); brush.R = 0;
uiDrawMoveTo(p->Context, 5, 10); brush.G = 0.5;
uiDrawLineTo(p->Context, 5, 50); brush.B = 0;
path = uiDrawNewPath(uiDrawFillModeWinding);
uiDrawPathNewFigure(path, 5, 10);
uiDrawPathLineTo(path, 5, 50);
uiDrawPathEnd(path);
sp.Cap = uiDrawLineCapFlat; sp.Cap = uiDrawLineCapFlat;
sp.Join = uiDrawLineJoinMiter; sp.Join = uiDrawLineJoinMiter;
sp.Thickness = 1; sp.Thickness = 1;
sp.MiterLimit = uiDrawDefaultMiterLimit; sp.MiterLimit = uiDrawDefaultMiterLimit;
uiDrawStroke(p->Context, &sp); uiDrawStroke(p->Context, path, &brush, &sp);
uiDrawFreePath(path);
uiDrawBeginPathRGB(p->Context, 0x80, 0xC0, 0x00); brush.R = 0.5;
uiDrawMoveTo(p->Context, 400, 100); brush.G = 0.75;
uiDrawArcTo(p->Context, brush.B = 0;
path = uiDrawNewPath(uiDrawFillModeWinding);
uiDrawPathNewFigure(path, 400, 100);
uiDrawPathArcTo(path,
400, 100, 400, 100,
50, 50,
30. * (M_PI / 180.), 30. * (M_PI / 180.),
// note the end angle here // note the end angle here
// in GDI, the second angle to AngleArc() is relative to the start, not to 0 // in GDI, the second angle to AngleArc() is relative to the start, not to 0
330. * (M_PI / 180.), 330. * (M_PI / 180.));
1);
// TODO add a checkbox for this // TODO add a checkbox for this
uiDrawLineTo(p->Context, 400, 100); uiDrawPathLineTo(path, 400, 100);
uiDrawArcTo(p->Context, uiDrawPathNewFigureWithArc(path,
510, 100, 510, 100,
50, 50,
30. * (M_PI / 180.), 30. * (M_PI / 180.),
330. * (M_PI / 180.), 330. * (M_PI / 180.));
0); uiDrawPathCloseFigure(path);
uiDrawCloseFigure(p->Context); uiDrawPathEnd(path);
sp.Cap = uiDrawLineCapFlat; sp.Cap = uiDrawLineCapFlat;
sp.Join = uiDrawLineJoinMiter; sp.Join = uiDrawLineJoinMiter;
sp.Thickness = 1; sp.Thickness = 1;
sp.MiterLimit = uiDrawDefaultMiterLimit; sp.MiterLimit = uiDrawDefaultMiterLimit;
uiDrawStroke(p->Context, &sp); uiDrawStroke(p->Context, path, &brush, &sp);
/*
uiDrawBeginPathRGB(p->Context, 0x00, 0x80, 0xC0); uiDrawBeginPathRGB(p->Context, 0x00, 0x80, 0xC0);
uiDrawMoveTo(p->Context, 300, 300); uiDrawMoveTo(p->Context, 300, 300);
uiDrawBezierTo(p->Context, uiDrawBezierTo(p->Context,