1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Started work on the keyframe engine to tie everything together!

This commit is contained in:
Robert 2020-01-08 20:36:27 +01:00
parent 139e1879c1
commit d1e0267709
28 changed files with 339 additions and 107 deletions

View File

@ -149,6 +149,11 @@
<Compile Include="Extensions\TypeExtensions.cs" /> <Compile Include="Extensions\TypeExtensions.cs" />
<Compile Include="JsonConverters\SKColorConverter.cs" /> <Compile Include="JsonConverters\SKColorConverter.cs" />
<Compile Include="Models\DataModelDescription.cs" /> <Compile Include="Models\DataModelDescription.cs" />
<Compile Include="Models\Profile\KeyframeEngines\FloatKeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\IntKeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\KeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\SKPointKeyframeEngine.cs" />
<Compile Include="Models\Profile\KeyframeEngines\SKSizeKeyframeEngine.cs" />
<Compile Include="Models\Profile\LayerProperties\BaseKeyframe.cs" /> <Compile Include="Models\Profile\LayerProperties\BaseKeyframe.cs" />
<Compile Include="Models\Profile\LayerProperties\Keyframe.cs" /> <Compile Include="Models\Profile\LayerProperties\Keyframe.cs" />
<Compile Include="Models\Profile\LayerProperties\BaseLayerProperty.cs" /> <Compile Include="Models\Profile\LayerProperties\BaseLayerProperty.cs" />

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class FloatKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(float)};
public override object GetCurrentValue()
{
// Nothing fancy for now, just return the base value
return ((LayerProperty<float>) LayerProperty).Value;
}
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class IntKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(int)};
public override object GetCurrentValue()
{
// Nothing fancy for now, just return the base value
return ((LayerProperty<int>) LayerProperty).Value;
}
}
}

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.LayerProperties;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
public abstract class KeyframeEngine
{
/// <summary>
/// Indicates whether <see cref="Initialize" /> has been called.
/// </summary>
public bool Initialized { get; private set; }
/// <summary>
/// The layer property this keyframe engine applies to.
/// </summary>
public BaseLayerProperty LayerProperty { get; set; }
/// <summary>
/// The keyframe progress in milliseconds.
/// </summary>
public double Progress { get; set; }
/// <summary>
/// The types this keyframe engine supports.
/// </summary>
public abstract List<Type> CompatibleTypes { get; }
/// <summary>
/// Associates the keyframe engine with the provided layer property.
/// </summary>
/// <param name="layerProperty"></param>
public void Initialize(BaseLayerProperty layerProperty)
{
if (Initialized)
throw new ArtemisCoreException("Cannot initialize the same keyframe engine twice");
if (!CompatibleTypes.Contains(layerProperty.Type))
throw new ArtemisCoreException($"This property engine does not support the provided type {layerProperty.Type.Name}");
LayerProperty = layerProperty;
Initialized = true;
}
/// <summary>
/// Updates the engine's progress
/// </summary>
/// <param name="deltaTime"></param>
public void Update(double deltaTime)
{
if (!Initialized)
return;
Progress += deltaTime;
// LayerProperty determines what's next: reset, stop, continue
}
/// <summary>
/// Gets the current value, if the progress is in between two keyframes the value will be interpolated
/// </summary>
/// <returns></returns>
public abstract object GetCurrentValue();
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class SKPointKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKPoint)};
public override object GetCurrentValue()
{
// Nothing fancy for now, just return the base value
return ((LayerProperty<SKPoint>) LayerProperty).Value;
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.KeyframeEngines
{
/// <inheritdoc />
public class SKSizeKeyframeEngine : KeyframeEngine
{
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKSize)};
public override object GetCurrentValue()
{
// Nothing fancy for now, just return the base value
return ((LayerProperty<SKSize>) LayerProperty).Value;
}
}
}

View File

