Exemple #1
0
        public static void drawScissor(NvgContext vg, float x, float y, float t)
        {
            vg.Save();

            // Draw first rect and set scissor to it's area.
            vg.Translate(x, y);
            vg.Rotate(NvgUtility.DegToRad(5));
            vg.BeginPath();
            vg.Rect(-20, -20, 60, 40);
            vg.FillColor(new Color(255, 0, 0, 255));
            vg.Fill();
            vg.Scissor(-20, -20, 60, 40);

            // Draw second rectangle with offset and rotation.
            vg.Translate(40, 0);
            vg.Rotate(t);

            // Draw the intended second rectangle without any scissoring.
            vg.Save();
            vg.ResetScissor();
            vg.BeginPath();
            vg.Rect(-20, -10, 60, 30);
            vg.FillColor(new Color(255, 128, 0, 64));
            vg.Fill();
            vg.Restore();

            // Draw second rectangle with combined scissoring.
            vg.IntersectScissor(-20, -10, 60, 30);
            vg.BeginPath();
            vg.Rect(-20, -10, 60, 30);
            vg.FillColor(new Color(255, 128, 0, 255));
            vg.Fill();

            vg.Restore();
        }
Exemple #2
0
        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();
        }