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
|
|
|
|
|
|
2015-01-09 13:56:54 +00:00
|
|
|
|
private bool preventchanges;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
// Slope values
|
2020-05-21 12:20:02 +00:00
|
|
|
|
private double anglexy;
|
|
|
|
|
private double anglez;
|
|
|
|
|
private double offset;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
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; } }
|
2015-01-09 13:56:54 +00:00
|
|
|
|
public bool UseLineAngles { get { return cbuselineangles.Checked; } set { preventchanges = true; cbuselineangles.Checked = value; preventchanges = 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
|
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = true;
|
2014-10-17 11:55:08 +00:00
|
|
|
|
pivotmodeselector.SelectedIndex = (int)value;
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = false;
|
2014-10-17 11:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
2020-05-18 16:14:54 +00:00
|
|
|
|
public double GetAngleXY(double defaultvalue)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
|
|
|
|
return sloperotation.GetResultFloat(defaultvalue);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 16:14:54 +00:00
|
|
|
|
public double GetAngleZ(double defaultvalue)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
|
|
|
|
return slopeangle.GetResultFloat(defaultvalue);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 16:14:54 +00:00
|
|
|
|
public double GetOffset(double defaultvalue)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
|
|
|
|
return slopeoffset.GetResultFloat(defaultvalue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
2020-05-22 20:30:32 +00:00
|
|
|
|
public void SetValues(double anglexy, double anglez, double offset, bool first)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(first)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
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
|
2021-03-21 16:38:43 +00:00
|
|
|
|
if(!double.IsNaN(this.anglexy) && this.anglexy != anglexy) this.anglexy = double.NaN;
|
|
|
|
|
if(!double.IsNaN(this.anglez) && this.anglez != anglez) this.anglez = double.NaN;
|
|
|
|
|
if(!double.IsNaN(this.offset) && this.offset != offset) this.offset = double.NaN;
|
2014-09-04 12:34:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 16:38:43 +00:00
|
|
|
|
public void SetOffset(double offset, bool first)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
|
|
|
|
if(first)
|
|
|
|
|
{
|
2014-09-04 12:34:26 +00:00
|
|
|
|
this.offset = offset;
|
2014-10-17 11:55:08 +00:00
|
|
|
|
}
|
2020-05-21 12:20:02 +00:00
|
|
|
|
else if(!double.IsNaN(this.offset) && this.offset != offset)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
2021-03-21 16:38:43 +00:00
|
|
|
|
this.offset = double.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()
|
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = true;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2020-05-21 12:20:02 +00:00
|
|
|
|
if(double.IsNaN(anglexy))
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
2014-07-11 10:13:26 +00:00
|
|
|
|
sloperotation.Text = "";
|
2016-04-27 09:13:07 +00:00
|
|
|
|
rotationcontrol.Angle = AngleControlEx.NO_ANGLE;
|
2014-10-17 11:55:08 +00:00
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 12:20:02 +00:00
|
|
|
|
if(double.IsNaN(anglez))
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 12:20:02 +00:00
|
|
|
|
slopeoffset.Text = (double.IsNaN(offset) ? "" : offset.ToString());
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = false;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
public void UpdateOffset()
|
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = true;
|
2020-05-21 12:20:02 +00:00
|
|
|
|
slopeoffset.Text = (double.IsNaN(offset) ? "" : offset.ToString());
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = false;
|
2014-09-04 12:34:26 +00:00
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
if(preventchanges) return;
|
|
|
|
|
preventchanges = true;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2020-05-21 12:20:02 +00:00
|
|
|
|
anglexy = General.ClampAngle(sloperotation.GetResultFloat(double.NaN));
|
|
|
|
|
rotationcontrol.Angle = (double.IsNaN(anglexy) ? AngleControlEx.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);
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = false;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-24 18:32:24 +00:00
|
|
|
|
private void rotationcontrol_AngleChanged(object sender, EventArgs e)
|
2014-10-17 11:55:08 +00:00
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
if(preventchanges) return;
|
|
|
|
|
preventchanges = true;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
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);
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = false;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void slopeangle_WhenTextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
if(preventchanges) return;
|
|
|
|
|
preventchanges = true;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
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);
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = false;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void angletrackbar_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
if(preventchanges) return;
|
|
|
|
|
preventchanges = true;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = false;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void slopeoffset_WhenTextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-03-21 16:38:43 +00:00
|
|
|
|
if (preventchanges) return;
|
|
|
|
|
preventchanges = true;
|
|
|
|
|
|
|
|
|
|
offset = slopeoffset.GetResultFloat(double.NaN);
|
2014-10-17 11:55:08 +00:00
|
|
|
|
if(OnAnglesChanged != null) OnAnglesChanged(this, EventArgs.Empty);
|
2021-03-21 16:38:43 +00:00
|
|
|
|
preventchanges = false;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void reset_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = true;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
|
|
|
|
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";
|
2021-03-21 16:38:43 +00:00
|
|
|
|
anglexy = 0.0;
|
|
|
|
|
anglez = 0.0;
|
|
|
|
|
offset = 0.0;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
|
2014-09-04 12:34:26 +00:00
|
|
|
|
if(OnResetClicked != null) OnResetClicked(this, EventArgs.Empty);
|
2015-01-09 13:56:54 +00:00
|
|
|
|
preventchanges = false;
|
2014-07-11 10:13:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 11:55:08 +00:00
|
|
|
|
private void pivotmodeselector_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-01-09 13:56:54 +00:00
|
|
|
|
if(preventchanges) 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;
|
2015-01-09 13:56:54 +00:00
|
|
|
|
if(preventchanges) return;
|
2014-08-25 11:15:19 +00:00
|
|
|
|
if(OnUseLineAnglesChanged != null) OnUseLineAnglesChanged(this, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|