Add multifont rendering to editor

This commit is contained in:
ExMatics HydrogenC
2023-11-30 13:41:45 +08:00
parent a3bc394e4e
commit 41bbce56f6
69 changed files with 1132 additions and 647 deletions

View File

@@ -35,7 +35,7 @@ namespace FlaxEditor.GUI
/// <summary>
/// The title font.
/// </summary>
public Font TitleFont;
public MultiFont TitleFont;
/// <summary>
/// The column title text color.

View File

@@ -191,7 +191,7 @@ namespace FlaxEditor.GUI
/// Gets or sets the font used to draw text.
/// </summary>
[EditorDisplay("Style"), EditorOrder(2000)]
public FontReference Font { get; set; }
public MultiFontReference Font { get; set; }
/// <summary>
/// Gets or sets the color of the text.
@@ -273,7 +273,7 @@ namespace FlaxEditor.GUI
MaximumItemsInViewCount = 20;
var style = Style.Current;
Font = new FontReference(style.FontMedium.First());
Font = new MultiFontReference(style.FontMedium);
TextColor = style.Foreground;
BackgroundColor = style.BackgroundNormal;
BackgroundColorHighlighted = BackgroundColor;
@@ -554,7 +554,7 @@ namespace FlaxEditor.GUI
var textRect = new Rectangle(margin, 0, clientRect.Width - boxSize - 2.0f * margin, clientRect.Height);
Render2D.PushClip(textRect);
var textColor = TextColor;
Render2D.DrawText(Font.GetFont(), text, textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center, TextWrapping.NoWrap, 1.0f, textScale);
Render2D.DrawText(Font.GetMultiFont(), text, textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center, TextWrapping.NoWrap, 1.0f, textScale);
Render2D.PopClip();
}

View File

@@ -234,11 +234,11 @@ namespace FlaxEditor.GUI.ContextMenu
{
var style = Style.Current;
float width = 20;
if (style.FontMedium.First())
if (style.FontMedium)
{
width += style.FontMedium.First().MeasureText(Text).X;
width += style.FontMedium.MeasureText(Text).X;
if (!string.IsNullOrEmpty(ShortKeys))
width += 40 + style.FontMedium.First().MeasureText(ShortKeys).X;
width += 40 + style.FontMedium.MeasureText(ShortKeys).X;
}
return Mathf.Max(width, base.MinimumWidth);

View File

@@ -317,7 +317,7 @@ namespace FlaxEditor.GUI
private Color _contentsColor;
private Color _linesColor;
private Color _labelsColor;
private Font _labelsFont;
private MultiFont _labelsFont;
/// <summary>
/// The keyframe UI points.
@@ -437,7 +437,7 @@ namespace FlaxEditor.GUI
_contentsColor = style.Background.RGBMultiplied(0.7f);
_linesColor = style.ForegroundDisabled.RGBMultiplied(0.7f);
_labelsColor = style.ForegroundDisabled;
_labelsFont = style.FontSmall.First();
_labelsFont = style.FontSmall;
_mainPanel = new Panel(ScrollBars.Both)
{

View File

@@ -489,7 +489,7 @@ namespace FlaxEditor.GUI.Docking
{
var style = Style.Current;
if (style?.FontMedium != null)
_titleSize = style.FontMedium.First().MeasureText(_title);
_titleSize = style.FontMedium.MeasureText(_title);
}
base.PerformLayoutBeforeChildren();

View File

@@ -87,8 +87,8 @@ namespace FlaxEditor.GUI
var font = style.FontSmall;
for (int i = 0; i < ranges.Length; i++)
{
var start = font.First().GetCharPosition(Name, ranges[i].StartIndex);
var end = font.First().GetCharPosition(Name, ranges[i].EndIndex);
var start = font.GetCharPosition(Name, ranges[i].StartIndex);
var end = font.GetCharPosition(Name, ranges[i].EndIndex);
_highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height));
}
Visible = true;

View File

