diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index e43751fd1..91eebe4eb 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -166,13 +166,13 @@ namespace FlaxEditor.Options /// Gets or sets the output log text font. /// [EditorDisplay("Output Log", "Text Font"), EditorOrder(320), Tooltip("The output log text font.")] - public MultiFontReference OutputLogTextFont + public FontReference OutputLogTextFont { get => _outputLogFont; set { - if (value == null || !value.Verify()) - _outputLogFont = new MultiFontReference(ConsoleFonts, 10); + if (value == null || !value.Font) + _outputLogFont = new FontReference(ConsoleFont, 10); else _outputLogFont = value; } @@ -238,14 +238,13 @@ namespace FlaxEditor.Options [FlaxEngine.Content.LoadAsyncInternal(EditorAssets.PrimaryFont), FlaxEngine.Content.LoadAsyncInternal(EditorAssets.CjkFont)]; - private static FontAsset[] ConsoleFonts => [FlaxEngine.Content.LoadAsyncInternal(EditorAssets.PrimaryFont), - FlaxEngine.Content.LoadAsyncInternal(EditorAssets.CjkFont)]; + private static FontAsset ConsoleFont => FlaxEngine.Content.LoadAsyncInternal(EditorAssets.PrimaryFont); private MultiFontReference _titleFont = new MultiFontReference(DefaultFonts, 18); private MultiFontReference _largeFont = new MultiFontReference(DefaultFonts, 14); private MultiFontReference _mediumFont = new MultiFontReference(DefaultFonts, 9); private MultiFontReference _smallFont = new MultiFontReference(DefaultFonts, 9); - private MultiFontReference _outputLogFont = new MultiFontReference(ConsoleFonts, 10); + private FontReference _outputLogFont = new FontReference(ConsoleFont, 10); /// diff --git a/Source/Editor/Windows/OutputLogWindow.cs b/Source/Editor/Windows/OutputLogWindow.cs index ac4fea5ba..f168d8d45 100644 --- a/Source/Editor/Windows/OutputLogWindow.cs +++ b/Source/Editor/Windows/OutputLogWindow.cs @@ -470,9 +470,9 @@ namespace FlaxEditor.Windows var wasEmpty = _output.TextLength == 0; // Cache fonts - _output.DefaultStyle.Font.GetMultiFont(); - _output.WarningStyle.Font.GetMultiFont(); - _output.ErrorStyle.Font.GetMultiFont(); + _output.DefaultStyle.Font.GetFont(); + _output.WarningStyle.Font.GetFont(); + _output.ErrorStyle.Font.GetFont(); // Generate the output log Span entries = CollectionsMarshal.AsSpan(_entries); @@ -536,7 +536,7 @@ namespace FlaxEditor.Windows } var prevBlockBottom = _textBlocks.Count == 0 ? 0.0f : _textBlocks[_textBlocks.Count - 1].Bounds.Bottom; var entryText = _textBuffer.ToString(startIndex, endIndex - startIndex); - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (!font) continue; var style = textBlock.Style; @@ -544,52 +544,46 @@ namespace FlaxEditor.Windows for (int j = 0; j < lines.Length; j++) { ref var line = ref lines[j]; - for (int k = 0; k < line.Blocks.Length; k++) + textBlock.Range.StartIndex = startIndex + line.FirstCharIndex; + textBlock.Range.EndIndex = startIndex + line.LastCharIndex + 1; + textBlock.Bounds = new Rectangle(new Float2(0.0f, prevBlockBottom), line.Size); + + if (textBlock.Range.Length > 0) { - ref var block = ref line.Blocks[k]; - - textBlock.Range.StartIndex = startIndex + block.FirstCharIndex; - textBlock.Range.EndIndex = startIndex + block.LastCharIndex + 1; - textBlock.Bounds = new Rectangle(new Float2(block.Location.X, prevBlockBottom), block.Size); - - if (textBlock.Range.Length > 0) + // Parse compilation error/warning + var regexStart = line.FirstCharIndex; + if (j == 0) + regexStart += prefixLength; + var regexLength = line.LastCharIndex + 1 - regexStart; + if (regexLength > 0) { - // Parse compilation error/warning - var regexStart = block.FirstCharIndex; - if (j == 0) - regexStart += prefixLength; - var regexLength = block.LastCharIndex + 1 - regexStart; - if (regexLength > 0) + var match = _compileRegex.Match(entryText, regexStart, regexLength); + if (match.Success) { - var match = _compileRegex.Match(entryText, regexStart, regexLength); - if (match.Success) + switch (match.Groups["level"].Value) { - switch (match.Groups["level"].Value) - { - case "error": - textBlock.Style = _output.ErrorStyle; - break; - case "warning": - textBlock.Style = _output.WarningStyle; - break; - } - textBlock.Tag = new TextBlockTag - { - Type = TextBlockTag.Types.CodeLocation, - Url = match.Groups["path"].Value, - Line = int.Parse(match.Groups["line"].Value), - }; + case "error": + textBlock.Style = _output.ErrorStyle; + break; + case "warning": + textBlock.Style = _output.WarningStyle; + break; } - // TODO: parsing hyperlinks with link - // TODO: parsing file paths with link + textBlock.Tag = new TextBlockTag + { + Type = TextBlockTag.Types.CodeLocation, + Url = match.Groups["path"].Value, + Line = int.Parse(match.Groups["line"].Value), + }; } + // TODO: parsing hyperlinks with link + // TODO: parsing file paths with link } - - _textBlocks.Add(textBlock); - textBlock.Style = style; } prevBlockBottom += line.Size.Y; + _textBlocks.Add(textBlock); + textBlock.Style = style; } } diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs b/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs index 9523ad30a..ab01df12b 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs @@ -186,7 +186,7 @@ namespace FlaxEngine.GUI }; // Process text into text blocks (handle newlines etc.) - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (!font) return; var lines = font.ProcessText(_text, ref textBlock.Range); @@ -195,27 +195,20 @@ namespace FlaxEngine.GUI for (int i = 0; i < lines.Length; i++) { ref var line = ref lines[i]; - + textBlock.Range = new TextRange + { + StartIndex = start + line.FirstCharIndex, + EndIndex = start + line.LastCharIndex, + }; if (i != 0) { context.Caret.X = 0; OnLineAdded(ref context, textBlock.Range.StartIndex - 1); } - for (int k = 0; k < line.Blocks.Length; k++) - { - ref var block = ref line.Blocks[k]; + textBlock.Bounds = new Rectangle(context.Caret, line.Size); + textBlock.Bounds.X += line.Location.X; - textBlock.Range = new TextRange - { - StartIndex = start + block.FirstCharIndex, - EndIndex = start + block.LastCharIndex, - }; - - textBlock.Bounds = new Rectangle(context.Caret, block.Size); - textBlock.Bounds.X += block.Location.X; - - context.AddTextBlock(ref textBlock); - } + context.AddTextBlock(ref textBlock); } // Update the caret location @@ -244,9 +237,9 @@ namespace FlaxEngine.GUI var ascender = textBlock.Ascender; //if (ascender <= 0) { - var textBlockFont = textBlock.Style.Font.GetMultiFont(); + var textBlockFont = textBlock.Style.Font.GetFont(); if (textBlockFont) - ascender = textBlockFont.MaxAscender; + ascender = textBlockFont.Ascender; } lineAscender = Mathf.Max(lineAscender, ascender); lineSize = Float2.Max(lineSize, textBlockSize); @@ -267,9 +260,9 @@ namespace FlaxEngine.GUI var ascender = textBlock.Ascender; if (ascender <= 0) { - var textBlockFont = textBlock.Style.Font.GetMultiFont(); + var textBlockFont = textBlock.Style.Font.GetFont(); if (textBlockFont) - ascender = textBlockFont.MaxAscender; + ascender = textBlockFont.Ascender; } vOffset = lineAscender - ascender; textBlock.Bounds.Location.Y += vOffset; diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs b/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs index 08637918d..d3c2feefe 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs @@ -11,9 +11,9 @@ namespace FlaxEngine.GUI { context.Caret.X = 0; var style = context.StyleStack.Peek(); - var font = style.Font.GetMultiFont(); + var font = style.Font.GetFont(); if (font) - context.Caret.Y += font.MaxHeight; + context.Caret.Y += font.Height; } private static void ProcessColor(ref ParsingContext context, ref HtmlTag tag) @@ -87,14 +87,15 @@ namespace FlaxEngine.GUI else { var style = context.StyleStack.Peek(); - style.Font = new MultiFontReference(style.Font); - if (tag.Attributes.TryGetValue("size", out var sizeText) && int.TryParse(sizeText, out var size) && tag.Attributes.TryGetValue(string.Empty, out var fontName)) + style.Font = new FontReference(style.Font); + if (tag.Attributes.TryGetValue(string.Empty, out var fontName)) { var font = (FontAsset)FindAsset(fontName, typeof(FontAsset)); if (font) - style.Font = new MultiFontReference([font], size); + style.Font.Font = font; } - + if (tag.Attributes.TryGetValue("size", out var sizeText) && int.TryParse(sizeText, out var size)) + style.Font.Size = size; context.StyleStack.Push(style); } } @@ -108,7 +109,7 @@ namespace FlaxEngine.GUI else { var style = context.StyleStack.Peek(); - // style.Font = style.Font.GetBold(); + style.Font = style.Font.GetBold(); context.StyleStack.Push(style); } } @@ -122,7 +123,7 @@ namespace FlaxEngine.GUI else { var style = context.StyleStack.Peek(); - // style.Font = style.Font.GetItalic(); + style.Font = style.Font.GetItalic(); context.StyleStack.Push(style); } } @@ -136,9 +137,9 @@ namespace FlaxEngine.GUI else { var style = context.StyleStack.Peek(); - style.Font = new MultiFontReference(style.Font); - TryParseNumberTag(ref tag, string.Empty, style.Font.First().Size, out var size); - style.Font = new MultiFontReference(style.Font, (int)size); + style.Font = new FontReference(style.Font); + TryParseNumberTag(ref tag, string.Empty, style.Font.Size, out var size); + style.Font.Size = (int)size; context.StyleStack.Push(style); } } @@ -173,9 +174,9 @@ namespace FlaxEngine.GUI imageBlock.Style.BackgroundBrush = image; // Setup size - var font = imageBlock.Style.Font.GetMultiFont(); + var font = imageBlock.Style.Font.GetFont(); if (font) - imageBlock.Bounds.Size = new Float2(font.MaxHeight); + imageBlock.Bounds.Size = new Float2(font.Height); imageBlock.Bounds.Size.X *= image.Size.X / image.Size.Y; // Keep original aspect ratio bool hasWidth = TryParseNumberTag(ref tag, "width", imageBlock.Bounds.Width, out var width); imageBlock.Bounds.Width = width; diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.cs b/Source/Engine/UI/GUI/Common/RichTextBox.cs index 78da9621c..f8ac7d353 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBox.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBox.cs @@ -46,7 +46,7 @@ namespace FlaxEngine.GUI var style = Style.Current; _textStyle = new TextBlockStyle { - Font = new MultiFontReference(style.FontMedium), + Font = new FontReference(style.FontMedium.Fonts.First()), Color = style.Foreground, BackgroundSelectedBrush = new SolidColorBrush(style.BackgroundSelected), }; diff --git a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs index 6247cb885..438a7e3d8 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs @@ -123,10 +123,10 @@ namespace FlaxEngine.GUI if (index <= 0) { ref TextBlock textBlock = ref textBlocks[0]; - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (font) { - height = font.MaxHeight / DpiScale; + height = font.Height / DpiScale; return textBlock.Bounds.UpperLeft; } } @@ -135,10 +135,10 @@ namespace FlaxEngine.GUI if (index >= _text.Length) { ref TextBlock textBlock = ref textBlocks[count - 1]; - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (font) { - height = font.MaxHeight / DpiScale; + height = font.Height / DpiScale; return textBlock.Bounds.UpperRight; } } @@ -150,10 +150,10 @@ namespace FlaxEngine.GUI if (textBlock.Range.Contains(index)) { - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (!font) break; - height = font.MaxHeight / DpiScale; + height = font.Height / DpiScale; return textBlock.Bounds.Location + font.GetCharPosition(_text, ref textBlock.Range, index - textBlock.Range.StartIndex); } } @@ -165,10 +165,10 @@ namespace FlaxEngine.GUI if (index >= textBlock.Range.EndIndex) { - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (!font) break; - height = font.MaxHeight / DpiScale; + height = font.Height / DpiScale; return textBlock.Bounds.UpperRight; } } @@ -193,7 +193,7 @@ namespace FlaxEngine.GUI if (containsY && (containsX || (i + 1 < count && textBlocks[i + 1].Bounds.Location.Y > textBlock.Bounds.Location.Y + 1.0f))) { - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (!font && textBlock.Range.Length > 0) break; return font.HitTestText(_text, ref textBlock.Range, location - textBlock.Bounds.Location) + textBlock.Range.StartIndex; @@ -281,7 +281,7 @@ namespace FlaxEngine.GUI } // Pick font - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (!font) continue; @@ -290,7 +290,7 @@ namespace FlaxEngine.GUI { var leftEdge = selection.StartIndex <= textBlock.Range.StartIndex ? textBlock.Bounds.UpperLeft : font.GetCharPosition(_text, selection.StartIndex); var rightEdge = selection.EndIndex >= textBlock.Range.EndIndex ? textBlock.Bounds.UpperRight : font.GetCharPosition(_text, selection.EndIndex); - float height = font.MaxHeight / DpiScale; + float height = font.Height / DpiScale; float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f); alpha *= alpha; Color selectionColor = Color.White * alpha; @@ -305,7 +305,7 @@ namespace FlaxEngine.GUI ref TextBlock textBlock = ref textBlocks[i]; // Pick font - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (!font) continue; @@ -332,7 +332,7 @@ namespace FlaxEngine.GUI ref TextBlock textBlock = ref textBlocks[i]; // Pick font - var font = textBlock.Style.Font.GetMultiFont(); + var font = textBlock.Style.Font.GetFont(); if (!font) continue; @@ -340,7 +340,7 @@ namespace FlaxEngine.GUI if (textBlock.Style.UnderlineBrush != null) { var underLineHeight = 2.0f; - var height = font.MaxHeight / DpiScale; + var height = font.Height / DpiScale; var underlineRect = new Rectangle(textBlock.Bounds.Location.X, textBlock.Bounds.Location.Y + height - underLineHeight * 0.5f, textBlock.Bounds.Width, underLineHeight); textBlock.Style.UnderlineBrush.Draw(underlineRect, textBlock.Style.Color); } diff --git a/Source/Engine/UI/GUI/TextBlockStyle.cs b/Source/Engine/UI/GUI/TextBlockStyle.cs index 08f74e7c8..c4c87715f 100644 --- a/Source/Engine/UI/GUI/TextBlockStyle.cs +++ b/Source/Engine/UI/GUI/TextBlockStyle.cs @@ -64,7 +64,7 @@ namespace FlaxEngine.GUI /// The text font. /// [EditorOrder(0)] - public MultiFontReference Font; + public FontReference Font; /// /// The custom material for the text rendering (must be GUI domain).