Пример #1
0
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);
}
Пример #2
0
void NanoVG::bezierTo( float c1x, float c1y, float c2x, float c2y, float x, float y )
{
    nvgBezierTo( m_context(), c1x, c1y, c2x, c2y, x, y );
}
Пример #3
0
void drawGraph(struct NVGcontext* vg, float x, float y, float w, float h, float t)
{
	struct NVGpaint bg;
	float samples[6];
	float sx[6], sy[6];
	float dx = w/5.0f;
	int i;

	samples[0] = (1+sinf(t*1.2345f+cosf(t*0.33457f)*0.44f) )*0.5f;
	samples[1] = (1+sinf(t*0.68363f+cosf(t*1.3f)*1.55f) )*0.5f;
	samples[2] = (1+sinf(t*1.1642f+cosf(t*0.33457f)*1.24f) )*0.5f;
	samples[3] = (1+sinf(t*0.56345f+cosf(t*1.63f)*0.14f) )*0.5f;
	samples[4] = (1+sinf(t*1.6245f+cosf(t*0.254f)*0.3f) )*0.5f;
	samples[5] = (1+sinf(t*0.345f+cosf(t*0.03f)*0.6f) )*0.5f;

	for (i = 0; i < 6; i++) {
		sx[i] = x+i*dx;
		sy[i] = y+h*samples[i]*0.8f;
	}

	// Graph background
	bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(0,160,192,0), nvgRGBA(0,160,192,64) );
	nvgBeginPath(vg);
	nvgMoveTo(vg, sx[0], sy[0]);
	for (i = 1; i < 6; i++)
		nvgBezierTo(vg, sx[i-1]+dx*0.5f,sy[i-1], sx[i]-dx*0.5f,sy[i], sx[i],sy[i]);
	nvgLineTo(vg, x+w, y+h);
	nvgLineTo(vg, x, y+h);
	nvgFillPaint(vg, bg);
	nvgFill(vg);

	// Graph line
	nvgBeginPath(vg);
	nvgMoveTo(vg, sx[0], sy[0]+2);
	for (i = 1; i < 6; i++)
		nvgBezierTo(vg, sx[i-1]+dx*0.5f,sy[i-1]+2, sx[i]-dx*0.5f,sy[i]+2, sx[i],sy[i]+2);
	nvgStrokeColor(vg, nvgRGBA(0,0,0,32) );
	nvgStrokeWidth(vg, 3.0f);
	nvgStroke(vg);

	nvgBeginPath(vg);
	nvgMoveTo(vg, sx[0], sy[0]);
	for (i = 1; i < 6; i++)
		nvgBezierTo(vg, sx[i-1]+dx*0.5f,sy[i-1], sx[i]-dx*0.5f,sy[i], sx[i],sy[i]);
	nvgStrokeColor(vg, nvgRGBA(0,160,192,255) );
	nvgStrokeWidth(vg, 3.0f);
	nvgStroke(vg);

	// Graph sample pos
	for (i = 0; i < 6; i++) {
		bg = nvgRadialGradient(vg, sx[i],sy[i]+2, 3.0f,8.0f, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,0) );
		nvgBeginPath(vg);
		nvgRect(vg, sx[i]-10, sy[i]-10+2, 20,20);
		nvgFillPaint(vg, bg);
		nvgFill(vg);
	}

	nvgBeginPath(vg);
	for (i = 0; i < 6; i++)
		nvgCircle(vg, sx[i], sy[i], 4.0f);
	nvgFillColor(vg, nvgRGBA(0,160,192,255) );
	nvgFill(vg);
	nvgBeginPath(vg);
	for (i = 0; i < 6; i++)
		nvgCircle(vg, sx[i], sy[i], 2.0f);
	nvgFillColor(vg, nvgRGBA(220,220,220,255) );
	nvgFill(vg);

	nvgStrokeWidth(vg, 1.0f);
}
Пример #4
0
void QNanoPainter::bezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y)
{
    _checkAlignPixelsAdjust(&x, &y);
    _checkAlignPixelsAdjust(&c1x, &c1y, &c2x, &c2y);
    nvgBezierTo(nvgCtx(), c1x, c1y, c2x, c2y, x, y);
}
Пример #5
0
static void
draw(NVGcontext *nvg, struct zr_command_queue *queue, int width, int height)
{
    const struct zr_command *cmd;
    glPushAttrib(GL_ENABLE_BIT|GL_COLOR_BUFFER_BIT);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_SCISSOR_TEST);
    glEnable(GL_TEXTURE_2D);

    nvgBeginFrame(nvg, width, height, ((float)width/(float)height));
    zr_foreach_command(cmd, queue) {
        switch (cmd->type) {
        case ZR_COMMAND_NOP: break;
        case ZR_COMMAND_SCISSOR: {
            const struct zr_command_scissor *s = zr_command(scissor, cmd);
            nvgScissor(nvg, s->x, s->y, s->w, s->h);
        } break;
        case ZR_COMMAND_LINE: {
            const struct zr_command_line *l = zr_command(line, cmd);
            nvgBeginPath(nvg);
            nvgMoveTo(nvg, l->begin.x, l->begin.y);
            nvgLineTo(nvg, l->end.x, l->end.y);
            nvgFillColor(nvg, nvgRGBA(l->color.r, l->color.g, l->color.b, l->color.a));
            nvgFill(nvg);
        } break;
        case ZR_COMMAND_CURVE: {
            const struct zr_command_curve *q = zr_command(curve, cmd);
            nvgBeginPath(nvg);
            nvgMoveTo(nvg, q->begin.x, q->begin.y);
            nvgBezierTo(nvg, q->ctrl[0].x, q->ctrl[0].y, q->ctrl[1].x, q->ctrl[1].y, q->end.x, q->end.y);
            nvgStrokeColor(nvg, nvgRGBA(q->color.r, q->color.g, q->color.b, q->color.a));
            nvgStroke(nvg);
        } break;
        case ZR_COMMAND_RECT: {
            const struct zr_command_rect *r = zr_command(rect, cmd);
            nvgBeginPath(nvg);
            nvgRoundedRect(nvg, r->x, r->y, r->w, r->h, r->rounding);
            nvgFillColor(nvg, nvgRGBA(r->color.r, r->color.g, r->color.b, r->color.a));
            nvgFill(nvg);
        } break;
        case ZR_COMMAND_CIRCLE: {
            const struct zr_command_circle *c = zr_command(circle, cmd);
            nvgBeginPath(nvg);
            nvgCircle(nvg, c->x + (c->w/2.0f), c->y + c->w/2.0f, c->w/2.0f);
            nvgFillColor(nvg, nvgRGBA(c->color.r, c->color.g, c->color.b, c->color.a));
            nvgFill(nvg);
        } break;
        case ZR_COMMAND_TRIANGLE: {
            const struct zr_command_triangle *t = zr_command(triangle, cmd);
            nvgBeginPath(nvg);
            nvgMoveTo(nvg, t->a.x, t->a.y);
            nvgLineTo(nvg, t->b.x, t->b.y);
            nvgLineTo(nvg, t->c.x, t->c.y);
            nvgLineTo(nvg, t->a.x, t->a.y);
            nvgFillColor(nvg, nvgRGBA(t->color.r, t->color.g, t->color.b, t->color.a));
            nvgFill(nvg);
        } break;
        case ZR_COMMAND_TEXT: {
            const struct zr_command_text *t = zr_command(text, cmd);
            nvgBeginPath(nvg);
            nvgRoundedRect(nvg, t->x, t->y, t->w, t->h, 0);
            nvgFillColor(nvg, nvgRGBA(t->background.r, t->background.g,
                t->background.b, t->background.a));
            nvgFill(nvg);

            nvgBeginPath(nvg);
            nvgFillColor(nvg, nvgRGBA(t->foreground.r, t->foreground.g,
                t->foreground.b, t->foreground.a));
            nvgTextAlign(nvg, NVG_ALIGN_MIDDLE);
            nvgText(nvg, t->x, t->y + t->h * 0.5f, t->string, &t->string[t->length]);
            nvgFill(nvg);
        } break;
        case ZR_COMMAND_IMAGE: {
            const struct zr_command_image *i = zr_command(image, cmd);
            NVGpaint imgpaint;
            imgpaint = nvgImagePattern(nvg, i->x, i->y, i->w, i->h, 0, i->img.handle.id, 1.0f);
            nvgBeginPath(nvg);
            nvgRoundedRect(nvg, i->x, i->y, i->w, i->h, 0);
            nvgFillPaint(nvg, imgpaint);
            nvgFill(nvg);
        } break;
        case ZR_COMMAND_ARC:
        default: break;
        }
    }
    zr_command_queue_clear(queue);

    nvgResetScissor(nvg);
    nvgEndFrame(nvg);
    glPopAttrib();
}
Пример #6
0
void Shape::render(NVGcontext& nanoVgContext) const
{
    switch(mType)
    {
        case Type::ARC:
        {
            const ArcInfo& info = mArcInfo;
            const Point& position = info.position;
            nvgArc(&nanoVgContext, position.getX(), position.getY(), info.radius, info.startAngle,
                    info.endAngle, info.clockWise ? NVG_CW : NVG_CCW);
        }
        break;

        case Type::TRIANGLE:
        {
            const TriangleInfo& info = mTriangleInfo;
            nvgMoveTo(&nanoVgContext, info.firstVertex.getX(), info.firstVertex.getY());
            nvgLineTo(&nanoVgContext, info.secondVertex.getX(), info.secondVertex.getY());
            nvgLineTo(&nanoVgContext, info.thirdVertex.getX(), info.thirdVertex.getY());
            nvgClosePath(&nanoVgContext);
        }
        break;

        case Type::RECT:
        {
            const RectInfo& info = mRectInfo;
            const Rect& rect = info.rect;

            if(info.rounded)
            {
                nvgRoundedRect(&nanoVgContext, rect.getX(), rect.getY(), rect.getWidth(),
                        rect.getHeight(), info.cornerRadius);
            }
            else
            {
                nvgRect(&nanoVgContext, rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
            }
        }
        break;

        case Type::ELLIPSE:
        {
            const EllipseInfo& info = mEllipseInfo;
            const Point& position = info.position;
            nvgEllipse(&nanoVgContext, position.getX(), position.getY(), info.horizontalRadius,
                    info.verticalRadius);
        }
        break;

        case Type::MOVE_TO:
        {
            const MoveToInfo& info = mMoveToInfo;
            const Point& position = info.position;
            nvgMoveTo(&nanoVgContext, position.getX(), position.getY());
        }
        break;

        case Type::LINE_TO:
        {
            const LineToInfo& info = mLineToInfo;
            const Point& position = info.position;
            nvgLineTo(&nanoVgContext, position.getX(), position.getY());
        }
        break;

        case Type::BEZIER_TO:
        {
            const BezierToInfo& info = mBezierToInfo;
            const Point& control1 = info.controlPosition1;
            const Point& control2 = info.controlPosition2;
            const Point& position = info.position;
            nvgBezierTo(&nanoVgContext, control1.getX(), control1.getY(), control2.getX(),
                    control2.getY(), position.getX(), position.getY());
        }
        break;

        case Type::QUAD_TO:
        {
            const QuadToInfo& info = mQuadToInfo;
            const Point& control = info.controlPosition;
            const Point& position = info.position;
            nvgQuadTo(&nanoVgContext, control.getX(), control.getY(), position.getX(), position.getY());
        }
        break;

        case Type::CLOSE_PATH:
        {
            nvgClosePath(&nanoVgContext);
        }
        break;

        default:
            return;
    }
}
Пример #7
0
JNIEXPORT void JNICALL Java_firststep_internal_NVG_bezierTo
  (JNIEnv *e, jclass c, jlong ctx, jfloat c1x, jfloat c1y, jfloat c2x, jfloat c2y, jfloat x, jfloat y)
{
	nvgBezierTo((NVGcontext*)ctx, c1x,c1y, c2x,c2y, x,y);
}
Пример #8
0
void VectorRenderer::cubicCurveTo(float c1x, float c1y, float c2x, float c2y, float x, float y) {
	nvgBezierTo(nvg, c1x, c1y, c2x, c2y, x, y);
}