Merge remote-tracking branch 'origin/master' into 1.12
# Conflicts: # Content/Shaders/GI/DDGI.flax # Content/Shaders/GUI.flax # Flax.flaxproj # Source/Editor/Windows/AboutDialog.cs # Source/Engine/Serialization/Stream.cpp # Source/Shaders/GUICommon.hlsl
This commit is contained in:
@@ -25,12 +25,12 @@ namespace FlaxEngine.GUI
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether canvas is 2D (screen-space).
|
||||
/// </summary>
|
||||
public bool Is2D => _canvas.RenderMode == CanvasRenderMode.ScreenSpace;
|
||||
public bool Is2D => _canvas.Is2D;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether canvas is 3D (world-space or camera-space).
|
||||
/// </summary>
|
||||
public bool Is3D => _canvas.RenderMode != CanvasRenderMode.ScreenSpace;
|
||||
public bool Is3D => _canvas.Is3D;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CanvasRootControl"/> class.
|
||||
|
||||
@@ -298,6 +298,7 @@ namespace FlaxEngine.GUI
|
||||
{
|
||||
case CanvasRenderMode.WorldSpace:
|
||||
case CanvasRenderMode.WorldSpaceFaceCamera:
|
||||
case CanvasRenderMode.GPUTexture:
|
||||
scale = 1.0f;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -595,7 +595,7 @@ namespace FlaxEngine.GUI
|
||||
Size = new Float2(size.X - margin, size.Y),
|
||||
Font = Font,
|
||||
TextColor = TextColor * 0.9f,
|
||||
TextColorHighlighted = TextColorHighlighted,
|
||||
TextColorHighlighted = TextColorHighlighted.Brightness < 0.05f ? Color.Lerp(TextColorHighlighted, Color.White, 0.3f) : TextColorHighlighted,
|
||||
HorizontalAlignment = HorizontalAlignment,
|
||||
VerticalAlignment = VerticalAlignment,
|
||||
Text = _items[i],
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#if FLAX_EDITOR
|
||||
using FlaxEditor.Options;
|
||||
#endif
|
||||
@@ -42,6 +44,38 @@ namespace FlaxEngine.GUI
|
||||
'<',
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The allowable characters to use for the text.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum AllowableCharacters
|
||||
{
|
||||
/// <summary>
|
||||
/// Wether to not allow any character in the text.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Whether to use letters in the text.
|
||||
/// </summary>
|
||||
Letters = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// Whether to use numbers in the text.
|
||||
/// </summary>
|
||||
Numbers = 1 << 1,
|
||||
|
||||
/// <summary>
|
||||
/// Whether to use symbols in the text.
|
||||
/// </summary>
|
||||
Symbols = 1 << 2,
|
||||
|
||||
/// <summary>
|
||||
/// Whether to use all characters in the text.
|
||||
/// </summary>
|
||||
All = Letters | Numbers | Symbols,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default height of the text box
|
||||
/// </summary>
|
||||
@@ -86,6 +120,11 @@ namespace FlaxEngine.GUI
|
||||
/// Flag used to indicate whenever text can contain multiple lines.
|
||||
/// </summary>
|
||||
protected bool _isMultiline;
|
||||
|
||||
/// <summary>
|
||||
/// The characters to allow in the text.
|
||||
/// </summary>
|
||||
protected AllowableCharacters _charactersToAllow = AllowableCharacters.All;
|
||||
|
||||
/// <summary>
|
||||
/// Flag used to indicate whenever text is read-only and cannot be modified by the user.
|
||||
@@ -188,6 +227,16 @@ namespace FlaxEngine.GUI
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The character to allow in the text.
|
||||
/// </summary>
|
||||
[EditorOrder(41), Tooltip("The character to allow in the text.")]
|
||||
public AllowableCharacters CharactersToAllow
|
||||
{
|
||||
get => _charactersToAllow;
|
||||
set => _charactersToAllow = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum number of characters the user can type into the text box control.
|
||||
/// </summary>
|
||||
@@ -395,15 +444,42 @@ namespace FlaxEngine.GUI
|
||||
value = value.GetLines()[0];
|
||||
}
|
||||
|
||||
if (_text != value)
|
||||
if (_text.Equals(value, StringComparison.Ordinal))
|
||||
return;
|
||||
|
||||
if (CharactersToAllow != AllowableCharacters.All)
|
||||
{
|
||||
Deselect();
|
||||
ResetViewOffset();
|
||||
|
||||
_text = value;
|
||||
|
||||
OnTextChanged();
|
||||
if (CharactersToAllow == AllowableCharacters.None)
|
||||
{
|
||||
value = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!CharactersToAllow.HasFlag(AllowableCharacters.Letters))
|
||||
{
|
||||
if (value != null)
|
||||
value = new string(value.Where(c => !char.IsLetter(c)).ToArray());
|
||||
}
|
||||
if (!CharactersToAllow.HasFlag(AllowableCharacters.Numbers))
|
||||
{
|
||||
if (value != null)
|
||||
value = new string(value.Where(c => !char.IsNumber(c)).ToArray());
|
||||
}
|
||||
if (!CharactersToAllow.HasFlag(AllowableCharacters.Symbols))
|
||||
{
|
||||
if (value != null)
|
||||
value = new string(value.Where(c => !char.IsSymbol(c)).ToArray());
|
||||
}
|
||||
value ??= string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
Deselect();
|
||||
ResetViewOffset();
|
||||
|
||||
_text = value;
|
||||
|
||||
OnTextChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -166,8 +166,26 @@ namespace FlaxEngine.GUI
|
||||
[NoSerialize, HideInEditor]
|
||||
public Float2 LocalLocation
|
||||
{
|
||||
get => _bounds.Location - (_parent != null ? _parent._bounds.Size * (_anchorMax + _anchorMin) * 0.5f : Float2.Zero) + _bounds.Size * _pivot;
|
||||
set => Bounds = new Rectangle(value + (_parent != null ? _parent.Bounds.Size * (_anchorMax + _anchorMin) * 0.5f : Float2.Zero) - _bounds.Size * _pivot, _bounds.Size);
|
||||
get
|
||||
{
|
||||
var anchor = Float2.Zero;
|
||||
if (_parent != null)
|
||||
{
|
||||
_parent.GetDesireClientArea(out var parentBounds);
|
||||
anchor = parentBounds.Location + parentBounds.Size * (_anchorMin + _anchorMax) * 0.5f;
|
||||
}
|
||||
return _bounds.Location - anchor + _bounds.Size * _pivot;
|
||||
}
|
||||
set
|
||||
{
|
||||
var anchor = Float2.Zero;
|
||||
if (_parent != null)
|
||||
{
|
||||
_parent.GetDesireClientArea(out var parentBounds);
|
||||
anchor = parentBounds.Location + parentBounds.Size * (_anchorMin + _anchorMax) * 0.5f;
|
||||
}
|
||||
Bounds = new Rectangle(value + anchor - _bounds.Size * _pivot, _bounds.Size);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace FlaxEngine.GUI
|
||||
/// Base class for container controls that can offset controls in a view (eg. scroll panels).
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEngine.GUI.ContainerControl" />
|
||||
[HideInEditor]
|
||||
public class ScrollableControl : ContainerControl
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -33,6 +33,11 @@ namespace FlaxEngine
|
||||
/// The world space rendering mode that places Canvas as any other object in the scene and orients it to face the camera. The size of the Canvas can be set manually using its Transform, and UI elements will render in front of or behind other objects in the scene based on 3D placement. This is useful for UIs that are meant to be a part of the world. This is also known as a 'diegetic interface'.
|
||||
/// </summary>
|
||||
WorldSpaceFaceCamera = 3,
|
||||
|
||||
/// <summary>
|
||||
/// The off-screen rendering mode that draws the contents of the canvas into a GPU texture that can be used in the scene or by other systems. The size of the canvas is automatically set to the size of the texture.
|
||||
/// </summary>
|
||||
GPUTexture = 4,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -105,7 +110,7 @@ namespace FlaxEngine
|
||||
private CanvasRenderMode _renderMode;
|
||||
private readonly CanvasRootControl _guiRoot;
|
||||
private CanvasRenderer _renderer;
|
||||
private bool _isLoading, _isRegisteredForTick;
|
||||
private bool _isLoading, _isRegisteredForTick, _isRegisteredForOnDraw;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the canvas rendering mode.
|
||||
@@ -169,6 +174,8 @@ namespace FlaxEngine
|
||||
|
||||
private bool Editor_IsCameraSpace => _renderMode == CanvasRenderMode.CameraSpace;
|
||||
|
||||
private bool Editor_IsGPUTexture => _renderMode == CanvasRenderMode.GPUTexture;
|
||||
|
||||
private bool Editor_UseRenderCamera => _renderMode == CanvasRenderMode.CameraSpace || _renderMode == CanvasRenderMode.WorldSpaceFaceCamera;
|
||||
#endif
|
||||
|
||||
@@ -206,6 +213,12 @@ namespace FlaxEngine
|
||||
[EditorOrder(60), Limit(0.01f), EditorDisplay("Canvas"), VisibleIf("Editor_IsCameraSpace"), Tooltip("Distance from the RenderCamera to place the plane with GUI. If the screen is resized, changes resolution, or the camera frustum changes, the Canvas will automatically change size to match as well.")]
|
||||
public float Distance { get; set; } = 500;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the output texture for the canvas when render mode is set to <see cref="CanvasRenderMode.GPUTexture"/>. The size of the canvas will be automatically set to the size of the texture. The canvas will render its content into this texture.
|
||||
/// </summary>
|
||||
[EditorOrder(70), NoSerialize, EditorDisplay("Canvas"), VisibleIf("Editor_IsGPUTexture")]
|
||||
public GPUTexture OutputTexture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the canvas GUI root control.
|
||||
/// </summary>
|
||||
@@ -329,6 +342,11 @@ namespace FlaxEngine
|
||||
_isRegisteredForTick = false;
|
||||
Scripting.Update -= OnUpdate;
|
||||
}
|
||||
if (_isRegisteredForOnDraw)
|
||||
{
|
||||
_isRegisteredForOnDraw = false;
|
||||
Scripting.Draw -= OnDraw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -358,7 +376,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether canvas is 3D (world-space or camera-space).
|
||||
/// </summary>
|
||||
public bool Is3D => _renderMode != CanvasRenderMode.ScreenSpace;
|
||||
public bool Is3D => _renderMode != CanvasRenderMode.ScreenSpace && _renderMode != CanvasRenderMode.GPUTexture;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the world matrix used to transform the GUI from the local space to the world space. Handles canvas rendering mode
|
||||
@@ -491,6 +509,11 @@ namespace FlaxEngine
|
||||
{
|
||||
if (_isLoading)
|
||||
return;
|
||||
if (_isRegisteredForOnDraw)
|
||||
{
|
||||
_isRegisteredForOnDraw = false;
|
||||
Scripting.Draw -= OnDraw;
|
||||
}
|
||||
|
||||
switch (_renderMode)
|
||||
{
|
||||
@@ -563,7 +586,32 @@ namespace FlaxEngine
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CanvasRenderMode.GPUTexture:
|
||||
{
|
||||
if (!_isRegisteredForOnDraw)
|
||||
{
|
||||
_isRegisteredForOnDraw = true;
|
||||
Scripting.Draw += OnDraw;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDraw()
|
||||
{
|
||||
var outputTexture = OutputTexture;
|
||||
if (!outputTexture || !outputTexture.IsAllocated)
|
||||
return;
|
||||
var context = GPUDevice.Instance.MainContext;
|
||||
_guiRoot.Size = outputTexture.Size;
|
||||
|
||||
Profiler.BeginEvent("UI Canvas");
|
||||
Profiler.BeginEventGPU("UI Canvas");
|
||||
context.Clear(outputTexture.View(), Color.Transparent);
|
||||
Render2D.CallDrawing(GUI, context, outputTexture);
|
||||
Profiler.EndEvent();
|
||||
Profiler.EndEventGPU();
|
||||
}
|
||||
|
||||
private void OnUpdate()
|
||||
|
||||
Reference in New Issue
Block a user