void Renderer2D::drawCircle( const attributes_2d& attributes, const float32_t& radius, const float32_t& border, const color_argb& color, const color_argb& borderColor, const Image2D& image, const float32_t& image_alpha, const float32_t& image_pos_x, const float32_t& image_pos_y, const float32_t& image_width, const float32_t& image_height, const float32_t& image_rotation ) { Context2D* context = _context2D; nvgSave( context ); nvgBeginPath( context ); nvgTranslate( context, attributes.position[0], attributes.position[1]); nvgSave( context ); nvgRotate( context, attributes.rotation ); nvgCircle( context, 0, 0, radius * attributes.scale ); if( image != 0 ) { NVGpaint paint = nvgImagePattern( context, image_pos_x-image_width/2, image_pos_y - image_height/2, image_width, image_height, image_rotation, image, image_alpha ); nvgFillPaint( context, paint); } else { nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) ); } nvgFill(context); nvgStrokeColor( context, nvgRGBA( borderColor.r, borderColor.g, borderColor.b, borderColor.a) ); nvgStrokeWidth( context, border ); nvgStroke( context ); nvgRestore( context ); nvgRestore( context ); }
void Renderer2D::drawRectangle( const attributes_2d& attributes, const float32_t& width, const float32_t& height, const float32_t& border, const color_argb& color, const color_argb& borderColor, const Image2D& image, const float32_t& image_alpha, const float32_t& image_pos_x, const float32_t& image_pos_y, const float32_t& image_width, const float32_t& image_height, const float32_t& image_rotation ) { Context2D* context = _context2D; const float32_t sWidth = width * attributes.scale; const float32_t sHeight = height * attributes.scale; nvgSave( context ); nvgBeginPath( context ); nvgTranslate( context, attributes.position[0], attributes.position[1] ); nvgSave( context ); nvgRotate( context, attributes.rotation ); nvgRect( context, -sWidth/2, -sHeight/2, sWidth, sHeight ); if( image != 0 ) { NVGpaint paint = nvgImagePattern( context, (-sWidth/2)+image_pos_x, (-sHeight/2)+image_pos_y, image_width, image_height, image_rotation, image, image_alpha ); nvgFillPaint( context, paint); } else { nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) ); } nvgFill( context ); nvgStrokeColor( context, nvgRGBA( borderColor.r, borderColor.g, borderColor.b, borderColor.a) ); nvgStrokeWidth( context, border ); nvgStroke( context ); nvgRestore( context ); nvgRestore( context ); }
void Renderer2D::drawText( const attributes_2d& attributes,Font2D font, const char* text, const float32_t& fontSize, const color_argb& color, const float32_t& blur, const float32_t& spacing, const float32_t& lineHeight, const TextAlignment& alignment ) { Context2D* context = _context2D; nvgSave( context ); nvgBeginPath( context ); nvgRotate( context, attributes.rotation ); nvgFontSize( context, fontSize * attributes.scale ); nvgFontBlur( context, blur ); nvgTextLetterSpacing(context, spacing); nvgTextLineHeight(context, lineHeight); nvgTextAlign(context, alignment.value ); nvgFontFaceId(context, font); nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) ); nvgFill(context); nvgText(context, attributes.position[0], attributes.position[1], text, NULL); nvgRestore( context ); }
void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float height, float t, int blowup, struct DemoData* data) { float x,y,popy; drawEyes(vg, width - 250, 50, 150, 100, mx, my, t); drawParagraph(vg, width - 450, 50, 150, 100, mx, my); drawGraph(vg, 0, height/2, width, height/2, t); drawColorwheel(vg, width - 300, height - 300, 250.0f, 250.0f, t); // Line joints drawLines(vg, 50, height-50, 600, 50, t); // Line caps drawWidths(vg, 10, 50, 30); // Line caps drawCaps(vg, 10, 300, 30); nvgSave(vg); if (blowup) { nvgRotate(vg, sinf(t*0.3f)*5.0f/180.0f*NVG_PI); nvgScale(vg, 2.0f, 2.0f); } // Widgets drawWindow(vg, "Widgets `n Stuff", 50, 50, 300, 400); x = 60; y = 95; drawSearchBox(vg, "Search", x,y,280,25); y += 40; drawDropDown(vg, "Effects", x,y,280,28); popy = y + 14; y += 45; // Form drawLabel(vg, "Login", x,y, 280,20); y += 25; drawEditBox(vg, "Email", x,y, 280,28); y += 35; drawEditBox(vg, "Password", x,y, 280,28); y += 38; drawCheckBox(vg, "Remember me", x,y, 140,28); drawButton(vg, ICON_LOGIN, "Sign in", x+138, y, 140, 28, nvgRGBA(0,96,128,255)); y += 45; // Slider drawLabel(vg, "Diameter", x,y, 280,20); y += 25; drawEditBoxNum(vg, "123.00", "px", x+180,y, 100,28); drawSlider(vg, 0.4f, x,y, 170,28); y += 55; drawButton(vg, ICON_TRASH, "Delete", x, y, 160, 28, nvgRGBA(128,16,8,255)); drawButton(vg, 0, "Cancel", x+170, y, 110, 28, nvgRGBA(0,0,0,0)); // Thumbnails box drawThumbnails(vg, 365, popy-30, 160, 300, data->images, 12, t); nvgRestore(vg); }
void Renderer2D::drawPath( const attributes_2d& attributes, const float32_t* path, const uint32_t& pathSize, const float32_t& border, const color_argb& color, const color_argb& borderColor, const Image2D& image, const float32_t& image_alpha, const float32_t& image_pos_x, const float32_t& image_pos_y, const float32_t& image_width, const float32_t& image_height, const float32_t& image_rotation ) { Context2D* context = _context2D; if( pathSize < 2 || pathSize % 2 != 0 ) return; nvgSave( context ); nvgBeginPath( context ); nvgTranslate( context, attributes.position[0], attributes.position[1] ); nvgSave( context ); nvgRotate( context, attributes.rotation ); nvgMoveTo( context, path[0], path[1]); for( uint32_t i=2; i<pathSize; i+=2 ) { nvgLineTo( context, path[i] * attributes.scale, path[i+1] * attributes.scale); } nvgClosePath( context ); if( image != 0 ) { NVGpaint paint = nvgImagePattern( context, image_pos_x-image_width/2, image_pos_y-image_height/2, image_width, image_height, image_rotation, image, image_alpha ); nvgFillPaint( context, paint); } else { nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) ); } nvgFill(context); nvgStrokeColor( context, nvgRGBA( borderColor.r, borderColor.g, borderColor.b, borderColor.a) ); nvgStrokeWidth( context, border ); nvgStroke( context ); nvgRestore( context ); nvgRestore( context ); }
void Cursor::draw(AlloyContext* context) const { pixel2 cursor = context->cursorPosition; if (fontSize > 0.0f && context->hasFocus && cursor.x >= 0 && cursor.y >= 0 && cursor.x < context->getScreenWidth() && cursor.y < context->getScreenHeight()) { NVGcontext* nvg = context->nvgContext; nvgTextAlign(nvg, align); nvgSave(nvg); nvgFontFaceId(nvg, context->getFontHandle(fontType)); nvgFontSize(nvg, fontSize); nvgFillColor(nvg, Color(255, 255, 255)); nvgTranslate(nvg, cursor.x+nudge.x, cursor.y+nudge.y); nvgRotate(nvg, angle); const float shift = 1.0f; const char* txt = codeString.c_str(); nvgFillColor(nvg, Color(0, 0, 0)); nvgText(nvg, +shift, 0, txt, nullptr); nvgText(nvg, -shift, 0, txt, nullptr); nvgText(nvg, 0, +shift, txt, nullptr); nvgText(nvg, 0, -shift, txt, nullptr); nvgFillColor(nvg, Color(255, 255, 255)); nvgText(nvg, 0, 0, txt, nullptr); nvgRestore(nvg); } }
void NanoVG::rotate( float angle ) { nvgRotate( m_context(), angle ); }
JNIEXPORT void JNICALL Java_org_lwjgl_nanovg_NanoVG_nnvgRotate(JNIEnv *__env, jclass clazz, jlong ctxAddress, jfloat angle) { NVGcontext *ctx = (NVGcontext *)(intptr_t)ctxAddress; UNUSED_PARAMS(__env, clazz) nvgRotate(ctx, angle); }
void GraphPane::draw(AlloyContext* context) { Region::draw(context); box2px rbounds = getBounds(); NVGcontext* nvg = context->nvgContext; box2px gbounds = rbounds; const float LARGE_TEXT = 18.0f; const float MEDIUM_TEXT = 16.0f; const float SMALL_TEXT = 12.0f; float2 gpos(-1, -1); gbounds.position = pixel2(rbounds.position.x + GRAPH_PADDING, rbounds.position.y + GRAPH_PADDING); gbounds.dimensions = pixel2(rbounds.dimensions.x - GRAPH_PADDING * 2, rbounds.dimensions.y - GRAPH_PADDING * 2); if (graphBounds.dimensions.x < 0 || graphBounds.dimensions.y < 0) { updateGraphBounds(); } nvgBeginPath(nvg); nvgRoundedRect(nvg, gbounds.position.x - 2, gbounds.position.y - 2, gbounds.dimensions.x + 4, gbounds.dimensions.y + 4, context->theme.CORNER_RADIUS); nvgFillColor(nvg, context->theme.LIGHTEST); nvgFill(nvg); //Draw vertical line for x=0 if (graphBounds.position.x < 0 && graphBounds.position.x + graphBounds.dimensions.x > 0) { float xpos = -graphBounds.position.x / graphBounds.dimensions.x; nvgBeginPath(nvg); nvgMoveTo(nvg, xpos * gbounds.dimensions.x + gbounds.position.x, gbounds.position.y); nvgLineTo(nvg, xpos * gbounds.dimensions.x + gbounds.position.x, gbounds.position.y + gbounds.dimensions.y); nvgStrokeWidth(nvg, 2.0f); nvgStrokeColor(nvg, context->theme.DARK.toSemiTransparent(0.75f)); nvgStroke(nvg); } //Draw horizontal line for y=0 if (graphBounds.position.y < 0 && graphBounds.position.y + graphBounds.dimensions.y > 0) { float ypos = -graphBounds.position.y / graphBounds.dimensions.y; nvgBeginPath(nvg); nvgMoveTo(nvg, gbounds.position.x, ypos * gbounds.dimensions.y + gbounds.position.y); nvgLineTo(nvg, gbounds.position.x + gbounds.dimensions.x, ypos * gbounds.dimensions.y + gbounds.position.y); nvgStrokeWidth(nvg, 2.0f); nvgStrokeColor(nvg, context->theme.DARK.toSemiTransparent(0.75f)); nvgStroke(nvg); } if (gbounds.contains(cursorPosition)) { context->setCursor(&Cursor::CrossHairs); gpos = (cursorPosition - gbounds.position) / gbounds.dimensions; gpos.y = 1 - gpos.y; gpos = gpos * graphBounds.dimensions + graphBounds.position; nvgBeginPath(nvg); nvgMoveTo(nvg, cursorPosition.x, gbounds.position.y); nvgLineTo(nvg, cursorPosition.x, gbounds.position.y + gbounds.dimensions.y); nvgStrokeWidth(nvg, 1.0f); nvgStrokeColor(nvg, context->theme.DARK.toSemiTransparent(0.25f)); nvgStroke(nvg); nvgBeginPath(nvg); nvgMoveTo(nvg, gbounds.position.x, cursorPosition.y); nvgLineTo(nvg, gbounds.position.x + gbounds.dimensions.x, cursorPosition.y); nvgStrokeWidth(nvg, 1.0f); nvgStrokeColor(nvg, context->theme.DARK.toSemiTransparent(0.25f)); nvgStroke(nvg); } for (GraphDataPtr& curve : curves) { std::vector<float2> points = curve->points; if (points.size() > 1 && graphBounds.dimensions.x > 0.0f && graphBounds.dimensions.y > 0.0f) { NVGcontext* nvg = context->nvgContext; float2 last = points[0]; last = (last - graphBounds.position) / graphBounds.dimensions; last.y = 1.0f - last.y; last = last * gbounds.dimensions + gbounds.position; nvgBeginPath(nvg); nvgMoveTo(nvg, last.x, last.y); for (int i = 1; i < (int)points.size(); i++) { float2 pt = points[i]; pt = (pt - graphBounds.position) / graphBounds.dimensions; pt.y = 1.0f - pt.y; pt = pt * gbounds.dimensions + gbounds.position; nvgLineTo(nvg, pt.x, pt.y); last = pt; } nvgStrokeWidth(nvg, 2.0f); nvgStrokeColor(nvg, curve->color); nvgStroke(nvg); } } nvgFontFaceId(nvg, context->getFontHandle(FontType::Bold)); nvgFontSize(nvg, LARGE_TEXT); nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP); drawText(nvg, rbounds.position + float2(rbounds.dimensions.x / 2, 2.0f), name, FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); nvgFontSize(nvg, MEDIUM_TEXT); nvgFontFaceId(nvg, context->getFontHandle(FontType::Bold)); nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_BOTTOM); drawText(nvg, rbounds.position + float2(rbounds.dimensions.x / 2, rbounds.dimensions.y - 4.0f), xAxisLabel, FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP); nvgSave(nvg); pixel2 center = rbounds.position + float2(2.0f, rbounds.dimensions.y * 0.5f); nvgTranslate(nvg, center.x, center.y); nvgRotate(nvg, -ALY_PI * 0.5f); drawText(nvg, pixel2(0, 2), yAxisLabel, FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); nvgRestore(nvg); nvgFontSize(nvg, SMALL_TEXT); nvgTextAlign(nvg, NVG_ALIGN_RIGHT | NVG_ALIGN_TOP); drawText(nvg, rbounds.position + float2(GRAPH_PADDING, GRAPH_PADDING), MakeString() << std::setprecision(2) << (graphBounds.position.y + graphBounds.dimensions.y), FontStyle::Outline, context->theme.LIGHTER, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_RIGHT | NVG_ALIGN_BOTTOM); drawText(nvg, rbounds.position + float2(GRAPH_PADDING, rbounds.dimensions.y - GRAPH_PADDING), MakeString() << std::setprecision(2) << graphBounds.position.y, FontStyle::Outline, context->theme.LIGHTER, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_RIGHT | NVG_ALIGN_TOP); drawText(nvg, rbounds.position + float2(rbounds.dimensions.x - GRAPH_PADDING, rbounds.dimensions.y - GRAPH_PADDING + 2), MakeString() << std::setprecision(2) << (graphBounds.position.x + graphBounds.dimensions.x), FontStyle::Outline, context->theme.LIGHTER, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); drawText(nvg, rbounds.position + float2(GRAPH_PADDING, rbounds.dimensions.y - GRAPH_PADDING + 2), MakeString() << std::setprecision(2) << graphBounds.position.x, FontStyle::Outline, context->theme.LIGHTER, context->theme.DARK); if (cursorPosition.x >= 0) { float minDist = 1E30f; float bestY = 0; GraphDataPtr closestCurve; for (GraphDataPtr& curve : curves) { float y = curve->interpolate(gpos.x); if (y != GraphData::NO_INTERSECT) { if (std::abs(y - gpos.y) < minDist) { minDist = std::abs(y - gpos.y); bestY = y; closestCurve = curve; } } } if (closestCurve.get() != nullptr) { nvgBeginPath(nvg); nvgStrokeWidth(nvg, 2.0f); nvgFillColor(nvg, closestCurve->color); nvgStrokeColor(nvg, context->theme.LIGHTER); float2 pt(gpos.x, bestY); pt = (pt - graphBounds.position) / graphBounds.dimensions; pt.y = 1.0f - pt.y; pt = pt * gbounds.dimensions + gbounds.position; nvgCircle(nvg, pt.x, pt.y, 4); nvgFill(nvg); nvgStroke(nvg); nvgBeginPath(nvg); nvgFillColor(nvg, context->theme.DARK); nvgCircle(nvg, cursorPosition.x, cursorPosition.y, 2); nvgFill(nvg); nvgTextAlign(nvg, NVG_ALIGN_RIGHT | NVG_ALIGN_MIDDLE); nvgFontSize(nvg, MEDIUM_TEXT); drawText(nvg, float2(pt.x - 8, pt.y), closestCurve->name, FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); drawText(nvg, float2(pt.x + 8, pt.y), MakeString() << "(" << std::setprecision(2) << gpos.x << ", " << std::setprecision(2) << bestY << ")", FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); } else { nvgBeginPath(nvg); nvgFillColor(nvg, context->theme.DARK); nvgCircle(nvg, cursorPosition.x, cursorPosition.y, 2); nvgFill(nvg); } } }
void NVGRenderer::rotate(float rad) { nvgRotate(m_context, rad); }
void ColorWheel::draw(NVGcontext *ctx) { Widget::draw(ctx); if (!mVisible) return; float x = mPos.x(), y = mPos.y(), w = mSize.x(), h = mSize.y(); NVGcontext* vg = ctx; int i; float r0, r1, ax,ay, bx,by, cx,cy, aeps, r; float hue = mHue; NVGpaint paint; nvgSave(vg); cx = x + w*0.5f; cy = y + h*0.5f; r1 = (w < h ? w : h) * 0.5f - 5.0f; r0 = r1 * .75f; 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 float u = std::max(r1/50, 1.5f); u = std::min(u, 4.f); nvgStrokeWidth(vg, u); nvgBeginPath(vg); nvgRect(vg, r0-1,-2*u,r1-r0+2,4*u); 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 float sx = r*(1 - mWhite - mBlack) + ax*mWhite + bx*mBlack; float sy = ay*mWhite + by*mBlack; nvgStrokeWidth(vg, u); nvgBeginPath(vg); nvgCircle(vg, sx,sy,2*u); nvgStrokeColor(vg, nvgRGBA(255,255,255,192)); nvgStroke(vg); nvgRestore(vg); nvgRestore(vg); }
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 QNanoPainter::rotate(float angle) { nvgRotate(nvgCtx(), angle); }
void drawClock(NVGcontext* vg, int screenWidth, int screenHeight) { int clockRadius = (fmin(screenWidth, screenHeight) - 10) / 2; NVGcolor baseColor = nvgRGB(145, 100, 0); NVGcolor lighterColor = nvgRGB(200, 140, 0); NVGcolor dblLighterColor = nvgRGB(255, 177, 0); NVGcolor lightestColor = nvgRGB(255, 195, 60); int widthLight = fmax(clockRadius * 0.0075, 1); int widthMedium = fmax(clockRadius * 0.013, 1); int widthHeavy = fmax(clockRadius * 0.025, 1); time_t t = time(NULL); struct tm localTime = *localtime(&t); nvgTranslate(vg, screenWidth / 2, screenHeight / 2); nvgStrokeColor(vg, baseColor); // Frame nvgSave(vg); nvgBeginPath(vg); nvgCircle(vg, 0, 0, clockRadius); nvgStrokeWidth(vg, widthMedium); nvgStroke(vg); nvgBeginPath(vg); nvgStrokeColor(vg, lighterColor); for (int i = 0; i < 12; i++) { nvgMoveTo(vg, 0, -clockRadius * 0.98); nvgLineTo(vg, 0, -clockRadius * 0.90); for (int j = 0; j < 5; j++) { nvgRotate(vg, 2 * M_PI / 12 / 5); nvgMoveTo(vg, 0, -clockRadius * 0.98); nvgLineTo(vg, 0, -clockRadius * 0.95); } } nvgStroke(vg); nvgBeginPath(vg); nvgFontFace(vg, "bold"); int digitsRadius = clockRadius * 0.79; int digitLargeSize = clockRadius * 0.29; int digitSmallSize = clockRadius * 0.2; int clockTitleSize = clockRadius * 0.06; nvgFillColor(vg, dblLighterColor); char* nineTitle = "9"; nvgFontSize(vg, digitLargeSize); nvgTranslate(vg, -digitsRadius, 0); nvgRotate(vg, - 3 * 2 * M_PI / 12); //nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, nineTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, lighterColor); char* tenTitle = "10"; nvgFontSize(vg, digitSmallSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, tenTitle, 0, 0); nvgFill(vg); char* elevenTitle = "11"; nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, elevenTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, dblLighterColor); char* twelveTitle = "12"; nvgFontSize(vg, digitLargeSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, twelveTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, lighterColor); char* oneTitle = "1"; nvgFontSize(vg, digitSmallSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, oneTitle, 0, 0); nvgFill(vg); char* twoTitle = "2"; nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, twoTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, dblLighterColor); char* threeTitle = "3"; nvgFontSize(vg, digitLargeSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, -digitsRadius); drawTextCenter(vg, threeTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, lighterColor); char* fourTitle = "4"; nvgFontSize(vg, digitSmallSize); nvgTranslate(vg, 0, digitsRadius); nvgRotate(vg, 2 * M_PI / 12 - M_PI); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, fourTitle, 0, 0); nvgFill(vg); char* fiveTitle = "5"; nvgTranslate(vg, 0, -digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, fiveTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, dblLighterColor); char* sixTitle = "6"; nvgFontSize(vg, digitLargeSize); nvgTranslate(vg, 0, -digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, sixTitle, 0, 0); nvgFill(vg); nvgFillColor(vg, lighterColor); char* sevenTitle = "7"; nvgFontSize(vg, digitSmallSize); nvgTranslate(vg, 0, -digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, sevenTitle, 0, 0); nvgFill(vg); char* eightTitle = "8"; nvgTranslate(vg, 0, -digitsRadius); nvgRotate(vg, 2 * M_PI / 12); nvgTranslate(vg, 0, digitsRadius); drawTextCenter(vg, eightTitle, 0, 0); nvgFill(vg); nvgRestore(vg); nvgSave(vg); nvgFontFace(vg, "black"); char* clockTitle = "ALPHA"; nvgFontSize(vg, clockTitleSize); nvgFillColor(vg, baseColor); nvgTranslate(vg, 0, clockTitleSize); nvgTextLetterSpacing(vg, clockTitleSize); drawTextCenter(vg, clockTitle, 0, -2 * clockTitleSize); nvgFill(vg); nvgRestore(vg); double secAngle = 2 * M_PI / 60 * localTime.tm_sec; double minAngle = 2 * M_PI / 60 * localTime.tm_min + secAngle / 60; double hrAngle = 2 * M_PI / 12 * localTime.tm_hour + minAngle / 60; // Hour hand nvgStrokeColor(vg, lighterColor); nvgSave(vg); nvgRotate(vg, hrAngle); nvgBeginPath(vg); nvgMoveTo(vg, 0, clockRadius * 0.02); nvgLineTo(vg, 0, -clockRadius * 0.5); nvgStrokeWidth(vg, widthHeavy); nvgStroke(vg); nvgRestore(vg); // Minute hand nvgStrokeColor(vg, lighterColor); nvgSave(vg); nvgRotate(vg, minAngle); nvgBeginPath(vg); nvgMoveTo(vg, 0, clockRadius * 0.04); nvgLineTo(vg, 0, -clockRadius * 0.8); nvgStrokeWidth(vg, widthMedium); nvgStroke(vg); nvgRestore(vg); // Second hand nvgStrokeColor(vg, lightestColor); nvgSave(vg); nvgRotate(vg, secAngle); nvgBeginPath(vg); nvgMoveTo(vg, 0, clockRadius * 0.05); nvgLineTo(vg, 0, -clockRadius * 0.9); nvgStrokeWidth(vg, widthLight); nvgStroke(vg); nvgRestore(vg); }
JNIEXPORT void JNICALL Java_firststep_internal_NVG_rotate (JNIEnv *e, jclass c, jlong ctx, jfloat angle) { nvgRotate((NVGcontext*)ctx, angle); }