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 #endif


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


#if defined(NANOVG_GL2) #if defined(NANOVG_GL2)
# define nvgCreateGL nvgCreateGL2 # define nvgCreateGL nvgCreateGL2


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

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


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


void nvgGlobalAlpha(NVGcontext* ctx, float alpha) 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); 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) 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 else
nvg__expandFill(ctx, 0.0f, NVG_MITER, 2.4f); 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->params.renderFill(ctx->params.userPtr, &fillPaint, state->compositeOperation, &state->scissor, ctx->fringeWidth,
ctx->cache->bounds, ctx->cache->paths, ctx->cache->npaths); ctx->cache->bounds, ctx->cache->paths, ctx->cache->npaths);
@@ -2269,9 +2296,11 @@ void nvgStroke(NVGcontext* ctx)
strokeWidth = ctx->fringeWidth; 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); nvg__flattenPaths(ctx);


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


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


// Render triangles. // Render triangles.
paint.image = ctx->fontImages[ctx->fontImageIdx]; 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); 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. // Sets the transparency applied to all rendered shapes.
// Already transparent paths will get proportionally more transparent as well. // Already transparent paths will get proportionally more transparent as well.
void nvgGlobalAlpha(NVGcontext* ctx, float alpha); 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 // Transforms
@@ -385,7 +389,7 @@ int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int


// Creates image from specified image data and texture format. // Creates image from specified image data and texture format.
// Returns handle to the image. // 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. // Creates image from specified image data.
// Returns handle to the image. // Returns handle to the image.


Loading…
Cancel
Save