2014-10-17 11:55:08 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
|
{
|
|
|
|
|
#region ================== Enums
|
|
|
|
|
|
|
|
|
|
internal enum SlopePivotMode
|
|
|
|
|
{
|
|
|
|
|
ORIGIN, // pivot around 0, 0
|
2014-10-17 11:55:08 +00:00
|
|
|
|
GLOBAL, // pivot around selection center
|
|
|
|
|
LOCAL, // pivot around sector center
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public partial class SectorSlopeControl : UserControl
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
2014-09-04 12:34:26 +00:00
|
|
|
|
public event EventHandler OnAnglesChanged;
|
2014-08-25 11:15:19 +00:00
|
|
|
|
public event EventHandler OnUseLineAnglesChanged;
|
2014-09-04 12:34:26 +00:00
|
|
|
|
public event EventHandler OnPivotModeChanged;
|
|
|
|
|
public event EventHandler OnResetClicked;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
|
|
private bool blockUpdate;
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
// Slope values
|
2014-07-11 10:13:26 +00:00
|
|
|
|
private float anglexy;
|
|
|
|
|
private float anglez;
|
|
|
|
|
private float offset;
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
2014-08-25 11:15:19 +00:00
|
|
|
|
public StepsList StepValues { set { sloperotation.StepValues = value; } }
|
|
|
|
|
public bool UseLineAngles { get { return cbuselineangles.Checked; } set { blockUpdate = true; cbuselineangles.Checked = value; blockUpdate = false; } }
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
internal SlopePivotMode PivotMode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (SlopePivotMode)pivotmodeselector.SelectedIndex;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
blockUpdate = true;
|
|
|
|
|
pivotmodeselector.SelectedIndex = (int)value;
|
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
|
|
public SectorSlopeControl()
|
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Property accessors
|
|
|
|
|
|
|
|
|
|
public float GetAngleXY(float defaultvalue)
|
|
|
|
|
{
|
|
|
|
|
return sloperotation.GetResultFloat(defaultvalue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetAngleZ(float defaultvalue)
|
|
|
|
|
{
|
|
|
|
|
return slopeangle.GetResultFloat(defaultvalue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetOffset(float defaultvalue)
|
|
|
|
|
{
|
|
|
|
|
return slopeoffset.GetResultFloat(defaultvalue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
public void SetValues(float anglexy, float anglez, float offset, bool first)
|
|
|
|
|
{
|
|
|
|
|
if (first)
|
|
|
|
|
{
|
2014-09-04 12:34:26 +00:00
|
|
|
|
// Set values
|
2014-07-11 10:13:26 +00:00
|
|
|
|
this.anglexy = anglexy;
|
|
|
|
|
this.anglez = anglez;
|
|
|
|
|
this.offset = offset;
|
2014-10-17 11:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-09-04 12:34:26 +00:00
|
|
|
|
// Or update values
|
2014-07-11 10:13:26 +00:00
|
|
|
|
if(!float.IsNaN(this.anglexy) && this.anglexy != anglexy) this.anglexy = float.NaN;
|
|
|
|
|
if(!float.IsNaN(this.anglez) && this.anglez != anglez) this.anglez = float.NaN;
|
|
|
|
|
if(!float.IsNaN(this.offset) && this.offset != offset) this.offset = float.NaN;
|
2014-09-04 12:34:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
public void SetOffset(float offset, bool first)
|
|
|
|
|
{
|
|
|
|
|
if(first)
|
|
|
|
|
{
|
2014-09-04 12:34:26 +00:00
|
|
|
|
this.offset = offset;
|
2014-10-17 11:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
else if(!float.IsNaN(this.offset) && this.offset != offset)
|
|
|
|
|
{
|
|
|
|
|
this.offset = float.NaN;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
2014-08-11 08:35:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
public void UpdateControls()
|
|
|
|
|
{
|
2014-08-11 08:35:39 +00:00
|
|
|
|
blockUpdate = true;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
if(float.IsNaN(anglexy))
|
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
sloperotation.Text = "";
|
2014-10-17 11:55:08 +00:00
|
|
|
|
rotationcontrol.Angle = GZBuilder.Controls.AngleControl.NO_ANGLE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-11 08:35:39 +00:00
|
|
|
|
sloperotation.Text = anglexy.ToString();
|
2014-10-17 11:55:08 +00:00
|
|
|
|
rotationcontrol.Angle = (int)Math.Round(anglexy + 90);
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
if(float.IsNaN(anglez))
|
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
slopeangle.Text = "";
|
|
|
|
|
angletrackbar.Value = 0;
|
2014-10-17 11:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-08-25 11:15:19 +00:00
|
|
|
|
//clamp value to [-85 .. 85]
|
|
|
|
|
anglez = General.Clamp(anglez, angletrackbar.Minimum, angletrackbar.Maximum);
|
|
|
|
|
|
2014-08-11 08:35:39 +00:00
|
|
|
|
slopeangle.Text = anglez.ToString();
|
2014-08-25 11:15:19 +00:00
|
|
|
|
angletrackbar.Value = (int)General.Clamp(anglez, angletrackbar.Minimum, angletrackbar.Maximum);
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-04 12:34:26 +00:00
|
|
|
|
slopeoffset.Text = (float.IsNaN(offset) ? "" : offset.ToString());
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
public void UpdateOffset()
|
|
|
|
|
{
|
2014-09-04 12:34:26 +00:00
|
|
|
|
blockUpdate = true;
|
|
|
|
|
slopeoffset.Text = (float.IsNaN(offset) ? "" : offset.ToString());
|
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
2014-08-25 11:15:19 +00:00
|
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void sloperotation_WhenTextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
if(blockUpdate) return;
|
|
|
|
|
blockUpdate = true;
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
anglexy = General.ClampAngle(sloperotation.GetResultFloat(float.NaN));
|
|
|
|
|
rotationcontrol.Angle = (float.IsNaN(anglexy) ? GZBuilder.Controls.AngleControl.NO_ANGLE : (int)Math.Round(anglexy + 90));
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2014-09-04 12:34:26 +00:00
|
|
|
|
if(OnAnglesChanged != null) OnAnglesChanged(this, EventArgs.Empty);
|
2014-07-11 10:13:26 +00:00
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-24 18:32:24 +00:00
|
|
|
|
private void rotationcontrol_AngleChanged(object sender, EventArgs e)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
if(blockUpdate) return;
|
|
|
|
|
blockUpdate = true;
|
|
|
|
|
|
2014-08-25 11:15:19 +00:00
|
|
|
|
anglexy = General.ClampAngle(rotationcontrol.Angle - 90);
|
|
|
|
|
sloperotation.Text = anglexy.ToString();
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2014-09-04 12:34:26 +00:00
|
|
|
|
if(OnAnglesChanged != null) OnAnglesChanged(this, EventArgs.Empty);
|
2014-07-11 10:13:26 +00:00
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void slopeangle_WhenTextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
if(blockUpdate) return;
|
|
|
|
|
blockUpdate = true;
|
|
|
|
|
|
2014-08-25 11:15:19 +00:00
|
|
|
|
anglez = General.Clamp((int)Math.Round(slopeangle.GetResultFloat(0f)), angletrackbar.Minimum, angletrackbar.Maximum);
|
|
|
|
|
angletrackbar.Value = (int)anglez;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2014-09-04 12:34:26 +00:00
|
|
|
|
if(OnAnglesChanged != null) OnAnglesChanged(this, EventArgs.Empty);
|
2014-07-11 10:13:26 +00:00
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void angletrackbar_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
if(blockUpdate) return;
|
|
|
|
|
blockUpdate = true;
|
|
|
|
|
|
|
|
|
|
slopeangle.Text = angletrackbar.Value.ToString();
|
2014-08-25 11:15:19 +00:00
|
|
|
|
anglez = angletrackbar.Value;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2014-09-04 12:34:26 +00:00
|
|
|
|
if(OnAnglesChanged != null) OnAnglesChanged(this, EventArgs.Empty);
|
2014-07-11 10:13:26 +00:00
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void slopeoffset_WhenTextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
offset = slopeoffset.GetResultFloat(float.NaN);
|
|
|
|
|
if(OnAnglesChanged != null) OnAnglesChanged(this, EventArgs.Empty);
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void reset_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
blockUpdate = true;
|
|
|
|
|
|
|
|
|
|
sloperotation.Text = "0";
|
2014-08-25 11:15:19 +00:00
|
|
|
|
rotationcontrol.Angle = 90;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
slopeangle.Text = "0";
|
|
|
|
|
angletrackbar.Value = 0;
|
|
|
|
|
slopeoffset.Text = "0";
|
|
|
|
|
anglexy = 0f;
|
|
|
|
|
anglez = 0f;
|
|
|
|
|
offset = 0f;
|
|
|
|
|
|
2014-09-04 12:34:26 +00:00
|
|
|
|
if(OnResetClicked != null) OnResetClicked(this, EventArgs.Empty);
|
2014-07-11 10:13:26 +00:00
|
|
|
|
blockUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void pivotmodeselector_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-09-04 12:34:26 +00:00
|
|
|
|
if(blockUpdate) return;
|
2014-10-17 11:55:08 +00:00
|
|
|
|
if(OnPivotModeChanged != null) OnPivotModeChanged(this, EventArgs.Empty);
|
2014-08-25 11:15:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void cbuselineangles_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-09-15 08:15:22 +00:00
|
|
|
|
sloperotation.ButtonStepsWrapAround = cbuselineangles.Checked;
|
2014-08-25 11:15:19 +00:00
|
|
|
|
if(blockUpdate) return;
|
|
|
|
|
if(OnUseLineAnglesChanged != null) OnUseLineAnglesChanged(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|