Ejemplo n.º 1
0
        static void DrawSlider(NanoVGContext vg, float pos, float x, float y, float w, float h)
        {
            NVGPaint bg, knob;
            float    cy = y + (int)(h * 0.5f);
            float    kr = (int)(h * 0.25f);

            NVG.Save(vg);
            //	NVG.ClearState(vg);

            // Slot
            bg = NVG.BoxGradient(vg, x, cy - 2 + 1, w, 4, 2, 2, NVG.RGBA(0, 0, 0, 32), NVG.RGBA(0, 0, 0, 128));
            NVG.BeginPath(vg);
            NVG.RoundedRect(vg, x, cy - 2, w, 4, 2);
            NVG.FillPaint(vg, bg);
            NVG.Fill(vg);

            // Knob Shadow
            bg = NVG.RadialGradient(vg, x + (int)(pos * w), cy + 1, kr - 3, kr + 3, NVG.RGBA(0, 0, 0, 64), NVG.RGBA(0, 0, 0, 0));
            NVG.BeginPath(vg);
            NVG.Rect(vg, x + (int)(pos * w) - kr - 5, cy - kr - 5, kr * 2 + 5 + 5, kr * 2 + 5 + 5 + 3);
            NVG.Circle(vg, x + (int)(pos * w), cy, kr);
            NVG.PathWinding(vg, NVGSolidity.NVG_HOLE);
            NVG.FillPaint(vg, bg);
            NVG.Fill(vg);

            // Knob
            knob = NVG.LinearGradient(vg, x, cy - kr, x, cy + kr, NVG.RGBA(255, 255, 255, 16), NVG.RGBA(0, 0, 0, 16));
            NVG.BeginPath(vg);
            NVG.Circle(vg, x + (int)(pos * w), cy, kr - 1);
            NVG.FillColor(vg, NVG.RGBA(40, 43, 48, 255));
            NVG.Fill(vg);
            NVG.FillPaint(vg, knob);
            NVG.Fill(vg);

            NVG.BeginPath(vg);
            NVG.Circle(vg, x + (int)(pos * w), cy, kr - 0.5f);
            NVG.StrokeColor(vg, NVG.RGBA(0, 0, 0, 92));
            NVG.Stroke(vg);

            NVG.Restore(vg);
        }