@ -128,9 +128,9 @@ namespace Artemis.Core.Models.Profile
public LayerProperty<SKPoint> PositionProperty { get; private set; } public LayerProperty<SKPoint> PositionProperty { get; private set; }
/// <summary> /// <summary>
/// The scale property of this layer, also found in <see cref="Properties" /> /// The size property of this layer, also found in <see cref="Properties" />
/// </summary> /// </summary>
public LayerProperty<SKSize> ScaleProperty { get; private set; } public LayerProperty<SKSize> SizeProperty { get; private set; }
/// <summary> /// <summary>
/// The rotation property of this layer, also found in <see cref="Properties" /> /// The rotation property of this layer, also found in <see cref="Properties" />
@ -304,12 +304,12 @@ namespace Artemis.Core.Models.Profile
var transformProperty = new LayerProperty<object>(this, null, "Core.Transform", "Transform", "The default properties collection every layer has, allows you to transform the shape."); var transformProperty = new LayerProperty<object>(this, null, "Core.Transform", "Transform", "The default properties collection every layer has, allows you to transform the shape.");
AnchorPointProperty = new LayerProperty<SKPoint>(this, transformProperty, "Core.AnchorPoint", "Anchor Point", "The point at which the shape is attached to its position."); AnchorPointProperty = new LayerProperty<SKPoint>(this, transformProperty, "Core.AnchorPoint", "Anchor Point", "The point at which the shape is attached to its position.");
PositionProperty = new LayerProperty<SKPoint>(this, transformProperty, "Core.Position", "Position", "The position of the shape."); PositionProperty = new LayerProperty<SKPoint>(this, transformProperty, "Core.Position", "Position", "The position of the shape.");
ScaleProperty = new LayerProperty<SKSize>(this, transformProperty, "Core.Scale", "Scale", "The scale of the shape.") {InputAffix = "%"}; SizeProperty = new LayerProperty<SKSize>(this, transformProperty, "Core.Size", "Size", "The size of the shape.") {InputAffix = "%"};
RotationProperty = new LayerProperty<int>(this, transformProperty, "Core.Rotation", "Rotation", "The rotation of the shape in degrees.") {InputAffix = "°"}; RotationProperty = new LayerProperty<int>(this, transformProperty, "Core.Rotation", "Rotation", "The rotation of the shape in degrees.") {InputAffix = "°"};
OpacityProperty = new LayerProperty<float>(this, transformProperty, "Core.Opacity", "Opacity", "The opacity of the shape.") {InputAffix = "%"}; OpacityProperty = new LayerProperty<float>(this, transformProperty, "Core.Opacity", "Opacity", "The opacity of the shape.") {InputAffix = "%"};
transformProperty.Children.Add(AnchorPointProperty); transformProperty.Children.Add(AnchorPointProperty);
transformProperty.Children.Add(PositionProperty); transformProperty.Children.Add(PositionProperty);
transformProperty.Children.Add(ScaleProperty); transformProperty.Children.Add(SizeProperty);
transformProperty.Children.Add(RotationProperty); transformProperty.Children.Add(RotationProperty);
transformProperty.Children.Add(OpacityProperty); transformProperty.Children.Add(OpacityProperty);
@ -345,7 +345,10 @@ namespace Artemis.Core.Models.Profile
path.AddRect(artemisLed.AbsoluteRenderRectangle); path.AddRect(artemisLed.AbsoluteRenderRectangle);
Path = path; Path = path;
LayerShape?.CalculateRenderProperties(); // This is called here so that the shape's render properties are up to date when other code
// responds to OnRenderPropertiesUpdated
LayerShape?.CalculateRenderProperties(PositionProperty.GetCurrentValue(), SizeProperty.GetCurrentValue());
OnRenderPropertiesUpdated(); OnRenderPropertiesUpdated();
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.KeyframeEngines;
namespace Artemis.Core.Models.Profile.LayerProperties namespace Artemis.Core.Models.Profile.LayerProperties
{ {
@ -67,12 +68,16 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// </summary> /// </summary>
public Type Type { get; set; } public Type Type { get; set; }
protected List<BaseKeyframe> BaseKeyframes { get; set; }
/// <summary> /// <summary>
/// A list of keyframes defining different values of the property in time, this list contains the untyped <see cref="BaseKeyframe"/>. /// A list of keyframes defining different values of the property in time, this list contains the untyped
/// <see cref="BaseKeyframe" />.
/// </summary> /// </summary>
public IReadOnlyCollection<BaseKeyframe> UntypedKeyframes => BaseKeyframes.AsReadOnly(); public IReadOnlyCollection<BaseKeyframe> UntypedKeyframes => BaseKeyframes.AsReadOnly();
public KeyframeEngine KeyframeEngine { get; set; }
protected List<BaseKeyframe> BaseKeyframes { get; set; }
protected object BaseValue protected object BaseValue
{ {
get => _baseValue; get => _baseValue;
@ -80,10 +85,13 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{ {
if (value != null && value.GetType() != Type) if (value != null && value.GetType() != Type)
throw new ArtemisCoreException($"Cannot set value of type {value.GetType()} on property {this}, expected type is {Type}."); throw new ArtemisCoreException($"Cannot set value of type {value.GetType()} on property {this}, expected type is {Type}.");
if (!Equals(_baseValue, value))
{
_baseValue = value; _baseValue = value;
OnValueChanged();
}
} }
} }
public void ApplyToEntity() public void ApplyToEntity()
{ {
@ -94,5 +102,16 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{ {
return $"{nameof(Id)}: {Id}, {nameof(Name)}: {Name}, {nameof(Description)}: {Description}"; return $"{nameof(Id)}: {Id}, {nameof(Name)}: {Name}, {nameof(Description)}: {Description}";
} }
#region Events
public event EventHandler<EventArgs> ValueChanged;
protected virtual void OnValueChanged()
{
ValueChanged?.Invoke(this, EventArgs.Empty);
}
#endregion
} }
} }

