Ejemplo n.º 1
0
        private Pattern CreateMask()
        {
            double max   = Math.Max(blur.Bounds.Width, blur.Bounds.Height) * .25;
            double scale = blur.Bounds.Width / (double)info.Bounds.Width;

            RadialGradient circle;

            // FIXME ugh cairo 1.0.2 is so broken why are we still shipping it.
            if (CairoAPI.cairo_version() > (1 * 10000 + 2 * 100 + 0))
            {
                circle = new RadialGradient(center.X * scale, center.Y * scale, radius * max * .7,
                                            center.X * scale, center.Y * scale, radius * max + max * .2);

                circle.AddColorStop(0, new Cairo.Color(0.0, 0.0, 0.0, 0.0));
                circle.AddColorStop(1.0, new Cairo.Color(1.0, 1.0, 1.0, 1.0));
            }
            else
            {
                circle = new RadialGradient(center.X * scale, center.Y * scale, radius * max + max * .2,
                                            center.X * scale, center.Y * scale, radius * max * .7);

                circle.AddColorStop(1.0, new Cairo.Color(0.0, 0.0, 0.0, 0.0));
                circle.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0));
            }
            return(circle);
        }
Ejemplo n.º 2
0
        protected override void OnSizeAllocated(Gdk.Rectangle rect)
        {
            x               = rect.Width / 2.0;
            y               = rect.Height / 2.0;
            radius          = Math.Min(rect.Width / 2, rect.Height / 2) - 5;
            base_line_width = Math.Sqrt(radius) * 0.2;

            bg_gradient = new RadialGradient(x, y, 0, x, y, radius);
            bg_gradient.AddColorStop(0, disc_color_a);
            bg_gradient.AddColorStop(1, disc_color_b);

            fg_gradient = new RadialGradient(x, y, 0, x, y, radius * 2);
            fg_gradient.AddColorStop(0, fill_color_a);
            fg_gradient.AddColorStop(1, fill_color_b);

            fg_gradient_full = new RadialGradient(x, y, 0, x, y, radius);
            fg_gradient_full.AddColorStop(0, disc_color_b);
            fg_gradient_full.AddColorStop(1, red_color);

            bound_gradient = new RadialGradient(x, y, 0, x, y, radius * 2);
            bound_gradient.AddColorStop(0, bound_color_a);
            bound_gradient.AddColorStop(1, bound_color_b);

            base.OnSizeAllocated(rect);
        }
Ejemplo n.º 3
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);

            using (RadialGradient 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();
            }

            // Stroke the pie
            Context.Cairo.SetSourceColor(CairoExtensions.ColorShade(color_a, 0.8));
            Context.Cairo.LineWidth = Context.LineWidth;
            Context.Cairo.Stroke();
        }
Ejemplo n.º 4
0
        protected override void PaintIconSurface(DockySurface surface)
        {
            surface.Context.LineWidth = 1;
            surface.Context.MoveTo((surface.Width / 2) - 0.5, 0);
            surface.Context.LineTo((surface.Width / 2) - 0.5, surface.Height);

            RadialGradient rg = new RadialGradient(surface.Width / 2, surface.Height / 2, 0, surface.Width / 2, surface.Height / 2, surface.Height / 2);

            rg.AddColorStop(0, new Cairo.Color(1, 1, 1, .5));
            rg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0));

            surface.Context.Pattern = rg;
            surface.Context.Stroke();
            rg.Destroy();

            surface.Context.MoveTo((surface.Width / 2) + 0.5, 0);
            surface.Context.LineTo((surface.Width / 2) + 0.5, surface.Height);

            rg = new RadialGradient(surface.Width / 2, surface.Height / 2, 0, surface.Width / 2, surface.Height / 2, surface.Height / 2);
            rg.AddColorStop(0, new Cairo.Color(0, 0, 0, 0.5));
            rg.AddColorStop(1, new Cairo.Color(0, 0, 0, 0));

            surface.Context.Pattern = rg;
            surface.Context.Stroke();
            rg.Destroy();
        }
Ejemplo n.º 5
0
        //---------------------------------------------------------------------
        private static void Mask()
        {
            Action <Surface> draw = surface =>
            {
                using (var ctx = new Context(surface))
                {
                    ctx.Scale(500, 500);

                    Gradient linpat = new LinearGradient(0, 0, 1, 1);
                    linpat.AddColorStop(0, new Color(0, 0.3, 0.8));
                    linpat.AddColorStop(1, new Color(1, 0.8, 0.3));

                    Gradient radpat = new RadialGradient(0.5, 0.5, 0.25, 0.5, 0.5, 0.6);
                    radpat.AddColorStop(0, new Color(0, 0, 0, 1));
                    radpat.AddColorStop(1, new Color(0, 0, 0, 0));

                    ctx.Source = linpat;
                    //ctx.Paint();
                    ctx.Mask(radpat);
                }
            };

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

            using (Surface surface = new PdfSurface("mask.pdf", 500, 500))
                draw(surface);

            using (Surface surface = new SvgSurface("mask.svg", 500, 500))
                draw(surface);
        }
    static void draw(Cairo.Context gr, int width, int height)
    {
        gr.Scale(width, height);
        gr.LineWidth = 0.04;
        LinearGradient pat;

        pat = new LinearGradient(0.0, 0.0, 0.0, 1.0);
        pat.AddColorStop(1, new Color(0, 0, 0, 1));
        pat.AddColorStop(0, new Color(1, 1, 1, 1));
        gr.Rectangle(new PointD(0, 0),
                     1, 1
                     );

        gr.Pattern = pat;
        gr.Fill();
        pat.Destroy();

        RadialGradient pat2 = new RadialGradient(0.45, 0.4, 0.1,
                                                 0.4, 0.4, 0.5);

        pat2.AddColorStop(0, new Color(1, 1, 1, 1));
        pat2.AddColorStop(1, new Color(0, 0, 0, 1));
        gr.Pattern = pat2;
        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Fill();
        pat2.Destroy();
    }
