Take stars out of types where they make more sense.
[mono-project.git] / mcs / class / Mono.C5 / UserGuideExamples / GCHForm.cs
blob574e6adf2fa124a8b35931c94413407e640896e2
1 /*
2 Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
3 Permission is hereby granted, free of charge, to any person obtaining a copy
4 of this software and associated documentation files (the "Software"), to deal
5 in the Software without restriction, including without limitation the rights
6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 copies of the Software, and to permit persons to whom the Software is
8 furnished to do so, subject to the following conditions:
10 The above copyright notice and this permission notice shall be included in
11 all copies or substantial portions of the Software.
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 SOFTWARE.
22 using System;
23 using System.Drawing;
24 using System.Collections;
25 using System.ComponentModel;
26 using System.Windows.Forms;
27 using System.Diagnostics;
28 using C5;
30 namespace GConvexHull
32 /// <summary>
33 /// Summary description for Form1.
34 /// </summary>
35 public class TesterForm : System.Windows.Forms.Form
37 //My data
39 //My GUI stuff
40 private System.Windows.Forms.Panel drawarea;
42 private Graphics drawg;
44 //Std stuff
45 private System.Windows.Forms.Button runButton;
46 private TextBox pointCount;
48 /// <summary>
49 /// Required designer variable.
50 /// </summary>
51 private System.ComponentModel.Container components = null;
54 public TesterForm()
57 // Required for Windows Form Designer support
59 InitializeComponent();
62 // TODO: Add any constructor code after InitializeComponent call
64 drawg = drawarea.CreateGraphics();
65 reset();
69 /// <summary>
70 /// Clean up any resources being used.
71 /// </summary>
72 protected override void Dispose(bool disposing)
74 if (disposing)
76 if (components != null)
78 components.Dispose();
82 base.Dispose(disposing);
85 #region Windows Form Designer generated code
86 /// <summary>
87 /// Required method for Designer support - do not modify
88 /// the contents of this method with the code editor.
89 /// </summary>
90 private void InitializeComponent()
92 this.drawarea = new System.Windows.Forms.Panel();
93 this.runButton = new System.Windows.Forms.Button();
94 this.pointCount = new System.Windows.Forms.TextBox();
95 this.SuspendLayout();
96 //
97 // drawarea
98 //
99 this.drawarea.BackColor = System.Drawing.Color.White;
100 this.drawarea.Location = new System.Drawing.Point(8, 9);
101 this.drawarea.Name = "drawarea";
102 this.drawarea.Size = new System.Drawing.Size(500, 500);
103 this.drawarea.TabIndex = 0;
104 this.drawarea.Paint += new System.Windows.Forms.PaintEventHandler(this.drawarea_Paint);
105 this.drawarea.Invalidated += new System.Windows.Forms.InvalidateEventHandler(this.drawarea_Invalidated);
106 this.drawarea.MouseMove += new System.Windows.Forms.MouseEventHandler(this.drawarea_MouseMove);
107 this.drawarea.MouseClick += new System.Windows.Forms.MouseEventHandler(this.drawarea_MouseClick);
109 // runButton
111 this.runButton.Location = new System.Drawing.Point(8, 516);
112 this.runButton.Name = "runButton";
113 this.runButton.Size = new System.Drawing.Size(42, 20);
114 this.runButton.TabIndex = 1;
115 this.runButton.Text = "Run";
116 this.runButton.Click += new System.EventHandler(this.runButton_Click);
118 // pointCount
120 this.pointCount.Location = new System.Drawing.Point(97, 517);
121 this.pointCount.Name = "pointCount";
122 this.pointCount.Size = new System.Drawing.Size(55, 20);
123 this.pointCount.TabIndex = 5;
125 // TesterForm
127 this.ClientSize = new System.Drawing.Size(524, 550);
128 this.Controls.Add(this.pointCount);
129 this.Controls.Add(this.runButton);
130 this.Controls.Add(this.drawarea);
131 this.Name = "TesterForm";
132 this.Text = "C5 Tester";
133 this.Load += new System.EventHandler(this.TesterForm_Load);
134 this.ResumeLayout(false);
135 this.PerformLayout();
138 #endregion
140 /// <summary>
141 /// The main entry point for the application.
142 /// </summary>
143 [STAThread]
144 static void Main()
146 Application.EnableVisualStyles();
147 Application.Run(new TesterForm());
150 Point[] pts;
151 Point[] chpts;
153 private void runButton_Click(object sender, System.EventArgs e)
155 int N = int.Parse(pointCount.Text);
156 pts = new Point[N];
157 for (int i = 0; i < N; i++)
158 pts[i] = Point.Random(500, 500);
159 chpts = Convexhull.ConvexHull(pts);
161 drawarea.Invalidate();
165 private void drawarea_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
167 mydraw();
171 private void resetButton_Click(object sender, System.EventArgs e)
173 reset();
177 private void reset()
179 drawarea.Invalidate();//(new Rectangle(0, 0, 40, 40));
184 public void mydraw()
186 if (pts == null)
188 return;
190 for (int i = 0; i < pts.Length; i++)
192 Point p = pts[i];
193 drawg.DrawEllipse(new Pen(Color.Red), transx(p.x) - 2, transy(p.y) - 2, 4, 4);
195 for (int i = 0; i < chpts.Length; i++)
197 int j = i + 1 < chpts.Length ? i + 1 : 0;
198 drawg.DrawEllipse(new Pen(Color.Blue), transx(chpts[i].x) - 2, transy(chpts[i].y) - 2, 4, 4);
199 drawg.DrawLine(new Pen(Color.LawnGreen), transx(chpts[i].x), transx(chpts[i].y), transx(chpts[j].x), transx(chpts[j].y));
205 private int transx(double x)
207 return (int)x;
211 private int transy(double y)
213 return (int)y;
217 private void dumpButton_Click(object sender, System.EventArgs e)
219 Debug.WriteLine("###############");
220 Debug.WriteLine("###############");
224 private void graphTypeControlArray_Click(object sender, System.EventArgs e)
226 Debug.WriteLine(e.GetType());
227 Debug.WriteLine(sender.GetType());
228 drawarea.Invalidate();
232 private void drawarea_MouseMove(object sender, MouseEventArgs e)
237 private void drawarea_MouseClick(object sender, MouseEventArgs e)
239 //double x = untransx(e.X), y = untransy(e.Y);
244 private void drawarea_Invalidated(object sender, InvalidateEventArgs e)
246 //msg.Text = e.InvalidRect + "";
247 //mydraw();
251 private void preparedFigureSelection_SelectedIndexChanged(object sender, System.EventArgs e)
255 private void voronoiButton_CheckedChanged(object sender, EventArgs e)
257 graphTypeControlArray_Click(sender, e);
260 private void delaunayButton_CheckedChanged(object sender, EventArgs e)
262 graphTypeControlArray_Click(sender, e);
265 private void TesterForm_Load(object sender, EventArgs e)