Mono Class Library: Cairo Namespace

Cairo.Context Class

This is the main object when drawing with Cairo. [Edit]

See Also: Context Members

public class Context : IDisposable

Remarks

C# Example
// This example sets up a surface on a GTK window and draws an arc to it. 
// More examples are available in the samples directory in mcs/classes/Mono.Cairo
//
// Compile like this:
//    mcs sample.cs -pkg:gtk-sharp-2.0 -r:Mono.Cairo
//
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;                

		#if OLD_SYSTEMS
		//
		// For old versions of Gtk# (before 2.8), you need the helper class
		// available in gtk-sharp/sample/GtkCairo.cs
		//
                Cairo.Context g = Gdk.Graphics.CreateDrawable (win);
                #else
		//
		// Starting with Gtk 2.8 Gtk has direct support for
		// Cairo, as its built on top of it, on older
		// versions, a helper routine is used
		//
                Context g = Gdk.CairoHelper.Create (args.Window);
		#endif

                int x, y, w, h, d;
                win.GetGeometry(out x, out y, out w, out h, out d);

                draw (g, w, h);
                return true;
        }
}
  

[Edit]

Requirements

Namespace: Cairo
Assembly: Mono.Cairo (in Mono.Cairo.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0