@@ -76,7 +76,7 @@ namespace FlaxEditor.GUI
var windowIcon = FlaxEngine.Content.LoadAsyncInternal<Texture>(EditorAssets.WindowIcon);
FontAsset windowIconsFont = FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.WindowIconsFont);
Font iconFont = windowIconsFont?.CreateFont(9);
MultiFont iconFont = new MultiFontReference([windowIconsFont], 9).GetMultiFont();
_window = mainWindow.RootWindow.Window;
_window.HitTest += OnHitTest;
@@ -108,7 +108,7 @@ namespace FlaxEditor.GUI
_closeButton = new Button
{
Text = ((char)EditorAssets.SegMDL2Icons.ChromeClose).ToString(),
Font = new FontReference(iconFont),
Font = new MultiFontReference(iconFont),
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
@@ -124,7 +124,7 @@ namespace FlaxEditor.GUI
_minimizeButton = new Button
{
Text = ((char)EditorAssets.SegMDL2Icons.ChromeMinimize).ToString(),
Font = new FontReference(iconFont),
Font = new MultiFontReference(iconFont),
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent,
@@ -139,7 +139,7 @@ namespace FlaxEditor.GUI
_maximizeButton = new Button
{
Text = ((char)(_window.IsMaximized ? EditorAssets.SegMDL2Icons.ChromeRestore : EditorAssets.SegMDL2Icons.ChromeMaximize)).ToString(),
Font = new FontReference(iconFont),
Font = new MultiFontReference(iconFont),
BackgroundColor = Color.Transparent,
BorderColor = Color.Transparent,
BorderColorHighlighted = Color.Transparent,

View File

@@ -102,8 +102,8 @@ namespace FlaxEditor.GUI
var style = Style.Current;
float width = 18;
if (style.FontMedium.First())
width += style.FontMedium.First().MeasureText(Text).X;
if (style.FontMedium)
width += style.FontMedium.MeasureText(Text).X;
Width = width;
}

View File

@@ -66,9 +66,9 @@ namespace FlaxEditor.GUI
{
var style = Style.Current;
if (style.FontMedium.First())
if (style.FontMedium)
{
Width = style.FontMedium.First().MeasureText(Text).X + 2 * DefaultMargin;
Width = style.FontMedium.MeasureText(Text).X + 2 * DefaultMargin;
}
}
}

View File

@@ -39,8 +39,8 @@ namespace FlaxEditor.GUI
{
Depth = -1;
if (Height < Style.Current.FontMedium.First().Height)
Height = Style.Current.FontMedium.First().Height + 4;
if (Height < Style.Current.FontMedium.MaxHeight)
Height = Style.Current.FontMedium.MaxHeight + 4;
}
/// <inheritdoc />

View File

@@ -130,7 +130,7 @@ namespace FlaxEditor.GUI
Render2D.FillRectangle(rect, column.TitleBackgroundColor);
var style = Style.Current;
var font = column.TitleFont ?? style.FontMedium.First();
var font = column.TitleFont ?? style.FontMedium;
Render2D.DrawText(font, column.Title, rect, column.TitleColor, TextAlignment.Center, TextAlignment.Center);
if (columnIndex < _columns.Length - 1)

View File

@@ -2,6 +2,7 @@
using System;
using System.Globalization;
using System.Linq;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -36,16 +37,16 @@ namespace FlaxEditor.GUI.Timeline.GUI
string labelText;
switch (_timeline.TimeShowMode)
{
case Timeline.TimeShowModes.Frames:
labelText = _timeline.CurrentFrame.ToString("###0", CultureInfo.InvariantCulture);
break;
case Timeline.TimeShowModes.Seconds:
labelText = _timeline.CurrentTime.ToString("###0.##'s'", CultureInfo.InvariantCulture);
break;
case Timeline.TimeShowModes.Time:
labelText = TimeSpan.FromSeconds(_timeline.CurrentTime).ToString("g");
break;
default: throw new ArgumentOutOfRangeException();
case Timeline.TimeShowModes.Frames:
labelText = _timeline.CurrentFrame.ToString("###0", CultureInfo.InvariantCulture);
break;
case Timeline.TimeShowModes.Seconds:
labelText = _timeline.CurrentTime.ToString("###0.##'s'", CultureInfo.InvariantCulture);
break;
case Timeline.TimeShowModes.Time:
labelText = TimeSpan.FromSeconds(_timeline.CurrentTime).ToString("g");
break;
default: throw new ArgumentOutOfRangeException();
}
var color = (_timeline.IsMovingPositionHandle ? style.ProgressNormal : style.Foreground).AlphaMultiplied(0.6f);
Matrix3x3.RotationZ(Mathf.PiOverTwo, out var m1);

View File

@@ -345,7 +345,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks
if (_previewValue != null)
{
// Based on Track.Draw for track text placement
var left = _xOffset + 16 + Style.Current.FontSmall.First().MeasureText(Title ?? Name).X;
var left = _xOffset + 16 + Style.Current.FontSmall.MeasureText(Title ?? Name).X;
if (Icon.IsValid)
left += 18;
if (IsExpanded)

View File

@@ -151,8 +151,8 @@ namespace FlaxEditor.GUI
if (hasSprite)
width += iconSize;
if (!string.IsNullOrEmpty(_text) && style.FontMedium.First())
width += style.FontMedium.First().MeasureText(_text).X + (hasSprite ? DefaultMargin : 0);
if (!string.IsNullOrEmpty(_text) && style.FontMedium)
width += style.FontMedium.MeasureText(_text).X + (hasSprite ? DefaultMargin : 0);
Width = width;
}

View File

@@ -115,7 +115,7 @@ namespace FlaxEditor.GUI.Tree
/// Gets or sets the font used to render text.
/// </summary>
[EditorDisplay("Style"), EditorOrder(2000)]
public FontReference TextFont { get; set; }
public MultiFontReference TextFont { get; set; }
/// <summary>
/// Gets or sets the color of the background when tree node is selected.
@@ -318,7 +318,7 @@ namespace FlaxEditor.GUI.Tree
BackgroundColorSelected = style.BackgroundSelected;
BackgroundColorHighlighted = style.BackgroundHighlighted;
BackgroundColorSelectedUnfocused = style.LightBackground;
TextFont = new FontReference(style.FontSmall.First());
TextFont = new MultiFontReference(style.FontSmall);
}
/// <summary>
@@ -573,7 +573,7 @@ namespace FlaxEditor.GUI.Tree
{
if (_textChanged)
{
var font = TextFont.GetFont();
var font = TextFont.GetMultiFont();
if (font)
{
_textWidth = font.MeasureText(_text).X;
@@ -657,7 +657,7 @@ namespace FlaxEditor.GUI.Tree
}
// Draw text
Render2D.DrawText(TextFont.GetFont(), _text, textRect, _cachedTextColor, TextAlignment.Near, TextAlignment.Center);
Render2D.DrawText(TextFont.GetMultiFont(), _text, textRect, _cachedTextColor, TextAlignment.Near, TextAlignment.Center);
// Draw drag and drop effect
if (IsDragOver && _tree.DraggedOverNode == this)