Update Cairo Sample
svn path=/trunk/gtk-sharp/; revision=33460
This commit is contained in:
parent
5a116de32a
commit
e474831d5e
4 changed files with 64 additions and 11 deletions
|
@ -34,7 +34,7 @@ class X {
|
||||||
{
|
{
|
||||||
int offx, offy;
|
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.SetRGBColor (1, 0, 0);
|
||||||
o.Translate (-offx, -offy);
|
o.Translate (-offx, -offy);
|
||||||
o.MoveTo (0, 0);
|
o.MoveTo (0, 0);
|
||||||
|
@ -52,15 +52,15 @@ class X {
|
||||||
|
|
||||||
static void CirclesExposeHandler (object obj, ExposeEventArgs args)
|
static void CirclesExposeHandler (object obj, ExposeEventArgs args)
|
||||||
{
|
{
|
||||||
Rectangle area = args.Event.area;
|
Rectangle area = args.Event.Area;
|
||||||
Gdk.Window window = args.Event.window;
|
Gdk.Window window = args.Event.Window;
|
||||||
Pixmap p = new Pixmap (window, area.width, area.height, -1);
|
Pixmap p = new Pixmap (window, area.Width, area.Height, -1);
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
//Cairo.Object o = p.CairoGraphics ();
|
//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);
|
DrawCircles (o, rect);
|
||||||
|
|
||||||
//using (Gdk.GC gc = new Gdk.GC (window)){
|
//using (Gdk.GC gc = new Gdk.GC (window)){
|
||||||
|
@ -101,8 +101,8 @@ class X {
|
||||||
o.Restore ();
|
o.Restore ();
|
||||||
|
|
||||||
// Fill the surface with the check
|
// Fill the surface with the check
|
||||||
o.SetPattern (check);
|
//o.SetPattern (check);
|
||||||
o.Rectangle (0, 0, rect.width, rect.height);
|
o.Rectangle (0, 0, rect.Width, rect.Height);
|
||||||
o.Fill ();
|
o.Fill ();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ class X {
|
||||||
o.Alpha = 0.5;
|
o.Alpha = 0.5;
|
||||||
Console.WriteLine (rect);
|
Console.WriteLine (rect);
|
||||||
o.MoveTo (0, 0);
|
o.MoveTo (0, 0);
|
||||||
o.LineTo (rect.width, rect.height);
|
o.LineTo (rect.Width, rect.Height);
|
||||||
o.Stroke ();
|
o.Stroke ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
46
sample/GtkCairo.cs
Normal file
46
sample/GtkCairo.cs
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -80,8 +80,8 @@ glade-viewer.exe: $(srcdir)/GladeViewer.cs $(assemblies)
|
||||||
glade-test.exe: $(srcdir)/GladeTest.cs $(srcdir)/test.glade $(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
|
$(CSC) /resource:$(srcdir)/test.glade,test.glade /out:glade-test.exe $(references) $(srcdir)/GladeTest.cs
|
||||||
|
|
||||||
cairo-sample.exe: $(srcdir)/CairoSample.cs $(assemblies)
|
cairo-sample.exe: $(srcdir)/CairoSample.cs $(srcdir)/GtkCairo.cs $(assemblies)
|
||||||
$(CSC) /out:cairo-sample.exe $(references) /r:Mono.Cairo $(srcdir)/CairoSample.cs
|
$(CSC) /out:cairo-sample.exe $(references) /r:Mono.Cairo $(srcdir)/CairoSample.cs $(srcdir)/GtkCairo.cs
|
||||||
|
|
||||||
testdnd.exe: $(srcdir)/TestDnd.cs $(assemblies)
|
testdnd.exe: $(srcdir)/TestDnd.cs $(assemblies)
|
||||||
$(CSC) /debug /unsafe /out:testdnd.exe $(references) $(srcdir)/TestDnd.cs
|
$(CSC) /debug /unsafe /out:testdnd.exe $(references) $(srcdir)/TestDnd.cs
|
||||||
|
@ -123,4 +123,5 @@ EXTRA_DIST = \
|
||||||
DrawingSample.cs \
|
DrawingSample.cs \
|
||||||
sysdraw.cs \
|
sysdraw.cs \
|
||||||
drawing-sample.exe.config \
|
drawing-sample.exe.config \
|
||||||
|
cairo-sample.exe.config \
|
||||||
CustomWidget.cs
|
CustomWidget.cs
|
||||||
|
|
6
sample/cairo-sample.exe.config.in
Normal file
6
sample/cairo-sample.exe.config.in
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<configuration>
|
||||||
|
<dllmap dll="libglib-2.0-0.dll" target="libglib-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
||||||
|
<dllmap dll="libgobject-2.0-0.dll" target="libgobject-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
||||||
|
<dllmap dll="libgdk-win32-2.0-0.dll" target="libgdk-x11-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
||||||
|
<dllmap dll="libgdk_pixbuf-2.0-0.dll" target="libgdk_pixbuf-2.0@LIB_PREFIX@.0@LIB_SUFFIX@"/>
|
||||||
|
</configuration>
|
Loading…
Reference in a new issue