public MainForm() { InitializeComponent(); _canvas = new Canvas(); _canvas.Dock = DockStyle.Fill; panel.Controls.Add(_canvas); _assets = _data.AssetNames; Array.Sort(_assets); foreach (var asset in _assets) { toolStripAssets.Items.Add(asset); } toolStripAssets.SelectedIndexChanged += delegate(object sender, EventArgs e) { RefreshAsset(toolStripAssets.SelectedIndex); }; _windingRules = Enum.GetNames(typeof(WindingRule)); foreach (var windingRule in _windingRules) { toolStripWinding.Items.Add(windingRule); } toolStripWinding.SelectedIndexChanged += delegate(object sender, EventArgs e) { _windingRule = (WindingRule)toolStripWinding.SelectedIndex; if (toolStripAssets.SelectedIndex >= 0) { RefreshAsset(toolStripAssets.SelectedIndex); } }; toolStripPolySize.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { PolySizeEvent(); } }; toolStripPolySize.Leave += delegate(object sender, EventArgs e) { PolySizeEvent(); }; toolStripButtonShowInput.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowInput = toolStripButtonShowInput.Checked; toolStripButtonShowWinding.Enabled = _canvas.ShowInput; RefreshAsset(toolStripAssets.SelectedIndex); }; toolStripButtonShowWinding.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowWinding = toolStripButtonShowWinding.Checked; RefreshAsset(toolStripAssets.SelectedIndex); }; toolStripButtonNoEmpty.CheckedChanged += delegate(object sender, EventArgs e) { _tess.NoEmptyPolygons = toolStripButtonNoEmpty.Checked; RefreshAsset(toolStripAssets.SelectedIndex); }; toolStripButtonBench.Click += delegate(object sender, EventArgs e) { new BenchForm().ShowDialog(this); }; toolStripButtonOpen.Click += delegate(object sender, EventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Test Files (*.dat)|*.dat|All Files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { var polygons = DataLoader.LoadDat(dialog.OpenFile()); RefreshAsset(polygons); toolStripAssets.SelectedIndex = -1; } }; SetAsset("redbook-winding"); SetShowInput(true); SetShowWinding(false); SetPolySize(3); SetWindingRule(WindingRule.EvenOdd); }
public MainForm() { InitializeComponent(); _canvas = new Canvas(); _canvas.Dock = DockStyle.Fill; panel.Controls.Add(_canvas); foreach (var asset in _data.Assets) { toolStripAssets.Items.Add(asset); } toolStripAssets.SelectedIndexChanged += delegate(object sender, EventArgs e) { if (toolStripAssets.SelectedIndex >= 0) { var asset = toolStripAssets.SelectedItem as DataLoader.Asset; _polys = asset.Polygons; RefreshCanvas(); } }; _windingRules = Enum.GetNames(typeof(WindingRule)); foreach (var windingRule in _windingRules) { toolStripWinding.Items.Add(windingRule); } toolStripWinding.SelectedIndexChanged += delegate(object sender, EventArgs e) { _windingRule = (WindingRule)toolStripWinding.SelectedIndex; RefreshCanvas(); }; toolStripPolySize.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { PolySizeEvent(); } }; toolStripPolySize.Leave += delegate(object sender, EventArgs e) { PolySizeEvent(); }; toolStripButtonShowInput.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowInput = toolStripButtonShowInput.Checked; toolStripButtonShowWinding.Enabled = _canvas.ShowInput; RefreshCanvas(); }; toolStripButtonShowWinding.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowWinding = toolStripButtonShowWinding.Checked; RefreshCanvas(); }; toolStripButtonNoEmpty.CheckedChanged += delegate(object sender, EventArgs e) { _tess.NoEmptyPolygons = toolStripButtonNoEmpty.Checked; RefreshCanvas(); }; toolStripButtonBench.Click += delegate(object sender, EventArgs e) { new BenchForm().ShowDialog(this); }; toolStripButtonFile.Click += delegate(object sender, EventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Test Files (*.dat)|*.dat|All Files (*.*)|*.*"; dialog.FilterIndex = 1; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { var polygons = DataLoader.LoadDat(dialog.OpenFile()); _polys = polygons; RefreshCanvas(); toolStripAssets.SelectedIndex = -1; } }; toolStripButtonFolder.Click += delegate(object sender, EventArgs e) { var dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { var files = Directory.GetFiles(dialog.SelectedPath, "*.dat"); if (files.Length > 0) { toolStripAssets.Items.Clear(); _polys = null; foreach (var file in files) { using (var stream = new FileStream(file, FileMode.Open)) { var polygons = DataLoader.LoadDat(stream); if (_polys == null) { _polys = polygons; } toolStripAssets.Items.Add(new DataLoader.Asset() { Name = Path.GetFileName(file), Polygons = polygons }); } } toolStripAssets.SelectedIndex = 0; RefreshCanvas(); } } }; SetAsset("redbook-winding"); SetShowInput(true); SetShowWinding(false); SetPolySize(3); SetWindingRule(WindingRule.EvenOdd); }