diff --git a/ChangeLog b/ChangeLog index e2b06b882..1c405dc1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-08-05 Rachel Hestilow + + * gnome/Canvas*.custom, IconTextItem.custom: Added. + + * sample/CanvasExample.cs: Added. + * sample/Makefile.in: Build canvas example in gnome build. + 2002-08-05 Rachel Hestilow * parser/Gnome.metadata: Patch from duncan for diff --git a/gnome/CanvasBpath.custom b/gnome/CanvasBpath.custom new file mode 100644 index 000000000..d744b1a1c --- /dev/null +++ b/gnome/CanvasBpath.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasBpath.custom - Gnome CanvasBpath class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasBpath (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasClipgroup.custom b/gnome/CanvasClipgroup.custom new file mode 100644 index 000000000..d42b16375 --- /dev/null +++ b/gnome/CanvasClipgroup.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasClipgroup.custom - Gnome CanvasClipgroup class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasClipgroup (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasEllipse.custom b/gnome/CanvasEllipse.custom new file mode 100644 index 000000000..9ecea43d7 --- /dev/null +++ b/gnome/CanvasEllipse.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasEllipse.custom - Gnome CanvasEllipse class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasEllipse (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasGroup.custom b/gnome/CanvasGroup.custom new file mode 100644 index 000000000..da75cefb5 --- /dev/null +++ b/gnome/CanvasGroup.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasGroup.custom - Gnome CanvasGroup class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +protected CanvasGroup (Gnome.CanvasGroup group, int type) : base (group, type) +{ +} + diff --git a/gnome/CanvasItem.custom b/gnome/CanvasItem.custom new file mode 100644 index 000000000..bc8e36c08 --- /dev/null +++ b/gnome/CanvasItem.custom @@ -0,0 +1,19 @@ +// +// Gnome.CanvasItem.custom - Gnome CanvasItem class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + + +[DllImport("gnomecanvas-2")] +static extern System.IntPtr gnome_canvas_item_new (IntPtr group, int type, IntPtr null_terminator); + +public CanvasItem (Gnome.CanvasGroup group, int type) +{ + Raw = gnome_canvas_item_new (group.Handle, type, IntPtr.Zero); +} + diff --git a/gnome/CanvasLine.custom b/gnome/CanvasLine.custom new file mode 100644 index 000000000..2daa25c8c --- /dev/null +++ b/gnome/CanvasLine.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasLine.custom - Gnome CanvasLine class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasLine (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasPixbuf.custom b/gnome/CanvasPixbuf.custom new file mode 100644 index 000000000..d52651e09 --- /dev/null +++ b/gnome/CanvasPixbuf.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasPixbuf.custom - Gnome CanvasPixbuf class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasPixbuf (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasPolygon.custom b/gnome/CanvasPolygon.custom new file mode 100644 index 000000000..5c53013ae --- /dev/null +++ b/gnome/CanvasPolygon.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasPolygon.custom - Gnome CanvasPolygon class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasPolygon (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasRE.custom b/gnome/CanvasRE.custom new file mode 100644 index 000000000..8f1e41d06 --- /dev/null +++ b/gnome/CanvasRE.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasRE.custom - Gnome CanvasRE class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +protected CanvasRE (Gnome.CanvasGroup group, int type) : base (group, type) +{ +} + diff --git a/gnome/CanvasRect.custom b/gnome/CanvasRect.custom new file mode 100644 index 000000000..ef3833fa1 --- /dev/null +++ b/gnome/CanvasRect.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasRect.custom - Gnome CanvasRect class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasRect (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasRichText.custom b/gnome/CanvasRichText.custom new file mode 100644 index 000000000..1151121ee --- /dev/null +++ b/gnome/CanvasRichText.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasRichText.custom - Gnome CanvasRichText class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasRichText (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasShape.custom b/gnome/CanvasShape.custom new file mode 100644 index 000000000..f824f8af5 --- /dev/null +++ b/gnome/CanvasShape.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasShape.custom - Gnome CanvasShape class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +protected CanvasShape (Gnome.CanvasGroup group, int type) : base (group, type) +{ +} + diff --git a/gnome/CanvasText.custom b/gnome/CanvasText.custom new file mode 100644 index 000000000..635dadeef --- /dev/null +++ b/gnome/CanvasText.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasText.custom - Gnome CanvasText class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasText (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/CanvasWidget.custom b/gnome/CanvasWidget.custom new file mode 100644 index 000000000..cfc611caa --- /dev/null +++ b/gnome/CanvasWidget.custom @@ -0,0 +1,14 @@ +// +// Gnome.CanvasWidget.custom - Gnome CanvasWidget class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public CanvasWidget (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/gnome/IconTextItem.custom b/gnome/IconTextItem.custom new file mode 100644 index 000000000..1d76c6e38 --- /dev/null +++ b/gnome/IconTextItem.custom @@ -0,0 +1,14 @@ +// +// Gnome.IconTextItem.custom - Gnome IconTextItem class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +public IconTextItem (Gnome.CanvasGroup group) : base (group, Type) +{ +} + diff --git a/sample/CanvasExample.cs b/sample/CanvasExample.cs new file mode 100644 index 000000000..3b6e4137d --- /dev/null +++ b/sample/CanvasExample.cs @@ -0,0 +1,182 @@ +// Canvas.cs - port of standard GNOME canvas demo +// +// Author: Rachel Hestilow +// +// (c) 2002 Rachel Hestilow + +namespace GtkSamples { + + using Gnome; + using Gtk; + using Gdk; + using GtkSharp; + using System; + + public class CanvasExample { + private int width = 400, height = 400; + private double remember_x = 0.0, remember_y = 0.0; + + private Canvas canvas; + private Random random = new Random (); + + public CanvasExample () { + Gtk.Window win = new Gtk.Window ("Canvas example"); + win.DeleteEvent += new DeleteEventHandler (Window_Delete); + + VBox vbox = new VBox (false, 0); + win.Add (vbox); + + vbox.PackStart (new Label ("Drag - move object.\n" + + "Double click - change color\n" + + "Right click - delete object"), + false, false, 0); + + canvas = new Canvas (); + canvas.SetSizeRequest (width, height); + canvas.SetScrollRegion (0.0, 0.0, (double) width, (double) height); + vbox.PackStart (canvas, false, false, 0); + + HBox hbox = new HBox (false, 0); + vbox.PackStart (hbox, false, false, 0); + + Button add_button = new Button ("Add an object"); + add_button.Clicked += new EventHandler (AddObject); + hbox.PackStart (add_button, false, false, 0); + + Button quit_button = new Button ("Quit"); + quit_button.Clicked += new EventHandler (Quit); + hbox.PackStart (quit_button, false, false, 0); + + win.ShowAll (); + } + + void Swap (ref double a, ref double b) { + double tmp = a; + a = b; + b = tmp; + } + + void AddObject (object obj, EventArgs args) + { + double x1 = random.Next (width); + double y1 = random.Next (height); + double x2 = random.Next (width); + double y2 = random.Next (height); + + if (x1 > x2) + Swap (ref x1, ref x2); + + if (y1 > y2) + Swap (ref y1, ref y2); + + if ((x2 - x1) < 10) + x2 += 10; + + if ((y2 - y1) < 10) + y2 += 10; + + CanvasRE item = null; + if (random.Next (2) > 0) + item = new CanvasRect (canvas.Root ()); + else + item = new CanvasEllipse (canvas.Root ()); + + item.X1 = x1; + item.Y1 = y1; + item.X2 = x2; + item.Y2 = y2; + item.FillColor = "white"; + item.OutlineColor = "black"; + item.WidthUnits = 1.0; + + item.CanvasEvent += new CanvasEventHandler (Item_Event); + } + + void ChangeItemColor (CanvasRE item) + { + string[] colors = new string[] {"red", "yellow", "green", "cyan", "blue", "magenta"}; + item.FillColor = colors[random.Next (colors.Length)]; + } + + void Item_Event (object obj, CanvasEventArgs args) { + EventButton ev = EventButton.New (args.Event.Handle); + SignalArgs sa = (SignalArgs) args; + CanvasRE item = (CanvasRE) obj; + + switch (ev.type) { + case EventType.ButtonPress: + if (ev.button == 1) { + remember_x = ev.x; + remember_y = ev.y; + sa.RetVal = true; + return; + } else if (ev.button == 3) { + item.Destroy (); + sa.RetVal = true; + return; + } + case EventType.TwoButtonPress: + ChangeItemColor (item); + sa.RetVal = true; + return; + case EventType.MotionNotify: + Gdk.ModifierType state = (Gdk.ModifierType) ev.state; + if ((state & Gdk.ModifierType.Button1Mask) != 0) { + double new_x = ev.x, new_y = ev.y; + item.Move (new_x - remember_x, new_y - remember_y); + remember_x = new_x; + remember_y = new_y; + sa.RetVal = true; + return; + } + break; + case EventType.EnterNotify: + item.WidthUnits = 3.0; + sa.RetVal = true; + return; + case EventType.LeaveNotify: + item.WidthUnits = 1.0; + sa.RetVal = true; + return; + } + + sa.RetVal = false; + return; + } + + void Quit (object obj, EventArgs args) + { + Application.Quit (); + } + + void Window_Delete (object obj, DeleteEventArgs args) + { + SignalArgs sa = (SignalArgs) args; + Application.Quit (); + sa.RetVal = true; + } + + void Quit (object obj, EventArgs args) + { + Application.Quit (); + } + + void Window_Delete (object obj, DeleteEventArgs args) + { + SignalArgs sa = (SignalArgs) args; + Application.Quit (); + sa.RetVal = true; + } + + public static int Main (string[] args) + { + Application.Init (); + + CanvasExample example = new CanvasExample (); + + Application.Run (); + return 0; + } + } +} + diff --git a/sample/Makefile.in b/sample/Makefile.in index 4062b2657..d6a45c016 100755 --- a/sample/Makefile.in +++ b/sample/Makefile.in @@ -2,7 +2,7 @@ MCS=mcs @ENABLE_GNOME_TRUE@ GNOME_PATH=-L ../gnome @ENABLE_GNOME_TRUE@ GNOME_ASSEMBLY=-r gnome-sharp.dll -@ENABLE_GNOME_TRUE@ GNOME_TARGETS=gnome-hello-world.exe +@ENABLE_GNOME_TRUE@ GNOME_TARGETS=gnome-hello-world.exe canvas-example.exe local_paths=-L ../glib -L ../pango -L ../atk -L ../gdk -L ../gtk $(GNOME_PATH) all_assemblies=-r glib-sharp.dll -r pango-sharp.dll -r atk-sharp.dll -r gdk-sharp.dll -r gtk-sharp.dll $(GNOME_ASSEMBLY) -r System.Drawing @@ -22,6 +22,9 @@ gtk-hello-world.exe: HelloWorld.cs gnome-hello-world.exe: GnomeHelloWorld.cs $(MCS) --unsafe -o gnome-hello-world.exe $(local_paths) $(all_assemblies) GnomeHelloWorld.cs +canvas-example.exe: CanvasExample.cs + $(MCS) --unsafe -o canvas-example.exe $(local_paths) $(all_assemblies) CanvasExample.cs + button.exe: ButtonApp.cs $(MCS) --unsafe -o button.exe $(local_paths) $(all_assemblies) ButtonApp.cs