protected override bool OnExposeEvent(Gdk.EventExpose evnt) { using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) { Gdk.Rectangle rect = Allocation; if (BackgroundColor.HasValue) { cr.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); cr.SetSourceColor(BackgroundColor.Value.ToCairoColor()); cr.Fill(); } if (GradientBackround) { Color gcol = Util.ToXwtColor(Style.Background(Gtk.StateType.Normal)); 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 (var pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Bottom)) { Cairo.Color color1 = gcol.ToCairoColor(); pat.AddColorStop(0, color1); gcol.Light -= 0.1; pat.AddColorStop(1, gcol.ToCairoColor()); cr.SetSource(pat); cr.FillPreserve(); } } cr.SetSourceColor(color.HasValue ? color.Value.ToCairoColor() : Style.Dark(Gtk.StateType.Normal).ToXwtColor().ToCairoColor()); cr.Rectangle(rect.X, rect.Y, rect.Width, topMargin); cr.Rectangle(rect.X, rect.Y + rect.Height - bottomMargin, rect.Width, bottomMargin); cr.Rectangle(rect.X, rect.Y, leftMargin, rect.Height); cr.Rectangle(rect.X + rect.Width - rightMargin, rect.Y, rightMargin, rect.Height); cr.Fill(); } bool res = base.OnExposeEvent(evnt); return(res); }
void HandleWidgetExposeEvent(object o, Gtk.ExposeEventArgs args) { // The Entry's GdkWindow is the top level window onto which // the frame is drawn; the actual text entry is drawn into a // separate window, so we can ensure that for themes that don't // respect HasFrame, we never ever allow the base frame drawing // to happen if (args.Event.Window == Widget.GdkWindow) { return; } if (Widget.Text.Length > 0) { return; } if (layout == null) { layout = new Pango.Layout(Widget.PangoContext); layout.FontDescription = Widget.PangoContext.FontDescription.Copy(); } int wh, ww; args.Event.Window.GetSize(out ww, out wh); int width, height; layout.SetText(placeHolderText); layout.GetPixelSize(out width, out height); Gdk.GC gc = new Gdk.GC(args.Event.Window); gc.Copy(Widget.Style.TextGC(Gtk.StateType.Normal)); Color color_a = Util.ToXwtColor(Widget.Style.Base(Gtk.StateType.Normal)); Color color_b = Util.ToXwtColor(Widget.Style.Text(Gtk.StateType.Normal)); gc.RgbFgColor = Util.ToGdkColor(color_b.BlendWith(color_a, 0.5)); args.Event.Window.DrawLayout(gc, 2, (wh - height) / 2 + 1, layout); gc.Dispose(); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { Gdk.Rectangle rect; if (DrawBackground) { GdkWindow.DrawRectangle(Style.BackgroundGC(Gtk.StateType.Normal), true, Allocation.X, Allocation.Y, Allocation.Width - 1, Allocation.Height - 1); } if (GradientBackround) { rect = new Gdk.Rectangle(Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height); Color gcol = Util.ToXwtColor(Style.Background(Gtk.StateType.Normal)); using (Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow)) { 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(); Cairo.Gradient pat = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Bottom); Cairo.Color color1 = gcol.ToCairoColor(); pat.AddColorStop(0, color1); gcol.Light -= 0.1; pat.AddColorStop(1, gcol.ToCairoColor()); cr.Pattern = pat; cr.FillPreserve(); } } bool res = base.OnExposeEvent(evnt); Gdk.GC borderColor; if (color != null) { borderColor = new Gdk.GC(GdkWindow); borderColor.RgbFgColor = Util.ToGdkColor(color.Value); } else { borderColor = Style.DarkGC(Gtk.StateType.Normal); } rect = Allocation; for (int n = 0; n < topMargin; n++) { GdkWindow.DrawLine(borderColor, rect.X, rect.Y + n, rect.Right, rect.Y + n); } for (int n = 0; n < bottomMargin; n++) { GdkWindow.DrawLine(borderColor, rect.X, rect.Bottom - n, rect.Right, rect.Bottom - n); } for (int n = 0; n < leftMargin; n++) { GdkWindow.DrawLine(borderColor, rect.X + n, rect.Y, rect.X + n, rect.Bottom); } for (int n = 0; n < rightMargin; n++) { GdkWindow.DrawLine(borderColor, rect.Right - n, rect.Y, rect.Right - n, rect.Bottom); } if (color != null) { borderColor.Dispose(); } return(res); }