void Application::drawUI() { if (context->dirtyUI) { context->setCursor(nullptr); if (uiFrameBuffer->width() != context->screenSize.x || uiFrameBuffer->height() != context->screenSize.y) { uiFrameBuffer->initialize(context->screenSize.x, context->screenSize.y); } uiFrameBuffer->begin(); glViewport(0, 0, uiFrameBuffer->width(),uiFrameBuffer->height()); NVGcontext* nvg = context->nvgContext; nvgBeginFrame(nvg, uiFrameBuffer->width(), uiFrameBuffer->height(),1.0f);//(float) context->pixelRatio nvgScissor(nvg, 0, 0, (float)uiFrameBuffer->width(), (float)uiFrameBuffer->height()); rootRegion.draw(context.get()); nvgScissor(nvg, 0, 0, (float)uiFrameBuffer->width(), (float)uiFrameBuffer->height()); Region* onTop = context->getOnTopRegion(); if (onTop != nullptr) { if (onTop->isVisible()) onTop->draw(context.get()); } const Cursor* cursor = context->getCursor(); if (!cursor) { cursor = &Cursor::Normal; } nvgEndFrame(nvg); uiFrameBuffer->end(); context->dirtyUI = false; } imageShader->draw(uiFrameBuffer->getTexture(), pixel2(0, 0),pixel2(context->viewSize)); }
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); }
virtual void onDraw() override { if (y() + height > 0) { if (y() < 0) nvgScissor(vg, gX(), gY() - y(), width, y() + height); BaseTrack::drawBase(); drawTrackFrame(); VS_RENDER_CHILDREN(); } }
static void draw(NVGcontext *nvg, struct gui_command_queue *queue, int width, int height) { const struct gui_command *cmd; glPushAttrib(GL_ENABLE_BIT|GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glEnable(GL_TEXTURE_2D); nvgBeginFrame(nvg, width, height, ((float)width/(float)height)); gui_foreach_command(cmd, queue) { switch (cmd->type) { case GUI_COMMAND_NOP: break; case GUI_COMMAND_SCISSOR: { const struct gui_command_scissor *s = gui_command(scissor, cmd); nvgScissor(nvg, s->x, s->y, s->w, s->h); } break; case GUI_COMMAND_LINE: { const struct gui_command_line *l = gui_command(line, cmd); draw_line(nvg, l->begin.x, l->begin.y, l->end.x, l->end.y, l->color); } break; case GUI_COMMAND_RECT: { const struct gui_command_rect *r = gui_command(rect, cmd); draw_rect(nvg, r->x, r->y, r->w, r->h, r->rounding, r->color); } break; case GUI_COMMAND_CIRCLE: { const struct gui_command_circle *c = gui_command(circle, cmd); draw_circle(nvg, c->x, c->y, (float)c->w / 2.0f, c->color); } break; case GUI_COMMAND_TRIANGLE: { const struct gui_command_triangle *t = gui_command(triangle, cmd); draw_triangle(nvg, t->a.x, t->a.y, t->b.x, t->b.y, t->c.x, t->c.y, t->color); } break; case GUI_COMMAND_TEXT: { const struct gui_command_text *t = gui_command(text, cmd); draw_text(nvg, t->x, t->y, t->w, t->h, t->foreground, t->background, t->string, t->length); } break; case GUI_COMMAND_IMAGE: { const struct gui_command_image *i = gui_command(image, cmd); draw_image(nvg, i->img.handle, i->x, i->y, i->w, i->h, 1); } break; case GUI_COMMAND_MAX: default: break; } } gui_command_queue_clear(queue); nvgResetScissor(nvg); nvgEndFrame(nvg); glPopAttrib(); }
void NanoVG::scissor( float x, float y, float w, float h ) { nvgScissor( m_context(), x, y, w, h ); }
void NVGRenderer::scissor(float x, float y, float w, float h) { nvgScissor(m_context, x, y, w, h); }
void Window::draw(NVGcontext *ctx) { int ds = mTheme->mWindowDropShadowSize, cr = mTheme->mWindowCornerRadius; int hh = mTheme->mWindowHeaderHeight; /* Draw window */ nvgSave(ctx); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), cr); nvgFillColor(ctx, mMouseFocus ? mTheme->mWindowFillFocused : mTheme->mWindowFillUnfocused); nvgFill(ctx); /* 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); if (!mTitle.empty()) { /* Draw header */ NVGpaint headerPaint = nvgLinearGradient( ctx, mPos.x(), mPos.y(), mPos.x(), mPos.y() + hh, mTheme->mWindowHeaderGradientTop, mTheme->mWindowHeaderGradientBot); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), hh, cr); nvgFillPaint(ctx, headerPaint); nvgFill(ctx); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), hh, cr); nvgStrokeColor(ctx, mTheme->mWindowHeaderSepTop); nvgScissor(ctx, mPos.x(), mPos.y(), mSize.x(), 0.5f); nvgStroke(ctx); nvgResetScissor(ctx); nvgBeginPath(ctx); nvgMoveTo(ctx, mPos.x() + 0.5f, mPos.y() + hh - 1.5f); nvgLineTo(ctx, mPos.x() + mSize.x() - 0.5f, mPos.y() + hh - 1.5); nvgStrokeColor(ctx, mTheme->mWindowHeaderSepBot); nvgStroke(ctx); nvgFontSize(ctx, 18.0f); nvgFontFace(ctx, "sans-bold"); nvgTextAlign(ctx, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE); nvgFontBlur(ctx, 2); nvgFillColor(ctx, mTheme->mDropShadow); nvgText(ctx, mPos.x() + mSize.x() / 2, mPos.y() + hh / 2, mTitle.c_str(), nullptr); nvgFontBlur(ctx, 0); nvgFillColor(ctx, mFocused ? mTheme->mWindowTitleFocused : mTheme->mWindowTitleUnfocused); nvgText(ctx, mPos.x() + mSize.x() / 2, mPos.y() + hh / 2 - 1, mTitle.c_str(), nullptr); } nvgRestore(ctx); Widget::draw(ctx); }
void drawThumbnails(struct NVGcontext* vg, float x, float y, float w, float h, const int* images, int nimages, float t) { float cornerRadius = 3.0f; struct NVGpaint shadowPaint, imgPaint, fadePaint; float ix,iy,iw,ih; float thumb = 60.0f; float arry = 30.5f; int imgw, imgh; float stackh = (nimages/2) * (thumb+10) + 10; int i; float u = (1+cosf(t*0.5f) )*0.5f; float scrollh; nvgSave(vg); // nvgClearState(vg); // Drop shadow shadowPaint = nvgBoxGradient(vg, x,y+4, w,h, cornerRadius*2, 20, 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); // Window nvgBeginPath(vg); nvgRoundedRect(vg, x,y, w,h, cornerRadius); nvgMoveTo(vg, x-10,y+arry); nvgLineTo(vg, x+1,y+arry-11); nvgLineTo(vg, x+1,y+arry+11); nvgFillColor(vg, nvgRGBA(200,200,200,255) ); nvgFill(vg); nvgSave(vg); nvgScissor(vg, x,y,w,h); nvgTranslate(vg, 0, -(stackh - h)*u); for (i = 0; i < nimages; i++) { float tx, ty; tx = x+10; ty = y+10; tx += (i%2) * (thumb+10); ty += (i/2) * (thumb+10); nvgImageSize(vg, images[i], &imgw, &imgh); if (imgw < imgh) { iw = thumb; ih = iw * (float)imgh/(float)imgw; ix = 0; iy = -(ih-thumb)*0.5f; } else { ih = thumb; iw = ih * (float)imgw/(float)imgh; ix = -(iw-thumb)*0.5f; iy = 0; } imgPaint = nvgImagePattern(vg, tx+ix, ty+iy, iw,ih, 0.0f/180.0f*NVG_PI, images[i], 0); nvgBeginPath(vg); nvgRoundedRect(vg, tx,ty, thumb,thumb, 5); nvgFillPaint(vg, imgPaint); nvgFill(vg); shadowPaint = nvgBoxGradient(vg, tx-1,ty, thumb+2,thumb+2, 5, 3, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0) ); nvgBeginPath(vg); nvgRect(vg, tx-5,ty-5, thumb+10,thumb+10); nvgRoundedRect(vg, tx,ty, thumb,thumb, 6); nvgPathWinding(vg, NVG_HOLE); nvgFillPaint(vg, shadowPaint); nvgFill(vg); nvgBeginPath(vg); nvgRoundedRect(vg, tx+0.5f,ty+0.5f, thumb-1,thumb-1, 4-0.5f); nvgStrokeWidth(vg,1.0f); nvgStrokeColor(vg, nvgRGBA(255,255,255,192) ); nvgStroke(vg); } nvgRestore(vg); // Hide fades fadePaint = nvgLinearGradient(vg, x,y,x,y+6, nvgRGBA(200,200,200,255), nvgRGBA(200,200,200,0) ); nvgBeginPath(vg); nvgRect(vg, x+4,y,w-8,6); nvgFillPaint(vg, fadePaint); nvgFill(vg); fadePaint = nvgLinearGradient(vg, x,y+h,x,y+h-6, nvgRGBA(200,200,200,255), nvgRGBA(200,200,200,0) ); nvgBeginPath(vg); nvgRect(vg, x+4,y+h-6,w-8,6); nvgFillPaint(vg, fadePaint); nvgFill(vg); // Scroll bar shadowPaint = nvgBoxGradient(vg, x+w-12+1,y+4+1, 8,h-8, 3,4, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,92) ); nvgBeginPath(vg); nvgRoundedRect(vg, x+w-12,y+4, 8,h-8, 3); nvgFillPaint(vg, shadowPaint); // nvgFillColor(vg, nvgRGBA(255,0,0,128) ); nvgFill(vg); scrollh = (h/stackh) * (h-8); shadowPaint = nvgBoxGradient(vg, x+w-12-1,y+4+(h-8-scrollh)*u-1, 8,scrollh, 3,4, nvgRGBA(220,220,220,255), nvgRGBA(128,128,128,255) ); nvgBeginPath(vg); nvgRoundedRect(vg, x+w-12+1,y+4+1 + (h-8-scrollh)*u, 8-2,scrollh-2, 2); nvgFillPaint(vg, shadowPaint); // nvgFillColor(vg, nvgRGBA(0,0,0,128) ); nvgFill(vg); nvgRestore(vg); }
void QNanoPainter::setClipRect(float x, float y, float width, float height) { _checkAlignPixelsAdjust(&x, &y); _checkAlignPixels(&width, &height); nvgScissor(nvgCtx(), x, y, width, height); }
void TextBox::draw(NVGcontext* ctx) { Widget::draw(ctx); NVGpaint bg = nvgBoxGradient(ctx, mPos.x() + 1, mPos.y() + 1 + 1.0f, mSize.x() - 2, mSize.y() - 2, 3, 4, Color(255, 32), Color(32, 32)); NVGpaint fg1 = nvgBoxGradient(ctx, mPos.x() + 1, mPos.y() + 1 + 1.0f, mSize.x() - 2, mSize.y() - 2, 3, 4, Color(150, 32), Color(32, 32)); NVGpaint fg2 = nvgBoxGradient(ctx, mPos.x() + 1, mPos.y() + 1 + 1.0f, mSize.x() - 2, mSize.y() - 2, 3, 4, nvgRGBA(255, 0, 0, 100), nvgRGBA(255, 0, 0, 50)); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x() + 1, mPos.y() + 1 + 1.0f, mSize.x() - 2, mSize.y() - 2, 3); if(mEditable && focused()) mValidFormat ? nvgFillPaint(ctx, fg1) : nvgFillPaint(ctx, fg2); else nvgFillPaint(ctx, bg); nvgFill(ctx); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x() + 0.5f, mPos.y() + 0.5f, mSize.x() - 1, mSize.y() - 1, 2.5f); nvgStrokeColor(ctx, Color(0, 48)); nvgStroke(ctx); nvgFontSize(ctx, fontSize()); nvgFontFace(ctx, "sans"); Vector2i drawPos(mPos.x(), mPos.y() + mSize.y() * 0.5f + 1); float xSpacing = mSize.y() * 0.3f; float unitWidth = 0; if (mUnitsImage > 0) { int w, h; nvgImageSize(ctx, mUnitsImage, &w, &h); float unitHeight = mSize.y() * 0.4f; unitWidth = w * unitHeight / h; NVGpaint imgPaint = nvgImagePattern( ctx, mPos.x() + mSize.x() - xSpacing - unitWidth, drawPos.y() - unitHeight * 0.5f, unitWidth, unitHeight, 0, mUnitsImage, mEnabled ? 0.7f : 0.35f); nvgBeginPath(ctx); nvgRect(ctx, mPos.x() + mSize.x() - xSpacing - unitWidth, drawPos.y() - unitHeight * 0.5f, unitWidth, unitHeight); nvgFillPaint(ctx, imgPaint); nvgFill(ctx); unitWidth += 2; } else if (!mUnits.empty()) { unitWidth = nvgTextBounds(ctx, 0, 0, mUnits.c_str(), nullptr, nullptr); nvgFillColor(ctx, Color(255, mEnabled ? 64 : 32)); nvgTextAlign(ctx, NVG_ALIGN_RIGHT | NVG_ALIGN_MIDDLE); nvgText(ctx, mPos.x() + mSize.x() - xSpacing, drawPos.y(), mUnits.c_str(), nullptr); unitWidth += 2; } switch (mAlignment) { case Alignment::Left: nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); drawPos.x() += xSpacing; break; case Alignment::Right: nvgTextAlign(ctx, NVG_ALIGN_RIGHT | NVG_ALIGN_MIDDLE); drawPos.x() += mSize.x() - unitWidth - xSpacing; break; case Alignment::Center: nvgTextAlign(ctx, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE); drawPos.x() += mSize.x() * 0.5f; break; } nvgFontSize(ctx, fontSize()); nvgFillColor(ctx, mEnabled ? mTheme->mTextColor : mTheme->mDisabledTextColor); // clip visible text area float clipX = mPos.x() + xSpacing - 1.0f; float clipY = mPos.y() + 1.0f; float clipWidth = mSize.x() - unitWidth - 2 * xSpacing + 2.0f; float clipHeight = mSize.y() - 3.0f; nvgScissor(ctx, clipX, clipY, clipWidth, clipHeight); Vector2i oldDrawPos(drawPos); drawPos.x() += mTextOffset; if (mCommitted) { nvgText(ctx, drawPos.x(), drawPos.y(), mValue.c_str(), nullptr); } else { const int maxGlyphs = 1024; NVGglyphPosition glyphs[maxGlyphs]; float textBound[4]; nvgTextBounds(ctx, drawPos.x(), drawPos.y(), mValueTemp.c_str(), nullptr, textBound); float lineh = textBound[3] - textBound[1]; // find cursor positions int nglyphs = nvgTextGlyphPositions(ctx, drawPos.x(), drawPos.y(), mValueTemp.c_str(), nullptr, glyphs, maxGlyphs); updateCursor(ctx, textBound[2], glyphs, nglyphs); // compute text offset int prevCPos = mCursorPos > 0 ? mCursorPos - 1 : 0; int nextCPos = mCursorPos < nglyphs ? mCursorPos + 1 : nglyphs; float prevCX = cursorIndex2Position(prevCPos, textBound[2], glyphs, nglyphs); float nextCX = cursorIndex2Position(nextCPos, textBound[2], glyphs, nglyphs); if (nextCX > clipX + clipWidth) mTextOffset -= nextCX - (clipX + clipWidth) + 1; if (prevCX < clipX) mTextOffset += clipX - prevCX + 1; drawPos.x() = oldDrawPos.x() + mTextOffset; // draw text with offset nvgText(ctx, drawPos.x(), drawPos.y(), mValueTemp.c_str(), nullptr); nvgTextBounds(ctx, drawPos.x(), drawPos.y(), mValueTemp.c_str(), nullptr, textBound); // recompute cursor positions nglyphs = nvgTextGlyphPositions(ctx, drawPos.x(), drawPos.y(), mValueTemp.c_str(), nullptr, glyphs, maxGlyphs); if (mCursorPos > -1) { if (mSelectionPos > -1) { float caretx = cursorIndex2Position(mCursorPos, textBound[2], glyphs, nglyphs); float selx = cursorIndex2Position(mSelectionPos, textBound[2], glyphs, nglyphs); if (caretx > selx) std::swap(caretx, selx); // draw selection nvgBeginPath(ctx); nvgFillColor(ctx, nvgRGBA(255, 255, 255, 80)); nvgRect(ctx, caretx, drawPos.y() - lineh * 0.5f, selx - caretx, lineh); nvgFill(ctx); } float caretx = cursorIndex2Position(mCursorPos, textBound[2], glyphs, nglyphs); // draw cursor nvgBeginPath(ctx); nvgMoveTo(ctx, caretx, drawPos.y() - lineh * 0.5f); nvgLineTo(ctx, caretx, drawPos.y() + lineh * 0.5f); nvgStrokeColor(ctx, nvgRGBA(255, 192, 0, 255)); nvgStrokeWidth(ctx, 1.0f); nvgStroke(ctx); } } nvgResetScissor(ctx); }
static void draw(NVGcontext *nvg, struct zr_command_queue *queue, int width, int height) { const struct zr_command *cmd; glPushAttrib(GL_ENABLE_BIT|GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glEnable(GL_TEXTURE_2D); nvgBeginFrame(nvg, width, height, ((float)width/(float)height)); zr_foreach_command(cmd, queue) { switch (cmd->type) { case ZR_COMMAND_NOP: break; case ZR_COMMAND_SCISSOR: { const struct zr_command_scissor *s = zr_command(scissor, cmd); nvgScissor(nvg, s->x, s->y, s->w, s->h); } break; case ZR_COMMAND_LINE: { const struct zr_command_line *l = zr_command(line, cmd); nvgBeginPath(nvg); nvgMoveTo(nvg, l->begin.x, l->begin.y); nvgLineTo(nvg, l->end.x, l->end.y); nvgFillColor(nvg, nvgRGBA(l->color.r, l->color.g, l->color.b, l->color.a)); nvgFill(nvg); } break; case ZR_COMMAND_CURVE: { const struct zr_command_curve *q = zr_command(curve, cmd); nvgBeginPath(nvg); nvgMoveTo(nvg, q->begin.x, q->begin.y); nvgBezierTo(nvg, q->ctrl[0].x, q->ctrl[0].y, q->ctrl[1].x, q->ctrl[1].y, q->end.x, q->end.y); nvgStrokeColor(nvg, nvgRGBA(q->color.r, q->color.g, q->color.b, q->color.a)); nvgStroke(nvg); } break; case ZR_COMMAND_RECT: { const struct zr_command_rect *r = zr_command(rect, cmd); nvgBeginPath(nvg); nvgRoundedRect(nvg, r->x, r->y, r->w, r->h, r->rounding); nvgFillColor(nvg, nvgRGBA(r->color.r, r->color.g, r->color.b, r->color.a)); nvgFill(nvg); } break; case ZR_COMMAND_CIRCLE: { const struct zr_command_circle *c = zr_command(circle, cmd); nvgBeginPath(nvg); nvgCircle(nvg, c->x + (c->w/2.0f), c->y + c->w/2.0f, c->w/2.0f); nvgFillColor(nvg, nvgRGBA(c->color.r, c->color.g, c->color.b, c->color.a)); nvgFill(nvg); } break; case ZR_COMMAND_TRIANGLE: { const struct zr_command_triangle *t = zr_command(triangle, cmd); nvgBeginPath(nvg); nvgMoveTo(nvg, t->a.x, t->a.y); nvgLineTo(nvg, t->b.x, t->b.y); nvgLineTo(nvg, t->c.x, t->c.y); nvgLineTo(nvg, t->a.x, t->a.y); nvgFillColor(nvg, nvgRGBA(t->color.r, t->color.g, t->color.b, t->color.a)); nvgFill(nvg); } break; case ZR_COMMAND_TEXT: { const struct zr_command_text *t = zr_command(text, cmd); nvgBeginPath(nvg); nvgRoundedRect(nvg, t->x, t->y, t->w, t->h, 0); nvgFillColor(nvg, nvgRGBA(t->background.r, t->background.g, t->background.b, t->background.a)); nvgFill(nvg); nvgBeginPath(nvg); nvgFillColor(nvg, nvgRGBA(t->foreground.r, t->foreground.g, t->foreground.b, t->foreground.a)); nvgTextAlign(nvg, NVG_ALIGN_MIDDLE); nvgText(nvg, t->x, t->y + t->h * 0.5f, t->string, &t->string[t->length]); nvgFill(nvg); } break; case ZR_COMMAND_IMAGE: { const struct zr_command_image *i = zr_command(image, cmd); NVGpaint imgpaint; imgpaint = nvgImagePattern(nvg, i->x, i->y, i->w, i->h, 0, i->img.handle.id, 1.0f); nvgBeginPath(nvg); nvgRoundedRect(nvg, i->x, i->y, i->w, i->h, 0); nvgFillPaint(nvg, imgpaint); nvgFill(nvg); } break; case ZR_COMMAND_ARC: default: break; } } zr_command_queue_clear(queue); nvgResetScissor(nvg); nvgEndFrame(nvg); glPopAttrib(); }
void imguiRenderNVGDraw() { const imguiGfxCmd* q = imguiGetRenderQueue(); int nq = imguiGetRenderQueueSize(); const float s = 1.0f/8.0f; nvgResetScissor(vg::ctx); for (int i = 0; i < nq; ++i) { const imguiGfxCmd& cmd = q[i]; if (cmd.type == IMGUI_GFXCMD_RECT) { if (cmd.rect.r == 0) { drawRect((float)cmd.rect.x*s+0.5f, (float)cmd.rect.y*s+0.5f, (float)cmd.rect.w*s-1, (float)cmd.rect.h*s-1, 1.0f, cmd.col); } else { drawRoundedRect((float)cmd.rect.x*s+0.5f, (float)cmd.rect.y*s+0.5f, (float)cmd.rect.w*s-1, (float)cmd.rect.h*s-1, (float)cmd.rect.r*s, 1.0f, cmd.col); } } else if (cmd.type == IMGUI_GFXCMD_LINE) { drawLine(cmd.line.x0*s, cmd.line.y0*s, cmd.line.x1*s, cmd.line.y1*s, cmd.line.r*s, 1.0f, cmd.col); } else if (cmd.type == IMGUI_GFXCMD_TRIANGLE) { if (cmd.flags == 1) { const float verts[3*2] = { (float)cmd.rect.x*s+0.5f, (float)cmd.rect.y*s+0.5f, (float)cmd.rect.x*s+0.5f+(float)cmd.rect.w*s-1, (float)cmd.rect.y*s+0.5f+(float)cmd.rect.h*s/2-0.5f, (float)cmd.rect.x*s+0.5f, (float)cmd.rect.y*s+0.5f+(float)cmd.rect.h*s-1, }; drawPolygon(verts, 3, 1.0f, cmd.col); } if (cmd.flags == 2) { const float verts[3*2] = { (float)cmd.rect.x*s+0.5f, (float)cmd.rect.y*s+0.5f+(float)cmd.rect.h*s-1, (float)cmd.rect.x*s+0.5f+(float)cmd.rect.w*s/2-0.5f, (float)cmd.rect.y*s+0.5f, (float)cmd.rect.x*s+0.5f+(float)cmd.rect.w*s-1, (float)cmd.rect.y*s+0.5f+(float)cmd.rect.h*s-1, }; drawPolygon(verts, 3, 1.0f, cmd.col); } } else if (cmd.type == IMGUI_GFXCMD_TEXT) { drawText(cmd.text.x, cmd.text.y, cmd.text.text, cmd.text.align, cmd.col); } else if (cmd.type == IMGUI_GFXCMD_SCISSOR) { if (cmd.flags) { nvgScissor(vg::ctx, cmd.rect.x, cmd.rect.y, cmd.rect.w, cmd.rect.h); } else { nvgResetScissor(vg::ctx); } } } nvgResetScissor(vg::ctx); }
bool setScissor(const Vector2f& pos, const Vector2f& size) { if (!m_inited) return false; nvgScissor(m_vg, pos.x, pos.y, size.x, size.y); return true; }
JNIEXPORT void JNICALL Java_firststep_internal_NVG_scissor (JNIEnv *e, jclass c, jlong ctx, jfloat x, jfloat y, jfloat w, jfloat h) { nvgScissor((NVGcontext*)ctx, x,y, w,h); }
void NanoInk::redrawText() { InkStyle& skin = this->skin(); nvgResetDisplayList(mTextCache); nvgBindDisplayList(mCtx, mTextCache); float left = mFrame.cleft(); float top = mFrame.ctop(); float width = mFrame.cwidth(); float height = mFrame.cheight(); float pleft = mFrame.pleft(); float ptop = mFrame.ptop(); float pwidth = mFrame.pwidth(); float pheight = mFrame.pheight(); float contentWidth = contentSize(DIM_X) - skin.padding()[DIM_X] - skin.padding()[DIM_X + 2]; float contentHeight = contentSize(DIM_Y) - skin.padding()[DIM_Y] - skin.padding()[DIM_Y + 2]; float cleft = pleft; NVGalign halign = NVG_ALIGN_LEFT; if(skin.align()[DIM_X] == CENTER) { halign = NVG_ALIGN_CENTER; cleft = pleft + pwidth / 2.f - contentWidth / 2.f; } else if(skin.align()[DIM_X] == RIGHT) { halign = NVG_ALIGN_RIGHT; cleft = pleft + pwidth - contentWidth; } float ctop = ptop; if(skin.align()[DIM_Y] == CENTER) ctop = ptop + pheight / 2.f - contentHeight / 2.f; else if(skin.align()[DIM_Y] == RIGHT) ctop = ptop + pheight - contentHeight; // Caption if(!mFrame.widget().label().empty() && !(pwidth <= 0.f || pheight <= 0.f)) { //if(mFrame.dclip(DIM_X) || mFrame.dclip(DIM_Y)) // ^ @note this doesn't work because a frame is set to clipped only by its parent, and not when the label is larger than the frame itself nvgScissor(mCtx, left, top, width, height); this->setupText(); float lineh = 0.f; nvgTextMetrics(mCtx, NULL, NULL, &lineh); const char* start = mFrame.widget().label().c_str(); float x = pleft; float y = ptop; for(NVGtextRow& row : mTextRows) { if(halign & NVG_ALIGN_LEFT) x = pleft; else if(halign & NVG_ALIGN_CENTER) x = pleft + pwidth*0.5f - row.width*0.5f; else if(halign & NVG_ALIGN_RIGHT) x = pleft + pwidth - row.width; if(mSelectFirst != mSelectSecond) { size_t indexStart = row.start - start; size_t indexEnd = row.end - start; if(indexEnd > selectStart() && indexStart < selectEnd()) { size_t selectStart = std::max(indexStart, this->selectStart()); size_t selectEnd = std::min(indexEnd, this->selectEnd()); NVGglyphPosition startPosition; nvgTextGlyphPosition(mCtx, 0.f, 0.f, row.start, row.end, selectStart - (row.start - start), &startPosition); NVGglyphPosition endPosition; nvgTextGlyphPosition(mCtx, 0.f, 0.f, row.start, row.end, selectEnd - (row.start - start), &endPosition); nvgBeginPath(mCtx); nvgFillColor(mCtx, nvgRGBA(0, 55, 255, 124)); nvgRect(mCtx, x + startPosition.x, y, endPosition.x - startPosition.x, lineh); nvgFill(mCtx); } } nvgFillColor(mCtx, nvgColour(skin.mTextColour)); nvgText(mCtx, x, y, row.start, row.end); y += lineh; } /* nvgText(mCtx, cleft, ctop, mFrame.widget().label().c_str(), nullptr); */ nvgResetScissor(mCtx); } if(mFrame.dclip(DIM_X) || mFrame.dclip(DIM_Y)) nvgResetScissor(mCtx); nvgBindDisplayList(mCtx, nullptr); }
void NanoInk::redrawImage() { InkStyle& skin = this->skin(); float left = mFrame.cleft(); float top = mFrame.ctop(); float width = mFrame.cwidth(); float height = mFrame.cheight(); float pleft = mFrame.pleft(); float ptop = mFrame.ptop(); float pwidth = mFrame.pwidth(); float pheight = mFrame.pheight(); float halfb = skin.borderWidth().x0() * 0.5; float b = skin.borderWidth().x0(); if(width - b <= 0.f || height - b <= 0.f) return; nvgResetDisplayList(mImageCache); nvgBindDisplayList(mCtx, mImageCache); float contentWidth = contentSize(DIM_X) - skin.padding()[DIM_X] - skin.padding()[DIM_X + 2]; float contentHeight = contentSize(DIM_Y) - skin.padding()[DIM_Y] - skin.padding()[DIM_Y + 2]; float cleft = pleft; NVGalign halign = NVG_ALIGN_LEFT; if(skin.align()[DIM_X] == CENTER) { halign = NVG_ALIGN_CENTER; cleft = pleft + pwidth / 2.f - contentWidth / 2.f; } else if(skin.align()[DIM_X] == RIGHT) { halign = NVG_ALIGN_RIGHT; cleft = pleft + pwidth - contentWidth; } float ctop = ptop; if(skin.align()[DIM_Y] == CENTER) ctop = ptop + pheight / 2.f - contentHeight / 2.f; else if(skin.align()[DIM_Y] == RIGHT) ctop = ptop + pheight - contentHeight; float c0 = mCorners.x0(); float c1 = mCorners.y0(); float c2 = mCorners.x1(); float c3 = mCorners.y1(); // Shadow if(!skin.shadow().d_null) { const Shadow& shadow = skin.shadow(); NVGpaint shadowPaint = nvgBoxGradient(mCtx, left + shadow.d_xpos - shadow.d_spread, top + shadow.d_ypos - shadow.d_spread, width + shadow.d_spread * 2.f, height + shadow.d_spread * 2.f, c0 + shadow.d_spread, shadow.d_blur, nvgRGBA(0, 0, 0, 128), nvgRGBA(0, 0, 0, 0)); nvgBeginPath(mCtx); nvgRect(mCtx, left + shadow.d_xpos - shadow.d_radius, top + shadow.d_ypos - shadow.d_radius, width + shadow.d_radius * 2.f, height + shadow.d_radius * 2.f); if(mCorners.null()) nvgRect(mCtx, left, top, width, height); else nvgRoundedBox(mCtx, left, top, width, height, c0, c1, c2, c3); nvgPathWinding(mCtx, NVG_HOLE); nvgFillPaint(mCtx, shadowPaint); nvgFill(mCtx); } // Rect nvgBeginPath(mCtx); if(mCorners.null()) nvgRect(mCtx, left + halfb, top + halfb, width - b, height - b); else nvgRoundedBox(mCtx, left + halfb, top + halfb, width - b, height - b, c0, c1, c2, c3, mFitCorners); if(skin.backgroundColour().a() > 0.f) { if(skin.topdownGradient().null()) { nvgFillColor(mCtx, nvgColour(skin.mBackgroundColour)); } else { NVGcolor first = nvgOffsetColour(skin.backgroundColour(), skin.topdownGradient().x()); NVGcolor second = nvgOffsetColour(skin.backgroundColour(), skin.topdownGradient().y()); nvgFillPaint(mCtx, (height > width) ? nvgLinearGradient(mCtx, left, top, left + width, top, first, second) : nvgLinearGradient(mCtx, left, top, left, top + height, first, second)); } nvgFill(mCtx); } if(skin.borderWidth().x0() > 0.f) { nvgStrokeWidth(mCtx, skin.borderWidth().x0()); nvgStrokeColor(mCtx, nvgColour(skin.borderColour())); nvgStroke(mCtx); } // ImageSkin if(!skin.imageSkin().null()) { const ImageSkin& imgskin = skin.mImageSkin; float margin = skin.imageSkin().d_margin * 2.f; if(imgskin.d_stretch == DIM_X) imgskin.stretchCoords(width + margin, imgskin.d_height, [this, left, ctop](ImageSkin::Section s, int x, int y, int w, int h){ this->drawSkinImage(s, float(left + x), float(ctop + y), float(w), float(h)); }); else if(imgskin.d_stretch == DIM_Y) imgskin.stretchCoords(imgskin.d_width, height + margin, [this, cleft, top](ImageSkin::Section s, int x, int y, int w, int h){ this->drawSkinImage(s, float(cleft + x), float(top + y), float(w), float(h)); }); else imgskin.stretchCoords(width + margin, height + margin, [this, left, top](ImageSkin::Section s, int x, int y, int w, int h){ this->drawSkinImage(s, float(left + x), float(top + y), float(w), float(h)); }); } if(mFrame.dclip(DIM_X) || mFrame.dclip(DIM_Y)) nvgScissor(mCtx, left, top, width, height); // Image if(mImage) this->drawImage(*mImage, cleft, ctop, contentWidth, contentHeight); if(mOverlay) this->drawImage(*mOverlay, cleft, ctop, contentWidth, contentHeight); if(mTile) this->drawImage(*mTile, left, top, width, height); if(mFrame.dclip(DIM_X) || mFrame.dclip(DIM_Y)) nvgResetScissor(mCtx); nvgBindDisplayList(mCtx, nullptr); }