2012-06-26 08:54:25 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2012-07-10 14:14:53 +00:00
|
|
|
|
using System.Globalization;
|
2012-06-26 08:54:25 +00:00
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.UDMFControls
|
|
|
|
|
{
|
|
|
|
|
public partial class FloatSlider : UserControl
|
|
|
|
|
{
|
|
|
|
|
private bool blockEvents;
|
|
|
|
|
public event EventHandler OnValueChanged;
|
|
|
|
|
|
|
|
|
|
public float Value {
|
|
|
|
|
get {
|
|
|
|
|
return (float)trackBar1.Value / 10f;
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
blockEvents = true;
|
2012-06-28 20:27:48 +00:00
|
|
|
|
float val = General.Clamp(value, (float)numericUpDown1.Minimum, (float)numericUpDown1.Maximum);
|
|
|
|
|
previousValue = (int)(val * 10f);
|
|
|
|
|
numericUpDown1.Value = (decimal)val;
|
2012-06-26 08:54:25 +00:00
|
|
|
|
blockEvents = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int previousValue;
|
|
|
|
|
private int delta;
|
|
|
|
|
public float Delta { get { return (float)delta / 10f; } }
|
|
|
|
|
|
|
|
|
|
private bool showLabels = true;
|
|
|
|
|
public bool ShowLabels {
|
|
|
|
|
get {
|
|
|
|
|
return showLabels;
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
showLabels = value;
|
|
|
|
|
labelMin.Visible = showLabels;
|
|
|
|
|
labelMax.Visible = showLabels;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FloatSlider() {
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
ShowLabels = showLabels;
|
|
|
|
|
numericUpDown1.DecimalPlaces = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetLimits(float min, float max, bool doubledLimits) {
|
|
|
|
|
blockEvents = true;
|
|
|
|
|
|
|
|
|
|
trackBar1.Value = General.Clamp(trackBar1.Value, (int)(min * 10), (int)(max * 10));
|
|
|
|
|
trackBar1.Minimum = (int)(min * 10);
|
|
|
|
|
trackBar1.Maximum = (int)(max * 10);
|
|
|
|
|
|
2012-07-10 14:14:53 +00:00
|
|
|
|
labelMin.Text = min.ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
labelMax.Text = max.ToString(CultureInfo.InvariantCulture);
|
2012-06-26 08:54:25 +00:00
|
|
|
|
|
|
|
|
|
numericUpDown1.Value = (decimal)General.Clamp((float)numericUpDown1.Value, min, max);
|
|
|
|
|
|
|
|
|
|
if (doubledLimits) {
|
2012-06-28 20:27:48 +00:00
|
|
|
|
numericUpDown1.Minimum = (decimal)(min * 10);
|
|
|
|
|
numericUpDown1.Maximum = (decimal)(max * 10);
|
2012-06-26 08:54:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
numericUpDown1.Minimum = (decimal)min;
|
|
|
|
|
numericUpDown1.Maximum = (decimal)max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blockEvents = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//events
|
|
|
|
|
private void trackBar1_ValueChanged(object sender, EventArgs e) {
|
|
|
|
|
int value = ((TrackBar)sender).Value;
|
|
|
|
|
delta = value - previousValue;
|
|
|
|
|
previousValue = value;
|
|
|
|
|
|
|
|
|
|
numericUpDown1.Value = Math.Round((decimal)(value / 10.0), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void numericUpDown1_ValueChanged(object sender, EventArgs e) {
|
|
|
|
|
float val = (float)((NumericUpDown)sender).Value;
|
|
|
|
|
|
|
|
|
|
if (!blockEvents && OnValueChanged != null)
|
|
|
|
|
OnValueChanged(this, EventArgs.Empty);
|
|
|
|
|
|
|
|
|
|
blockEvents = true;
|
|
|
|
|
trackBar1.Value = General.Clamp((int)(val * 10), trackBar1.Minimum, trackBar1.Maximum);
|
|
|
|
|
blockEvents = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|