Ejemplo n.º 7
0
        void DrawShape(Context g, int width, int height)
        {
            int inner_x = radius + border + inner;
            int cx      = Center.X;
            int cy      = Center.Y;

            g.Operator = Operator.Source;
            g.SetSource(new SolidPattern(new Cairo.Color(0, 0, 0, 0)));
            g.Rectangle(0, 0, width, height);
            g.Paint();

            g.NewPath();
            g.Translate(cx, cy);
            g.Rotate(angle);

            g.SetSource(new SolidPattern(new Cairo.Color(0.2, 0.2, 0.2, .6)));
            g.Operator = Operator.Over;
            g.Rectangle(0, -(border + inner), inner_x, 2 * (border + inner));
            g.Arc(inner_x, 0, inner + border, 0, 2 * Math.PI);
            g.Arc(0, 0, radius + border, 0, 2 * Math.PI);
            g.Fill();

            g.SetSource(new SolidPattern(new Cairo.Color(0, 0, 0, 1.0)));
            g.Operator = Operator.DestOut;
            g.Arc(inner_x, 0, inner, 0, 2 * Math.PI);
#if true
            g.Fill();
#else
            g.FillPreserve();

            g.Operator = Operator.Over;
            RadialGradient rg = new RadialGradient(inner_x - (inner * 0.3), inner * 0.3, inner * 0.1, inner_x, 0, inner);
            rg.AddColorStop(0, new Cairo.Color(0.0, 0.2, .8, 0.5));
            rg.AddColorStop(0.7, new Cairo.Color(0.0, 0.2, .8, 0.1));
            rg.AddColorStop(1.0, new Cairo.Color(0.0, 0.0, 0.0, 0.0));
            g.Source = rg;
            g.Fill();
            rg.Destroy();
#endif
            g.Operator = Operator.Over;
            g.Matrix   = new Matrix();
            g.Translate(cx, cy);
            if (source != null)
            {
                CairoHelper.SetSourcePixbuf(g, source, -source.Width / 2, -source.Height / 2);
            }

            g.Arc(0, 0, radius, 0, 2 * Math.PI);
            g.Fill();

            if (overlay != null)
            {
                CairoHelper.SetSourcePixbuf(g, overlay, -overlay.Width / 2, -overlay.Height / 2);
                g.Arc(0, 0, radius, angle, angle + Math.PI);
                g.ClosePath();
                g.FillPreserve();
                g.SetSource(new SolidPattern(new Cairo.Color(1.0, 1.0, 1.0, 1.0)));
                g.Stroke();
            }
        }
Ejemplo n.º 8
0
        RadialGradient GetCornerGradient(double x, double y, double radius, double thickness)
        {
            var gradient = new RadialGradient(x, y, radius - thickness, x, y, radius + thickness);

            gradient.AddColorStop(0, BackgroundColor);
            gradient.AddColorStop(1, GetColor(BackgroundColor, 0.75));
            return(gradient);
        }
Ejemplo n.º 9
0
        protected override void DrawBackground(Context context, Gdk.Rectangle region)
        {
            LayoutRoundedRectangle(context, region);
            context.Clip();

            context.SetSourceColor(CairoExtensions.ParseColor("D3E6FF"));
            context.Paint();

            context.Save();
            context.Translate(region.X + region.Width / 2.0, region.Y + region.Height);

            using (var rg = new RadialGradient(0, 0, 0, 0, 0, region.Height * 1.2)) {
                var color = CairoExtensions.ParseColor("E5F0FF");
                rg.AddColorStop(0, color);
                color.A = 0;
                rg.AddColorStop(1, color);

                context.Scale(region.Width / (double)region.Height, 1.0);
                context.SetSource(rg);
                context.Paint();
            }

            context.Restore();

            LayoutRoundedRectangle(context, region, -3, -3, 2);
            context.SetSourceRGBA(1, 1, 1, 0.4);
            context.LineWidth = 1;
            context.StrokePreserve();

            context.Clip();

            int boxSize = 11;
            int x       = region.Left + (region.Width % boxSize) / 2;

            for (; x < region.Right; x += boxSize)
            {
                context.MoveTo(x + 0.5, region.Top);
                context.LineTo(x + 0.5, region.Bottom);
            }

            int y = region.Top + (region.Height % boxSize) / 2;

            y += boxSize / 2;
            for (; y < region.Bottom; y += boxSize)
            {
                context.MoveTo(region.Left, y + 0.5);
                context.LineTo(region.Right, y + 0.5);
            }

            context.SetSourceRGBA(1, 1, 1, 0.2);
            context.Stroke();

            context.ResetClip();
        }
