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;
}
// TODO this is a mess.
static void doDrawArc(ID2D1GeometrySink *sink, double xCenter, double yCenter, double radius, double startAngle, double endAngle)
{
double delta;
double add;
int negative;
D2D1_ARC_SEGMENT as;
double endX, endY;
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
while (delta > M_PI) {
// this line alternates between getting the 180 degree and 360 degree point; the add variable does the alternating
arcStartXY(xCenter, yCenter, radius, startAngle + add, &endX, &endY);
// this line alternates between getting the 180 degree and 360 degree point; the negative variable does the alternating
arcStartXY(xCenter, yCenter, radius, startAngle + (negative * M_PI), &endX, &endY);
as.point.x = endX;
as.point.y = endY;
as.size.width = radius;
@ -165,7 +166,10 @@ static void doDrawArc(ID2D1GeometrySink *sink, double xCenter, double yCenter, d
as.arcSize = D2D1_ARC_SIZE_SMALL;
ID2D1GeometrySink_AddArc(sink, &as);
delta -= M_PI;
add += M_PI;
if (negative == 0)
negative = 1;
else
negative = 0;
}
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;
// Direct2D expects degrees
as.rotationAngle = delta * (180.0 / M_PI);
if (!negative)
as.rotationAngle += 180;
as.sweepDirection = D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE;
as.arcSize = D2D1_ARC_SIZE_SMALL;
if (!negative)
as.arcSize = D2D1_ARC_SIZE_LARGE;
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;
@ -324,6 +332,7 @@ static ID2D1Brush *makeBrush(uiDrawBrush *b, ID2D1RenderTarget *rt)
return NULL; // make compiler happy
}
// TODO use stroke params
void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeParams *sp)
{
ID2D1Brush *brush;

View File

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