Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
using System;
using System.Runtime.InteropServices;
using Cairo;
namespace Gdk
{
public class Context
{
private Context () {}
// Note: we don't need or want a .dll.config since we p/invoke
// the proper lib based on the os check below
// win32 only imports
[DllImport("libgdk-win32-2.0-0.dll")]
internal static extern IntPtr gdk_win32_hdc_get(IntPtr drawable, IntPtr gc, int usage);
[DllImport("libgdk-win32-2.0-0.dll")]
internal static extern void gdk_win32_hdc_release(IntPtr drawable,IntPtr gc,int usage);
// x11 only imports
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_x11_drawable_get_xdisplay (IntPtr handle);
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_drawable_get_visual (IntPtr handle);
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_x11_visual_get_xvisual (IntPtr handle);
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_x11_drawable_get_xid (IntPtr handle);
public static Cairo.Context CreateDrawable (Gdk.Drawable drawable)
{
return CreateDrawable (drawable, true);
}
public static Cairo.Context CreateDrawable (Gdk.Drawable drawable, bool double_buffered)
{
int x, y, w, h, d;
Cairo.Surface surface;
bool needs_xlate;
((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d);
PlatformID os = Environment.OSVersion.Platform;
needs_xlate = drawable is Gdk.Window && double_buffered;
if (needs_xlate)
((Gdk.Window)drawable).GetInternalPaintInfo (out drawable, out x, out y);
if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT ||
os == PlatformID.Win32S || os == PlatformID.WinCE) {
Gdk.GC gcc = new Gdk.GC (drawable);
IntPtr windc = gdk_win32_hdc_get (drawable.Handle, gcc.Handle, 0);
surface = new Win32Surface (windc);
if (double_buffered)
gdk_win32_hdc_release (drawable.Handle, gcc.Handle, 0);
} else {
IntPtr display = gdk_x11_drawable_get_xdisplay (drawable.Handle);
IntPtr visual = gdk_drawable_get_visual (drawable.Handle);
IntPtr xvisual = gdk_x11_visual_get_xvisual (visual);
IntPtr xdrawable = gdk_x11_drawable_get_xid (drawable.Handle);
surface = new XlibSurface (display, xdrawable, xvisual, w, h);
}
Cairo.Context ctx = new Cairo.Context (surface);
if (needs_xlate)
ctx.Translate (-(double) x, -(double) y);
return ctx;
}
}
}

View File

