Skip to content

Commit

Permalink
DemoColorSelection: Remove Drawn callback and preserve selected color
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bl8 committed Jul 29, 2011
1 parent da1481b commit b2931f2
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions sample/GtkDemo/DemoColorSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public DemoColorSelection () : base ("Color Selection")
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
Expand All @@ -56,18 +55,6 @@ protected override bool OnDeleteEvent (Gdk.Event evt)
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")) {
Expand All @@ -77,8 +64,8 @@ private void ChangeColorCallback (object o, EventArgs args)
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 ();
Expand Down

0 comments on commit b2931f2

Please sign in to comment.