예제 #1
0
        public override void DrawPie(double fraction)
        {
            // Calculate the pie path
            fraction = Theme.Clamp(0.0, 1.0, fraction);
            double a1 = 3.0 * Math.PI / 2.0;
            double a2 = a1 + 2.0 * Math.PI * fraction;

            if (fraction == 0.0)
            {
                return;
            }

            Context.Cairo.MoveTo(Context.X, Context.Y);
            Context.Cairo.Arc(Context.X, Context.Y, Context.Radius, a1, a2);
            Context.Cairo.LineTo(Context.X, Context.Y);

            // Fill the pie
            Color color_a = Colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected);
            Color color_b = CairoExtensions.ColorShade(color_a, 1.4);

            var fill = new RadialGradient(Context.X, Context.Y, 0,
                                          Context.X, Context.Y, 2.0 * Context.Radius);

            fill.AddColorStop(0, color_a);
            fill.AddColorStop(1, color_b);
            Context.Cairo.SetSource(fill);

            Context.Cairo.FillPreserve();
            fill.Dispose();

            // Stroke the pie
            Context.Cairo.SetSourceColor(CairoExtensions.ColorShade(color_a, 0.8));
            Context.Cairo.LineWidth = Context.LineWidth;
            Context.Cairo.Stroke();
        }
예제 #2
0
        private void gradientToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lastSelected  = "gradient";
            OnPaintAction = cr =>
            {
                Gradient pat = new LinearGradient(0.0, 0.0, 0.0, 256.0);
                pat.AddColorStopRgba(1, 0, 0, 0, 1);
                pat.AddColorStopRgba(0, 1, 1, 1, 1);
                cr.Rectangle(0, 0, 256, 256);
                cr.SetSource(pat);
                cr.Fill();
                pat.Dispose();

                pat = new RadialGradient(115.2, 102.4, 25.6,
                                         102.4, 102.4, 128.0);
                pat.AddColorStopRgba(0, 1, 1, 1, 1);
                pat.AddColorStopRgba(1, 0, 0, 0, 1);
                cr.SetSource(pat);
                cr.Arc(128.0, 128.0, 76.8, 0, 2 * Math.PI);
                cr.Fill();
                pat.Dispose();
            };

            Invalidate();
        }
예제 #3
0
        //---------------------------------------------------------------------
        private static void Gradient()
        {
            Action <Surface> draw = surface =>
            {
                using (var c = new Context(surface))
                {
                    Gradient pat = new LinearGradient(0.0, 0.0, 0.0, 256.0);
                    pat.AddColorStopRgba(1, 0, 0, 0, 1);
                    pat.AddColorStopRgba(0, 1, 1, 1, 1);
                    c.Rectangle(0, 0, 256, 256);
                    c.SetSource(pat);
                    c.Fill();
                    pat.Dispose();

                    pat = new RadialGradient(115.2, 102.4, 25.6,
                                             102.4, 102.4, 128.0);
                    pat.AddColorStopRgba(0, 1, 1, 1, 1);
                    pat.AddColorStopRgba(1, 0, 0, 0, 1);
                    c.SetSource(pat);
                    c.Arc(128.0, 128.0, 76.8, 0, 2 * Math.PI);
                    c.Fill();
                    pat.Dispose();
                }
            };

            using (Surface surface = new ImageSurface(Format.Argb32, 500, 500))
            {
                draw(surface);
                surface.WriteToPng("gradient.png");
            }

            using (Surface surface = new PdfSurface("gradient.pdf", 500, 500))
            {
                draw(surface);
                surface.WriteToPng("gradient1.png");
            }

            using (Surface surface = new SvgSurface("gradient.svg", 500, 500))
            {
                draw(surface);
                surface.WriteToPng("gradient2.png");
            }
        }
예제 #4
0
        void DrawLed(int index, Context cr)
        {
            PointD led = new PointD();

            led.X = imageX + CurrentDefinition.Leds[index].X / scale;
            led.Y = imageY + CurrentDefinition.Leds[index].Y / scale;
            double         glowRadius = LedSize * 2 / scale;
            RadialGradient gradient   = new RadialGradient(led.X, led.Y, 0, led.X, led.Y, glowRadius);

            gradient.AddColorStop(0, new Cairo.Color(ColorBuffer[index].Red, ColorBuffer[index].Green, ColorBuffer[index].Blue, ColorBuffer[index].Alpha));
            gradient.AddColorStop(0.15, new Cairo.Color(ColorBuffer[index].Red, ColorBuffer[index].Green, ColorBuffer[index].Blue, ColorBuffer[index].Alpha));
            gradient.AddColorStop(1, new Cairo.Color(ColorBuffer[index].Red, ColorBuffer[index].Green, ColorBuffer[index].Blue, 0));
            cr.Save();
            cr.Rectangle(led.X - glowRadius, led.Y - glowRadius, glowRadius * 2, glowRadius * 2);
            cr.Clip();
            cr.SetSource(gradient);
            cr.Mask(gradient);
            cr.Restore();
            gradient.Dispose();
        }