Refactor engine to support double-precision vectors

This commit is contained in:
2022-06-13 00:40:32 +02:00
parent f82e370392
commit a881c90b2e
744 changed files with 19062 additions and 12467 deletions
+71 -71
View File
@@ -13,10 +13,10 @@ namespace FlaxEngine.GUI
private struct AnchorPresetData
{
public AnchorPresets Preset;
public Vector2 Min;
public Vector2 Max;
public Float2 Min;
public Float2 Max;
public AnchorPresetData(AnchorPresets preset, Vector2 min, Vector2 max)
public AnchorPresetData(AnchorPresets preset, Float2 min, Float2 max)
{
Preset = preset;
Min = min;
@@ -26,27 +26,27 @@ namespace FlaxEngine.GUI
private static readonly AnchorPresetData[] AnchorPresetsData =
{
new AnchorPresetData(AnchorPresets.TopLeft, new Vector2(0, 0), new Vector2(0, 0)),
new AnchorPresetData(AnchorPresets.TopCenter, new Vector2(0.5f, 0), new Vector2(0.5f, 0)),
new AnchorPresetData(AnchorPresets.TopRight, new Vector2(1, 0), new Vector2(1, 0)),
new AnchorPresetData(AnchorPresets.TopLeft, new Float2(0, 0), new Float2(0, 0)),
new AnchorPresetData(AnchorPresets.TopCenter, new Float2(0.5f, 0), new Float2(0.5f, 0)),
new AnchorPresetData(AnchorPresets.TopRight, new Float2(1, 0), new Float2(1, 0)),
new AnchorPresetData(AnchorPresets.MiddleLeft, new Vector2(0, 0.5f), new Vector2(0, 0.5f)),
new AnchorPresetData(AnchorPresets.MiddleCenter, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f)),
new AnchorPresetData(AnchorPresets.MiddleRight, new Vector2(1, 0.5f), new Vector2(1, 0.5f)),
new AnchorPresetData(AnchorPresets.MiddleLeft, new Float2(0, 0.5f), new Float2(0, 0.5f)),
new AnchorPresetData(AnchorPresets.MiddleCenter, new Float2(0.5f, 0.5f), new Float2(0.5f, 0.5f)),
new AnchorPresetData(AnchorPresets.MiddleRight, new Float2(1, 0.5f), new Float2(1, 0.5f)),
new AnchorPresetData(AnchorPresets.BottomLeft, new Vector2(0, 1), new Vector2(0, 1)),
new AnchorPresetData(AnchorPresets.BottomCenter, new Vector2(0.5f, 1), new Vector2(0.5f, 1)),
new AnchorPresetData(AnchorPresets.BottomRight, new Vector2(1, 1), new Vector2(1, 1)),
new AnchorPresetData(AnchorPresets.BottomLeft, new Float2(0, 1), new Float2(0, 1)),
new AnchorPresetData(AnchorPresets.BottomCenter, new Float2(0.5f, 1), new Float2(0.5f, 1)),
new AnchorPresetData(AnchorPresets.BottomRight, new Float2(1, 1), new Float2(1, 1)),
new AnchorPresetData(AnchorPresets.HorizontalStretchTop, new Vector2(0, 0), new Vector2(1, 0)),
new AnchorPresetData(AnchorPresets.HorizontalStretchMiddle, new Vector2(0, 0.5f), new Vector2(1, 0.5f)),
new AnchorPresetData(AnchorPresets.HorizontalStretchBottom, new Vector2(0, 1), new Vector2(1, 1)),
new AnchorPresetData(AnchorPresets.HorizontalStretchTop, new Float2(0, 0), new Float2(1, 0)),
new AnchorPresetData(AnchorPresets.HorizontalStretchMiddle, new Float2(0, 0.5f), new Float2(1, 0.5f)),
new AnchorPresetData(AnchorPresets.HorizontalStretchBottom, new Float2(0, 1), new Float2(1, 1)),
new AnchorPresetData(AnchorPresets.VerticalStretchLeft, new Vector2(0, 0), new Vector2(0, 1)),
new AnchorPresetData(AnchorPresets.VerticalStretchCenter, new Vector2(0.5f, 0), new Vector2(0.5f, 1)),
new AnchorPresetData(AnchorPresets.VerticalStretchRight, new Vector2(1, 0), new Vector2(1, 1)),
new AnchorPresetData(AnchorPresets.VerticalStretchLeft, new Float2(0, 0), new Float2(0, 1)),
new AnchorPresetData(AnchorPresets.VerticalStretchCenter, new Float2(0.5f, 0), new Float2(0.5f, 1)),
new AnchorPresetData(AnchorPresets.VerticalStretchRight, new Float2(1, 0), new Float2(1, 1)),
new AnchorPresetData(AnchorPresets.StretchAll, new Vector2(0, 0), new Vector2(1, 1)),
new AnchorPresetData(AnchorPresets.StretchAll, new Float2(0, 0), new Float2(1, 1)),
};
private ContainerControl _parent;
@@ -68,11 +68,11 @@ namespace FlaxEngine.GUI
private Rectangle _bounds;
private Margin _offsets = new Margin(0.0f, 100.0f, 0.0f, 30.0f);
private Vector2 _anchorMin;
private Vector2 _anchorMax;
private Vector2 _scale = new Vector2(1.0f);
private Vector2 _pivot = new Vector2(0.5f);
private Vector2 _shear;
private Float2 _anchorMin;
private Float2 _anchorMax;
private Float2 _scale = new Float2(1.0f);
private Float2 _pivot = new Float2(0.5f);
private Float2 _shear;
private float _rotation;
internal Matrix3x3 _cachedTransform;
internal Matrix3x3 _cachedTransformInv;
@@ -122,7 +122,7 @@ namespace FlaxEngine.GUI
Defocus();
Vector2 oldParentSize;
Float2 oldParentSize;
if (_parent != null)
{
oldParentSize = _parent.Size;
@@ -130,7 +130,7 @@ namespace FlaxEngine.GUI
}
else
{
oldParentSize = Vector2.Zero;
oldParentSize = Float2.Zero;
}
_parent = value;
@@ -184,8 +184,8 @@ namespace FlaxEngine.GUI
var result = AnchorPresets.Custom;
for (int i = 0; i < AnchorPresetsData.Length; i++)
{
if (Vector2.NearEqual(ref _anchorMin, ref AnchorPresetsData[i].Min) &&
Vector2.NearEqual(ref _anchorMax, ref AnchorPresetsData[i].Max))
if (Float2.NearEqual(ref _anchorMin, ref AnchorPresetsData[i].Min) &&
Float2.NearEqual(ref _anchorMax, ref AnchorPresetsData[i].Max))
{
result = AnchorPresetsData[i].Preset;
break;
@@ -318,14 +318,14 @@ namespace FlaxEngine.GUI
/// <summary>
/// Gets screen position of the control (upper left corner).
/// </summary>
public Vector2 ScreenPos
public Float2 ScreenPos
{
get
{
var parentWin = Root;
if (parentWin == null)
throw new InvalidOperationException("Missing parent window.");
var clientPos = PointToWindow(Vector2.Zero);
var clientPos = PointToWindow(Float2.Zero);
return parentWin.PointToScreen(clientPos);
}
}
@@ -379,7 +379,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">Upper left corner location.</param>
/// <param name="size">Bounds size.</param>
public Control(Vector2 location, Vector2 size)
public Control(Float2 location, Float2 size)
: this(new Rectangle(location, size))
{
}
@@ -440,7 +440,7 @@ namespace FlaxEngine.GUI
// Paint Background
if (_backgroundColor.A > 0.0f)
{
Render2D.FillRectangle(new Rectangle(Vector2.Zero, Size), _backgroundColor);
Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), _backgroundColor);
}
}
@@ -632,16 +632,16 @@ namespace FlaxEngine.GUI
/// <param name="direction">The navigation direction.</param>
/// <returns>The navigation origin for the automatic navigation.</returns>
[NoAnimate]
public virtual Vector2 GetNavOrigin(NavDirection direction)
public virtual Float2 GetNavOrigin(NavDirection direction)
{
var size = Size;
switch (direction)
{
case NavDirection.Up: return new Vector2(size.X * 0.5f, 0);
case NavDirection.Down: return new Vector2(size.X * 0.5f, size.Y);
case NavDirection.Left: return new Vector2(0, size.Y * 0.5f);
case NavDirection.Right: return new Vector2(size.X, size.Y * 0.5f);
case NavDirection.Next: return Vector2.Zero;
case NavDirection.Up: return new Float2(size.X * 0.5f, 0);
case NavDirection.Down: return new Float2(size.X * 0.5f, size.Y);
case NavDirection.Left: return new Float2(0, size.Y * 0.5f);
case NavDirection.Right: return new Float2(size.X, size.Y * 0.5f);
case NavDirection.Next: return Float2.Zero;
default: return size * 0.5f;
}
}
@@ -654,7 +654,7 @@ namespace FlaxEngine.GUI
/// <param name="caller">The control that calls the event.</param>
/// <param name="visited">The list with visited controls. Used to skip recursive navigation calls when doing traversal across the UI hierarchy.</param>
/// <returns>The target navigation control or null if didn't performed any navigation.</returns>
public virtual Control OnNavigate(NavDirection direction, Vector2 location, Control caller, List<Control> visited)
public virtual Control OnNavigate(NavDirection direction, Float2 location, Control caller, List<Control> visited)
{
if (caller == _parent && AutoFocus && Visible)
return this;
@@ -706,7 +706,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">Mouse location in Control Space</param>
[NoAnimate]
public virtual void OnMouseEnter(Vector2 location)
public virtual void OnMouseEnter(Float2 location)
{
// Set flag
_isMouseOver = true;
@@ -724,7 +724,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">Mouse location in Control Space</param>
[NoAnimate]
public virtual void OnMouseMove(Vector2 location)
public virtual void OnMouseMove(Float2 location)
{
// Update tooltip
if (ShowTooltip && OnTestTooltipOverControl(ref location))
@@ -766,7 +766,7 @@ namespace FlaxEngine.GUI
/// <param name="delta">Mouse wheel move delta. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. Normalized to [-1;1] range.</param>
/// <returns>True if event has been handled</returns>
[NoAnimate]
public virtual bool OnMouseWheel(Vector2 location, float delta)
public virtual bool OnMouseWheel(Float2 location, float delta)
{
return false;
}
@@ -778,7 +778,7 @@ namespace FlaxEngine.GUI
/// <param name="button">Mouse buttons state (flags)</param>
/// <returns>True if event has been handled, otherwise false</returns>
[NoAnimate]
public virtual bool OnMouseDown(Vector2 location, MouseButton button)
public virtual bool OnMouseDown(Float2 location, MouseButton button)
{
return false;
}
@@ -790,7 +790,7 @@ namespace FlaxEngine.GUI
/// <param name="button">Mouse buttons state (flags)</param>
/// <returns>True if event has been handled, otherwise false</returns>
[NoAnimate]
public virtual bool OnMouseUp(Vector2 location, MouseButton button)
public virtual bool OnMouseUp(Float2 location, MouseButton button)
{
return false;
}
@@ -802,7 +802,7 @@ namespace FlaxEngine.GUI
/// <param name="button">Mouse buttons state (flags)</param>
/// <returns>True if event has been handled, otherwise false</returns>
[NoAnimate]
public virtual bool OnMouseDoubleClick(Vector2 location, MouseButton button)
public virtual bool OnMouseDoubleClick(Float2 location, MouseButton button)
{
return false;
}
@@ -867,7 +867,7 @@ namespace FlaxEngine.GUI
/// <param name="location">Touch location in Control Space</param>
/// <param name="pointerId">The touch pointer identifier. Stable for the whole touch gesture/interaction.</param>
[NoAnimate]
public virtual void OnTouchEnter(Vector2 location, int pointerId)
public virtual void OnTouchEnter(Float2 location, int pointerId)
{
if (_touchOvers == null)
_touchOvers = new List<int>();
@@ -881,7 +881,7 @@ namespace FlaxEngine.GUI
/// <param name="pointerId">The touch pointer identifier. Stable for the whole touch gesture/interaction.</param>
/// <returns>True if event has been handled, otherwise false.</returns>
[NoAnimate]
public virtual bool OnTouchDown(Vector2 location, int pointerId)
public virtual bool OnTouchDown(Float2 location, int pointerId)
{
return false;
}
@@ -892,7 +892,7 @@ namespace FlaxEngine.GUI
/// <param name="location">Touch location in Control Space.</param>
/// <param name="pointerId">The touch pointer identifier. Stable for the whole touch gesture/interaction.</param>
[NoAnimate]
public virtual void OnTouchMove(Vector2 location, int pointerId)
public virtual void OnTouchMove(Float2 location, int pointerId)
{
}
@@ -903,7 +903,7 @@ namespace FlaxEngine.GUI
/// <param name="pointerId">The touch pointer identifier. Stable for the whole touch gesture/interaction.</param>
/// <returns>True if event has been handled, otherwise false.</returns>
[NoAnimate]
public virtual bool OnTouchUp(Vector2 location, int pointerId)
public virtual bool OnTouchUp(Float2 location, int pointerId)
{
return false;
}
@@ -944,7 +944,7 @@ namespace FlaxEngine.GUI
/// <param name="data">The data. See <see cref="DragDataText"/> and <see cref="DragDataFiles"/>.</param>
/// <returns>The drag event result effect.</returns>
[NoAnimate]
public virtual DragDropEffect OnDragEnter(ref Vector2 location, DragData data)
public virtual DragDropEffect OnDragEnter(ref Float2 location, DragData data)
{
// Set flag
_isDragOver = true;
@@ -958,7 +958,7 @@ namespace FlaxEngine.GUI
/// <param name="data">The data. See <see cref="DragDataText"/> and <see cref="DragDataFiles"/>.</param>
/// <returns>The drag event result effect.</returns>
[NoAnimate]
public virtual DragDropEffect OnDragMove(ref Vector2 location, DragData data)
public virtual DragDropEffect OnDragMove(ref Float2 location, DragData data)
{
return DragDropEffect.None;
}
@@ -970,7 +970,7 @@ namespace FlaxEngine.GUI
/// <param name="data">The data. See <see cref="DragDataText"/> and <see cref="DragDataFiles"/>.</param>
/// <returns>The drag event result effect.</returns>
[NoAnimate]
public virtual DragDropEffect OnDragDrop(ref Vector2 location, DragData data)
public virtual DragDropEffect OnDragDrop(ref Float2 location, DragData data)
{
// Clear flag
_isDragOver = false;
@@ -1063,11 +1063,11 @@ namespace FlaxEngine.GUI
/// <param name="location">The popup start location (in this control local space).</param>
/// <param name="area">The allowed area of mouse movement to show tooltip (in this control local space).</param>
/// <returns>True if can show tooltip, otherwise false to skip.</returns>
public virtual bool OnShowTooltip(out string text, out Vector2 location, out Rectangle area)
public virtual bool OnShowTooltip(out string text, out Float2 location, out Rectangle area)
{
text = _tooltipText;
location = Size * new Vector2(0.5f, 1.0f);
area = new Rectangle(Vector2.Zero, Size);
location = Size * new Float2(0.5f, 1.0f);
area = new Rectangle(Float2.Zero, Size);
return ShowTooltip;
}
@@ -1084,7 +1084,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">The location.</param>
/// <returns>True if tooltip can be still visible, otherwise false.</returns>
public virtual bool OnTestTooltipOverControl(ref Vector2 location)
public virtual bool OnTestTooltipOverControl(ref Float2 location)
{
return ContainsPoint(ref location) && ShowTooltip;
}
@@ -1099,7 +1099,7 @@ namespace FlaxEngine.GUI
/// <param name="locationParent">The location in Parent Space.</param>
/// <param name="location">The location of intersection in Control Space.</param>
/// <returns>True if given point in Parent Space intersects with this control content, otherwise false.</returns>
public virtual bool IntersectsContent(ref Vector2 locationParent, out Vector2 location)
public virtual bool IntersectsContent(ref Float2 locationParent, out Float2 location)
{
location = PointFromParent(ref locationParent);
return ContainsPoint(ref location);
@@ -1110,7 +1110,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">Point location in Control Space to check</param>
/// <returns>True if point is inside control's area, otherwise false.</returns>
public virtual bool ContainsPoint(ref Vector2 location)
public virtual bool ContainsPoint(ref Float2 location)
{
return location.X >= 0 &&
location.Y >= 0 &&
@@ -1124,7 +1124,7 @@ namespace FlaxEngine.GUI
/// <param name="parent">This control parent of any other parent.</param>
/// <param name="location">Input location of the point to convert</param>
/// <returns>Converted point location in parent control coordinates</returns>
public Vector2 PointToParent(ContainerControl parent, Vector2 location)
public Float2 PointToParent(ContainerControl parent, Float2 location)
{
if (parent == null)
throw new ArgumentNullException();
@@ -1146,7 +1146,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">The input location of the point to convert.</param>
/// <returns>The converted point location in parent control coordinates.</returns>
public Vector2 PointToParent(Vector2 location)
public Float2 PointToParent(Float2 location)
{
return PointToParent(ref location);
}
@@ -1156,7 +1156,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">The input location of the point to convert.</param>
/// <returns>The converted point location in parent control coordinates.</returns>
public virtual Vector2 PointToParent(ref Vector2 location)
public virtual Float2 PointToParent(ref Float2 location)
{
Matrix3x3.Transform2D(ref location, ref _cachedTransform, out var result);
return result;
@@ -1167,7 +1167,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="locationParent">The input location of the point to convert.</param>
/// <returns>The converted point location in control's space.</returns>
public Vector2 PointFromParent(Vector2 locationParent)
public Float2 PointFromParent(Float2 locationParent)
{
return PointFromParent(ref locationParent);
}
@@ -1177,7 +1177,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="locationParent">The input location of the point to convert.</param>
/// <returns>The converted point location in control's space.</returns>
public virtual Vector2 PointFromParent(ref Vector2 locationParent)
public virtual Float2 PointFromParent(ref Float2 locationParent)
{
Matrix3x3.Transform2D(ref locationParent, ref _cachedTransformInv, out var result);
return result;
@@ -1189,7 +1189,7 @@ namespace FlaxEngine.GUI
/// <param name="parent">This control parent of any other parent.</param>
/// <param name="location">Input location of the point to convert</param>
/// <returns>The converted point location in control's space.</returns>
public Vector2 PointFromParent(ContainerControl parent, Vector2 location)
public Float2 PointFromParent(ContainerControl parent, Float2 location)
{
if (parent == null)
throw new ArgumentNullException();
@@ -1213,7 +1213,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">Input location of the point to convert</param>
/// <returns>Converted point location in window coordinates</returns>
public Vector2 PointToWindow(Vector2 location)
public Float2 PointToWindow(Float2 location)
{
location = PointToParent(ref location);
if (_parent != null)
@@ -1228,7 +1228,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">Input location of the point to convert</param>
/// <returns>Converted point location in control's space</returns>
public Vector2 PointFromWindow(Vector2 location)
public Float2 PointFromWindow(Float2 location)
{
if (_parent != null)
{
@@ -1242,7 +1242,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">Input location of the point to convert</param>
/// <returns>Converted point location in screen coordinates</returns>
public virtual Vector2 PointToScreen(Vector2 location)
public virtual Float2 PointToScreen(Float2 location)
{
location = PointToParent(ref location);
if (_parent != null)
@@ -1257,7 +1257,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="location">Input location of the point to convert</param>
/// <returns>Converted point location in local control's space</returns>
public virtual Vector2 PointFromScreen(Vector2 location)
public virtual Float2 PointFromScreen(Float2 location)
{
if (_parent != null)
{
@@ -1291,7 +1291,7 @@ namespace FlaxEngine.GUI
/// Sets the scale and updates the transform.
/// </summary>
/// <param name="scale">The scale.</param>
protected virtual void SetScaleInternal(ref Vector2 scale)
protected virtual void SetScaleInternal(ref Float2 scale)
{
_scale = scale;
UpdateTransform();
@@ -1302,7 +1302,7 @@ namespace FlaxEngine.GUI
/// Sets the pivot and updates the transform.
/// </summary>
/// <param name="pivot">The pivot.</param>
protected virtual void SetPivotInternal(ref Vector2 pivot)
protected virtual void SetPivotInternal(ref Float2 pivot)
{
_pivot = pivot;
UpdateTransform();
@@ -1313,7 +1313,7 @@ namespace FlaxEngine.GUI
/// Sets the shear and updates the transform.
/// </summary>
/// <param name="shear">The shear.</param>
protected virtual void SetShearInternal(ref Vector2 shear)
protected virtual void SetShearInternal(ref Float2 shear)
{
_shear = shear;
UpdateTransform();