@@ -0,0 +1,108 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
double xc = 0.5;
double yc = 0.5;
double radius = 0.4;
double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */
double angle2 = 180.0 * (M_PI/180.0); /* in radians */
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.Arc (xc, yc, radius, angle1, angle2);
gr.Stroke ();
/* draw helping lines */
gr.Color = new Color(1, 0.2, 0.2, 0.6);
gr.Arc (xc, yc, 0.05, 0, 2*M_PI);
gr.Fill ();
gr.LineWidth = 0.03;
gr.Arc (xc, yc, radius, angle1, angle1);
gr.LineTo (new PointD(xc, yc));
gr.Arc (xc, yc, radius, angle2, angle2);
gr.LineTo (new PointD(xc, yc));
gr.Stroke ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,104 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
double xc = 0.5;
double yc = 0.5;
double radius = 0.4;
double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */
double angle2 = 180.0 * (M_PI/180.0); /* in radians */
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.ArcNegative (xc, yc, radius, angle1, angle2);
gr.Stroke ();
/* draw helping lines */
gr.Color = new Color(1, 0.2, 0.2, 0.6);
gr.Arc (xc, yc, 0.05, 0, 2*M_PI);
gr.Fill ();
gr.LineWidth = 0.03;
gr.Arc (xc, yc, radius, angle1, angle1);
gr.LineTo (new PointD(xc, yc));
gr.Arc (xc, yc, radius, angle2, angle2);
gr.LineTo (new PointD(xc, yc));
gr.Stroke ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,181 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void oval_path (Cairo.Context gr, double xc, double yc, double xr, double yr)
{
gr.Translate (xc, yc);
gr.Scale (1.0, yr / xr);
gr.MoveTo (new PointD (xr, 0.0) );
gr.Arc (0, 0, xr, 0, 2 * M_PI);
gr.ClosePath ();
}
/*
* Draw a red, green, and blue circle equally spaced inside
* the larger circle of radius r at (xc, yc)
*/
static void draw_3circles (Cairo.Context gr, double xc, double yc, double radius)
{
double subradius = radius * (2 / 3.0 - 0.1);
gr.Color = new Color (1, 0, 0, 0.5);
oval_path (gr,
xc + radius / 3 * Math.Cos (M_PI * (0.5)),
yc - radius / 3 * Math.Sin (M_PI * (0.5)),
subradius, subradius);
gr.Fill ();
gr.Color = new Color (0, 1, 0, 0.5);
oval_path (gr,
xc + radius / 3 * Math.Cos (M_PI * (0.5 + 2/.3)),
yc - radius / 3 * Math.Sin (M_PI * (0.5 + 2/.3)),
subradius, subradius);
gr.Fill ();
gr.Color = new Color (0, 0, 1, 0.5);
oval_path (gr,
xc + radius / 3 * Math.Cos (M_PI * (0.5 + 4/.3)),
yc - radius / 3 * Math.Sin (M_PI * (0.5 + 4/.3)),
subradius, subradius);
gr.Fill ();
}
static void draw (Cairo.Context gr, int width, int height)
{
Surface overlay, punch, circles;
/* Fill the background */
double radius = 0.5 * (width < height ? width : height) - 10;
double xc = width / 2;
double yc = height / 2;
Surface target = gr.Target;
overlay = target.CreateSimilar (Content.ColorAlpha, width, height);
punch = target.CreateSimilar (Content.Alpha, width, height);
circles = target.CreateSimilar (Content.ColorAlpha, width, height);
gr.Save ();
gr.Target = overlay;
/* Draw a black circle on the overlay
*/
gr.Color = new Color (0, 0, 0, 1);
oval_path (gr, xc, yc, radius, radius);
gr.Fill ();
gr.Save ();
gr.Target = punch;
/* Draw 3 circles to the punch surface, then cut
* that out of the main circle in the overlay
*/
draw_3circles (gr, xc, yc, radius);
gr.Restore ();
gr.Operator = Operator.DestOut;
punch.Show (gr, width, height);
/* Now draw the 3 circles in a subgroup again
* at half intensity, and use OperatorAdd to join up
* without seams.
*/
gr.Save ();
gr.Target = circles;
//gr.Alpha = 0.5;
gr.Operator = Operator.Over;
draw_3circles (gr, xc, yc, radius);
gr.Restore ();
gr.Operator = Operator.Add;
circles.Show (gr, width, height);
gr.Restore ();
overlay.Show (gr, width, height);
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,95 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI);
gr.Clip ();
gr.NewPath ();
gr.Rectangle (new PointD (0, 0), 1, 1);
gr.Fill ();
gr.Color = new Color (0, 1, 0, 1);
gr.MoveTo ( new PointD (0, 0) );
gr.LineTo ( new PointD (1, 1) );
gr.MoveTo ( new PointD (1, 0) );
gr.LineTo ( new PointD (0, 1) );
gr.Stroke ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,112 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
int w, h;
ImageSurface image;
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.Arc (0.5, 0.5, 0.3, 0, 2*M_PI);
gr.Clip ();
gr.NewPath ();
image = new ImageSurface("data/e.png");
w = image.Width;
h = image.Height;
gr.Scale (1.0/w, 1.0/h);
image.Show (gr, 0, 0);
image.Destroy();
gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI);
gr.Clip ();
gr.NewPath ();
gr.Rectangle (new PointD (0, 0), 1, 1);
gr.Fill ();
gr.Color = new Color (0, 1, 0, 1);
gr.MoveTo ( new PointD (0, 0) );
gr.LineTo ( new PointD (1, 1) );
gr.MoveTo ( new PointD (1, 0) );
gr.LineTo ( new PointD (0, 1) );
gr.Stroke ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,13 @@
#!/bin/bash
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp circles.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp arc.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp arcneg.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp clip.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp clip_img.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp curve_rect.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp curve_to.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp fillstroke.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp gradient.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp image.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp image_pattern.cs sysdraw.cs
mcs -r:System.Drawing -r:Mono.Cairo -pkg:gtk-sharp text.cs sysdraw.cs