View File

@ -9,14 +9,18 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{ {
} }
/// <summary>
/// The value of the property without any keyframes applied
/// </summary>
public T Value public T Value
{ {
get => (T) BaseValue; get => BaseValue != null ? (T) BaseValue : default;
set => BaseValue = value; set => BaseValue = value;
} }
/// <summary> /// <summary>
/// A list of keyframes defining different values of the property in time, this list contains the strongly typed <see cref="Keyframe{T}"/> /// A list of keyframes defining different values of the property in time, this list contains the strongly typed
/// <see cref="Keyframe{T}" />
/// </summary> /// </summary>
public ReadOnlyCollection<Keyframe<T>> Keyframes => BaseKeyframes.Cast<Keyframe<T>>().ToList().AsReadOnly(); public ReadOnlyCollection<Keyframe<T>> Keyframes => BaseKeyframes.Cast<Keyframe<T>>().ToList().AsReadOnly();
@ -45,5 +49,17 @@ namespace Artemis.Core.Models.Profile.LayerProperties
{ {
BaseKeyframes.Clear(); BaseKeyframes.Clear();
} }
/// <summary>
/// Gets the current value using the keyframes
/// </summary>
/// <returns></returns>
public T GetCurrentValue()
{
if (KeyframeEngine == null)
return Value;
return (T) KeyframeEngine.GetCurrentValue();
}
} }
} }

View File

