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 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 VScrollPanel::draw (NVGcontext * ctx) { if (mChildren.empty()) return; Widget * child = mChildren[0]; mChildPreferredHeight = child->preferredSize (ctx).y(); float scrollh = height() * std::min (1.0f, height() / (float) mChildPreferredHeight); nvgSave (ctx); nvgTranslate (ctx, mPos.x(), mPos.y()); nvgScissor (ctx, 0, 0, mSize.x(), mSize.y()); nvgTranslate (ctx, 0, -mScroll * (mChildPreferredHeight - mSize.y())); if (child->visible()) child->draw (ctx); nvgRestore (ctx); NVGpaint paint = nvgBoxGradient ( ctx, mPos.x() + mSize.x() - 12 + 1, mPos.y() + 4 + 1, 8, mSize.y() - 8, 3, 4, Color (0, 32), Color (0, 92)); nvgBeginPath (ctx); nvgRoundedRect (ctx, mPos.x() + mSize.x() - 12, mPos.y() + 4, 8, mSize.y() - 8, 3); nvgFillPaint (ctx, paint); nvgFill (ctx); paint = nvgBoxGradient ( ctx, mPos.x() + mSize.x() - 12 - 1, mPos.y() + 4 + (mSize.y() - 8 - scrollh) * mScroll - 1, 8, scrollh, 3, 4, Color (220, 100), Color (128, 100)); nvgBeginPath (ctx); nvgRoundedRect (ctx, mPos.x() + mSize.x() - 12 + 1, mPos.x() + 4 + 1 + (mSize.y() - 8 - scrollh) * mScroll, 8 - 2, scrollh - 2, 2); nvgFillPaint (ctx, paint); nvgFill (ctx); }
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 Popup::draw(NVGcontext* ctx) { refreshRelativePlacement(); if (!mVisible) return; int ds = mTheme->mWindowDropShadowSize, cr = mTheme->mWindowCornerRadius; /* Draw a drop shadow */ NVGpaint shadowPaint = nvgBoxGradient( ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), cr*2, ds*2, mTheme->mDropShadow, mTheme->mTransparent); nvgBeginPath(ctx); nvgRect(ctx, mPos.x()-ds,mPos.y()-ds, mSize.x()+2*ds, mSize.y()+2*ds); nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), cr); nvgPathWinding(ctx, NVG_HOLE); nvgFillPaint(ctx, shadowPaint); nvgFill(ctx); /* Draw window */ nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), cr); nvgMoveTo(ctx, mPos.x()-15,mPos.y()+mAnchorHeight); nvgLineTo(ctx, mPos.x()+1,mPos.y()+mAnchorHeight-15); nvgLineTo(ctx, mPos.x()+1,mPos.y()+mAnchorHeight+15); nvgFillColor(ctx, mTheme->mWindowPopup); nvgFill(ctx); Widget::draw(ctx); }
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 ProgressBar::draw(NVGcontext* ctx) { Widget::draw(ctx); NVGpaint paint = nvgBoxGradient( ctx, mPos.x() + 1, mPos.y() + 1, mSize.x()-2, mSize.y(), 3, 4, Color(0, 32), Color(0, 92)); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), 3); nvgFillPaint(ctx, paint); nvgFill(ctx); float value = std::min(std::max(0.0f, mValue), 1.0f); int barPos = (int) std::round((mSize.x() - 2) * value); paint = nvgBoxGradient( ctx, mPos.x(), mPos.y(), barPos+1.5f, mSize.y()-1, 3, 4, Color(220, 100), Color(128, 100)); nvgBeginPath(ctx); nvgRoundedRect( ctx, mPos.x()+1, mPos.y()+1, barPos, mSize.y()-2, 3); nvgFillPaint(ctx, paint); nvgFill(ctx); }
virtual void updateGL( osg::State* state ) const { // Some test drawings... nvgBeginPath( _vg ); nvgRect( _vg, 300, 300, 120, 30 ); nvgFillColor( _vg, nvgRGBA(255, 192, 0, 255) ); nvgFill( _vg ); nvgClosePath( _vg ); nvgBeginPath( _vg ); nvgCircle( _vg, 400, 500, 50 ); nvgFillColor( _vg, nvgRGBA(0, 192, 255, 100) ); nvgFill( _vg ); nvgClosePath( _vg ); if ( _loadedImages.size()>0 ) { NVGpaint imgPaint = nvgImagePattern( _vg, 600, 150, 300, 400, 0.0f, _loadedImages[0], 1.0f ); nvgBeginPath( _vg ); nvgRoundedRect( _vg, 600, 150, 300, 400, 5 ); nvgFillPaint( _vg, imgPaint ); nvgFill( _vg ); nvgClosePath( _vg ); } }
void CheckerboardGlyph::draw(const box2px& bounds, const Color& fgColor, const Color& bgColor, AlloyContext* context) { NVGcontext* nvg = context->nvgContext; NVGpaint imgPaint = nvgImagePattern(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x, bounds.dimensions.y, 0.f, handle, 1.0f); if (bgColor.a > 0) { nvgBeginPath(nvg); nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x, bounds.dimensions.y); nvgFillColor(nvg, Color(bgColor)); nvgFill(nvg); } nvgBeginPath(nvg); nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x, bounds.dimensions.y); nvgFillPaint(nvg, imgPaint); nvgFill(nvg); if (fgColor.a > 0) { nvgBeginPath(nvg); nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x, bounds.dimensions.y); nvgFillColor(nvg, Color(fgColor)); nvgFill(nvg); } }
void Application::Impl_::paintEvent(NVGcontext* context){ int winWidth, winHeight; glfwGetWindowSize(window_.get(), &winWidth, &winHeight); int fWidth, fHeight; glfwGetFramebufferSize(window_.get(), &fWidth, &fHeight); float pxRatio = (float)fWidth / (float)winWidth; nvgBeginFrame(context, winWidth, winHeight, pxRatio); Rect textRect(0.f,10.f,winWidth,20.f); Rect boardMaxRect(0.f,textRect.height + textRect.y,winWidth,winHeight - textRect.height); float boardSizeMin = std::min(boardMaxRect.width,boardMaxRect.height); Rect boardRect(20.f, 20.f + textRect.height,boardSizeMin-40.f, boardSizeMin-40.f); if (boardMaxRect.height > boardMaxRect.width){ boardRect.move(0,(boardMaxRect.height - boardMaxRect.width)/2.f); }else{ boardRect.move((boardMaxRect.width - boardMaxRect.height)/2.f,0); } // draw the text rect nvgBeginPath(context); nvgFillColor(context, nvgRGBA(0,0,0,50)); nvgRect(context,textRect); nvgFill(context); nvgClosePath(context); // draw the board boardView_->paint(context,boardRect); if (isEnd_){ // change the color of the board nvgBeginPath(context); nvgFillColor(context, nvgRGBA(0,0,0,30)); nvgRect(context,boardMaxRect); nvgFill(context); nvgClosePath(context); // & display the game over std::string text("GAME OVER"); nvgBeginPath(context); float x= 0; float y= 0; textRect.center(x,y); nvgFontSize(context, 20); nvgFontFace(context, "sans"); nvgTextAlign(context, NVG_ALIGN_MIDDLE|NVG_ALIGN_CENTER); nvgFill(context); nvgFillColor(context, nvgRGBA(0,0,0,255)); nvgText(context,x+1,y+1,text.c_str(),NULL); nvgFillColor(context, nvgRGBA(200,20,20,255)); nvgText(context,x,y,text.c_str(),NULL); } nvgEndFrame(context); }
void IterationRunWork::output(run::World& run) { // draw background demo::background( batb, run ); if ( item_ ) { switch ( item_->mode ) { case WorkItem::Mode::Definite: { //tb_widget_->set( item_->alpha, item_->tag ); const auto& tag = item_->tag; auto alpha = item_->alpha; // draw progressbar. FIXME auto nvg = batb.gl.nanovg_begin( run.scene ); float_t w = 512; float_t h = 22; float_t x = 0.5 * (run.scene.wth - w); float_t y = 0.5 * run.scene.hth + 112; float_t r = 11; nvgBeginPath( nvg ); nvgRoundedRect( nvg, x, y, w, h, r ); nvgFillColor( nvg, nvgRGBf( 1.0, 1.0, 1.0 ) ); nvgFill( nvg ); nvgBeginPath( nvg ); nvgRoundedRect( nvg, x, y, alpha * w, h, r ); nvgFillColor( nvg, nvgRGBf( 1.0, 0.22, 0.0 ) ); nvgFill( nvg ); static int font = -1; if ( font == -1 ) { font = batb.gl.nanovg_font( "sans", file::static_data( "batb/Ubuntu-Title.ttf" ) ); } nvgFontSize( nvg, 20 ); nvgTextAlign( nvg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE ); nvgFontFaceId( nvg, font ); nvgFillColor( nvg, nvgRGBf( 0.0, 0.0, 0.0 ) ); //nvgFillColor( nvg, nvgRGBf( 0.11, 0.64, 0.04 ) ); nvgText( nvg, x + 0.5 * w, y + 0.5 * h, tag.c_str(), nullptr ); batb.gl.nanovg_end(); } break; case WorkItem::Mode::Indefinite: // FIXME: draw a finite progressbar/spinner break; } } }
void Console::draw(NVGcontext* ctx){ Widget::draw(ctx); //Screen *sc = dynamic_cast<Screen *>(this->window()->parent()); // Draw rounded rectangel around text area //////////////////// NVGpaint paint = nvgBoxGradient( ctx, mPos.x() + 1, mPos.y() + 1, mSize.x()-2, mSize.y(), 3, 4, Color(0, 32), Color(0, 92)); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), 3); nvgFillPaint(ctx, paint); nvgFill(ctx); /////////////////////////////////////////////////////////////// nvgFontSize(ctx, 18.0f); nvgFontFace(ctx, "sans"); nvgTextAlign(ctx, NVG_ALIGN_LEFT|NVG_ALIGN_TOP); float x, y, linew, lineh; nvgTextMetrics(ctx, nullptr, nullptr, &lineh); x = mPos.x(); y = mPos.y(); linew = mSize.x(); mNumRows = mSize.y()/lineh ; // make sure that the size of console is updated //setSize(Vector2i(mSize.x(), nrows*lineh)); // this code does not work. It //changes size each frame. Move from draw into one time function. // init console output if(mInit) { initBuffer(ctx, linew); mInit = false; } //typedef std::deque<std::string> Buffer_t; //temp solution: when buffer is not full. Move this to updateFunction. for(auto it = mBuffer.begin();it!=mBuffer.end();++it) { nvgBeginPath(ctx); nvgFillColor(ctx, nvgRGBA(255,255,255,16)); nvgRect(ctx, x, y, linew, lineh); nvgFill(ctx); nvgFillColor(ctx, nvgRGBA(255,255,255,255)); nvgText(ctx, x, y, it->c_str(), nullptr); y += lineh; } updateCursor(ctx, lineh); //update cursor and draw //mCaret.onClick(ctx, lineh, mMouseDownPos - mPos); mCaret.draw(ctx, lineh, mPos); }
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 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 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 FPScounter::on_draw() { head = (head+1) % FPS_HISTORY_COUNT; float new_time = time(); values[head] = new_time - current_time; current_time = new_time; size_t i, _head; float avg, w, h; avg = 0; _head = head; for (i = 0; i < 10; i++) { avg += values[head]; _head = (head+FPS_HISTORY_COUNT-1) % FPS_HISTORY_COUNT; } avg /= 10.0f; w = 200; h = 30; nvgBeginPath(vg); nvgRect(vg, x,y, w,h); nvgFillColor(vg, nvgRGBA(0,0,0,128)); nvgFill(vg); nvgBeginPath(vg); nvgMoveTo(vg, x, y+h); for (i = 0; i < FPS_HISTORY_COUNT; i++) { float v = 1.0f / (0.00001f + values[(head+i) % FPS_HISTORY_COUNT]); if (v > 80.0f) v = 80.0f; float vx = x + ((float)i/(FPS_HISTORY_COUNT-1)) * w; float vy = y + h - ((v / 80.0f) * h); nvgLineTo(vg, vx, vy); } nvgLineTo(vg, x+w, y+h); nvgFillColor(vg, nvgRGBA(255,192,0,128)); nvgFill(vg); label.setText(std::to_string(1.f/avg) + " FPS"); label.setPosition(x+w-5, y+h/2); // nvgFontSize(vg, 18.0f); // nvgFontFace(vg, "sans"); // nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_MIDDLE); // nvgFillColor(vg, nvgRGBA(240,240,240,255)); // sprintf(str, "%.2f FPS", 1.0f / avg); // nvgText(vg, x+w-5,y+h/2, str, NULL); }
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 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 nvguLine(NVGcontext* ctx, float x0, float y0, float x1, float y1) { nvgBeginPath(ctx); nvgMoveTo(ctx, x0, y0); nvgLineTo(ctx, x1, y1); nvgStroke(ctx); }
void CheckBox::draw(NVGcontext *ctx) { Widget::draw(ctx); nvgFontSize(ctx, fontSize()); nvgFontFace(ctx, "sans"); nvgFillColor(ctx, mEnabled ? mTheme->mTextColor : mTheme->mDisabledTextColor); nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); nvgText(ctx, mPos.x + 1.2f * mSize.y + 5, mPos.y + mSize.y * 0.5f, mCaption.c_str(), nullptr); NVGpaint bg = nvgBoxGradient(ctx, mPos.x + 1.5f, mPos.y + 1.5f, mSize.y - 2.0f, mSize.y - 2.0f, 3, 3, mPushed ? Color(0, 100) : Color(0, 32), Color(0, 0, 0, 180)); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x + 1.0f, mPos.y + 1.0f, mSize.y - 2.0f, mSize.y - 2.0f, 3); nvgFillPaint(ctx, bg); nvgFill(ctx); if (mChecked) { nvgFontSize(ctx, 1.8 * mSize.y); nvgFontFace(ctx, "icons"); nvgFillColor(ctx, mEnabled ? mTheme->mIconColor : mTheme->mDisabledTextColor); nvgTextAlign(ctx, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE); nvgText(ctx, mPos.x + mSize.y * 0.5f + 1, mPos.y + mSize.y * 0.5f, utf8(ENTYPO_ICON_CHECK).data(), nullptr); } }
void draw<circle_t>(circle_t& circle, NVGcolor& color) { nvgBeginPath(graphics::vg); nvgCircle(graphics::vg, circle.x, circle.y, circle.r); nvgFillColor(graphics::vg, color); nvgFill(graphics::vg); }
static void drawRoundedRect(float x, float y, float w, float h, float r, float fth, unsigned int col) { nvgBeginPath(vg::ctx); nvgFillColor(vg::ctx, nvgRGBA(col&0xff, (col>>8)&0xff, (col>>16)&0xff, (col>>24)&0xff)); nvgRoundedRect(vg::ctx, x, y, w, h, r); nvgFill(vg::ctx); }
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 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 drawCheckBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h) { struct NVGpaint bg; char icon[8]; NVG_NOTUSED(w); nvgFontSize(vg, 18.0f); nvgFontFace(vg, "sans"); nvgFillColor(vg, nvgRGBA(255,255,255,160) ); nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); nvgText(vg, x+28,y+h*0.5f,text, NULL); bg = nvgBoxGradient(vg, x+1,y+(int)(h*0.5f)-9+1, 18,18, 3,3, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,92) ); nvgBeginPath(vg); nvgRoundedRect(vg, x+1,y+(int)(h*0.5f)-9, 18,18, 3); nvgFillPaint(vg, bg); nvgFill(vg); nvgFontSize(vg, 40); nvgFontFace(vg, "icons"); nvgFillColor(vg, nvgRGBA(255,255,255,128) ); nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); nvgText(vg, x+9+2, y+h*0.5f, cpToUTF8(ICON_CHECK,icon), NULL); }
void vsDropShadow(NVGcontext *ctx, float x, float y, float w, float h, float r, float feather, float alpha) { nvgBeginPath(ctx); y += feather; h -= feather; nvgMoveTo(ctx, x - feather, y - feather); nvgLineTo(ctx, x, y - feather); nvgLineTo(ctx, x, y + h - feather); nvgArcTo(ctx, x, y + h, x + r, y + h, r); nvgArcTo(ctx, x + w, y + h, x + w, y + h - r, r); nvgLineTo(ctx, x + w, y - feather); nvgLineTo(ctx, x + w + feather, y - feather); nvgLineTo(ctx, x + w + feather, y + h + feather); nvgLineTo(ctx, x - feather, y + h + feather); nvgClosePath(ctx); nvgFillPaint(ctx, nvgBoxGradient(ctx, x - feather * 0.5f, y - feather * 0.5f, w + feather, h + feather, r + feather * 0.5f, feather, nvgRGBAf(0, 0, 0, alpha * alpha), nvgRGBAf(0, 0, 0, 0))); nvgFill(ctx); }
void QNanoPainter::drawImage(QNanoImage &image, const QRectF sourceRect, const QRectF destinationRect) { image.setParentPainter(this); float sx = sourceRect.x(); float sy = sourceRect.y(); float sw = sourceRect.width(); float sh = sourceRect.height(); float dx = destinationRect.x(); float dy = destinationRect.y(); float dw = destinationRect.width(); float dh = destinationRect.height(); _checkAlignPixelsAdjust(&dx, &dy); _checkAlignPixels(&dw, &dh); float startX = dx - sx * (dw/sw); float startY = dy - sy * (dh/sh); float endX = dw * image.width() / sw; float endY = dh * image.height() / sh; NVGpaint ip = nvgImagePattern(nvgCtx(), startX, startY, endX, endY, 0.0f, image.getID(nvgCtx()), 1.0f); nvgSave(nvgCtx()); nvgBeginPath(nvgCtx()); rect(dx, dy, dw, dh); nvgFillPaint(nvgCtx(), ip); nvgFill(nvgCtx()); nvgRestore(nvgCtx()); }