3 // Mono.Cairo drawing samples using GTK# as drawing surface
4 // Autor: Jordi Mas <jordi@ximian.com>. Based on work from Owen Taylor
5 // Hisham Mardam Bey <hisham@hisham.cc>
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Reflection;
33 using System.Runtime.InteropServices;
44 Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
46 a = new CairoGraphic ();
48 Box box = new HBox (true, 0);
59 public class CairoGraphic : DrawingArea
61 static readonly double M_PI = 3.14159265358979323846;
63 static void draw (Cairo.Context gr, int width, int height)
68 double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */
69 double angle2 = 180.0 * (M_PI/180.0); /* in radians */
71 gr.Scale (width, height);
74 gr.ArcNegative (xc, yc, radius, angle1, angle2);
77 /* draw helping lines */
78 gr.Color = new Color(1, 0.2, 0.2, 0.6);
79 gr.Arc (xc, yc, 0.05, 0, 2*M_PI);
82 gr.Arc (xc, yc, radius, angle1, angle1);
83 gr.LineTo (new PointD(xc, yc));
84 gr.Arc (xc, yc, radius, angle2, angle2);
85 gr.LineTo (new PointD(xc, yc));
89 protected override bool OnExposeEvent (Gdk.EventExpose args)
91 Gdk.Window win = args.Window;
92 //Gdk.Rectangle area = args.Area;
94 Cairo.Context g = Gdk.Context.CreateDrawable (win);
97 win.GetGeometry(out x, out y, out w, out h, out d);