Ejemplo n.º 10
0
        public void RadialGradientSmall()
        {
            InitBlank();
            var g = new RadialGradient(5, 5, 5, 30, 30, 15);

            g.AddColorStop(0, Colors.Red);
            g.AddColorStop(0.5, Colors.Green);
            g.AddColorStop(1, Colors.Blue);
            context.Rectangle(5, 5, 40, 40);
            context.Pattern = g;
            context.Fill();
            CheckImage("RadialGradientSmall.png");
        }
        protected virtual void DrawBackground(Cairo.Context context, Gdk.Rectangle region)
        {
            LayoutRoundedRectangle(context, region);
            context.ClipPreserve();

            using (LinearGradient lg = new LinearGradient(region.X, region.Y, region.X, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarFill1Color);
                lg.AddColorStop(1, Styles.StatusBarFill4Color);

                context.SetSource(lg);
                context.FillPreserve();
            }

            context.Save();
            double midX = region.X + region.Width / 2.0;
            double midY = region.Y + region.Height;

            context.Translate(midX, midY);

            using (RadialGradient rg = new RadialGradient(0, 0, 0, 0, 0, region.Height * 1.2)) {
                rg.AddColorStop(0, Styles.StatusBarFill1Color);
                rg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarFill1Color, 0));

                context.Scale(region.Width / (double)region.Height, 1.0);
                context.SetSource(rg);
                context.Fill();
            }
            context.Restore();

            using (LinearGradient lg = new LinearGradient(0, region.Y, 0, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarShadowColor1);
                lg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarShadowColor1, Styles.StatusBarShadowColor1.A * 0.2));

                LayoutRoundedRectangle(context, region, 0, -1);
                context.LineWidth = 1;
                context.SetSource(lg);
                context.Stroke();
            }

            using (LinearGradient lg = new LinearGradient(0, region.Y, 0, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarShadowColor2);
                lg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarShadowColor2, Styles.StatusBarShadowColor2.A * 0.2));

                LayoutRoundedRectangle(context, region, 0, -2);
                context.LineWidth = 1;
                context.SetSource(lg);
                context.Stroke();
            }

            context.ResetClip();
        }
Ejemplo n.º 12
0
        private Pattern CreateMask()
        {
            double max   = Math.Max(blur.Bounds.Width, blur.Bounds.Height) * .25;
            double scale = blur.Bounds.Width / (double)info.Bounds.Width;

            RadialGradient circle;

            circle = new RadialGradient(center.X * scale, center.Y * scale, radius * max * .7,
                                        center.X * scale, center.Y * scale, radius * max + max * .2);

            circle.AddColorStop(0, new Cairo.Color(0.0, 0.0, 0.0, 0.0));
            circle.AddColorStop(1.0, new Cairo.Color(1.0, 1.0, 1.0, 1.0));
            return(circle);
        }
Ejemplo n.º 13
0
        public void SaveRestoreRadialGradient()
        {
            // Pattern is saved
            InitBlank();
            var g = new RadialGradient(20, 20, 5, 30, 30, 30);

            g.AddColorStop(0, Colors.Red);
            g.AddColorStop(0.5, Colors.Green);
            g.AddColorStop(1, Colors.Blue);
            context.Save();
            context.Pattern = g;
            context.Restore();
            context.Rectangle(5, 5, 40, 40);
            context.Fill();
            CheckImage("SaveRestoreRadialGradient.png");
        }
Ejemplo n.º 14
0
        //---------------------------------------------------------------------
        private static void Demo02()
        {
            Action <Surface> draw = surface =>
            {
                using (var c = new Context(surface))
                {
                    c.Scale(500, 500);

                    Gradient radpat = new RadialGradient(0.25, 0.25, 0.1, 0.5, 0.5, 0.5);
                    radpat.AddColorStop(0, new Color(1.0, 0.8, 0.8));
                    radpat.AddColorStop(1, new Color(0.9, 0.0, 0.0));

                    for (int i = 1; i < 10; i++)
                    {
                        for (int j = 1; j < 10; j++)
                        {
                            c.Rectangle(i / 10d - 0.04, j / 10d - 0.04, 0.08, 0.08);
                        }
                    }
                    c.Source = radpat;
                    c.Fill();

                    Gradient linpat = new LinearGradient(0.25, 0.35, 0.75, 0.65);
                    linpat.AddColorStop(0.00, new Color(1, 1, 1, 0));
                    linpat.AddColorStop(0.25, new Color(0, 1, 0, 0.5));
                    linpat.AddColorStop(0.50, new Color(1, 1, 1, 0));
                    linpat.AddColorStop(0.75, new Color(0, 0, 1, 0.5));
                    linpat.AddColorStop(1.00, new Color(1, 1, 1, 0));

                    c.Rectangle(0, 0, 1, 1);
                    c.Source = linpat;
                    c.Fill();
                }
            };

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

            using (Surface surface = new PdfSurface("demo02.pdf", 500, 500))
                draw(surface);

            using (Surface surface = new SvgSurface("demo02.svg", 500, 500))
                draw(surface);
        }
