From e5dde2ff7e2f22db8f16a8029ac7d929f4eed2bd Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 26 Aug 2004 19:10:48 +0000 Subject: [PATCH] 2004-08-26 Manuel V. Santos * gdk/Device.custom : glue to expose object fields. * gdk/DeviceAxis.custom : expand the ToString to incl use: * gdk/EventButton.custom : fix for Axes prop. * gdk/EventMotion.custom : fix for Axes prop. * gdk/Gdk.metadata : hide some accessors on Device. * gdk/Makefile.am : add new custom. * gdk/glue/Makefile.am : add new .c * gdk/glue/makefile.win32 : add new .o * gdk/glue/device.c : ditto. * gtk/InputDialog.custom : glue to expose button fields. * gtk/Makefile.am : add new custom. * gtk/glue/Makefile.am : add new .c * gtk/glue/makefile.win32 : add new .o * gtk/glue/inputdialog.c : ditto. * sample/ScribbleXInput.cs : new sample using extension events. svn path=/trunk/gtk-sharp/; revision=32899 --- ChangeLog | 18 ++++ doc/en/Gdk/Device.xml | 205 +++++++++++++++++++++++++++---------- doc/en/Gtk/InputDialog.xml | 26 +++++ gdk/Device.custom | 106 +++++++++++++++++++ gdk/DeviceAxis.custom | 2 +- gdk/EventButton.cs | 7 +- gdk/EventMotion.cs | 7 +- gdk/Gdk.metadata | 3 + gdk/Makefile.am | 1 + gdk/glue/Makefile.am | 1 + gdk/glue/device.c | 84 +++++++++++++++ gdk/glue/makefile.win32 | 1 + gtk/InputDialog.custom | 42 ++++++++ gtk/Makefile.am | 1 + gtk/glue/Makefile.am | 1 + gtk/glue/inputdialog.c | 40 ++++++++ gtk/glue/makefile.win32 | 1 + sample/Makefile.am | 6 +- sample/ScribbleXInput.cs | 166 ++++++++++++++++++++++++++++++ 19 files changed, 657 insertions(+), 61 deletions(-) create mode 100644 gdk/Device.custom create mode 100644 gdk/glue/device.c create mode 100644 gtk/InputDialog.custom create mode 100644 gtk/glue/inputdialog.c create mode 100644 sample/ScribbleXInput.cs diff --git a/ChangeLog b/ChangeLog index e7fffd45e..e04ba6e3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2004-08-26 Manuel V. Santos + + * gdk/Device.custom : glue to expose object fields. + * gdk/DeviceAxis.custom : expand the ToString to incl use: + * gdk/EventButton.custom : fix for Axes prop. + * gdk/EventMotion.custom : fix for Axes prop. + * gdk/Gdk.metadata : hide some accessors on Device. + * gdk/Makefile.am : add new custom. + * gdk/glue/Makefile.am : add new .c + * gdk/glue/makefile.win32 : add new .o + * gdk/glue/device.c : ditto. + * gtk/InputDialog.custom : glue to expose button fields. + * gtk/Makefile.am : add new custom. + * gtk/glue/Makefile.am : add new .c + * gtk/glue/makefile.win32 : add new .o + * gtk/glue/inputdialog.c : ditto. + * sample/ScribbleXInput.cs : new sample using extension events. + 2004-08-25 Mike Kestner * generator/Signal.cs : use typeof instead of Type.GetType to diff --git a/doc/en/Gdk/Device.xml b/doc/en/Gdk/Device.xml index 024aa2449..f52865186 100644 --- a/doc/en/Gdk/Device.xml +++ b/doc/en/Gdk/Device.xml @@ -99,21 +99,6 @@ None. - - - Property - - Gdk.InputSource - - - - - Sets the source type for an input device. - Sets the source type for an input device. - None. - None. - - Method @@ -150,45 +135,6 @@ To be added - - - Method - - System.Void - - - - - - - - To be added - a - a - a - To be added - - - - - Method - - System.Boolean - - - - - - - - Interprets an array of double as axis values for a given device, and locates the value in the array for a given axis use. - An array of axes. - The to look for. - Found value. - True if the given axis use was found, otherwise false. - To be added - - Method @@ -251,5 +197,154 @@ None. + + + Property + + System.String + + + + To be added + a + To be added + + + + + Property + + Gdk.InputSource + + + + To be added + a + To be added + + + + + Property + + Gdk.InputMode + + + + To be added + a + To be added + + + + + Property + + System.Boolean + + + + To be added + a + To be added + + + + + Property + + System.Int32 + + + + To be added + a + To be added + + + + + Property + + System.Int32 + + + + To be added + a + To be added + + + + + Method + + System.Boolean + + + + + + + + To be added + a + a + a + a + To be added + + + + + Method + + System.Void + + + + + + + + To be added + a + a + a + To be added + + + + + Method + + Gdk.DeviceAxis + + + + + + To be added + a + a + To be added + + + + + Method + + Gdk.DeviceKey + + + + + + To be added + a + a + To be added + + - \ No newline at end of file + diff --git a/doc/en/Gtk/InputDialog.xml b/doc/en/Gtk/InputDialog.xml index 1c8af99b0..d08fda4bd 100644 --- a/doc/en/Gtk/InputDialog.xml +++ b/doc/en/Gtk/InputDialog.xml @@ -171,5 +171,31 @@ Chain to this constructor if you have manually registered a native value for your subclass. + + + Property + + Gtk.Button + + + + To be added + a + To be added + + + + + Property + + Gtk.Button + + + + To be added + a + To be added + + \ No newline at end of file diff --git a/gdk/Device.custom b/gdk/Device.custom new file mode 100644 index 000000000..aff77c3e4 --- /dev/null +++ b/gdk/Device.custom @@ -0,0 +1,106 @@ +// Display.custom - customizations to Gdk.Display +// +// Authors: Manuel V. Santos +// +// Copyright (c) 2004 Manuel V. Santos +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + + [DllImport("gdksharpglue")] + static extern IntPtr gtksharp_gdk_device_get_name (IntPtr device); + + [DllImport("gdksharpglue")] + static extern InputSource gtksharp_gdk_device_get_source (IntPtr device); + + [DllImport("gdksharpglue")] + static extern InputMode gtksharp_gdk_device_get_mode (IntPtr device); + + [DllImport("gdksharpglue")] + static extern bool gtksharp_gdk_device_has_cursor (IntPtr device); + + [DllImport("gdksharpglue")] + static extern int gtksharp_gdk_device_get_num_axes (IntPtr device); + + [DllImport("gdksharpglue")] + static extern int gtksharp_gdk_device_get_num_keys (IntPtr device); + + [DllImport("gdksharpglue")] + static extern DeviceAxis gtksharp_gdk_device_get_device_axis (IntPtr device, uint axis); + + [DllImport("gdksharpglue")] + static extern DeviceKey gtksharp_gdk_device_get_device_key (IntPtr device, uint axis); + + [DllImport("libgdk-win32-2.0-0.dll")] + static extern void gdk_device_set_source(IntPtr device, int source); + + [DllImport("libgdk-win32-2.0-0.dll")] + static extern void gdk_device_get_state(IntPtr device, IntPtr window, double [] axes, out int maskAsInt); + + + public string Name { + get { + IntPtr rawName = gtksharp_gdk_device_get_name (Handle); + return Marshal.PtrToStringAnsi(rawName); + } + } + + public Gdk.InputSource Source { + get { + return gtksharp_gdk_device_get_source (Handle); + } + set { + gdk_device_set_source(Handle, (int) value); + } + } + + public Gdk.InputMode Mode { + get { + return gtksharp_gdk_device_get_mode (Handle); + } + } + + public bool HasCursor { + get { + return gtksharp_gdk_device_has_cursor (Handle); + } + } + + public int NumAxes { + get { + return gtksharp_gdk_device_get_num_axes (Handle); + } + } + + public int NumKeys { + get { + return gtksharp_gdk_device_get_num_keys (Handle); + } + } + + public void GetState(Gdk.Window window, out double [] axes, out Gdk.ModifierType mask) { + int maskAsInt; + axes = new double [this.NumAxes]; + gdk_device_get_state(Handle, window.Handle, axes, out maskAsInt); + mask = (Gdk.ModifierType) maskAsInt; + } + + public Gdk.DeviceAxis GetDeviceAxis (uint axis) { + return gtksharp_gdk_device_get_device_axis (Handle, axis); + } + + public Gdk.DeviceKey GetDeviceKey (uint axis) { + return gtksharp_gdk_device_get_device_key (Handle, axis); + } diff --git a/gdk/DeviceAxis.custom b/gdk/DeviceAxis.custom index 4cb6e702e..923f9fdbe 100644 --- a/gdk/DeviceAxis.custom +++ b/gdk/DeviceAxis.custom @@ -32,7 +32,7 @@ public override string ToString () { - return "Gdk.DeviceAxis, max:" + this.Max + ",min:" + this.Min; + return "Gdk.DeviceAxis, max:" + this.Max + ",min:" + this.Min + ",use:" + this.Use; } diff --git a/gdk/EventButton.cs b/gdk/EventButton.cs index 88737775b..6f3c1a965 100644 --- a/gdk/EventButton.cs +++ b/gdk/EventButton.cs @@ -104,9 +104,12 @@ namespace Gdk { public double[] Axes { get { - double[] result = new double [2]; + double[] result = null; IntPtr axes = gtksharp_gdk_event_button_get_axes (Handle); - Marshal.Copy (result, 0, axes, 2); + if (axes != IntPtr.Zero) { + result = new double[Device.NumAxes]; + Marshal.Copy (axes, result, 0, result.Length); + } return result; } } diff --git a/gdk/EventMotion.cs b/gdk/EventMotion.cs index 3e95b4db5..938de53e7 100644 --- a/gdk/EventMotion.cs +++ b/gdk/EventMotion.cs @@ -105,9 +105,12 @@ namespace Gdk { public double[] Axes { get { - double[] result = new double [2]; + double[] result = null; IntPtr axes = gtksharp_gdk_event_motion_get_axes (Handle); - Marshal.Copy (result, 0, axes, 2); + if (axes != IntPtr.Zero) { + result = new double [Device.NumAxes]; + Marshal.Copy (axes, result, 0, result.Length); + } return result; } } diff --git a/gdk/Gdk.metadata b/gdk/Gdk.metadata index 85fee2def..957130688 100644 --- a/gdk/Gdk.metadata +++ b/gdk/Gdk.metadata @@ -28,6 +28,9 @@ 1 ref 1 + 1 + 1 + 1 1 1 1 diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 9f6b7c8fa..9d31275cd 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -42,6 +42,7 @@ build_sources = $(addprefix $(srcdir)/, $(sources)) AssemblyInfo.cs customs = \ Atom.custom \ Color.custom \ + Device.custom \ DeviceAxis.custom \ Display.custom \ DisplayManager.custom \ diff --git a/gdk/glue/Makefile.am b/gdk/glue/Makefile.am index 2948eb6c1..2ad38777f 100644 --- a/gdk/glue/Makefile.am +++ b/gdk/glue/Makefile.am @@ -2,6 +2,7 @@ lib_LTLIBRARIES = libgdksharpglue.la libgdksharpglue_la_SOURCES = \ dragcontext.c \ + device.c \ event.c \ selection.c \ vmglueheaders.h \ diff --git a/gdk/glue/device.c b/gdk/glue/device.c new file mode 100644 index 000000000..22e7f4442 --- /dev/null +++ b/gdk/glue/device.c @@ -0,0 +1,84 @@ +/* device.c : Glue to access fields in GdkDevice. + * + * Author: Manuel V. Santos + * + * Copyright (c) Manuel V. Santos + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the Lesser GNU General + * Public License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include + +/* Forward declarations */ +gchar* gtksharp_gdk_device_get_name (GdkDevice *device); +GdkInputSource gtksharp_gdk_device_get_source (GdkDevice *device); +GdkInputMode gtksharp_gdk_device_get_mode (GdkDevice *device); +gboolean gtksharp_gdk_device_has_cursor (GdkDevice *device); +gint gtksharp_gdk_device_get_num_axes (GdkDevice *device); +gint gtksharp_gdk_device_get_num_keys (GdkDevice *device); +GdkDeviceAxis* gtksharp_gdk_device_get_axes (GdkDevice *device); +GdkDeviceKey* gtksharp_gdk_device_get_keys (GdkDevice *device); +/* */ + + +gchar* +gtksharp_gdk_device_get_name (GdkDevice *device) +{ + return device->name; +} + +GdkInputSource +gtksharp_gdk_device_get_source (GdkDevice *device) +{ + return device->source; +} + +GdkInputMode +gtksharp_gdk_device_get_mode (GdkDevice *device) +{ + return device->mode; +} + +gboolean +gtksharp_gdk_device_has_cursor (GdkDevice *device) +{ + return device->has_cursor; +} + +gint +gtksharp_gdk_device_get_num_axes (GdkDevice *device) +{ + return device->num_axes; +} + +gint +gtksharp_gdk_device_get_num_keys (GdkDevice *device) +{ + return device->num_keys; +} + +GdkDeviceAxis +gtksharp_gdk_device_get_device_axis (GdkDevice *device, guint i) +{ + return device->axes[i]; +} + +GdkDeviceKey +gtksharp_gdk_device_get_device_key (GdkDevice *device, guint i) +{ + return device->keys[i]; +} + diff --git a/gdk/glue/makefile.win32 b/gdk/glue/makefile.win32 index 8e152991c..7081f8d9a 100755 --- a/gdk/glue/makefile.win32 +++ b/gdk/glue/makefile.win32 @@ -5,6 +5,7 @@ DLLWRAP=dllwrap -mno-cygwin -mms-bitfields --target i386-mingw32 --export-all-sy GLUE_OBJS = \ dragcontext.o \ + device.o \ event.o \ selection.o \ win32dll.o diff --git a/gtk/InputDialog.custom b/gtk/InputDialog.custom new file mode 100644 index 000000000..5542eb605 --- /dev/null +++ b/gtk/InputDialog.custom @@ -0,0 +1,42 @@ +// Gtk.InputDialog.custom - Gtk InputDialog class customizations +// +// Author: Manuel V. Santos +// +// Copyright (C) 2004 Manuel V. Santos. +// +// This code is inserted after the automatically generated code. +// +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + [DllImport("gtksharpglue")] + static extern IntPtr gtksharp_input_dialog_get_save_button (IntPtr i); + + public Gtk.Button SaveButton { + get { + IntPtr rawButton = gtksharp_input_dialog_get_save_button (Handle); + return new Button (rawButton); + } + } + + [DllImport("gtksharpglue")] + static extern IntPtr gtksharp_input_dialog_get_close_button (IntPtr i); + + public Gtk.Button CloseButton { + get { + IntPtr rawButton = gtksharp_input_dialog_get_close_button (Handle); + return new Button (rawButton); + } + } diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 6cdc8d3d6..3b18aaae3 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -49,6 +49,7 @@ customs = \ IconFactory.custom \ IconSet.custom \ ImageMenuItem.custom \ + InputDialog.custom \ ItemFactory.custom \ Label.custom \ Layout.custom \ diff --git a/gtk/glue/Makefile.am b/gtk/glue/Makefile.am index 9b154f5a5..7dfe67471 100644 --- a/gtk/glue/Makefile.am +++ b/gtk/glue/Makefile.am @@ -10,6 +10,7 @@ libgtksharpglue_la_SOURCES = \ container.c \ dialog.c \ fileselection.c \ + inputdialog.c \ layout.c \ nodestore.c \ object.c \ diff --git a/gtk/glue/inputdialog.c b/gtk/glue/inputdialog.c new file mode 100644 index 000000000..d862ad353 --- /dev/null +++ b/gtk/glue/inputdialog.c @@ -0,0 +1,40 @@ +/* inputdialog.c : Glue for accessing fields in the GtkInputDialog widget. + * + * Author: Manuel V. Santos + * + * Copyright (c) 2004 Manuel V. Santos + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the Lesser GNU General + * Public License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +/* Forward declarations */ +GtkWidget *gtksharp_input_dialog_get_save_button (GtkInputDialog *dialog); + +GtkWidget *gtksharp_input_dialog_get_close_button (GtkInputDialog *dialog); +/* */ + +GtkWidget* +gtksharp_input_dialog_get_save_button (GtkInputDialog *dialog) +{ + return dialog->save_button; +} + +GtkWidget* +gtksharp_input_dialog_get_close_button (GtkInputDialog *dialog) +{ + return dialog->close_button; +} diff --git a/gtk/glue/makefile.win32 b/gtk/glue/makefile.win32 index 8ea9b82b9..8936a106b 100755 --- a/gtk/glue/makefile.win32 +++ b/gtk/glue/makefile.win32 @@ -12,6 +12,7 @@ GLUE_OBJS = \ container.o \ dialog.o \ fileselection.o \ + inputdialog.o \ layout.o \ nodestore.o \ object.o \ diff --git a/sample/Makefile.am b/sample/Makefile.am index b86888b52..597fb6f31 100755 --- a/sample/Makefile.am +++ b/sample/Makefile.am @@ -24,7 +24,7 @@ VTE_TARGETS= VTE_ASSEMBLY= endif -TARGETS = custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe custom-widget.exe $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS) +TARGETS = custom-cellrenderer.exe gtk-hello-world.exe button.exe calendar.exe subclass.exe menu.exe size.exe scribble.exe scribble-xinput.exe treeviewdemo.exe managedtreeviewdemo.exe testdnd.exe custom-widget.exe $(GNOME_TARGETS) $(GLADE_TARGETS) $(VTE_TARGETS) assemblies=../glib/glib-sharp.dll ../pango/pango-sharp.dll ../atk/atk-sharp.dll ../gdk/gdk-sharp.dll ../gtk/gtk-sharp.dll $(GNOME_ASSEMBLY) $(GLADE_ASSEMBLY) $(VTE_ASSEMBLY) references=$(addprefix /r:, $(assemblies)) @@ -65,6 +65,9 @@ size.exe: $(srcdir)/Size.cs $(assemblies) scribble.exe: $(srcdir)/Scribble.cs $(assemblies) $(CSC) /out:scribble.exe $(references) $(srcdir)/Scribble.cs +scribble-xinput.exe: $(srcdir)/ScribbleXInput.cs $(assemblies) + $(CSC) /out:scribble-xinput.exe $(references) $(srcdir)/ScribbleXInput.cs + treeviewdemo.exe: $(srcdir)/TreeViewDemo.cs $(assemblies) $(CSC) /out:treeviewdemo.exe $(references) $(srcdir)/TreeViewDemo.cs @@ -107,6 +110,7 @@ EXTRA_DIST = \ Menu.cs \ Size.cs \ Scribble.cs \ + ScribbleXInput.cs \ TreeViewDemo.cs \ ManagedTreeViewDemo.cs \ GladeViewer.cs \ diff --git a/sample/ScribbleXInput.cs b/sample/ScribbleXInput.cs new file mode 100644 index 000000000..d975426af --- /dev/null +++ b/sample/ScribbleXInput.cs @@ -0,0 +1,166 @@ +// ScribbleXInput.cs - port of Gtk+ scribble demo +// +// Author: Manuel V. Santos +// +// (c) 2002 Rachel Hestilow +// (c) 2004 Manuel V. Santos + +namespace GtkSamples { + + using Gtk; + using Gdk; + using System; + + public class ScribbleXInput { + private static Gtk.Window win; + private static Gtk.VBox vBox; + private static Gtk.Button inputButton; + private static Gtk.Button quitButton; + private static Gtk.DrawingArea darea; + private static Gdk.Pixmap pixmap = null; + private static Gtk.InputDialog inputDialog = null; + + public static int Main (string[] args) { + Application.Init (); + win = new Gtk.Window ("Scribble XInput Demo"); + win.DeleteEvent += new DeleteEventHandler (WindowDelete); + + vBox = new VBox (false, 0); + win.Add (vBox); + + darea = new Gtk.DrawingArea (); + darea.SetSizeRequest (200, 200); + darea.ExtensionEvents=ExtensionMode.Cursor; + vBox.PackStart (darea, true, true, 0); + + darea.ExposeEvent += new ExposeEventHandler (ExposeEvent); + darea.ConfigureEvent += new ConfigureEventHandler (ConfigureEvent); + darea.MotionNotifyEvent += new MotionNotifyEventHandler (MotionNotifyEvent); + darea.ButtonPressEvent += new ButtonPressEventHandler (ButtonPressEvent); + darea.Events = EventMask.ExposureMask | EventMask.LeaveNotifyMask | + EventMask.ButtonPressMask | EventMask.PointerMotionMask; + + inputButton = new Button("Input Dialog"); + vBox.PackStart (inputButton, false, false, 0); + + inputButton.Clicked += new EventHandler (InputButtonClicked); + + quitButton = new Button("Quit"); + vBox.PackStart (quitButton, false, false, 0); + + quitButton.Clicked += new EventHandler (QuitButtonClicked); + + win.ShowAll (); + Application.Run (); + return 0; + } + + static void InputButtonClicked (object obj, EventArgs args) { + if (inputDialog == null) { + inputDialog = new InputDialog (); + inputDialog.SaveButton.Hide (); + inputDialog.CloseButton.Clicked += new EventHandler(InputDialogClose); + inputDialog.DeleteEvent += new DeleteEventHandler(InputDialogDelete); + } + inputDialog.Present (); + } + + static void QuitButtonClicked (object obj, EventArgs args) { + Application.Quit (); + } + + static void WindowDelete (object obj, DeleteEventArgs args) { + Application.Quit (); + args.RetVal = true; + } + + static void InputDialogClose (object obj, EventArgs args) { + inputDialog.Hide (); + } + + static void InputDialogDelete (object obj, DeleteEventArgs args) { + inputDialog.Hide (); + args.RetVal = true; + } + + static void ExposeEvent (object obj, ExposeEventArgs args) { + Gdk.Rectangle area = args.Event.Area; + args.Event.Window.DrawDrawable (darea.Style.ForegroundGC(darea.State), + pixmap, + area.X, area.Y, + area.X, area.Y, + area.Width, area.Height); + + args.RetVal = false; + } + + static void ConfigureEvent (object obj, ConfigureEventArgs args) { + Gdk.EventConfigure ev = args.Event; + Gdk.Window window = ev.Window; + Gdk.Rectangle allocation = darea.Allocation; + + pixmap = new Gdk.Pixmap (window, allocation.Width, allocation.Height, -1); + pixmap.DrawRectangle (darea.Style.WhiteGC, true, 0, 0, + allocation.Width, allocation.Height); + + args.RetVal = true; + } + + static void DrawBrush (Widget widget, InputSource source, + double x, double y, double pressure) { + Gdk.GC gc; + switch (source) { + case InputSource.Mouse: + gc = widget.Style.BlackGC; + break; + case InputSource.Pen: + gc = widget.Style.BlackGC; + break; + case InputSource.Eraser: + gc = widget.Style.WhiteGC; + break; + default: + gc = widget.Style.BlackGC; + break; + } + + Gdk.Rectangle update_rect = new Gdk.Rectangle (); + update_rect.X = (int) (x - 10.0d * pressure); + update_rect.Y = (int) (y - 10.0d * pressure); + update_rect.Width = (int) (20.0d * pressure); + update_rect.Height = (int) (20.0d * pressure); + + pixmap.DrawRectangle (gc, true, + update_rect.X, update_rect.Y, + update_rect.Width, update_rect.Height); + darea.QueueDrawArea (update_rect.X, update_rect.Y, + update_rect.Width, update_rect.Height); + + } + + static void ButtonPressEvent (object obj, ButtonPressEventArgs args) { + Gdk.EventButton ev = args.Event; + + if (ev.Button == 1 && pixmap != null) { + double pressure; + ev.Device.GetAxis (ev.Axes, AxisUse.Pressure, out pressure); + DrawBrush ((Widget) obj, ev.Device.Source, ev.X, ev.Y, pressure); + } + args.RetVal = true; + } + + static void MotionNotifyEvent (object obj, MotionNotifyEventArgs args) { + Gdk.EventMotion ev = args.Event; + Widget widget = (Widget) obj; + if ((ev.State & Gdk.ModifierType.Button1Mask) != 0 && pixmap != null) { + double x,y,pressure; + if (!ev.Device.GetAxis (ev.Axes, AxisUse.Pressure, out pressure)) { + pressure = 0.5; + } + DrawBrush (widget, ev.Device.Source, ev.X, ev.Y, pressure); + } + args.RetVal = true; + } + } +} +