mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Added undo/redo to profile editor
Added shape anchor point display and movement
This commit is contained in:
1 parent
7ddf816ca5
commit
0c245ba83d
25 files changed
+386
-68
No files matched your search
@@ -290,7 +290,7 @@ namespace Artemis.Core.Models.Profile
|
||||
Path = path;
|
||||
// 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());
|
||||
LayerShape?.CalculateRenderProperties(PositionProperty.CurrentValue, SizeProperty.CurrentValue);
|
||||
|
||||
OnRenderPropertiesUpdated();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,5 +81,42 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
||||
(float) (height * Layer.SizeProperty.CurrentValue.Height)
|
||||
);
|
||||
}
|
||||
|
||||
public void SetFromUnscaledAnchor(SKPoint anchor, TimeSpan? time)
|
||||
{
|
||||
if (!Layer.Leds.Any())
|
||||
{
|
||||
Layer.PositionProperty.SetCurrentValue(SKPoint.Empty, time);
|
||||
Layer.SizeProperty.SetCurrentValue(SKSize.Empty, time);
|
||||
return;
|
||||
}
|
||||
|
||||
var x = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.X);
|
||||
var y = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.Y);
|
||||
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;
|
||||
|
||||
Layer.AnchorPointProperty.SetCurrentValue(new SKPoint(
|
||||
(float) (100f / width * (anchor.X - x - Layer.PositionProperty.CurrentValue.X)) / 100f,
|
||||
(float) (100f / height * (anchor.Y - y - Layer.PositionProperty.CurrentValue.Y)) / 100f
|
||||
), time);
|
||||
CalculateRenderProperties(Layer.PositionProperty.CurrentValue, Layer.SizeProperty.CurrentValue);
|
||||
}
|
||||
|
||||
public SKPoint GetUnscaledAnchor()
|
||||
{
|
||||
if (!Layer.Leds.Any())
|
||||
return SKPoint.Empty;
|
||||
|
||||
var x = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.X);
|
||||
var y = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.Y);
|
||||
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;
|
||||
|
||||
return new SKPoint(
|
||||
(float) (x + width * (Layer.AnchorPointProperty.CurrentValue.X + Layer.PositionProperty.CurrentValue.X)),
|
||||
(float) (y + height * (Layer.AnchorPointProperty.CurrentValue.Y + Layer.PositionProperty.CurrentValue.Y))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Surface;
|
||||
@@ -17,6 +18,8 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
PluginInfo = pluginInfo;
|
||||
Name = name;
|
||||
UndoStack = new Stack<string>();
|
||||
RedoStack = new Stack<string>();
|
||||
|
||||
AddChild(new Folder(this, null, "Root folder"));
|
||||
ApplyToEntity();
|
||||
@@ -28,14 +31,10 @@ namespace Artemis.Core.Models.Profile
|
||||
EntityId = profileEntity.Id;
|
||||
|
||||
PluginInfo = pluginInfo;
|
||||
Name = profileEntity.Name;
|
||||
UndoStack = new Stack<string>();
|
||||
RedoStack = new Stack<string>();
|
||||
|
||||
// Populate the profile starting at the root, the rest is populated recursively
|
||||
var rootFolder = profileEntity.Folders.FirstOrDefault(f => f.ParentId == new Guid());
|
||||
if (rootFolder == null)
|
||||
AddChild(new Folder(this, null, "Root folder"));
|
||||
else
|
||||
AddChild(new Folder(this, null, rootFolder));
|
||||
ApplyToProfile();
|
||||
}
|
||||
|
||||
public PluginInfo PluginInfo { get; }
|
||||
@@ -43,6 +42,9 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
internal ProfileEntity ProfileEntity { get; set; }
|
||||
|
||||
internal Stack<string> UndoStack { get; set; }
|
||||
internal Stack<string> RedoStack { get; set; }
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
lock (this)
|
||||
@@ -89,6 +91,22 @@ namespace Artemis.Core.Models.Profile
|
||||
ProfileEntity.Layers.AddRange(GetAllLayers().Select(f => f.LayerEntity));
|
||||
}
|
||||
|
||||
public void ApplyToProfile()
|
||||
{
|
||||
Name = ProfileEntity.Name;
|
||||
|
||||
lock (_children)
|
||||
{
|
||||
_children.Clear();
|
||||
// Populate the profile starting at the root, the rest is populated recursively
|
||||
var rootFolder = ProfileEntity.Folders.FirstOrDefault(f => f.ParentId == new Guid());
|
||||
if (rootFolder == null)
|
||||
AddChild(new Folder(this, null, "Root folder"));
|
||||
else
|
||||
AddChild(new Folder(this, null, rootFolder));
|
||||
}
|
||||
}
|
||||
|
||||
internal void Activate(ArtemisSurface surface)
|
||||
{
|
||||
lock (this)
|
||||
|
||||
Reference in new issue
Block a user