mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-25 07:05:41 +00:00
967e3e9c5a
* generator/ClassBase.cs: Change hasDefaultConstructor to protected, adjust now that it is an attr and not a subnode. Also add virtual property AssignToName (for ctors). * generator/Ctor.cs: Add property ForceStatic. (Generate): Optimize return code a bit for the static case. * generator/Method.cs: Assign to a "raw_ret" pointer before calling FromNativeReturn. * generator/Parameters.cs: Change "out ref" to "out", not "ref". * generator/Property.cs: Fix to work correctly with all object and struct types (mostly just some if-cases added). * generator/SignalHandler.cs: Remove args_type and argfields (unused). (Generate): Initialize struct if necessary. * generator/StructBase.cs: Massive reworking to support methods, ctors, etc. * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event fields. Fix docs. * glib/Value.cs: Work correctly with boxed properties. * gnome/Modules.cs: Use new struct ctors. * gnome/Program.custom: Remove Get, this is being generated now. * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. * parser/Metadata.pm: Change per-class attributes to actually be attributes. * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap typedefs. * sample/test/TestColorSelection.cs: Display color string in hex format, update to use IsNull instead of == null, and size dialog to look pretty. * sample/Size.cs: Added. svn path=/trunk/gtk-sharp/; revision=6264
137 lines
3.5 KiB
C#
137 lines
3.5 KiB
C#
//
|
|
// TestColorSelection.cs
|
|
//
|
|
// Author: Duncan Mak (duncan@ximian.com)
|
|
//
|
|
// Copyright (C) 2002, Duncan Mak, Ximian Inc.
|
|
//
|
|
|
|
using System;
|
|
using System.Text;
|
|
|
|
using Gtk;
|
|
using GtkSharp;
|
|
|
|
namespace WidgetViewer {
|
|
public class TestColorSelection
|
|
{
|
|
static ColorSelectionDialog window = null;
|
|
static Dialog dialog = null;
|
|
|
|
public static Gtk.Window Create ()
|
|
{
|
|
HBox options = new HBox (false, 0);
|
|
CheckButton check_button = null;
|
|
|
|
window = new ColorSelectionDialog ("Color selection dialog");
|
|
window.ColorSelection.HasOpacityControl = true;
|
|
window.ColorSelection.HasPalette = true;
|
|
|
|
window.SetDefaultSize (250, 200);
|
|
window.VBox.PackStart (options, false, false, 0);
|
|
window.VBox.BorderWidth = 10;
|
|
|
|
check_button = new CheckButton("Show Opacity");
|
|
check_button.Active = true;
|
|
options.PackStart (check_button, false, false, 0);
|
|
check_button.Toggled += new EventHandler (Opacity_Callback);
|
|
|
|
check_button = new CheckButton("Show Palette");
|
|
check_button.Active = true;
|
|
options.PackEnd (check_button, false, false, 0);
|
|
check_button.Toggled += new EventHandler (Palette_Callback);
|
|
|
|
window.ColorSelection.ColorChanged += new EventHandler (Color_Changed);
|
|
window.OkButton.Clicked += new EventHandler (Color_Selection_OK);
|
|
window.CancelButton.Clicked += new EventHandler (Color_Selection_Cancel);
|
|
|
|
options.ShowAll ();
|
|
|
|
return window;
|
|
}
|
|
|
|
static void Opacity_Callback (object o, EventArgs args)
|
|
{
|
|
window.ColorSelection.HasOpacityControl = ((ToggleButton )o).Active;
|
|
}
|
|
|
|
static void Palette_Callback (object o, EventArgs args)
|
|
{
|
|
window.ColorSelection.HasPalette = ((ToggleButton )o).Active;
|
|
}
|
|
|
|
static string HexFormat (Gdk.Color color)
|
|
{
|
|
StringBuilder s = new StringBuilder ();
|
|
ushort[] vals = { color.red, color.green, color.blue };
|
|
char[] hexchars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
'A', 'B', 'C', 'D', 'E', 'F'};
|
|
|
|
s.Append ('#');
|
|
foreach (ushort val in vals) {
|
|
/* Convert to a range of 0-255, then lookup the
|
|
* digit for each half-byte */
|
|
byte rounded = (byte) (val >> 8);
|
|
s.Append (hexchars[(rounded & 0xf0) >> 4]);
|
|
s.Append (hexchars[rounded & 0x0f]);
|
|
}
|
|
|
|
return s.ToString ();
|
|
}
|
|
|
|
static void Color_Changed (object o, EventArgs args)
|
|
{
|
|
Gdk.Color color = window.ColorSelection.CurrentColor;
|
|
Console.WriteLine (HexFormat (color));
|
|
}
|
|
|
|
static void Color_Selection_OK (object o, EventArgs args)
|
|
{
|
|
Gdk.Color selected = window.ColorSelection.CurrentColor;
|
|
if (selected.IsNull) {
|
|
Console.WriteLine ("Color selection failed.");
|
|
return;
|
|
}
|
|
Display_Result (selected);
|
|
}
|
|
|
|
static void Color_Selection_Cancel (object o, EventArgs args)
|
|
{
|
|
if (dialog != null)
|
|
dialog.Destroy ();
|
|
window.Destroy ();
|
|
}
|
|
|
|
static void Display_Result (Gdk.Color color)
|
|
{
|
|
if (color.IsNull)
|
|
Console.WriteLine ("Null color");
|
|
dialog = new Dialog ();
|
|
dialog.Title = "Selected Color";
|
|
|
|
dialog.VBox.PackStart (new Gtk.Label (HexFormat (color)),
|
|
false, false, 0);
|
|
|
|
DrawingArea da = new DrawingArea ();
|
|
|
|
da.ModifyBg (StateType.Normal, color);
|
|
|
|
dialog.VBox.PackStart (da, true, true, 0);
|
|
dialog.SetDefaultSize (200, 200);
|
|
|
|
Button button = new Button ("OK");
|
|
button.Clicked += new EventHandler (Close_Button);
|
|
button.CanDefault = true;
|
|
dialog.ActionArea.PackStart (button, true, true, 0);
|
|
button.GrabDefault ();
|
|
|
|
dialog.ShowAll ();
|
|
}
|
|
|
|
static void Close_Button (object o, EventArgs args)
|
|
{
|
|
Color_Selection_Cancel (o, args);
|
|
}
|
|
}
|
|
}
|