[Gtk-sharp-list] gnome canvas line / polygon

Max Stekelenburg max.stekelenburg@planet.nl
Mon, 14 Apr 2003 06:27:17 +0200


--Boundary_(ID_5MvZ6r3tm5DMemtjfNXaAw)
Content-type: text/plain
Content-transfer-encoding: 7BIT

On Sat, 2003-04-12 at 20:48, Miguel de Icaza wrote:
> Hello,
> 
> > I seem to unable to figure out how to get a line or a polygon in the
> > canvas. CanvasRect,CanvasEllipse and CanvasText work fine.
> > 
> > I tried using just gnome# e.g:
> 
> Could you please post a complete sample, so we can try to debug it?
> 
> Miguel
Ok here is an example of a line based on points, a poly on points and a
poly on pathdef (which works).
You probably need to stretch the window a little to see the poly based
on pathdef.
Also there is a trial to get it working by instantiating the points
through dll calls but some versions did not compile or resulted in
assertions. None did work.


--Boundary_(ID_5MvZ6r3tm5DMemtjfNXaAw)
Content-type: text/plain; name=test.cs; charset=ANSI_X3.4-1968
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=test.cs

namespace GtkSamples {
	using Gnome;
	using Gtk;
	using Gdk;
	using GtkSharp;
	using System;
	using System.Collections;
	using System.ComponentModel;
	using System.Reflection;
	using System.Runtime.InteropServices;
	class test {
		static void Window_Delete (object obj, DeleteEventArgs args)
		{
			SignalArgs sa = (SignalArgs) args;
			Application.Quit ();
			sa.RetVal = true;
		}
		static Canvas canvas;
		public static int Main (string[] args)
		{
			Application.Init ();
			Gtk.Window win = new Gtk.Window ("Canvas example");
			win.DeleteEvent += new DeleteEventHandler (Window_Delete);
			VBox vbox = new VBox (false, 0);
			canvas = new Canvas ();
			ScrolledWindow sw=new ScrolledWindow();
			sw.Add(canvas);
			win.Add (sw);
			win.ShowAll ();

			CanvasLine line = new CanvasLine(canvas.Root());
			line.FillColor="green";
			line.ArrowShapeA=6.0;
			line.ArrowShapeB=6.0;
			line.ArrowShapeC=6.0;
			line.WidthUnits=3.0;
			line.LastArrowhead=true;
			line.FirstArrowhead=true;
			double [] pts={65,5,85,45};
			line.Points=CanvasPoints.New(pts);
			
			CanvasPolygon poly=new CanvasPolygon(canvas.Root());
			double [] pts2={95,5,95,45,115,45};
			poly.Points=CanvasPoints.New(pts2);
			poly.FillColor="red";
			poly.WidthUnits=3.0;
			poly.OutlineColor="green";
			
			CanvasPolygon poly2=new CanvasPolygon(canvas.Root());
			CanvasPathDef cpd=new CanvasPathDef();
			cpd.MoveTo(145,45);
			cpd.LineTo(125,5);
			poly2.PathDef=cpd;
			poly2.FillColor="red";
			poly2.WidthUnits=3.0;
			poly2.OutlineColor="green";
			Application.Run ();
			
			/*
			*/
			return 0;
		}
		[DllImport("gnomecanvas-2")]
		static extern IntPtr gnome_canvas_points_new(int num_points);
		[DllImport("gnomecanvas-2")]
		static extern IntPtr gnome_canvas_item_new(IntPtr group, uint type,IntPtr null_terminator);
		[DllImport("gnomecanvas-2")]
		static extern uint gnome_canvas_polygon_get_type();
		[DllImport("libgobject-2.0-0.dll")]
		static extern void g_object_set_property(IntPtr obj,string name,IntPtr val);
		[DllImport("gtksharpglue")]
		static extern System.IntPtr gtksharp_gnome_canvas_points_new_from_array(uint num_points,double[] coords);
		static extern System.IntPtr gtksharp_value_create(uint type);
		[DllImport("libgobject-2.0-0.dll")]
		static extern void g_value_set_pointer(IntPtr val,IntPtr data);
		static void addpoly(){
			/*
			IntPtr points=gnome_canvas_points_new(3);
			unsafe {
			points->coords[0]= 5.0;
			points->coords[1]= 5.0;
			points->coords[2]= 10.0;
			points->coords[3]= 10.0;
			points->coords[4]= 5.0;
			points->coords[5]= 10.0;
			}
			*/
			double[] coords={5.0,5.0,40.0,40.0,5.0,40.0};
			IntPtr points=gtksharp_gnome_canvas_points_new_from_array((uint) coords.Length/2,coords);
			System.Console.WriteLine("1 {0}",points);
			IntPtr item=gnome_canvas_item_new(canvas.Root().Handle,gnome_canvas_polygon_get_type(),IntPtr.Zero);
			System.Console.WriteLine("2");
			//g_object_set_property(item,"points",points);//is not GObject
			//g_object_set_property(item,"points",new GLib.Value(points,IntPtr.Zero).Handle);
			//IntPtr val=gtksharp_value_create(18<<2);
			GLib.Value v=new GLib.Value(points,"GnomeCanvasPoints");
			//g_value_set_pointer(val,points);
			//g_object_set_property(item,"points",val);//is not GObject
			System.Console.WriteLine("3");
			g_object_set_property(item,"fill_color",new GLib.Value("tan").Handle);
			System.Console.WriteLine("1");
			g_object_set_property(item,"outline_color",new GLib.Value("black").Handle);
			System.Console.WriteLine("1");
			g_object_set_property(item,"width_units",new GLib.Value(3.0).Handle);
			System.Console.WriteLine("1");
			//setup_item(item);
			//gnome_canvas_points_unref(points);
		}
	}
}


--Boundary_(ID_5MvZ6r3tm5DMemtjfNXaAw)--