Fix for issue #77

- line caps did not consider AA width
This commit is contained in:
Mikko Mononen 2014-05-23 09:37:36 +03:00
parent 4ee8aa9cde
commit 611b043fff
2 changed files with 43 additions and 9 deletions

View File

@ -936,6 +936,37 @@ void drawWidths(struct NVGcontext* vg, float x, float y, float width)
nvgRestore(vg);
}
void drawCaps(struct NVGcontext* vg, float x, float y, float width)
{
int i;
int caps[3] = {NVG_BUTT, NVG_ROUND, NVG_SQUARE};
float lineWidth = 8.0f;
nvgSave(vg);
nvgBeginPath(vg);
nvgRect(vg, x-lineWidth/2, y, width+lineWidth, 40);
nvgFillColor(vg, nvgRGBA(255,255,255,32));
nvgFill(vg);
nvgBeginPath(vg);
nvgRect(vg, x, y, width, 40);
nvgFillColor(vg, nvgRGBA(255,255,255,32));
nvgFill(vg);
nvgStrokeWidth(vg, lineWidth);
for (i = 0; i < 3; i++) {
nvgLineCap(vg, caps[i]);
nvgStrokeColor(vg, nvgRGBA(0,0,0,255));
nvgBeginPath(vg);
nvgMoveTo(vg, x, y + i*10 + 5);
nvgLineTo(vg, x+width, y + i*10 + 5);
nvgStroke(vg);
}
nvgRestore(vg);
}
void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float height,
float t, int blowup, struct DemoData* data)
{
@ -949,9 +980,12 @@ void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float he
// Line joints
drawLines(vg, 50, height-50, 600, 50, t);
// Line width;
// Line caps
drawWidths(vg, 10, 50, 30);
// Line caps
drawCaps(vg, 10, 300, 30);
nvgSave(vg);
if (blowup) {
nvgRotate(vg, sinf(t*0.3f)*5.0f/180.0f*NVG_PI);

View File

@ -1564,11 +1564,11 @@ static int nvg__expandStrokeAndFill(struct NVGcontext* ctx, int feats, float w,
dly = -dx;
if (lineCap == NVG_BUTT || lineCap == NVG_SQUARE) {
if (lineCap == NVG_BUTT) {
px = p0->x;
py = p0->y;
px = p0->x + dx*ctx->fringeWidth*0.5f;
py = p0->y + dy*ctx->fringeWidth*0.5f;
} else /*if (lineCap == NVG_SQUARE)*/ {
px = p0->x - dx*w;
py = p0->y - dy*w;
px = p0->x - dx*(w - ctx->fringeWidth);
py = p0->y - dy*(w - ctx->fringeWidth);
}
nvg__vset(dst, px + dlx*lw - dx*aa, py + dly*lw - dy*aa, lu,0); dst++;
nvg__vset(dst, px - dlx*rw - dx*aa, py - dly*rw - dy*aa, ru,0); dst++;
@ -1616,11 +1616,11 @@ static int nvg__expandStrokeAndFill(struct NVGcontext* ctx, int feats, float w,
dly = -dx;
if (lineCap == NVG_BUTT || lineCap == NVG_SQUARE) {
if (lineCap == NVG_BUTT) {
px = p1->x;
py = p1->y;
px = p1->x - dx*ctx->fringeWidth*0.5f;
py = p1->y - dy*ctx->fringeWidth*0.5f;
} else /*if (lineCap == NVG_SQUARE)*/ {
px = p1->x + dx*w;
py = p1->y + dy*w;
px = p1->x + dx*(w - ctx->fringeWidth);
py = p1->y + dy*(w - ctx->fringeWidth);
}
nvg__vset(dst, px + dlx*lw, py + dly * lw, lu,1); dst++;
nvg__vset(dst, px - dlx*rw, py - dly * rw, ru,1); dst++;