Fix color trackball usage with undo

This commit is contained in:
Wojciech Figat
2021-12-21 22:21:11 +01:00
parent e778fe8342
commit ae8d6ba433
2 changed files with 43 additions and 13 deletions

View File

@@ -44,6 +44,7 @@ namespace FlaxEditor.CustomEditors.Editors
// Trackball
_trackball = masterPanel.Custom<ColorSelector>();
_trackball.CustomControl.ColorChanged += OnColorWheelChanged;
_trackball.CustomControl.SlidingEnd += ClearToken;
// Scale editor
{
@@ -73,6 +74,7 @@ namespace FlaxEditor.CustomEditors.Editors
var element = layout.FloatValue();
element.SetLimits(limit);
element.FloatValue.ValueChanged += OnValueChanged;
element.FloatValue.SlidingEnd += ClearToken;
var back = FlaxEngine.GUI.Style.Current.TextBoxBackground;
var grayOutFactor = 0.6f;
element.FloatValue.BorderColor = Color.Lerp(borderColor, back, grayOutFactor);
@@ -85,7 +87,10 @@ namespace FlaxEditor.CustomEditors.Editors
if (IsSetBlocked)
return;
SetValue(new Vector4(color.R, color.G, color.B, _wElement.FloatValue.Value));
var isSliding = _trackball.CustomControl.IsSliding;
var token = isSliding ? this : null;
var value = new Vector4(color.R, color.G, color.B, _wElement.FloatValue.Value);
SetValue(value, token);
}
private void OnValueChanged()
@@ -93,11 +98,10 @@ namespace FlaxEditor.CustomEditors.Editors
if (IsSetBlocked)
return;
SetValue(new Vector4(
_xElement.FloatValue.Value,
_yElement.FloatValue.Value,
_zElement.FloatValue.Value,
_wElement.FloatValue.Value));
var isSliding = _xElement.IsSliding || _yElement.IsSliding || _zElement.IsSliding || _wElement.IsSliding;
var token = isSliding ? this : null;
var value = new Vector4(_xElement.FloatValue.Value, _yElement.FloatValue.Value, _zElement.FloatValue.Value, _wElement.FloatValue.Value);
SetValue(value, token);
}
/// <inheritdoc />

View File

@@ -46,6 +46,21 @@ namespace FlaxEditor.GUI.Dialogs
}
}
/// <summary>
/// Gets a value indicating whether user is using a wheel.
/// </summary>
public bool IsSliding => _isMouseDownWheel;
/// <summary>
/// Occurs when sliding starts.
/// </summary>
public event Action SlidingStart;
/// <summary>
/// Occurs when sliding ends.
/// </summary>
public event Action SlidingEnd;
/// <summary>
/// Initializes a new instance of the <see cref="ColorSelector"/> class.
/// </summary>
@@ -134,6 +149,15 @@ namespace FlaxEditor.GUI.Dialogs
}
}
private void EndSliding()
{
if (_isMouseDownWheel)
{
_isMouseDownWheel = false;
SlidingEnd?.Invoke();
}
}
/// <inheritdoc />
public override void Draw()
{
@@ -155,8 +179,7 @@ namespace FlaxEditor.GUI.Dialogs
/// <inheritdoc />
public override void OnLostFocus()
{
// Clear flags
_isMouseDownWheel = false;
EndSliding();
base.OnLostFocus();
}
@@ -174,8 +197,12 @@ namespace FlaxEditor.GUI.Dialogs
{
if (button == MouseButton.Left && _wheelRect.Contains(location))
{
_isMouseDownWheel = true;
StartMouseCapture();
if (!_isMouseDownWheel)
{
_isMouseDownWheel = true;
StartMouseCapture();
SlidingStart?.Invoke();
}
UpdateMouse(ref location);
}
@@ -188,8 +215,8 @@ namespace FlaxEditor.GUI.Dialogs
{
if (button == MouseButton.Left && _isMouseDownWheel)
{
_isMouseDownWheel = false;
EndMouseCapture();
EndSliding();
return true;
}
@@ -199,8 +226,7 @@ namespace FlaxEditor.GUI.Dialogs
/// <inheritdoc />
public override void OnEndMouseCapture()
{
// Clear flags
_isMouseDownWheel = false;
EndSliding();
}
/// <inheritdoc />