summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/common/nanovg/nanovg.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/nanovg/nanovg.cpp84
1 files changed, 55 insertions, 29 deletions
diff --git a/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp b/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp
index ae696b3b428..36a87ff7f25 100644
--- a/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp
+++ b/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp
@@ -257,10 +257,14 @@ static void nvg__setDevicePixelRatio(NVGcontext* ctx, float ratio)
static NVGcompositeOperationState nvg__compositeOperationState(int op)
{
- int sfactor = NVG_ONE;
- int dfactor = NVG_ONE_MINUS_SRC_ALPHA;
+ int sfactor, dfactor;
- if (op == NVG_SOURCE_IN)
+ if (op == NVG_SOURCE_OVER)
+ {
+ sfactor = NVG_ONE;
+ dfactor = NVG_ONE_MINUS_SRC_ALPHA;
+ }
+ else if (op == NVG_SOURCE_IN)
{
sfactor = NVG_DST_ALPHA;
dfactor = NVG_ZERO;
@@ -310,6 +314,11 @@ static NVGcompositeOperationState nvg__compositeOperationState(int op)
sfactor = NVG_ONE_MINUS_DST_ALPHA;
dfactor = NVG_ONE_MINUS_SRC_ALPHA;
}
+ else
+ {
+ sfactor = NVG_ONE;
+ dfactor = NVG_ZERO;
+ }
NVGcompositeOperationState state;
state.srcRGB = sfactor;
@@ -431,8 +440,7 @@ void nvgCancelFrame(NVGcontext* ctx)
void nvgEndFrame(NVGcontext* ctx)
{
- NVGstate* state = nvg__getState(ctx);
- ctx->params.renderFlush(ctx->params.userPtr, state->compositeOperation);
+ ctx->params.renderFlush(ctx->params.userPtr);
if (ctx->fontImageIdx != 0) {
int fontImage = ctx->fontImages[ctx->fontImageIdx];
int i, j, iw, ih;
@@ -508,7 +516,7 @@ NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u)
{
int i;
float oneminu;
- NVGcolor cint;
+ NVGcolor cint = {{{0}}};
u = nvg__clampf(u, 0.0f, 1.0f);
oneminu = 1.0f - u;
@@ -2166,22 +2174,31 @@ void nvgRect(NVGcontext* ctx, float x, float y, float w, float h)
void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r)
{
- if (r < 0.1f) {
- nvgRect(ctx, x,y,w,h);
+ nvgRoundedRectVarying(ctx, x, y, w, h, r, r, r, r);
+}
+
+void nvgRoundedRectVarying(NVGcontext* ctx, float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft)
+{
+ if(radTopLeft < 0.1f && radTopRight < 0.1f && radBottomRight < 0.1f && radBottomLeft < 0.1f) {
+ nvgRect(ctx, x, y, w, h);
return;
- }
- else {
- float rx = nvg__minf(r, nvg__absf(w)*0.5f) * nvg__signf(w), ry = nvg__minf(r, nvg__absf(h)*0.5f) * nvg__signf(h);
+ } else {
+ float halfw = nvg__absf(w)*0.5f;
+ float halfh = nvg__absf(h)*0.5f;
+ float rxBL = nvg__minf(radBottomLeft, halfw) * nvg__signf(w), ryBL = nvg__minf(radBottomLeft, halfh) * nvg__signf(h);
+ float rxBR = nvg__minf(radBottomRight, halfw) * nvg__signf(w), ryBR = nvg__minf(radBottomRight, halfh) * nvg__signf(h);
+ float rxTR = nvg__minf(radTopRight, halfw) * nvg__signf(w), ryTR = nvg__minf(radTopRight, halfh) * nvg__signf(h);
+ float rxTL = nvg__minf(radTopLeft, halfw) * nvg__signf(w), ryTL = nvg__minf(radTopLeft, halfh) * nvg__signf(h);
float vals[] = {
- NVG_MOVETO, x, y+ry,
- NVG_LINETO, x, y+h-ry,
- NVG_BEZIERTO, x, y+h-ry*(1-NVG_KAPPA90), x+rx*(1-NVG_KAPPA90), y+h, x+rx, y+h,
- NVG_LINETO, x+w-rx, y+h,
- NVG_BEZIERTO, x+w-rx*(1-NVG_KAPPA90), y+h, x+w, y+h-ry*(1-NVG_KAPPA90), x+w, y+h-ry,
- NVG_LINETO, x+w, y+ry,
- NVG_BEZIERTO, x+w, y+ry*(1-NVG_KAPPA90), x+w-rx*(1-NVG_KAPPA90), y, x+w-rx, y,
- NVG_LINETO, x+rx, y,
- NVG_BEZIERTO, x+rx*(1-NVG_KAPPA90), y, x, y+ry*(1-NVG_KAPPA90), x, y+ry,
+ NVG_MOVETO, x, y + ryTL,
+ NVG_LINETO, x, y + h - ryBL,
+ NVG_BEZIERTO, x, y + h - ryBL*(1 - NVG_KAPPA90), x + rxBL*(1 - NVG_KAPPA90), y + h, x + rxBL, y + h,
+ NVG_LINETO, x + w - rxBR, y + h,
+ NVG_BEZIERTO, x + w - rxBR*(1 - NVG_KAPPA90), y + h, x + w, y + h - ryBR*(1 - NVG_KAPPA90), x + w, y + h - ryBR,
+ NVG_LINETO, x + w, y + ryTR,
+ NVG_BEZIERTO, x + w, y + ryTR*(1 - NVG_KAPPA90), x + w - rxTR*(1 - NVG_KAPPA90), y, x + w - rxTR, y,
+ NVG_LINETO, x + rxTL, y,
+ NVG_BEZIERTO, x + rxTL*(1 - NVG_KAPPA90), y, x, y + ryTL*(1 - NVG_KAPPA90), x, y + ryTL,
NVG_CLOSE
};
nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals));
@@ -2245,7 +2262,7 @@ void nvgFill(NVGcontext* ctx)
fillPaint.innerColor.a *= state->alpha;
fillPaint.outerColor.a *= state->alpha;
- ctx->params.renderFill(ctx->params.userPtr, &fillPaint, &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);
// Count triangles
@@ -2286,7 +2303,7 @@ void nvgStroke(NVGcontext* ctx)
else
nvg__expandStroke(ctx, strokeWidth*0.5f, state->lineCap, state->lineJoin, state->miterLimit);
- ctx->params.renderStroke(ctx->params.userPtr, &strokePaint, &state->scissor, ctx->fringeWidth,
+ ctx->params.renderStroke(ctx->params.userPtr, &strokePaint, state->compositeOperation, &state->scissor, ctx->fringeWidth,
strokeWidth, ctx->cache->paths, ctx->cache->npaths);
// Count triangles
@@ -2434,7 +2451,7 @@ static void nvg__renderText(NVGcontext* ctx, NVGvertex* verts, int nverts)
paint.innerColor.a *= state->alpha;
paint.outerColor.a *= state->alpha;
- ctx->params.renderTriangles(ctx->params.userPtr, &paint, &state->scissor, verts, nverts);
+ ctx->params.renderTriangles(ctx->params.userPtr, &paint, state->compositeOperation, &state->scissor, verts, nverts);
ctx->drawCallCount++;
ctx->textTriCount += nverts/3;
@@ -2587,6 +2604,7 @@ enum NVGcodepointType {
NVG_SPACE,
NVG_NEWLINE,
NVG_CHAR,
+ NVG_CJK_CHAR,
};
int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows)
@@ -2654,7 +2672,15 @@ int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, floa
type = NVG_NEWLINE;
break;
default:
- type = NVG_CHAR;
+ if ((iter.codepoint >= 0x4E00 && iter.codepoint <= 0x9FFF) ||
+ (iter.codepoint >= 0x3000 && iter.codepoint <= 0x30FF) ||
+ (iter.codepoint >= 0xFF00 && iter.codepoint <= 0xFFEF) ||
+ (iter.codepoint >= 0x1100 && iter.codepoint <= 0x11FF) ||
+ (iter.codepoint >= 0x3130 && iter.codepoint <= 0x318F) ||
+ (iter.codepoint >= 0xAC00 && iter.codepoint <= 0xD7AF))
+ type = NVG_CJK_CHAR;
+ else
+ type = NVG_CHAR;
break;
}
@@ -2681,7 +2707,7 @@ int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, floa
} else {
if (rowStart == NULL) {
// Skip white space until the beginning of the line
- if (type == NVG_CHAR) {
+ if (type == NVG_CHAR || type == NVG_CJK_CHAR) {
// The current char is the row so far
rowStartX = iter.x;
rowStart = iter.str;
@@ -2701,26 +2727,26 @@ int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, floa
float nextWidth = iter.nextx - rowStartX;
// track last non-white space character
- if (type == NVG_CHAR) {
+ if (type == NVG_CHAR || type == NVG_CJK_CHAR) {
rowEnd = iter.next;
rowWidth = iter.nextx - rowStartX;
rowMaxX = q.x1 - rowStartX;
}
// track last end of a word
- if (ptype == NVG_CHAR && type == NVG_SPACE) {
+ if (((ptype == NVG_CHAR || ptype == NVG_CJK_CHAR) && type == NVG_SPACE) || type == NVG_CJK_CHAR) {
breakEnd = iter.str;
breakWidth = rowWidth;
breakMaxX = rowMaxX;
}
// track last beginning of a word
- if (ptype == NVG_SPACE && type == NVG_CHAR) {
+ if ((ptype == NVG_SPACE && (type == NVG_CHAR || type == NVG_CJK_CHAR)) || type == NVG_CJK_CHAR) {
wordStart = iter.str;
wordStartX = iter.x;
wordMinX = q.x0 - rowStartX;
}
// Break to new line when a character is beyond break width.
- if (type == NVG_CHAR && nextWidth > breakRowWidth) {
+ if ((type == NVG_CHAR || type == NVG_CJK_CHAR) && nextWidth > breakRowWidth) {
// The run length is too long, need to break to new line.
if (breakEnd == rowStart) {
// The current word is longer than the row length, just break it from here.