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.
This commit is contained in:
Bertrand Lorentz 2011-07-29 18:06:03 +02:00
parent da1481b23d
commit b2931f22c3

View file

@ -30,7 +30,6 @@ namespace GtkDemo
vbox.PackStart (frame, true, true, 0); vbox.PackStart (frame, true, true, 0);
drawingArea = new DrawingArea (); drawingArea = new DrawingArea ();
drawingArea.Drawn += new DrawnHandler (DrawnCallback);
// set a minimum size // set a minimum size
drawingArea.SetSizeRequest (200,200); drawingArea.SetSizeRequest (200,200);
// set the color // set the color
@ -56,18 +55,6 @@ namespace GtkDemo
return true; 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) private void ChangeColorCallback (object o, EventArgs args)
{ {
using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog ("Changing color")) { using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog ("Changing color")) {
@ -77,8 +64,8 @@ namespace GtkDemo
colorSelectionDialog.ColorSelection.HasPalette = true; colorSelectionDialog.ColorSelection.HasPalette = true;
if (colorSelectionDialog.Run () == (int) ResponseType.Ok) { if (colorSelectionDialog.Run () == (int) ResponseType.Ok) {
Gdk.RGBA selected = colorSelectionDialog.ColorSelection.CurrentRgba; color = colorSelectionDialog.ColorSelection.CurrentRgba;
drawingArea.OverrideBackgroundColor (StateFlags.Normal, selected); drawingArea.OverrideBackgroundColor (StateFlags.Normal, color);
} }
colorSelectionDialog.Hide (); colorSelectionDialog.Hide ();