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.ComponentModel;
|
2015-03-23 14:19:23 +00:00
|
|
|
using System.Globalization;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
2019-08-29 14:30:49 +00:00
|
|
|
#if !NO_FORMS_DESIGN
|
2009-07-10 19:15:22 +00:00
|
|
|
[Designer(typeof(ButtonsNumericTextboxDesigner))]
|
2019-08-29 14:30:49 +00:00
|
|
|
#endif
|
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-08-21 08:37:02 +00:00
|
|
|
public event EventHandler WhenButtonsClicked;
|
2010-01-02 20:22:05 +00:00
|
|
|
public event EventHandler WhenEnterPressed;
|
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
|
|
|
|
2014-02-21 14:42:12 +00:00
|
|
|
private bool ignorebuttonchange;
|
|
|
|
private StepsList steps;
|
2013-07-08 13:39:06 +00:00
|
|
|
private int stepsize = 1;
|
|
|
|
private float stepsizeFloat = 1.0f; //mxd
|
2015-03-23 14:19:23 +00:00
|
|
|
private float stepsizeBig = 10.0f; //mxd
|
|
|
|
private float stepsizeSmall = 0.1f; //mxd
|
2014-09-15 08:15:22 +00:00
|
|
|
private bool wrapsteps; //mxd
|
2015-03-23 14:19:23 +00:00
|
|
|
private bool usemodifierkeys; //mxd
|
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
|
|
|
|
2015-03-23 14:19:23 +00:00
|
|
|
public bool AllowDecimal { get { return textbox.AllowDecimal; } set { textbox.AllowDecimal = value; UpdateButtonsTooltip(); } }
|
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; } }
|
2016-10-10 14:14:47 +00:00
|
|
|
public bool AllowExpressions { get { return textbox.AllowExpressions; } set { textbox.AllowExpressions = value; } } //mxd/mgr_inz_rafal
|
2013-07-08 13:39:06 +00:00
|
|
|
public int ButtonStep { get { return stepsize; } set { stepsize = value; } }
|
|
|
|
public float ButtonStepFloat { get { return stepsizeFloat; } set { stepsizeFloat = value; } } //mxd. This is used when AllowDecimal is true
|
2015-03-23 14:19:23 +00:00
|
|
|
public float ButtonStepBig { get { return stepsizeBig; } set { stepsizeBig = value; } } //mxd
|
|
|
|
public float ButtonStepSmall { get { return stepsizeSmall; } set { stepsizeSmall = value; } } //mxd
|
2013-03-18 13:52:27 +00:00
|
|
|
override 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; } }
|
2015-03-23 14:19:23 +00:00
|
|
|
public StepsList StepValues { get { return steps; } set { steps = value; UpdateButtonsTooltip(); } }
|
2014-09-15 08:15:22 +00:00
|
|
|
public bool ButtonStepsWrapAround { get { return wrapsteps; } set { wrapsteps = value; } }
|
2015-03-23 14:19:23 +00:00
|
|
|
public bool ButtonStepsUseModifierKeys { get { return usemodifierkeys; } set { usemodifierkeys = value; UpdateButtonsTooltip(); } }
|
2014-09-15 08:15:22 +00:00
|
|
|
|
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;
|
2015-03-23 14:19:23 +00:00
|
|
|
UpdateButtonsTooltip(); //mxd
|
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())
|
|
|
|
{
|
2015-05-28 21:27:47 +00:00
|
|
|
bool ctrl = ((ModifierKeys & Keys.Control) == Keys.Control); //mxd
|
|
|
|
bool shift = ((ModifierKeys & Keys.Shift) == Keys.Shift); //mxd
|
|
|
|
|
|
|
|
if(steps != null && (!usemodifierkeys || (!ctrl && !shift)))
|
2009-07-10 19:15:22 +00:00
|
|
|
{
|
|
|
|
if(buttons.Value < 0)
|
2014-09-15 08:15:22 +00:00
|
|
|
textbox.Text = steps.GetNextHigherWrap(textbox.GetResult(0), wrapsteps).ToString(); //mxd
|
2009-07-10 19:15:22 +00:00
|
|
|
else if(buttons.Value > 0)
|
2014-09-15 08:15:22 +00:00
|
|
|
textbox.Text = steps.GetNextLowerWrap(textbox.GetResult(0), wrapsteps).ToString(); //mxd
|
2009-07-10 19:15:22 +00:00
|
|
|
}
|
|
|
|
else if(textbox.AllowDecimal)
|
|
|
|
{
|
2020-05-22 19:39:18 +00:00
|
|
|
double stepsizemod; //mxd
|
2015-03-23 14:19:23 +00:00
|
|
|
if(usemodifierkeys)
|
2015-05-28 21:27:47 +00:00
|
|
|
stepsizemod = (ctrl ? stepsizeSmall : (shift ? stepsizeBig : stepsizeFloat));
|
2015-03-23 14:19:23 +00:00
|
|
|
else
|
|
|
|
stepsizemod = stepsizeFloat;
|
|
|
|
|
2020-05-22 19:39:18 +00:00
|
|
|
double newvalue = Math.Round(textbox.GetResultFloat(0.0f) - (buttons.Value * stepsizemod), General.Map.FormatInterface.VertexDecimals);
|
2009-07-10 19:15:22 +00:00
|
|
|
if((newvalue < 0.0f) && !textbox.AllowNegative) newvalue = 0.0f;
|
2015-03-23 14:19:23 +00:00
|
|
|
textbox.Text = newvalue.ToString();
|
2009-07-10 19:15:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-23 14:19:23 +00:00
|
|
|
int stepsizemod; //mxd
|
|
|
|
if(usemodifierkeys)
|
2015-05-28 21:27:47 +00:00
|
|
|
stepsizemod = (ctrl ? (int)stepsizeSmall : (shift ? (int)stepsizeBig : stepsize));
|
2015-03-23 14:19:23 +00:00
|
|
|
else
|
|
|
|
stepsizemod = stepsize;
|
|
|
|
|
|
|
|
int newvalue = textbox.GetResult(0) - (buttons.Value * stepsizemod);
|
2009-07-10 19:15:22 +00:00
|
|
|
if((newvalue < 0) && !textbox.AllowNegative) newvalue = 0;
|
|
|
|
textbox.Text = newvalue.ToString();
|
|
|
|
}
|
2009-07-10 13:56:22 +00:00
|
|
|
}
|
2009-08-21 08:37:02 +00:00
|
|
|
|
2009-07-10 13:56:22 +00:00
|
|
|
buttons.Value = 0;
|
2009-08-21 08:37:02 +00:00
|
|
|
|
|
|
|
if(WhenButtonsClicked != null)
|
|
|
|
WhenButtonsClicked(this, EventArgs.Empty);
|
|
|
|
|
2009-07-10 13:56:22 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-05-28 21:27:47 +00:00
|
|
|
if(steps != null && (!usemodifierkeys || ((ModifierKeys & Keys.Control) != Keys.Control && (ModifierKeys & Keys.Shift) != Keys.Shift)))
|
2009-07-10 19:19:28 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2013-07-09 11:29:10 +00:00
|
|
|
buttons.Value -= Math.Sign(e.Delta);
|
2009-07-10 19:19:28 +00:00
|
|
|
}
|
2009-07-10 19:15:22 +00:00
|
|
|
}
|
2010-01-02 20:22:05 +00:00
|
|
|
|
|
|
|
// Key pressed in textbox
|
|
|
|
private void textbox_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
|
|
|
// Enter key?
|
|
|
|
if((e.KeyData == Keys.Enter) && (WhenEnterPressed != null))
|
|
|
|
WhenEnterPressed(this, EventArgs.Empty);
|
|
|
|
}
|
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);
|
|
|
|
}
|
2015-07-26 23:18:13 +00:00
|
|
|
|
|
|
|
//mxd. This determines the result value at given inremental step
|
|
|
|
public int GetResult(int original, int step)
|
|
|
|
{
|
|
|
|
return textbox.GetResult(original, step);
|
|
|
|
}
|
2009-07-10 13:56:22 +00:00
|
|
|
|
|
|
|
// This determines the result value
|
2020-05-18 16:14:54 +00:00
|
|
|
public double GetResultFloat(double original)
|
2009-07-10 13:56:22 +00:00
|
|
|
{
|
|
|
|
return textbox.GetResultFloat(original);
|
|
|
|
}
|
2015-03-23 14:19:23 +00:00
|
|
|
|
2015-07-26 23:18:13 +00:00
|
|
|
//mxd. This determines the result value at given inremental step
|
2020-05-18 16:14:54 +00:00
|
|
|
public double GetResultFloat(double original, int step)
|
2015-07-26 23:18:13 +00:00
|
|
|
{
|
|
|
|
return textbox.GetResultFloat(original, step);
|
|
|
|
}
|
|
|
|
|
2015-03-23 14:19:23 +00:00
|
|
|
//mxd
|
|
|
|
public void UpdateButtonsTooltip()
|
|
|
|
{
|
|
|
|
if(usemodifierkeys)
|
|
|
|
{
|
Fixed, Visual mode, Auto-align actions: incorrect texture was used when clamping texture offsets of 3D floor sides.
Fixed, Numeric textbox: incorrect character was treated as decimal separator character was used when using certain Windows regional settings.
Changed, Edit Things window: when applicable, the "Filter" textbox is now focused when opening the window.
Changed, Sector Effects browser window: when applicable, the "Filter" textbox is now focused when opening the window.
Changed, Edit Things window: when the "Filter" textbox is focused, pressing the "Down" key will now switch focus to the Things list.
Changed, Sector Effects Browser window: when the "Filter" textbox is focused, pressing the "Down" key will now switch focus to the Effects list.
Changed, Linedef Action Browser window: when the "Filter" textbox is focused, pressing the "Down" key will now switch focus to the Actions list.
Configurations, Doom map format thing flags: changed "Multiplayer" flag name to "Multiplayer only".
2015-09-23 11:04:12 +00:00
|
|
|
string tip = "Hold Ctrl to change value by " + stepsizeSmall.ToString(CultureInfo.CurrentCulture) + "." + Environment.NewLine +
|
|
|
|
"Hold Shift to change value by " + stepsizeBig.ToString(CultureInfo.CurrentCulture) + ".";
|
2015-03-23 14:19:23 +00:00
|
|
|
tooltip.SetToolTip(buttons, tip);
|
|
|
|
textbox.UpdateTextboxStyle(tip);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tooltip.RemoveAll();
|
|
|
|
textbox.UpdateTextboxStyle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-14 10:52:46 +00:00
|
|
|
// biwa
|
|
|
|
public void ResetIncrementStep()
|
|
|
|
{
|
|
|
|
textbox.ResetIncrementStep();
|
|
|
|
}
|
|
|
|
|
2021-08-21 07:28:05 +00:00
|
|
|
public void SelectAll()
|
|
|
|
{
|
|
|
|
textbox.SelectAll();
|
|
|
|
}
|
|
|
|
|
2009-07-10 13:56:22 +00:00
|
|
|
#endregion
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|