|
@@ -20,8 +20,13 @@ |
|
|
#define ICON_LOGIN 0xE740 |
|
|
#define ICON_LOGIN 0xE740 |
|
|
#define ICON_TRASH 0xE729 |
|
|
#define ICON_TRASH 0xE729 |
|
|
|
|
|
|
|
|
|
|
|
//static float minf(float a, float b) { return a < b ? a : b; } |
|
|
|
|
|
static float maxf(float a, float b) { return a > b ? a : b; } |
|
|
|
|
|
//static float absf(float a) { return a >= 0.0f ? a : -a; } |
|
|
|
|
|
static float clampf(float a, float mn, float mx) { return a < mn ? mn : (a > mx ? mx : a); } |
|
|
|
|
|
|
|
|
// Returns 1 if col.rgba is 0.0f,0.0f,0.0f,0.0f, 0 otherwise |
|
|
// Returns 1 if col.rgba is 0.0f,0.0f,0.0f,0.0f, 0 otherwise |
|
|
int isBlack( struct NVGcolor col ) |
|
|
|
|
|
|
|
|
int isBlack(NVGcolor col) |
|
|
{ |
|
|
{ |
|
|
if( col.r == 0.0f && col.g == 0.0f && col.b == 0.0f && col.a == 0.0f ) |
|
|
if( col.r == 0.0f && col.g == 0.0f && col.b == 0.0f && col.a == 0.0f ) |
|
|
{ |
|
|
{ |
|
@@ -52,11 +57,11 @@ static char* cpToUTF8(int cp, char* str) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void drawWindow(struct NVGcontext* vg, const char* title, float x, float y, float w, float h) |
|
|
|
|
|
|
|
|
void drawWindow(NVGcontext* vg, const char* title, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
float cornerRadius = 3.0f; |
|
|
float cornerRadius = 3.0f; |
|
|
struct NVGpaint shadowPaint; |
|
|
|
|
|
struct NVGpaint headerPaint; |
|
|
|
|
|
|
|
|
NVGpaint shadowPaint; |
|
|
|
|
|
NVGpaint headerPaint; |
|
|
|
|
|
|
|
|
nvgSave(vg); |
|
|
nvgSave(vg); |
|
|
// nvgClearState(vg); |
|
|
// nvgClearState(vg); |
|
@@ -104,9 +109,9 @@ void drawWindow(struct NVGcontext* vg, const char* title, float x, float y, floa |
|
|
nvgRestore(vg); |
|
|
nvgRestore(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawSearchBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
|
|
|
|
|
|
void drawSearchBox(NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
struct NVGpaint bg; |
|
|
|
|
|
|
|
|
NVGpaint bg; |
|
|
char icon[8]; |
|
|
char icon[8]; |
|
|
float cornerRadius = h/2-1; |
|
|
float cornerRadius = h/2-1; |
|
|
|
|
|
|
|
@@ -142,9 +147,9 @@ void drawSearchBox(struct NVGcontext* vg, const char* text, float x, float y, fl |
|
|
nvgText(vg, x+w-h*0.55f, y+h*0.55f, cpToUTF8(ICON_CIRCLED_CROSS,icon), NULL); |
|
|
nvgText(vg, x+w-h*0.55f, y+h*0.55f, cpToUTF8(ICON_CIRCLED_CROSS,icon), NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawDropDown(struct NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
|
|
|
|
|
|
void drawDropDown(NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
struct NVGpaint bg; |
|
|
|
|
|
|
|
|
NVGpaint bg; |
|
|
char icon[8]; |
|
|
char icon[8]; |
|
|
float cornerRadius = 4.0f; |
|
|
float cornerRadius = 4.0f; |
|
|
|
|
|
|
|
@@ -172,7 +177,7 @@ void drawDropDown(struct NVGcontext* vg, const char* text, float x, float y, flo |
|
|
nvgText(vg, x+w-h*0.5f, y+h*0.5f, cpToUTF8(ICON_CHEVRON_RIGHT,icon), NULL); |
|
|
nvgText(vg, x+w-h*0.5f, y+h*0.5f, cpToUTF8(ICON_CHEVRON_RIGHT,icon), NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawLabel(struct NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
|
|
|
|
|
|
void drawLabel(NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
NVG_NOTUSED(w); |
|
|
NVG_NOTUSED(w); |
|
|
|
|
|
|
|
@@ -184,9 +189,9 @@ void drawLabel(struct NVGcontext* vg, const char* text, float x, float y, float |
|
|
nvgText(vg, x,y+h*0.5f,text, NULL); |
|
|
nvgText(vg, x,y+h*0.5f,text, NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawEditBoxBase(struct NVGcontext* vg, float x, float y, float w, float h) |
|
|
|
|
|
|
|
|
void drawEditBoxBase(NVGcontext* vg, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
struct NVGpaint bg; |
|
|
|
|
|
|
|
|
NVGpaint bg; |
|
|
// Edit |
|
|
// Edit |
|
|
bg = nvgBoxGradient(vg, x+1,y+1+1.5f, w-2,h-2, 3,4, nvgRGBA(255,255,255,32), nvgRGBA(32,32,32,32)); |
|
|
bg = nvgBoxGradient(vg, x+1,y+1+1.5f, w-2,h-2, 3,4, nvgRGBA(255,255,255,32), nvgRGBA(32,32,32,32)); |
|
|
nvgBeginPath(vg); |
|
|
nvgBeginPath(vg); |
|
@@ -200,7 +205,7 @@ void drawEditBoxBase(struct NVGcontext* vg, float x, float y, float w, float h) |
|
|
nvgStroke(vg); |
|
|
nvgStroke(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawEditBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
|
|
|
|
|
|
void drawEditBox(NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
drawEditBoxBase(vg, x,y, w,h); |
|
|
drawEditBoxBase(vg, x,y, w,h); |
|
@@ -212,7 +217,7 @@ void drawEditBox(struct NVGcontext* vg, const char* text, float x, float y, floa |
|
|
nvgText(vg, x+h*0.3f,y+h*0.5f,text, NULL); |
|
|
nvgText(vg, x+h*0.3f,y+h*0.5f,text, NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawEditBoxNum(struct NVGcontext* vg, |
|
|
|
|
|
|
|
|
void drawEditBoxNum(NVGcontext* vg, |
|
|
const char* text, const char* units, float x, float y, float w, float h) |
|
|
const char* text, const char* units, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
float uw; |
|
|
float uw; |
|
@@ -234,9 +239,9 @@ void drawEditBoxNum(struct NVGcontext* vg, |
|
|
nvgText(vg, x+w-uw-h*0.5f,y+h*0.5f,text, NULL); |
|
|
nvgText(vg, x+w-uw-h*0.5f,y+h*0.5f,text, NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawCheckBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
|
|
|
|
|
|
void drawCheckBox(NVGcontext* vg, const char* text, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
struct NVGpaint bg; |
|
|
|
|
|
|
|
|
NVGpaint bg; |
|
|
char icon[8]; |
|
|
char icon[8]; |
|
|
NVG_NOTUSED(w); |
|
|
NVG_NOTUSED(w); |
|
|
|
|
|
|
|
@@ -260,9 +265,9 @@ void drawCheckBox(struct NVGcontext* vg, const char* text, float x, float y, flo |
|
|
nvgText(vg, x+9+2, y+h*0.5f, cpToUTF8(ICON_CHECK,icon), NULL); |
|
|
nvgText(vg, x+9+2, y+h*0.5f, cpToUTF8(ICON_CHECK,icon), NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawButton(struct NVGcontext* vg, int preicon, const char* text, float x, float y, float w, float h, struct NVGcolor col) |
|
|
|
|
|
|
|
|
void drawButton(NVGcontext* vg, int preicon, const char* text, float x, float y, float w, float h, NVGcolor col) |
|
|
{ |
|
|
{ |
|
|
struct NVGpaint bg; |
|
|
|
|
|
|
|
|
NVGpaint bg; |
|
|
char icon[8]; |
|
|
char icon[8]; |
|
|
float cornerRadius = 4.0f; |
|
|
float cornerRadius = 4.0f; |
|
|
float tw = 0, iw = 0; |
|
|
float tw = 0, iw = 0; |
|
@@ -309,9 +314,9 @@ void drawButton(struct NVGcontext* vg, int preicon, const char* text, float x, f |
|
|
nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f,text, NULL); |
|
|
nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f,text, NULL); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawSlider(struct NVGcontext* vg, float pos, float x, float y, float w, float h) |
|
|
|
|
|
|
|
|
void drawSlider(NVGcontext* vg, float pos, float x, float y, float w, float h) |
|
|
{ |
|
|
{ |
|
|
struct NVGpaint bg, knob; |
|
|
|
|
|
|
|
|
NVGpaint bg, knob; |
|
|
float cy = y+(int)(h*0.5f); |
|
|
float cy = y+(int)(h*0.5f); |
|
|
float kr = (int)(h*0.25f); |
|
|
float kr = (int)(h*0.25f); |
|
|
|
|
|
|
|
@@ -351,9 +356,9 @@ void drawSlider(struct NVGcontext* vg, float pos, float x, float y, float w, flo |
|
|
nvgRestore(vg); |
|
|
nvgRestore(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawEyes(struct NVGcontext* vg, float x, float y, float w, float h, float mx, float my, float t) |
|
|
|
|
|
|
|
|
void drawEyes(NVGcontext* vg, float x, float y, float w, float h, float mx, float my, float t) |
|
|
{ |
|
|
{ |
|
|
struct NVGpaint gloss, bg; |
|
|
|
|
|
|
|
|
NVGpaint gloss, bg; |
|
|
float ex = w *0.23f; |
|
|
float ex = w *0.23f; |
|
|
float ey = h * 0.5f; |
|
|
float ey = h * 0.5f; |
|
|
float lx = x + ex; |
|
|
float lx = x + ex; |
|
@@ -417,9 +422,9 @@ void drawEyes(struct NVGcontext* vg, float x, float y, float w, float h, float m |
|
|
nvgFill(vg); |
|
|
nvgFill(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawGraph(struct NVGcontext* vg, float x, float y, float w, float h, float t) |
|
|
|
|
|
|
|
|
void drawGraph(NVGcontext* vg, float x, float y, float w, float h, float t) |
|
|
{ |
|
|
{ |
|
|
struct NVGpaint bg; |
|
|
|
|
|
|
|
|
NVGpaint bg; |
|
|
float samples[6]; |
|
|
float samples[6]; |
|
|
float sx[6], sy[6]; |
|
|
float sx[6], sy[6]; |
|
|
float dx = w/5.0f; |
|
|
float dx = w/5.0f; |
|
@@ -488,10 +493,36 @@ void drawGraph(struct NVGcontext* vg, float x, float y, float w, float h, float |
|
|
nvgStrokeWidth(vg, 1.0f); |
|
|
nvgStrokeWidth(vg, 1.0f); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, const int* images, int nimages, float t) |
|
|
|
|
|
|
|
|
void drawSpinner(NVGcontext* vg, float cx, float cy, float r, float t) |
|
|
|
|
|
{ |
|
|
|
|
|
float a0 = 0.0f + t*6; |
|
|
|
|
|
float a1 = NVG_PI + t*6; |
|
|
|
|
|
float r0 = r; |
|
|
|
|
|
float r1 = r * 0.75f; |
|
|
|
|
|
float ax,ay, bx,by; |
|
|
|
|
|
NVGpaint paint; |
|
|
|
|
|
|
|
|
|
|
|
nvgSave(vg); |
|
|
|
|
|
|
|
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
|
nvgArc(vg, cx,cy, r0, a0, a1, NVG_CW); |
|
|
|
|
|
nvgArc(vg, cx,cy, r1, a1, a0, NVG_CCW); |
|
|
|
|
|
nvgClosePath(vg); |
|
|
|
|
|
ax = cx + cosf(a0) * (r0+r1)*0.5f; |
|
|
|
|
|
ay = cy + sinf(a0) * (r0+r1)*0.5f; |
|
|
|
|
|
bx = cx + cosf(a1) * (r0+r1)*0.5f; |
|
|
|
|
|
by = cy + sinf(a1) * (r0+r1)*0.5f; |
|
|
|
|
|
paint = nvgLinearGradient(vg, ax,ay, bx,by, nvgRGBA(0,0,0,0), nvgRGBA(0,0,0,128)); |
|
|
|
|
|
nvgFillPaint(vg, paint); |
|
|
|
|
|
nvgFill(vg); |
|
|
|
|
|
|
|
|
|
|
|
nvgRestore(vg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void drawThumbnails(NVGcontext* vg, float x, float y, float w, float h, const int* images, int nimages, float t) |
|
|
{ |
|
|
{ |
|
|
float cornerRadius = 3.0f; |
|
|
float cornerRadius = 3.0f; |
|
|
struct NVGpaint shadowPaint, imgPaint, fadePaint; |
|
|
|
|
|
|
|
|
NVGpaint shadowPaint, imgPaint, fadePaint; |
|
|
float ix,iy,iw,ih; |
|
|
float ix,iy,iw,ih; |
|
|
float thumb = 60.0f; |
|
|
float thumb = 60.0f; |
|
|
float arry = 30.5f; |
|
|
float arry = 30.5f; |
|
@@ -499,7 +530,8 @@ void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, c |
|
|
float stackh = (nimages/2) * (thumb+10) + 10; |
|
|
float stackh = (nimages/2) * (thumb+10) + 10; |
|
|
int i; |
|
|
int i; |
|
|
float u = (1+cosf(t*0.5f))*0.5f; |
|
|
float u = (1+cosf(t*0.5f))*0.5f; |
|
|
float scrollh; |
|
|
|
|
|
|
|
|
float u2 = (1-cosf(t*0.2f))*0.5f; |
|
|
|
|
|
float scrollh, dv; |
|
|
|
|
|
|
|
|
nvgSave(vg); |
|
|
nvgSave(vg); |
|
|
// nvgClearState(vg); |
|
|
// nvgClearState(vg); |
|
@@ -526,8 +558,10 @@ void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, c |
|
|
nvgScissor(vg, x,y,w,h); |
|
|
nvgScissor(vg, x,y,w,h); |
|
|
nvgTranslate(vg, 0, -(stackh - h)*u); |
|
|
nvgTranslate(vg, 0, -(stackh - h)*u); |
|
|
|
|
|
|
|
|
|
|
|
dv = 1.0f / (float)(nimages-1); |
|
|
|
|
|
|
|
|
for (i = 0; i < nimages; i++) { |
|
|
for (i = 0; i < nimages; i++) { |
|
|
float tx, ty; |
|
|
|
|
|
|
|
|
float tx, ty, v, a; |
|
|
tx = x+10; |
|
|
tx = x+10; |
|
|
ty = y+10; |
|
|
ty = y+10; |
|
|
tx += (i%2) * (thumb+10); |
|
|
tx += (i%2) * (thumb+10); |
|
@@ -544,7 +578,14 @@ void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, c |
|
|
ix = -(iw-thumb)*0.5f; |
|
|
ix = -(iw-thumb)*0.5f; |
|
|
iy = 0; |
|
|
iy = 0; |
|
|
} |
|
|
} |
|
|
imgPaint = nvgImagePattern(vg, tx+ix, ty+iy, iw,ih, 0.0f/180.0f*NVG_PI, images[i], 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v = i * dv; |
|
|
|
|
|
a = clampf((u2-v) / dv, 0, 1); |
|
|
|
|
|
|
|
|
|
|
|
if (a < 1.0f) |
|
|
|
|
|
drawSpinner(vg, tx+thumb/2,ty+thumb/2, thumb*0.25f, t); |
|
|
|
|
|
|
|
|
|
|
|
imgPaint = nvgImagePattern(vg, tx+ix, ty+iy, iw,ih, 0.0f/180.0f*NVG_PI, images[i], a); |
|
|
nvgBeginPath(vg); |
|
|
nvgBeginPath(vg); |
|
|
nvgRoundedRect(vg, tx,ty, thumb,thumb, 5); |
|
|
nvgRoundedRect(vg, tx,ty, thumb,thumb, 5); |
|
|
nvgFillPaint(vg, imgPaint); |
|
|
nvgFillPaint(vg, imgPaint); |
|
@@ -598,12 +639,12 @@ void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, c |
|
|
nvgRestore(vg); |
|
|
nvgRestore(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawColorwheel(struct NVGcontext* vg, float x, float y, float w, float h, float t) |
|
|
|
|
|
|
|
|
void drawColorwheel(NVGcontext* vg, float x, float y, float w, float h, float t) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
float r0, r1, ax,ay, bx,by, cx,cy, aeps, r; |
|
|
float r0, r1, ax,ay, bx,by, cx,cy, aeps, r; |
|
|
float hue = sinf(t * 0.12f); |
|
|
float hue = sinf(t * 0.12f); |
|
|
struct NVGpaint paint; |
|
|
|
|
|
|
|
|
NVGpaint paint; |
|
|
|
|
|
|
|
|
nvgSave(vg); |
|
|
nvgSave(vg); |
|
|
|
|
|
|
|
@@ -703,7 +744,7 @@ void drawColorwheel(struct NVGcontext* vg, float x, float y, float w, float h, f |
|
|
nvgRestore(vg); |
|
|
nvgRestore(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawLines(struct NVGcontext* vg, float x, float y, float w, float h, float t) |
|
|
|
|
|
|
|
|
void drawLines(NVGcontext* vg, float x, float y, float w, float h, float t) |
|
|
{ |
|
|
{ |
|
|
int i, j; |
|
|
int i, j; |
|
|
float pad = 5.0f, s = w/9.0f - pad*2; |
|
|
float pad = 5.0f, s = w/9.0f - pad*2; |
|
@@ -757,7 +798,7 @@ void drawLines(struct NVGcontext* vg, float x, float y, float w, float h, float |
|
|
nvgRestore(vg); |
|
|
nvgRestore(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int loadDemoData(struct NVGcontext* vg, struct DemoData* data) |
|
|
|
|
|
|
|
|
int loadDemoData(NVGcontext* vg, DemoData* data) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
@@ -766,25 +807,25 @@ int loadDemoData(struct NVGcontext* vg, struct DemoData* data) |
|
|
|
|
|
|
|
|
for (i = 0; i < 12; i++) { |
|
|
for (i = 0; i < 12; i++) { |
|
|
char file[128]; |
|
|
char file[128]; |
|
|
snprintf(file, 128, "./nanovg_res/images/image%d.jpg", i+1); |
|
|
|
|
|
data->images[i] = nvgCreateImage(vg, file); |
|
|
|
|
|
|
|
|
snprintf(file, 128, "../example/images/image%d.jpg", i+1); |
|
|
|
|
|
data->images[i] = nvgCreateImage(vg, file, 0); |
|
|
if (data->images[i] == 0) { |
|
|
if (data->images[i] == 0) { |
|
|
printf("Could not load %s.\n", file); |
|
|
printf("Could not load %s.\n", file); |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
data->fontIcons = nvgCreateFont(vg, "icons", "./nanovg_res/entypo.ttf"); |
|
|
|
|
|
|
|
|
data->fontIcons = nvgCreateFont(vg, "icons", "../example/entypo.ttf"); |
|
|
if (data->fontIcons == -1) { |
|
|
if (data->fontIcons == -1) { |
|
|
printf("Could not add font icons.\n"); |
|
|
printf("Could not add font icons.\n"); |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
data->fontNormal = nvgCreateFont(vg, "sans", "./nanovg_res/Roboto-Regular.ttf"); |
|
|
|
|
|
|
|
|
data->fontNormal = nvgCreateFont(vg, "sans", "../example/Roboto-Regular.ttf"); |
|
|
if (data->fontNormal == -1) { |
|
|
if (data->fontNormal == -1) { |
|
|
printf("Could not add font italic.\n"); |
|
|
printf("Could not add font italic.\n"); |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
data->fontBold = nvgCreateFont(vg, "sans-bold", "./nanovg_res/Roboto-Bold.ttf"); |
|
|
|
|
|
|
|
|
data->fontBold = nvgCreateFont(vg, "sans-bold", "../example/Roboto-Bold.ttf"); |
|
|
if (data->fontBold == -1) { |
|
|
if (data->fontBold == -1) { |
|
|
printf("Could not add font bold.\n"); |
|
|
printf("Could not add font bold.\n"); |
|
|
return -1; |
|
|
return -1; |
|
@@ -793,7 +834,7 @@ int loadDemoData(struct NVGcontext* vg, struct DemoData* data) |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void freeDemoData(struct NVGcontext* vg, struct DemoData* data) |
|
|
|
|
|
|
|
|
void freeDemoData(NVGcontext* vg, DemoData* data) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
@@ -804,10 +845,10 @@ void freeDemoData(struct NVGcontext* vg, struct DemoData* data) |
|
|
nvgDeleteImage(vg, data->images[i]); |
|
|
nvgDeleteImage(vg, data->images[i]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawParagraph(struct NVGcontext* vg, float x, float y, float width, float height, float mx, float my) |
|
|
|
|
|
|
|
|
void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, float mx, float my) |
|
|
{ |
|
|
{ |
|
|
struct NVGtextRow rows[3]; |
|
|
|
|
|
struct NVGglyphPosition glyphs[100]; |
|
|
|
|
|
|
|
|
NVGtextRow rows[3]; |
|
|
|
|
|
NVGglyphPosition glyphs[100]; |
|
|
const char* text = "This is longer chunk of text.\n \n Would have used lorem ipsum but she was busy jumping over the lazy dog with the fox and all the men who came to the aid of the party."; |
|
|
const char* text = "This is longer chunk of text.\n \n Would have used lorem ipsum but she was busy jumping over the lazy dog with the fox and all the men who came to the aid of the party."; |
|
|
const char* start; |
|
|
const char* start; |
|
|
const char* end; |
|
|
const char* end; |
|
@@ -815,6 +856,7 @@ void drawParagraph(struct NVGcontext* vg, float x, float y, float width, float h |
|
|
float lineh; |
|
|
float lineh; |
|
|
float caretx, px; |
|
|
float caretx, px; |
|
|
float bounds[4]; |
|
|
float bounds[4]; |
|
|
|
|
|
float a; |
|
|
float gx,gy; |
|
|
float gx,gy; |
|
|
int gutter = 0; |
|
|
int gutter = 0; |
|
|
NVG_NOTUSED(height); |
|
|
NVG_NOTUSED(height); |
|
@@ -833,11 +875,11 @@ void drawParagraph(struct NVGcontext* vg, float x, float y, float width, float h |
|
|
end = text + strlen(text); |
|
|
end = text + strlen(text); |
|
|
while ((nrows = nvgTextBreakLines(vg, start, end, width, rows, 3))) { |
|
|
while ((nrows = nvgTextBreakLines(vg, start, end, width, rows, 3))) { |
|
|
for (i = 0; i < nrows; i++) { |
|
|
for (i = 0; i < nrows; i++) { |
|
|
struct NVGtextRow* row = &rows[i]; |
|
|
|
|
|
|
|
|
NVGtextRow* row = &rows[i]; |
|
|
int hit = mx > x && mx < (x+width) && my >= y && my < (y+lineh); |
|
|
int hit = mx > x && mx < (x+width) && my >= y && my < (y+lineh); |
|
|
|
|
|
|
|
|
nvgBeginPath(vg); |
|
|
nvgBeginPath(vg); |
|
|
nvgFillColor(vg, nvgRGBA(255,255,255,hit?64:8)); |
|
|
|
|
|
|
|
|
nvgFillColor(vg, nvgRGBA(255,255,255,hit?64:16)); |
|
|
nvgRect(vg, x, y, row->width, lineh); |
|
|
nvgRect(vg, x, y, row->width, lineh); |
|
|
nvgFill(vg); |
|
|
nvgFill(vg); |
|
|
|
|
|
|
|
@@ -896,6 +938,14 @@ void drawParagraph(struct NVGcontext* vg, float x, float y, float width, float h |
|
|
nvgTextLineHeight(vg, 1.2f); |
|
|
nvgTextLineHeight(vg, 1.2f); |
|
|
|
|
|
|
|
|
nvgTextBoxBounds(vg, x,y, 150, "Hover your mouse over the text to see calculated caret position.", NULL, bounds); |
|
|
nvgTextBoxBounds(vg, x,y, 150, "Hover your mouse over the text to see calculated caret position.", NULL, bounds); |
|
|
|
|
|
|
|
|
|
|
|
// Fade the tooltip out when close to it. |
|
|
|
|
|
gx = fabsf((mx - (bounds[0]+bounds[2])*0.5f) / (bounds[0] - bounds[2])); |
|
|
|
|
|
gy = fabsf((my - (bounds[1]+bounds[3])*0.5f) / (bounds[1] - bounds[3])); |
|
|
|
|
|
a = maxf(gx, gy) - 0.5f; |
|
|
|
|
|
a = clampf(a, 0, 1); |
|
|
|
|
|
nvgGlobalAlpha(vg, a); |
|
|
|
|
|
|
|
|
nvgBeginPath(vg); |
|
|
nvgBeginPath(vg); |
|
|
nvgFillColor(vg, nvgRGBA(220,220,220,255)); |
|
|
nvgFillColor(vg, nvgRGBA(220,220,220,255)); |
|
|
nvgRoundedRect(vg, bounds[0]-2,bounds[1]-2, (int)(bounds[2]-bounds[0])+4, (int)(bounds[3]-bounds[1])+4, 3); |
|
|
nvgRoundedRect(vg, bounds[0]-2,bounds[1]-2, (int)(bounds[2]-bounds[0])+4, (int)(bounds[3]-bounds[1])+4, 3); |
|
@@ -911,7 +961,7 @@ void drawParagraph(struct NVGcontext* vg, float x, float y, float width, float h |
|
|
nvgRestore(vg); |
|
|
nvgRestore(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawWidths(struct NVGcontext* vg, float x, float y, float width) |
|
|
|
|
|
|
|
|
void drawWidths(NVGcontext* vg, float x, float y, float width) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
@@ -932,8 +982,75 @@ void drawWidths(struct NVGcontext* vg, float x, float y, float width) |
|
|
nvgRestore(vg); |
|
|
nvgRestore(vg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float height, |
|
|
|
|
|
float t, int blowup, struct DemoData* data) |
|
|
|
|
|
|
|
|
void drawCaps(NVGcontext* vg, float x, float y, float width) |
|
|
|
|
|
{ |
|
|
|
|
|
int i; |
|
|
|
|
|
int caps[3] = {NVG_BUTT, NVG_ROUND, NVG_SQUARE}; |
|
|
|
|
|
float lineWidth = 8.0f; |
|
|
|
|
|
|
|
|
|
|
|
nvgSave(vg); |
|
|
|
|
|
|
|
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
|
nvgRect(vg, x-lineWidth/2, y, width+lineWidth, 40); |
|
|
|
|
|
nvgFillColor(vg, nvgRGBA(255,255,255,32)); |
|
|
|
|
|
nvgFill(vg); |
|
|
|
|
|
|
|
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
|
nvgRect(vg, x, y, width, 40); |
|
|
|
|
|
nvgFillColor(vg, nvgRGBA(255,255,255,32)); |
|
|
|
|
|
nvgFill(vg); |
|
|
|
|
|
|
|
|
|
|
|
nvgStrokeWidth(vg, lineWidth); |
|
|
|
|
|
for (i = 0; i < 3; i++) { |
|
|
|
|
|
nvgLineCap(vg, caps[i]); |
|
|
|
|
|
nvgStrokeColor(vg, nvgRGBA(0,0,0,255)); |
|
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
|
nvgMoveTo(vg, x, y + i*10 + 5); |
|
|
|
|
|
nvgLineTo(vg, x+width, y + i*10 + 5); |
|
|
|
|
|
nvgStroke(vg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
nvgRestore(vg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void drawScissor(NVGcontext* vg, float x, float y, float t) |
|
|
|
|
|
{ |
|
|
|
|
|
nvgSave(vg); |
|
|
|
|
|
|
|
|
|
|
|
// Draw first rect and set scissor to it's area. |
|
|
|
|
|
nvgTranslate(vg, x, y); |
|
|
|
|
|
nvgRotate(vg, nvgDegToRad(5)); |
|
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
|
nvgRect(vg, -20,-20,60,40); |
|
|
|
|
|
nvgFillColor(vg, nvgRGBA(255,0,0,255)); |
|
|
|
|
|
nvgFill(vg); |
|
|
|
|
|
nvgScissor(vg, -20,-20,60,40); |
|
|
|
|
|
|
|
|
|
|
|
// Draw second rectangle with offset and rotation. |
|
|
|
|
|
nvgTranslate(vg, 40,0); |
|
|
|
|
|
nvgRotate(vg, t); |
|
|
|
|
|
|
|
|
|
|
|
// Draw the intended second rectangle without any scissoring. |
|
|
|
|
|
nvgSave(vg); |
|
|
|
|
|
nvgResetScissor(vg); |
|
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
|
nvgRect(vg, -20,-10,60,30); |
|
|
|
|
|
nvgFillColor(vg, nvgRGBA(255,128,0,64)); |
|
|
|
|
|
nvgFill(vg); |
|
|
|
|
|
nvgRestore(vg); |
|
|
|
|
|
|
|
|
|
|
|
// Draw second rectangle with combined scissoring. |
|
|
|
|
|
nvgIntersectScissor(vg, -20,-10,60,30); |
|
|
|
|
|
nvgBeginPath(vg); |
|
|
|
|
|
nvgRect(vg, -20,-10,60,30); |
|
|
|
|
|
nvgFillColor(vg, nvgRGBA(255,128,0,255)); |
|
|
|
|
|
nvgFill(vg); |
|
|
|
|
|
|
|
|
|
|
|
nvgRestore(vg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void renderDemo(NVGcontext* vg, float mx, float my, float width, float height, |
|
|
|
|
|
float t, int blowup, DemoData* data) |
|
|
{ |
|
|
{ |
|
|
float x,y,popy; |
|
|
float x,y,popy; |
|
|
|
|
|
|
|
@@ -943,11 +1060,16 @@ void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float he |
|
|
drawColorwheel(vg, width - 300, height - 300, 250.0f, 250.0f, t); |
|
|
drawColorwheel(vg, width - 300, height - 300, 250.0f, 250.0f, t); |
|
|
|
|
|
|
|
|
// Line joints |
|
|
// Line joints |
|
|
drawLines(vg, 50, height-50, 600, 50, t); |
|
|
|
|
|
|
|
|
drawLines(vg, 120, height-50, 600, 50, t); |
|
|
|
|
|
|
|
|
// Line width; |
|
|
|
|
|
|
|
|
// Line caps |
|
|
drawWidths(vg, 10, 50, 30); |
|
|
drawWidths(vg, 10, 50, 30); |
|
|
|
|
|
|
|
|
|
|
|
// Line caps |
|
|
|
|
|
drawCaps(vg, 10, 300, 30); |
|
|
|
|
|
|
|
|
|
|
|
drawScissor(vg, 50, height-80, t); |
|
|
|
|
|
|
|
|
nvgSave(vg); |
|
|
nvgSave(vg); |
|
|
if (blowup) { |
|
|
if (blowup) { |
|
|
nvgRotate(vg, sinf(t*0.3f)*5.0f/180.0f*NVG_PI); |
|
|
nvgRotate(vg, sinf(t*0.3f)*5.0f/180.0f*NVG_PI); |
|
@@ -1065,8 +1187,8 @@ static void flipHorizontal(unsigned char* image, int w, int h, int stride) |
|
|
{ |
|
|
{ |
|
|
int i = 0, j = h-1, k; |
|
|
int i = 0, j = h-1, k; |
|
|
while (i < j) { |
|
|
while (i < j) { |
|
|
unsigned char* ri = &image[i * stride]; |
|
|
|
|
|
unsigned char* rj = &image[j * stride]; |
|
|
|
|
|
|
|
|
unsigned char* ri = &image[i * stride]; |
|
|
|
|
|
unsigned char* rj = &image[j * stride]; |
|
|
for (k = 0; k < w*4; k++) { |
|
|
for (k = 0; k < w*4; k++) { |
|
|
unsigned char t = ri[k]; |
|
|
unsigned char t = ri[k]; |
|
|
ri[k] = rj[k]; |
|
|
ri[k] = rj[k]; |
|
|