diff --git a/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs b/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs
index a824076f7..fb7a0b29d 100644
--- a/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs
+++ b/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs
@@ -79,7 +79,6 @@ namespace FlaxEditor.CustomEditors.Editors
public class ScaleEditor : Float3Editor
{
private Button _linkButton;
- private SpriteBrush _linkBrush;
///
public override void Initialize(LayoutElementsContainer layout)
@@ -89,20 +88,16 @@ namespace FlaxEditor.CustomEditors.Editors
LinkValues = Editor.Instance.Windows.PropertiesWin.ScaleLinked;
// Add button with the link icon.
- _linkBrush = new SpriteBrush(Editor.Instance.Icons.Link32);
- _linkButton = new Button
+ //Editor.Instance.Icons.Link32
+ _linkButton = new IconButton(Editor.Instance.Icons.Link32)
{
Parent = LinkedLabel,
Width = 18,
Height = 18,
- BackgroundBrush = _linkBrush,
- AnchorPreset = AnchorPresets.TopLeft,
+ AnchorPreset = AnchorPresets.TopLeft
};
_linkButton.Clicked += ToggleLink;
- _linkButton.BorderColor = Color.Transparent;
- _linkButton.BorderColorSelected = Color.Transparent;
- _linkButton.BorderColorHighlighted = Color.Transparent;
SetLinkStyle();
var x = LinkedLabel.Text.Value.Length * 7 + 5;
@@ -142,9 +137,7 @@ namespace FlaxEditor.CustomEditors.Editors
private void SetLinkStyle()
{
Color backgroundColor = LinkValues ? FlaxEngine.GUI.Style.Current.BackgroundSelected : FlaxEngine.GUI.Style.Current.ForegroundDisabled;
- _linkButton.BackgroundColor = backgroundColor;
- _linkButton.BackgroundColorHighlighted = backgroundColor.RGBMultiplied(0.9f);
- _linkButton.BackgroundColorSelected = backgroundColor.RGBMultiplied(0.8f);
+ _linkButton.SetColors(backgroundColor);
_linkButton.TooltipText = (LinkValues ? "Unlink" : "Link") + " values for uniform scaling.";
}
}
diff --git a/Source/Engine/UI/GUI/Common/Button.cs b/Source/Engine/UI/GUI/Common/Button.cs
index 0e0d29615..b6ee13e41 100644
--- a/Source/Engine/UI/GUI/Common/Button.cs
+++ b/Source/Engine/UI/GUI/Common/Button.cs
@@ -10,7 +10,7 @@ namespace FlaxEngine.GUI
public class Button : ContainerControl
{
///
- /// The default height fro the buttons.
+ /// The default height for the buttons.
///
public const float DefaultHeight = 24.0f;
@@ -195,7 +195,7 @@ namespace FlaxEngine.GUI
/// Sets the button colors palette based on a given main color.
///
/// The main color.
- public void SetColors(Color color)
+ public virtual void SetColors(Color color)
{
BackgroundColor = color;
BorderColor = color.RGBMultiplied(0.5f);
diff --git a/Source/Engine/UI/GUI/Common/IconButton.cs b/Source/Engine/UI/GUI/Common/IconButton.cs
index 196b4b9c4..e2652cd9f 100644
--- a/Source/Engine/UI/GUI/Common/IconButton.cs
+++ b/Source/Engine/UI/GUI/Common/IconButton.cs
@@ -9,159 +9,66 @@ namespace FlaxEngine.GUI
///
public class IconButton : Button
{
- ///
- public override void ClearState()
+ ///
+ /// The sprite rendered on the button.
+ ///
+ public SpriteHandle ButtonSprite { get; set; }
+
+ ///
+ /// Whether or not to hide the border of the button.
+ ///
+ public bool HideBorder = true;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The sprite used by the button.
+ public IconButton(SpriteHandle buttonSprite)
+ : this(0, 0, buttonSprite)
{
- base.ClearState();
-
- if (_isPressed)
- OnPressEnd();
}
- ///
- public override void DrawSelf()
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Position X coordinate
+ /// Position Y coordinate
+ /// The sprite used by the button.
+ /// Width
+ /// Height
+ /// Whether or not to hide the border.
+ public IconButton(float x, float y, SpriteHandle buttonSprite, float width = 120, float height = DefaultHeight, bool hideBorder = true)
+ : base(x, y, width, height)
{
- // Cache data
- Rectangle clientRect = new Rectangle(Float2.Zero, Size);
- bool enabled = EnabledInHierarchy;
- 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);
+ ButtonSprite = buttonSprite;
+ BackgroundBrush = new SpriteBrush(ButtonSprite);
+ HideBorder = hideBorder;
}
- ///
- public override void OnMouseEnter(Float2 location)
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Position
+ /// Size
+ /// The sprite used by the button.
+ public IconButton(Float2 location, Float2 size, SpriteHandle buttonSprite)
+ : this(location.X, location.Y, buttonSprite, size.X, size.Y)
{
- base.OnMouseEnter(location);
-
- HoverBegin?.Invoke();
}
- ///
- public override void OnMouseLeave()
+ ///
+ /// Sets the colors of the button, taking into account the field.>
+ ///
+ /// The color to use.
+ public override void SetColors(Color color)
{
- if (_isPressed)
- {
- OnPressEnd();
- }
+ BackgroundColor = color;
+ BackgroundColorSelected = color.RGBMultiplied(0.8f);
+ BackgroundColorHighlighted = color.RGBMultiplied(1.2f);
- HoverEnd?.Invoke();
-
- base.OnMouseLeave();
- }
-
- ///
- 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;
- }
-
- ///
- 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;
- }
-
- ///
- public override bool OnTouchDown(Float2 location, int pointerId)
- {
- if (base.OnTouchDown(location, pointerId))
- return true;
-
- if (!_isPressed)
- {
- OnPressBegin();
- return true;
- }
- return false;
- }
-
- ///
- public override bool OnTouchUp(Float2 location, int pointerId)
- {
- if (base.OnTouchUp(location, pointerId))
- return true;
-
- if (_isPressed)
- {
- OnPressEnd();
- OnClick();
- return true;
- }
- return false;
- }
-
- ///
- public override void OnTouchLeave()
- {
- if (_isPressed)
- {
- OnPressEnd();
- }
-
- base.OnTouchLeave();
- }
-
- ///
- public override void OnLostFocus()
- {
- if (_isPressed)
- {
- OnPressEnd();
- }
-
- base.OnLostFocus();
- }
-
- ///
- public override void OnSubmit()
- {
- OnClick();
-
- base.OnSubmit();
+ BorderColor = HideBorder ? Color.Transparent : color.RGBMultiplied(0.5f);
+ BorderColorSelected = BorderColor;
+ BorderColorHighlighted = BorderColor;
}
}
}