GtkSharp/sample/GtkDemo/DemoColorSelection.cs
Mike Kestner d41f6593b0 2004-02-10 Mike Kestner <mkestner@ximian.com>
* art/Art.metadata : mark a field private
	* art/art-api.xml : regen
	* gda/Gda.metadata : mark a few structs opaque
	* gda/gda-api.xml : regen
	* gdk/*.custom : fix changed field names
	* gdk/gdk-api.xml : regen
	* generator/Field.cs : StudlyCase simple typed field names.
	* gnome/Gnome.metadata : mark FontEntry.weight private to
	avoid collision with Weight field. s|//|/api/namespace|g
	* gnome/gnome-api.xml : regen
	* gtk/Gtk.metadata : rename AccelKey.accel_key to key to
	avoid collision with type name.
	* gtk/*.custom : fix changed field names
	* gtk/gtk-api.xml : regen
	* pango/pango-api.xml : regen
	* parser/gapi_pp.pl : add a private_regex to hide BACKEND
	and ENGINE apis, which are by convention private.
	* sample/* : make compile
	* sample/GtkDemo/* : make compile
	* sample/test/* : make compile
	* sources/gtk-sharp-sources.xml : exclude a bunch of pango
	source files.

svn path=/trunk/gtk-sharp/; revision=22947
2004-02-10 16:04:50 +00:00

111 lines
3 KiB
C#

//
// DemoColorSelection.cs, port of colorsel.c from gtk-demo
//
// Author: Daniel Kornhauser <dkor@alum.mit.edu>
//
// Copyright (C) 2003, Ximian Inc.
/*
*
* GtkColorSelection lets the user choose a color. GtkColorSelectionDialog is
* a prebuilt dialog containing a GtkColorSelection.
*
*/
using System;
using Gdk;
using Gtk;
using GtkSharp;
namespace GtkDemo
{
public class DemoColorSelection
{
private Gtk.Window window ;
private Gdk.Color color;
private ColorSelectionDialog colorSelectionDialog;
private Gtk.DrawingArea drawingArea;
public DemoColorSelection ()
{
window = new Gtk.Window ("Color Selection");
window.DeleteEvent += new DeleteEventHandler (WindowDelete);
window.BorderWidth = 8;
VBox vbox = new VBox (false,8);
vbox.BorderWidth = 8;
window.Add (vbox);
// Create the color swatch area
Frame frame = new Frame ();
frame.ShadowType = ShadowType.In;
vbox.PackStart (frame, true, true, 0);
drawingArea = new DrawingArea ();
drawingArea.ExposeEvent += new ExposeEventHandler (ExposeEventCallback);
// set a minimum size
drawingArea.SetSizeRequest (200,200);
// set the color
color = new Gdk.Color (0, 0, 0xff);
drawingArea.ModifyBg (StateType.Normal, color);
frame.Add (drawingArea);
Alignment alignment = new Alignment (1.0f, 0.5f, 0.0f, 0.0f);
Button button = new Button ("_Change the above color");
button.Clicked += new EventHandler (ChangeColorCallback);
alignment.Add (button);
vbox.PackStart (alignment);
window.ShowAll ();
}
private void WindowDelete (object o, DeleteEventArgs args)
{
window.Hide ();
window.Destroy ();
}
// Expose callback for the drawing area
private void ExposeEventCallback (object o, ExposeEventArgs args)
{
EventExpose eventExpose = args.Event;
Gdk.Window window = eventExpose.window;
Rectangle area = eventExpose.Area;
window.DrawRectangle (drawingArea.Style.BackgroundGC(StateType.Normal),
true,
area.X, area.Y,
area.Width, area.Height);
SignalArgs sa = (SignalArgs) args;
sa.RetVal = true;
}
private void ChangeColorCallback (object o, EventArgs args)
{
colorSelectionDialog = new ColorSelectionDialog ("Changing color");
colorSelectionDialog.TransientFor = window;
colorSelectionDialog.ColorSelection.PreviousColor = color;
colorSelectionDialog.ColorSelection.CurrentColor = color;
colorSelectionDialog.ColorSelection.HasPalette = true;
colorSelectionDialog.CancelButton.Clicked += new EventHandler (Color_Selection_Cancel);
colorSelectionDialog.OkButton.Clicked += new EventHandler (Color_Selection_OK);
colorSelectionDialog.ShowAll();
}
private void Color_Selection_OK (object o, EventArgs args)
{
Gdk.Color selected = colorSelectionDialog.ColorSelection.CurrentColor;
drawingArea.ModifyBg (StateType.Normal, selected);
colorSelectionDialog.Destroy ();
}
private void Color_Selection_Cancel (object o, EventArgs args)
{
colorSelectionDialog.Destroy ();
}
}
}