Beispiel #1
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            Gdk.Rectangle rect = Allocation;

            //Gdk.Rectangle.Right and Bottom are inconsistent
            int right = rect.X + rect.Width, bottom = rect.Y + rect.Height;

            var bcolor = backgroundColorSet ? BackgroundColor : Style.Background(Gtk.StateType.Normal);

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                if (GradientBackround)
                {
                    cr.NewPath();
                    cr.MoveTo(rect.X, rect.Y);
                    cr.RelLineTo(rect.Width, 0);
                    cr.RelLineTo(0, rect.Height);
                    cr.RelLineTo(-rect.Width, 0);
                    cr.RelLineTo(0, -rect.Height);
                    cr.ClosePath();
                    using (Cairo.Gradient pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, bottom)) {
                        pat.AddColorStop(0, bcolor.ToCairoColor());
                        Xwt.Drawing.Color gcol = bcolor.ToXwtColor();
                        gcol.Light -= 0.1;
                        if (gcol.Light < 0)
                        {
                            gcol.Light = 0;
                        }
                        pat.AddColorStop(1, gcol.ToCairoColor());
                        cr.SetSource(pat);
                        cr.Fill();
                    }
                }
                else
                {
                    if (backgroundColorSet)
                    {
                        Gdk.GC gc = new Gdk.GC(GdkWindow);
                        gc.RgbFgColor = bcolor;
                        evnt.Window.DrawRectangle(gc, true, rect.X, rect.Y, rect.Width, rect.Height);
                        gc.Dispose();
                    }
                }
            }
            base.OnExposeEvent(evnt);

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                cr.SetSourceColor(Style.Dark(Gtk.StateType.Normal).ToCairoColor());

                double y = rect.Y + topMargin / 2d;
                cr.LineWidth = topMargin;
                cr.Line(rect.X, y, right, y);
                cr.Stroke();

                y            = bottom - bottomMargin / 2d;
                cr.LineWidth = bottomMargin;
                cr.Line(rect.X, y, right, y);
                cr.Stroke();

                double x = rect.X + leftMargin / 2d;
                cr.LineWidth = leftMargin;
                cr.Line(x, rect.Y, x, bottom);
                cr.Stroke();

                x            = right - rightMargin / 2d;
                cr.LineWidth = rightMargin;
                cr.Line(x, rect.Y, x, bottom);
                cr.Stroke();

                return(false);
            }
        }
Beispiel #2
0
 public override void AddColorStop(object backend, double position, Xwt.Drawing.Color color)
 {
     Cairo.Gradient g = (Cairo.Gradient)backend;
     g.AddColorStop(position, color.ToCairoColor());
 }