Data model conditions - Expanded events UI logic

This commit is contained in:
SpoinkyNL committed 2020-10-25 22:32:38 +01:00
1 parent fbd319beb9
commit e7ce16ba73
15 files changed
+226 -54

No files matched your search

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Storage.Entities.Profile.Abstract;
namespace Artemis.Core
@@ -36,6 +37,8 @@ namespace Artemis.Core
_children.Insert(index.Value, dataModelConditionPart);
else
_children.Add(dataModelConditionPart);
OnChildAdded();
}
}
@@ -49,9 +52,19 @@ namespace Artemis.Core
{
dataModelConditionPart.Parent = null;
_children.Remove(dataModelConditionPart);
OnChildRemoved();
}
}
/// <summary>
/// Removes all children. You monster.
/// </summary>
public void ClearChildren()
{
while (Children.Any())
RemoveChild(Children[0]);
}
/// <summary>
/// Evaluates the condition part on the data model
/// </summary>
@@ -71,7 +84,7 @@ namespace Artemis.Core
#region IDisposable
/// <summary>
/// Disposed the condition part
/// Disposed the condition part
/// </summary>
protected virtual void Dispose(bool disposing)
{
@@ -88,5 +101,22 @@ namespace Artemis.Core
}
#endregion
#region Events
public event EventHandler ChildAdded;
public event EventHandler ChildRemoved;
protected virtual void OnChildAdded()
{
ChildAdded?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnChildRemoved()
{
ChildRemoved?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}
@@ -43,7 +43,7 @@ namespace Artemis.Core
public Type? EventArgumentType { get; set; }
internal DataModelConditionEventEntity Entity { get; set; }
/// <inheritdoc />
public override bool Evaluate()
{
@@ -93,8 +93,7 @@ namespace Artemis.Core
SubscribeToEventPath();
// Remove the old root group that was tied to the old data model
while (Children.Any())
RemoveChild(Children[0]);
ClearChildren();
if (EventPath != null)
{
@@ -164,6 +163,8 @@ namespace Artemis.Core
internal void Initialize()
{
ClearChildren();
if (Entity.EventPath == null)
return;
@@ -45,7 +45,9 @@ namespace Artemis.Core
else if (childEntity is DataModelConditionGeneralPredicateEntity predicateEntity)
AddChild(new DataModelConditionGeneralPredicate(this, predicateEntity));
else if (childEntity is DataModelConditionListPredicateEntity listPredicateEntity)
AddChild(new DataModelConditionListPredicate(this, listPredicateEntity));
AddChild(new DataModelConditionListPredicate(this, listPredicateEntity));
else if (childEntity is DataModelConditionEventPredicateEntity eventPredicateEntity)
AddChild(new DataModelConditionEventPredicate(this, eventPredicateEntity));
}
}
@@ -281,6 +281,13 @@ namespace Artemis.Core
Entity.Path = Path;
Entity.DataModelGuid = DataModelGuid;
Entity.WrapperType = Target switch
{
ListPredicateWrapperDataModel _ => PathWrapperType.List,
EventPredicateWrapperDataModel _ => PathWrapperType.Event,
_ => PathWrapperType.None
};
}
#endregion
+66 -23
View File
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using Artemis.Core.LayerBrushes;
using Artemis.Core.LayerEffects;
@@ -68,27 +67,6 @@ namespace Artemis.Core
Initialize();
}
internal LayerEntity LayerEntity { get; set; }
/// <inheritdoc />
public override List<ILayerProperty> GetAllLayerProperties()
{
List<ILayerProperty> result = new List<ILayerProperty>();
result.AddRange(General.GetAllLayerProperties());
result.AddRange(Transform.GetAllLayerProperties());
if (LayerBrush?.BaseProperties != null)
result.AddRange(LayerBrush.BaseProperties.GetAllLayerProperties());
foreach (BaseLayerEffect layerEffect in LayerEffects)
{
if (layerEffect.BaseProperties != null)
result.AddRange(layerEffect.BaseProperties.GetAllLayerProperties());
}
return result;
}
internal override RenderElementEntity RenderElementEntity => LayerEntity;
/// <summary>
/// A collection of all the LEDs this layer is assigned to.
/// </summary>
@@ -131,6 +109,25 @@ namespace Artemis.Core
internal set => SetAndNotify(ref _layerBrush, value);
}
internal LayerEntity LayerEntity { get; set; }
internal override RenderElementEntity RenderElementEntity => LayerEntity;
/// <inheritdoc />
public override List<ILayerProperty> GetAllLayerProperties()
{
List<ILayerProperty> result = new List<ILayerProperty>();
result.AddRange(General.GetAllLayerProperties());
result.AddRange(Transform.GetAllLayerProperties());
if (LayerBrush?.BaseProperties != null)
result.AddRange(LayerBrush.BaseProperties.GetAllLayerProperties());
foreach (BaseLayerEffect layerEffect in LayerEffects)
if (layerEffect.BaseProperties != null)
result.AddRange(layerEffect.BaseProperties.GetAllLayerProperties());
return result;
}
/// <inheritdoc />
public override string ToString()
{
@@ -309,7 +306,9 @@ namespace Artemis.Core
if (stickToMainSegment)
{
if (!DisplayContinuously)
{
TimelinePosition = StartSegmentLength + timeOverride;
}
else
{
double progress = timeOverride.TotalMilliseconds % MainSegmentLength.TotalMilliseconds;
@@ -320,7 +319,9 @@ namespace Artemis.Core
}
}
else
{
TimelinePosition = timeOverride;
}
double delta = (TimelinePosition - beginTime).TotalSeconds;
@@ -356,7 +357,9 @@ namespace Artemis.Core
return;
if (_layerBitmap == null)
{
_layerBitmap = new SKBitmap(new SKImageInfo((int) Path.Bounds.Width, (int) Path.Bounds.Height));
}
else if (_layerBitmap.Info.Width != (int) Path.Bounds.Width || _layerBitmap.Info.Height != (int) Path.Bounds.Height)
{
_layerBitmap.Dispose();
@@ -388,7 +391,7 @@ namespace Artemis.Core
else if (General.ResizeMode.CurrentValue == LayerResizeMode.Clip)
ClipRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
using SKPaint canvasPaint = new SKPaint { BlendMode = General.BlendMode.CurrentValue };
using SKPaint canvasPaint = new SKPaint {BlendMode = General.BlendMode.CurrentValue};
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PostProcess(layerCanvas, _layerBitmap.Info, layerPath, canvasPaint);
@@ -475,7 +478,9 @@ namespace Artemis.Core
throw new ObjectDisposedException("Layer");
if (!Leds.Any())
{
Path = new SKPath();
}
else
{
SKPath path = new SKPath {FillType = SKPathFillType.Winding};
@@ -548,6 +553,44 @@ namespace Artemis.Core
}
}
/// <summary>
/// Creates a transformation matrix that applies the current transformation settings
/// </summary>
/// <param name="zeroBased">
/// If true, treats the layer as if it is located at 0,0 instead of its actual position on the
/// surface
/// </param>
/// <returns>The transformation matrix containing the current transformation settings</returns>
public SKMatrix GetTransformMatrix(bool zeroBased)
{
if (_disposed)
throw new ObjectDisposedException("Layer");
SKSize sizeProperty = Transform.Scale.CurrentValue;
float rotationProperty = Transform.Rotation.CurrentValue;
SKPoint anchorPosition = GetLayerAnchorPosition(Path, zeroBased);
SKPoint anchorProperty = Transform.AnchorPoint.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
float x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
float y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
if (General.ResizeMode == LayerResizeMode.Normal)
{
SKMatrix transform = SKMatrix.MakeTranslation(x, y);
transform = transform.PostConcat(SKMatrix.MakeRotationDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y));
transform = transform.PostConcat(SKMatrix.MakeScale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y));
return transform;
}
else
{
SKMatrix transform = SKMatrix.MakeTranslation(x, y);
transform = transform.PostConcat(SKMatrix.MakeRotationDegrees(rotationProperty * -1, anchorPosition.X, anchorPosition.Y));
return transform;
}
}
/// <summary>
/// Excludes the provided path from the translations applied to the layer by applying translations that cancel the
/// layer translations out