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 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 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); }
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 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 Screen::drawWidgets() { if (!mVisible) return; glfwMakeContextCurrent(mGLFWWindow); glfwGetFramebufferSize(mGLFWWindow, &mFBSize[0], &mFBSize[1]); glfwGetWindowSize(mGLFWWindow, &mSize[0], &mSize[1]); glViewport(0, 0, mFBSize[0], mFBSize[1]); /* Calculate pixel ratio for hi-dpi devices. */ mPixelRatio = (float) mFBSize[0] / (float) mSize[0]; nvgBeginFrame(mNVGContext, mSize[0], mSize[1], mPixelRatio); draw(mNVGContext); double elapsed = glfwGetTime() - mLastInteraction; if (elapsed > 0.5f) { /* Draw tooltips */ const Widget *widget = findWidget(mMousePos); if (widget && !widget->tooltip().empty()) { int tooltipWidth = 150; float bounds[4]; nvgFontFace(mNVGContext, "sans"); nvgFontSize(mNVGContext, 15.0f); nvgTextAlign(mNVGContext, NVG_ALIGN_CENTER | NVG_ALIGN_TOP); nvgTextLineHeight(mNVGContext, 1.1f); Vector2i pos = widget->absolutePosition() + Vector2i(widget->width() / 2, widget->height() + 10); nvgTextBoxBounds(mNVGContext, pos.x(), pos.y(), tooltipWidth, widget->tooltip().c_str(), nullptr, bounds); nvgGlobalAlpha(mNVGContext, std::min(1.0, 2 * (elapsed - 0.5f)) * 0.8); nvgBeginPath(mNVGContext); nvgFillColor(mNVGContext, Color(0, 255)); int h = (bounds[2] - bounds[0]) / 2; nvgRoundedRect(mNVGContext, bounds[0] - 4 - h, bounds[1] - 4, (int) (bounds[2] - bounds[0]) + 8, (int) (bounds[3] - bounds[1]) + 8, 3); int px = (int) ((bounds[2] + bounds[0]) / 2) - h; nvgMoveTo(mNVGContext, px, bounds[1] - 10); nvgLineTo(mNVGContext, px + 7, bounds[1] + 1); nvgLineTo(mNVGContext, px - 7, bounds[1] + 1); nvgFill(mNVGContext); nvgFillColor(mNVGContext, Color(255, 255)); nvgFontBlur(mNVGContext, 0.0f); nvgTextBox(mNVGContext, pos.x() - h, pos.y(), tooltipWidth, widget->tooltip().c_str(), nullptr); } } nvgEndFrame(mNVGContext); }
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 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 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 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 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); }
int main() { glfwInit(); glfwDefaultWindowHints(); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); GLFWwindow *window = glfwCreateWindow(800, 600, "nanovg Demo", nullptr, nullptr); NVGcontext *vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG); while (!glfwWindowShouldClose(window)) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); nvgBeginFrame(vg, 800, 600, 1); nvgBeginPath(vg); nvgRoundedRect(vg, 12, 12, 800-12*2, 600-12*2, 4); nvgFillColor(vg, nvgRGBA(255, 255, 255, 192)); nvgFill(vg); nvgEndFrame(vg); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; }
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::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 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 TextNode::renderItself(RenderContext& renderContext) { NVGcontext& nanoVgContext = renderContext.getNanoVgContext(); nvgSave(&nanoVgContext); setupContext(nanoVgContext); Color finalColor = mFontColor.getBlendedColor(renderContext.getBlendColors()); nvgFillColor(&nanoVgContext, nvgRGBAf(finalColor.getRed(), finalColor.getGreen(), finalColor.getBlue(), finalColor.getAlpha())); for(const Text& text : mTexts) { const char* charArray = text.getString().getCharArray(); float positionX = text.getPosition().getX(); float positionY = text.getPosition().getY(); if(isPositive(text.getBoxWidth())) { nvgTextBox(&nanoVgContext, positionX, positionY, text.getBoxWidth(), charArray, nullptr); } else { nvgText(&nanoVgContext, positionX, positionY, charArray, nullptr); } } nvgRestore(&nanoVgContext); Node::renderItself(renderContext); }
void Material::update(NVGcontext* vg, double time) { if (m_framebufferObject == nullptr) return; if (m_initialized == true && m_animate == false) return; float circle_size = float((cos(time) + 1.0) * 128.0); nvgluBindFramebuffer(m_framebufferObject); glViewport(0, 0, m_width, m_height); // Any alpha other than zero will fail for some FBO reason glClearColor(m_color.r, m_color.g, m_color.b, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); nvgBeginFrame(vg, m_width, m_height, /*pixelRatio*/1.0f); nvgBeginPath(vg); if (m_animate) nvgCircle(vg, float(m_width) * 0.5f, float(m_height) * 0.5f, circle_size); if(m_type == 2) nvgFillColor(vg, nvgRGBA(220, 45, 0, 200)); else if(m_type == 1) nvgFillColor(vg, nvgRGBA(0, 220, 45, 200)); else nvgFillColor(vg, nvgRGBA(10, 145, 200, 200)); nvgFill(vg); if(m_type == 2) { nvgFontFace(vg, "sans"); nvgFontSize(vg, 80.0f); nvgTextAlign(vg, NVG_ALIGN_CENTER); nvgFillColor(vg, nvgRGBA(255, 255, 255, 255)); nvgText(vg, float(m_width) * 0.5f, (float(m_height) * 0.5f) + 20.0f, "Add Object", nullptr); } nvgEndFrame(vg); nvgluBindFramebuffer(NULL); m_initialized = true; }
static void draw_circle(NVGcontext *ctx, float x, float y, float r, const gui_byte *c) { nvgBeginPath(ctx); nvgCircle(ctx, x + r, y + r, r); nvgFillColor(ctx, nvgRGBA(c[0], c[1], c[2], c[3])); nvgFill(ctx); }
static void draw_rect(NVGcontext *ctx, float x, float y, float w, float h, float r, const gui_byte* c) { nvgBeginPath(ctx); nvgRoundedRect(ctx, x, y, w, h, r); nvgFillColor(ctx, nvgRGBA(c[0], c[1], c[2], c[3])); nvgFill(ctx); }
void Label::on_draw() { nvgFontSize(vg, 18.0f); nvgFontFace(vg, "sans"); nvgTextAlign(vg, NVG_ALIGN_RIGHT | NVG_ALIGN_MIDDLE); nvgFillColor(vg, nvgRGBA(240, 240, 240, 255)); nvgText(vg, x,y, text.c_str(), NULL); }
static void draw_rect(NVGcontext *ctx, float x, float y, float w, float h, float r, struct gui_color c) { nvgBeginPath(ctx); nvgRoundedRect(ctx, x, y, w, h, r); nvgFillColor(ctx, nvgRGBA(c.r, c.g, c.b, c.a)); nvgFill(ctx); }
static void draw_circle(NVGcontext *ctx, float x, float y, float r, struct gui_color c) { nvgBeginPath(ctx); nvgCircle(ctx, x + r, y + r, r); nvgFillColor(ctx, nvgRGBA(c.r, c.g, c.b, c.a)); nvgFill(ctx); }
static void draw_line(NVGcontext *ctx, float x0, float y0, float x1, float y1, const gui_byte *c) { nvgBeginPath(ctx); nvgMoveTo(ctx, x0, y0); nvgLineTo(ctx, x1, y1); nvgFillColor(ctx, nvgRGBA(c[0], c[1], c[2], c[3])); nvgFill(ctx); }
static void draw_line(NVGcontext *ctx, float x0, float y0, float x1, float y1, struct gui_color c) { nvgBeginPath(ctx); nvgMoveTo(ctx, x0, y0); nvgLineTo(ctx, x1, y1); nvgFillColor(ctx, nvgRGBA(c.r, c.g, c.b, c.a)); nvgFill(ctx); }