diff --git a/sample/CairoSample.cs b/sample/CairoSample.cs index 407455d1e..fa7ff50dd 100644 --- a/sample/CairoSample.cs +++ b/sample/CairoSample.cs @@ -34,7 +34,7 @@ class X { { int offx, offy; - using (Cairo.Graphics o = args.Event.window.CairoGraphics (out offx, out offy)){ + using (Cairo.Graphics o = GtkCairo.GraphicsFromWindow (args.Event.Window, out offx, out offy)){ o.SetRGBColor (1, 0, 0); o.Translate (-offx, -offy); o.MoveTo (0, 0); @@ -52,15 +52,15 @@ class X { static void CirclesExposeHandler (object obj, ExposeEventArgs args) { - Rectangle area = args.Event.area; - Gdk.Window window = args.Event.window; - Pixmap p = new Pixmap (window, area.width, area.height, -1); + Rectangle area = args.Event.Area; + Gdk.Window window = args.Event.Window; + Pixmap p = new Pixmap (window, area.Width, area.Height, -1); int x, y; //Cairo.Object o = p.CairoGraphics (); - using (Cairo.Graphics o = window.CairoGraphics (out x, out y)) + using (Cairo.Graphics o = GtkCairo.GraphicsFromWindow (window, out x, out y)) { - o.Translate (-area.x, -area.y); + o.Translate (-area.X, -area.Y); DrawCircles (o, rect); //using (Gdk.GC gc = new Gdk.GC (window)){ @@ -101,8 +101,8 @@ class X { o.Restore (); // Fill the surface with the check - o.SetPattern (check); - o.Rectangle (0, 0, rect.width, rect.height); + //o.SetPattern (check); + o.Rectangle (0, 0, rect.Width, rect.Height); o.Fill (); #endif } @@ -111,7 +111,7 @@ class X { o.Alpha = 0.5; Console.WriteLine (rect); o.MoveTo (0, 0); - o.LineTo (rect.width, rect.height); + o.LineTo (rect.Width, rect.Height); o.Stroke (); } } diff --git a/sample/GtkCairo.cs b/sample/GtkCairo.cs new file mode 100644 index 000000000..19cd92afa --- /dev/null +++ b/sample/GtkCairo.cs @@ -0,0 +1,46 @@ +using System; +using Cairo; +using System.Runtime.InteropServices; + +public class GtkCairo { + +#region You can cut and paste this into your application + [DllImport("libgdk-win32-2.0-0.dll")] + static extern IntPtr gdk_x11_drawable_get_xdisplay (IntPtr raw); + + [DllImport("libgdk-win32-2.0-0.dll")] + static extern IntPtr gdk_x11_drawable_get_xid (IntPtr raw); + + [DllImport("libgdk-win32-2.0-0.dll")] + static extern void gdk_window_get_internal_paint_info(IntPtr raw, out IntPtr real_drawable, out int x_offset, out int y_offset); + + static public Cairo.Graphics GraphicsFromWindow (Gdk.Window window, out int offset_x, out int offset_y) + { + IntPtr real_drawable; + Cairo.Graphics o = new Cairo.Graphics (); + + gdk_window_get_internal_paint_info (window.Handle, out real_drawable, out offset_x, out offset_y); + IntPtr x11 = gdk_x11_drawable_get_xid (real_drawable); + IntPtr display = gdk_x11_drawable_get_xdisplay (real_drawable); + o.SetTargetDrawable (display, x11); + + return o; + } + + static public Cairo.Graphics GraphicsFromDrawable (Gdk.Drawable drawable) + { + Cairo.Graphics o = new Cairo.Graphics (); + + IntPtr display = gdk_x11_drawable_get_xdisplay (drawable.Handle); + o.SetTargetDrawable (display, gdk_x11_drawable_get_xid (drawable.Handle)); + + return o; + } + + static GtkCairo () + { + + } + +#endregion +} diff --git a/sample/Makefile.am b/sample/Makefile.am index 597fb6f31..53e912db4 100755 --- a/sample/Makefile.am +++ b/sample/Makefile.am @@ -80,8 +80,8 @@ glade-viewer.exe: $(srcdir)/GladeViewer.cs $(assemblies) glade-test.exe: $(srcdir)/GladeTest.cs $(srcdir)/test.glade $(assemblies) $(CSC) /resource:$(srcdir)/test.glade,test.glade /out:glade-test.exe $(references) $(srcdir)/GladeTest.cs -cairo-sample.exe: $(srcdir)/CairoSample.cs $(assemblies) - $(CSC) /out:cairo-sample.exe $(references) /r:Mono.Cairo $(srcdir)/CairoSample.cs +cairo-sample.exe: $(srcdir)/CairoSample.cs $(srcdir)/GtkCairo.cs $(assemblies) + $(CSC) /out:cairo-sample.exe $(references) /r:Mono.Cairo $(srcdir)/CairoSample.cs $(srcdir)/GtkCairo.cs testdnd.exe: $(srcdir)/TestDnd.cs $(assemblies) $(CSC) /debug /unsafe /out:testdnd.exe $(references) $(srcdir)/TestDnd.cs @@ -123,4 +123,5 @@ EXTRA_DIST = \ DrawingSample.cs \ sysdraw.cs \ drawing-sample.exe.config \ + cairo-sample.exe.config \ CustomWidget.cs diff --git a/sample/cairo-sample.exe.config.in b/sample/cairo-sample.exe.config.in new file mode 100644 index 000000000..0924374e0 --- /dev/null +++ b/sample/cairo-sample.exe.config.in @@ -0,0 +1,6 @@ + + + + + +