コード例 #1
0
ファイル: Demo.cs プロジェクト: MatijaBrown/SilkyNvg
        private void DrawColourwheel(float x, float y, float w, float h, float t)
        {
            float hue = MathF.Sin(t * 0.12f);

            _nvg.Save();

            float cx   = x + w * 0.5f;
            float cy   = y + h * 0.5f;
            float r1   = (w < h ? w : h) * 0.5f - 5.0f;
            float r0   = r1 - 20.0f;
            float aeps = 0.5f / r1;

            Paint paint;
            float ax, ay, bx, by;

            for (int i = 0; i < 6; i++)
            {
                float a0 = (float)i / 6.0f * MathF.PI * 2.0f - aeps;
                float a1 = (float)(i + 1.0f) / 6.0f * MathF.PI * 2.0f + aeps;
                _nvg.BeginPath();
                _nvg.Arc(cx, cy, r0, a0, a1, Winding.Cw);
                _nvg.Arc(cx, cy, r1, a1, a0, Winding.Ccw);
                _nvg.ClosePath();
                ax    = cx + MathF.Cos(a0) * (r0 + 1) * 0.5f;
                ay    = cy + MathF.Sin(a0) * (r0 + 1) * 0.5f;
                bx    = cx + MathF.Cos(a1) * (r0 + 1) * 0.5f;
                by    = cy + MathF.Sin(a1) * (r0 + 1) * 0.5f;
                paint = _nvg.LinearGradient(ax, ay, bx, by, _nvg.Hsla(a0 / (MathF.PI * 2), 1.0f, 0.55f, 255), _nvg.Hsla(a1 / (MathF.PI * 2), 1.0f, 0.55f, 255));
                _nvg.FillPaint(paint);
                _nvg.Fill();
            }

            _nvg.BeginPath();
            _nvg.Circle(cx, cy, r0 - 0.5f);
            _nvg.Circle(cx, cy, r1 + 0.5f);
            _nvg.StrokeColour(new Colour(0, 0, 0, 64));
            _nvg.StrokeWidth(1.0f);
            _nvg.Stroke();

            _nvg.Save();
            _nvg.Translate(cx, cy);
            _nvg.Rotate(hue * MathF.PI * 2);

            _nvg.StrokeWidth(2.0f);
            _nvg.BeginPath();
            _nvg.Rect(r0 - 1, -3, r1 - r0 + 2, 6);
            _nvg.StrokeColour(new Colour(255, 255, 255, 255));
            _nvg.Stroke();

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

            float r = r0 - 6;

            ax = MathF.Cos(120.0f / 180.0f * MathF.PI) * r;
            ay = MathF.Sin(120.0f / 180.0f * MathF.PI) * r;
            bx = MathF.Cos(-120.0f / 180.0f * MathF.PI) * r;
            by = MathF.Sin(-120.0f / 180.0f * MathF.PI) * r;
            _nvg.BeginPath();
            _nvg.MoveTo(r, 0);
            _nvg.LineTo(ax, ay);
            _nvg.LineTo(bx, by);
            _nvg.ClosePath();
            paint = _nvg.LinearGradient(r, 0, ax, ay, _nvg.Hsla(hue, 1.0f, 0.5f, 255), _nvg.Rgba(255, 255, 255, 255));
            _nvg.FillPaint(paint);
            _nvg.Fill();
            paint = _nvg.LinearGradient((r + ax) * 0.5f, (0 + ay) * 0.5f, bx, by, new Colour(0, 0, 0, 0), new Colour(0, 0, 0, 255));
            _nvg.FillPaint(paint);
            _nvg.Fill();
            _nvg.StrokeColour(new Colour(0, 0, 0, 64));
            _nvg.Stroke();

            ax = MathF.Cos(120.0f / 180.0f * MathF.PI) * r * 0.3f;
            ay = MathF.Sin(120.0f / 180.0f * MathF.PI) * r * 0.4f;
            _nvg.StrokeWidth(2.0f);
            _nvg.BeginPath();
            _nvg.Circle(ax, ay, 5);
            _nvg.StrokeColour(new Colour(255, 255, 255, 192));
            _nvg.Stroke();

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

            _nvg.Restore();
            _nvg.Restore();
        }