Merge remote-tracking branch 'origin/master' into 1.9

# Conflicts:
#	Source/Engine/Content/Storage/FlaxStorage.cpp
#	Source/Engine/Renderer/GBufferPass.cpp
This commit is contained in:
Wojtek Figat
2024-05-15 23:49:05 +02:00
54 changed files with 902 additions and 360 deletions

View File

@@ -4,6 +4,27 @@ using System.ComponentModel;
namespace FlaxEngine.GUI
{
/// <summary>
/// Options for text case
/// </summary>
public enum TextCaseOptions
{
/// <summary>
/// No text case.
/// </summary>
None,
/// <summary>
/// Uppercase.
/// </summary>
Uppercase,
/// <summary>
/// Lowercase
/// </summary>
Lowercase
}
/// <summary>
/// The basic GUI label control.
/// </summary>
@@ -45,6 +66,24 @@ namespace FlaxEngine.GUI
}
}
/// <summary>
/// The text case.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2000), Tooltip("The case of the text.")]
public TextCaseOptions CaseOption { get; set; } = TextCaseOptions.None;
/// <summary>
/// Whether to bold the text.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2001), Tooltip("Bold the text.")]
public bool Bold { get; set; } = false;
/// <summary>
/// Whether to italicize the text.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2002), Tooltip("Italicize the text.")]
public bool Italic { get; set; } = false;
/// <summary>
/// Gets or sets the color of the text.
/// </summary>
@@ -234,18 +273,49 @@ namespace FlaxEngine.GUI
}
}
Render2D.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale);
Font font = GetFont();
var text = ConvertedText();
Render2D.DrawText(font, Material, text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale);
if (ClipText)
Render2D.PopClip();
}
private Font GetFont()
{
Font font;
if (Bold)
font = Italic ? _font.GetBold().GetItalic().GetFont() : _font.GetBold().GetFont();
else if (Italic)
font = _font.GetItalic().GetFont();
else
font = _font.GetFont();
return font;
}
private LocalizedString ConvertedText()
{
LocalizedString text = _text;
switch (CaseOption)
{
case TextCaseOptions.Uppercase:
text = text.ToString().ToUpper();
break;
case TextCaseOptions.Lowercase:
text = text.ToString().ToLower();
break;
}
return text;
}
/// <inheritdoc />
protected override void PerformLayoutBeforeChildren()
{
if (_autoWidth || _autoHeight || _autoFitText)
{
var font = _font.GetFont();
Font font = GetFont();
var text = ConvertedText();
if (font)
{
// Calculate text size
@@ -255,7 +325,7 @@ namespace FlaxEngine.GUI
layout.Bounds.Size.X = Width - Margin.Width;
else if (_autoWidth && !_autoHeight)
layout.Bounds.Size.Y = Height - Margin.Height;
_textSize = font.MeasureText(_text, ref layout);
_textSize = font.MeasureText(text, ref layout);
_textSize.Y *= BaseLinesGapScale;
// Check if size is controlled via text

View File

@@ -24,11 +24,49 @@ namespace FlaxEngine.GUI
get => _watermarkText;
set => _watermarkText = value;
}
/// <summary>
/// The text case.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2000), Tooltip("The case of the text.")]
public TextCaseOptions CaseOption { get; set; } = TextCaseOptions.None;
/// <summary>
/// Whether to bold the text.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2001), Tooltip("Bold the text.")]
public bool Bold { get; set; } = false;
/// <summary>
/// Whether to italicize the text.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2002), Tooltip("Italicize the text.")]
public bool Italic { get; set; } = false;
/// <summary>
/// The vertical alignment of the text.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2023), Tooltip("The vertical alignment of the text.")]
public TextAlignment VerticalAlignment
{
get => _layout.VerticalAlignment;
set => _layout.VerticalAlignment = value;
}
/// <summary>
/// The vertical alignment of the text.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2024), Tooltip("The horizontal alignment of the text.")]
public TextAlignment HorizontalAlignment
{
get => _layout.HorizontalAlignment;
set => _layout.HorizontalAlignment = value;
}
/// <summary>
/// Gets or sets the text wrapping within the control bounds.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2023), Tooltip("The text wrapping within the control bounds.")]
[EditorDisplay("Text Style"), EditorOrder(2025), Tooltip("The text wrapping within the control bounds.")]
public TextWrapping Wrapping
{
get => _layout.TextWrapping;
@@ -38,13 +76,13 @@ namespace FlaxEngine.GUI
/// <summary>
/// Gets or sets the font.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2024)]
[EditorDisplay("Text Style"), EditorOrder(2026)]
public FontReference Font { get; set; }
/// <summary>
/// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.
/// </summary>
[EditorDisplay("Text Style"), EditorOrder(2025), Tooltip("Custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")]
[EditorDisplay("Text Style"), EditorOrder(2027), Tooltip("Custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")]
public MaterialBase TextMaterial { get; set; }
/// <summary>
@@ -98,19 +136,46 @@ namespace FlaxEngine.GUI
/// <inheritdoc />
public override Float2 GetTextSize()
{
var font = Font.GetFont();
var font = GetFont();
if (font == null)
{
return Float2.Zero;
}
return font.MeasureText(_text, ref _layout);
return font.MeasureText(ConvertedText(), ref _layout);
}
private Font GetFont()
{
Font font;
if (Bold)
font = Italic ? Font.GetBold().GetItalic().GetFont() : Font.GetBold().GetFont();
else if (Italic)
font = Font.GetItalic().GetFont();
else
font = Font.GetFont();
return font;
}
private string ConvertedText()
{
string text = _text;
switch (CaseOption)
{
case TextCaseOptions.Uppercase:
text = text.ToUpper();
break;
case TextCaseOptions.Lowercase:
text = text.ToLower();
break;
}
return text;
}
/// <inheritdoc />
public override Float2 GetCharPosition(int index, out float height)
{
var font = Font.GetFont();
var font = GetFont();
if (font == null)
{
height = Height;
@@ -118,19 +183,19 @@ namespace FlaxEngine.GUI
}
height = font.Height / DpiScale;
return font.GetCharPosition(_text, index, ref _layout);
return font.GetCharPosition(ConvertedText(), index, ref _layout);
}
/// <inheritdoc />
public override int HitTestText(Float2 location)
{
var font = Font.GetFont();
var font = GetFont();
if (font == null)
{
return 0;
}
return font.HitTestText(_text, location, ref _layout);
return font.HitTestText(ConvertedText(), location, ref _layout);
}
/// <inheritdoc />
@@ -147,7 +212,7 @@ namespace FlaxEngine.GUI
// Cache data
var rect = new Rectangle(Float2.Zero, Size);
bool enabled = EnabledInHierarchy;
var font = Font.GetFont();
var font = GetFont();
if (!font)
return;
@@ -166,11 +231,13 @@ namespace FlaxEngine.GUI
if (useViewOffset)
Render2D.PushTransform(Matrix3x3.Translation2D(-_viewOffset));
var text = ConvertedText();
// Check if sth is selected to draw selection
if (HasSelection)
{
var leftEdge = font.GetCharPosition(_text, SelectionLeft, ref _layout);
var rightEdge = font.GetCharPosition(_text, SelectionRight, ref _layout);
var leftEdge = font.GetCharPosition(text, SelectionLeft, ref _layout);
var rightEdge = font.GetCharPosition(text, SelectionRight, ref _layout);
var fontHeight = font.Height;
var textHeight = fontHeight / DpiScale;
@@ -207,12 +274,12 @@ namespace FlaxEngine.GUI
}
// Text or watermark
if (_text.Length > 0)
if (text.Length > 0)
{
var color = TextColor;
if (!enabled)
color *= 0.6f;
Render2D.DrawText(font, _text, color, ref _layout, TextMaterial);
Render2D.DrawText(font, text, color, ref _layout, TextMaterial);
}
else if (!string.IsNullOrEmpty(_watermarkText))
{
@@ -224,7 +291,25 @@ namespace FlaxEngine.GUI
{
float alpha = Mathf.Saturate(Mathf.Cos(_animateTime * CaretFlashSpeed) * 0.5f + 0.7f);
alpha = alpha * alpha * alpha * alpha * alpha * alpha;
Render2D.FillRectangle(CaretBounds, CaretColor * alpha);
if (CaretPosition == 0)
{
var bounds = CaretBounds;
if (_layout.VerticalAlignment == TextAlignment.Center)
bounds.Y = _layout.Bounds.Y + _layout.Bounds.Height * 0.5f - bounds.Height * 0.5f;
else if (_layout.VerticalAlignment == TextAlignment.Far)
bounds.Y = _layout.Bounds.Y + _layout.Bounds.Height - bounds.Height;
if (_layout.HorizontalAlignment == TextAlignment.Center)
bounds.X = _layout.Bounds.X + _layout.Bounds.Width * 0.5f - bounds.Width * 0.5f;
else if (_layout.HorizontalAlignment == TextAlignment.Far)
bounds.X = _layout.Bounds.X + _layout.Bounds.Width - bounds.Width;
Render2D.FillRectangle(bounds, CaretColor * alpha);
}
else
{
Render2D.FillRectangle(CaretBounds, CaretColor * alpha);
}
}
// Restore rendering state

View File

@@ -17,6 +17,9 @@ namespace FlaxEngine.GUI
private ScrollBars _scrollBars;
private float _scrollBarsSize = ScrollBar.DefaultSize;
private Margin _scrollMargin;
private Color _scrollbarTrackColor;
private Color _scrollbarThumbColor;
private Color _scrollbarThumbSelectedColor;
/// <summary>
/// The cached scroll area bounds. Used to scroll contents of the panel control. Cached during performing layout.
@@ -49,7 +52,7 @@ namespace FlaxEngine.GUI
/// <summary>
/// Gets or sets the scroll bars usage by this panel.
/// </summary>
[EditorOrder(0), Tooltip("The scroll bars usage.")]
[EditorDisplay("Scrollbar Style"), EditorOrder(1500), Tooltip("The scroll bars usage.")]
public ScrollBars ScrollBars
{
get => _scrollBars;
@@ -73,6 +76,12 @@ namespace FlaxEngine.GUI
//VScrollBar.X += VScrollBar.Width;
VScrollBar.ValueChanged += () => SetViewOffset(Orientation.Vertical, VScrollBar.Value);
}
if (VScrollBar != null)
{
VScrollBar.TrackColor = _scrollbarTrackColor;
VScrollBar.ThumbColor = _scrollbarThumbColor;
VScrollBar.ThumbSelectedColor = _scrollbarThumbSelectedColor;
}
}
else if (VScrollBar != null)
{
@@ -94,6 +103,12 @@ namespace FlaxEngine.GUI
//HScrollBar.Offsets += new Margin(0, 0, HScrollBar.Height * 0.5f, 0);
HScrollBar.ValueChanged += () => SetViewOffset(Orientation.Horizontal, HScrollBar.Value);
}
if (HScrollBar != null)
{
HScrollBar.TrackColor = _scrollbarTrackColor;
HScrollBar.ThumbColor = _scrollbarThumbColor;
HScrollBar.ThumbSelectedColor = _scrollbarThumbSelectedColor;
}
}
else if (HScrollBar != null)
{
@@ -108,7 +123,7 @@ namespace FlaxEngine.GUI
/// <summary>
/// Gets or sets the size of the scroll bars.
/// </summary>
[EditorOrder(5), Tooltip("Scroll bars size.")]
[EditorDisplay("Scrollbar Style"), EditorOrder(1501), Tooltip("Scroll bars size.")]
public float ScrollBarsSize
{
get => _scrollBarsSize;
@@ -124,7 +139,7 @@ namespace FlaxEngine.GUI
/// <summary>
/// Gets or sets a value indicating whether always show scrollbars. Otherwise show them only if scrolling is available.
/// </summary>
[EditorOrder(10), Tooltip("Whether always show scrollbars. Otherwise show them only if scrolling is available.")]
[EditorDisplay("Scrollbar Style"), EditorOrder(1502), Tooltip("Whether always show scrollbars. Otherwise show them only if scrolling is available.")]
public bool AlwaysShowScrollbars
{
get => _alwaysShowScrollbars;
@@ -157,7 +172,7 @@ namespace FlaxEngine.GUI
/// <summary>
/// Gets or sets the scroll margin applies to the child controls area. Can be used to expand the scroll area bounds by adding a margin.
/// </summary>
[EditorOrder(20), Tooltip("Scroll margin applies to the child controls area. Can be used to expand the scroll area bounds by adding a margin.")]
[EditorDisplay("Scrollbar Style"), EditorOrder(1503), Tooltip("Scroll margin applies to the child controls area. Can be used to expand the scroll area bounds by adding a margin.")]
public Margin ScrollMargin
{
get => _scrollMargin;
@@ -171,6 +186,57 @@ namespace FlaxEngine.GUI
}
}
/// <summary>
/// The color of the scroll bar track.
/// </summary>
[EditorDisplay("Scrollbar Style"), EditorOrder(1600), ExpandGroups]
public Color ScrollbarTrackColor
{
get => _scrollbarTrackColor;
set
{
_scrollbarTrackColor = value;
if (VScrollBar != null)
VScrollBar.TrackColor = _scrollbarTrackColor;
if (HScrollBar != null)
HScrollBar.TrackColor = _scrollbarTrackColor;
}
}
/// <summary>
/// The color of the scroll bar thumb.
/// </summary>
[EditorDisplay("Scrollbar Style"), EditorOrder(1601)]
public Color ScrollbarThumbColor
{
get => _scrollbarThumbColor;
set
{
_scrollbarThumbColor = value;
if (VScrollBar != null)
VScrollBar.ThumbColor = _scrollbarThumbColor;
if (HScrollBar != null)
HScrollBar.ThumbColor = _scrollbarThumbColor;
}
}
/// <summary>
/// The color of the scroll bar thumb when selected.
/// </summary>
[EditorDisplay("Scrollbar Style"), EditorOrder(1602)]
public Color ScrollbarThumbSelectedColor
{
get => _scrollbarThumbSelectedColor;
set
{
_scrollbarThumbSelectedColor = value;
if (VScrollBar != null)
VScrollBar.ThumbSelectedColor = _scrollbarThumbSelectedColor;
if (HScrollBar != null)
HScrollBar.ThumbSelectedColor = _scrollbarThumbSelectedColor;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Panel"/> class.
/// </summary>
@@ -187,6 +253,10 @@ namespace FlaxEngine.GUI
public Panel(ScrollBars scrollBars, bool autoFocus = false)
{
AutoFocus = autoFocus;
var style = Style.Current;
_scrollbarTrackColor = style.BackgroundHighlighted;
_scrollbarThumbColor = style.BackgroundNormal;
_scrollbarThumbSelectedColor = style.BackgroundSelected;
ScrollBars = scrollBars;
}

View File

@@ -74,6 +74,21 @@ namespace FlaxEngine.GUI
/// </summary>
public bool EnableSmoothing { get; set; } = true;
/// <summary>
/// The track color.
/// </summary>
public Color TrackColor;
/// <summary>
/// The thumb color.
/// </summary>
public Color ThumbColor;
/// <summary>
/// The selected thumb color.
/// </summary>
public Color ThumbSelectedColor;
/// <summary>
/// Gets or sets the minimum value.
/// </summary>
@@ -209,6 +224,10 @@ namespace FlaxEngine.GUI
AutoFocus = false;
_orientation = orientation;
var style = Style.Current;
TrackColor = style.BackgroundHighlighted;
ThumbColor = style.BackgroundNormal;
ThumbSelectedColor = style.BackgroundSelected;
}
/// <summary>
@@ -377,8 +396,8 @@ namespace FlaxEngine.GUI
base.Draw();
var style = Style.Current;
Render2D.FillRectangle(_trackRect, style.BackgroundHighlighted * _thumbOpacity);
Render2D.FillRectangle(_thumbRect, (_thumbClicked ? style.BackgroundSelected : style.BackgroundNormal) * _thumbOpacity);
Render2D.FillRectangle(_trackRect, TrackColor * _thumbOpacity);
Render2D.FillRectangle(_thumbRect, (_thumbClicked ? ThumbSelectedColor : ThumbColor) * _thumbOpacity);
}
/// <inheritdoc />

View File

@@ -234,11 +234,16 @@ namespace FlaxEngine.GUI
Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), Color.Lerp(style.BackgroundSelected, style.Background, 0.6f));
Render2D.FillRectangle(new Rectangle(1.1f, 1.1f, Width - 2, Height - 2), style.Background);
// Padding for text
var textRect = GetClientArea();
textRect.X += 5;
textRect.Width -= 10;
// Tooltip text
Render2D.DrawText(
style.FontMedium,
_currentText,
GetClientArea(),
textRect,
style.Foreground,
TextAlignment.Center,
TextAlignment.Center,