Exemplo n.º 1
0
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 );
}
Exemplo n.º 2
0
void Renderer2D::drawRectangle( const attributes_2d& attributes, const float32_t& width, const float32_t& height,
			const float32_t& border, const color_argb& color, const color_argb& borderColor,
			const Image2D& image, const float32_t& image_alpha, const float32_t& image_pos_x,
			const float32_t& image_pos_y, const float32_t& image_width, const float32_t& image_height,
			const float32_t& image_rotation )
{
	Context2D* context = _context2D;
	const float32_t sWidth = width * attributes.scale;
	const float32_t sHeight = height * attributes.scale;

	nvgSave( context );
	nvgBeginPath( context );
	nvgTranslate( context, attributes.position[0], attributes.position[1] );

	nvgSave( context );
	nvgRotate( context, attributes.rotation );
	nvgRect( context, -sWidth/2, -sHeight/2, sWidth, sHeight );
	if( image != 0 )
	{
		NVGpaint paint = nvgImagePattern( context, (-sWidth/2)+image_pos_x, (-sHeight/2)+image_pos_y,
				image_width, image_height, image_rotation, image, image_alpha );
		nvgFillPaint( context, paint);
	}
	else
	{
		nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) );
	}
	nvgFill( context );
	nvgStrokeColor( context, nvgRGBA( borderColor.r, borderColor.g, borderColor.b, borderColor.a) );
	nvgStrokeWidth( context, border );
	nvgStroke( context );
	nvgRestore( context );

	nvgRestore( context );
}
Exemplo n.º 3
0
void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float height,
				float t, int blowup, struct DemoData* data)
{
	float x,y,popy;

	drawEyes(vg, width - 250, 50, 150, 100, mx, my, t);
	drawParagraph(vg, width - 450, 50, 150, 100, mx, my);
	drawGraph(vg, 0, height/2, width, height/2, t);
	drawColorwheel(vg, width - 300, height - 300, 250.0f, 250.0f, t);

	// Line joints
	drawLines(vg, 50, height-50, 600, 50, t);

	// Line caps
	drawWidths(vg, 10, 50, 30);

	// Line caps
	drawCaps(vg, 10, 300, 30);

	nvgSave(vg);
	if (blowup) {
		nvgRotate(vg, sinf(t*0.3f)*5.0f/180.0f*NVG_PI);
		nvgScale(vg, 2.0f, 2.0f);
	}

	// Widgets
	drawWindow(vg, "Widgets `n Stuff", 50, 50, 300, 400);
	x = 60; y = 95;
	drawSearchBox(vg, "Search", x,y,280,25);
	y += 40;
	drawDropDown(vg, "Effects", x,y,280,28);
	popy = y + 14;
	y += 45;

	// Form
	drawLabel(vg, "Login", x,y, 280,20);
	y += 25;
	drawEditBox(vg, "Email",  x,y, 280,28);
	y += 35;
	drawEditBox(vg, "Password", x,y, 280,28);
	y += 38;
	drawCheckBox(vg, "Remember me", x,y, 140,28);
	drawButton(vg, ICON_LOGIN, "Sign in", x+138, y, 140, 28, nvgRGBA(0,96,128,255));
	y += 45;

	// Slider
	drawLabel(vg, "Diameter", x,y, 280,20);
	y += 25;
	drawEditBoxNum(vg, "123.00", "px", x+180,y, 100,28);
	drawSlider(vg, 0.4f, x,y, 170,28);
	y += 55;

	drawButton(vg, ICON_TRASH, "Delete", x, y, 160, 28, nvgRGBA(128,16,8,255));
	drawButton(vg, 0, "Cancel", x+170, y, 110, 28, nvgRGBA(0,0,0,0));

	// Thumbnails box
	drawThumbnails(vg, 365, popy-30, 160, 300, data->images, 12, t);

	nvgRestore(vg);
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
void TextNode::renderItself(RenderContext& renderContext)
{
    NVGcontext& nanoVgContext = renderContext.getNanoVgContext();
    nvgSave(&nanoVgContext);

    setupContext(nanoVgContext);

    Color finalColor = mFontColor.getBlendedColor(renderContext.getBlendColors());
    nvgFillColor(&nanoVgContext, nvgRGBAf(finalColor.getRed(), finalColor.getGreen(),
            finalColor.getBlue(), finalColor.getAlpha()));

    for(const Text& text : mTexts)
    {
        const char* charArray = text.getString().getCharArray();
        float positionX = text.getPosition().getX();
        float positionY = text.getPosition().getY();
        if(isPositive(text.getBoxWidth()))
        {
            nvgTextBox(&nanoVgContext, positionX, positionY, text.getBoxWidth(), charArray, nullptr);
        }
        else
        {
            nvgText(&nanoVgContext, positionX, positionY, charArray, nullptr);
        }
    }

    nvgRestore(&nanoVgContext);

    Node::renderItself(renderContext);
}
Exemplo n.º 6
0
void Renderer2D::drawText( const attributes_2d& attributes,Font2D font, const char* text, const float32_t& fontSize,
			const color_argb& color, const float32_t& blur, const float32_t& spacing,
			const float32_t& lineHeight, const TextAlignment& alignment )
{
	Context2D* context = _context2D;

	nvgSave( context );
	nvgBeginPath( context );

	nvgRotate( context, attributes.rotation );

	nvgFontSize( context, fontSize * attributes.scale );
	nvgFontBlur( context, blur );
	nvgTextLetterSpacing(context, spacing);
	nvgTextLineHeight(context, lineHeight);
	nvgTextAlign(context, alignment.value );
	nvgFontFaceId(context, font);

	nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) );
	nvgFill(context);

	nvgText(context, attributes.position[0], attributes.position[1], text, NULL);

	nvgRestore( context );
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
	void NanoInk::drawCache(NVGdisplayList* cache)
	{
		nvgSave(mCtx);
		nvgTranslate(mCtx, floor(mFrame.dabsolute(DIM_X)), floor(mFrame.dabsolute(DIM_Y)));
		nvgDrawDisplayList(mCtx, cache);
		nvgRestore(mCtx);
	}
Exemplo n.º 9
0
Rect TextNode::generateBoundingBox()
{
    Rect boundingBox = Node::generateBoundingBox();

    if(mFontColor.isVisible())
    {
        NVGcontext& nanoVgContext = Application::getNanoVgContext();
        nvgSave(&nanoVgContext);

        float bounds[4];
        setupContext(nanoVgContext);

        for(const Text& text : mTexts)
        {
            const char* charArray = text.getString().getCharArray();
            float positionX = text.getPosition().getX();
            float positionY = text.getPosition().getY();
            if(isPositive(text.getBoxWidth()))
            {
                nvgTextBoxBounds(&nanoVgContext, positionX, positionY, text.getBoxWidth(),
                        charArray, nullptr, bounds);
            }
            else
            {
                nvgTextBounds(&nanoVgContext, positionX, positionY, charArray, nullptr, bounds);
            }

            boundingBox.join(Rect(Point(bounds[0], bounds[1]), Point(bounds[2], bounds[3])));
        }

        nvgRestore(&nanoVgContext);
    }

    return boundingBox;
}
Exemplo n.º 10
0
void QNanoPainter::drawImage(QNanoImage &image, const QRectF sourceRect, const QRectF destinationRect)
{
    image.setParentPainter(this);
    float sx = sourceRect.x();
    float sy = sourceRect.y();
    float sw = sourceRect.width();
    float sh = sourceRect.height();
    float dx = destinationRect.x();
    float dy = destinationRect.y();
    float dw = destinationRect.width();
    float dh = destinationRect.height();
    _checkAlignPixelsAdjust(&dx, &dy);
    _checkAlignPixels(&dw, &dh);
    float startX = dx - sx * (dw/sw);
    float startY = dy - sy * (dh/sh);
    float endX = dw * image.width() / sw;
    float endY = dh * image.height() / sh;
    NVGpaint ip = nvgImagePattern(nvgCtx(), startX, startY, endX, endY, 0.0f, image.getID(nvgCtx()), 1.0f);
    nvgSave(nvgCtx());
    nvgBeginPath(nvgCtx());
    rect(dx, dy, dw, dh);
    nvgFillPaint(nvgCtx(), ip);
    nvgFill(nvgCtx());
    nvgRestore(nvgCtx());
}
Exemplo n.º 11
0
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);
}
Exemplo n.º 12
0
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);
}
Exemplo n.º 13
0
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);
}
Exemplo n.º 14
0
void TextNode::getTextMetrics(float& ascender, float& descender, float& lineHeight) const
{
    NVGcontext& nanoVgContext = Application::getNanoVgContext();
    nvgSave(&nanoVgContext);

    setupContext(nanoVgContext);

    nvgTextMetrics(&nanoVgContext, &ascender, &descender, &lineHeight);

    nvgRestore(&nanoVgContext);
}
Exemplo n.º 15
0
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 );
}
Exemplo n.º 16
0
void VectorRenderer::preDraw(lmscalar a, lmscalar b, lmscalar c, lmscalar d, lmscalar e, lmscalar f) {
	LOOM_PROFILE_SCOPE(vectorPreDraw);

	nvgSave(nvg);
	nvgTransform(nvg, (float) a, (float) b, (float) c, (float) d, (float) e, (float) f);
	
	nvgLineCap(nvg, NVG_BUTT);
	nvgLineJoin(nvg, NVG_ROUND);

	currentTextFormat = VectorTextFormat::defaultFormat;
	currentTextFormatAlpha = 1;
	currentTextFormatApplied = false;
}
Exemplo n.º 17
0
void QNanoPainter::drawImage(QNanoImage &image, float x, float y, float width, float height)
{
    _checkAlignPixelsAdjust(&x, &y);
    _checkAlignPixels(&width, &height);
    image.setParentPainter(this);
    NVGpaint ip = nvgImagePattern(nvgCtx(), x, y, width, height, 0.0f, image.getID(nvgCtx()), 1.0f);
    nvgSave(nvgCtx());
    nvgBeginPath(nvgCtx());
    nvgRect(nvgCtx(), x, y, width, height);
    nvgFillPaint(nvgCtx(), ip);
    nvgFill(nvgCtx());
    nvgRestore(nvgCtx());
}
Exemplo n.º 18
0
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);
}
Exemplo n.º 19
0
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);
}
Exemplo n.º 20
0
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);
}
Exemplo n.º 21
0
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 Cursor::draw(AlloyContext* context) const {
	pixel2 cursor = context->cursorPosition;
	if (fontSize > 0.0f && context->hasFocus && cursor.x >= 0 && cursor.y >= 0
			&& cursor.x < context->getScreenWidth() && cursor.y < context->getScreenHeight()) {
		NVGcontext* nvg = context->nvgContext;
		nvgTextAlign(nvg, align);
		nvgSave(nvg);
		nvgFontFaceId(nvg, context->getFontHandle(fontType));
		nvgFontSize(nvg, fontSize);
		nvgFillColor(nvg, Color(255, 255, 255));
		nvgTranslate(nvg, cursor.x+nudge.x, cursor.y+nudge.y);
		nvgRotate(nvg, angle);
		const float shift = 1.0f;
		const char* txt = codeString.c_str();
		nvgFillColor(nvg, Color(0, 0, 0));
		nvgText(nvg, +shift, 0, txt, nullptr);
		nvgText(nvg, -shift, 0, txt, nullptr);
		nvgText(nvg, 0, +shift, txt, nullptr);
		nvgText(nvg, 0, -shift, txt, nullptr);
		nvgFillColor(nvg, Color(255, 255, 255));
		nvgText(nvg, 0, 0, txt, nullptr);
		nvgRestore(nvg);
	}
}
Exemplo n.º 23
0
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);
}
Exemplo n.º 24
0
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);
}
Exemplo n.º 25
0
void NanoVG::save()
{
    nvgSave( m_context() );
}
Exemplo n.º 26
0
void draw_demostuff(NVGcontext *vg, int x, int y, float w, float h) {
    nvgSave(vg);
    nvgTranslate(vg, x, y);

    bndSplitterWidgets(vg, 0, 0, w, h);
    
    x = 10;
    y = 10;

    bndToolButton(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_DEFAULT,
        BND_ICONID(6,3),"Default");
    y += 25;
    bndToolButton(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_HOVER,
        BND_ICONID(6,3),"Hovered");
    y += 25;   
    bndToolButton(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_ACTIVE,
        BND_ICONID(6,3),"Active");
    
    y += 40;
    bndRadioButton(vg,x,y,80,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_DEFAULT,
        -1,"Default");
    y += 25;
    bndRadioButton(vg,x,y,80,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_HOVER,
        -1,"Hovered");
    y += 25;
    bndRadioButton(vg,x,y,80,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_ACTIVE,
        -1,"Active");

    y += 25;
    bndLabel(vg,x,y,120,BND_WIDGET_HEIGHT,-1,"Label:");
    y += BND_WIDGET_HEIGHT;
    bndChoiceButton(vg,x,y,80,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_DEFAULT,
        -1, "Default");
    y += 25;
    bndChoiceButton(vg,x,y,80,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_HOVER,
        -1, "Hovered");
    y += 25;
    bndChoiceButton(vg,x,y,80,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_ACTIVE,
        -1, "Active");
        
    y += 25;
    int ry = y;
    int rx = x;
    
    y = 10;
    x += 130;
    bndOptionButton(vg,x,y,120,BND_WIDGET_HEIGHT,BND_DEFAULT,"Default");
    y += 25;
    bndOptionButton(vg,x,y,120,BND_WIDGET_HEIGHT,BND_HOVER,"Hovered");
    y += 25;
    bndOptionButton(vg,x,y,120,BND_WIDGET_HEIGHT,BND_ACTIVE,"Active");

    y += 40;
    bndNumberField(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_DOWN,BND_DEFAULT,
        "Top","100");
    y += BND_WIDGET_HEIGHT-2;
    bndNumberField(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_ALL,BND_DEFAULT,
        "Center","100");
    y += BND_WIDGET_HEIGHT-2;
    bndNumberField(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_TOP,BND_DEFAULT,
        "Bottom","100");

    int mx = x-30;
    int my = y-12;
    int mw = 120;
    bndMenuBackground(vg,mx,my,mw,120,BND_CORNER_TOP);
    bndMenuLabel(vg,mx,my,mw,BND_WIDGET_HEIGHT,-1,"Menu Title");
    my += BND_WIDGET_HEIGHT-2;
    bndMenuItem(vg,mx,my,mw,BND_WIDGET_HEIGHT,BND_DEFAULT,
        BND_ICONID(17,3),"Default");
    my += BND_WIDGET_HEIGHT-2;
    bndMenuItem(vg,mx,my,mw,BND_WIDGET_HEIGHT,BND_HOVER,
        BND_ICONID(18,3),"Hovered");
    my += BND_WIDGET_HEIGHT-2;
    bndMenuItem(vg,mx,my,mw,BND_WIDGET_HEIGHT,BND_ACTIVE,
        BND_ICONID(19,3),"Active");
    
    y = 10;
    x += 130;
    int ox = x;
    bndNumberField(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_DEFAULT,
        "Default","100");
    y += 25;
    bndNumberField(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_HOVER,
        "Hovered","100");
    y += 25;
    bndNumberField(vg,x,y,120,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_ACTIVE,
        "Active","100");
    
    y += 40;
    bndRadioButton(vg,x,y,60,BND_WIDGET_HEIGHT,BND_CORNER_RIGHT,BND_DEFAULT,
        -1,"One");
    x += 60-1;
    bndRadioButton(vg,x,y,60,BND_WIDGET_HEIGHT,BND_CORNER_ALL,BND_DEFAULT,
        -1,"Two");
    x += 60-1;
    bndRadioButton(vg,x,y,60,BND_WIDGET_HEIGHT,BND_CORNER_ALL,BND_DEFAULT,
        -1,"Three");
    x += 60-1;
    bndRadioButton(vg,x,y,60,BND_WIDGET_HEIGHT,BND_CORNER_LEFT,BND_ACTIVE,
        -1,"Butts");
    
    x = ox;
    y += 40;
    float progress_value = fmodf(glfwGetTime()/10.0,1.0);
    char progress_label[32];
    sprintf(progress_label, "%d%%", int(progress_value*100+0.5f));
    bndSlider(vg,x,y,240,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_DEFAULT,
        progress_value,"Default",progress_label);
    y += 25;
    bndSlider(vg,x,y,240,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_HOVER,
        progress_value,"Hovered",progress_label);
    y += 25;
    bndSlider(vg,x,y,240,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_ACTIVE,
        progress_value,"Active",progress_label);

    int rw = x+240-rx;
    float s_offset = sinf(glfwGetTime()/2.0)*0.5+0.5;
    float s_size = cosf(glfwGetTime()/3.11)*0.5+0.5;
    
    bndScrollBar(vg,rx,ry,rw,BND_SCROLLBAR_HEIGHT,BND_DEFAULT,s_offset,s_size);
    ry += 20;
    bndScrollBar(vg,rx,ry,rw,BND_SCROLLBAR_HEIGHT,BND_HOVER,s_offset,s_size);
    ry += 20;
    bndScrollBar(vg,rx,ry,rw,BND_SCROLLBAR_HEIGHT,BND_ACTIVE,s_offset,s_size);
    
    const char edit_text[] = "The quick brown fox";
    int textlen = strlen(edit_text)+1;
    int t = int(glfwGetTime()*2);
    int idx1 = (t/textlen)%textlen;
    int idx2 = idx1 + (t%(textlen-idx1));
    
    ry += 25;
    bndTextField(vg,rx,ry,240,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_DEFAULT,
        -1, edit_text, idx1, idx2);
    ry += 25;
    bndTextField(vg,rx,ry,240,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_HOVER,
        -1, edit_text, idx1, idx2);
    ry += 25;
    bndTextField(vg,rx,ry,240,BND_WIDGET_HEIGHT,BND_CORNER_NONE,BND_ACTIVE,
        -1, edit_text, idx1, idx2);
        
    draw_noodles(vg, 20, ry+50);
    
    rx += rw + 20;
    ry = 10;
    bndScrollBar(vg,rx,ry,BND_SCROLLBAR_WIDTH,240,BND_DEFAULT,s_offset,s_size);
    rx += 20;
    bndScrollBar(vg,rx,ry,BND_SCROLLBAR_WIDTH,240,BND_HOVER,s_offset,s_size);
    rx += 20;
    bndScrollBar(vg,rx,ry,BND_SCROLLBAR_WIDTH,240,BND_ACTIVE,s_offset,s_size);
    
    x = ox;
    y += 40;
    bndToolButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_RIGHT,
        BND_DEFAULT,BND_ICONID(0,10),NULL);
    x += BND_TOOL_WIDTH-1;
    bndToolButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_ALL,
        BND_DEFAULT,BND_ICONID(1,10),NULL);
    x += BND_TOOL_WIDTH-1;
    bndToolButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_ALL,
        BND_DEFAULT,BND_ICONID(2,10),NULL);
    x += BND_TOOL_WIDTH-1;
    bndToolButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_ALL,
        BND_DEFAULT,BND_ICONID(3,10),NULL);
    x += BND_TOOL_WIDTH-1;
    bndToolButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_ALL,
        BND_DEFAULT,BND_ICONID(4,10),NULL);
    x += BND_TOOL_WIDTH-1;
    bndToolButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_LEFT,
        BND_DEFAULT,BND_ICONID(5,10),NULL);
    x += BND_TOOL_WIDTH-1;
    x += 5;
    bndRadioButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_RIGHT,
        BND_DEFAULT,BND_ICONID(0,11),NULL);
    x += BND_TOOL_WIDTH-1;
    bndRadioButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_ALL,
        BND_DEFAULT,BND_ICONID(1,11),NULL);
    x += BND_TOOL_WIDTH-1;
    bndRadioButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_ALL,
        BND_DEFAULT,BND_ICONID(2,11),NULL);
    x += BND_TOOL_WIDTH-1;
    bndRadioButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_ALL,
        BND_DEFAULT,BND_ICONID(3,11),NULL);
    x += BND_TOOL_WIDTH-1;
    bndRadioButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_ALL,
        BND_ACTIVE,BND_ICONID(4,11),NULL);
    x += BND_TOOL_WIDTH-1;
    bndRadioButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_LEFT,
        BND_DEFAULT,BND_ICONID(5,11),NULL);

    nvgRestore(vg);
}
Exemplo n.º 27
0
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);
    }
}
JNIEXPORT void JNICALL Java_org_lwjgl_nanovg_NanoVG_nnvgSave(JNIEnv *__env, jclass clazz, jlong ctxAddress) {
	NVGcontext *ctx = (NVGcontext *)(intptr_t)ctxAddress;
	UNUSED_PARAMS(__env, clazz)
	nvgSave(ctx);
}
Exemplo n.º 29
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);
			}
		}
	}
Exemplo n.º 30
0
		void NVGRenderer::saveState()
		{
			nvgSave(m_context);
		}