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 System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Text;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Actions;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
2009-07-10 19:15:22 +00:00
|
|
|
[Designer(typeof(ButtonsNumericTextboxDesigner))]
|
2009-07-10 13:56:22 +00:00
|
|
|
public partial class ButtonsNumericTextbox : UserControl
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
#region ================== Events
|
|
|
|
|
2009-07-10 19:15:22 +00:00
|
|
|
public event EventHandler WhenTextChanged;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
2009-07-10 13:56:22 +00:00
|
|
|
|
|
|
|
#region ================== Variables
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2009-07-10 13:56:22 +00:00
|
|
|
private bool ignorebuttonchange = false;
|
2009-07-10 19:15:22 +00:00
|
|
|
private StepsList steps = null;
|
|
|
|
private int stepsize = 1;
|
2009-07-10 13:56:22 +00:00
|
|
|
|
|
|
|
#endregion
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2009-07-10 13:56:22 +00:00
|
|
|
#region ================== Properties
|
2009-07-10 19:15:22 +00:00
|
|
|
|
|
|
|
public bool AllowDecimal { get { return textbox.AllowDecimal; } set { textbox.AllowDecimal = value; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
public bool AllowNegative { get { return textbox.AllowNegative; } set { textbox.AllowNegative = value; } }
|
2009-07-10 13:56:22 +00:00
|
|
|
public bool AllowRelative { get { return textbox.AllowRelative; } set { textbox.AllowRelative = value; } }
|
2009-07-10 19:15:22 +00:00
|
|
|
public int ButtonStep { get { return stepsize; } set { stepsize = value; } }
|
2009-07-10 13:56:22 +00:00
|
|
|
public string Text { get { return textbox.Text; } set { textbox.Text = value; } }
|
2009-07-10 19:15:22 +00:00
|
|
|
internal NumericTextbox Textbox { get { return textbox; } }
|
|
|
|
public StepsList StepValues { get { return steps; } set { steps = value; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2009-07-10 13:56:22 +00:00
|
|
|
public ButtonsNumericTextbox()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
2009-07-10 13:56:22 +00:00
|
|
|
buttons.Value = 0;
|
2009-07-10 19:15:22 +00:00
|
|
|
textbox.MouseWheel += textbox_MouseWheel;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Interface
|
|
|
|
|
|
|
|
// Client size changes
|
|
|
|
protected override void OnClientSizeChanged(EventArgs e)
|
|
|
|
{
|
|
|
|
base.OnClientSizeChanged(e);
|
|
|
|
ClickableNumericTextbox_Resize(this, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Layout changes
|
|
|
|
private void ClickableNumericTextbox_Layout(object sender, LayoutEventArgs e)
|
|
|
|
{
|
|
|
|
ClickableNumericTextbox_Resize(sender, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Control resizes
|
|
|
|
private void ClickableNumericTextbox_Resize(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
buttons.Height = textbox.Height + 4;
|
|
|
|
textbox.Width = ClientRectangle.Width - buttons.Width - 2;
|
|
|
|
buttons.Left = textbox.Width + 2;
|
|
|
|
this.Height = buttons.Height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Text in textbox changes
|
|
|
|
private void textbox_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
2009-07-10 19:15:22 +00:00
|
|
|
if(WhenTextChanged != null) WhenTextChanged(sender, e);
|
2009-07-10 13:56:22 +00:00
|
|
|
buttons.Enabled = !textbox.CheckIsRelative();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2009-07-10 13:56:22 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Buttons changed
|
|
|
|
private void buttons_ValueChanged(object sender, EventArgs e)
|
|
|
|
{
|
2009-07-10 13:56:22 +00:00
|
|
|
if(!ignorebuttonchange)
|
|
|
|
{
|
|
|
|
ignorebuttonchange = true;
|
|
|
|
if(!textbox.CheckIsRelative())
|
|
|
|
{
|
2009-07-10 19:15:22 +00:00
|
|
|
if(steps != null)
|
|
|
|
{
|
|
|
|
if(buttons.Value < 0)
|
|
|
|
textbox.Text = steps.GetNextHigher(textbox.GetResult(0)).ToString();
|
|
|
|
else if(buttons.Value > 0)
|
|
|
|
textbox.Text = steps.GetNextLower(textbox.GetResult(0)).ToString();
|
|
|
|
}
|
|
|
|
else if(textbox.AllowDecimal)
|
|
|
|
{
|
|
|
|
float newvalue = textbox.GetResultFloat(0.0f) - (float)(buttons.Value * stepsize);
|
|
|
|
if((newvalue < 0.0f) && !textbox.AllowNegative) newvalue = 0.0f;
|
|
|
|
textbox.Text = newvalue.ToString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int newvalue = textbox.GetResult(0) - (buttons.Value * stepsize);
|
|
|
|
if((newvalue < 0) && !textbox.AllowNegative) newvalue = 0;
|
|
|
|
textbox.Text = newvalue.ToString();
|
|
|
|
}
|
2009-07-10 13:56:22 +00:00
|
|
|
}
|
|
|
|
buttons.Value = 0;
|
|
|
|
ignorebuttonchange = false;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-10 19:15:22 +00:00
|
|
|
// Mouse wheel used
|
|
|
|
private void textbox_MouseWheel(object sender, MouseEventArgs e)
|
|
|
|
{
|
2009-07-10 19:19:28 +00:00
|
|
|
if(steps != null)
|
|
|
|
{
|
|
|
|
if(e.Delta > 0)
|
|
|
|
textbox.Text = steps.GetNextHigher(textbox.GetResult(0)).ToString();
|
|
|
|
else if(e.Delta < 0)
|
|
|
|
textbox.Text = steps.GetNextLower(textbox.GetResult(0)).ToString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(e.Delta < 0)
|
|
|
|
buttons.Value += 1;
|
|
|
|
else if(e.Delta > 0)
|
|
|
|
buttons.Value -= 1;
|
|
|
|
}
|
2009-07-10 19:15:22 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
2009-07-10 13:56:22 +00:00
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This checks if the number is relative
|
|
|
|
public bool CheckIsRelative()
|
|
|
|
{
|
|
|
|
return textbox.CheckIsRelative();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This determines the result value
|
|
|
|
public int GetResult(int original)
|
|
|
|
{
|
|
|
|
return textbox.GetResult(original);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This determines the result value
|
|
|
|
public float GetResultFloat(float original)
|
|
|
|
{
|
|
|
|
return textbox.GetResultFloat(original);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|