Finish implementing IconButton and use that to create a more intuitive scale linking interface.
This commit is contained in:
@@ -79,7 +79,6 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
public class ScaleEditor : Float3Editor
|
public class ScaleEditor : Float3Editor
|
||||||
{
|
{
|
||||||
private Button _linkButton;
|
private Button _linkButton;
|
||||||
private SpriteBrush _linkBrush;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Initialize(LayoutElementsContainer layout)
|
public override void Initialize(LayoutElementsContainer layout)
|
||||||
@@ -89,20 +88,16 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
LinkValues = Editor.Instance.Windows.PropertiesWin.ScaleLinked;
|
LinkValues = Editor.Instance.Windows.PropertiesWin.ScaleLinked;
|
||||||
|
|
||||||
// Add button with the link icon.
|
// Add button with the link icon.
|
||||||
_linkBrush = new SpriteBrush(Editor.Instance.Icons.Link32);
|
//Editor.Instance.Icons.Link32
|
||||||
_linkButton = new Button
|
_linkButton = new IconButton(Editor.Instance.Icons.Link32)
|
||||||
{
|
{
|
||||||
Parent = LinkedLabel,
|
Parent = LinkedLabel,
|
||||||
Width = 18,
|
Width = 18,
|
||||||
Height = 18,
|
Height = 18,
|
||||||
BackgroundBrush = _linkBrush,
|
AnchorPreset = AnchorPresets.TopLeft
|
||||||
AnchorPreset = AnchorPresets.TopLeft,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_linkButton.Clicked += ToggleLink;
|
_linkButton.Clicked += ToggleLink;
|
||||||
_linkButton.BorderColor = Color.Transparent;
|
|
||||||
_linkButton.BorderColorSelected = Color.Transparent;
|
|
||||||
_linkButton.BorderColorHighlighted = Color.Transparent;
|
|
||||||
SetLinkStyle();
|
SetLinkStyle();
|
||||||
|
|
||||||
var x = LinkedLabel.Text.Value.Length * 7 + 5;
|
var x = LinkedLabel.Text.Value.Length * 7 + 5;
|
||||||
@@ -142,9 +137,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
private void SetLinkStyle()
|
private void SetLinkStyle()
|
||||||
{
|
{
|
||||||
Color backgroundColor = LinkValues ? FlaxEngine.GUI.Style.Current.BackgroundSelected : FlaxEngine.GUI.Style.Current.ForegroundDisabled;
|
Color backgroundColor = LinkValues ? FlaxEngine.GUI.Style.Current.BackgroundSelected : FlaxEngine.GUI.Style.Current.ForegroundDisabled;
|
||||||
_linkButton.BackgroundColor = backgroundColor;
|
_linkButton.SetColors(backgroundColor);
|
||||||
_linkButton.BackgroundColorHighlighted = backgroundColor.RGBMultiplied(0.9f);
|
|
||||||
_linkButton.BackgroundColorSelected = backgroundColor.RGBMultiplied(0.8f);
|
|
||||||
_linkButton.TooltipText = (LinkValues ? "Unlink" : "Link") + " values for uniform scaling.";
|
_linkButton.TooltipText = (LinkValues ? "Unlink" : "Link") + " values for uniform scaling.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace FlaxEngine.GUI
|
|||||||
public class Button : ContainerControl
|
public class Button : ContainerControl
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The default height fro the buttons.
|
/// The default height for the buttons.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const float DefaultHeight = 24.0f;
|
public const float DefaultHeight = 24.0f;
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ namespace FlaxEngine.GUI
|
|||||||
/// Sets the button colors palette based on a given main color.
|
/// Sets the button colors palette based on a given main color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">The main color.</param>
|
/// <param name="color">The main color.</param>
|
||||||
public void SetColors(Color color)
|
public virtual void SetColors(Color color)
|
||||||
{
|
{
|
||||||
BackgroundColor = color;
|
BackgroundColor = color;
|
||||||
BorderColor = color.RGBMultiplied(0.5f);
|
BorderColor = color.RGBMultiplied(0.5f);
|
||||||
|
|||||||
@@ -9,159 +9,66 @@ namespace FlaxEngine.GUI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class IconButton : Button
|
public class IconButton : Button
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <summary>
|
||||||
public override void ClearState()
|
/// The sprite rendered on the button.
|
||||||
|
/// </summary>
|
||||||
|
public SpriteHandle ButtonSprite { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not to hide the border of the button.
|
||||||
|
/// </summary>
|
||||||
|
public bool HideBorder = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="IconButton"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="buttonSprite">The sprite used by the button.</param>
|
||||||
|
public IconButton(SpriteHandle buttonSprite)
|
||||||
|
: this(0, 0, buttonSprite)
|
||||||
{
|
{
|
||||||
base.ClearState();
|
|
||||||
|
|
||||||
if (_isPressed)
|
|
||||||
OnPressEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <summary>
|
||||||
public override void DrawSelf()
|
/// Initializes a new instance of the <see cref="IconButton"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">Position X coordinate</param>
|
||||||
|
/// <param name="y">Position Y coordinate</param>
|
||||||
|
/// <param name="buttonSprite">The sprite used by the button.</param>
|
||||||
|
/// <param name="width">Width</param>
|
||||||
|
/// <param name="height">Height</param>
|
||||||
|
/// <param name="hideBorder">Whether or not to hide the border.</param>
|
||||||
|
public IconButton(float x, float y, SpriteHandle buttonSprite, float width = 120, float height = DefaultHeight, bool hideBorder = true)
|
||||||
|
: base(x, y, width, height)
|
||||||
{
|
{
|
||||||
// Cache data
|
ButtonSprite = buttonSprite;
|
||||||
Rectangle clientRect = new Rectangle(Float2.Zero, Size);
|
BackgroundBrush = new SpriteBrush(ButtonSprite);
|
||||||
bool enabled = EnabledInHierarchy;
|
HideBorder = hideBorder;
|
||||||
Color backgroundColor = BackgroundColor;
|
|
||||||
Color borderColor = BorderColor;
|
|
||||||
Color textColor = TextColor;
|
|
||||||
if (!enabled)
|
|
||||||
{
|
|
||||||
backgroundColor *= 0.5f;
|
|
||||||
borderColor *= 0.5f;
|
|
||||||
textColor *= 0.6f;
|
|
||||||
}
|
|
||||||
else if (_isPressed)
|
|
||||||
{
|
|
||||||
backgroundColor = BackgroundColorSelected;
|
|
||||||
borderColor = BorderColorSelected;
|
|
||||||
}
|
|
||||||
else if (IsMouseOver || IsNavFocused)
|
|
||||||
{
|
|
||||||
backgroundColor = BackgroundColorHighlighted;
|
|
||||||
borderColor = BorderColorHighlighted;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw background
|
|
||||||
if (BackgroundBrush != null)
|
|
||||||
BackgroundBrush.Draw(clientRect, backgroundColor);
|
|
||||||
else
|
|
||||||
Render2D.FillRectangle(clientRect, backgroundColor);
|
|
||||||
Render2D.DrawRectangle(clientRect, borderColor);
|
|
||||||
|
|
||||||
// Draw text
|
|
||||||
Render2D.DrawText(_font?.GetFont(), TextMaterial, _text, clientRect, textColor, TextAlignment.Center, TextAlignment.Center);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <summary>
|
||||||
public override void OnMouseEnter(Float2 location)
|
/// Initializes a new instance of the <see cref="IconButton"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="location">Position</param>
|
||||||
|
/// <param name="size">Size</param>
|
||||||
|
/// <param name="buttonSprite">The sprite used by the button.</param>
|
||||||
|
public IconButton(Float2 location, Float2 size, SpriteHandle buttonSprite)
|
||||||
|
: this(location.X, location.Y, buttonSprite, size.X, size.Y)
|
||||||
{
|
{
|
||||||
base.OnMouseEnter(location);
|
|
||||||
|
|
||||||
HoverBegin?.Invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <summary>
|
||||||
public override void OnMouseLeave()
|
/// Sets the colors of the button, taking into account the <see cref="HideBorder"/> field.>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The color to use.</param>
|
||||||
|
public override void SetColors(Color color)
|
||||||
{
|
{
|
||||||
if (_isPressed)
|
BackgroundColor = color;
|
||||||
{
|
BackgroundColorSelected = color.RGBMultiplied(0.8f);
|
||||||
OnPressEnd();
|
BackgroundColorHighlighted = color.RGBMultiplied(1.2f);
|
||||||
}
|
|
||||||
|
|
||||||
HoverEnd?.Invoke();
|
BorderColor = HideBorder ? Color.Transparent : color.RGBMultiplied(0.5f);
|
||||||
|
BorderColorSelected = BorderColor;
|
||||||
base.OnMouseLeave();
|
BorderColorHighlighted = BorderColor;
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool OnMouseDown(Float2 location, MouseButton button)
|
|
||||||
{
|
|
||||||
if (base.OnMouseDown(location, button))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (button == MouseButton.Left && !_isPressed)
|
|
||||||
{
|
|
||||||
OnPressBegin();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool OnMouseUp(Float2 location, MouseButton button)
|
|
||||||
{
|
|
||||||
if (base.OnMouseUp(location, button))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (button == MouseButton.Left && _isPressed)
|
|
||||||
{
|
|
||||||
OnPressEnd();
|
|
||||||
OnClick();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool OnTouchDown(Float2 location, int pointerId)
|
|
||||||
{
|
|
||||||
if (base.OnTouchDown(location, pointerId))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!_isPressed)
|
|
||||||
{
|
|
||||||
OnPressBegin();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool OnTouchUp(Float2 location, int pointerId)
|
|
||||||
{
|
|
||||||
if (base.OnTouchUp(location, pointerId))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (_isPressed)
|
|
||||||
{
|
|
||||||
OnPressEnd();
|
|
||||||
OnClick();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void OnTouchLeave()
|
|
||||||
{
|
|
||||||
if (_isPressed)
|
|
||||||
{
|
|
||||||
OnPressEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnTouchLeave();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void OnLostFocus()
|
|
||||||
{
|
|
||||||
if (_isPressed)
|
|
||||||
{
|
|
||||||
OnPressEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnLostFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void OnSubmit()
|
|
||||||
{
|
|
||||||
OnClick();
|
|
||||||
|
|
||||||
base.OnSubmit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user