Allows to turn on/off antialias for shapes.

This commit adds a new `nvgShapeAntiAlias()` function for turning on/off antialias for specific shapes.
This commit is contained in:
Olli Wang 2017-07-11 18:36:40 +08:00
parent 7e42ac6099
commit 17321202da
2 changed files with 13 additions and 2 deletions

View File

@ -67,6 +67,7 @@ enum NVGpointFlags
struct NVGstate { struct NVGstate {
NVGcompositeOperationState compositeOperation; NVGcompositeOperationState compositeOperation;
int shapeAntiAlias;
NVGpaint fill; NVGpaint fill;
NVGpaint stroke; NVGpaint stroke;
float strokeWidth; float strokeWidth;
@ -646,6 +647,7 @@ void nvgReset(NVGcontext* ctx)
nvg__setPaintColor(&state->fill, nvgRGBA(255,255,255,255)); nvg__setPaintColor(&state->fill, nvgRGBA(255,255,255,255));
nvg__setPaintColor(&state->stroke, nvgRGBA(0,0,0,255)); nvg__setPaintColor(&state->stroke, nvgRGBA(0,0,0,255));
state->compositeOperation = nvg__compositeOperationState(NVG_SOURCE_OVER); state->compositeOperation = nvg__compositeOperationState(NVG_SOURCE_OVER);
state->shapeAntiAlias = 1;
state->strokeWidth = 1.0f; state->strokeWidth = 1.0f;
state->miterLimit = 10.0f; state->miterLimit = 10.0f;
state->lineCap = NVG_BUTT; state->lineCap = NVG_BUTT;
@ -665,6 +667,12 @@ void nvgReset(NVGcontext* ctx)
} }
// State setting // State setting
void nvgShapeAntiAlias(NVGcontext* ctx, int enabled)
{
NVGstate* state = nvg__getState(ctx);
state->shapeAntiAlias = enabled;
}
void nvgStrokeWidth(NVGcontext* ctx, float width) void nvgStrokeWidth(NVGcontext* ctx, float width)
{ {
NVGstate* state = nvg__getState(ctx); NVGstate* state = nvg__getState(ctx);
@ -2203,7 +2211,7 @@ void nvgFill(NVGcontext* ctx)
int i; int i;
nvg__flattenPaths(ctx); nvg__flattenPaths(ctx);
if (ctx->params.edgeAntiAlias) if (ctx->params.edgeAntiAlias && state->shapeAntiAlias)
nvg__expandFill(ctx, ctx->fringeWidth, NVG_MITER, 2.4f); nvg__expandFill(ctx, ctx->fringeWidth, NVG_MITER, 2.4f);
else else
nvg__expandFill(ctx, 0.0f, NVG_MITER, 2.4f); nvg__expandFill(ctx, 0.0f, NVG_MITER, 2.4f);
@ -2248,7 +2256,7 @@ void nvgStroke(NVGcontext* ctx)
nvg__flattenPaths(ctx); nvg__flattenPaths(ctx);
if (ctx->params.edgeAntiAlias) if (ctx->params.edgeAntiAlias && state->shapeAntiAlias)
nvg__expandStroke(ctx, strokeWidth*0.5f + ctx->fringeWidth*0.5f, state->lineCap, state->lineJoin, state->miterLimit); nvg__expandStroke(ctx, strokeWidth*0.5f + ctx->fringeWidth*0.5f, state->lineCap, state->lineJoin, state->miterLimit);
else else
nvg__expandStroke(ctx, strokeWidth*0.5f, state->lineCap, state->lineJoin, state->miterLimit); nvg__expandStroke(ctx, strokeWidth*0.5f, state->lineCap, state->lineJoin, state->miterLimit);

View File

@ -238,6 +238,9 @@ void nvgReset(NVGcontext* ctx);
// //
// Current render style can be saved and restored using nvgSave() and nvgRestore(). // Current render style can be saved and restored using nvgSave() and nvgRestore().
// Sets whether to draw antialias for nvgStroke() and nvgFill(). It's enabled by default.
void nvgShapeAntiAlias(NVGcontext* ctx, int enabled);
// Sets current stroke style to a solid color. // Sets current stroke style to a solid color.
void nvgStrokeColor(NVGcontext* ctx, NVGcolor color); void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);