JNIEXPORT void JNICALL Java_firststep_internal_NVG__1_1radialGradient (JNIEnv *e, jclass c, jlong ctx, jobject paint, jfloat cx, jfloat cy, jfloat inr, jfloat outr, jobject scol, jobject ecol) { checkJO(scol,"\nRadialGradient was passed NULL start colour\n"); checkJO(ecol,"\nRadialGradient was passed NULL end colour\n"); NVGpaint p = nvgRadialGradient((NVGcontext*)ctx, cx, cy, inr, outr, (NVGcolor)*((NVGcolor*)getBuffPtr(e,scol)), (NVGcolor)*((NVGcolor*)getBuffPtr(e,ecol))); NVGpaint* dp = (NVGpaint*)getBuffPtr(e,paint); *dp = p; }
void Slider::draw(NVGcontext* ctx) { Vector2f center = mPos.cast<float>() + mSize.cast<float>() * 0.5f; Vector2f knobPos(mPos.x() + mValue * mSize.x(), center.y() + 0.5f); float kr = (int)(mSize.y()*0.5f); NVGpaint bg = nvgBoxGradient(ctx, mPos.x(), center.y() - 3 + 1, mSize.x(), 6, 3, 3, Color(0, mEnabled ? 32 : 10), Color(0, mEnabled ? 128 : 210)); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x(), center.y() - 3 + 1, mSize.x(), 6, 2); nvgFillPaint(ctx, bg); nvgFill(ctx); if (mHighlightedRange.second != mHighlightedRange.first) { nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x() + mHighlightedRange.first * mSize.x(), center.y() - 3 + 1, mSize.x() * (mHighlightedRange.second-mHighlightedRange.first), 6, 2); nvgFillColor(ctx, mHighlightColor); nvgFill(ctx); } NVGpaint knobShadow = nvgRadialGradient(ctx, knobPos.x(), knobPos.y(), kr-3, kr+3, Color(0, 64), mTheme->mTransparent); nvgBeginPath(ctx); nvgRect(ctx, knobPos.x() - kr - 5, knobPos.y() - kr - 5, kr*2+10, kr*2+10+3); nvgCircle(ctx, knobPos.x(), knobPos.y(), kr); nvgPathWinding(ctx, NVG_HOLE); nvgFillPaint(ctx, knobShadow); nvgFill(ctx); NVGpaint knob = nvgLinearGradient(ctx, mPos.x(), center.y() - kr, mPos.x(), center.y() + kr, mTheme->mBorderLight, mTheme->mBorderMedium); NVGpaint knobReverse = nvgLinearGradient(ctx, mPos.x(), center.y() - kr, mPos.x(), center.y() + kr, mTheme->mBorderMedium, mTheme->mBorderLight); nvgBeginPath(ctx); nvgCircle(ctx, knobPos.x(), knobPos.y(), kr); nvgStrokeColor(ctx, mTheme->mBorderDark); nvgFillPaint(ctx, knob); nvgStroke(ctx); nvgFill(ctx); nvgBeginPath(ctx); nvgCircle(ctx, knobPos.x(), knobPos.y(), kr/2); nvgFillColor(ctx, Color(150, mEnabled ? 255 : 100)); nvgStrokePaint(ctx, knobReverse); nvgStroke(ctx); nvgFill(ctx); }
void drawSlider(struct NVGcontext* vg, float pos, float x, float y, float w, float h) { struct NVGpaint bg, knob; float cy = y+(int)(h*0.5f); float kr = (float)( (int)(h*0.25f) ); nvgSave(vg); // nvgClearState(vg); // Slot bg = nvgBoxGradient(vg, x,cy-2+1, w,4, 2,2, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,128) ); nvgBeginPath(vg); nvgRoundedRect(vg, x,cy-2, w,4, 2); nvgFillPaint(vg, bg); nvgFill(vg); // Knob Shadow bg = nvgRadialGradient(vg, x+(int)(pos*w),cy+1, kr-3,kr+3, nvgRGBA(0,0,0,64), nvgRGBA(0,0,0,0) ); nvgBeginPath(vg); nvgRect(vg, x+(int)(pos*w)-kr-5,cy-kr-5,kr*2+5+5,kr*2+5+5+3); nvgCircle(vg, x+(int)(pos*w),cy, kr); nvgPathWinding(vg, NVG_HOLE); nvgFillPaint(vg, bg); nvgFill(vg); // Knob knob = nvgLinearGradient(vg, x,cy-kr,x,cy+kr, nvgRGBA(255,255,255,16), nvgRGBA(0,0,0,16) ); nvgBeginPath(vg); nvgCircle(vg, x+(int)(pos*w),cy, kr-1); nvgFillColor(vg, nvgRGBA(40,43,48,255) ); nvgFill(vg); nvgFillPaint(vg, knob); nvgFill(vg); nvgBeginPath(vg); nvgCircle(vg, x+(int)(pos*w),cy, kr-0.5f); nvgStrokeColor(vg, nvgRGBA(0,0,0,92) ); nvgStroke(vg); nvgRestore(vg); }
NVGpaint NanoVG::radialGradient( float cx, float cy, float inr, float outr, NVGcolor icol, NVGcolor ocol ) { return nvgRadialGradient( m_context(), cx, cy, inr, outr, icol, ocol ); }
void drawColorwheel(struct NVGcontext* vg, float x, float y, float w, float h, float t) { int i; float r0, r1, ax,ay, bx,by, cx,cy, aeps, r; float hue = sinf(t * 0.12f); struct NVGpaint paint; nvgSave(vg); /* nvgBeginPath(vg); nvgRect(vg, x,y,w,h); nvgFillColor(vg, nvgRGBA(255,0,0,128) ); nvgFill(vg);*/ cx = x + w*0.5f; cy = y + h*0.5f; r1 = (w < h ? w : h) * 0.5f - 5.0f; r0 = r1 - 20.0f; aeps = 0.5f / r1; // half a pixel arc length in radians (2pi cancels out). for (i = 0; i < 6; i++) { float a0 = (float)i / 6.0f * NVG_PI * 2.0f - aeps; float a1 = (float)(i+1.0f) / 6.0f * NVG_PI * 2.0f + aeps; 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, nvgHSLA(a0/(NVG_PI*2),1.0f,0.55f,255), nvgHSLA(a1/(NVG_PI*2),1.0f,0.55f,255) ); nvgFillPaint(vg, paint); nvgFill(vg); } nvgBeginPath(vg); nvgCircle(vg, cx,cy, r0-0.5f); nvgCircle(vg, cx,cy, r1+0.5f); nvgStrokeColor(vg, nvgRGBA(0,0,0,64) ); nvgStrokeWidth(vg, 1.0f); nvgStroke(vg); // Selector nvgSave(vg); nvgTranslate(vg, cx,cy); nvgRotate(vg, hue*NVG_PI*2); // Marker on nvgStrokeWidth(vg, 2.0f); nvgBeginPath(vg); nvgRect(vg, r0-1,-3,r1-r0+2,6); nvgStrokeColor(vg, nvgRGBA(255,255,255,192) ); nvgStroke(vg); paint = nvgBoxGradient(vg, r0-3,-5,r1-r0+6,10, 2,4, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0) ); nvgBeginPath(vg); nvgRect(vg, r0-2-10,-4-10,r1-r0+4+20,8+20); nvgRect(vg, r0-2,-4,r1-r0+4,8); nvgPathWinding(vg, NVG_HOLE); nvgFillPaint(vg, paint); nvgFill(vg); // Center triangle r = r0 - 6; ax = cosf(120.0f/180.0f*NVG_PI) * r; ay = sinf(120.0f/180.0f*NVG_PI) * r; bx = cosf(-120.0f/180.0f*NVG_PI) * r; by = sinf(-120.0f/180.0f*NVG_PI) * r; nvgBeginPath(vg); nvgMoveTo(vg, r,0); nvgLineTo(vg, ax,ay); nvgLineTo(vg, bx,by); nvgClosePath(vg); paint = nvgLinearGradient(vg, r,0, ax,ay, nvgHSLA(hue,1.0f,0.5f,255), nvgRGBA(255,255,255,255) ); nvgFillPaint(vg, paint); nvgFill(vg); paint = nvgLinearGradient(vg, (r+ax)*0.5f,(0+ay)*0.5f, bx,by, nvgRGBA(0,0,0,0), nvgRGBA(0,0,0,255) ); nvgFillPaint(vg, paint); nvgFill(vg); nvgStrokeColor(vg, nvgRGBA(0,0,0,64) ); nvgStroke(vg); // Select circle on triangle ax = cosf(120.0f/180.0f*NVG_PI) * r*0.3f; ay = sinf(120.0f/180.0f*NVG_PI) * r*0.4f; nvgStrokeWidth(vg, 2.0f); nvgBeginPath(vg); nvgCircle(vg, ax,ay,5); nvgStrokeColor(vg, nvgRGBA(255,255,255,192) ); nvgStroke(vg); paint = nvgRadialGradient(vg, ax,ay, 7,9, nvgRGBA(0,0,0,64), nvgRGBA(0,0,0,0) ); nvgBeginPath(vg); nvgRect(vg, ax-20,ay-20,40,40); nvgCircle(vg, ax,ay,7); nvgPathWinding(vg, NVG_HOLE); nvgFillPaint(vg, paint); nvgFill(vg); nvgRestore(vg); nvgRestore(vg); }
void drawGraph(struct NVGcontext* vg, float x, float y, float w, float h, float t) { struct NVGpaint bg; float samples[6]; float sx[6], sy[6]; float dx = w/5.0f; int i; samples[0] = (1+sinf(t*1.2345f+cosf(t*0.33457f)*0.44f) )*0.5f; samples[1] = (1+sinf(t*0.68363f+cosf(t*1.3f)*1.55f) )*0.5f; samples[2] = (1+sinf(t*1.1642f+cosf(t*0.33457f)*1.24f) )*0.5f; samples[3] = (1+sinf(t*0.56345f+cosf(t*1.63f)*0.14f) )*0.5f; samples[4] = (1+sinf(t*1.6245f+cosf(t*0.254f)*0.3f) )*0.5f; samples[5] = (1+sinf(t*0.345f+cosf(t*0.03f)*0.6f) )*0.5f; for (i = 0; i < 6; i++) { sx[i] = x+i*dx; sy[i] = y+h*samples[i]*0.8f; } // Graph background bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(0,160,192,0), nvgRGBA(0,160,192,64) ); nvgBeginPath(vg); nvgMoveTo(vg, sx[0], sy[0]); for (i = 1; i < 6; i++) nvgBezierTo(vg, sx[i-1]+dx*0.5f,sy[i-1], sx[i]-dx*0.5f,sy[i], sx[i],sy[i]); nvgLineTo(vg, x+w, y+h); nvgLineTo(vg, x, y+h); nvgFillPaint(vg, bg); nvgFill(vg); // Graph line nvgBeginPath(vg); nvgMoveTo(vg, sx[0], sy[0]+2); for (i = 1; i < 6; i++) nvgBezierTo(vg, sx[i-1]+dx*0.5f,sy[i-1]+2, sx[i]-dx*0.5f,sy[i]+2, sx[i],sy[i]+2); nvgStrokeColor(vg, nvgRGBA(0,0,0,32) ); nvgStrokeWidth(vg, 3.0f); nvgStroke(vg); nvgBeginPath(vg); nvgMoveTo(vg, sx[0], sy[0]); for (i = 1; i < 6; i++) nvgBezierTo(vg, sx[i-1]+dx*0.5f,sy[i-1], sx[i]-dx*0.5f,sy[i], sx[i],sy[i]); nvgStrokeColor(vg, nvgRGBA(0,160,192,255) ); nvgStrokeWidth(vg, 3.0f); nvgStroke(vg); // Graph sample pos for (i = 0; i < 6; i++) { bg = nvgRadialGradient(vg, sx[i],sy[i]+2, 3.0f,8.0f, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,0) ); nvgBeginPath(vg); nvgRect(vg, sx[i]-10, sy[i]-10+2, 20,20); nvgFillPaint(vg, bg); nvgFill(vg); } nvgBeginPath(vg); for (i = 0; i < 6; i++) nvgCircle(vg, sx[i], sy[i], 4.0f); nvgFillColor(vg, nvgRGBA(0,160,192,255) ); nvgFill(vg); nvgBeginPath(vg); for (i = 0; i < 6; i++) nvgCircle(vg, sx[i], sy[i], 2.0f); nvgFillColor(vg, nvgRGBA(220,220,220,255) ); nvgFill(vg); nvgStrokeWidth(vg, 1.0f); }
void drawEyes(struct NVGcontext* vg, float x, float y, float w, float h, float mx, float my, float t) { struct NVGpaint gloss, bg; float ex = w *0.23f; float ey = h * 0.5f; float lx = x + ex; float ly = y + ey; float rx = x + w - ex; float ry = y + ey; float dx,dy,d; float br = (ex < ey ? ex : ey) * 0.5f; float blink = 1 - powf(sinf(t*0.5f),200)*0.8f; bg = nvgLinearGradient(vg, x,y+h*0.5f,x+w*0.1f,y+h, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,16) ); nvgBeginPath(vg); nvgEllipse(vg, lx+3.0f,ly+16.0f, ex,ey); nvgEllipse(vg, rx+3.0f,ry+16.0f, ex,ey); nvgFillPaint(vg, bg); nvgFill(vg); bg = nvgLinearGradient(vg, x,y+h*0.25f,x+w*0.1f,y+h, nvgRGBA(220,220,220,255), nvgRGBA(128,128,128,255) ); nvgBeginPath(vg); nvgEllipse(vg, lx,ly, ex,ey); nvgEllipse(vg, rx,ry, ex,ey); nvgFillPaint(vg, bg); nvgFill(vg); dx = (mx - rx) / (ex * 10); dy = (my - ry) / (ey * 10); d = sqrtf(dx*dx+dy*dy); if (d > 1.0f) { dx /= d; dy /= d; } dx *= ex*0.4f; dy *= ey*0.5f; nvgBeginPath(vg); nvgEllipse(vg, lx+dx,ly+dy+ey*0.25f*(1-blink), br,br*blink); nvgFillColor(vg, nvgRGBA(32,32,32,255) ); nvgFill(vg); dx = (mx - rx) / (ex * 10); dy = (my - ry) / (ey * 10); d = sqrtf(dx*dx+dy*dy); if (d > 1.0f) { dx /= d; dy /= d; } dx *= ex*0.4f; dy *= ey*0.5f; nvgBeginPath(vg); nvgEllipse(vg, rx+dx,ry+dy+ey*0.25f*(1-blink), br,br*blink); nvgFillColor(vg, nvgRGBA(32,32,32,255) ); nvgFill(vg); gloss = nvgRadialGradient(vg, lx-ex*0.25f,ly-ey*0.5f, ex*0.1f,ex*0.75f, nvgRGBA(255,255,255,128), nvgRGBA(255,255,255,0) ); nvgBeginPath(vg); nvgEllipse(vg, lx,ly, ex,ey); nvgFillPaint(vg, gloss); nvgFill(vg); gloss = nvgRadialGradient(vg, rx-ex*0.25f,ry-ey*0.5f, ex*0.1f,ex*0.75f, nvgRGBA(255,255,255,128), nvgRGBA(255,255,255,0) ); nvgBeginPath(vg); nvgEllipse(vg, rx,ry, ex,ey); nvgFillPaint(vg, gloss); nvgFill(vg); }