Files
RobustToolbox/Robust.Client/UserInterface/Controls/CheckBox.cs
T
Pieter-Jan BriersandGitHub 09c36b57cd Shift half of Clyde around to implement better outline rendering. (#830)
* Attempted Clyde cleanup, didn't get far.

* Add negation operator to Vector2i.

* Add RenderOrder to ISpriteComponent.

* Post process shaders.

Adds "post process" shaders to sprite component.
These are executed on the WHOLE sprite component (every layer)
in one draw.

This is necessary to implement functional outlines.
2019-07-06 19:17:33 +02:00

78 lines
2.0 KiB
C#

using Robust.Client.Graphics;
using Robust.Client.Graphics.Drawing;
using Robust.Shared.Maths;
namespace Robust.Client.UserInterface.Controls
{
[ControlWrap("CheckBox")]
public class CheckBox : Button
{
public const string StylePropertyIcon = "icon";
public const string StylePropertyHSeparation = "hseparation";
public CheckBox()
{
}
public CheckBox(string name) : base(name)
{
}
protected internal override void Draw(DrawingHandleScreen handle)
{
var offset = 0;
var icon = _getIcon();
if (icon != null)
{
offset += _getIcon().Width + _getHSeparation();
var vOffset = (PixelHeight - _getIcon().Height) / 2;
handle.DrawTextureRectRegion(icon, UIBox2.FromDimensions((0, vOffset), icon.Size * UIScale));
}
var box = new UIBox2(offset, 0, PixelWidth, PixelHeight);
DrawTextInternal(handle, box);
}
protected override Vector2 CalculateMinimumSize()
{
var minSize = _getIcon()?.Size / UIScale ?? Vector2.Zero;
var font = ActualFont;
if (!string.IsNullOrWhiteSpace(Text) && !ClipText)
{
minSize += (EnsureWidthCache() / UIScale + _getHSeparation() / UIScale, 0);
}
minSize = Vector2.ComponentMax(minSize, (0, font.GetHeight(UIScale) / UIScale));
return minSize;
}
private Texture _getIcon()
{
if (TryGetStyleProperty(StylePropertyIcon, out Texture tex))
{
return tex;
}
return null;
}
private int _getHSeparation()
{
if (TryGetStyleProperty(StylePropertyHSeparation, out int hSep))
{
return hSep;
}
return 0;
}
protected override void SetDefaults()
{
base.SetDefaults();
ToggleMode = true;
}
}
}