2014-12-03 23:15:26 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderEffects
|
|
|
|
|
{
|
|
|
|
|
[DesignerCategory("code")]
|
|
|
|
|
internal partial class IntControl : UserControl
|
2013-09-11 09:47:53 +00:00
|
|
|
|
{
|
|
|
|
|
public event EventHandler OnValueChanging;
|
|
|
|
|
public event EventHandler OnValueChanged;
|
|
|
|
|
|
|
|
|
|
private int previousValue;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public int Value
|
|
|
|
|
{
|
|
|
|
|
get { return (int)numericUpDown1.Value; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
blockEvents = true;
|
|
|
|
|
previousValue = General.Clamp(value, (int)numericUpDown1.Minimum, (int)numericUpDown1.Maximum);
|
|
|
|
|
numericUpDown1.Value = previousValue;
|
|
|
|
|
valueChanged = false;
|
|
|
|
|
blockEvents = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal int Delta { get { return delta; } }
|
|
|
|
|
private int delta;
|
|
|
|
|
|
|
|
|
|
public string Label { get { return label1.Text; } set { label1.Text = value; } }
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public bool ExtendedLimits
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
get { return extendedLimits; }
|
|
|
|
|
set {
|
|
|
|
|
extendedLimits = value;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
UpdateLimits();
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private bool extendedLimits;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public bool AllowNegative
|
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
get { return allowNegative; }
|
|
|
|
|
set {
|
|
|
|
|
allowNegative = value;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(!allowNegative)
|
|
|
|
|
{
|
|
|
|
|
if(minimum < 0 && maximum < 0)
|
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
int diff = Math.Abs(maximum - minimum);
|
|
|
|
|
minimum = 0;
|
|
|
|
|
maximum = diff;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
|
if(minimum < 0) minimum = 0;
|
|
|
|
|
if(maximum < 0) maximum = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
UpdateLimits();
|
2013-03-18 13:52:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool allowNegative;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public int Minimum
|
|
|
|
|
{
|
|
|
|
|
get { return minimum; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
minimum = value;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
UpdateLimits();
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private int minimum;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
|
|
|
|
|
public int Maximum
|
|
|
|
|
{
|
|
|
|
|
get { return maximum; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
maximum = value;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
UpdateLimits();
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private int maximum;
|
|
|
|
|
|
|
|
|
|
private bool blockEvents;
|
|
|
|
|
private bool valueChanged;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
internal IntControl()
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
InitializeComponent();
|
2014-02-21 14:42:12 +00:00
|
|
|
|
numericUpDown1.MouseLeave += numericUpDown1_MouseLeave;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void UpdateLimits()
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
blockEvents = true;
|
|
|
|
|
|
|
|
|
|
trackBar1.Value = General.Clamp(trackBar1.Value, minimum, maximum);
|
|
|
|
|
trackBar1.Minimum = minimum;
|
|
|
|
|
trackBar1.Maximum = maximum;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
labelMaximum.Text = maximum.ToString();
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
numericUpDown1.Value = General.Clamp((int)numericUpDown1.Value, minimum, maximum);
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (extendedLimits)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
numericUpDown1.Minimum = minimum * 32;
|
|
|
|
|
numericUpDown1.Maximum = maximum * 32;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
numericUpDown1.Minimum = minimum;
|
|
|
|
|
numericUpDown1.Maximum = maximum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blockEvents = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//events
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void trackBar1_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
if (!blockEvents) numericUpDown1.Value = ((TrackBar)sender).Value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
int value = (int)((NumericUpDown)sender).Value;
|
|
|
|
|
if (value == previousValue) return;
|
|
|
|
|
|
|
|
|
|
valueChanged = true;
|
|
|
|
|
delta = value - previousValue;
|
|
|
|
|
previousValue = value;
|
|
|
|
|
|
|
|
|
|
if (!blockEvents && OnValueChanging != null)
|
|
|
|
|
OnValueChanging(this, EventArgs.Empty);
|
|
|
|
|
|
|
|
|
|
blockEvents = true;
|
|
|
|
|
trackBar1.Value = General.Clamp(value, trackBar1.Minimum, trackBar1.Maximum);
|
|
|
|
|
blockEvents = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void trackBar1_MouseLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (valueChanged && OnValueChanged != null)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
OnValueChanged(this, EventArgs.Empty);
|
|
|
|
|
valueChanged = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void numericUpDown1_MouseLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (valueChanged && OnValueChanged != null)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
OnValueChanged(this, EventArgs.Empty);
|
|
|
|
|
valueChanged = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2013-03-18 13:52:27 +00:00
|
|
|
|
}
|