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); }
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 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 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 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 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 VScrollPanel::draw(NVGcontext *ctx) { if (m_children.empty()) return; Widget *child = m_children[0]; child->set_position(Vector2i(0, -m_scroll*(m_child_preferred_height - m_size.y()))); m_child_preferred_height = child->preferred_size(ctx).y(); float scrollh = height() * std::min(1.0f, height() / (float) m_child_preferred_height); if (m_update_layout) { m_update_layout = false; child->perform_layout(ctx); } nvgSave(ctx); nvgTranslate(ctx, m_pos.x(), m_pos.y()); nvgIntersectScissor(ctx, 0, 0, m_size.x(), m_size.y()); if (child->visible()) child->draw(ctx); nvgRestore(ctx); if (m_child_preferred_height <= m_size.y()) return; NVGpaint paint = nvgBoxGradient( ctx, m_pos.x() + m_size.x() - 12 + 1, m_pos.y() + 4 + 1, 8, m_size.y() - 8, 3, 4, Color(0, 32), Color(0, 92)); nvgBeginPath(ctx); nvgRoundedRect(ctx, m_pos.x() + m_size.x() - 12, m_pos.y() + 4, 8, m_size.y() - 8, 3); nvgFillPaint(ctx, paint); nvgFill(ctx); paint = nvgBoxGradient( ctx, m_pos.x() + m_size.x() - 12 - 1, m_pos.y() + 4 + (m_size.y() - 8 - scrollh) * m_scroll - 1, 8, scrollh, 3, 4, Color(220, 100), Color(128, 100)); nvgBeginPath(ctx); nvgRoundedRect(ctx, m_pos.x() + m_size.x() - 12 + 1, m_pos.y() + 4 + 1 + (m_size.y() - 8 - scrollh) * m_scroll, 8 - 2, scrollh - 2, 2); nvgFillPaint(ctx, paint); nvgFill(ctx); }
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); }
JNIEXPORT void JNICALL Java_firststep_internal_NVG__1_1boxGradient (JNIEnv *e, jclass cls, jlong ctx, jobject paint, jfloat x, jfloat y, jfloat w, jfloat h, jfloat r, jfloat f, jobject scol, jobject ecol) { checkJO(scol,"\nBoxGradient was passed NULL start colour\n"); checkJO(ecol,"\nBoxGradient was passed NULL end colour\n"); NVGpaint p = nvgBoxGradient((NVGcontext*)ctx, x, y, w, h, r, f, (NVGcolor)*((NVGcolor*)getBuffPtr(e,scol)), (NVGcolor)*((NVGcolor*)getBuffPtr(e,ecol))); NVGpaint* dp = (NVGpaint*)getBuffPtr(e,paint); *dp = p; }
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 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 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); }
void drawSearchBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h) { struct NVGpaint bg; char icon[8]; float cornerRadius = h/2-1; // Edit bg = nvgBoxGradient(vg, x,y+1.5f, w,h, h/2,5, nvgRGBA(0,0,0,16), nvgRGBA(0,0,0,92) ); nvgBeginPath(vg); nvgRoundedRect(vg, x,y, w,h, cornerRadius); 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, h*1.3f); nvgFontFace(vg, "icons"); nvgFillColor(vg, nvgRGBA(255,255,255,64) ); nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); nvgText(vg, x+h*0.55f, y+h*0.55f, cpToUTF8(ICON_SEARCH,icon), NULL); nvgFontSize(vg, 20.0f); nvgFontFace(vg, "sans"); nvgFillColor(vg, nvgRGBA(255,255,255,32) ); nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); nvgText(vg, x+h*1.05f,y+h*0.5f,text, NULL); nvgFontSize(vg, h*1.3f); nvgFontFace(vg, "icons"); nvgFillColor(vg, nvgRGBA(255,255,255,32) ); nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); nvgText(vg, x+w-h*0.55f, y+h*0.55f, cpToUTF8(ICON_CIRCLED_CROSS,icon), NULL); }
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); }
NVGpaint nvgBoxGradient(NVGcontext* ctx, Rect rect, float r, float f, NVGcolor icol, NVGcolor ocol){ return nvgBoxGradient(ctx,rect.x,rect.y,rect.width,rect.height,r,f,icol,ocol); }
NVGpaint NanoVG::boxGradient( float x, float y, float w, float h, float r, float f, NVGcolor icol, NVGcolor ocol ) { return nvgBoxGradient( m_context(), x, y, w, h, r, f, icol, ocol ); }
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 ColorWheel::draw(NVGcontext *ctx) { Widget::draw(ctx); if (!mVisible) return; float x = mPos.x(), y = mPos.y(), w = mSize.x(), h = mSize.y(); NVGcontext* vg = ctx; int i; float r0, r1, ax,ay, bx,by, cx,cy, aeps, r; float hue = mHue; NVGpaint paint; nvgSave(vg); cx = x + w*0.5f; cy = y + h*0.5f; r1 = (w < h ? w : h) * 0.5f - 5.0f; r0 = r1 * .75f; aeps = 0.5f / r1; // half a pixel arc length in radians (2pi cancels out). for (i = 0; i < 6; i++) { float a0 = (float)i / 6.0f * NVG_PI * 2.0f - aeps; float a1 = (float)(i+1.0f) / 6.0f * NVG_PI * 2.0f + aeps; nvgBeginPath(vg); nvgArc(vg, cx,cy, r0, a0, a1, NVG_CW); nvgArc(vg, cx,cy, r1, a1, a0, NVG_CCW); nvgClosePath(vg); ax = cx + cosf(a0) * (r0+r1)*0.5f; ay = cy + sinf(a0) * (r0+r1)*0.5f; bx = cx + cosf(a1) * (r0+r1)*0.5f; by = cy + sinf(a1) * (r0+r1)*0.5f; paint = nvgLinearGradient(vg, ax, ay, bx, by, nvgHSLA(a0 / (NVG_PI * 2), 1.0f, 0.55f, 255), nvgHSLA(a1 / (NVG_PI * 2), 1.0f, 0.55f, 255)); nvgFillPaint(vg, paint); nvgFill(vg); } nvgBeginPath(vg); nvgCircle(vg, cx,cy, r0-0.5f); nvgCircle(vg, cx,cy, r1+0.5f); nvgStrokeColor(vg, nvgRGBA(0,0,0,64)); nvgStrokeWidth(vg, 1.0f); nvgStroke(vg); // Selector nvgSave(vg); nvgTranslate(vg, cx,cy); nvgRotate(vg, hue*NVG_PI*2); // Marker on float u = std::max(r1/50, 1.5f); u = std::min(u, 4.f); nvgStrokeWidth(vg, u); nvgBeginPath(vg); nvgRect(vg, r0-1,-2*u,r1-r0+2,4*u); nvgStrokeColor(vg, nvgRGBA(255,255,255,192)); nvgStroke(vg); paint = nvgBoxGradient(vg, r0-3,-5,r1-r0+6,10, 2,4, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0)); nvgBeginPath(vg); nvgRect(vg, r0-2-10,-4-10,r1-r0+4+20,8+20); nvgRect(vg, r0-2,-4,r1-r0+4,8); nvgPathWinding(vg, NVG_HOLE); nvgFillPaint(vg, paint); nvgFill(vg); // Center triangle r = r0 - 6; ax = cosf(120.0f/180.0f*NVG_PI) * r; ay = sinf(120.0f/180.0f*NVG_PI) * r; bx = cosf(-120.0f/180.0f*NVG_PI) * r; by = sinf(-120.0f/180.0f*NVG_PI) * r; nvgBeginPath(vg); nvgMoveTo(vg, r,0); nvgLineTo(vg, ax, ay); nvgLineTo(vg, bx, by); nvgClosePath(vg); paint = nvgLinearGradient(vg, r, 0, ax, ay, nvgHSLA(hue, 1.0f, 0.5f, 255), nvgRGBA(255, 255, 255, 255)); nvgFillPaint(vg, paint); nvgFill(vg); paint = nvgLinearGradient(vg, (r + ax) * 0.5f, (0 + ay) * 0.5f, bx, by, nvgRGBA(0, 0, 0, 0), nvgRGBA(0, 0, 0, 255)); nvgFillPaint(vg, paint); nvgFill(vg); nvgStrokeColor(vg, nvgRGBA(0, 0, 0, 64)); nvgStroke(vg); // Select circle on triangle float sx = r*(1 - mWhite - mBlack) + ax*mWhite + bx*mBlack; float sy = ay*mWhite + by*mBlack; nvgStrokeWidth(vg, u); nvgBeginPath(vg); nvgCircle(vg, sx,sy,2*u); nvgStrokeColor(vg, nvgRGBA(255,255,255,192)); nvgStroke(vg); nvgRestore(vg); nvgRestore(vg); }
void OGUIFileBrowser::draw() { // ToDo (damiles): Create scroll for more files in window if (_is_file_browser_visible) { NVGcontext *vg = (NVGcontext *) _window->vg; nvgBeginPath(vg); nvgRect(vg, 0, 0, _window->getWindowWidth(), _window->getWindowHeight()); nvgFillColor(vg, nvgRGBA(28, 30, 34, 255)); nvgFill(vg); // sep line nvgBeginPath(vg); nvgMoveTo(vg, 200, 40); nvgLineTo(vg, 200, _window->getWindowHeight()); nvgFillColor(vg, nvgRGBA(0,0,0,255)); nvgFill(vg); nvgBeginPath(vg); nvgMoveTo(vg, 0, 40); nvgLineTo(vg, _window->getWindowWidth(), 40); nvgFillColor(vg, nvgRGBA(0,0,0,255)); nvgFill(vg); nvgBeginPath(vg); nvgMoveTo(vg, 200, _window->getWindowHeight()-40); nvgLineTo(vg, _window->getWindowWidth(), _window->getWindowHeight()-40); nvgFillColor(vg, nvgRGBA(0,0,0,255)); nvgFill(vg); // Draw accept and cancel buttons if(drawBasicButton(vg, this->_window, "Accept", _window->getWindowWidth()-100, _window->getWindowHeight()-30, 90, 20, _window->mouse_x, _window->mouse_y)){ _is_file_browser_visible=0; } if(drawBasicButton(vg, this->_window, "Close", _window->getWindowWidth()-200, _window->getWindowHeight()-30, 90, 20, _window->mouse_x, _window->mouse_y)){ _file_browser_result= NULL; _is_file_browser_visible=0; } // Draw de devices we found drawHeader(vg, "System", 0, 40, 200); // Draw system files int x=10; int y=75; for(int i=0; i<_system.size(); i++){ OGUIFile *file= _system.at(i); if( file->draw(vg, x, y, _window->mouse_x, _window->mouse_y) ){ // is clicked _file_browser_result= file; if(_file_browser_result!=NULL) { if (_file_browser_result->_is_dir && _actual_folder.compare(_file_browser_result->_path) != 0) { readFolder(_file_browser_result->_path); _actual_folder= _file_browser_result->_path; _file_browser_result = NULL; } } } y+=22; } // Draw files x=210; y=50; int max_height= _window->getWindowHeight()-80; for(int i=0; i<_file_list.size(); i++){ OGUIFile *file= _file_list.at(i); if( file->draw(vg, x, y, _window->mouse_x, _window->mouse_y) ){ // is clicked _file_browser_result= file; if(_file_browser_result!=NULL) { if (_file_browser_result->_is_dir && _actual_folder.compare(_file_browser_result->_path) != 0) { readFolder(_file_browser_result->_path); _actual_folder= _file_browser_result->_path; _file_browser_result = NULL; } } } y+=22; if(y>=max_height){ x+=202; y=50; } } // Show icon in header nvgFontSize(vg, 16.0f); nvgFontFace(vg, "icons"); nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_TOP); nvgFillColor(vg, nvgRGBA(0,0,0,255)); nvgText(vg, 10, 11, "\uF115", NULL); nvgFillColor(vg, nvgRGBA(255, 255, 255, 255)); nvgText(vg, 11, 13, "\uF115", NULL); nvgFillColor(vg, nvgRGBA(255,255,255,255)); // show path in header nvgFontSize(vg, 18.0f); nvgFontFace(vg, "sans-bold"); nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); nvgFillColor(vg, nvgRGBA(0, 0, 0, 255)); nvgText(vg, 35, 10, resolved_path, NULL); nvgFillColor(vg, nvgRGBA(255, 255, 255, 255)); nvgText(vg, 36, 12, resolved_path, NULL); if(_file_browser_result!=NULL) { if (_file_browser_result->_is_dir == false) { // show file in footer nvgFontSize(vg, 18.0f); nvgFontFace(vg, "sans-bold"); nvgTextAlign(vg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); nvgFillColor(vg, nvgRGBA(0, 0, 0, 255)); nvgText(vg, 209, _window->getWindowHeight()-32, _file_browser_result->_file_name.c_str(), NULL); nvgFillColor(vg, nvgRGBA(255, 255, 255, 255)); nvgText(vg, 210, _window->getWindowHeight()-30, _file_browser_result->_file_name.c_str(), NULL); // Draw preview if its image if(_file_browser_result->isImage()){ x=0; y=_window->getWindowHeight()-200; drawHeader(vg, "Preview", 0, y-30, 200); int w=200; int h=200; NVGpaint bg; // Box 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); // Image preview if(_preview_image==-1){ _preview_image= nvgCreateImageRGBA(vg, 150, 150, 0, _file_browser_result->getPreview()); }else{ nvgUpdateImage(vg, _preview_image, _file_browser_result->getPreview()); } NVGpaint imgPaint = nvgImagePattern(vg, 25, y+25, 150, 150, 0, _preview_image, 1); nvgBeginPath(vg); nvgRect(vg, 25, y+25, 150,150); nvgFillPaint(vg, imgPaint); nvgFill(vg); } } } } }
void OGUITextInput::draw(int x, int y, int w) { int h = this->height; OGUIWidget::draw(x, y, w); OGUIArea* area= (OGUIArea*)(this->area); NVGcontext* vg= (NVGcontext*)(area->window->vg); 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); nvgFontSize(vg, 20.0f*area->window->font_scale); nvgFontFace(vg, "sans"); if(value.compare(label)==0) nvgFillColor(vg, nvgRGBA(255,255,255,64)); else nvgFillColor(vg, nvgRGBA(255,255,255,128)); nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); nvgText(vg, x+h*0.3f,y+h*0.5f, value.c_str(), NULL); if(area->window->mouse_x > x && area->window->mouse_x < x+w && area->window->mouse_y > y && area->window->mouse_y < y + h ) { area->window->setCursor(TEXT_CURSOR); if (area->window->mouse_state == GLFW_PRESS) { is_focus_= true; area->window->setKeyFocus(this); if(value.compare(label)==0) value=""; } }else{ area->window->setCursor(DEFAULT_CURSOR); if (area->window->mouse_state == GLFW_PRESS) { if(value.compare("")==0) value= string(label); is_focus_= false; } } if(is_focus_){ float char_pos= nvgTextBounds(vg, x, y, value.c_str(), NULL, NULL); nvgBeginPath(vg); animation_alpha_+=10; animation_alpha_=animation_alpha_%255; nvgFillColor(vg, nvgRGBA(255,192,0,animation_alpha_)); nvgRect(vg, x+h*0.3f+char_pos, y+6, 1, 20); nvgFill(vg); } }
void drawColorwheel(struct NVGcontext* vg, float x, float y, float w, float h, float t) { int i; float r0, r1, ax,ay, bx,by, cx,cy, aeps, r; float hue = sinf(t * 0.12f); struct NVGpaint paint; nvgSave(vg); /* nvgBeginPath(vg); nvgRect(vg, x,y,w,h); nvgFillColor(vg, nvgRGBA(255,0,0,128) ); nvgFill(vg);*/ cx = x + w*0.5f; cy = y + h*0.5f; r1 = (w < h ? w : h) * 0.5f - 5.0f; r0 = r1 - 20.0f; aeps = 0.5f / r1; // half a pixel arc length in radians (2pi cancels out). for (i = 0; i < 6; i++) { float a0 = (float)i / 6.0f * NVG_PI * 2.0f - aeps; float a1 = (float)(i+1.0f) / 6.0f * NVG_PI * 2.0f + aeps; nvgBeginPath(vg); nvgArc(vg, cx,cy, r0, a0, a1, NVG_CW); nvgArc(vg, cx,cy, r1, a1, a0, NVG_CCW); nvgClosePath(vg); ax = cx + cosf(a0) * (r0+r1)*0.5f; ay = cy + sinf(a0) * (r0+r1)*0.5f; bx = cx + cosf(a1) * (r0+r1)*0.5f; by = cy + sinf(a1) * (r0+r1)*0.5f; paint = nvgLinearGradient(vg, ax,ay, bx,by, nvgHSLA(a0/(NVG_PI*2),1.0f,0.55f,255), nvgHSLA(a1/(NVG_PI*2),1.0f,0.55f,255) ); nvgFillPaint(vg, paint); nvgFill(vg); } nvgBeginPath(vg); nvgCircle(vg, cx,cy, r0-0.5f); nvgCircle(vg, cx,cy, r1+0.5f); nvgStrokeColor(vg, nvgRGBA(0,0,0,64) ); nvgStrokeWidth(vg, 1.0f); nvgStroke(vg); // Selector nvgSave(vg); nvgTranslate(vg, cx,cy); nvgRotate(vg, hue*NVG_PI*2); // Marker on nvgStrokeWidth(vg, 2.0f); nvgBeginPath(vg); nvgRect(vg, r0-1,-3,r1-r0+2,6); nvgStrokeColor(vg, nvgRGBA(255,255,255,192) ); nvgStroke(vg); paint = nvgBoxGradient(vg, r0-3,-5,r1-r0+6,10, 2,4, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0) ); nvgBeginPath(vg); nvgRect(vg, r0-2-10,-4-10,r1-r0+4+20,8+20); nvgRect(vg, r0-2,-4,r1-r0+4,8); nvgPathWinding(vg, NVG_HOLE); nvgFillPaint(vg, paint); nvgFill(vg); // Center triangle r = r0 - 6; ax = cosf(120.0f/180.0f*NVG_PI) * r; ay = sinf(120.0f/180.0f*NVG_PI) * r; bx = cosf(-120.0f/180.0f*NVG_PI) * r; by = sinf(-120.0f/180.0f*NVG_PI) * r; nvgBeginPath(vg); nvgMoveTo(vg, r,0); nvgLineTo(vg, ax,ay); nvgLineTo(vg, bx,by); nvgClosePath(vg); paint = nvgLinearGradient(vg, r,0, ax,ay, nvgHSLA(hue,1.0f,0.5f,255), nvgRGBA(255,255,255,255) ); nvgFillPaint(vg, paint); nvgFill(vg); paint = nvgLinearGradient(vg, (r+ax)*0.5f,(0+ay)*0.5f, bx,by, nvgRGBA(0,0,0,0), nvgRGBA(0,0,0,255) ); nvgFillPaint(vg, paint); nvgFill(vg); nvgStrokeColor(vg, nvgRGBA(0,0,0,64) ); nvgStroke(vg); // Select circle on triangle ax = cosf(120.0f/180.0f*NVG_PI) * r*0.3f; ay = sinf(120.0f/180.0f*NVG_PI) * r*0.4f; nvgStrokeWidth(vg, 2.0f); nvgBeginPath(vg); nvgCircle(vg, ax,ay,5); nvgStrokeColor(vg, nvgRGBA(255,255,255,192) ); nvgStroke(vg); paint = nvgRadialGradient(vg, ax,ay, 7,9, nvgRGBA(0,0,0,64), nvgRGBA(0,0,0,0) ); nvgBeginPath(vg); nvgRect(vg, ax-20,ay-20,40,40); nvgCircle(vg, ax,ay,7); nvgPathWinding(vg, NVG_HOLE); nvgFillPaint(vg, paint); nvgFill(vg); nvgRestore(vg); nvgRestore(vg); }
void 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 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); }