mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Added undo/redo to profile editor
Added shape anchor point display and movement
This commit is contained in:
1 parent
e9677f2070
commit
c97b479779
25 files changed
+386
-68
No files matched your search
@@ -27,7 +27,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
}
|
||||
|
||||
protected BaseLayerProperty BaseProperty { get; }
|
||||
protected internal object BaseValue { get; set; }
|
||||
public object BaseValue { get; internal set; }
|
||||
public Easings.Functions EasingFunction { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -22,7 +22,14 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// <summary>
|
||||
/// Gets the value of the property with keyframes applied
|
||||
/// </summary>
|
||||
public T CurrentValue => KeyframeEngine != null ? (T) KeyframeEngine.GetCurrentValue() : Value;
|
||||
public T CurrentValue
|
||||
{
|
||||
get
|
||||
{
|
||||
var currentValue = base.GetCurrentValue();
|
||||
return currentValue == null ? default : (T)currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of keyframes defining different values of the property in time, this list contains the strongly typed
|
||||
@@ -36,8 +43,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// <param name="keyframe">The keyframe to remove</param>
|
||||
public void AddKeyframe(Keyframe<T> keyframe)
|
||||
{
|
||||
BaseKeyframes.Add(keyframe);
|
||||
SortKeyframes();
|
||||
base.AddKeyframe(keyframe);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,20 +52,7 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// <param name="keyframe">The keyframe to remove</param>
|
||||
public void RemoveKeyframe(Keyframe<T> keyframe)
|
||||
{
|
||||
BaseKeyframes.Remove(keyframe);
|
||||
SortKeyframes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value using the regular value or if present, keyframes
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public T GetCurrentValue()
|
||||
{
|
||||
if (KeyframeEngine == null || !Keyframes.Any())
|
||||
return Value;
|
||||
|
||||
return (T) KeyframeEngine.GetCurrentValue();
|
||||
base.RemoveKeyframe(keyframe);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user