* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Mono.Cairo / Samples / gtk / arcneg.cs
1 //
2 //
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>
6 //
7
8 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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.
29 //
30
31 using System;
32 using System.Reflection;
33 using System.Runtime.InteropServices;
34 using Cairo;
35 using Gtk;
36
37 public class GtkCairo
38 {
39         static DrawingArea a;
40
41         static void Main ()
42         {
43                 Application.Init ();
44                 Gtk.Window w = new Gtk.Window ("Mono.Cairo Circles demo");
45
46                 a = new CairoGraphic ();
47
48                 Box box = new HBox (true, 0);
49                 box.Add (a);
50                 w.Add (box);
51                 w.Resize (500,500);
52                 w.ShowAll ();
53
54                 Application.Run ();
55         }
56
57 }
58
59 public class CairoGraphic : DrawingArea
60 {
61         static readonly double  M_PI = 3.14159265358979323846;
62
63         static void draw (Cairo.Context gr, int width, int height)
64         {
65                 double xc = 0.5;
66                 double yc = 0.5;
67                 double radius = 0.4;
68                 double angle1 = 45.0  * (M_PI/180.0);  /* angles are specified */
69                 double angle2 = 180.0 * (M_PI/180.0);  /* in radians           */
70
71                 gr.Scale (width, height);
72                 gr.LineWidth = 0.04;
73
74                 gr.ArcNegative (xc, yc, radius, angle1, angle2);
75                 gr.Stroke ();
76
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);
80                 gr.Fill ();
81                 gr.LineWidth = 0.03;
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));
86                 gr.Stroke ();
87         }
88
89         protected override bool OnExposeEvent (Gdk.EventExpose args)
90         {
91                 Gdk.Window win = args.Window;
92                 //Gdk.Rectangle area = args.Area;
93
94                 Cairo.Context g = Gdk.Context.CreateDrawable (win);
95
96                 int x, y, w, h, d;
97                 win.GetGeometry(out x, out y, out w, out h, out d);
98
99                 draw (g, w, h);
100                 return true;
101         }
102
103 }
104