Ejemplo n.º 2
0
        static void DrawColorWheel(NanoVGContext vg, float x, float y, float w, float h, float t)
        {
            int      i;
            float    r0, r1, ax, ay, bx, by, cx, cy, aeps, r;
            float    hue = (float)Math.Sin(t * 0.12f);
            NVGPaint paint;

            NVG.Save(vg);

            cx   = x + w * 0.5f;
            cy   = y + h * 0.5f;
            r1   = (w < h ? w : h) * 0.5f - 5.0f;
            r0   = r1 - 20.0f;
            aeps = 0.5f / r1;               // half a pixel arc length in radians (2pi cancels out).

            for (i = 0; i < 6; i++)
            {
                float a0 = (float)i / 6.0f * (float)Math.PI * 2.0f - aeps;
                float a1 = (float)(i + 1.0f) / 6.0f * (float)Math.PI * 2.0f + aeps;
                NVG.BeginPath(vg);
                NVG.Arc(vg, cx, cy, r0, a0, a1, NVGWinding.NVG_CW);
                NVG.Arc(vg, cx, cy, r1, a1, a0, NVGWinding.NVG_CCW);
                NVG.ClosePath(vg);
                ax    = cx + (float)Math.Cos(a0) * (r0 + r1) * 0.5f;
                ay    = cy + (float)Math.Sin(a0) * (r0 + r1) * 0.5f;
                bx    = cx + (float)Math.Cos(a1) * (r0 + r1) * 0.5f;
                by    = cy + (float)Math.Sin(a1) * (r0 + r1) * 0.5f;
                paint = NVG.LinearGradient(vg, ax, ay, bx, by, NVG.HSLA(a0 / ((float)Math.PI * 2), 1.0f, 0.55f, 255), NVG.HSLA(a1 / ((float)Math.PI * 2), 1.0f, 0.55f, 255));
                NVG.FillPaint(vg, paint);
                NVG.Fill(vg);
            }

            NVG.BeginPath(vg);
            NVG.Circle(vg, cx, cy, r0 - 0.5f);
            NVG.Circle(vg, cx, cy, r1 + 0.5f);
            NVG.StrokeColor(vg, NVG.RGBA(0, 0, 0, 64));
            NVG.StrokeWidth(vg, 1.0f);
            NVG.Stroke(vg);

            // Selector
            NVG.Save(vg);
            NVG.Translate(vg, cx, cy);
            NVG.Rotate(vg, hue * (float)Math.PI * 2);

            // Marker on
            NVG.StrokeWidth(vg, 2.0f);
            NVG.BeginPath(vg);
            NVG.Rect(vg, r0 - 1, -3, r1 - r0 + 2, 6);
            NVG.StrokeColor(vg, NVG.RGBA(255, 255, 255, 192));
            NVG.Stroke(vg);

            paint = NVG.BoxGradient(vg, r0 - 3, -5, r1 - r0 + 6, 10, 2, 4, NVG.RGBA(0, 0, 0, 128), NVG.RGBA(0, 0, 0, 0));
            NVG.BeginPath(vg);
            NVG.Rect(vg, r0 - 2 - 10, -4 - 10, r1 - r0 + 4 + 20, 8 + 20);
            NVG.Rect(vg, r0 - 2, -4, r1 - r0 + 4, 8);
            NVG.PathWinding(vg, NVGSolidity.NVG_HOLE);
            NVG.FillPaint(vg, paint);
            NVG.Fill(vg);

            // Center triangle
            r  = r0 - 6;
            ax = (float)Math.Cos(120.0f / 180.0f * (float)Math.PI) * r;
            ay = (float)Math.Sin(120.0f / 180.0f * (float)Math.PI) * r;
            bx = (float)Math.Cos(-120.0f / 180.0f * (float)Math.PI) * r;
            by = (float)Math.Sin(-120.0f / 180.0f * (float)Math.PI) * r;
            NVG.BeginPath(vg);
            NVG.MoveTo(vg, r, 0);
            NVG.LineTo(vg, ax, ay);
            NVG.LineTo(vg, bx, by);
            NVG.ClosePath(vg);
            paint = NVG.LinearGradient(vg, r, 0, ax, ay, NVG.HSLA(hue, 1.0f, 0.5f, 255), NVG.RGBA(255, 255, 255, 255));
            NVG.FillPaint(vg, paint);
            NVG.Fill(vg);
            paint = NVG.LinearGradient(vg, (r + ax) * 0.5f, (0 + ay) * 0.5f, bx, by, NVG.RGBA(0, 0, 0, 0), NVG.RGBA(0, 0, 0, 255));
            NVG.FillPaint(vg, paint);
            NVG.Fill(vg);
            NVG.StrokeColor(vg, NVG.RGBA(0, 0, 0, 64));
            NVG.Stroke(vg);

            // Select circle on triangle
            ax = (float)Math.Cos(120.0f / 180.0f * (float)Math.PI) * r * 0.3f;
            ay = (float)Math.Sin(120.0f / 180.0f * (float)Math.PI) * r * 0.4f;
            NVG.StrokeWidth(vg, 2.0f);
            NVG.BeginPath(vg);
            NVG.Circle(vg, ax, ay, 5);
            NVG.StrokeColor(vg, NVG.RGBA(255, 255, 255, 192));
            NVG.Stroke(vg);

            paint = NVG.RadialGradient(vg, ax, ay, 7, 9, NVG.RGBA(0, 0, 0, 64), NVG.RGBA(0, 0, 0, 0));
            NVG.BeginPath(vg);
            NVG.Rect(vg, ax - 20, ay - 20, 40, 40);
            NVG.Circle(vg, ax, ay, 7);
            NVG.PathWinding(vg, NVGSolidity.NVG_HOLE);
            NVG.FillPaint(vg, paint);
            NVG.Fill(vg);

            NVG.Restore(vg);

            NVG.Restore(vg);
        }
