Add Double2, Double3, Double4 to C# scripting API
This commit is contained in:
85
Source/Editor/CustomEditors/Editors/Double2Editor.cs
Normal file
85
Source/Editor/CustomEditors/Editors/Double2Editor.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Linq;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Editors
|
||||
{
|
||||
/// <summary>
|
||||
/// Default implementation of the inspector used to edit Double2 value type properties.
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(Double2)), DefaultEditor]
|
||||
public class Double2Editor : CustomEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// The X component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement XElement;
|
||||
|
||||
/// <summary>
|
||||
/// The Y component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement YElement;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DisplayStyle Style => DisplayStyle.Inline;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize(LayoutElementsContainer layout)
|
||||
{
|
||||
var grid = layout.CustomContainer<UniformGridPanel>();
|
||||
var gridControl = grid.CustomControl;
|
||||
gridControl.ClipChildren = false;
|
||||
gridControl.Height = TextBox.DefaultHeight;
|
||||
gridControl.SlotsHorizontally = 2;
|
||||
gridControl.SlotsVertically = 1;
|
||||
|
||||
LimitAttribute limit = null;
|
||||
var attributes = Values.GetAttributes();
|
||||
if (attributes != null)
|
||||
{
|
||||
limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
|
||||
}
|
||||
|
||||
XElement = grid.DoubleValue();
|
||||
XElement.SetLimits(limit);
|
||||
XElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
XElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
|
||||
YElement = grid.DoubleValue();
|
||||
YElement.SetLimits(limit);
|
||||
YElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
YElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
}
|
||||
|
||||
private void OnValueChanged()
|
||||
{
|
||||
if (IsSetBlocked)
|
||||
return;
|
||||
|
||||
var isSliding = XElement.IsSliding || YElement.IsSliding;
|
||||
var token = isSliding ? this : null;
|
||||
var value = new Double2(XElement.DoubleValue.Value, YElement.DoubleValue.Value);
|
||||
SetValue(value, token);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Refresh()
|
||||
{
|
||||
base.Refresh();
|
||||
|
||||
if (HasDifferentValues)
|
||||
{
|
||||
// TODO: support different values for ValueBox<T>
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = (Double2)Values[0];
|
||||
XElement.DoubleValue.Value = value.X;
|
||||
YElement.DoubleValue.Value = value.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Source/Editor/CustomEditors/Editors/Double3Editor.cs
Normal file
96
Source/Editor/CustomEditors/Editors/Double3Editor.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Linq;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Editors
|
||||
{
|
||||
/// <summary>
|
||||
/// Default implementation of the inspector used to edit Double3 value type properties.
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(Double3)), DefaultEditor]
|
||||
public class Double3Editor : CustomEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// The X component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement XElement;
|
||||
|
||||
/// <summary>
|
||||
/// The Y component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement YElement;
|
||||
|
||||
/// <summary>
|
||||
/// The Z component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement ZElement;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DisplayStyle Style => DisplayStyle.Inline;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize(LayoutElementsContainer layout)
|
||||
{
|
||||
var grid = layout.CustomContainer<UniformGridPanel>();
|
||||
var gridControl = grid.CustomControl;
|
||||
gridControl.ClipChildren = false;
|
||||
gridControl.Height = TextBox.DefaultHeight;
|
||||
gridControl.SlotsHorizontally = 3;
|
||||
gridControl.SlotsVertically = 1;
|
||||
|
||||
LimitAttribute limit = null;
|
||||
var attributes = Values.GetAttributes();
|
||||
if (attributes != null)
|
||||
{
|
||||
limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
|
||||
}
|
||||
|
||||
XElement = grid.DoubleValue();
|
||||
XElement.SetLimits(limit);
|
||||
XElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
XElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
|
||||
YElement = grid.DoubleValue();
|
||||
YElement.SetLimits(limit);
|
||||
YElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
YElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
|
||||
ZElement = grid.DoubleValue();
|
||||
ZElement.SetLimits(limit);
|
||||
ZElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
ZElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
}
|
||||
|
||||
private void OnValueChanged()
|
||||
{
|
||||
if (IsSetBlocked)
|
||||
return;
|
||||
|
||||
var isSliding = XElement.IsSliding || YElement.IsSliding || ZElement.IsSliding;
|
||||
var token = isSliding ? this : null;
|
||||
var value = new Double3(XElement.DoubleValue.Value, YElement.DoubleValue.Value, ZElement.DoubleValue.Value);
|
||||
SetValue(value, token);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Refresh()
|
||||
{
|
||||
base.Refresh();
|
||||
|
||||
if (HasDifferentValues)
|
||||
{
|
||||
// TODO: support different values for ValueBox<T>
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = (Double3)Values[0];
|
||||
XElement.DoubleValue.Value = value.X;
|
||||
YElement.DoubleValue.Value = value.Y;
|
||||
ZElement.DoubleValue.Value = value.Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
107
Source/Editor/CustomEditors/Editors/Double4Editor.cs
Normal file
107
Source/Editor/CustomEditors/Editors/Double4Editor.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Linq;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Editors
|
||||
{
|
||||
/// <summary>
|
||||
/// Default implementation of the inspector used to edit Double4 value type properties.
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(Double4)), DefaultEditor]
|
||||
public class Double4Editor : CustomEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// The X component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement XElement;
|
||||
|
||||
/// <summary>
|
||||
/// The Y component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement YElement;
|
||||
|
||||
/// <summary>
|
||||
/// The Z component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement ZElement;
|
||||
|
||||
/// <summary>
|
||||
/// The W component editor.
|
||||
/// </summary>
|
||||
protected DoubleValueElement WElement;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override DisplayStyle Style => DisplayStyle.Inline;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize(LayoutElementsContainer layout)
|
||||
{
|
||||
var grid = layout.CustomContainer<UniformGridPanel>();
|
||||
var gridControl = grid.CustomControl;
|
||||
gridControl.ClipChildren = false;
|
||||
gridControl.Height = TextBox.DefaultHeight;
|
||||
gridControl.SlotsHorizontally = 4;
|
||||
gridControl.SlotsVertically = 1;
|
||||
|
||||
LimitAttribute limit = null;
|
||||
var attributes = Values.GetAttributes();
|
||||
if (attributes != null)
|
||||
{
|
||||
limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
|
||||
}
|
||||
|
||||
XElement = grid.DoubleValue();
|
||||
XElement.SetLimits(limit);
|
||||
XElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
XElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
|
||||
YElement = grid.DoubleValue();
|
||||
YElement.SetLimits(limit);
|
||||
YElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
YElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
|
||||
ZElement = grid.DoubleValue();
|
||||
ZElement.SetLimits(limit);
|
||||
ZElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
ZElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
|
||||
WElement = grid.DoubleValue();
|
||||
WElement.SetLimits(limit);
|
||||
WElement.DoubleValue.ValueChanged += OnValueChanged;
|
||||
WElement.DoubleValue.SlidingEnd += ClearToken;
|
||||
}
|
||||
|
||||
private void OnValueChanged()
|
||||
{
|
||||
if (IsSetBlocked)
|
||||
return;
|
||||
|
||||
var isSliding = XElement.IsSliding || YElement.IsSliding || ZElement.IsSliding || WElement.IsSliding;
|
||||
var token = isSliding ? this : null;
|
||||
var value = new Double4(XElement.DoubleValue.Value, YElement.DoubleValue.Value, ZElement.DoubleValue.Value, WElement.DoubleValue.Value);
|
||||
SetValue(value, token);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Refresh()
|
||||
{
|
||||
base.Refresh();
|
||||
|
||||
if (HasDifferentValues)
|
||||
{
|
||||
// TODO: support different values for ValueBox<T>
|
||||
}
|
||||
else
|
||||
{
|
||||
var value = (Double4)Values[0];
|
||||
XElement.DoubleValue.Value = value.X;
|
||||
YElement.DoubleValue.Value = value.Y;
|
||||
ZElement.DoubleValue.Value = value.Z;
|
||||
WElement.DoubleValue.Value = value.W;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1773
Source/Engine/Core/Math/Double2.cs
Normal file
1773
Source/Engine/Core/Math/Double2.cs
Normal file
File diff suppressed because it is too large
Load Diff
2060
Source/Engine/Core/Math/Double3.cs
Normal file
2060
Source/Engine/Core/Math/Double3.cs
Normal file
File diff suppressed because it is too large
Load Diff
1534
Source/Engine/Core/Math/Double4.cs
Normal file
1534
Source/Engine/Core/Math/Double4.cs
Normal file
File diff suppressed because it is too large
Load Diff
46
Source/Engine/Core/Math/TypeConverters/Double2Converter.cs
Normal file
46
Source/Engine/Core/Math/TypeConverters/Double2Converter.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
namespace FlaxEngine.TypeConverters
|
||||
{
|
||||
internal class Double2Converter : TypeConverter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof(string))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
string[] v = str.Split(',');
|
||||
return new Double2(double.Parse(v[0]), double.Parse(v[1]));
|
||||
}
|
||||
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
{
|
||||
var v = (Double2)value;
|
||||
return v.X + "," + v.Y;
|
||||
}
|
||||
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Source/Engine/Core/Math/TypeConverters/Double3Converter.cs
Normal file
46
Source/Engine/Core/Math/TypeConverters/Double3Converter.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
namespace FlaxEngine.TypeConverters
|
||||
{
|
||||
internal class Double3Converter : TypeConverter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof(string))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
string[] v = str.Split(',');
|
||||
return new Double3(double.Parse(v[0]), double.Parse(v[1]), double.Parse(v[2]));
|
||||
}
|
||||
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
{
|
||||
var v = (Double3)value;
|
||||
return v.X + "," + v.Y + "," + v.Z;
|
||||
}
|
||||
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Source/Engine/Core/Math/TypeConverters/Double4Converter.cs
Normal file
46
Source/Engine/Core/Math/TypeConverters/Double4Converter.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
namespace FlaxEngine.TypeConverters
|
||||
{
|
||||
internal class Double4Converter : TypeConverter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof(string))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
string[] v = str.Split(',');
|
||||
return new Double4(double.Parse(v[0]), double.Parse(v[1]), double.Parse(v[2]), double.Parse(v[3]));
|
||||
}
|
||||
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
{
|
||||
var v = (Double4)value;
|
||||
return v.X + "," + v.Y + "," + v.Z + "," + v.W;
|
||||
}
|
||||
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user