3 // Mono.Cairo drawing samples using X11 as drawing surface
4 // Autor: Hisham Mardam Bey <hisham@hisham.cc>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Reflection;
32 using System.Runtime.InteropServices;
37 static void draw (Cairo.Graphics gr, int width, int height)
41 double rect_width = 0.8;
42 double rect_height = 0.8;
47 gr.Scale (width, height);
52 if (rect_width == 0 || rect_height == 0)
55 if (rect_width/2<radius) {
56 if (rect_height/2<radius) {
57 gr.MoveTo( new PointD(x0, (y0 + y1)/2) );
59 gr.CurveTo ( new PointD (x0 ,y0),
61 new PointD ((x0 + x1)/2, y0)
64 gr.CurveTo ( new PointD (x1, y0 ),
66 new PointD (x1, (y0 + y1)/2)
69 gr.CurveTo ( new PointD (x1, y1),
71 new PointD ((x1 + x0)/2, y1)
74 gr.CurveTo ( new PointD (x0, y1),
76 new PointD (x0, (y0 + y1)/2)
80 gr.MoveTo ( new PointD (x0, y0 + radius) );
82 gr.CurveTo ( new PointD (x0 ,y0),
84 new PointD ((x0 + x1)/2, y0)
87 gr.CurveTo ( new PointD (x1, y0),
89 new PointD (x1, y0 + radius)
92 gr.LineTo ( new PointD (x1 , y1 - radius) );
94 gr.CurveTo ( new PointD (x1, y1),
96 new PointD ((x1 + x0)/2, y1)
99 gr.CurveTo ( new PointD (x0, y1),
101 new PointD (x0, y1- radius)
106 if (rect_height/2<radius) {
107 gr.MoveTo ( new PointD (x0, (y0 + y1)/2) );
109 gr.CurveTo ( new PointD (x0 , y0),
110 new PointD (x0 , y0),
111 new PointD (x0 + radius, y0)
114 gr.LineTo ( new PointD (x1 - radius, y0) );
116 gr.CurveTo ( new PointD (x1, y0),
118 new PointD (x1, (y0 + y1)/2)
121 gr.CurveTo ( new PointD (x1, y1),
123 new PointD (x1 - radius, y1)
126 gr.LineTo ( new PointD (x0 + radius, y1) );
128 gr.CurveTo ( new PointD ( x0, y1),
130 new PointD (x0, (y0 + y1)/2)
134 gr.MoveTo ( new PointD (x0, y0 + radius) );
136 gr.CurveTo ( new PointD (x0 , y0),
137 new PointD (x0 , y0),
138 new PointD (x0 + radius, y0)
141 gr.LineTo ( new PointD (x1 - radius, y0) );
143 gr.CurveTo ( new PointD (x1, y0),
145 new PointD (x1, y0 + radius)
148 gr.LineTo ( new PointD (x1 , y1 - radius) );
150 gr.CurveTo ( new PointD ( x1, y1),
152 new PointD (x1 - radius, y1)
155 gr.LineTo ( new PointD (x0 + radius, y1) );
156 gr.CurveTo ( new PointD ( x0, y1),
158 new PointD (x0, y1- radius)
163 gr.Color = new Color (0.5,0.5,1, 1);
165 gr.Color = new Color(0.5, 0, 0, 0.5);
169 static void Main (string [] args)
171 Window win = new Window (500, 500);
175 Cairo.Surface s = Cairo.Surface.CreateForXlib (win.Display,
177 X11.XDefaultVisual (win.Display, win.Screen),
178 (int)win.Width, (int)win.Height);
181 Cairo.Graphics g = new Cairo.Graphics (s);
185 IntPtr xev = new IntPtr ();
188 X11.XNextEvent (win.Display, xev);