2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#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 CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
{
|
|
|
|
public class LineLengthLabel : IDisposable
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2012-11-11 21:52:08 +00:00
|
|
|
private const int TEXT_CAPACITY = 15;
|
2009-04-19 18:07:22 +00:00
|
|
|
private const float TEXT_SCALE = 14f;
|
|
|
|
private const string VALUE_FORMAT = "0";
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2012-06-07 01:06:37 +00:00
|
|
|
protected TextLabel label;
|
2013-09-11 09:47:53 +00:00
|
|
|
protected Vector2D start;
|
|
|
|
protected Vector2D end;
|
2012-11-11 21:52:08 +00:00
|
|
|
private bool showAngle; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#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
|
2012-11-11 21:52:08 +00:00
|
|
|
public LineLengthLabel(bool showAngle)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2012-11-11 21:52:08 +00:00
|
|
|
this.showAngle = showAngle; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
// Initialize
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public LineLengthLabel(Vector2D start, Vector2D end)
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
Initialize();
|
|
|
|
Move(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialization
|
2012-06-07 01:06:37 +00:00
|
|
|
protected virtual void Initialize()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
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
|
2013-09-11 09:47:53 +00:00
|
|
|
protected virtual void Update()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
Vector2D delta = end - start;
|
|
|
|
float length = delta.GetLength();
|
2012-11-11 21:52:08 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
if(showAngle) {
|
2013-04-11 09:27:16 +00:00
|
|
|
int angle = (int)Math.Round(Angle2D.RadToDeg(delta.GetAngle()));// * 180 / Math.PI);
|
2012-11-11 21:52:08 +00:00
|
|
|
label.Text = "l:" + length.ToString(VALUE_FORMAT) + "; a:" + angle;
|
|
|
|
} else {
|
|
|
|
label.Text = length.ToString(VALUE_FORMAT);
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|