Ejemplo n.º 15
0
        public void gradient(Context cr, int width, int height)
        {
            Normalize(cr, width, height);

            LinearGradient lg = new LinearGradient(0.0, 0.0, 0.0, 1.0);

            lg.AddColorStop(1, new Color(0, 0, 0, 1));
            lg.AddColorStop(0, new Color(1, 1, 1, 1));
            cr.Rectangle(0, 0, 1, 1);
            cr.Source = lg;
            cr.Fill();

            RadialGradient rg = new RadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5);

            rg.AddColorStop(0, new Color(1, 1, 1, 1));
            rg.AddColorStop(1, new Color(0, 0, 0, 1));
            cr.Source = rg;
            cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI);
            cr.Fill();
        }
Ejemplo n.º 16
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();
        }
Ejemplo n.º 17
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 = CairoExtensions.GdkRGBAToCairoColor(
                Widget.StyleContext.GetBackgroundColor(StateFlags.Selected));
            Color color_b = CairoExtensions.ColorShade(color_a, 1.4);

            RadialGradient 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.Pattern = fill;

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

            // Stroke the pie
            Context.Cairo.Color     = CairoExtensions.ColorShade(color_a, 0.8);
            Context.Cairo.LineWidth = Context.LineWidth;
            Context.Cairo.Stroke();
        }
Ejemplo n.º 18
0
 public override void ApplyBrushToContext(GraphicsContext g)
 {
     using (ImageSurface surface = ((ImageSurface)g.GetTarget()))
     {
         double actualWidth   = surface.Width;
         double actualHeight  = surface.Height;
         double maximumRadius = actualWidth > actualHeight ? actualWidth : actualHeight;
         using (RadialGradient lg = new RadialGradient(CX0 * actualWidth, CY0 * actualHeight, Radius0 * maximumRadius, CX1 * actualWidth, CY1 * actualHeight, Radius1 * maximumRadius))
         {
             if (GradientStops != null)
             {
                 foreach (GradientStop gs in GradientStops)
                 {
                     lg.AddColorStop(gs.Offset, gs.Color);
                 }
             }
             g.SetSource(lg);
         }
     }
 }
Ejemplo n.º 19
0
        private void Render(Clutter.CairoTexture texture, int with_state, bool outwards)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double alpha_f = with_state == 0 ? 0.5 : (with_state == 1 ? 0.8 : 1);

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            context.LineWidth = lwidth;

            if (outwards)
            {
                context.MoveTo(texture.Width * 0.5 - texture.Height * 0.45, texture.Height * 0.9);
                context.CurveTo(texture.Width * 0.3, texture.Height, texture.Width * 0.6, texture.Height, texture.Width * 0.5 + texture.Height * 0.45, texture.Height * 0.9);
                context.ArcNegative(texture.Width * 0.5, texture.Height * 0.9, texture.Height * 0.45, 0, Math.PI);
                context.ClosePath();
                Gradient g1 = new LinearGradient(0, texture.Height / 2, 0, texture.Height);
                g1.AddColorStop(0, new Cairo.Color(0.6, 0.6, 0.6, 1.0 * alpha_f));
                g1.AddColorStop(1.0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                context.Pattern = g1;
                context.FillPreserve();
                context.SetSourceRGBA(1.0, 1.0, 1.0, 1.0 * alpha_f);
                context.Stroke();
                ((IDisposable)g1).Dispose();

                context.Arc(Width * 0.5, Height * 0.33 + lwidth, Height * 0.33, 0, Math.PI * 2);
                context.ClosePath();
                context.Operator = Operator.Source;
                Gradient g2 = new RadialGradient(texture.Width * 0.5, texture.Height * 0.25, 0, texture.Width * 0.5, texture.Height * 0.25, texture.Width * 0.5);
                g2.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g2.AddColorStop(1.0, new Cairo.Color(0.6, 0.6, 0.6, 1.0 * alpha_f));
                context.Pattern = g2;
                //context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.FillPreserve();
                Gradient g3 = new LinearGradient(0, 0, 0, texture.Height * 0.5);
                g3.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g3.AddColorStop(1.0, new Cairo.Color(0, 0, 0, 1.0 * alpha_f));
                context.Pattern = g3;
                //context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.Stroke();
                ((IDisposable)g2).Dispose();
                ((IDisposable)g3).Dispose();
            }
            else
            {
                Cairo.PointD c     = new Cairo.PointD(texture.Width * 0.5, texture.Height * 0.5);
                double       max_r = Math.Min(c.X, c.Y) - hlwidth;

                context.Arc(c.X, c.Y, max_r, 0, Math.PI * 2);
                context.ArcNegative(c.X, c.Y, max_r * 0.25, Math.PI * 2, 0);
                context.ClosePath();
                context.SetSourceRGBA(0.5, 0.5, 0.5, 1.0 * alpha_f);
                context.StrokePreserve();
                Gradient g1 = new LinearGradient(0, texture.Height, texture.Width, 0);
                g1.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g1.AddColorStop(0.5, new Cairo.Color(0.7, 0.7, 0.7, 1.0 * alpha_f));
                g1.AddColorStop(1, new Cairo.Color(0.9, 0.9, 0.9, 1.0 * alpha_f));
                context.Pattern = g1;
                context.Fill();
                ((IDisposable)g1).Dispose();

                context.ArcNegative(c.X, c.Y, max_r * 0.25 + lwidth, Math.PI * 1.75, Math.PI * 0.75);
                context.Arc(c.X, c.Y, max_r, Math.PI * 0.75, Math.PI * 1.75);
                context.ClosePath();
                Gradient g2 = new LinearGradient(c.X, c.Y, c.X * 0.35, c.Y * 0.35);
                g2.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g2.AddColorStop(1, new Cairo.Color(1.0, 1.0, 1.0, 0.0));
                context.Pattern = g2;
                context.Fill();
                ((IDisposable)g2).Dispose();

                context.ArcNegative(c.X, c.Y, max_r * 0.25 + lwidth, Math.PI * 2, 0);
                context.Arc(c.X, c.Y, max_r * 0.45, 0, Math.PI * 2);
                context.SetSourceRGBA(1.0, 1.0, 1.0, 0.8 * alpha_f);
                context.Fill();

                context.Arc(c.X, c.Y, max_r - lwidth, 0, Math.PI * 2);
                Gradient g3 = new LinearGradient(0, texture.Height, texture.Width, 0);
                g3.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 0.0));
                g3.AddColorStop(1, new Cairo.Color(0.9, 0.9, 0.9, 1.0 * alpha_f));
                context.Pattern = g3;
                context.Stroke();
                ((IDisposable)g3).Dispose();
            }

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Ejemplo n.º 20
0
        protected override void PaintIconSurface(DockySurface surface)
        {
            int     size = Math.Min(surface.Width, surface.Height);
            Context cr   = surface.Context;

            double center = size / 2.0;

            Cairo.Color base_color = new Cairo.Color(1, .3, .3, .5).SetHue(120 * (1 - CPUUtilization));

            double radius = Math.Max(Math.Min(CPUUtilization * 1.3, 1), .001);

            // draw underlay
            cr.Arc(center, center, center * RadiusPercent, 0, Math.PI * 2);
            cr.Color = new Cairo.Color(0, 0, 0, .5);
            cr.FillPreserve();

            RadialGradient rg = new RadialGradient(center, center, 0, center, center, center * RadiusPercent);

            rg.AddColorStop(0, base_color);
            rg.AddColorStop(0.2, base_color);
            rg.AddColorStop(1, new Cairo.Color(base_color.R, base_color.G, base_color.B, 0.15));
            cr.Pattern = rg;
            cr.FillPreserve();

            rg.Destroy();

            // draw cpu indicator
            rg = new RadialGradient(center, center, 0, center, center, center * RadiusPercent * radius);
            rg.AddColorStop(0, new Cairo.Color(base_color.R, base_color.G, base_color.B, 1));
            rg.AddColorStop(0.2, new Cairo.Color(base_color.R, base_color.G, base_color.B, 1));
            rg.AddColorStop(1, new Cairo.Color(base_color.R, base_color.G, base_color.B, Math.Max(0, CPUUtilization * 1.3 - 1)));
            cr.Pattern = rg;
            cr.Fill();

            rg.Destroy();

            // draw highlight
            cr.Arc(center, center * .8, center * .6, 0, Math.PI * 2);
            LinearGradient lg = new LinearGradient(0, 0, 0, center);

            lg.AddColorStop(0, new Cairo.Color(1, 1, 1, .35));
            lg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0));
            cr.Pattern = lg;
            cr.Fill();
            lg.Destroy();

            // draw outer circles
            cr.LineWidth = 1;
            cr.Arc(center, center, center * RadiusPercent, 0, Math.PI * 2);
            cr.Color = new Cairo.Color(1, 1, 1, .75);
            cr.Stroke();

            cr.LineWidth = 1;
            cr.Arc(center, center, center * RadiusPercent - 1, 0, Math.PI * 2);
            cr.Color = new Cairo.Color(.8, .8, .8, .75);
            cr.Stroke();

            // draw memory indicate
            cr.LineWidth = size / 32.0;
            cr.ArcNegative(center, center, center * RadiusPercent - 1, Math.PI, Math.PI - Math.PI * (2 * MemoryUtilization));
            cr.Color = new Cairo.Color(1, 1, 1, .8);
            cr.Stroke();
        }
