mirror of
https://github.com/memononen/nanovg
synced 2026-09-26 16:19:07 +03:00
Merge pull request #386 from olliwang/flags
Allows to turn on/off antialias for shapes.
This commit is contained in:
commit
30e1c98175
2 changed files with 13 additions and 2 deletions
12
src/nanovg.c
12
src/nanovg.c
|
|
@ -67,6 +67,7 @@ enum NVGpointFlags
|
|||
|
||||
struct NVGstate {
|
||||
NVGcompositeOperationState compositeOperation;
|
||||
int shapeAntiAlias;
|
||||
NVGpaint fill;
|
||||
NVGpaint stroke;
|
||||
float strokeWidth;
|
||||
|
|
@ -646,6 +647,7 @@ void nvgReset(NVGcontext* ctx)
|
|||
nvg__setPaintColor(&state->fill, nvgRGBA(255,255,255,255));
|
||||
nvg__setPaintColor(&state->stroke, nvgRGBA(0,0,0,255));
|
||||
state->compositeOperation = nvg__compositeOperationState(NVG_SOURCE_OVER);
|
||||
state->shapeAntiAlias = 1;
|
||||
state->strokeWidth = 1.0f;
|
||||
state->miterLimit = 10.0f;
|
||||
state->lineCap = NVG_BUTT;
|
||||
|
|
@ -665,6 +667,12 @@ void nvgReset(NVGcontext* ctx)
|
|||
}
|
||||
|
||||
// State setting
|
||||
void nvgShapeAntiAlias(NVGcontext* ctx, int enabled)
|
||||
{
|
||||
NVGstate* state = nvg__getState(ctx);
|
||||
state->shapeAntiAlias = enabled;
|
||||
}
|
||||
|
||||
void nvgStrokeWidth(NVGcontext* ctx, float width)
|
||||
{
|
||||
NVGstate* state = nvg__getState(ctx);
|
||||
|
|
@ -2203,7 +2211,7 @@ void nvgFill(NVGcontext* ctx)
|
|||
int i;
|
||||
|
||||
nvg__flattenPaths(ctx);
|
||||
if (ctx->params.edgeAntiAlias)
|
||||
if (ctx->params.edgeAntiAlias && state->shapeAntiAlias)
|
||||
nvg__expandFill(ctx, ctx->fringeWidth, NVG_MITER, 2.4f);
|
||||
else
|
||||
nvg__expandFill(ctx, 0.0f, NVG_MITER, 2.4f);
|
||||
|
|
@ -2248,7 +2256,7 @@ void nvgStroke(NVGcontext* 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);
|
||||
else
|
||||
nvg__expandStroke(ctx, strokeWidth*0.5f, state->lineCap, state->lineJoin, state->miterLimit);
|
||||
|
|
|
|||
|
|
@ -238,6 +238,9 @@ void nvgReset(NVGcontext* ctx);
|
|||
//
|
||||
// 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.
|
||||
void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue