merge -r 61110:61111
[mono.git] / mcs / class / System.Drawing / Samples / Standalone / Shapes.cs
1 //
2 // Shapes.cs
3 //
4 // Authors:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Drawing;
31 using System.Drawing.Drawing2D;
32
33 namespace Samples.Common {
34
35         public class Shapes {
36
37                 static public object[] GetList ()
38                 {
39                         return new object[] {
40                                 "Arc",
41                                 "Bezier",
42                                 "Beziers",
43                                 "Closed Curve",
44                                 "Curve",
45                                 "Ellipse",
46                                 "Line",
47                                 "Lines",
48                                 "Pie",
49                                 "Polygon",
50                                 "Rectangle",
51                                 "Rectangles",
52                                 "String",
53                                 "Complex (AddPath)"
54                         };
55                 }
56
57                 static public GraphicsPath GetShape (int index)
58                 {
59                         switch (index) {
60                         case 0:
61                                 return Arc ();
62                         case 1:
63                                 return Bezier ();
64                         case 2:
65                                 return Beziers ();
66                         case 3:
67                                 return ClosedCurve ();
68                         case 4:
69                                 return Curve ();
70                         case 5:
71                                 return Ellipse ();
72                         case 6:
73                                 return Line ();
74                         case 7:
75                                 return Lines ();
76                         case 8:
77                                 return Pie ();
78                         case 9:
79                                 return Polygon ();
80                         case 10:
81                                 return Rectangle ();
82                         case 11:
83                                 return Rectangles ();
84                         case 12:
85                                 return String ();
86                         case 13:
87                                 return Complex ();
88                         default:
89                                 // nothing to show
90                                 return null;
91                         }
92                 }
93
94                 static private GraphicsPath Arc ()
95                 {
96                         GraphicsPath path = new GraphicsPath ();
97                         path.AddArc (20, 20, 200, 200, 60, 120);
98                         return path;
99                 }
100
101                 static private GraphicsPath Bezier ()
102                 {
103                         GraphicsPath path = new GraphicsPath ();
104                         path.AddBezier (
105                                 new Point (20, 100), new Point (70, 10),
106                                 new Point (130, 200), new Point (180, 100)
107                                 );
108                         return path;
109                 }
110
111                 static private GraphicsPath Beziers ()
112                 {
113                         GraphicsPath path = new GraphicsPath ();
114                         path.AddBeziers (new Point[7] { 
115                                 new Point (20, 100), new Point (70, 10),
116                                 new Point (130, 200), new Point (180, 100),
117                                 new Point (200, 100), new Point (240, 240),
118                                 new Point (20, 100)
119                                 });
120                         return path;
121                 }
122
123                 static private GraphicsPath ClosedCurve ()
124                 {
125                         GraphicsPath path = new GraphicsPath ();
126                         path.AddClosedCurve (new Point[4] { 
127                                 new Point (20, 100), new Point (70, 10),
128                                 new Point (130, 200), new Point (180, 100)
129                                 });
130                         return path;
131                 }
132
133                 static private GraphicsPath Curve ()
134                 {
135                         GraphicsPath path = new GraphicsPath ();
136                         path.AddCurve (new Point[4] { 
137                                 new Point (20, 100), new Point (70, 10),
138                                 new Point (130, 200), new Point (180, 100)
139                                 });
140                         return path;
141                 }
142
143                 static private GraphicsPath Ellipse ()
144                 {
145                         GraphicsPath path = new GraphicsPath ();
146                         path.AddEllipse (20, 20, 200, 100);
147                         return path;
148                 }
149
150                 static private GraphicsPath Line ()
151                 {
152                         GraphicsPath path = new GraphicsPath ();
153                         path.AddLine (20, 20, 200, 100);
154                         return path;
155                 }
156
157                 static private GraphicsPath Lines ()
158                 {
159                         GraphicsPath path = new GraphicsPath ();
160                         path.AddLines (new Point[4] { 
161                                 new Point (20, 100), new Point (70, 10),
162                                 new Point (130, 200), new Point (180, 100)
163                                 });
164                         return path;
165                 }
166
167                 static private GraphicsPath Pie ()
168                 {
169                         GraphicsPath path = new GraphicsPath ();
170                         path.AddPie (20, 20, 200, 200, 60, 120);
171                         return path;
172                 }
173
174                 static private GraphicsPath Polygon ()
175                 {
176                         GraphicsPath path = new GraphicsPath ();
177                         path.AddPolygon (new Point[4] { 
178                                 new Point (20, 100), new Point (70, 10),
179                                 new Point (130, 200), new Point (180, 100)
180                                 });
181                         return path;
182                 }
183
184                 static private GraphicsPath Rectangle ()
185                 {
186                         GraphicsPath path = new GraphicsPath ();
187                         path.AddRectangle (new Rectangle (20, 20, 200, 200));
188                         return path;
189                 }
190
191                 static private GraphicsPath Rectangles ()
192                 {
193                         GraphicsPath path = new GraphicsPath ();
194                         path.AddRectangles (new Rectangle[2] {
195                                 new Rectangle (20, 20, 100, 100),
196                                 new Rectangle (100, 100, 20, 20)
197                                 });
198                         return path;
199                 }
200
201                 static private GraphicsPath String ()
202                 {
203                         GraphicsPath path = new GraphicsPath ();
204                         try {
205                                 path.AddString ("Mono", FontFamily.GenericMonospace, 0, 10f, new Point (20, 20), StringFormat.GenericDefault);
206                         }
207                         catch (NotImplementedException) {
208                                 // not implemented in libgdiplus
209                         }
210                         return path;
211                 }
212
213                 static private GraphicsPath Complex ()
214                 {
215                         GraphicsPath path = new GraphicsPath ();
216                         path.AddPath (Pie (), false);
217                         path.AddPath (Rectangle (), true);
218                         path.AddPath (Polygon (), false);
219                         return path;
220                 }
221         }
222 }