Ejemplo n.º 21
0
        void PaintBadgeSurface(DockySurface surface)
        {
            if (string.IsNullOrEmpty(BadgeText))
            {
                return;
            }

            int    padding   = 4;
            int    lineWidth = 2;
            double size      = (IsSmall ? 0.9 : 0.65) * Math.Min(surface.Width, surface.Height);
            double x         = surface.Width - size / 2;
            double y         = size / 2;

            if (!IsSmall)
            {
                // draw outline shadow
                surface.Context.LineWidth = lineWidth;
                surface.Context.Color     = new Cairo.Color(0, 0, 0, 0.5);
                surface.Context.Arc(x, y + 1, size / 2 - lineWidth, 0, Math.PI * 2);
                surface.Context.Stroke();

                // draw filled gradient
                RadialGradient rg = new RadialGradient(x, lineWidth, 0, x, lineWidth, size);
                rg.AddColorStop(0, badgeColors [0]);
                rg.AddColorStop(1.0, badgeColors [1]);

                surface.Context.Pattern = rg;
                surface.Context.Arc(x, y, size / 2 - lineWidth, 0, Math.PI * 2);
                surface.Context.Fill();
                rg.Destroy();

                // draw outline
                surface.Context.Color = new Cairo.Color(1, 1, 1, 1);
                surface.Context.Arc(x, y, size / 2 - lineWidth, 0, Math.PI * 2);
                surface.Context.Stroke();

                surface.Context.LineWidth = lineWidth / 2;
                surface.Context.Color     = badgeColors [1];
                surface.Context.Arc(x, y, size / 2 - 2 * lineWidth, 0, Math.PI * 2);
                surface.Context.Stroke();

                surface.Context.Color = new Cairo.Color(0, 0, 0, 0.2);
            }
            else
            {
                lineWidth = 0;
                padding   = 2;
            }

            using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout())
            {
                layout.Width                  = Pango.Units.FromPixels(surface.Height / 2);
                layout.Ellipsize              = Pango.EllipsizeMode.None;
                layout.FontDescription        = new Gtk.Style().FontDescription;
                layout.FontDescription.Weight = Pango.Weight.Bold;

                Pango.Rectangle inkRect, logicalRect;
                layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(surface.Height / 2);
                layout.SetText(BadgeText);
                layout.GetPixelExtents(out inkRect, out logicalRect);

                size -= 2 * padding + 2 * lineWidth;

                double scale = Math.Min(1, Math.Min(size / (double)logicalRect.Width, size / (double)logicalRect.Height));

                if (!IsSmall)
                {
                    surface.Context.Color = new Cairo.Color(0, 0, 0, 0.2);
                }
                else
                {
                    surface.Context.Color = new Cairo.Color(0, 0, 0, 0.6);
                    x = surface.Width - scale * logicalRect.Width / 2;
                    y = scale * logicalRect.Height / 2;
                }

                surface.Context.MoveTo(x - scale * logicalRect.Width / 2, y - scale * logicalRect.Height / 2);

                // draw text
                surface.Context.Save();
                if (scale < 1)
                {
                    surface.Context.Scale(scale, scale);
                }

                surface.Context.LineWidth = 2;
                Pango.CairoHelper.LayoutPath(surface.Context, layout);
                surface.Context.StrokePreserve();
                surface.Context.Color = new Cairo.Color(1, 1, 1, 1);
                surface.Context.Fill();
                surface.Context.Restore();

                layout.FontDescription.Dispose();
                layout.Context.Dispose();
            }
        }
Ejemplo n.º 22
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (!IsRealized)
            {
                return(false);
            }

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                cr.LineWidth = 1;

                int    x       = Allocation.X;
                int    width   = Allocation.Width;
                int    right   = x + width;
                int    xMiddle = x + width / 2;
                double yMiddle = Allocation.Y + Allocation.Height / 2.0;

                if (!string.IsNullOrEmpty(title))
                {
                    using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) {
                        layout.SetText(title);
                        layout.Width           = Pango.Units.FromPixels(Allocation.Width - Allocation.Height);
                        layout.FontDescription = Style.FontDescription;
                        layout.Ellipsize       = Pango.EllipsizeMode.End;
                        layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(8);
                        layout.FontDescription.Weight       = Pango.Weight.Bold;

                        Pango.Rectangle logical, ink;
                        layout.GetPixelExtents(out ink, out logical);

                        cr.MoveTo(Allocation.X + 2, Allocation.Y + (Allocation.Height - logical.Height) / 2);
                        Pango.CairoHelper.LayoutPath(cr, layout);
                        cr.Color = TextColor.SetAlpha(.6);
                        cr.Fill();

                        x += logical.Width + 5;

                        layout.Context.Dispose();
                    }
                }

                if (DrawLine)
                {
                    cr.MoveTo(x, yMiddle);
                    cr.LineTo(right, yMiddle);

                    RadialGradient rg = new RadialGradient(
                        xMiddle,
                        yMiddle,
                        0,
                        xMiddle,
                        yMiddle,
                        width / 2);
                    rg.AddColorStop(0, new Cairo.Color(0, 0, 0, 0.4));
                    rg.AddColorStop(1, new Cairo.Color(0, 0, 0, 0));

                    cr.Pattern = rg;
                    cr.Stroke();
                    rg.Destroy();

                    cr.MoveTo(x, yMiddle + 1);
                    cr.LineTo(right, yMiddle + 1);

                    rg = new RadialGradient(
                        xMiddle,
                        yMiddle + 1,
                        0,
                        xMiddle,
                        yMiddle + 1,
                        width / 2);
                    rg.AddColorStop(0, new Cairo.Color(1, 1, 1, .4));
                    rg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0));

                    cr.Pattern = rg;
                    cr.Stroke();
                    rg.Destroy();
                }

                (cr.Target as IDisposable).Dispose();
            }
            return(false);
        }
