Browse Source

Import alpha/tint stuff from VCV

pull/338/head
falkTX 3 years ago
parent
commit
23f89562ac
3 changed files with 50 additions and 13 deletions
  1. +1
    -0
      dgl/src/NanoVG.cpp
  2. +44
    -12
      dgl/src/nanovg/nanovg.c
  3. +5
    -1
      dgl/src/nanovg/nanovg.h

+ 1
- 0
dgl/src/NanoVG.cpp View File

@@ -83,6 +83,7 @@ DGL_EXT(PFNGLUNIFORMBLOCKBINDINGPROC, glUniformBlockBinding)
#endif

#include "nanovg/nanovg_gl.h"
#include "nanovg/nanovg_gl_utils.h"

#if defined(NANOVG_GL2)
# define nvgCreateGL nvgCreateGL2


+ 44
- 12
dgl/src/nanovg/nanovg.c View File

@@ -74,7 +74,7 @@ struct NVGstate {
float miterLimit;
int lineJoin;
int lineCap;
float alpha;
NVGcolor tint;
float xform[6];
NVGscissor scissor;
float fontSize;
@@ -651,7 +651,7 @@ void nvgReset(NVGcontext* ctx)
state->miterLimit = 10.0f;
state->lineCap = NVG_BUTT;
state->lineJoin = NVG_MITER;
state->alpha = 1.0f;
state->tint = nvgRGBAf(1, 1, 1, 1);
nvgTransformIdentity(state->xform);

state->scissor.extent[0] = -1.0f;
@@ -697,9 +697,34 @@ void nvgLineJoin(NVGcontext* ctx, int join)
}

void nvgGlobalAlpha(NVGcontext* ctx, float alpha)
{
nvgGlobalTint(ctx, nvgRGBAf(1, 1, 1, alpha));
}

void nvgGlobalTint(NVGcontext* ctx, NVGcolor tint)
{
NVGstate* state = nvg__getState(ctx);
state->tint = tint;
}

NVGcolor nvgGetGlobalTint(NVGcontext* ctx)
{
NVGstate* state = nvg__getState(ctx);
return state->tint;
}

void nvgAlpha(NVGcontext* ctx, float alpha)
{
NVGstate* state = nvg__getState(ctx);
state->tint.a *= alpha;
}

void nvgTint(NVGcontext* ctx, NVGcolor tint)
{
NVGstate* state = nvg__getState(ctx);
state->alpha = alpha;
int i;
for (i = 0; i < 4; i++)
state->tint.rgba[i] *= tint.rgba[i];
}

void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f)
@@ -2234,9 +2259,11 @@ void nvgFill(NVGcontext* ctx)
else
nvg__expandFill(ctx, 0.0f, NVG_MITER, 2.4f);

// Apply global alpha
fillPaint.innerColor.a *= state->alpha;
fillPaint.outerColor.a *= state->alpha;
// Apply global tint
for (i = 0; i < 4; i++) {
fillPaint.innerColor.rgba[i] *= state->tint.rgba[i];
fillPaint.outerColor.rgba[i] *= state->tint.rgba[i];
}

ctx->params.renderFill(ctx->params.userPtr, &fillPaint, state->compositeOperation, &state->scissor, ctx->fringeWidth,
ctx->cache->bounds, ctx->cache->paths, ctx->cache->npaths);
@@ -2269,9 +2296,11 @@ void nvgStroke(NVGcontext* ctx)
strokeWidth = ctx->fringeWidth;
}

// Apply global alpha
strokePaint.innerColor.a *= state->alpha;
strokePaint.outerColor.a *= state->alpha;
// Apply global tint
for (i = 0; i < 4; i++) {
strokePaint.innerColor.rgba[i] *= state->tint.rgba[i];
strokePaint.outerColor.rgba[i] *= state->tint.rgba[i];
}

nvg__flattenPaths(ctx);

@@ -2438,15 +2467,18 @@ static int nvg__allocTextAtlas(NVGcontext* ctx)

static void nvg__renderText(NVGcontext* ctx, NVGvertex* verts, int nverts)
{
int i;
NVGstate* state = nvg__getState(ctx);
NVGpaint paint = state->fill;

// Render triangles.
paint.image = ctx->fontImages[ctx->fontImageIdx];

// Apply global alpha
paint.innerColor.a *= state->alpha;
paint.outerColor.a *= state->alpha;
// Apply global tint
for (i = 0; i < 4; i++) {
paint.innerColor.rgba[i] *= state->tint.rgba[i];
paint.outerColor.rgba[i] *= state->tint.rgba[i];
}

ctx->params.renderTriangles(ctx->params.userPtr, &paint, state->compositeOperation, &state->scissor, verts, nverts, ctx->fringeWidth);



+ 5
- 1
dgl/src/nanovg/nanovg.h View File

@@ -279,6 +279,10 @@ void nvgLineJoin(NVGcontext* ctx, int join);
// Sets the transparency applied to all rendered shapes.
// Already transparent paths will get proportionally more transparent as well.
void nvgGlobalAlpha(NVGcontext* ctx, float alpha);
void nvgGlobalTint(NVGcontext* ctx, NVGcolor tint);
NVGcolor nvgGetGlobalTint(NVGcontext* ctx);
void nvgAlpha(NVGcontext* ctx, float alpha);
void nvgTint(NVGcontext* ctx, NVGcolor tint);

//
// Transforms
@@ -385,7 +389,7 @@ int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int

// Creates image from specified image data and texture format.
// Returns handle to the image.
int nvgCreateImageRaw(NVGcontext* ctx, int w, int h, int imageFlags, NVGtexture format, const unsigned char* data);
int nvgCreateImageRaw(NVGcontext* ctx, int w, int h, int imageFlags, enum NVGtexture format, const unsigned char* data);

// Creates image from specified image data.
// Returns handle to the image.


Loading…
Cancel
Save