Fix C# editor
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace FlaxEngine
|
||||
{
|
||||
/// <summary>
|
||||
@@ -11,41 +13,10 @@ namespace FlaxEngine
|
||||
get; set;
|
||||
} = null;
|
||||
|
||||
public static void DrawText(Font font, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void DrawText(Font font, string text, Color color, ref TextLayoutOptions layout, MaterialBase customMaterial = null, bool useFallback = true)
|
||||
{
|
||||
var layout = new TextLayoutOptions
|
||||
{
|
||||
Bounds = layoutRect,
|
||||
HorizontalAlignment = horizontalAlignment,
|
||||
VerticalAlignment = verticalAlignment,
|
||||
TextWrapping = textWrapping,
|
||||
Scale = scale,
|
||||
BaseLinesGapScale = baseLinesGapScale,
|
||||
};
|
||||
|
||||
if (Fallbacks != null)
|
||||
{
|
||||
Render2D.DrawText(font, Fallbacks, text, color, ref layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
Render2D.DrawText(font, text, color, ref layout);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawText(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f)
|
||||
{
|
||||
var layout = new TextLayoutOptions
|
||||
{
|
||||
Bounds = layoutRect,
|
||||
HorizontalAlignment = horizontalAlignment,
|
||||
VerticalAlignment = verticalAlignment,
|
||||
TextWrapping = textWrapping,
|
||||
Scale = scale,
|
||||
BaseLinesGapScale = baseLinesGapScale,
|
||||
};
|
||||
|
||||
if (Fallbacks != null)
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
Render2D.DrawText(font, Fallbacks, text, color, ref layout, customMaterial);
|
||||
}
|
||||
@@ -55,9 +26,56 @@ namespace FlaxEngine
|
||||
}
|
||||
}
|
||||
|
||||
public static Float2 MeasureText(Font font, string text)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void DrawText(Font font, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null)
|
||||
var layout = new TextLayoutOptions
|
||||
{
|
||||
Bounds = layoutRect,
|
||||
HorizontalAlignment = horizontalAlignment,
|
||||
VerticalAlignment = verticalAlignment,
|
||||
TextWrapping = textWrapping,
|
||||
Scale = scale,
|
||||
BaseLinesGapScale = baseLinesGapScale,
|
||||
};
|
||||
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
Render2D.DrawText(font, Fallbacks, text, color, ref layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
Render2D.DrawText(font, text, color, ref layout);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void DrawText(Font font, MaterialBase customMaterial, string text, Rectangle layoutRect, Color color, TextAlignment horizontalAlignment = TextAlignment.Near, TextAlignment verticalAlignment = TextAlignment.Near, TextWrapping textWrapping = TextWrapping.NoWrap, float baseLinesGapScale = 1.0f, float scale = 1.0f, bool useFallback = true)
|
||||
{
|
||||
var layout = new TextLayoutOptions
|
||||
{
|
||||
Bounds = layoutRect,
|
||||
HorizontalAlignment = horizontalAlignment,
|
||||
VerticalAlignment = verticalAlignment,
|
||||
TextWrapping = textWrapping,
|
||||
Scale = scale,
|
||||
BaseLinesGapScale = baseLinesGapScale,
|
||||
};
|
||||
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
Render2D.DrawText(font, Fallbacks, text, color, ref layout, customMaterial);
|
||||
}
|
||||
else
|
||||
{
|
||||
Render2D.DrawText(font, text, color, ref layout, customMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Float2 MeasureText(Font font, string text, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.MeasureText(Fallbacks, text);
|
||||
}
|
||||
@@ -67,9 +85,10 @@ namespace FlaxEngine
|
||||
}
|
||||
}
|
||||
|
||||
public static Float2 MeasureText(Font font, string text, ref TextRange textRange)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Float2 MeasureText(Font font, string text, ref TextRange textRange, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null)
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.MeasureText(Fallbacks, text, ref textRange);
|
||||
}
|
||||
@@ -79,9 +98,10 @@ namespace FlaxEngine
|
||||
}
|
||||
}
|
||||
|
||||
public static Float2 MeasureText(Font font, string text, ref TextLayoutOptions layout)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Float2 MeasureText(Font font, string text, ref TextLayoutOptions layout, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null)
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.MeasureText(Fallbacks, text, ref layout);
|
||||
}
|
||||
@@ -91,9 +111,10 @@ namespace FlaxEngine
|
||||
}
|
||||
}
|
||||
|
||||
public static Float2 MeasureText(Font font, string text, ref TextRange textRange, ref TextLayoutOptions layout)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Float2 MeasureText(Font font, string text, ref TextRange textRange, ref TextLayoutOptions layout, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null)
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.MeasureText(Fallbacks, text, ref textRange, ref layout);
|
||||
}
|
||||
@@ -103,24 +124,108 @@ namespace FlaxEngine
|
||||
}
|
||||
}
|
||||
|
||||
public static Float2 GetCharPosition(Font font, string text, int index)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int HitTestText(Font font, string text, Float2 location, bool useFallback = true)
|
||||
{
|
||||
return font.GetCharPosition(Style.Current.Fallbacks, text, index);
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.HitTestText(Fallbacks, text, location);
|
||||
}
|
||||
else
|
||||
{
|
||||
return font.HitTestText(text, location);
|
||||
}
|
||||
}
|
||||
|
||||
public static Float2 GetCharPosition(Font font, string text, ref TextRange textRange, int index)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int HitTestText(Font font, string text, ref TextRange textRange, Float2 location, bool useFallback = true)
|
||||
{
|
||||
return font.GetCharPosition(Style.Current.Fallbacks, text, ref textRange, index);
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.HitTestText(Fallbacks, text, ref textRange, location);
|
||||
}
|
||||
else
|
||||
{
|
||||
return font.HitTestText(text, ref textRange, location);
|
||||
}
|
||||
}
|
||||
|
||||
public static Float2 GetCharPosition(Font font, string text, int index, ref TextLayoutOptions layout)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int HitTestText(Font font, string text, Float2 location, ref TextLayoutOptions layout, bool useFallback = true)
|
||||
{
|
||||
return font.GetCharPosition(Style.Current.Fallbacks, text, index, ref layout);
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.HitTestText(Fallbacks, text, location, ref layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
return font.HitTestText(text, location, ref layout);
|
||||
}
|
||||
}
|
||||
|
||||
public static Float2 GetCharPosition(Font font, string text, ref TextRange textRange, int index, ref TextLayoutOptions layout)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int HitTestText(Font font, string text, ref TextRange textRange, Float2 location, ref TextLayoutOptions layout, bool useFallback = true)
|
||||
{
|
||||
return font.GetCharPosition(Style.Current.Fallbacks, text, ref textRange, index, ref layout);
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.HitTestText(Fallbacks, text, ref textRange, location, ref layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
return font.HitTestText(text, ref textRange, location, ref layout);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Float2 GetCharPosition(Font font, string text, int index, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.GetCharPosition(Fallbacks, text, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
return font.GetCharPosition(text, index);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Float2 GetCharPosition(Font font, string text, ref TextRange textRange, int index, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.GetCharPosition(Fallbacks, text, ref textRange, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
return font.GetCharPosition(text, ref textRange, index);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Float2 GetCharPosition(Font font, string text, int index, ref TextLayoutOptions layout, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.GetCharPosition(Fallbacks, text, index, ref layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
return font.GetCharPosition(text, index, ref layout);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Float2 GetCharPosition(Font font, string text, ref TextRange textRange, int index, ref TextLayoutOptions layout, bool useFallback = true)
|
||||
{
|
||||
if (Fallbacks != null && useFallback)
|
||||
{
|
||||
return font.GetCharPosition(Fallbacks, text, ref textRange, index, ref layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
return font.GetCharPosition(text, ref textRange, index, ref layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
@@ -262,7 +261,7 @@ namespace FlaxEngine.GUI
|
||||
Render2D.DrawRectangle(clientRect, borderColor, BorderThickness);
|
||||
|
||||
// Draw text
|
||||
Render2D.DrawText(_font?.GetFont(), TextMaterial, _text, clientRect, textColor, TextAlignment.Center, TextAlignment.Center);
|
||||
FallbackTextUtils.DrawText(_font?.GetFont(), TextMaterial, _text, clientRect, textColor, TextAlignment.Center, TextAlignment.Center);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
@@ -674,7 +673,7 @@ namespace FlaxEngine.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(), FontMaterial, _items[_selectedIndex], textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center);
|
||||
FallbackTextUtils.DrawText(Font.GetFont(), FontMaterial, _items[_selectedIndex], textRect, enabled ? textColor : textColor * 0.5f, TextAlignment.Near, TextAlignment.Center);
|
||||
Render2D.PopClip();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEditor.Options;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
@@ -235,7 +233,7 @@ namespace FlaxEngine.GUI
|
||||
}
|
||||
}
|
||||
|
||||
Render2D.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale);
|
||||
FallbackTextUtils.DrawText(_font.GetFont(), Material, _text, rect, color, hAlignment, wAlignment, Wrapping, BaseLinesGapScale, scale);
|
||||
|
||||
if (ClipText)
|
||||
Render2D.PopClip();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEngine.Utilities;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace FlaxEngine.GUI
|
||||
if (!font)
|
||||
break;
|
||||
height = font.Height / DpiScale;
|
||||
return textBlock.Bounds.Location + font.GetCharPosition(_text, ref textBlock.Range, index - textBlock.Range.StartIndex);
|
||||
return textBlock.Bounds.Location + FallbackTextUtils.GetCharPosition(font, _text, ref textBlock.Range, index - textBlock.Range.StartIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace FlaxEngine.GUI
|
||||
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;
|
||||
return FallbackTextUtils.HitTestText(font, _text, ref textBlock.Range, location - textBlock.Bounds.Location) + textBlock.Range.StartIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,8 +288,8 @@ namespace FlaxEngine.GUI
|
||||
// Selection
|
||||
if (hasSelection && textBlock.Style.BackgroundSelectedBrush != null && textBlock.Range.Intersect(ref selection))
|
||||
{
|
||||
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);
|
||||
var leftEdge = selection.StartIndex <= textBlock.Range.StartIndex ? textBlock.Bounds.UpperLeft : FallbackTextUtils.GetCharPosition(font, _text, selection.StartIndex);
|
||||
var rightEdge = selection.EndIndex >= textBlock.Range.EndIndex ? textBlock.Bounds.UpperRight : FallbackTextUtils.GetCharPosition(font, _text, selection.EndIndex);
|
||||
float height = font.Height / DpiScale;
|
||||
float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f);
|
||||
alpha *= alpha;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
@@ -120,7 +118,7 @@ namespace FlaxEngine.GUI
|
||||
}
|
||||
|
||||
height = font.Height / DpiScale;
|
||||
return font.GetCharPosition(_text, index, ref _layout);
|
||||
return FallbackTextUtils.GetCharPosition(font, _text, index, ref _layout);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -132,7 +130,7 @@ namespace FlaxEngine.GUI
|
||||
return 0;
|
||||
}
|
||||
|
||||
return font.HitTestText(_text, location, ref _layout);
|
||||
return FallbackTextUtils.HitTestText(font, _text, location, ref _layout);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -171,8 +169,8 @@ namespace FlaxEngine.GUI
|
||||
// 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 = FallbackTextUtils.GetCharPosition(font, _text, SelectionLeft, ref _layout);
|
||||
var rightEdge = FallbackTextUtils.GetCharPosition(font, _text, SelectionRight, ref _layout);
|
||||
float fontHeight = font.Height / DpiScale;
|
||||
|
||||
// Draw selection background
|
||||
@@ -213,25 +211,11 @@ namespace FlaxEngine.GUI
|
||||
var color = TextColor;
|
||||
if (!enabled)
|
||||
color *= 0.6f;
|
||||
if (Render2D.Fallbacks != null)
|
||||
{
|
||||
Render2D.DrawText(font, Render2D.Fallbacks, _text, color, ref _layout, TextMaterial);
|
||||
}
|
||||
else
|
||||
{
|
||||
Render2D.DrawText(font, _text, color, ref _layout, TextMaterial);
|
||||
}
|
||||
FallbackTextUtils.DrawText(font, _text, color, ref _layout, TextMaterial);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(_watermarkText) && !IsFocused)
|
||||
{
|
||||
if (Render2D.Fallbacks != null)
|
||||
{
|
||||
Render2D.DrawText(font, Render2D.Fallbacks, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
|
||||
}
|
||||
else
|
||||
{
|
||||
Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
|
||||
}
|
||||
FallbackTextUtils.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial);
|
||||
}
|
||||
|
||||
// Caret
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
@@ -375,7 +374,7 @@ namespace FlaxEngine.GUI
|
||||
textColor *= 0.6f;
|
||||
}
|
||||
|
||||
Render2D.DrawText(HeaderTextFont.GetFont(), HeaderTextMaterial, HeaderText, textRect, textColor, TextAlignment.Near, TextAlignment.Center);
|
||||
FallbackTextUtils.DrawText(HeaderTextFont.GetFont(), HeaderTextMaterial, HeaderText, textRect, textColor, TextAlignment.Near, TextAlignment.Center);
|
||||
|
||||
if (!_isClosed && EnableContainmentLines)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
@@ -235,7 +234,7 @@ namespace FlaxEngine.GUI
|
||||
Render2D.FillRectangle(new Rectangle(1.1f, 1.1f, Width - 2, Height - 2), style.Background);
|
||||
|
||||
// Tooltip text
|
||||
Render2D.DrawText(
|
||||
FallbackTextUtils.DrawText(
|
||||
style.FontMedium,
|
||||
_currentText,
|
||||
GetClientArea(),
|
||||
|
||||
Reference in New Issue
Block a user