mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-23 04:12:12 +00:00
- nice wrapper for line length labels
- line length labels while drawing!
This commit is contained in:
parent
77720694a3
commit
9f07f2ef2c
7 changed files with 157 additions and 31 deletions
|
@ -39,6 +39,7 @@
|
||||||
<Compile Include="ClassicModes\DrawGeometryMode.cs" />
|
<Compile Include="ClassicModes\DrawGeometryMode.cs" />
|
||||||
<Compile Include="Testing\TriangulatorMode.cs" />
|
<Compile Include="Testing\TriangulatorMode.cs" />
|
||||||
<Compile Include="ClassicModes\DragThingsMode.cs" />
|
<Compile Include="ClassicModes\DragThingsMode.cs" />
|
||||||
|
<Compile Include="Tools\LineLengthLabel.cs" />
|
||||||
<Compile Include="VisualModes\BaseVisualMode.cs" />
|
<Compile Include="VisualModes\BaseVisualMode.cs" />
|
||||||
<Compile Include="VisualModes\BaseVisualSector.cs" />
|
<Compile Include="VisualModes\BaseVisualSector.cs" />
|
||||||
<Compile Include="ClassicModes\DragVerticesMode.cs" />
|
<Compile Include="ClassicModes\DragVerticesMode.cs" />
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
protected ICollection<Linedef> snaptolines;
|
protected ICollection<Linedef> snaptolines;
|
||||||
|
|
||||||
// Text labels for all unstable lines
|
// Text labels for all unstable lines
|
||||||
protected TextLabel[] labels;
|
protected LineLengthLabel[] labels;
|
||||||
|
|
||||||
// Keep track of view changes
|
// Keep track of view changes
|
||||||
private float lastoffsetx;
|
private float lastoffsetx;
|
||||||
|
@ -100,7 +100,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
{
|
{
|
||||||
// Clean up
|
// Clean up
|
||||||
if(labels != null)
|
if(labels != null)
|
||||||
foreach(TextLabel l in labels) l.Dispose();
|
foreach(LineLengthLabel l in labels) l.Dispose();
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
|
@ -151,22 +151,10 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
unstablelines = MapSet.UnstableLinedefsFromVertices(selectedverts);
|
unstablelines = MapSet.UnstableLinedefsFromVertices(selectedverts);
|
||||||
|
|
||||||
// Make text labels
|
// Make text labels
|
||||||
labels = new TextLabel[unstablelines.Count];
|
labels = new LineLengthLabel[unstablelines.Count];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach(Linedef l in unstablelines)
|
foreach(Linedef l in unstablelines)
|
||||||
{
|
labels[index++] = new LineLengthLabel(l.Start.Position, l.End.Position);
|
||||||
Vector2D center = l.GetCenterPoint();
|
|
||||||
labels[index] = new TextLabel(12);
|
|
||||||
labels[index].Rectangle = new RectangleF(center.x, center.y, 0f, 0f);
|
|
||||||
labels[index].AlignX = TextAlignmentX.Center;
|
|
||||||
labels[index].AlignY = TextAlignmentY.Middle;
|
|
||||||
labels[index].Color = General.Colors.Highlight;
|
|
||||||
labels[index].Backcolor = General.Colors.Background;
|
|
||||||
labels[index].Scale = 14f;
|
|
||||||
labels[index].TransformCoords = true;
|
|
||||||
labels[index].Text = l.Length.ToString("0");
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cursor.Current = Cursors.Default;
|
Cursor.Current = Cursors.Default;
|
||||||
}
|
}
|
||||||
|
@ -271,13 +259,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
// Update labels
|
// Update labels
|
||||||
int index = 0;
|
int index = 0;
|
||||||
foreach(Linedef l in unstablelines)
|
foreach(Linedef l in unstablelines)
|
||||||
{
|
labels[index++].Move(l.Start.Position, l.End.Position);
|
||||||
l.UpdateCache();
|
|
||||||
Vector2D center = l.GetCenterPoint();
|
|
||||||
labels[index].Rectangle = new RectangleF(center.x, center.y, 0f, 0f);
|
|
||||||
labels[index].Text = l.Length.ToString("0");
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Moved
|
// Moved
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -164,9 +164,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
// Redraw overlay
|
// Redraw overlay
|
||||||
if(renderer.StartOverlay(true))
|
if(renderer.StartOverlay(true))
|
||||||
{
|
{
|
||||||
foreach(TextLabel l in labels)
|
foreach(LineLengthLabel l in labels)
|
||||||
{
|
{
|
||||||
renderer.RenderText(l);
|
renderer.RenderText(l.TextLabel);
|
||||||
}
|
}
|
||||||
renderer.Finish();
|
renderer.Finish();
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,9 +169,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
// Redraw overlay
|
// Redraw overlay
|
||||||
if(renderer.StartOverlay(true))
|
if(renderer.StartOverlay(true))
|
||||||
{
|
{
|
||||||
foreach(TextLabel l in labels)
|
foreach(LineLengthLabel l in labels)
|
||||||
{
|
{
|
||||||
renderer.RenderText(l);
|
renderer.RenderText(l.TextLabel);
|
||||||
}
|
}
|
||||||
renderer.Finish();
|
renderer.Finish();
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,9 +146,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
// Redraw overlay
|
// Redraw overlay
|
||||||
if(renderer.StartOverlay(true))
|
if(renderer.StartOverlay(true))
|
||||||
{
|
{
|
||||||
foreach(TextLabel l in labels)
|
foreach(LineLengthLabel l in labels)
|
||||||
{
|
{
|
||||||
renderer.RenderText(l);
|
renderer.RenderText(l.TextLabel);
|
||||||
}
|
}
|
||||||
renderer.Finish();
|
renderer.Finish();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
|
|
||||||
// Drawing points
|
// Drawing points
|
||||||
private List<DrawnVertex> points;
|
private List<DrawnVertex> points;
|
||||||
|
private List<LineLengthLabel> labels;
|
||||||
|
|
||||||
// Keep track of view changes
|
// Keep track of view changes
|
||||||
private float lastoffsetx;
|
private float lastoffsetx;
|
||||||
|
@ -91,6 +92,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
// Initialize
|
// Initialize
|
||||||
this.basemode = General.Map.Mode;
|
this.basemode = General.Map.Mode;
|
||||||
points = new List<DrawnVertex>();
|
points = new List<DrawnVertex>();
|
||||||
|
labels = new List<LineLengthLabel>();
|
||||||
|
|
||||||
// No selection in this mode
|
// No selection in this mode
|
||||||
General.Map.Map.ClearAllSelected();
|
General.Map.Map.ClearAllSelected();
|
||||||
|
@ -107,7 +109,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
if(!isdisposed)
|
if(!isdisposed)
|
||||||
{
|
{
|
||||||
// Clean up
|
// Clean up
|
||||||
|
if(labels != null)
|
||||||
|
foreach(LineLengthLabel l in labels) l.Dispose();
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -579,6 +583,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
float vsize = ((float)renderer.VertexSize + 1.0f) / renderer.Scale;
|
float vsize = ((float)renderer.VertexSize + 1.0f) / renderer.Scale;
|
||||||
float vsizeborder = ((float)renderer.VertexSize + 3.0f) / renderer.Scale;
|
float vsizeborder = ((float)renderer.VertexSize + 3.0f) / renderer.Scale;
|
||||||
|
|
||||||
|
// The last label's end must go to the mouse cursor
|
||||||
|
if(labels.Count > 0) labels[labels.Count - 1].End = curp.pos;
|
||||||
|
|
||||||
// Render drawing lines
|
// Render drawing lines
|
||||||
if(renderer.StartOverlay(true))
|
if(renderer.StartOverlay(true))
|
||||||
{
|
{
|
||||||
|
@ -624,6 +631,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
// Render vertex at cursor
|
// Render vertex at cursor
|
||||||
renderer.RenderRectangleFilled(new RectangleF(curp.pos.x - vsize, curp.pos.y - vsize, vsize * 2.0f, vsize * 2.0f), color, true);
|
renderer.RenderRectangleFilled(new RectangleF(curp.pos.x - vsize, curp.pos.y - vsize, vsize * 2.0f, vsize * 2.0f), color, true);
|
||||||
|
|
||||||
|
// Go for all labels
|
||||||
|
foreach(LineLengthLabel l in labels) renderer.RenderText(l.TextLabel);
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
renderer.Finish();
|
renderer.Finish();
|
||||||
}
|
}
|
||||||
|
@ -732,7 +742,11 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
// Mouse inside window?
|
// Mouse inside window?
|
||||||
if(General.Interface.MouseInDisplay)
|
if(General.Interface.MouseInDisplay)
|
||||||
{
|
{
|
||||||
points.Add(GetCurrentPosition());
|
DrawnVertex newpoint = GetCurrentPosition();
|
||||||
|
points.Add(newpoint);
|
||||||
|
labels.Add(new LineLengthLabel());
|
||||||
|
labels[labels.Count - 1].Start = newpoint.pos;
|
||||||
|
if(labels.Count > 1) labels[labels.Count - 2].End = newpoint.pos;
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
// Check if point stitches with the first
|
// Check if point stitches with the first
|
||||||
|
@ -755,6 +769,12 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
|
||||||
public void RemovePoint()
|
public void RemovePoint()
|
||||||
{
|
{
|
||||||
if(points.Count > 0) points.RemoveAt(points.Count - 1);
|
if(points.Count > 0) points.RemoveAt(points.Count - 1);
|
||||||
|
if(labels.Count > 0)
|
||||||
|
{
|
||||||
|
labels[labels.Count - 1].Dispose();
|
||||||
|
labels.RemoveAt(labels.Count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
123
Source/BuilderModes/Tools/LineLengthLabel.cs
Normal file
123
Source/BuilderModes/Tools/LineLengthLabel.cs
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
|
||||||
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
||||||
|
* This program is released under GNU General Public License
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Namespaces
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using CodeImp.DoomBuilder.Interface;
|
||||||
|
using CodeImp.DoomBuilder.IO;
|
||||||
|
using CodeImp.DoomBuilder.Map;
|
||||||
|
using CodeImp.DoomBuilder.Rendering;
|
||||||
|
using CodeImp.DoomBuilder.Geometry;
|
||||||
|
using System.Drawing;
|
||||||
|
using CodeImp.DoomBuilder.Editing;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace CodeImp.DoomBuilder.BuilderModes
|
||||||
|
{
|
||||||
|
public class LineLengthLabel : IDisposable
|
||||||
|
{
|
||||||
|
#region ================== Constants
|
||||||
|
|
||||||
|
private const int TEXT_CAPACITY = 10;
|
||||||
|
private const float TEXT_SCALE = 14f;
|
||||||
|
private const string VALUE_FORMAT = "0";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Variables
|
||||||
|
|
||||||
|
private TextLabel label;
|
||||||
|
private Vector2D start;
|
||||||
|
private Vector2D end;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Properties
|
||||||
|
|
||||||
|
public TextLabel TextLabel { get { return label; } }
|
||||||
|
public Vector2D Start { get { return start; } set { start = value; Update(); } }
|
||||||
|
public Vector2D End { get { return end; } set { end = value; Update(); } }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Constructor / Disposer
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public LineLengthLabel()
|
||||||
|
{
|
||||||
|
// Initialize
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public LineLengthLabel(Vector2D start, Vector2D end)
|
||||||
|
{
|
||||||
|
// Initialize
|
||||||
|
Initialize();
|
||||||
|
Move(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialization
|
||||||
|
private void Initialize()
|
||||||
|
{
|
||||||
|
label = new TextLabel(TEXT_CAPACITY);
|
||||||
|
label.AlignX = TextAlignmentX.Center;
|
||||||
|
label.AlignY = TextAlignmentY.Middle;
|
||||||
|
label.Color = General.Colors.Highlight;
|
||||||
|
label.Backcolor = General.Colors.Background;
|
||||||
|
label.Scale = TEXT_SCALE;
|
||||||
|
label.TransformCoords = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disposer
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
label.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Methods
|
||||||
|
|
||||||
|
// This updates the text
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
Vector2D delta = end - start;
|
||||||
|
float length = delta.GetLength();
|
||||||
|
label.Text = length.ToString(VALUE_FORMAT);
|
||||||
|
label.Rectangle = new RectangleF(start.x + delta.x * 0.5f, start.y + delta.y * 0.5f, 0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This moves the label
|
||||||
|
public void Move(Vector2D start, Vector2D end)
|
||||||
|
{
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue