Plugins - Moved test data model to a seperate plugin

Core - Moved built-in types to a separate folder and namespace
This commit is contained in:
Robert committed 2020-09-16 19:22:37 +02:00
1 parent d788183f25
commit d9017c67b4
59 files changed
+350 -131

No files matched your search

@@ -1,51 +0,0 @@
using System;
using SkiaSharp;
namespace Artemis.Core
{
/// <inheritdoc />
public class FloatDataBindingConverter : FloatDataBindingConverter<float>
{
}
/// <inheritdoc />
/// <typeparam name="T">The type of layer property this converter is applied to</typeparam>
public class FloatDataBindingConverter<T> : DataBindingConverter<T, float>
{
/// <summary>
/// Creates a new instance of the <see cref="FloatDataBindingConverter{T}" /> class
/// </summary>
public FloatDataBindingConverter()
{
SupportsSum = true;
SupportsInterpolate = true;
}
/// <inheritdoc />
public override float Sum(float a, float b)
{
return a + b;
}
/// <inheritdoc />
public override float Interpolate(float a, float b, double progress)
{
var diff = b - a;
return (float) (a + diff * progress);
}
/// <inheritdoc />
public override void ApplyValue(float value)
{
if (ValueTypeSetExpression == null)
return;
if (DataBinding.LayerProperty.PropertyDescription.MaxInputValue is float max)
value = Math.Min(value, max);
if (DataBinding.LayerProperty.PropertyDescription.MinInputValue is float min)
value = Math.Max(value, min);
base.ApplyValue(value);
}
}
}
@@ -1,26 +0,0 @@
using System;
namespace Artemis.Core
{
/// <inheritdoc />
public class GeneralDataBindingConverter<T> : DataBindingConverter<T, object> where T : ILayerProperty
{
public GeneralDataBindingConverter()
{
SupportsSum = false;
SupportsInterpolate = false;
}
/// <inheritdoc />
public override object Sum(object a, object b)
{
throw new NotSupportedException();
}
/// <inheritdoc />
public override object Interpolate(object a, object b, double progress)
{
throw new NotSupportedException();
}
}
}
@@ -1,41 +0,0 @@
using System;
namespace Artemis.Core
{
/// <inheritdoc />
public class IntDataBindingConverter : IntDataBindingConverter<int>
{
}
/// <inheritdoc />
public class IntDataBindingConverter<T> : DataBindingConverter<T, int>
{
/// <summary>
/// Creates a new instance of the <see cref="IntDataBindingConverter{T}" /> class
/// </summary>
public IntDataBindingConverter()
{
SupportsSum = true;
SupportsInterpolate = true;
}
/// <summary>
/// Gets or sets the <see cref="MidpointRounding" /> mode used for rounding during interpolation. Defaults to
/// <see cref="MidpointRounding.AwayFromZero" />
/// </summary>
public MidpointRounding InterpolationRoundingMode { get; set; } = MidpointRounding.AwayFromZero;
/// <inheritdoc />
public override int Sum(int a, int b)
{
return a + b;
}
/// <inheritdoc />
public override int Interpolate(int a, int b, double progress)
{
var diff = b - a;
return (int) Math.Round(a + diff * progress, InterpolationRoundingMode);
}
}
}
@@ -1,70 +0,0 @@
using System;
using SkiaSharp;
namespace Artemis.Core
{
// This is internal because it's mainly a proof-of-concept
internal class SKColorArgbDataBindingConverter : DataBindingConverter<SKColor, byte>
{
private readonly Channel _channel;
public SKColorArgbDataBindingConverter(Channel channel)
{
_channel = channel;
SupportsSum = true;
SupportsInterpolate = true;
}
public override byte Sum(byte a, byte b)
{
return ClampToByte(a + b);
}
public override byte Interpolate(byte a, byte b, double progress)
{
var diff = b - a;
return ClampToByte(a + diff * progress);
}
public override void ApplyValue(byte value)
{
switch (_channel)
{
case Channel.Alpha:
DataBinding.LayerProperty.CurrentValue = DataBinding.LayerProperty.CurrentValue.WithAlpha(value);
break;
case Channel.Red:
DataBinding.LayerProperty.CurrentValue = DataBinding.LayerProperty.CurrentValue.WithRed(value);
break;
case Channel.Green:
DataBinding.LayerProperty.CurrentValue = DataBinding.LayerProperty.CurrentValue.WithGreen(value);
break;
case Channel.Blue:
DataBinding.LayerProperty.CurrentValue = DataBinding.LayerProperty.CurrentValue.WithBlue(value);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public override byte ConvertFromObject(object source)
{
var saveValue = Convert.ToDouble(source);
return ClampToByte(saveValue);
}
private static byte ClampToByte(double value)
{
return (byte) Math.Clamp(value, 0, 255);
}
public enum Channel
{
Alpha,
Red,
Green,
Blue
}
}
}
@@ -1,20 +0,0 @@
using SkiaSharp;
namespace Artemis.Core
{
/// <inheritdoc />
public class SKColorDataBindingConverter : DataBindingConverter<SKColor, SKColor>
{
/// <inheritdoc />
public override SKColor Sum(SKColor a, SKColor b)
{
return a.Sum(b);
}
/// <inheritdoc />
public override SKColor Interpolate(SKColor a, SKColor b, double progress)
{
return a.Interpolate(b, (float)progress);
}
}
}
@@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
{
internal class DivideModifierType : DataBindingModifierType
{
public DivideModifierType()
{
PreferredParameterType = typeof(float);
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Description => "Divide by";
public override string Icon => "Divide";
public override object Apply(object currentValue, object parameterValue)
{
var parameter = Convert.ToSingle(parameterValue);
// Ye ye none of that
if (parameter == 0)
return 0;
return Convert.ToSingle(currentValue) / parameter;
}
}
}
@@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
{
internal class FloorModifierType : DataBindingModifierType
{
public FloorModifierType()
{
SupportsParameter = false;
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Description => "Floor";
public override string Icon => "ArrowDownDropCircleOutline";
public override object Apply(object currentValue, object parameterValue)
{
var floatValue = Convert.ToSingle(currentValue);
return Math.Floor(floatValue);
}
}
}
@@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
{
internal class MultiplicationModifierType : DataBindingModifierType
{
public MultiplicationModifierType()
{
PreferredParameterType = typeof(float);
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Description => "Multiply by";
public override string Icon => "Close";
public override object Apply(object currentValue, object parameterValue)
{
return Convert.ToSingle(currentValue) * Convert.ToSingle(parameterValue);
}
}
}
@@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
namespace Artemis.Core
{
internal class PercentageOfModifierType : DataBindingModifierType
{
public PercentageOfModifierType()
{
PreferredParameterType = typeof(float);
}
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
public override string Description => "Percentage of";
public override string Icon => "Percent";
public override object Apply(object currentValue, object parameterValue)
{
var parameter = Convert.ToSingle(parameterValue);
// Ye ye none of that
if (parameter == 0f)
return 100f;
return 100f / Convert.ToSingle(parameterValue) * Convert.ToSingle(currentValue);
}
}
}