Ejemplo n.º 23
0
        void DrawTab(Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la)
        {
            // This logic is stupid to have here, should be in the caller!
            if (dragging)
            {
                tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress);
                tabBounds.X = Clamp(tabBounds.X, tabStartX, tabEndX - tabBounds.Width);
            }
            int padding = LeftRightPadding;

            padding = (int)(padding * Math.Min(1.0, Math.Max(0.5, (tabBounds.Width - 30) / 70.0)));

            ctx.LineWidth = 1;
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 0, active);
            ctx.ClosePath();
            using (var gr = new LinearGradient(tabBounds.X, TopBarPadding, tabBounds.X, allocation.Bottom)) {
                if (active)
                {
                    gr.AddColorStop(0, Styles.BreadcrumbGradientStartColor.MultiplyAlpha(tab.Opacity));
                    gr.AddColorStop(1, Styles.BreadcrumbBackgroundColor.MultiplyAlpha(tab.Opacity));
                }
                else
                {
                    gr.AddColorStop(0, CairoExtensions.ParseColor("f4f4f4").MultiplyAlpha(tab.Opacity));
                    gr.AddColorStop(1, CairoExtensions.ParseColor("cecece").MultiplyAlpha(tab.Opacity));
                }
                ctx.SetSource(gr);
            }
            ctx.Fill();

            ctx.SetSourceColor(new Cairo.Color(1, 1, 1, .5).MultiplyAlpha(tab.Opacity));
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 1, active);
            ctx.Stroke();

            ctx.SetSourceColor(Styles.BreadcrumbBorderColor.MultiplyAlpha(tab.Opacity));
            LayoutTabBorder(ctx, allocation, tabBounds.Width, tabBounds.X, 0, active);
            ctx.StrokePreserve();

            if (tab.GlowStrength > 0)
            {
                Gdk.Point mouse = tracker.MousePosition;
                using (var rg = new RadialGradient(mouse.X, tabBounds.Bottom, 0, mouse.X, tabBounds.Bottom, 100)) {
                    rg.AddColorStop(0, new Cairo.Color(1, 1, 1, 0.4 * tab.Opacity * tab.GlowStrength));
                    rg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0));

                    ctx.SetSource(rg);
                    ctx.Fill();
                }
            }
            else
            {
                ctx.NewPath();
            }

            // Render Close Button (do this first so we can tell how much text to render)

            var ch    = allocation.Height - TopBarPadding - BottomBarPadding + CloseImageTopOffset;
            var crect = new Gdk.Rectangle(tabBounds.Right - padding - CloseButtonSize + 3,
                                          tabBounds.Y + TopBarPadding + (ch - CloseButtonSize) / 2,
                                          CloseButtonSize, CloseButtonSize);

            tab.CloseButtonAllocation = crect;
            tab.CloseButtonAllocation.Inflate(2, 2);

            bool closeButtonHovered = tracker.Hovered && tab.CloseButtonAllocation.Contains(tracker.MousePosition) && tab.WidthModifier >= 1.0f;
            bool drawCloseButton    = tabBounds.Width > 60 || highlight || closeButtonHovered;

            if (drawCloseButton)
            {
                DrawCloseButton(ctx, new Gdk.Point(crect.X + crect.Width / 2, crect.Y + crect.Height / 2), closeButtonHovered, tab.Opacity, tab.DirtyStrength);
            }

            // Render Text
            int w = tabBounds.Width - (padding * 2 + CloseButtonSize);

            if (!drawCloseButton)
            {
                w += CloseButtonSize;
            }

            int textStart = tabBounds.X + padding;

            ctx.MoveTo(textStart, tabBounds.Y + TopPadding + TextOffset + VerticalTextSize);
            if (!Platform.IsMac && !Platform.IsWindows)
            {
                // This is a work around for a linux specific problem.
                // A bug in the proprietary ATI driver caused TAB text not to draw.
                // If that bug get's fixed remove this HACK asap.
                la.Ellipsize = Pango.EllipsizeMode.End;
                la.Width     = (int)(w * Pango.Scale.PangoScale);
                ctx.SetSourceColor(tab.Notify ? new Cairo.Color(0, 0, 1) : Styles.TabBarActiveTextColor);
                Pango.CairoHelper.ShowLayoutLine(ctx, la.GetLine(0));
            }
            else
            {
                // ellipses are for space wasting ..., we cant afford that
                using (var lg = new LinearGradient(textStart + w - 5, 0, textStart + w + 3, 0)) {
                    var color = tab.Notify ? new Cairo.Color(0, 0, 1) : Styles.TabBarActiveTextColor;
                    color = color.MultiplyAlpha(tab.Opacity);
                    lg.AddColorStop(0, color);
                    color.A = 0;
                    lg.AddColorStop(1, color);
                    ctx.SetSource(lg);
                    Pango.CairoHelper.ShowLayoutLine(ctx, la.GetLine(0));
                }
            }
            la.Dispose();
        }
