From b2931f22c3004df536c4d4738d2452e5b3a78a38 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Fri, 29 Jul 2011 18:06:03 +0200 Subject: [PATCH 1/2] DemoColorSelection: Remove Drawn callback and preserve selected color The drawing area is automatically cleared to the background color, so we don't need a Drawn callback to do it ourselves. Preserve the color selected in the color selection dialog, so that it's pre-selected the next time the dialog is opened. --- sample/GtkDemo/DemoColorSelection.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/sample/GtkDemo/DemoColorSelection.cs b/sample/GtkDemo/DemoColorSelection.cs index d8f5f8b79..ee6ad53dc 100644 --- a/sample/GtkDemo/DemoColorSelection.cs +++ b/sample/GtkDemo/DemoColorSelection.cs @@ -30,7 +30,6 @@ namespace GtkDemo vbox.PackStart (frame, true, true, 0); drawingArea = new DrawingArea (); - drawingArea.Drawn += new DrawnHandler (DrawnCallback); // set a minimum size drawingArea.SetSizeRequest (200,200); // set the color @@ -56,18 +55,6 @@ namespace GtkDemo return true; } - // Drawn callback for the drawing area - private void DrawnCallback (object o, DrawnArgs args) - { - Cairo.Context cr = args.Cr; - - Gdk.RGBA rgba = StyleContext.GetBackgroundColor (StateFlags.Normal); - cr.SetSourceRGBA (rgba.Red, rgba.Green, rgba.Blue, rgba.Alpha); - cr.Paint (); - - args.RetVal = true; - } - private void ChangeColorCallback (object o, EventArgs args) { using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog ("Changing color")) { @@ -77,8 +64,8 @@ namespace GtkDemo colorSelectionDialog.ColorSelection.HasPalette = true; if (colorSelectionDialog.Run () == (int) ResponseType.Ok) { - Gdk.RGBA selected = colorSelectionDialog.ColorSelection.CurrentRgba; - drawingArea.OverrideBackgroundColor (StateFlags.Normal, selected); + color = colorSelectionDialog.ColorSelection.CurrentRgba; + drawingArea.OverrideBackgroundColor (StateFlags.Normal, color); } colorSelectionDialog.Hide (); From 6e6d448cf2cf8f0aa84a99db24342a8487a726ca Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Fri, 29 Jul 2011 18:10:58 +0200 Subject: [PATCH 2/2] DemoDrawingArea: Fix sample to actually do some drawing --- sample/GtkDemo/DemoDrawingArea.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sample/GtkDemo/DemoDrawingArea.cs b/sample/GtkDemo/DemoDrawingArea.cs index c8744e177..3e6bfbe45 100644 --- a/sample/GtkDemo/DemoDrawingArea.cs +++ b/sample/GtkDemo/DemoDrawingArea.cs @@ -112,6 +112,7 @@ namespace GtkDemo cr.SetSourceRGB (1, 1, 1); // If we're outside the clip, this will do nothing. cr.Rectangle (i, j, CheckSize, CheckSize); + cr.Fill (); j += CheckSize + Spacing; ++ycount; @@ -146,6 +147,7 @@ namespace GtkDemo surface = widget.Window.CreateSimilarSurface (Cairo.Content.Color, allocation.Width, allocation.Height); var cr = new Cairo.Context (surface); + cr.SetSourceRGB (1, 1, 1); cr.Paint (); ((IDisposable)cr).Dispose (); @@ -186,8 +188,8 @@ namespace GtkDemo var update_rect = new Gdk.Rectangle ((int)x - 3, (int)y - 3, 6, 6); var cr = new Cairo.Context (surface); - cr.Fill (); Gdk.CairoHelper.Rectangle (cr, update_rect); + cr.Fill (); ((IDisposable)cr).Dispose ();