示例#1
0
文件: Demo.cs 项目: rds1983/NvgSharp
        public static void drawSlider(NvgContext vg, float pos, float x, float y, float w, float h)
        {
            Paint bg, knob;
            float cy = y + (int)(h * 0.5f);
            float kr = (int)(h * 0.25f);

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

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

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

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

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

            vg.Restore();
        }
示例#2
0
        /// <inheritdoc />
        protected override void OnPaint(object sender, NvgContext e)
        {
            base.OnPaint(sender, e);

            e.BeginPath();
            e.Circle(ClientLocation.X + Size.Width / 2f, ClientLocation.Y + Size.Height / 2f, Size.Width / 2f);

            e.FillColor(Lit ? NanoVg.Rgba(ActiveColor) : NanoVg.Rgba(0xFF475054));
            e.Fill();

            e.StrokeColor(NanoVg.Rgba(0xFF192025));
            e.Stroke();
        }
        /// <inheritdoc />
        protected override void OnPaint(object sender, NvgContext e)
        {
            base.OnPaint(sender, e);

            e.BeginPath();
            e.Circle(ClientLocation.X + 7, ClientLocation.Y + 7, 7);

            e.FillColor(Checked ? NanoVg.Rgba(ActiveColor) : NanoVg.Rgba(0xFF475054));
            e.Fill();

            e.StrokeColor(NanoVg.Rgba(0xFF192025));
            e.Stroke();

            e.FillColor(NanoVg.Rgba(ForeColor));
            e.FontFace(Font.Family);
            e.FontSize(Font.Size);
            e.TextAlign(NvgAlign.Left | NvgAlign.Middle);
            e.Text(ClientLocation.X + 18, ClientLocation.Y + 7.5f, Text);
        }
示例#4
0
文件: Demo.cs 项目: rds1983/NvgSharp
        public static void drawColorwheel(NvgContext vg, float x, float y, float w, float h, float t)
        {
            int   i;
            float r0, r1, ax, ay, bx, by, cx, cy, aeps, r;
            float hue = (float)Math.Sin(t * 0.12f);
            Paint paint;

            vg.Save();

            /*	vg.BeginPath();
             *      vg.Rect(x,y,w,h);
             *      vg.FillColor(new Color(255,0,0,128));
             *      vg.Fill();*/

            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;
                vg.BeginPath();
                vg.Arc(cx, cy, r0, a0, a1, Winding.ClockWise);
                vg.Arc(cx, cy, r1, a1, a0, Winding.CounterClockWise);
                vg.ClosePath();
                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 = vg.LinearGradient(ax, ay, bx, by, NvgUtility.HSLA(a0 / ((float)Math.PI * 2), 1.0f, 0.55f, 255), NvgUtility.HSLA(a1 / ((float)Math.PI * 2), 1.0f, 0.55f, 255));
                vg.FillPaint(paint);
                vg.Fill();
            }

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

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

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

            paint = vg.BoxGradient(r0 - 3, -5, r1 - r0 + 6, 10, 2, 4, new Color(0, 0, 0, 128), new Color(0, 0, 0, 0));
            vg.BeginPath();
            vg.Rect(r0 - 2 - 10, -4 - 10, r1 - r0 + 4 + 20, 8 + 20);
            vg.Rect(r0 - 2, -4, r1 - r0 + 4, 8);
            vg.PathWinding(Solidity.Hole);
            vg.FillPaint(paint);
            vg.Fill();

            // 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;
            vg.BeginPath();
            vg.MoveTo(r, 0);
            vg.LineTo(ax, ay);
            vg.LineTo(bx, by);
            vg.ClosePath();
            paint = vg.LinearGradient(r, 0, ax, ay, NvgUtility.HSLA(hue, 1.0f, 0.5f, 255), new Color(255, 255, 255, 255));
            vg.FillPaint(paint);
            vg.Fill();
            paint = vg.LinearGradient((r + ax) * 0.5f, (0 + ay) * 0.5f, bx, by, new Color(0, 0, 0, 0), new Color(0, 0, 0, 255));
            vg.FillPaint(paint);
            vg.Fill();
            vg.StrokeColor(new Color(0, 0, 0, 64));
            vg.Stroke();

            // 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;
            vg.StrokeWidth(2.0f);
            vg.BeginPath();
            vg.Circle(ax, ay, 5);
            vg.StrokeColor(new Color(255, 255, 255, 192));
            vg.Stroke();

            paint = vg.RadialGradient(ax, ay, 7, 9, new Color(0, 0, 0, 64), new Color(0, 0, 0, 0));
            vg.BeginPath();
            vg.Rect(ax - 20, ay - 20, 40, 40);
            vg.Circle(ax, ay, 7);
            vg.PathWinding(Solidity.Hole);
            vg.FillPaint(paint);
            vg.Fill();

            vg.Restore();

            vg.Restore();
        }
示例#5
0
文件: Demo.cs 项目: rds1983/NvgSharp
        public static void drawGraph(NvgContext vg, float x, float y, float w, float h, float t)
        {
            Paint 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 + (float)Math.Cos(t * 0.33457f) * 0.44f)) * 0.5f;
            samples[1] = (1 + (float)Math.Sin(t * 0.68363f + (float)Math.Cos(t * 1.3f) * 1.55f)) * 0.5f;
            samples[2] = (1 + (float)Math.Sin(t * 1.1642f + (float)Math.Cos(t * 0.33457) * 1.24f)) * 0.5f;
            samples[3] = (1 + (float)Math.Sin(t * 0.56345f + (float)Math.Cos(t * 1.63f) * 0.14f)) * 0.5f;
            samples[4] = (1 + (float)Math.Sin(t * 1.6245f + (float)Math.Cos(t * 0.254f) * 0.3f)) * 0.5f;
            samples[5] = (1 + (float)Math.Sin(t * 0.345f + (float)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 = vg.LinearGradient(x, y, x, y + h, new Color(0, 160, 192, 0), new Color(0, 160, 192, 64));
            vg.BeginPath();
            vg.MoveTo(sx[0], sy[0]);
            for (i = 1; i < 6; i++)
            {
                vg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i]);
            }
            vg.LineTo(x + w, y + h);
            vg.LineTo(x, y + h);
            vg.FillPaint(bg);
            vg.Fill();

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

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

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

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

            vg.StrokeWidth(1.0f);
        }