void vsColoredNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1, NVGcolor color0, NVGcolor color1) { float length = bnd_fmaxf(fabsf(x1 - x0), fabsf(y1 - y0)); // how much a noodle curves (0 to 10) int noodleCurving = 3; float delta = length * (float) noodleCurving / 10.0f; nvgBeginPath(ctx); nvgMoveTo(ctx, x0, y0); nvgBezierTo(ctx, x0 + delta, y0, x1 - delta, y1, x1, y1); NVGcolor colorw = nvgRGB(52, 22, 99); colorw.a = (color0.a < color1.a) ? color0.a : color1.a; nvgStrokeColor(ctx, colorw); nvgStrokeWidth(ctx, BND_NODE_WIRE_OUTLINE_WIDTH); nvgStroke(ctx); nvgStrokePaint(ctx, nvgLinearGradient(ctx, x0, y0, x1, y1, color0, color1)); nvgStrokeWidth(ctx, BND_NODE_WIRE_WIDTH); nvgStroke(ctx); }
void drawLines(struct NVGcontext* vg, float x, float y, float w, float h, float t) { int i, j; float pad = 5.0f, s = w/9.0f - pad*2; float pts[4*2], fx, fy; int joins[3] = {NVG_MITER, NVG_ROUND, NVG_BEVEL}; int caps[3] = {NVG_BUTT, NVG_ROUND, NVG_SQUARE}; NVG_NOTUSED(h); nvgSave(vg); pts[0] = -s*0.25f + cosf(t*0.3f) * s*0.5f; pts[1] = sinf(t*0.3f) * s*0.5f; pts[2] = -s*0.25f; pts[3] = 0; pts[4] = s*0.25f; pts[5] = 0; pts[6] = s*0.25f + cosf(-t*0.3f) * s*0.5f; pts[7] = sinf(-t*0.3f) * s*0.5f; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { fx = x + s*0.5f + (i*3+j)/9.0f*w + pad; fy = y - s*0.5f + pad; nvgLineCap(vg, caps[i]); nvgLineJoin(vg, joins[j]); nvgStrokeWidth(vg, s*0.3f); nvgStrokeColor(vg, nvgRGBA(0,0,0,160) ); nvgBeginPath(vg); nvgMoveTo(vg, fx+pts[0], fy+pts[1]); nvgLineTo(vg, fx+pts[2], fy+pts[3]); nvgLineTo(vg, fx+pts[4], fy+pts[5]); nvgLineTo(vg, fx+pts[6], fy+pts[7]); nvgStroke(vg); nvgLineCap(vg, NVG_BUTT); nvgLineJoin(vg, NVG_BEVEL); nvgStrokeWidth(vg, 1.0f); nvgStrokeColor(vg, nvgRGBA(0,192,255,255) ); nvgBeginPath(vg); nvgMoveTo(vg, fx+pts[0], fy+pts[1]); nvgLineTo(vg, fx+pts[2], fy+pts[3]); nvgLineTo(vg, fx+pts[4], fy+pts[5]); nvgLineTo(vg, fx+pts[6], fy+pts[7]); nvgStroke(vg); } } nvgRestore(vg); }
void NanoInk::drawImage() { #if 1 // DEBUG if(sDebugDraw && mVisible) { float left = mFrame.dabsolute(DIM_X) + mFrame.cleft(); float top = mFrame.dabsolute(DIM_Y) + mFrame.ctop(); float width = mFrame.cwidth(); float height = mFrame.cheight(); nvgBeginPath(mCtx); nvgRect(mCtx, left + 0.5f, top + 0.5f, width - 1.f, height - 1.f); nvgStrokeWidth(mCtx, 1.f); nvgStrokeColor(mCtx, nvgColour(Colour::Red)); nvgStroke(mCtx); } #endif if(this->skin().mEmpty || !mVisible) return; ++sDebugBatch; if(!mImageCache) mImageCache = nvgCreateDisplayList(11); if(mImageUpdate) this->redrawImage(); this->drawCache(mImageCache); mImageUpdate = false; }
void 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 TabWidget::draw(NVGcontext* ctx) { int tab_height = m_header->preferred_size(ctx).y(); auto active_area = m_header->active_button_area(); for (int i = 0; i < 3; ++i) { nvgSave(ctx); if (i == 0) nvgIntersectScissor(ctx, m_pos.x(), m_pos.y(), active_area.first.x() + 1, m_size.y()); else if (i == 1) nvgIntersectScissor(ctx, m_pos.x() + active_area.second.x(), m_pos.y(), m_size.x() - active_area.second.x(), m_size.y()); else nvgIntersectScissor(ctx, m_pos.x(), m_pos.y() + tab_height + 2, m_size.x(), m_size.y()); nvgBeginPath(ctx); nvgStrokeWidth(ctx, 1.0f); nvgRoundedRect(ctx, m_pos.x() + 0.5f, m_pos.y() + tab_height + 1.5f, m_size.x() - 1, m_size.y() - tab_height - 2, m_theme->m_button_corner_radius); nvgStrokeColor(ctx, m_theme->m_border_light); nvgStroke(ctx); nvgBeginPath(ctx); nvgRoundedRect(ctx, m_pos.x() + 0.5f, m_pos.y() + tab_height + 0.5f, m_size.x() - 1, m_size.y() - tab_height - 2, m_theme->m_button_corner_radius); nvgStrokeColor(ctx, m_theme->m_border_dark); nvgStroke(ctx); nvgRestore(ctx); } Widget::draw(ctx); }
void drawCaps(struct NVGcontext* vg, float x, float y, float width) { int i; int caps[3] = {NVG_BUTT, NVG_ROUND, NVG_SQUARE}; float lineWidth = 8.0f; nvgSave(vg); nvgBeginPath(vg); nvgRect(vg, x-lineWidth/2, y, width+lineWidth, 40); nvgFillColor(vg, nvgRGBA(255,255,255,32)); nvgFill(vg); nvgBeginPath(vg); nvgRect(vg, x, y, width, 40); nvgFillColor(vg, nvgRGBA(255,255,255,32)); nvgFill(vg); nvgStrokeWidth(vg, lineWidth); for (i = 0; i < 3; i++) { nvgLineCap(vg, caps[i]); nvgStrokeColor(vg, nvgRGBA(0,0,0,255)); nvgBeginPath(vg); nvgMoveTo(vg, x, y + i*10 + 5); nvgLineTo(vg, x+width, y + i*10 + 5); nvgStroke(vg); } nvgRestore(vg); }
void TabWidget::draw(NVGcontext* ctx) { int tabHeight = mHeader->preferredSize(ctx).y(); auto activeArea = mHeader->activeButtonArea(); for (int i = 0; i < 3; ++i) { nvgSave(ctx); if (i == 0) nvgIntersectScissor(ctx, mPos.x(), mPos.y(), activeArea.first.x() + 1, mSize.y()); else if (i == 1) nvgIntersectScissor(ctx, mPos.x() + activeArea.second.x(), mPos.y(), mSize.x() - activeArea.second.x(), mSize.y()); else nvgIntersectScissor(ctx, mPos.x(), mPos.y() + tabHeight + 2, mSize.x(), mSize.y()); nvgBeginPath(ctx); nvgStrokeWidth(ctx, 1.0f); nvgRoundedRect(ctx, mPos.x() + 0.5f, mPos.y() + tabHeight + 1.5f, mSize.x() - 1, mSize.y() - tabHeight - 2, mTheme->mButtonCornerRadius); nvgStrokeColor(ctx, mTheme->mBorderLight); nvgStroke(ctx); nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x() + 0.5f, mPos.y() + tabHeight + 0.5f, mSize.x() - 1, mSize.y() - tabHeight - 2, mTheme->mButtonCornerRadius); nvgStrokeColor(ctx, mTheme->mBorderDark); nvgStroke(ctx); nvgRestore(ctx); } Widget::draw(ctx); }
void 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 testrect(NVGcontext *vg, UIrect rect) { #if 0 nvgBeginPath(vg); nvgRect(vg,rect.x+0.5,rect.y+0.5,rect.w-1,rect.h-1); nvgStrokeColor(vg,nvgRGBf(1,0,0)); nvgStrokeWidth(vg,1); nvgStroke(vg); #endif }
void draw<line_t>(line_t& line, NVGcolor& color) { nvgBeginPath(graphics::vg); nvgMoveTo(graphics::vg, line.p.x, line.p.y); nvgLineTo(graphics::vg, line.q.x, line.q.y); nvgStrokeColor(graphics::vg, color); nvgStrokeWidth(graphics::vg, 3 * graphics::one_pixel); nvgStroke(graphics::vg); }
void ExpandTree::drawDebug(AlloyContext* context) { if (selectedItem) { NVGcontext* nvg = context->nvgContext; nvgStrokeWidth(nvg, 1.0f); nvgStrokeColor(nvg, Color(220, 64, 64)); nvgBeginPath(nvg); box2px bounds = selectedItem->getBounds(); box2px pbounds = drawRegion->getBounds(); bounds.position += pbounds.position; bounds.intersect(getBounds()); nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x, bounds.dimensions.y); nvgStroke(nvg); } Composite::drawDebug(context); }
void ImagePanel::draw (NVGcontext * ctx) { ivec2 grid = gridSize(); for (size_t i = 0; i < mImages.size(); ++i) { ivec2 p = mPos + ivec2 (mMargin) + ivec2 ((int)i % grid.x, (int)i / grid.x) * (mThumbSize + mSpacing); int imgw, imgh; nvgImageSize (ctx, mImages[i].first, &imgw, &imgh); float iw, ih, ix, iy; if (imgw < imgh) { iw = mThumbSize; ih = iw * (float)imgh / (float)imgw; ix = 0; iy = - (ih - mThumbSize) * 0.5f; } else { ih = mThumbSize; iw = ih * (float)imgw / (float)imgh; ix = - (iw - mThumbSize) * 0.5f; iy = 0; } NVGpaint imgPaint = nvgImagePattern ( ctx, p.x + ix, p.y + iy, iw, ih, 0, mImages[i].first, mMouseIndex == (int)i ? 1.0 : 0.7); nvgBeginPath (ctx); nvgRoundedRect (ctx, p.x, p.y, mThumbSize, mThumbSize, 5); nvgFillPaint (ctx, imgPaint); nvgFill (ctx); NVGpaint shadowPaint = nvgBoxGradient (ctx, p.x - 1, p.y, mThumbSize + 2, mThumbSize + 2, 5, 3, nvgRGBA (0, 0, 0, 128), nvgRGBA (0, 0, 0, 0)); nvgBeginPath (ctx); nvgRect (ctx, p.x - 5, p.y - 5, mThumbSize + 10, mThumbSize + 10); nvgRoundedRect (ctx, p.x, p.y, mThumbSize, mThumbSize, 6); nvgPathWinding (ctx, NVG_HOLE); nvgFillPaint (ctx, shadowPaint); nvgFill (ctx); nvgBeginPath (ctx); nvgRoundedRect (ctx, p.x + 0.5f, p.y + 0.5f, mThumbSize - 1, mThumbSize - 1, 4 - 0.5f); nvgStrokeWidth (ctx, 1.0f); nvgStrokeColor (ctx, nvgRGBA (255, 255, 255, 80)); nvgStroke (ctx); } }
void Render() override { nvgBeginPath(GNvg); if (EdgePainter.Points.size() >= 4) { glm::vec2 temp = camera.WorldToScreen(glm::vec2(EdgePainter.Points[0], EdgePainter.Points[1])); nvgMoveTo(GNvg, temp[0], temp[1]); for (int i = 2; i < EdgePainter.Points.size(); i += 2) { temp = camera.WorldToScreen(glm::vec2(EdgePainter.Points[i], EdgePainter.Points[i + 1])); nvgLineTo(GNvg, temp[0], temp[1]); } } nvgStrokeColor(GNvg, nvgRGB(255, 255, 255)); nvgStrokeWidth(GNvg, 5); nvgStroke(GNvg); }
void Caret::draw(NVGcontext *ctx, float lineh, Vector2i offset) { //std::cout << "Cursor("<< mCursorPos.x()<< ","<< mCursorPos.y() <<")" << std::endl; if(isVisible()) { //float caretx = cursorIndex2Position(mCursorPos.x(), textBound[2], glyphs, nglyphs); //mPosition = getCursorPosition(ctx, mCursorPos, lineh); // draw cursor nvgBeginPath(ctx); nvgMoveTo(ctx, offset.x() + mPos.x(), offset.y()+ mPos.y() ); nvgLineTo(ctx, offset.x() + mPos.x(), offset.y()+ mPos.y()+ lineh ); nvgStrokeColor(ctx, nvgRGBA(255, 192, 0, 255)); nvgStrokeWidth(ctx, 1.0f); nvgStroke(ctx); } if(mSelectionState) { // draw selection int linew = mConsole->mSize.x(); nvgBeginPath(ctx); nvgFillColor(ctx, nvgRGBA(255, 255, 255, 80)); if(mIdx.y() == mSelectionIdx.y()) { int x = std::min(mPos.x(),mSelectionPos.x()); x += offset.x(); nvgRect(ctx, x, offset.y()+ mPos.y(), std::abs(mSelectionPos.x()-mPos.x()), lineh); } else if(mIdx.y() > mSelectionIdx.y()) { nvgRect(ctx, offset.x()+mSelectionPos.x(), offset.y()+ mSelectionPos.y(), linew-mSelectionPos.x(), lineh); if(mIdx.y()-mSelectionIdx.y()>1) nvgRect(ctx, offset.x(), offset.y()+ mSelectionPos.y()+lineh, linew, mPos.y()-mSelectionPos.y()-lineh); nvgRect(ctx, offset.x(), offset.y()+ mPos.y(), mPos.x(), lineh); } else { nvgRect(ctx, offset.x(), offset.y()+ mSelectionPos.y(), mSelectionPos.x(), lineh); if(mSelectionIdx.y()-mIdx.y()>1) nvgRect(ctx, offset.x(), offset.y()+ mPos.y()+lineh, linew, mSelectionPos.y()-mPos.y()-lineh); nvgRect(ctx, offset.x()+mPos.x(), offset.y()+ mPos.y(), linew-mPos.x(), lineh); } nvgFill(ctx); } }
void Widget::draw(NVGcontext *ctx) { #if NANOGUI_SHOW_WIDGET_BOUNDS nvgStrokeWidth(ctx, 1.0f); nvgBeginPath(ctx); nvgRect(ctx, mPos.x() - 0.5f, mPos.y() - 0.5f, mSize.x() + 1, mSize.y() + 1); nvgStrokeColor(ctx, nvgRGBA(255, 0, 0, 255)); nvgStroke(ctx); #endif if (mChildren.empty()) return; nvgTranslate(ctx, mPos.x(), mPos.y()); for (auto child : mChildren) if (child->visible()) child->draw(ctx); nvgTranslate(ctx, -mPos.x(), -mPos.y()); }
void draw<vec_field_t>(vec_field_t& vf, NVGcolor& color) { vf.foreach_element([&](size_t i, size_t j, vec_t& v){ vec_t pos = vf.get_coordinates(i, j), to = pos + v; nvgBeginPath(vg); nvgCircle(vg, pos.x, pos.y, .2); nvgFillColor(vg, color); nvgFill(vg); nvgBeginPath(vg); nvgMoveTo(vg, pos.x, pos.y); nvgLineTo(vg, to.x, to.y); nvgStrokeColor(vg, color); nvgStrokeWidth(vg, one_pixel); nvgStroke(vg); }); }
void drawWidths(struct NVGcontext* vg, float x, float y, float width) { nvgSave(vg); nvgStrokeColor(vg, nvgRGBA(0,0,0,255) ); for (uint32_t ii = 0; ii < 20; ++ii) { float w = (ii+0.5f)*0.1f; nvgStrokeWidth(vg, w); nvgBeginPath(vg); nvgMoveTo(vg, x,y); nvgLineTo(vg, x+width,y+width*0.3f); nvgStroke(vg); y += 10; } nvgRestore(vg); }
void GraphNodeLink::draw(NVGcontext* ctx) { auto sourceSize = mSource->size().cast<float>(); Eigen::Vector2i inputPosition( mSource->absolutePosition().x() - mParent->absolutePosition().x() + (sourceSize.x() * 0.5f), mSource->absolutePosition().y() - mParent->absolutePosition().y() + (sourceSize.y() * 0.5f) ); Eigen::Vector2i outputPosition(Eigen::Vector2i::Zero()); if (hasTarget()) { // Get relative position of parent (node) of the target (sink) Eigen::Vector2i delta = mSink->parent()->absolutePosition() - mSink->parent()->position(); delta.x() -= (sourceSize.x() * 0.5f); delta.y() -= (sourceSize.y() * 0.5f); outputPosition = mSink->absolutePosition() - delta; } else { Eigen::Vector2i offset = mSource->absolutePosition() - mParent->absolutePosition(); Eigen::Vector2i delta = mTargetPosition - mSource->position(); outputPosition = offset + delta; } Eigen::Vector2i positionDiff = outputPosition - inputPosition; NVGcontext* vg = ctx; nvgStrokeColor(vg, nvgRGBA(131, 148, 150, 255)); nvgStrokeWidth(vg, 2.0f); nvgBeginPath(vg); nvgMoveTo( vg, inputPosition.x(), inputPosition.y() ); nvgQuadTo(vg, 1.2 * positionDiff.x(), positionDiff.y(), outputPosition.x(), outputPosition.y() ); nvgStroke(vg); Widget::draw(ctx); }
void Renderer2D::drawPath( const attributes_2d& attributes, const float32_t* path, const uint32_t& pathSize, const float32_t& border, const color_argb& color, const color_argb& borderColor, const Image2D& image, const float32_t& image_alpha, const float32_t& image_pos_x, const float32_t& image_pos_y, const float32_t& image_width, const float32_t& image_height, const float32_t& image_rotation ) { Context2D* context = _context2D; if( pathSize < 2 || pathSize % 2 != 0 ) return; nvgSave( context ); nvgBeginPath( context ); nvgTranslate( context, attributes.position[0], attributes.position[1] ); nvgSave( context ); nvgRotate( context, attributes.rotation ); nvgMoveTo( context, path[0], path[1]); for( uint32_t i=2; i<pathSize; i+=2 ) { nvgLineTo( context, path[i] * attributes.scale, path[i+1] * attributes.scale); } nvgClosePath( context ); if( image != 0 ) { NVGpaint paint = nvgImagePattern( context, image_pos_x-image_width/2, image_pos_y-image_height/2, image_width, image_height, image_rotation, image, image_alpha ); nvgFillPaint( context, paint); } else { nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) ); } nvgFill(context); nvgStrokeColor( context, nvgRGBA( borderColor.r, borderColor.g, borderColor.b, borderColor.a) ); nvgStrokeWidth( context, border ); nvgStroke( context ); nvgRestore( context ); nvgRestore( context ); }
void t2Image::drawInRounedRect(int x, int y, int width, int height, float radius, int angle /*= 0*/, int alpha /*= 255*/, bool bFill /*= true*/) { NVGpaint imgPaint = nvgImagePattern(t2GetContext(), x, y, width, height, angle / 255.0f, img, alpha / 255.0f); nvgBeginPath(t2GetContext()); if(!bFill) nvgStrokeWidth(t2GetContext(), strokeWidth); nvgRoundedRect(t2GetContext(), x, y, width, height, radius); if(bFill) { nvgFillPaint(t2GetContext(), imgPaint); nvgFill(t2GetContext()); } else { nvgStrokePaint(t2GetContext(), imgPaint); nvgStroke(t2GetContext()); } }
//Render a rectangle bool renderRect(Skin::SkinClass::Attributes &skinClass, float x, float y, float sw, float sh) { if (!m_inited) return false; NVGcolor col = nvgRGBA(skinClass.fill.r, skinClass.fill.g, skinClass.fill.b, skinClass.fill.a); //NVGpaint bg = nvgLinearGradient(m_vg, pos.x, pos.y, pos.x, pos.y + size.y, nvgRGBA(255,255,255,isBlack(col)?16:64), nvgRGBA(0,0,0,isBlack(col)?16:64)); nvgBeginPath(m_vg); nvgRoundedRect(m_vg, x, y, sw, sh, skinClass.cornerRadius); if (!skinClass.hasImage || skinClass.hasFill) { nvgFillColor(m_vg, col); nvgFill(m_vg); } if (skinClass.hasImage) { //int w = size.x, h= size.y; //nvgImageSize(m_vg, skinClass.imageHandle, &w, &h); NVGpaint img = nvgImagePattern(m_vg, x, y, sw, sh, 0.f, skinClass.imageHandle, col.a); nvgFillPaint(m_vg, img); nvgFill(m_vg); } if (skinClass.hasGradient) { NVGpaint g = nvgLinearGradient(m_vg, x, y, x, y + sh, nvgRGBA(skinClass.gradientA.r, skinClass.gradientA.g, skinClass.gradientA.b, skinClass.gradientA.a), nvgRGBA(skinClass.gradientB.r, skinClass.gradientB.g, skinClass.gradientB.b, skinClass.gradientB.a) ); nvgFillPaint(m_vg, g); nvgFill(m_vg); } if (skinClass.hasStroke) { nvgStrokeWidth(m_vg, skinClass.strokeWidth); nvgStrokeColor(m_vg, nvgRGBA(skinClass.stroke.r, skinClass.stroke.g, skinClass.stroke.b, skinClass.stroke.a)); nvgStroke(m_vg); } return true; }
bool Button::Draw(NVGcontext *context, float deltaTime) { if (Widget::Draw(context, deltaTime)) return true; // Draw the default button here nvgBeginPath(context); nvgRoundedRect(context, bounds.position.x, bounds.position.y, bounds.size.x - 4, bounds.size.y - 4, 20); nvgStrokeWidth(context, 2); nvgStrokeColor(context, nvgRGB(100, 100, 100)); nvgFillColor(context, nvgRGB(240, 240, 240)); if (mouseInsideWidgetBounds()) { nvgFillColor(context, nvgRGB(220, 220, 220)); } nvgFill(context); nvgStroke(context); return true; }
int main() { GLFWwindow* window; NVGcontext* vg = NULL; GPUtimer gpuTimer; PerfGraph fps, cpuGraph, gpuGraph; double prevt = 0, cpuTime = 0; NVGLUframebuffer* fb = NULL; int winWidth, winHeight; int fbWidth, fbHeight; float pxRatio; if (!glfwInit()) { printf("Failed to init GLFW."); return -1; } initGraph(&fps, GRAPH_RENDER_FPS, "Frame Time"); initGraph(&cpuGraph, GRAPH_RENDER_MS, "CPU Time"); initGraph(&gpuGraph, GRAPH_RENDER_MS, "GPU Time"); glfwSetErrorCallback(errorcb); #ifndef _WIN32 // don't require this on win32, and works with more cards glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #endif glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1); #ifdef DEMO_MSAA glfwWindowHint(GLFW_SAMPLES, 4); #endif window = glfwCreateWindow(1000, 600, "NanoVG", NULL, NULL); // window = glfwCreateWindow(1000, 600, "NanoVG", glfwGetPrimaryMonitor(), NULL); if (!window) { glfwTerminate(); return -1; } glfwSetKeyCallback(window, key); glfwMakeContextCurrent(window); #ifdef NANOVG_GLEW glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { printf("Could not init glew.\n"); return -1; } // GLEW generates GL error because it calls glGetString(GL_EXTENSIONS), we'll consume it here. glGetError(); #endif #ifdef DEMO_MSAA vg = nvgCreateGL3(NVG_STENCIL_STROKES | NVG_DEBUG); #else vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG); #endif if (vg == NULL) { printf("Could not init nanovg.\n"); return -1; } // Create hi-dpi FBO for hi-dpi screens. glfwGetWindowSize(window, &winWidth, &winHeight); glfwGetFramebufferSize(window, &fbWidth, &fbHeight); // Calculate pixel ration for hi-dpi devices. pxRatio = (float)fbWidth / (float)winWidth; // The image pattern is tiled, set repeat on x and y. fb = nvgluCreateFramebuffer(vg, (int)(100*pxRatio), (int)(100*pxRatio), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); if (fb == NULL) { printf("Could not create FBO.\n"); return -1; } if (loadFonts(vg) == -1) { printf("Could not load fonts\n"); return -1; } glfwSwapInterval(0); initGPUTimer(&gpuTimer); glfwSetTime(0); prevt = glfwGetTime(); while (!glfwWindowShouldClose(window)) { double mx, my, t, dt; float gpuTimes[3]; int i, n; t = glfwGetTime(); dt = t - prevt; prevt = t; startGPUTimer(&gpuTimer); glfwGetCursorPos(window, &mx, &my); glfwGetWindowSize(window, &winWidth, &winHeight); glfwGetFramebufferSize(window, &fbWidth, &fbHeight); // Calculate pixel ration for hi-dpi devices. pxRatio = (float)fbWidth / (float)winWidth; renderPattern(vg, fb, t, pxRatio); // Update and render glViewport(0, 0, fbWidth, fbHeight); glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); nvgBeginFrame(vg, winWidth, winHeight, pxRatio); // Use the FBO as image pattern. if (fb != NULL) { NVGpaint img = nvgImagePattern(vg, 0, 0, 100, 100, 0, fb->image, 1.0f); nvgSave(vg); for (i = 0; i < 20; i++) { nvgBeginPath(vg); nvgRect(vg, 10 + i*30,10, 10, winHeight-20); nvgFillColor(vg, nvgHSLA(i/19.0f, 0.5f, 0.5f, 255)); nvgFill(vg); } nvgBeginPath(vg); nvgRoundedRect(vg, 140 + sinf(t*1.3f)*100, 140 + cosf(t*1.71244f)*100, 250, 250, 20); nvgFillPaint(vg, img); nvgFill(vg); nvgStrokeColor(vg, nvgRGBA(220,160,0,255)); nvgStrokeWidth(vg, 3.0f); nvgStroke(vg); nvgRestore(vg); } renderGraph(vg, 5,5, &fps); renderGraph(vg, 5+200+5,5, &cpuGraph); if (gpuTimer.supported) renderGraph(vg, 5+200+5+200+5,5, &gpuGraph); nvgEndFrame(vg); // Measure the CPU time taken excluding swap buffers (as the swap may wait for GPU) cpuTime = glfwGetTime() - t; updateGraph(&fps, dt); updateGraph(&cpuGraph, cpuTime); // We may get multiple results. n = stopGPUTimer(&gpuTimer, gpuTimes, 3); for (i = 0; i < n; i++) updateGraph(&gpuGraph, gpuTimes[i]); glfwSwapBuffers(window); glfwPollEvents(); } nvgluDeleteFramebuffer(fb); nvgDeleteGL3(vg); printf("Average Frame Time: %.2f ms\n", getGraphAverage(&fps) * 1000.0f); printf(" CPU Time: %.2f ms\n", getGraphAverage(&cpuGraph) * 1000.0f); printf(" GPU Time: %.2f ms\n", getGraphAverage(&gpuGraph) * 1000.0f); glfwTerminate(); return 0; }
void NanoVG::setStrokeWidth( float width ) { nvgStrokeWidth( m_context(), width ); }
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 NVGRenderer::setStrokeWidth(float width) { nvgStrokeWidth(m_context, width); }
void drawUI(NVGcontext *vg, int item, int corners) { const UIData *head = (const UIData *)uiGetHandle(item); UIrect rect = uiGetRect(item); if (uiGetState(item) == UI_FROZEN) { nvgGlobalAlpha(vg, BND_DISABLED_ALPHA); } if (head) { switch(head->subtype) { default: { testrect(vg,rect); drawUIItems(vg,item,corners); } break; case ST_HBOX: { drawUIItemsHbox(vg, item); } break; case ST_VBOX: { drawUIItemsVbox(vg, item); } break; case ST_PANEL: { bndBevel(vg,rect.x,rect.y,rect.w,rect.h); drawUIItems(vg,item,corners); } break; case ST_LABEL: { assert(head); const UIButtonData *data = (UIButtonData*)head; bndLabel(vg,rect.x,rect.y,rect.w,rect.h, data->iconid,data->label); } break; case ST_BUTTON: { const UIButtonData *data = (UIButtonData*)head; bndToolButton(vg,rect.x,rect.y,rect.w,rect.h, corners,(BNDwidgetState)uiGetState(item), data->iconid,data->label); } break; case ST_CHECK: { const UICheckData *data = (UICheckData*)head; BNDwidgetState state = (BNDwidgetState)uiGetState(item); if (*data->option) state = BND_ACTIVE; bndOptionButton(vg,rect.x,rect.y,rect.w,rect.h, state, data->label); } break; case ST_RADIO:{ const UIRadioData *data = (UIRadioData*)head; BNDwidgetState state = (BNDwidgetState)uiGetState(item); if (*data->value == item) state = BND_ACTIVE; bndRadioButton(vg,rect.x,rect.y,rect.w,rect.h, corners,state, data->iconid,data->label); } break; case ST_SLIDER:{ const UISliderData *data = (UISliderData*)head; BNDwidgetState state = (BNDwidgetState)uiGetState(item); static char value[32]; sprintf(value,"%.0f%%",(*data->progress)*100.0f); bndSlider(vg,rect.x,rect.y,rect.w,rect.h, corners,state, *data->progress,data->label,value); } break; case ST_TEXT: { const UITextData *data = (UITextData*)head; BNDwidgetState state = (BNDwidgetState)uiGetState(item); int idx = strlen(data->text); bndTextField(vg,rect.x,rect.y,rect.w,rect.h, corners,state, -1, data->text, idx, idx); } break; case ST_DEMOSTUFF: { draw_demostuff(vg, rect.x, rect.y, rect.w, rect.h); } break; case ST_RECT: { const UIRectData *data = (UIRectData*)head; if (rect.w && rect.h) { BNDwidgetState state = (BNDwidgetState)uiGetState(item); nvgSave(vg); nvgStrokeColor(vg, nvgRGBAf(data->color.r,data->color.g,data->color.b,0.9f)); if (state != BND_DEFAULT) { nvgFillColor(vg, nvgRGBAf(data->color.r,data->color.g,data->color.b,0.5f)); } else { nvgFillColor(vg, nvgRGBAf(data->color.r,data->color.g,data->color.b,0.1f)); } nvgStrokeWidth(vg,2); nvgBeginPath(vg); #if 0 nvgRect(vg,rect.x,rect.y,rect.w,rect.h); #else nvgRoundedRect(vg,rect.x,rect.y,rect.w,rect.h,3); #endif nvgFill(vg); nvgStroke(vg); if (state != BND_DEFAULT) { nvgFillColor(vg, nvgRGBAf(0.0f,0.0f,0.0f,1.0f)); nvgFontSize(vg, 15.0f); nvgBeginPath(vg); nvgTextAlign(vg, NVG_ALIGN_TOP|NVG_ALIGN_CENTER); nvgTextBox(vg, rect.x, rect.y+rect.h*0.3f, rect.w, data->label, NULL); } nvgRestore(vg); } nvgSave(vg); nvgIntersectScissor(vg, rect.x, rect.y, rect.w, rect.h); drawUIItems(vg,item,corners); nvgRestore(vg); } break; } } else { testrect(vg,rect); drawUIItems(vg,item,corners); } if (uiGetState(item) == UI_FROZEN) { nvgGlobalAlpha(vg, 1.0); } }
void GraphPane::draw(AlloyContext* context) { Region::draw(context); box2px rbounds = getBounds(); NVGcontext* nvg = context->nvgContext; box2px gbounds = rbounds; const float LARGE_TEXT = 18.0f; const float MEDIUM_TEXT = 16.0f; const float SMALL_TEXT = 12.0f; float2 gpos(-1, -1); gbounds.position = pixel2(rbounds.position.x + GRAPH_PADDING, rbounds.position.y + GRAPH_PADDING); gbounds.dimensions = pixel2(rbounds.dimensions.x - GRAPH_PADDING * 2, rbounds.dimensions.y - GRAPH_PADDING * 2); if (graphBounds.dimensions.x < 0 || graphBounds.dimensions.y < 0) { updateGraphBounds(); } nvgBeginPath(nvg); nvgRoundedRect(nvg, gbounds.position.x - 2, gbounds.position.y - 2, gbounds.dimensions.x + 4, gbounds.dimensions.y + 4, context->theme.CORNER_RADIUS); nvgFillColor(nvg, context->theme.LIGHTEST); nvgFill(nvg); //Draw vertical line for x=0 if (graphBounds.position.x < 0 && graphBounds.position.x + graphBounds.dimensions.x > 0) { float xpos = -graphBounds.position.x / graphBounds.dimensions.x; nvgBeginPath(nvg); nvgMoveTo(nvg, xpos * gbounds.dimensions.x + gbounds.position.x, gbounds.position.y); nvgLineTo(nvg, xpos * gbounds.dimensions.x + gbounds.position.x, gbounds.position.y + gbounds.dimensions.y); nvgStrokeWidth(nvg, 2.0f); nvgStrokeColor(nvg, context->theme.DARK.toSemiTransparent(0.75f)); nvgStroke(nvg); } //Draw horizontal line for y=0 if (graphBounds.position.y < 0 && graphBounds.position.y + graphBounds.dimensions.y > 0) { float ypos = -graphBounds.position.y / graphBounds.dimensions.y; nvgBeginPath(nvg); nvgMoveTo(nvg, gbounds.position.x, ypos * gbounds.dimensions.y + gbounds.position.y); nvgLineTo(nvg, gbounds.position.x + gbounds.dimensions.x, ypos * gbounds.dimensions.y + gbounds.position.y); nvgStrokeWidth(nvg, 2.0f); nvgStrokeColor(nvg, context->theme.DARK.toSemiTransparent(0.75f)); nvgStroke(nvg); } if (gbounds.contains(cursorPosition)) { context->setCursor(&Cursor::CrossHairs); gpos = (cursorPosition - gbounds.position) / gbounds.dimensions; gpos.y = 1 - gpos.y; gpos = gpos * graphBounds.dimensions + graphBounds.position; nvgBeginPath(nvg); nvgMoveTo(nvg, cursorPosition.x, gbounds.position.y); nvgLineTo(nvg, cursorPosition.x, gbounds.position.y + gbounds.dimensions.y); nvgStrokeWidth(nvg, 1.0f); nvgStrokeColor(nvg, context->theme.DARK.toSemiTransparent(0.25f)); nvgStroke(nvg); nvgBeginPath(nvg); nvgMoveTo(nvg, gbounds.position.x, cursorPosition.y); nvgLineTo(nvg, gbounds.position.x + gbounds.dimensions.x, cursorPosition.y); nvgStrokeWidth(nvg, 1.0f); nvgStrokeColor(nvg, context->theme.DARK.toSemiTransparent(0.25f)); nvgStroke(nvg); } for (GraphDataPtr& curve : curves) { std::vector<float2> points = curve->points; if (points.size() > 1 && graphBounds.dimensions.x > 0.0f && graphBounds.dimensions.y > 0.0f) { NVGcontext* nvg = context->nvgContext; float2 last = points[0]; last = (last - graphBounds.position) / graphBounds.dimensions; last.y = 1.0f - last.y; last = last * gbounds.dimensions + gbounds.position; nvgBeginPath(nvg); nvgMoveTo(nvg, last.x, last.y); for (int i = 1; i < (int)points.size(); i++) { float2 pt = points[i]; pt = (pt - graphBounds.position) / graphBounds.dimensions; pt.y = 1.0f - pt.y; pt = pt * gbounds.dimensions + gbounds.position; nvgLineTo(nvg, pt.x, pt.y); last = pt; } nvgStrokeWidth(nvg, 2.0f); nvgStrokeColor(nvg, curve->color); nvgStroke(nvg); } } nvgFontFaceId(nvg, context->getFontHandle(FontType::Bold)); nvgFontSize(nvg, LARGE_TEXT); nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP); drawText(nvg, rbounds.position + float2(rbounds.dimensions.x / 2, 2.0f), name, FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); nvgFontSize(nvg, MEDIUM_TEXT); nvgFontFaceId(nvg, context->getFontHandle(FontType::Bold)); nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_BOTTOM); drawText(nvg, rbounds.position + float2(rbounds.dimensions.x / 2, rbounds.dimensions.y - 4.0f), xAxisLabel, FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP); nvgSave(nvg); pixel2 center = rbounds.position + float2(2.0f, rbounds.dimensions.y * 0.5f); nvgTranslate(nvg, center.x, center.y); nvgRotate(nvg, -ALY_PI * 0.5f); drawText(nvg, pixel2(0, 2), yAxisLabel, FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); nvgRestore(nvg); nvgFontSize(nvg, SMALL_TEXT); nvgTextAlign(nvg, NVG_ALIGN_RIGHT | NVG_ALIGN_TOP); drawText(nvg, rbounds.position + float2(GRAPH_PADDING, GRAPH_PADDING), MakeString() << std::setprecision(2) << (graphBounds.position.y + graphBounds.dimensions.y), FontStyle::Outline, context->theme.LIGHTER, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_RIGHT | NVG_ALIGN_BOTTOM); drawText(nvg, rbounds.position + float2(GRAPH_PADDING, rbounds.dimensions.y - GRAPH_PADDING), MakeString() << std::setprecision(2) << graphBounds.position.y, FontStyle::Outline, context->theme.LIGHTER, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_RIGHT | NVG_ALIGN_TOP); drawText(nvg, rbounds.position + float2(rbounds.dimensions.x - GRAPH_PADDING, rbounds.dimensions.y - GRAPH_PADDING + 2), MakeString() << std::setprecision(2) << (graphBounds.position.x + graphBounds.dimensions.x), FontStyle::Outline, context->theme.LIGHTER, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP); drawText(nvg, rbounds.position + float2(GRAPH_PADDING, rbounds.dimensions.y - GRAPH_PADDING + 2), MakeString() << std::setprecision(2) << graphBounds.position.x, FontStyle::Outline, context->theme.LIGHTER, context->theme.DARK); if (cursorPosition.x >= 0) { float minDist = 1E30f; float bestY = 0; GraphDataPtr closestCurve; for (GraphDataPtr& curve : curves) { float y = curve->interpolate(gpos.x); if (y != GraphData::NO_INTERSECT) { if (std::abs(y - gpos.y) < minDist) { minDist = std::abs(y - gpos.y); bestY = y; closestCurve = curve; } } } if (closestCurve.get() != nullptr) { nvgBeginPath(nvg); nvgStrokeWidth(nvg, 2.0f); nvgFillColor(nvg, closestCurve->color); nvgStrokeColor(nvg, context->theme.LIGHTER); float2 pt(gpos.x, bestY); pt = (pt - graphBounds.position) / graphBounds.dimensions; pt.y = 1.0f - pt.y; pt = pt * gbounds.dimensions + gbounds.position; nvgCircle(nvg, pt.x, pt.y, 4); nvgFill(nvg); nvgStroke(nvg); nvgBeginPath(nvg); nvgFillColor(nvg, context->theme.DARK); nvgCircle(nvg, cursorPosition.x, cursorPosition.y, 2); nvgFill(nvg); nvgTextAlign(nvg, NVG_ALIGN_RIGHT | NVG_ALIGN_MIDDLE); nvgFontSize(nvg, MEDIUM_TEXT); drawText(nvg, float2(pt.x - 8, pt.y), closestCurve->name, FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); nvgTextAlign(nvg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE); drawText(nvg, float2(pt.x + 8, pt.y), MakeString() << "(" << std::setprecision(2) << gpos.x << ", " << std::setprecision(2) << bestY << ")", FontStyle::Outline, context->theme.LIGHTEST, context->theme.DARK); } else { nvgBeginPath(nvg); nvgFillColor(nvg, context->theme.DARK); nvgCircle(nvg, cursorPosition.x, cursorPosition.y, 2); nvgFill(nvg); } } }
void draw(NVGcontext *vg, float w, float h) { bndBackground(vg, 0, 0, w, h); // some OUI stuff uiBeginLayout(); int root = panel(); // position root element uiSetSize(0,w,h); ((UIData*)uiGetHandle(root))->handler = roothandler; uiSetEvents(root, UI_SCROLL|UI_BUTTON0_DOWN); uiSetBox(root, UI_COLUMN); static int choice = -1; int menu = uiItem(); uiSetLayout(menu, UI_HFILL|UI_TOP); uiSetBox(menu, UI_ROW); uiInsert(root, menu); int opt_blendish_demo = add_menu_option(menu, "Blendish Demo", &choice); int opt_oui_demo = add_menu_option(menu, "OUI Demo", &choice); int opt_layouts = add_menu_option(menu, "UI_LAYOUT", &choice); int opt_row = add_menu_option(menu, "UI_ROW", &choice); int opt_column = add_menu_option(menu, "UI_COLUMN", &choice); int opt_wrap = add_menu_option(menu, "UI_WRAP", &choice); if (choice < 0) choice = opt_blendish_demo; int content = uiItem(); uiSetLayout(content, UI_FILL); uiInsert(root, content); if (choice == opt_blendish_demo) { int democontent = uiItem(); uiSetLayout(democontent, UI_FILL); uiInsert(content, democontent); UIData *data = (UIData *)uiAllocHandle(democontent, sizeof(UIData)); data->handler = 0; data->subtype = ST_DEMOSTUFF; } else if (choice == opt_oui_demo) { int democontent = uiItem(); uiSetLayout(democontent, UI_TOP); uiSetSize(democontent, 250, 0); uiInsert(content, democontent); build_democontent(democontent); } else if (choice == opt_layouts) { build_layoutdemo(content); } else if (choice == opt_row) { build_rowdemo(content); } else if (choice == opt_column) { build_columndemo(content); } else if (choice == opt_wrap) { build_wrapdemo(content); } uiEndLayout(); drawUI(vg, 0, BND_CORNER_NONE); #if 0 for (int i = 0; i < uiGetLastItemCount(); ++i) { if (uiRecoverItem(i) == -1) { UIitem *pitem = uiLastItemPtr(i); nvgBeginPath(vg); nvgRect(vg,pitem->margins[0],pitem->margins[1],pitem->size[0],pitem->size[1]); nvgStrokeWidth(vg, 2); nvgStrokeColor(vg, nvgRGBAf(1.0f,0.0f,0.0f,0.5f)); nvgStroke(vg); } } #endif if (choice == opt_blendish_demo) { UIvec2 cursor = uiGetCursor(); cursor.x -= w/2; cursor.y -= h/2; if (abs(cursor.x) > (w/3)) { bndJoinAreaOverlay(vg, 0, 0, w, h, 0, (cursor.x > 0)); } else if (abs(cursor.y) > (h/3)) { bndJoinAreaOverlay(vg, 0, 0, w, h, 1, (cursor.y > 0)); } } uiProcess((int)(glfwGetTime()*1000.0)); }
JNIEXPORT void JNICALL Java_org_lwjgl_nanovg_NanoVG_nnvgStrokeWidth(JNIEnv *__env, jclass clazz, jlong ctxAddress, jfloat size) { NVGcontext *ctx = (NVGcontext *)(intptr_t)ctxAddress; UNUSED_PARAMS(__env, clazz) nvgStrokeWidth(ctx, size); }