// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
namespace FlaxEngine.GUI
{
///
/// Button with an icon.
///
public class IconButton : Button
{
///
/// 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)
{
}
///
/// 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)
{
ButtonSprite = buttonSprite;
BackgroundBrush = new SpriteBrush(ButtonSprite);
HideBorder = hideBorder;
}
///
/// 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)
{
}
///
/// Sets the colors of the button, taking into account the field.>
///
/// The color to use.
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;
}
}
}