View File

@@ -0,0 +1,206 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static void draw (Cairo.Context gr, int width, int height)
{
double x0 = 0.1;
double y0 = 0.1;
double rect_width = 0.8;
double rect_height = 0.8;
double radius = 0.4;
double x1,y1;
gr.Scale (width, height);
gr.LineWidth = 0.04;
x1=x0+rect_width;
y1=y0+rect_height;
if (rect_width == 0 || rect_height == 0)
return;
if (rect_width/2<radius) {
if (rect_height/2<radius) {
gr.MoveTo( new PointD(x0, (y0 + y1)/2) );
gr.CurveTo ( new PointD (x0 ,y0),
new PointD (x0, y0),
new PointD ((x0 + x1)/2, y0)
);
gr.CurveTo ( new PointD (x1, y0 ),
new PointD (x1, y0 ),
new PointD (x1, (y0 + y1)/2)
);
gr.CurveTo ( new PointD (x1, y1),
new PointD (x1, y1),
new PointD ((x1 + x0)/2, y1)
);
gr.CurveTo ( new PointD (x0, y1),
new PointD (x0, y1),
new PointD (x0, (y0 + y1)/2)
);
}
else {
gr.MoveTo ( new PointD (x0, y0 + radius) );
gr.CurveTo ( new PointD (x0 ,y0),
new PointD (x0, y0),
new PointD ((x0 + x1)/2, y0)
);
gr.CurveTo ( new PointD (x1, y0),
new PointD (x1, y0),
new PointD (x1, y0 + radius)
);
gr.LineTo ( new PointD (x1 , y1 - radius) );
gr.CurveTo ( new PointD (x1, y1),
new PointD (x1, y1),
new PointD ((x1 + x0)/2, y1)
);
gr.CurveTo ( new PointD (x0, y1),
new PointD (x0, y1),
new PointD (x0, y1- radius)
);
}
}
else {
if (rect_height/2<radius) {
gr.MoveTo ( new PointD (x0, (y0 + y1)/2) );
gr.CurveTo ( new PointD (x0 , y0),
new PointD (x0 , y0),
new PointD (x0 + radius, y0)
);
gr.LineTo ( new PointD (x1 - radius, y0) );
gr.CurveTo ( new PointD (x1, y0),
new PointD (x1, y0),
new PointD (x1, (y0 + y1)/2)
);
gr.CurveTo ( new PointD (x1, y1),
new PointD (x1, y1),
new PointD (x1 - radius, y1)
);
gr.LineTo ( new PointD (x0 + radius, y1) );
gr.CurveTo ( new PointD ( x0, y1),
new PointD (x0, y1),
new PointD (x0, (y0 + y1)/2)
);
}
else {
gr.MoveTo ( new PointD (x0, y0 + radius) );
gr.CurveTo ( new PointD (x0 , y0),
new PointD (x0 , y0),
new PointD (x0 + radius, y0)
);
gr.LineTo ( new PointD (x1 - radius, y0) );
gr.CurveTo ( new PointD (x1, y0),
new PointD (x1, y0),
new PointD (x1, y0 + radius)
);
gr.LineTo ( new PointD (x1 , y1 - radius) );
gr.CurveTo ( new PointD ( x1, y1),
new PointD (x1, y1),
new PointD (x1 - radius, y1)
);
gr.LineTo ( new PointD (x0 + radius, y1) );
gr.CurveTo ( new PointD ( x0, y1),
new PointD (x0, y1),
new PointD (x0, y1- radius)
);
}
}
gr.Color = new Color (0.5,0.5,1, 1);
gr.FillPreserve ();
gr.Color = new Color(0.5, 0, 0, 0.5);
gr.Stroke ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,104 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static void draw (Cairo.Context gr, int width, int height)
{
double x=0.1, y=0.5;
double x1=0.4, y1=0.9, x2=0.6, y2=0.1, x3=0.9, y3=0.5;
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.MoveTo ( new PointD (x, y) );
gr.CurveTo ( new PointD (x1, y1),
new PointD (x2, y2),
new PointD (x3, y3)
);
gr.Stroke ();
gr.Color = new Color (1, 0.2, 0.2, 0.6);
gr.LineWidth = 0.03;
gr.MoveTo ( new PointD (x, y) );
gr.LineTo ( new PointD (x1, y1) );
gr.MoveTo ( new PointD (x2, y2) );
gr.LineTo ( new PointD (x3, y3) );
gr.Stroke ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

View File

@@ -0,0 +1,104 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static void draw (Cairo.Context gr, int width, int height)
{
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.MoveTo ( new PointD (0.5, 0.1) );
gr.LineTo ( new PointD (0.9, 0.9) );
gr.RelLineTo ( new Distance (-0.4, 0.0) );
gr.CurveTo ( new PointD (0.2, 0.9),
new PointD ( 0.2, 0.5),
new PointD (0.5, 0.5)
);
gr.ClosePath ();
gr.MoveTo ( new PointD (0.25, 0.1) );
gr.RelLineTo ( new Distance (0.2, 0.2) );
gr.RelLineTo ( new Distance ( -0.2, 0.2) );
gr.RelLineTo ( new Distance (-0.2, -0.2) );
gr.ClosePath ();
gr.Color = new Color (0, 0, 1, 1);
gr.FillPreserve ();
gr.Color = new Color ( 0, 0, 0, 1);
gr.Stroke ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,108 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
gr.Scale (width, height);
gr.LineWidth = 0.04;
LinearGradient pat;
pat = new LinearGradient (0.0, 0.0, 0.0, 1.0);
pat.AddColorStop (1, new Color (0, 0, 0, 1) );
pat.AddColorStop (0, new Color (1, 1, 1, 1) );
gr.Rectangle ( new PointD (0, 0),
1, 1
);
gr.Pattern = pat;
gr.Fill ();
pat.Destroy ();
RadialGradient pat2 = new RadialGradient (0.45, 0.4, 0.1,
0.4, 0.4, 0.5);
pat2.AddColorStop (0, new Color (1, 1, 1, 1) );
pat2.AddColorStop (1, new Color (0, 0, 0, 1) );
gr.Pattern = pat2;
gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI);
gr.Fill ();
pat2.Destroy ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,101 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
int w, h;
ImageSurface image;
gr.Scale (width, height);
gr.LineWidth = 0.04;
image = new ImageSurface ("data/e.png");
w = image.Width;
h = image.Height;
gr.Translate (0.5, 0.5);
gr.Rotate (45* M_PI/180);
gr.Scale (1.0/w, 1.0/h);
gr.Translate (-0.5*w, -0.5*h);
image.Show (gr, 0, 0);
image.Destroy ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,117 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
int w, h;
ImageSurface image;
Matrix matrix;
SurfacePattern pattern;
gr.Scale (width, height);
gr.LineWidth = 0.04;
image = new ImageSurface ("data/e.png");
w = image.Width;
h = image.Height;
pattern = new SurfacePattern (image);
pattern.Extend = Cairo.Extend.Repeat;
gr.Translate (0.5, 0.5);
gr.Rotate (M_PI / 4);
gr.Scale (1 / Math.Sqrt (2), 1 / Math.Sqrt (2));
gr.Translate (- 0.5, - 0.5);
matrix = new Matrix ();
matrix.InitScale (w * 5.0, h * 5.0);
pattern.Matrix = matrix;
gr.Pattern = pattern;
gr.Rectangle ( new PointD (0, 0),
1.0, 1.0);
gr.Fill ();
pattern.Destroy ();
image.Destroy();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,179 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
//gr.Scale (width, height);
//gr.LineWidth = 0.04;
double X_FUZZ = 0.08;
double Y_FUZZ = 0.08;
double X_INNER_RADIUS = 0.3;
double Y_INNER_RADIUS = 0.2;
double X_OUTER_RADIUS = 0.45;
double Y_OUTER_RADIUS = 0.35;
double SPIKES = 10;
int i;
double x;
double y;
string text = "KAPOW!";
cairo_text_extents_t extents;
srand (45);
cairo_set_line_width (cr, 0.01);
for (i = 0; i < SPIKES * 2; i++) {
x = 0.5 + cos (M_PI * i / SPIKES) * X_INNER_RADIUS +
(double) rand() * X_FUZZ / RAND_MAX;
y = 0.5 + sin (M_PI * i / SPIKES) * Y_INNER_RADIUS +
(double) rand() * Y_FUZZ / RAND_MAX;
if (i == 0)
cairo_move_to (cr, x, y);
else
cairo_line_to (cr, x, y);
i++;
x = 0.5 + cos (M_PI * i / SPIKES) * X_OUTER_RADIUS +
(double) rand() * X_FUZZ / RAND_MAX;
y = 0.5 + sin (M_PI * i / SPIKES) * Y_OUTER_RADIUS +
(double) rand() * Y_FUZZ / RAND_MAX;
cairo_line_to (cr, x, y);
}
cairo_close_path (cr);
cairo_stroke (cr);
cairo_select_font_face (cr, "Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_move_to (cr, x, y);
cairo_text_path (cr, text);
cairo_set_font_size (cr, 0.2);
cairo_text_extents (cr, text, &extents);
x = 0.5-(extents.width/2 + extents.x_bearing);
y = 0.5-(extents.height/2 + extents.y_bearing);
cairo_set_source_rgb (cr, 1 , 1, 0.5);
cairo_fill (cr);
cairo_move_to (cr, x, y);
cairo_text_path (cr, text);
cairo_set_source_rgb (cr, 0 , 0, 0);
cairo_stroke (cr);
gr.Arc (xc, yc, radius, angle1, angle2);
gr.Stroke ();
/* draw helping lines */
gr.Color = new Color(1, 0.2, 0.2, 0.6);
gr.Arc (xc, yc, 0.05, 0, 2*M_PI);
gr.Fill ();
gr.LineWidth = 0.03;
gr.Arc (xc, yc, radius, angle1, angle1);
gr.LineTo (new PointD(xc, yc));
gr.Arc (xc, yc, radius, angle2, angle2);
gr.LineTo (new PointD(xc, yc));
gr.Stroke ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}

View File

@@ -0,0 +1,114 @@
//
//
// GDK-X11 interface
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Gtk;
using Cairo;
namespace Gdk
{
public class Context
{
// Note: we don't need or want a .dll.config since we p/invoke
// the proper lib based on the os check below
// win32 only imports
[DllImport("libgdk-win32-2.0-0.dll")]
internal static extern IntPtr gdk_win32_hdc_get(IntPtr drawable, IntPtr gc, int usage);
[DllImport("libgdk-win32-2.0-0.dll")]
internal static extern void gdk_win32_hdc_release(IntPtr drawable,IntPtr gc,int usage);
// x11 only imports
[DllImport("libgdk-x11-2.0.so")]
internal static extern IntPtr gdk_x11_drawable_get_xdisplay (IntPtr raw);
[DllImport("libgdk-x11-2.0.so")]
internal static extern IntPtr gdk_x11_drawable_get_xid (IntPtr raw);
[DllImport("libgdk-x11-2.0.so")]
internal static extern IntPtr gdk_drawable_get_visual (IntPtr raw);
[DllImport("libgdk-x11-2.0.so")]
internal static extern IntPtr gdk_x11_visual_get_xvisual (IntPtr raw);
[DllImport("libgdk-x11-2.0.so")]
internal static extern IntPtr gdk_cairo_create (IntPtr raw);
public static Cairo.Context CreateDrawable (Gdk.Drawable drawable)
{
IntPtr x_drawable = IntPtr.Zero;
int x_off = 0, y_off = 0;
int x, y, w, h, d;
((Gdk.Window)drawable).GetGeometry(out x, out y, out w, out h, out d);
bool is_gdk_window = drawable is Gdk.Window;
if (is_gdk_window)
((Gdk.Window) drawable).GetInternalPaintInfo(out drawable,
out x_off, out y_off);
Cairo.Surface surface;
PlatformID os = Environment.OSVersion.Platform;
if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT ||
os == PlatformID.Win32S || os == PlatformID.WinCE) {
Gdk.GC gcc = new Gdk.GC (drawable);
IntPtr windc = gdk_win32_hdc_get (drawable.Handle, gcc.Handle, 0);
surface = new Win32Surface (windc);
gdk_win32_hdc_release (drawable.Handle, gcc.Handle, 0);
} else {
x_drawable = drawable.Handle;
IntPtr visual = gdk_drawable_get_visual(x_drawable);
IntPtr Xdisplay = gdk_x11_drawable_get_xdisplay(x_drawable);
IntPtr Xvisual = gdk_x11_visual_get_xvisual(visual);
IntPtr Xdrawable = gdk_x11_drawable_get_xid (x_drawable);
surface = new Cairo.XlibSurface (Xdisplay,
Xdrawable,
Xvisual,
w, h);
}
Cairo.Context g = new Cairo.Context (surface);
// this can be safely removed now, just keep it for a bit more
//Cairo.Context g = new Cairo.Context (
// gdk_cairo_create (x_drawable ));
if (is_gdk_window)
g.Translate (-(double)x_off,-(double)y_off);
return g;
}
}
}

View File

@@ -0,0 +1,104 @@
//
//
// Mono.Cairo drawing samples using GTK# as drawing surface
// Hisham Mardam Bey <hisham@hisham.cc>
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Cairo;
using Gtk;
public class GtkCairo
{
static DrawingArea a;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
a = new CairoGraphic ();
Box box = new HBox (true, 0);
box.Add (a);
w.Add (box);
w.Resize (500,500);
w.ShowAll ();
Application.Run ();
}
}
public class CairoGraphic : DrawingArea
{
static readonly double M_PI = 3.14159265358979323846;
static void draw (Cairo.Context gr, int width, int height)
{
gr.Scale (width, height);
gr.LineWidth = 0.04;
gr.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Bold);
gr.SetFontSize (0.35);
gr.MoveTo ( new PointD(0.04, 0.53) );
gr.ShowText ("Hello");
gr.MoveTo ( new PointD(0.27, 0.65) );
gr.TextPath ("void");
gr.ColorRgb = new Color (0.5, 0.5, 1, 0);
gr.FillPreserve ();
gr.ColorRgb = new Color (0, 0, 0, 0);
gr.LineWidth = 0.01;
gr.Stroke ();
gr.Color = new Color (1,0.2,0.2, 0.6);
gr.Arc (0.04, 0.53, 0.02, 0, 2*M_PI);
gr.Arc (0.27, 0.65, 0.02, 0, 2*M_PI);
gr.Fill ();
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
//Gdk.Rectangle area = args.Area;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
int x, y, w, h, d;
win.GetGeometry(out x, out y, out w, out h, out d);
draw (g, w, h);
return true;
}
}