void TabWidget::draw(NVGcontext* ctx) { int tab_height = m_header->preferred_size(ctx).y(); auto active_area = m_header->active_button_area(); for (int i = 0; i < 3; ++i) { nvgSave(ctx); if (i == 0) nvgIntersectScissor(ctx, m_pos.x(), m_pos.y(), active_area.first.x() + 1, m_size.y()); else if (i == 1) nvgIntersectScissor(ctx, m_pos.x() + active_area.second.x(), m_pos.y(), m_size.x() - active_area.second.x(), m_size.y()); else nvgIntersectScissor(ctx, m_pos.x(), m_pos.y() + tab_height + 2, m_size.x(), m_size.y()); nvgBeginPath(ctx); nvgStrokeWidth(ctx, 1.0f); nvgRoundedRect(ctx, m_pos.x() + 0.5f, m_pos.y() + tab_height + 1.5f, m_size.x() - 1, m_size.y() - tab_height - 2, m_theme->m_button_corner_radius); nvgStrokeColor(ctx, m_theme->m_border_light); nvgStroke(ctx); nvgBeginPath(ctx); nvgRoundedRect(ctx, m_pos.x() + 0.5f, m_pos.y() + tab_height + 0.5f, m_size.x() - 1, m_size.y() - tab_height - 2, m_theme->m_button_corner_radius); nvgStrokeColor(ctx, m_theme->m_border_dark); nvgStroke(ctx); nvgRestore(ctx); } Widget::draw(ctx); }
void TabWidget::draw(NVGcontext* ctx) { int tabHeight = mHeader->preferredSize(ctx).y(); auto activeArea = mHeader->activeButtonArea(); for (int i = 0; i < 3; ++i) { nvgSave(ctx); if (i == 0) nvgIntersectScissor(ctx, mPos.x(), mPos.y(), activeArea.first.x() + 1, mSize.y()); else if (i == 1) nvgIntersectScissor(ctx, mPos.x() + activeArea.second.x(), mPos.y(), mSize.x() - activeArea.second.x(), mSize.y()); else nvgIntersectScissor(ctx, mPos.x(), mPos.y() + tabHeight + 2, mSize.x(), mSize.y()); nvgBeginPath(ctx); nvgStrokeWidth(ctx, 1.0f); nvgRoundedRect(ctx, mPos.x() + 0.5f, mPos.y() + tabHeight + 1.5f, mSize.x() - 1, mSize.y() - tabHeight - 2, mTheme->mButtonCornerRadius); nvgStrokeColor(ctx, mTheme->mBorderLight); nvgStroke(ctx); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x() + 0.5f, mPos.y() + tabHeight + 0.5f, mSize.x() - 1, mSize.y() - tabHeight - 2, mTheme->mButtonCornerRadius); nvgStrokeColor(ctx, mTheme->mBorderDark); nvgStroke(ctx); nvgRestore(ctx); } Widget::draw(ctx); }
void Graph::draw(NVGcontext *ctx) { Widget::draw(ctx); nvgBeginPath(ctx); nvgRect(ctx, mPos.x, mPos.y, mSize.x, mSize.y); nvgFillColor(ctx, mBackgroundColor); nvgFill(ctx); if (mValues.size() < 2) return; nvgBeginPath(ctx); nvgMoveTo(ctx, mPos.x, mPos.y + mSize.y); for (size_t i = 0; i < (size_t)mValues.size(); i++) { float value = mValues[i]; float vx = mPos.x + i * mSize.x / (float)(mValues.size() - 1); float vy = mPos.y + (1 - value) * mSize.y; nvgLineTo(ctx, vx, vy); } nvgLineTo(ctx, mPos.x + mSize.x, mPos.y + mSize.y); nvgStrokeColor(ctx, Colour(100, 255)); nvgStroke(ctx); nvgFillColor(ctx, mForegroundColor); nvgFill(ctx); nvgFontFace(ctx, "sans"); if (!mCaption.empty()) { nvgFontSize(ctx, 14.0f); nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); nvgFillColor(ctx, mTextColor); nvgText(ctx, mPos.x + 3, mPos.y + 1, mCaption.c_str(), NULL); } if (!mHeader.empty()) { nvgFontSize(ctx, 18.0f); nvgTextAlign(ctx, NVG_ALIGN_RIGHT | NVG_ALIGN_TOP); nvgFillColor(ctx, mTextColor); nvgText(ctx, mPos.x + mSize.x - 3, mPos.y + 1, mHeader.c_str(), NULL); } if (!mFooter.empty()) { nvgFontSize(ctx, 15.0f); nvgTextAlign(ctx, NVG_ALIGN_RIGHT | NVG_ALIGN_BOTTOM); nvgFillColor(ctx, mTextColor); nvgText(ctx, mPos.x + mSize.x - 3, mPos.y + mSize.y - 1, mFooter.c_str(), NULL); } nvgBeginPath(ctx); nvgRect(ctx, mPos.x, mPos.y, mSize.x, mSize.y); nvgStrokeColor(ctx, Colour(100, 255)); nvgStroke(ctx); }
void drawLines(struct NVGcontext* vg, float x, float y, float w, float h, float t) { int i, j; float pad = 5.0f, s = w/9.0f - pad*2; float pts[4*2], fx, fy; int joins[3] = {NVG_MITER, NVG_ROUND, NVG_BEVEL}; int caps[3] = {NVG_BUTT, NVG_ROUND, NVG_SQUARE}; NVG_NOTUSED(h); nvgSave(vg); pts[0] = -s*0.25f + cosf(t*0.3f) * s*0.5f; pts[1] = sinf(t*0.3f) * s*0.5f; pts[2] = -s*0.25f; pts[3] = 0; pts[4] = s*0.25f; pts[5] = 0; pts[6] = s*0.25f + cosf(-t*0.3f) * s*0.5f; pts[7] = sinf(-t*0.3f) * s*0.5f; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { fx = x + s*0.5f + (i*3+j)/9.0f*w + pad; fy = y - s*0.5f + pad; nvgLineCap(vg, caps[i]); nvgLineJoin(vg, joins[j]); nvgStrokeWidth(vg, s*0.3f); nvgStrokeColor(vg, nvgRGBA(0,0,0,160) ); nvgBeginPath(vg); nvgMoveTo(vg, fx+pts[0], fy+pts[1]); nvgLineTo(vg, fx+pts[2], fy+pts[3]); nvgLineTo(vg, fx+pts[4], fy+pts[5]); nvgLineTo(vg, fx+pts[6], fy+pts[7]); nvgStroke(vg); nvgLineCap(vg, NVG_BUTT); nvgLineJoin(vg, NVG_BEVEL); nvgStrokeWidth(vg, 1.0f); nvgStrokeColor(vg, nvgRGBA(0,192,255,255) ); nvgBeginPath(vg); nvgMoveTo(vg, fx+pts[0], fy+pts[1]); nvgLineTo(vg, fx+pts[2], fy+pts[3]); nvgLineTo(vg, fx+pts[4], fy+pts[5]); nvgLineTo(vg, fx+pts[6], fy+pts[7]); nvgStroke(vg); } } nvgRestore(vg); }
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 NanoInk::drawImage() { #if 1 // DEBUG if(sDebugDraw && mVisible) { float left = mFrame.dabsolute(DIM_X) + mFrame.cleft(); float top = mFrame.dabsolute(DIM_Y) + mFrame.ctop(); float width = mFrame.cwidth(); float height = mFrame.cheight(); nvgBeginPath(mCtx); nvgRect(mCtx, left + 0.5f, top + 0.5f, width - 1.f, height - 1.f); nvgStrokeWidth(mCtx, 1.f); nvgStrokeColor(mCtx, nvgColour(Colour::Red)); nvgStroke(mCtx); } #endif if(this->skin().mEmpty || !mVisible) return; ++sDebugBatch; if(!mImageCache) mImageCache = nvgCreateDisplayList(11); if(mImageUpdate) this->redrawImage(); this->drawCache(mImageCache); mImageUpdate = false; }
void drawDropDown(struct NVGcontext* vg, const char* text, float x, float y, float w, float h) { struct NVGpaint bg; char icon[8]; float cornerRadius = 4.0f; bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(255,255,255,16), nvgRGBA(0,0,0,16) ); nvgBeginPath(vg); nvgRoundedRect(vg, x+1,y+1, w-2,h-2, cornerRadius-1); nvgFillPaint(vg, bg); nvgFill(vg); nvgBeginPath(vg); nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f); nvgStrokeColor(vg, nvgRGBA(0,0,0,48) ); nvgStroke(vg); nvgFontSize(vg, 20.0f); nvgFontFace(vg, "sans"); nvgFillColor(vg, nvgRGBA(255,255,255,160) ); nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); nvgText(vg, x+h*0.3f,y+h*0.5f,text, NULL); nvgFontSize(vg, h*1.3f); nvgFontFace(vg, "icons"); nvgFillColor(vg, nvgRGBA(255,255,255,64) ); nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); nvgText(vg, x+w-h*0.5f, y+h*0.5f, cpToUTF8(ICON_CHEVRON_RIGHT,icon), NULL); }
void drawCaps(struct 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 vsColoredNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1, NVGcolor color0, NVGcolor color1) { float length = bnd_fmaxf(fabsf(x1 - x0), fabsf(y1 - y0)); // how much a noodle curves (0 to 10) int noodleCurving = 3; float delta = length * (float) noodleCurving / 10.0f; nvgBeginPath(ctx); nvgMoveTo(ctx, x0, y0); nvgBezierTo(ctx, x0 + delta, y0, x1 - delta, y1, x1, y1); NVGcolor colorw = nvgRGB(52, 22, 99); colorw.a = (color0.a < color1.a) ? color0.a : color1.a; nvgStrokeColor(ctx, colorw); nvgStrokeWidth(ctx, BND_NODE_WIRE_OUTLINE_WIDTH); nvgStroke(ctx); nvgStrokePaint(ctx, nvgLinearGradient(ctx, x0, y0, x1, y1, color0, color1)); nvgStrokeWidth(ctx, BND_NODE_WIRE_WIDTH); nvgStroke(ctx); }
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 draw<line_t>(line_t& line, NVGcolor& color) { nvgBeginPath(graphics::vg); nvgMoveTo(graphics::vg, line.p.x, line.p.y); nvgLineTo(graphics::vg, line.q.x, line.q.y); nvgStrokeColor(graphics::vg, color); nvgStrokeWidth(graphics::vg, 3 * graphics::one_pixel); nvgStroke(graphics::vg); }
void testrect(NVGcontext *vg, UIrect rect) { #if 0 nvgBeginPath(vg); nvgRect(vg,rect.x+0.5,rect.y+0.5,rect.w-1,rect.h-1); nvgStrokeColor(vg,nvgRGBf(1,0,0)); nvgStrokeWidth(vg,1); nvgStroke(vg); #endif }
void FHUD::Render(int w, int h) { if(!Temp) { Temp = RC.Render->NewSGObject(); Temp->LoadModelFromResource(RC.Engine->EnemyMesh1); Temp->SetScale(glm::vec3(1.2f)); Temp->SetVisible(false); } if(Health <= 0) { nvgBeginPath(vg); nvgRect(vg, 0, 0, (float)w, (float)h); nvgFillColor(vg, nvgRGBA(255, 0, 0, 200)); nvgFill(vg); Temp->SetVisible(true); Temp->SetRed(true); } else { Temp->SetVisible(false); nvgFillColor(vg, nvgRGB(0, 0, 0)); nvgFontSize(vg, 36); nvgFontFace(vg, "normal"); nvgText(vg, 0, 50, "Health", nullptr); nvgBeginPath(vg); nvgRect(vg, 100, 23, (float)Health * 10, 35); nvgStrokeColor(vg, nvgRGBA(0, 0, 0, 255)); NVGpaint redPaint = nvgLinearGradient(vg, 100, 23, 100, 35, nvgRGBA(255, 255, 255, 255), nvgRGBA(255, 0, 0, 100)); //nvgFillColor(vg, nvgRGBA(255, 0, 0, 128)); nvgFillPaint(vg, redPaint); nvgFill(vg); nvgBeginPath(vg); nvgRect(vg, 100, 23, (float)MaxHealth * 10, 35); nvgStrokeColor(vg, nvgRGBA(0, 0, 0, 255)); nvgStroke(vg); } }
void drawWindow(struct NVGcontext* vg, const char* title, float x, float y, float w, float h) { float cornerRadius = 3.0f; struct NVGpaint shadowPaint; struct NVGpaint headerPaint; nvgSave(vg); // nvgClearState(vg); // Window nvgBeginPath(vg); nvgRoundedRect(vg, x,y, w,h, cornerRadius); nvgFillColor(vg, nvgRGBA(28,30,34,192) ); // nvgFillColor(vg, nvgRGBA(0,0,0,128) ); nvgFill(vg); // Drop shadow shadowPaint = nvgBoxGradient(vg, x,y+2, w,h, cornerRadius*2, 10, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0) ); nvgBeginPath(vg); nvgRect(vg, x-10,y-10, w+20,h+30); nvgRoundedRect(vg, x,y, w,h, cornerRadius); nvgPathWinding(vg, NVG_HOLE); nvgFillPaint(vg, shadowPaint); nvgFill(vg); // Header headerPaint = nvgLinearGradient(vg, x,y,x,y+15, nvgRGBA(255,255,255,8), nvgRGBA(0,0,0,16) ); nvgBeginPath(vg); nvgRoundedRect(vg, x+1,y+1, w-2,30, cornerRadius-1); nvgFillPaint(vg, headerPaint); nvgFill(vg); nvgBeginPath(vg); nvgMoveTo(vg, x+0.5f, y+0.5f+30); nvgLineTo(vg, x+0.5f+w-1, y+0.5f+30); nvgStrokeColor(vg, nvgRGBA(0,0,0,32) ); nvgStroke(vg); nvgFontSize(vg, 18.0f); nvgFontFace(vg, "sans-bold"); nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); nvgFontBlur(vg,2); nvgFillColor(vg, nvgRGBA(0,0,0,128) ); nvgText(vg, x+w/2,y+16+1, title, NULL); nvgFontBlur(vg,0); nvgFillColor(vg, nvgRGBA(220,220,220,160) ); nvgText(vg, x+w/2,y+16, title, NULL); nvgRestore(vg); }
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 drawEditBoxBase(struct NVGcontext* vg, float x, float y, float w, float h) { struct NVGpaint bg; // 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) ); nvgBeginPath(vg); nvgRoundedRect(vg, x+1,y+1, w-2,h-2, 4-1); nvgFillPaint(vg, bg); nvgFill(vg); nvgBeginPath(vg); nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, 4-0.5f); nvgStrokeColor(vg, nvgRGBA(0,0,0,48) ); nvgStroke(vg); }
void drawButton(struct NVGcontext* vg, int preicon, const char* text, float x, float y, float w, float h, struct NVGcolor col) { struct NVGpaint bg; char icon[8]; float cornerRadius = 4.0f; float tw = 0, iw = 0; bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(255,255,255,isBlack(col)?16:32), nvgRGBA(0,0,0,isBlack(col)?16:32) ); nvgBeginPath(vg); nvgRoundedRect(vg, x+1,y+1, w-2,h-2, cornerRadius-1); if (!isBlack(col) ) { nvgFillColor(vg, col); nvgFill(vg); } nvgFillPaint(vg, bg); nvgFill(vg); nvgBeginPath(vg); nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f); nvgStrokeColor(vg, nvgRGBA(0,0,0,48) ); nvgStroke(vg); nvgFontSize(vg, 20.0f); nvgFontFace(vg, "sans-bold"); tw = nvgTextBounds(vg, 0,0, text, NULL, NULL); if (preicon != 0) { nvgFontSize(vg, h*1.3f); nvgFontFace(vg, "icons"); iw = nvgTextBounds(vg, 0,0, cpToUTF8(preicon,icon), NULL, NULL); iw += h*0.15f; } if (preicon != 0) { nvgFontSize(vg, h*1.3f); nvgFontFace(vg, "icons"); nvgFillColor(vg, nvgRGBA(255,255,255,96) ); nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); nvgText(vg, x+w*0.5f-tw*0.5f-iw*0.75f, y+h*0.5f, cpToUTF8(preicon,icon), NULL); } nvgFontSize(vg, 20.0f); nvgFontFace(vg, "sans-bold"); nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); nvgFillColor(vg, nvgRGBA(0,0,0,160) ); nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f-1,text, NULL); nvgFillColor(vg, nvgRGBA(255,255,255,160) ); nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f,text, NULL); }
void ExpandTree::drawDebug(AlloyContext* context) { if (selectedItem) { NVGcontext* nvg = context->nvgContext; nvgStrokeWidth(nvg, 1.0f); nvgStrokeColor(nvg, Color(220, 64, 64)); nvgBeginPath(nvg); box2px bounds = selectedItem->getBounds(); box2px pbounds = drawRegion->getBounds(); bounds.position += pbounds.position; bounds.intersect(getBounds()); nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x, bounds.dimensions.y); nvgStroke(nvg); } Composite::drawDebug(context); }
void ImagePanel::draw (NVGcontext * ctx) { ivec2 grid = gridSize(); for (size_t i = 0; i < mImages.size(); ++i) { ivec2 p = mPos + ivec2 (mMargin) + ivec2 ((int)i % grid.x, (int)i / grid.x) * (mThumbSize + mSpacing); int imgw, imgh; nvgImageSize (ctx, mImages[i].first, &imgw, &imgh); float iw, ih, ix, iy; if (imgw < imgh) { iw = mThumbSize; ih = iw * (float)imgh / (float)imgw; ix = 0; iy = - (ih - mThumbSize) * 0.5f; } else { ih = mThumbSize; iw = ih * (float)imgw / (float)imgh; ix = - (iw - mThumbSize) * 0.5f; iy = 0; } NVGpaint imgPaint = nvgImagePattern ( ctx, p.x + ix, p.y + iy, iw, ih, 0, mImages[i].first, mMouseIndex == (int)i ? 1.0 : 0.7); nvgBeginPath (ctx); nvgRoundedRect (ctx, p.x, p.y, mThumbSize, mThumbSize, 5); nvgFillPaint (ctx, imgPaint); nvgFill (ctx); NVGpaint shadowPaint = nvgBoxGradient (ctx, p.x - 1, p.y, mThumbSize + 2, mThumbSize + 2, 5, 3, nvgRGBA (0, 0, 0, 128), nvgRGBA (0, 0, 0, 0)); nvgBeginPath (ctx); nvgRect (ctx, p.x - 5, p.y - 5, mThumbSize + 10, mThumbSize + 10); nvgRoundedRect (ctx, p.x, p.y, mThumbSize, mThumbSize, 6); nvgPathWinding (ctx, NVG_HOLE); nvgFillPaint (ctx, shadowPaint); nvgFill (ctx); nvgBeginPath (ctx); nvgRoundedRect (ctx, p.x + 0.5f, p.y + 0.5f, mThumbSize - 1, mThumbSize - 1, 4 - 0.5f); nvgStrokeWidth (ctx, 1.0f); nvgStrokeColor (ctx, nvgRGBA (255, 255, 255, 80)); nvgStroke (ctx); } }
void Render() override { nvgBeginPath(GNvg); if (EdgePainter.Points.size() >= 4) { glm::vec2 temp = camera.WorldToScreen(glm::vec2(EdgePainter.Points[0], EdgePainter.Points[1])); nvgMoveTo(GNvg, temp[0], temp[1]); for (int i = 2; i < EdgePainter.Points.size(); i += 2) { temp = camera.WorldToScreen(glm::vec2(EdgePainter.Points[i], EdgePainter.Points[i + 1])); nvgLineTo(GNvg, temp[0], temp[1]); } } nvgStrokeColor(GNvg, nvgRGB(255, 255, 255)); nvgStrokeWidth(GNvg, 5); nvgStroke(GNvg); }
void Caret::draw(NVGcontext *ctx, float lineh, Vector2i offset) { //std::cout << "Cursor("<< mCursorPos.x()<< ","<< mCursorPos.y() <<")" << std::endl; if(isVisible()) { //float caretx = cursorIndex2Position(mCursorPos.x(), textBound[2], glyphs, nglyphs); //mPosition = getCursorPosition(ctx, mCursorPos, lineh); // draw cursor nvgBeginPath(ctx); nvgMoveTo(ctx, offset.x() + mPos.x(), offset.y()+ mPos.y() ); nvgLineTo(ctx, offset.x() + mPos.x(), offset.y()+ mPos.y()+ lineh ); nvgStrokeColor(ctx, nvgRGBA(255, 192, 0, 255)); nvgStrokeWidth(ctx, 1.0f); nvgStroke(ctx); } if(mSelectionState) { // draw selection int linew = mConsole->mSize.x(); nvgBeginPath(ctx); nvgFillColor(ctx, nvgRGBA(255, 255, 255, 80)); if(mIdx.y() == mSelectionIdx.y()) { int x = std::min(mPos.x(),mSelectionPos.x()); x += offset.x(); nvgRect(ctx, x, offset.y()+ mPos.y(), std::abs(mSelectionPos.x()-mPos.x()), lineh); } else if(mIdx.y() > mSelectionIdx.y()) { nvgRect(ctx, offset.x()+mSelectionPos.x(), offset.y()+ mSelectionPos.y(), linew-mSelectionPos.x(), lineh); if(mIdx.y()-mSelectionIdx.y()>1) nvgRect(ctx, offset.x(), offset.y()+ mSelectionPos.y()+lineh, linew, mPos.y()-mSelectionPos.y()-lineh); nvgRect(ctx, offset.x(), offset.y()+ mPos.y(), mPos.x(), lineh); } else { nvgRect(ctx, offset.x(), offset.y()+ mSelectionPos.y(), mSelectionPos.x(), lineh); if(mSelectionIdx.y()-mIdx.y()>1) nvgRect(ctx, offset.x(), offset.y()+ mPos.y()+lineh, linew, mSelectionPos.y()-mPos.y()-lineh); nvgRect(ctx, offset.x()+mPos.x(), offset.y()+ mPos.y(), linew-mPos.x(), lineh); } nvgFill(ctx); } }
void Widget::draw(NVGcontext *ctx) { #if NANOGUI_SHOW_WIDGET_BOUNDS nvgStrokeWidth(ctx, 1.0f); nvgBeginPath(ctx); nvgRect(ctx, mPos.x() - 0.5f, mPos.y() - 0.5f, mSize.x() + 1, mSize.y() + 1); nvgStrokeColor(ctx, nvgRGBA(255, 0, 0, 255)); nvgStroke(ctx); #endif if (mChildren.empty()) return; nvgTranslate(ctx, mPos.x(), mPos.y()); for (auto child : mChildren) if (child->visible()) child->draw(ctx); nvgTranslate(ctx, -mPos.x(), -mPos.y()); }
void draw<vec_field_t>(vec_field_t& vf, NVGcolor& color) { vf.foreach_element([&](size_t i, size_t j, vec_t& v){ vec_t pos = vf.get_coordinates(i, j), to = pos + v; nvgBeginPath(vg); nvgCircle(vg, pos.x, pos.y, .2); nvgFillColor(vg, color); nvgFill(vg); nvgBeginPath(vg); nvgMoveTo(vg, pos.x, pos.y); nvgLineTo(vg, to.x, to.y); nvgStrokeColor(vg, color); nvgStrokeWidth(vg, one_pixel); nvgStroke(vg); }); }
void GraphNodeLink::draw(NVGcontext* ctx) { auto sourceSize = mSource->size().cast<float>(); Eigen::Vector2i inputPosition( mSource->absolutePosition().x() - mParent->absolutePosition().x() + (sourceSize.x() * 0.5f), mSource->absolutePosition().y() - mParent->absolutePosition().y() + (sourceSize.y() * 0.5f) ); Eigen::Vector2i outputPosition(Eigen::Vector2i::Zero()); if (hasTarget()) { // Get relative position of parent (node) of the target (sink) Eigen::Vector2i delta = mSink->parent()->absolutePosition() - mSink->parent()->position(); delta.x() -= (sourceSize.x() * 0.5f); delta.y() -= (sourceSize.y() * 0.5f); outputPosition = mSink->absolutePosition() - delta; } else { Eigen::Vector2i offset = mSource->absolutePosition() - mParent->absolutePosition(); Eigen::Vector2i delta = mTargetPosition - mSource->position(); outputPosition = offset + delta; } Eigen::Vector2i positionDiff = outputPosition - inputPosition; NVGcontext* vg = ctx; nvgStrokeColor(vg, nvgRGBA(131, 148, 150, 255)); nvgStrokeWidth(vg, 2.0f); nvgBeginPath(vg); nvgMoveTo( vg, inputPosition.x(), inputPosition.y() ); nvgQuadTo(vg, 1.2 * positionDiff.x(), positionDiff.y(), outputPosition.x(), outputPosition.y() ); nvgStroke(vg); Widget::draw(ctx); }
void drawWidths(struct NVGcontext* vg, float x, float y, float width) { nvgSave(vg); nvgStrokeColor(vg, nvgRGBA(0,0,0,255) ); for (uint32_t ii = 0; ii < 20; ++ii) { float w = (ii+0.5f)*0.1f; nvgStrokeWidth(vg, w); nvgBeginPath(vg); nvgMoveTo(vg, x,y); nvgLineTo(vg, x+width,y+width*0.3f); nvgStroke(vg); y += 10; } 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 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); }
bool Button::Draw(NVGcontext *context, float deltaTime) { if (Widget::Draw(context, deltaTime)) return true; // Draw the default button here nvgBeginPath(context); nvgRoundedRect(context, bounds.position.x, bounds.position.y, bounds.size.x - 4, bounds.size.y - 4, 20); nvgStrokeWidth(context, 2); nvgStrokeColor(context, nvgRGB(100, 100, 100)); nvgFillColor(context, nvgRGB(240, 240, 240)); if (mouseInsideWidgetBounds()) { nvgFillColor(context, nvgRGB(220, 220, 220)); } nvgFill(context); nvgStroke(context); return true; }
//Render a rectangle bool renderRect(Skin::SkinClass::Attributes &skinClass, float x, float y, float sw, float sh) { if (!m_inited) return false; NVGcolor col = nvgRGBA(skinClass.fill.r, skinClass.fill.g, skinClass.fill.b, skinClass.fill.a); //NVGpaint bg = nvgLinearGradient(m_vg, pos.x, pos.y, pos.x, pos.y + size.y, nvgRGBA(255,255,255,isBlack(col)?16:64), nvgRGBA(0,0,0,isBlack(col)?16:64)); nvgBeginPath(m_vg); nvgRoundedRect(m_vg, x, y, sw, sh, skinClass.cornerRadius); if (!skinClass.hasImage || skinClass.hasFill) { nvgFillColor(m_vg, col); nvgFill(m_vg); } if (skinClass.hasImage) { //int w = size.x, h= size.y; //nvgImageSize(m_vg, skinClass.imageHandle, &w, &h); NVGpaint img = nvgImagePattern(m_vg, x, y, sw, sh, 0.f, skinClass.imageHandle, col.a); nvgFillPaint(m_vg, img); nvgFill(m_vg); } if (skinClass.hasGradient) { NVGpaint g = nvgLinearGradient(m_vg, x, y, x, y + sh, nvgRGBA(skinClass.gradientA.r, skinClass.gradientA.g, skinClass.gradientA.b, skinClass.gradientA.a), nvgRGBA(skinClass.gradientB.r, skinClass.gradientB.g, skinClass.gradientB.b, skinClass.gradientB.a) ); nvgFillPaint(m_vg, g); nvgFill(m_vg); } if (skinClass.hasStroke) { nvgStrokeWidth(m_vg, skinClass.strokeWidth); nvgStrokeColor(m_vg, nvgRGBA(skinClass.stroke.r, skinClass.stroke.g, skinClass.stroke.b, skinClass.stroke.a)); nvgStroke(m_vg); } return true; }
void NanoVG::setStrokeColor( NVGcolor color ) { nvgStrokeColor( m_context(), color ); }