Merge branch 'scale-icon-change' of https://github.com/Menotdan/FlaxEngine into Menotdan-scale-icon-change

This commit is contained in:
Wojtek Figat
2023-05-16 12:01:10 +02:00
5 changed files with 99 additions and 12 deletions

View File

@@ -360,7 +360,7 @@ namespace FlaxEditor.Content
}
/// <summary>
/// Updates the tooltip text.
/// Updates the tooltip text text.
/// </summary>
public virtual void UpdateTooltipText()
{

View File

@@ -78,7 +78,7 @@ namespace FlaxEditor.CustomEditors.Editors
/// <seealso cref="FlaxEditor.CustomEditors.Editors.Float3Editor" />
public class ScaleEditor : Float3Editor
{
private Image _linkImage;
private Button _linkButton;
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
@@ -87,18 +87,22 @@ namespace FlaxEditor.CustomEditors.Editors
LinkValues = Editor.Instance.Windows.PropertiesWin.ScaleLinked;
_linkImage = new Image
// Add button with the link icon.
//Editor.Instance.Icons.Link32
_linkButton = new IconButton(Editor.Instance.Icons.Link32)
{
Parent = LinkedLabel,
Width = 18,
Height = 18,
Brush = LinkValues ? new SpriteBrush(Editor.Instance.Icons.Link32) : new SpriteBrush(),
AnchorPreset = AnchorPresets.TopLeft,
TooltipText = "Scale values are linked together.",
AnchorPreset = AnchorPresets.TopLeft
};
_linkButton.Clicked += ToggleLink;
SetLinkStyle();
var x = LinkedLabel.Text.Value.Length * 7 + 5;
_linkImage.LocalX += x;
_linkImage.LocalY += 1;
_linkButton.LocalX += x;
_linkButton.LocalY += 1;
LinkedLabel.SetupContextMenu += (label, menu, editor) =>
{
@@ -127,7 +131,14 @@ namespace FlaxEditor.CustomEditors.Editors
{
LinkValues = !LinkValues;
Editor.Instance.Windows.PropertiesWin.ScaleLinked = LinkValues;
_linkImage.Brush = LinkValues ? new SpriteBrush(Editor.Instance.Icons.Link32) : new SpriteBrush();
SetLinkStyle();
}
private void SetLinkStyle()
{
Color backgroundColor = LinkValues ? FlaxEngine.GUI.Style.Current.BackgroundSelected : FlaxEngine.GUI.Style.Current.ForegroundDisabled;
_linkButton.SetColors(backgroundColor);
_linkButton.TooltipText = (LinkValues ? "Unlink" : "Link") + " values for uniform scaling.";
}
}
}

View File

@@ -1037,7 +1037,9 @@ namespace FlaxEditor.Utilities
/// <returns>The processed name path.</returns>
public static string GetAssetNamePath(string path)
{
path = GetAssetNamePathWithExt(path);
var projectFolder = Globals.ProjectFolder;
if (path.StartsWith(projectFolder))
path = path.Substring(projectFolder.Length + 1);
return StringUtils.GetPathWithoutExtension(path);
}

View File

@@ -10,7 +10,7 @@ namespace FlaxEngine.GUI
public class Button : ContainerControl
{
/// <summary>
/// The default height fro the buttons.
/// The default height for the buttons.
/// </summary>
public const float DefaultHeight = 24.0f;
@@ -195,7 +195,7 @@ namespace FlaxEngine.GUI
/// Sets the button colors palette based on a given main color.
/// </summary>
/// <param name="color">The main color.</param>
public void SetColors(Color color)
public virtual void SetColors(Color color)
{
BackgroundColor = color;
BorderColor = color.RGBMultiplied(0.5f);

View File

@@ -0,0 +1,74 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
namespace FlaxEngine.GUI
{
/// <summary>
/// Button with an icon.
/// </summary>
public class IconButton : Button
{
/// <summary>
/// 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)
{
}
/// <summary>
/// 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)
{
ButtonSprite = buttonSprite;
BackgroundBrush = new SpriteBrush(ButtonSprite);
HideBorder = hideBorder;
}
/// <summary>
/// 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)
{
}
/// <summary>
/// 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)
{
BackgroundColor = color;
BackgroundColorSelected = color.RGBMultiplied(0.8f);
BackgroundColorHighlighted = color.RGBMultiplied(1.2f);
BorderColor = HideBorder ? Color.Transparent : color.RGBMultiplied(0.5f);
BorderColorSelected = BorderColor;
BorderColorHighlighted = BorderColor;
}
}
}