Added undo/redo to profile editor

Added shape anchor point display and movement
This commit is contained in:
Robert committed 2020-01-14 17:19:53 +01:00
1 parent e9677f2070
commit c97b479779
25 files changed
+386 -68

No files matched your search

@@ -101,10 +101,10 @@ namespace Artemis.Core.Models.Profile.LayerProperties
protected List<BaseKeyframe> BaseKeyframes { get; set; }
protected internal object BaseValue
public object BaseValue
{
get => _baseValue;
set
internal set
{
if (value != null && value.GetType() != Type)
throw new ArtemisCoreException($"Cannot set value of type {value.GetType()} on property {this}, expected type is {Type}.");
@@ -164,13 +164,13 @@ namespace Artemis.Core.Models.Profile.LayerProperties
/// Creates a new keyframe for this base property without knowing the type
/// </summary>
/// <returns></returns>
public BaseKeyframe CreateNewKeyframe(TimeSpan position)
public BaseKeyframe CreateNewKeyframe(TimeSpan position, object value)
{
// Create a strongly typed keyframe or else it cannot be cast later on
var keyframeType = typeof(Keyframe<>);
var keyframe = (BaseKeyframe) Activator.CreateInstance(keyframeType.MakeGenericType(Type), Layer, this);
keyframe.Position = position;
keyframe.BaseValue = BaseValue;
keyframe.BaseValue = value;
BaseKeyframes.Add(keyframe);
SortKeyframes();
@@ -186,6 +186,17 @@ namespace Artemis.Core.Models.Profile.LayerProperties
BaseKeyframes.Clear();
}
/// <summary>
/// Gets the current value using the regular value or if present, keyframes
/// </summary>
public object GetCurrentValue()
{
if (KeyframeEngine == null || !UntypedKeyframes.Any())
return BaseValue;
return KeyframeEngine.GetCurrentValue();
}
/// <summary>
/// Gets the current value using the regular value or keyframes.
/// </summary>
@@ -207,12 +218,32 @@ namespace Artemis.Core.Models.Profile.LayerProperties
var currentKeyframe = UntypedKeyframes.FirstOrDefault(k => k.Position == time.Value);
// Create a new keyframe if none found
if (currentKeyframe == null)
currentKeyframe = CreateNewKeyframe(time.Value);
currentKeyframe = CreateNewKeyframe(time.Value, value);
currentKeyframe.BaseValue = value;
}
}
/// <summary>
/// Adds a keyframe to the property.
/// </summary>
/// <param name="keyframe">The keyframe to remove</param>
public void AddKeyframe(BaseKeyframe keyframe)
{
BaseKeyframes.Add(keyframe);
SortKeyframes();
}
/// <summary>
/// Removes a keyframe from the property.
/// </summary>
/// <param name="keyframe">The keyframe to remove</param>
public void RemoveKeyframe(BaseKeyframe keyframe)
{
BaseKeyframes.Remove(keyframe);
SortKeyframes();
}
internal void SortKeyframes()
{
BaseKeyframes = BaseKeyframes.OrderBy(k => k.Position).ToList();