From 75d891a785058143868278664f61d6f967029eff Mon Sep 17 00:00:00 2001 From: Remi Gillig Date: Thu, 4 Feb 2016 22:44:41 +0000 Subject: [PATCH] Add "Open" button in TessBed for easy external tests --- TessBed/MainForm.Designer.cs | 15 +++++++++++++- TessBed/MainForm.cs | 38 +++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/TessBed/MainForm.Designer.cs b/TessBed/MainForm.Designer.cs index c86d2f1..fe61097 100644 --- a/TessBed/MainForm.Designer.cs +++ b/TessBed/MainForm.Designer.cs @@ -44,6 +44,7 @@ private void InitializeComponent() this.toolStripButtonShowInput = new System.Windows.Forms.ToolStripButton(); this.toolStripButtonShowWinding = new System.Windows.Forms.ToolStripButton(); this.toolStripButtonBench = new System.Windows.Forms.ToolStripButton(); + this.toolStripButtonOpen = new System.Windows.Forms.ToolStripButton(); this.panel = new System.Windows.Forms.Panel(); this.statusStrip.SuspendLayout(); this.toolStrip.SuspendLayout(); @@ -78,7 +79,8 @@ private void InitializeComponent() this.toolStripSeparator3, this.toolStripButtonShowInput, this.toolStripButtonShowWinding, - this.toolStripButtonBench}); + this.toolStripButtonBench, + this.toolStripButtonOpen}); this.toolStrip.Location = new System.Drawing.Point(0, 0); this.toolStrip.Name = "toolStrip"; this.toolStrip.Size = new System.Drawing.Size(752, 25); @@ -164,6 +166,16 @@ private void InitializeComponent() this.toolStripButtonBench.Size = new System.Drawing.Size(76, 22); this.toolStripButtonBench.Text = "Benchmarks"; // + // toolStripButtonOpen + // + this.toolStripButtonOpen.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.toolStripButtonOpen.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonOpen.Image"))); + this.toolStripButtonOpen.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripButtonOpen.Name = "toolStripButtonOpen"; + this.toolStripButtonOpen.Size = new System.Drawing.Size(76, 22); + this.toolStripButtonOpen.Text = "Open"; + this.toolStripButtonOpen.ToolTipText = "Open a .dat file"; + // // panel // this.panel.Dock = System.Windows.Forms.DockStyle.Fill; @@ -210,6 +222,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripButton toolStripButtonShowWinding; private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; private System.Windows.Forms.ToolStripButton toolStripButtonBench; + private System.Windows.Forms.ToolStripButton toolStripButtonOpen; } } diff --git a/TessBed/MainForm.cs b/TessBed/MainForm.cs index d030143..405ba4e 100644 --- a/TessBed/MainForm.cs +++ b/TessBed/MainForm.cs @@ -63,19 +63,13 @@ public MainForm() { _canvas.ShowInput = toolStripButtonShowInput.Checked; toolStripButtonShowWinding.Enabled = _canvas.ShowInput; - if (toolStripAssets.SelectedIndex >= 0) - { - RefreshAsset(toolStripAssets.SelectedIndex); - } + RefreshAsset(toolStripAssets.SelectedIndex); }; toolStripButtonShowWinding.CheckedChanged += delegate(object sender, EventArgs e) { _canvas.ShowWinding = toolStripButtonShowWinding.Checked; - if (toolStripAssets.SelectedIndex >= 0) - { - RefreshAsset(toolStripAssets.SelectedIndex); - } + RefreshAsset(toolStripAssets.SelectedIndex); }; toolStripButtonBench.Click += delegate(object sender, EventArgs e) @@ -83,6 +77,20 @@ public MainForm() 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); @@ -151,7 +159,11 @@ private void SetPolySize(int polySize) private void RefreshAsset(int index) { - RefreshAsset(_assets[index]); + if (index >= 0) + { + var asset = _data.GetAsset(_assets[index]); + RefreshAsset(asset.Polygons); + } } private Vec3 Project(Vec3 v) @@ -188,13 +200,11 @@ private object VertexCombine(Vec3 position, object[] data, float[] weights) return Color.FromArgb((int)rgba[3], (int)rgba[0], (int)rgba[1], (int)rgba[2]); } - private void RefreshAsset(string name) + private void RefreshAsset(PolygonSet polygons) { - var asset = _data.GetAsset(name); - _sw.Reset(); - foreach (var poly in asset.Polygons) + foreach (var poly in polygons) { var v = new ContourVertex[poly.Count]; for (int i = 0; i < poly.Count; i++) @@ -232,7 +242,7 @@ private void RefreshAsset(string name) } var input = new PolygonSet(); - foreach (var poly in asset.Polygons) + foreach (var poly in polygons) { var projPoly = new Polygon(); for (int i = 0; i < poly.Count; i++)