Ejemplo n.º 3
0
        static void DrawGraph(NanoVGContext vg, float x, float y, float w, float h, float t)
        {
            NVGPaint bg;

            float[] samples = new float[6];
            float[] sx      = new float[6], sy = new float[6];
            float   dx      = w / 5.0f;
            int     i;

            samples[0] = (1 + (float)Math.Sin(t * 1.2345f + Math.Cos(t * 0.33457f) * 0.44f)) * 0.5f;
            samples[1] = (1 + (float)Math.Sin(t * 0.68363f + Math.Cos(t * 1.3f) * 1.55f)) * 0.5f;
            samples[2] = (1 + (float)Math.Sin(t * 1.1642f + Math.Cos(t * 0.33457) * 1.24f)) * 0.5f;
            samples[3] = (1 + (float)Math.Sin(t * 0.56345f + Math.Cos(t * 1.63f) * 0.14f)) * 0.5f;
            samples[4] = (1 + (float)Math.Sin(t * 1.6245f + Math.Cos(t * 0.254f) * 0.3f)) * 0.5f;
            samples[5] = (1 + (float)Math.Sin(t * 0.345f + Math.Cos(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 = NVG.LinearGradient(vg, x, y, x, y + h, NVG.RGBA(0, 160, 192, 0), NVG.RGBA(0, 160, 192, 64));
            NVG.BeginPath(vg);
            NVG.MoveTo(vg, sx[0], sy[0]);
            for (i = 1; i < 6; i++)
            {
                NVG.BezierTo(vg, sx[i - 1] + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i]);
            }
            NVG.LineTo(vg, x + w, y + h);
            NVG.LineTo(vg, x, y + h);
            NVG.FillPaint(vg, bg);
            NVG.Fill(vg);

            // Graph line
            NVG.BeginPath(vg);
            NVG.MoveTo(vg, sx[0], sy[0] + 2);
            for (i = 1; i < 6; i++)
            {
                NVG.BezierTo(vg, sx[i - 1] + dx * 0.5f, sy[i - 1] + 2, sx[i] - dx * 0.5f, sy[i] + 2, sx[i], sy[i] + 2);
            }
            NVG.StrokeColor(vg, NVG.RGBA(0, 0, 0, 32));
            NVG.StrokeWidth(vg, 3.0f);
            NVG.Stroke(vg);

            NVG.BeginPath(vg);
            NVG.MoveTo(vg, sx[0], sy[0]);
            for (i = 1; i < 6; i++)
            {
                NVG.BezierTo(vg, sx[i - 1] + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i]);
            }
            NVG.StrokeColor(vg, NVG.RGBA(0, 160, 192, 255));
            NVG.StrokeWidth(vg, 3.0f);
            NVG.Stroke(vg);

            // Graph sample pos
            for (i = 0; i < 6; i++)
            {
                bg = NVG.RadialGradient(vg, sx[i], sy[i] + 2, 3.0f, 8.0f, NVG.RGBA(0, 0, 0, 32), NVG.RGBA(0, 0, 0, 0));
                NVG.BeginPath(vg);
                NVG.Rect(vg, sx[i] - 10, sy[i] - 10 + 2, 20, 20);
                NVG.FillPaint(vg, bg);
                NVG.Fill(vg);
            }

            NVG.BeginPath(vg);
            for (i = 0; i < 6; i++)
            {
                NVG.Circle(vg, sx[i], sy[i], 4.0f);
            }
            NVG.FillColor(vg, NVG.RGBA(0, 160, 192, 255));
            NVG.Fill(vg);
            NVG.BeginPath(vg);
            for (i = 0; i < 6; i++)
            {
                NVG.Circle(vg, sx[i], sy[i], 2.0f);
            }
            NVG.FillColor(vg, NVG.RGBA(220, 220, 220, 255));
            NVG.Fill(vg);

            NVG.StrokeWidth(vg, 1.0f);
        }
Ejemplo n.º 4
0
        static void DrawEyes(NanoVGContext vg, float x, float y, float w, float h, float mx, float my, float t)
        {
            NVGPaint gloss, bg;
            float    ex = w * 0.23f;
            float    ey = h * 0.5f;
            float    lx = x + ex;
            float    ly = y + ey;
            float    rx = x + w - ex;
            float    ry = y + ey;
            float    dx, dy, d;
            float    br    = (ex < ey ? ex : ey) * 0.5f;
            float    blink = 1 - (float)(Math.Pow(Math.Sin(t * 0.5f), 200) * 0.8f);

            bg = NVG.LinearGradient(vg, x, y + h * 0.5f, x + w * 0.1f, y + h, NVG.RGBA(0, 0, 0, 32), NVG.RGBA(0, 0, 0, 16));
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, lx + 3.0f, ly + 16.0f, ex, ey);
            NVG.Ellipse(vg, rx + 3.0f, ry + 16.0f, ex, ey);
            NVG.FillPaint(vg, bg);
            NVG.Fill(vg);

            bg = NVG.LinearGradient(vg, x, y + h * 0.25f, x + w * 0.1f, y + h, NVG.RGBA(220, 220, 220, 255), NVG.RGBA(128, 128, 128, 255));
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, lx, ly, ex, ey);
            NVG.Ellipse(vg, rx, ry, ex, ey);
            NVG.FillPaint(vg, bg);
            NVG.Fill(vg);

            dx = (mx - rx) / (ex * 10);
            dy = (my - ry) / (ey * 10);
            d  = (float)Math.Sqrt(dx * dx + dy * dy);
            if (d > 1.0f)
            {
                dx /= d; dy /= d;
            }
            dx *= ex * 0.4f;
            dy *= ey * 0.5f;
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, lx + dx, ly + dy + ey * 0.25f * (1 - blink), br, br * blink);
            NVG.FillColor(vg, NVG.RGBA(32, 32, 32, 255));
            NVG.Fill(vg);

            dx = (mx - rx) / (ex * 10);
            dy = (my - ry) / (ey * 10);
            d  = (float)Math.Sqrt(dx * dx + dy * dy);
            if (d > 1.0f)
            {
                dx /= d; dy /= d;
            }
            dx *= ex * 0.4f;
            dy *= ey * 0.5f;
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, rx + dx, ry + dy + ey * 0.25f * (1 - blink), br, br * blink);
            NVG.FillColor(vg, NVG.RGBA(32, 32, 32, 255));
            NVG.Fill(vg);

            gloss = NVG.RadialGradient(vg, lx - ex * 0.25f, ly - ey * 0.5f, ex * 0.1f, ex * 0.75f, NVG.RGBA(255, 255, 255, 128), NVG.RGBA(255, 255, 255, 0));
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, lx, ly, ex, ey);
            NVG.FillPaint(vg, gloss);
            NVG.Fill(vg);

            gloss = NVG.RadialGradient(vg, rx - ex * 0.25f, ry - ey * 0.5f, ex * 0.1f, ex * 0.75f, NVG.RGBA(255, 255, 255, 128), NVG.RGBA(255, 255, 255, 0));
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, rx, ry, ex, ey);
            NVG.FillPaint(vg, gloss);
            NVG.Fill(vg);
        }