* attribute.cs (GetMarshal): Work even if "DefineCustom" is
[mono.git] / mcs / class / Mono.Cairo / Samples / x11 / curve_rect.cs
1 //
2 //
3 //      Mono.Cairo drawing samples using X11 as drawing surface
4 //      Autor: Hisham Mardam Bey <hisham@hisham.cc>
5 //
6
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using System;
31 using System.Reflection;
32 using System.Runtime.InteropServices;
33 using Cairo;
34
35 public class X11Test
36 {
37         static void draw (Cairo.Graphics gr, int width, int height)
38         {
39                 double x0 = 0.1;
40                 double y0 = 0.1;
41                 double rect_width  = 0.8;
42                 double rect_height = 0.8;
43                 double radius = 0.4;
44
45                 double x1,y1;
46
47                 gr.Scale (width, height);
48                 gr.LineWidth = 0.04;
49
50                 x1=x0+rect_width;
51                 y1=y0+rect_height;
52                 if (rect_width == 0 || rect_height == 0)
53                   return;
54
55                 if (rect_width/2<radius) {
56                         if (rect_height/2<radius) {
57                                 gr.MoveTo( new PointD(x0, (y0 + y1)/2) );
58
59                                 gr.CurveTo ( new PointD (x0 ,y0),
60                                              new PointD (x0, y0),
61                                              new PointD ((x0 + x1)/2, y0)
62                                              );
63
64                                 gr.CurveTo ( new PointD (x1, y0 ),
65                                              new PointD (x1, y0 ),
66                                              new PointD (x1, (y0 + y1)/2)
67                                              );
68
69                                 gr.CurveTo ( new PointD (x1, y1),
70                                              new PointD (x1, y1),
71                                              new PointD ((x1 + x0)/2, y1)
72                                              );
73
74                                 gr.CurveTo ( new PointD (x0, y1),
75                                              new PointD (x0, y1),
76                                              new PointD (x0, (y0 + y1)/2)
77                                              );
78                         }
79                         else {
80                                 gr.MoveTo ( new PointD (x0, y0 + radius) );
81
82                                 gr.CurveTo ( new PointD (x0 ,y0),
83                                              new PointD (x0, y0),
84                                              new PointD ((x0 + x1)/2, y0)
85                                              );
86
87                                 gr.CurveTo ( new PointD (x1, y0),
88                                              new PointD (x1, y0),
89                                              new PointD (x1, y0 + radius)
90                                              );
91
92                                 gr.LineTo ( new PointD (x1 , y1 - radius) );
93
94                                 gr.CurveTo ( new PointD (x1, y1),
95                                              new PointD (x1, y1),
96                                              new PointD ((x1 + x0)/2, y1)
97                                              );
98
99                                 gr.CurveTo ( new PointD (x0, y1),
100                                              new PointD (x0, y1),
101                                              new PointD (x0, y1- radius)
102                                              );
103                         }
104                 }
105                 else {
106                         if (rect_height/2<radius) {
107                                 gr.MoveTo ( new PointD (x0, (y0 + y1)/2) );
108
109                                 gr.CurveTo ( new PointD (x0 , y0),
110                                              new PointD (x0 , y0),
111                                              new PointD (x0 + radius, y0)
112                                              );
113
114                                 gr.LineTo ( new PointD (x1 - radius, y0) );
115
116                                 gr.CurveTo ( new PointD (x1, y0),
117                                              new PointD (x1, y0),
118                                              new PointD (x1, (y0 + y1)/2)
119                                              );
120
121                                 gr.CurveTo ( new PointD (x1, y1),
122                                              new PointD (x1, y1),
123                                              new PointD (x1 - radius, y1)
124                                              );
125
126                                 gr.LineTo ( new PointD (x0 + radius, y1) );
127
128                                 gr.CurveTo ( new PointD ( x0, y1),
129                                              new PointD (x0, y1),
130                                              new PointD (x0, (y0 + y1)/2)
131                                              );
132                         }
133                         else {
134                                 gr.MoveTo  ( new PointD (x0, y0 + radius) );
135
136                                 gr.CurveTo ( new PointD (x0 , y0),
137                                              new PointD (x0 , y0),
138                                              new PointD (x0 + radius, y0)
139                                              );
140
141                                 gr.LineTo ( new PointD (x1 - radius, y0) );
142
143                                 gr.CurveTo ( new PointD (x1, y0),
144                                              new PointD (x1, y0),
145                                              new PointD (x1, y0 + radius)
146                                              );
147
148                                 gr.LineTo ( new PointD (x1 , y1 - radius) );
149
150                                 gr.CurveTo ( new PointD ( x1, y1),
151                                              new PointD (x1, y1),
152                                              new PointD (x1 - radius, y1)
153                                              );
154
155                                 gr.LineTo ( new PointD (x0 + radius, y1) );
156                                 gr.CurveTo ( new PointD ( x0, y1),
157                                              new PointD (x0, y1),
158                                              new PointD (x0, y1- radius)
159                                              );
160                         }
161                 }
162
163                 gr.Color = new Color (0.5,0.5,1, 1);
164                 gr.FillPreserve ();
165                 gr.Color = new Color(0.5, 0, 0, 0.5);
166                 gr.Stroke ();
167         }
168         
169         static void Main (string [] args)
170         {
171                 Window win = new Window (500, 500);
172                 
173                 win.Show ();
174                 
175                 Cairo.Surface s = Cairo.Surface.CreateForXlib (win.Display,
176                                win.XWindow,
177                                X11.XDefaultVisual (win.Display, win.Screen),
178                                (int)win.Width, (int)win.Height);
179
180                 
181                 Cairo.Graphics g = new Cairo.Graphics (s);
182                 
183                 draw (g, 500, 500);
184                 
185                 IntPtr xev = new IntPtr ();
186                 
187                 while (true) {                  
188                         X11.XNextEvent (win.Display, xev);
189                 }               
190         }
191 }