@ -13,11 +13,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{ {
} }
public override void CalculateRenderProperties() public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
{ {
var width = Layer.AbsoluteRectangle.Width; var width = Layer.AbsoluteRectangle.Width;
var height = Layer.AbsoluteRectangle.Height; var height = Layer.AbsoluteRectangle.Height;
var rect = SKRect.Create(Position.X * width, Position.Y * height, Size.Width * width, Size.Height * height); var rect = SKRect.Create(shapePosition.X * width, shapePosition.Y * height, shapeSize.Width * width, shapeSize.Height * height);
var path = new SKPath(); var path = new SKPath();
path.AddOval(rect); path.AddOval(rect);

View File

@ -1,4 +1,5 @@
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes namespace Artemis.Core.Models.Profile.LayerShapes
{ {
@ -12,8 +13,9 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{ {
} }
public override void CalculateRenderProperties() public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
{ {
// TODO: Scale the path? Not sure if desirable
RenderPath = Layer.Path; RenderPath = Layer.Path;
RenderRectangle = Layer.Path.GetRect(); RenderRectangle = Layer.Path.GetRect();
} }

View File

@ -6,9 +6,6 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{ {
public abstract class LayerShape public abstract class LayerShape
{ {
private SKPoint _position;
private SKSize _size;
protected LayerShape(Layer layer) protected LayerShape(Layer layer)
{ {
Layer = layer; Layer = layer;
@ -17,48 +14,13 @@ namespace Artemis.Core.Models.Profile.LayerShapes
protected LayerShape(Layer layer, ShapeEntity shapeEntity) protected LayerShape(Layer layer, ShapeEntity shapeEntity)
{ {
Layer = layer; Layer = layer;
Anchor = new SKPoint(shapeEntity.Anchor?.X ?? 0, shapeEntity.Anchor?.Y ?? 0);
Position = new SKPoint(shapeEntity.Position?.X ?? 0, shapeEntity.Position?.Y ?? 0);
Size = new SKSize(shapeEntity.Width, shapeEntity.Height);
} }
/// <summary> /// <summary>
/// The layer this shape is attached to /// The layer this shape is attached to
/// </summary> /// </summary>
public Layer Layer { get; set; } public Layer Layer { get; set; }
/// <summary>
/// At which position the shape is attached to the layer
/// </summary>
public SKPoint Anchor { get; set; }
/// <summary>
/// The position of the shape
/// </summary>
public SKPoint Position
{
get => _position;
set
{
_position = value;
Layer.CalculateRenderProperties();
}
}
/// <summary>
/// The size of the shape
/// </summary>
public SKSize Size
{
get => _size;
set
{
_size = value;
Layer.CalculateRenderProperties();
}
}
/// <summary> /// <summary>
/// A render rectangle relative to the layer /// A render rectangle relative to the layer
/// </summary> /// </summary>
@ -69,17 +31,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
/// </summary> /// </summary>
public SKPath RenderPath { get; protected set; } public SKPath RenderPath { get; protected set; }
public abstract void CalculateRenderProperties(); public abstract void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize);
public virtual void ApplyToEntity() public virtual void ApplyToEntity()
{ {
Layer.LayerEntity.ShapeEntity = new ShapeEntity Layer.LayerEntity.ShapeEntity = new ShapeEntity();
{
Anchor = new ShapePointEntity {X = Anchor.X, Y = Anchor.Y},
Position = new ShapePointEntity {X = Position.X, Y = Position.Y},
Width = Size.Width,
Height = Size.Height
};
} }
/// <summary> /// <summary>
@ -90,8 +46,8 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{ {
if (!Layer.Leds.Any()) if (!Layer.Leds.Any())
{ {
Position = SKPoint.Empty; Layer.PositionProperty.Value = SKPoint.Empty;
Size = SKSize.Empty; Layer.SizeProperty.Value = SKSize.Empty;
return; return;
} }
@ -100,8 +56,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
var width = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.X + l.RgbLed.AbsoluteLedRectangle.Size.Width) - x; var width = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.X + l.RgbLed.AbsoluteLedRectangle.Size.Width) - x;
var height = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y; var height = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y;
Position = new SKPoint((float) (100f / width * (rect.Left - x)) / 100f, (float) (100f / height * (rect.Top - y)) / 100f); Layer.PositionProperty.Value = new SKPoint((float) (100f / width * (rect.Left - x)) / 100f, (float) (100f / height * (rect.Top - y)) / 100f);
Size = new SKSize((float) (100f / width * rect.Width) / 100f, (float) (100f / height * rect.Height) / 100f); Layer.SizeProperty.Value = new SKSize((float) (100f / width * rect.Width) / 100f, (float) (100f / height * rect.Height) / 100f);
// TODO: Update keyframes
CalculateRenderProperties(Layer.PositionProperty.Value, Layer.SizeProperty.Value);
} }
public SKRect GetUnscaledRectangle() public SKRect GetUnscaledRectangle()
@ -115,10 +74,10 @@ namespace Artemis.Core.Models.Profile.LayerShapes
var height = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y; var height = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y;
return SKRect.Create( return SKRect.Create(
(float) (x + width * Position.X), (float) (x + width * Layer.PositionProperty.Value.X),
(float) (y + height * Position.Y), (float) (y + height * Layer.PositionProperty.Value.Y),
(float) (width * Size.Width), (float) (width * Layer.SizeProperty.Value.Width),
(float) (height * Size.Height) (float) (height * Layer.SizeProperty.Value.Height)
); );
} }
} }

View File

@ -25,7 +25,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
/// </summary> /// </summary>
public List<SKPoint> RenderPoints => Points.Select(p => new SKPoint(p.X * Layer.AbsoluteRectangle.Width, p.Y * Layer.AbsoluteRectangle.Height)).ToList(); public List<SKPoint> RenderPoints => Points.Select(p => new SKPoint(p.X * Layer.AbsoluteRectangle.Width, p.Y * Layer.AbsoluteRectangle.Height)).ToList();
public override void CalculateRenderProperties() public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
{ {
var path = new SKPath(); var path = new SKPath();
path.AddPoly(RenderPoints.ToArray()); path.AddPoly(RenderPoints.ToArray());

View File

@ -13,11 +13,11 @@ namespace Artemis.Core.Models.Profile.LayerShapes
{ {
} }
public override void CalculateRenderProperties() public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
{ {
var width = Layer.AbsoluteRectangle.Width; var width = Layer.AbsoluteRectangle.Width;
var height = Layer.AbsoluteRectangle.Height; var height = Layer.AbsoluteRectangle.Height;
var rect = SKRect.Create(Position.X * width, Position.Y * height, Size.Width * width, Size.Height * height); var rect = SKRect.Create(shapePosition.X * width, shapePosition.Y * height, shapeSize.Width * width, shapeSize.Height * height);
var path = new SKPath(); var path = new SKPath();
path.AddRect(rect); path.AddRect(rect);
path.Transform(SKMatrix.MakeTranslation(Layer.Rectangle.Left, Layer.Rectangle.Top)); path.Transform(SKMatrix.MakeTranslation(Layer.Rectangle.Left, Layer.Rectangle.Top));

View File

@ -42,11 +42,14 @@ namespace Artemis.Core.Plugins.Models
{ {
get => _value; get => _value;
set set
{
if (!Equals(_value, value))
{ {
_value = value; _value = value;
OnSettingChanged(); OnSettingChanged();
} }
} }
}
/// <summary> /// <summary>
/// Determines whether the setting has been changed /// Determines whether the setting has been changed

View File

@ -5,11 +5,6 @@ namespace Artemis.Storage.Entities.Profile
public class ShapeEntity public class ShapeEntity
{ {
public ShapeEntityType Type { get; set; } public ShapeEntityType Type { get; set; }
public ShapePointEntity Anchor { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public ShapePointEntity Position { get; set; }
public List<ShapePointEntity> Points { get; set; } public List<ShapePointEntity> Points { get; set; }
} }

View File

@ -61,7 +61,7 @@
</Canvas> </Canvas>
<!-- Timeline header --> <!-- Timeline header -->
<ScrollViewer Grid.Row="0" x:Name="TimelineHeaderScrollViewer" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" > <ScrollViewer Grid.Row="0" x:Name="TimelineHeaderScrollViewer" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<StackPanel> <StackPanel>
<!-- Time --> <!-- Time -->
<timeline:PropertyTimelineHeader Margin="0 25 0 0" <timeline:PropertyTimelineHeader Margin="0 25 0 0"

View File

@ -12,8 +12,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
{ {
public class LayerPropertiesViewModel : ProfileEditorPanelViewModel public class LayerPropertiesViewModel : ProfileEditorPanelViewModel
{ {
private readonly IProfileEditorService _profileEditorService;
private readonly ILayerPropertyViewModelFactory _layerPropertyViewModelFactory; private readonly ILayerPropertyViewModelFactory _layerPropertyViewModelFactory;
private readonly IProfileEditorService _profileEditorService;
public LayerPropertiesViewModel(IProfileEditorService profileEditorService, ILayerPropertyViewModelFactory layerPropertyViewModelFactory) public LayerPropertiesViewModel(IProfileEditorService profileEditorService, ILayerPropertyViewModelFactory layerPropertyViewModelFactory)
{ {

View File

@ -11,10 +11,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
public class LayerPropertyViewModel : PropertyChangedBase public class LayerPropertyViewModel : PropertyChangedBase
{ {
private readonly IKernel _kernel; private readonly IKernel _kernel;
private bool _keyframesEnabled;
public LayerPropertyViewModel(BaseLayerProperty layerProperty, public LayerPropertyViewModel(BaseLayerProperty layerProperty, LayerPropertyViewModel parent, ILayerPropertyViewModelFactory layerPropertyViewModelFactory, IKernel kernel)
LayerPropertyViewModel parent,
ILayerPropertyViewModelFactory layerPropertyViewModelFactory, IKernel kernel)
{ {
_kernel = kernel; _kernel = kernel;
@ -33,6 +32,20 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
public bool IsExpanded { get; set; } public bool IsExpanded { get; set; }
public bool KeyframesEnabled
{
get => _keyframesEnabled;
set
{
_keyframesEnabled = value;
UpdateKeyframes();
}
}
private void UpdateKeyframes()
{
}
public PropertyInputViewModel GetPropertyInputViewModel() public PropertyInputViewModel GetPropertyInputViewModel()
{ {
var match = _kernel.Get<List<PropertyInputViewModel>>().FirstOrDefault(p => p.CompatibleTypes.Contains(LayerProperty.Type)); var match = _kernel.Get<List<PropertyInputViewModel>>().FirstOrDefault(p => p.CompatibleTypes.Contains(LayerProperty.Type));

View File

@ -1,10 +1,26 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
{ {
public class FloatPropertyInputViewModel : PropertyInputViewModel public class FloatPropertyInputViewModel : PropertyInputViewModel
{ {
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(float)}; public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(float)};
protected override void UpdateBaseValue(object value)
{
throw new NotImplementedException();
}
protected override void UpdateKeyframeValue(BaseKeyframe keyframe, object value)
{
throw new NotImplementedException();
}
protected override void CreateKeyframeForValue(object value)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -1,10 +1,26 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
{ {
public class IntPropertyInputViewModel : PropertyInputViewModel public class IntPropertyInputViewModel : PropertyInputViewModel
{ {
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(int)}; public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(int)};
protected override void UpdateBaseValue(object value)
{
throw new NotImplementedException();
}
protected override void UpdateKeyframeValue(BaseKeyframe keyframe, object value)
{
throw new NotImplementedException();
}
protected override void CreateKeyframeForValue(object value)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.UI.Exceptions; using Artemis.UI.Exceptions;
using Stylet; using Stylet;
@ -12,6 +14,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
public abstract List<Type> CompatibleTypes { get; } public abstract List<Type> CompatibleTypes { get; }
public LayerPropertyViewModel LayerPropertyViewModel { get; private set; } public LayerPropertyViewModel LayerPropertyViewModel { get; private set; }
public object InputValue
{
get => LayerPropertyViewModel.LayerProperty.KeyframeEngine.GetCurrentValue();
set => UpdateInputValue(value);
}
public void Initialize(LayerPropertyViewModel layerPropertyViewModel) public void Initialize(LayerPropertyViewModel layerPropertyViewModel)
{ {
if (Initialized) if (Initialized)
@ -20,7 +28,32 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
throw new ArtemisUIException($"This input VM does not support the provided type {layerPropertyViewModel.LayerProperty.Type.Name}"); throw new ArtemisUIException($"This input VM does not support the provided type {layerPropertyViewModel.LayerProperty.Type.Name}");
LayerPropertyViewModel = layerPropertyViewModel; LayerPropertyViewModel = layerPropertyViewModel;
Update();
Initialized = true; Initialized = true;
} }
public void Update()
{
NotifyOfPropertyChange(() => InputValue);
}
private void UpdateInputValue(object value)
{
// If keyframes are disabled, update the base value
if (!LayerPropertyViewModel.KeyframesEnabled)
{
UpdateBaseValue(value);
return;
}
// If on a keyframe, update the keyframe TODO: Make decisions..
// var currentKeyframe = LayerPropertyViewModel.LayerProperty.UntypedKeyframes.FirstOrDefault(k => k.Position == LayerPropertyViewModel.)
// Otherwise, add a new keyframe at the current position
}
protected abstract void UpdateBaseValue(object value);
protected abstract void UpdateKeyframeValue(BaseKeyframe keyframe, object value);
protected abstract void CreateKeyframeForValue(object value);
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp; using SkiaSharp;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
@ -7,5 +8,20 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
public class SKPointPropertyInputViewModel : PropertyInputViewModel public class SKPointPropertyInputViewModel : PropertyInputViewModel
{ {
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKPoint)}; public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKPoint)};
protected override void UpdateBaseValue(object value)
{
throw new NotImplementedException();
}
protected override void UpdateKeyframeValue(BaseKeyframe keyframe, object value)
{
throw new NotImplementedException();
}
protected override void CreateKeyframeForValue(object value)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Artemis.Core.Models.Profile.LayerProperties;
using SkiaSharp; using SkiaSharp;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput
@ -7,5 +8,20 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
public class SKSizePropertyInputViewModel : PropertyInputViewModel public class SKSizePropertyInputViewModel : PropertyInputViewModel
{ {
public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKSize)}; public sealed override List<Type> CompatibleTypes { get; } = new List<Type> {typeof(SKSize)};
protected override void UpdateBaseValue(object value)
{
throw new NotImplementedException();
}
protected override void UpdateKeyframeValue(BaseKeyframe keyframe, object value)
{
throw new NotImplementedException();
}
protected override void CreateKeyframeForValue(object value)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -36,7 +36,7 @@
ToolTip="{Binding LayerPropertyViewModel.LayerProperty.Description}" ToolTip="{Binding LayerPropertyViewModel.LayerProperty.Description}"
HorizontalAlignment="Left" /> HorizontalAlignment="Left" />
<ContentControl Grid.Column="2" Margin="20 0" s:View.Model="{Binding PropertyInputViewModel}"/> <ContentControl Grid.Column="2" Margin="20 0" s:View.Model="{Binding PropertyInputViewModel}" />
<Button Grid.Column="3" <Button Grid.Column="3"
Style="{StaticResource MaterialDesignOutlinedButton}" Style="{StaticResource MaterialDesignOutlinedButton}"

View File

@ -1,13 +1,9 @@
using System.Collections.Generic; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput;
using System.Linq;
using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
{ {
public class PropertyTreeChildViewModel : PropertyTreeItemViewModel public class PropertyTreeChildViewModel : PropertyTreeItemViewModel
{ {
private bool _keyframesEnabled;
public PropertyTreeChildViewModel(LayerPropertyViewModel layerPropertyViewModel) public PropertyTreeChildViewModel(LayerPropertyViewModel layerPropertyViewModel)
{ {
LayerPropertyViewModel = layerPropertyViewModel; LayerPropertyViewModel = layerPropertyViewModel;
@ -16,19 +12,5 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree
public LayerPropertyViewModel LayerPropertyViewModel { get; } public LayerPropertyViewModel LayerPropertyViewModel { get; }
public PropertyInputViewModel PropertyInputViewModel { get; set; } public PropertyInputViewModel PropertyInputViewModel { get; set; }
public bool KeyframesEnabled
{
get => _keyframesEnabled;
set
{
_keyframesEnabled = value;
UpdateKeyframes();
}
}
private void UpdateKeyframes()
{
}
} }
} }

View File

@ -99,8 +99,8 @@
</StackPanel> </StackPanel>
</HierarchicalDataTemplate> </HierarchicalDataTemplate>
<!-- Children show their full view --> <!-- Children show their full view -->
<DataTemplate DataType="{x:Type local:PropertyTreeChildViewModel}" > <DataTemplate DataType="{x:Type local:PropertyTreeChildViewModel}">
<ContentControl s:View.Model="{Binding}"/> <ContentControl s:View.Model="{Binding}" />
</DataTemplate> </DataTemplate>
</TreeView.Resources> </TreeView.Resources>
</TreeView> </TreeView>

View File

@ -1,5 +1,4 @@
using System; using System;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerProperties; using Artemis.Core.Models.Profile.LayerProperties;
using Stylet; using Stylet;