Ejemplo n.º 24
0
        protected void OnExpose(object sender, ExposeEventArgs args)
        {
            using (Context cr = Gdk.CairoHelper.Create(GdkWindow)) {
                var left   = Allocation.Left;
                var top    = Allocation.Top;
                var width  = Allocation.Width;
                var height = Allocation.Height;
                var radius = barWidth / 2;
                int bigRadius;

                double fudgeFactor = -0.0125 * radius;

                if (curveStyle == CurveStyle.HalfCurve)
                {
                    bigRadius = height - radius - 2;
                    int originX = left + (width / 2);
                    int originY = top + height - radius;

                    cr.MoveTo(originX - bigRadius + barWidth, originY);
                    cr.Arc(originX - bigRadius + radius, originY, radius, 0, Math.PI);
                    cr.Arc(originX, originY, bigRadius, Math.PI, 0);
                    cr.Arc(originX + bigRadius - radius, originY, radius, 0, Math.PI);
                    cr.ArcNegative(originX, originY, bigRadius - barWidth + fudgeFactor, 0, Math.PI);
                    cr.ClosePath();
                    backgroundColor.SetSource(cr);
                    cr.Fill();

                    double r  = ((1 - _progress) * -180.0).ToRadians();
                    double x2 = TouchGlobal.CalcX(originX, bigRadius - radius, r);
                    double y2 = TouchGlobal.CalcY(originY, bigRadius - radius, r);

                    cr.MoveTo(originX - bigRadius + barWidth, originY);
                    cr.Arc(originX - bigRadius + radius, originY, radius, 0, Math.PI);
                    cr.Arc(originX, originY, bigRadius, Math.PI, r);
                    cr.Arc(x2, y2, radius, r, r + Math.PI);
                    cr.ArcNegative(originX, originY, bigRadius - barWidth + fudgeFactor, r, Math.PI);
                    cr.LineTo(left, originY);
                    cr.ClosePath();
                    progressColor.SetSource(cr);
                    cr.Fill();
                }
                else if (curveStyle == CurveStyle.ThreeQuarterCurve)
                {
                    int below = (0.45 * height).ToInt();
                    bigRadius = height - below - 2;
                    int originX = left + (width / 2);
                    int originY = top + height - below;

                    double x2 = TouchGlobal.CalcX(originX, bigRadius - radius, 3 * Math.PI / 4);
                    double y2 = TouchGlobal.CalcY(originY, bigRadius - radius, 3 * Math.PI / 4);

                    cr.MoveTo(x2, y2);
                    cr.Arc(x2, y2, radius, 7 * Math.PI / 4, 3 * Math.PI / 4);
                    cr.Arc(originX, originY, bigRadius, 3 * Math.PI / 4, Math.PI / 4);
                    x2 = TouchGlobal.CalcX(originX, bigRadius - radius, Math.PI / 4);
                    y2 = TouchGlobal.CalcY(originY, bigRadius - radius, Math.PI / 4);
                    cr.Arc(x2, y2, radius, Math.PI / 4, (-135.0).ToRadians());
                    cr.ArcNegative(originX, originY, bigRadius - barWidth + fudgeFactor, Math.PI / 4, 3 * Math.PI / 4);
                    cr.ClosePath();
                    backgroundColor.SetSource(cr);
                    cr.Fill();

                    double r = (_progress * 270.0 + 135.0).ToRadians();

                    x2 = TouchGlobal.CalcX(originX, bigRadius - radius, 3 * Math.PI / 4);
                    y2 = TouchGlobal.CalcY(originY, bigRadius - radius, 3 * Math.PI / 4);
                    cr.Arc(x2, y2, radius, 7 * Math.PI / 4, 3 * Math.PI / 4);
                    cr.Arc(originX, originY, bigRadius, 3 * Math.PI / 4, r);
                    x2 = TouchGlobal.CalcX(originX, bigRadius - radius, r);
                    y2 = TouchGlobal.CalcY(originY, bigRadius - radius, r);
                    cr.Arc(x2, y2, radius, r, r + Math.PI);
                    cr.ArcNegative(originX, originY, bigRadius - barWidth + fudgeFactor, r, 3 * Math.PI / 4);

                    var outlineColor = new TouchColor(progressColor);
                    outlineColor.ModifyColor(0.5);
                    var highlightColor = new TouchColor(progressColor);
                    highlightColor.ModifyColor(1.4);
                    var lowlightColor = new TouchColor(progressColor);
                    lowlightColor.ModifyColor(0.75);

                    var colorOriginX = TouchGlobal.CalcX(originX, bigRadius - 5, 11 * Math.PI / 8);
                    var colorOriginY = TouchGlobal.CalcY(originY, bigRadius - 5, 11 * Math.PI / 8);
                    using (var grad = new RadialGradient(colorOriginX, colorOriginY, 0, colorOriginX, colorOriginY, (bigRadius - 5) * 2)) {
                        grad.AddColorStop(0, highlightColor.ToCairoColor());
                        grad.AddColorStop(0.35, progressColor.ToCairoColor());
                        grad.AddColorStop(0.75, lowlightColor.ToCairoColor());
                        cr.SetSource(grad);
                        cr.FillPreserve();
                    }

                    outlineColor.SetSource(cr);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
            }
        }