* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Drawing / Samples / Standalone / flatten.cs
1 //
2 // flatten.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.ComponentModel;
31 using System.Drawing;
32 using System.Drawing.Drawing2D;
33 using System.Text;
34 using System.Windows.Forms;
35
36 namespace Samples {
37         public partial class flatten: Form {
38
39                 // default values
40                 private float translateX = 0f;
41                 private float translateY = 10f;
42                 private float flat = 0.1f;
43
44                 private Pen default_pen;
45                 private Pen flat_pen;
46
47                 public flatten ()
48                 {
49                         InitializeComponent ();
50
51                         object[] shapes = Samples.Common.Shapes.GetList ();
52                         shapeComboBox.Items.AddRange (shapes);
53
54                         default_pen = new System.Drawing.Pen (System.Drawing.Color.Black, 2);
55                         flat_pen = new System.Drawing.Pen (System.Drawing.Color.Red, 1);
56
57                         translateXtextBox.Text = translateX.ToString ();
58                         translateYtextBox.Text = translateY.ToString ();
59                         flattenTextBox.Text = flat.ToString ();
60                 }
61
62                 private void Flattener_Paint (object sender, PaintEventArgs e)
63                 {
64                         GraphicsPath path = Samples.Common.Shapes.GetShape (shapeComboBox.SelectedIndex);
65                         if (path == null)
66                                 return;
67
68                         e.Graphics.DrawPath (default_pen, path);
69                         int pcount = path.PointCount;
70
71                         if ((translateX != 0f) || (translateY != 0f)) {
72                                 Matrix translateMatrix = new Matrix ();
73                                 translateMatrix.Translate (translateX, translateY);
74                                 path.Flatten (translateMatrix, flat);
75                         } else {
76                                 path.Flatten (null, flat);
77                         }
78                         e.Graphics.DrawPath (flat_pen, path);
79
80                         int fcount = path.PointCount;
81                         path.Dispose ();
82
83                         infoLabel.Text = System.String.Format ("Path Points: {0}, Flat Points: {1}", pcount, fcount);
84                 }
85
86                 private void redrawButton_Click (object sender, EventArgs e)
87                 {
88                         if (Single.TryParse (translateXtextBox.Text, out translateX)) {
89                                 translateXtextBox.BackColor = SystemColors.Window;
90                         } else {
91                                 translateXtextBox.BackColor = Color.Red;
92                         }
93
94                         if (Single.TryParse (translateYtextBox.Text, out translateY)) {
95                                 translateYtextBox.BackColor = SystemColors.Window;
96                         } else {
97                                 translateYtextBox.BackColor = Color.Red;
98                         }
99
100                         if (Single.TryParse (flattenTextBox.Text, out flat)) {
101                                 flattenTextBox.BackColor = SystemColors.Window;
102                         } else {
103                                 flattenTextBox.BackColor = Color.Red;
104                         }
105
106                         Invalidate ();
107                         Update ();
108                 }
109
110                 [STAThread]
111                 static void Main ()
112                 {
113                         Application.EnableVisualStyles ();
114                         Application.SetCompatibleTextRenderingDefault (false);
115                         Application.Run (new flatten ());
116                 }
117         }
118 }