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

Added layer shapes, editor is still WIP

This commit is contained in:
SpoinkyNL 2019-12-15 22:52:04 +01:00
parent 8ba43ecec1
commit 580db3185e
115 changed files with 1949 additions and 1189 deletions

View File

@ -166,6 +166,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\LayerShapes\Ellipse.cs" />
<Compile Include="Models\Profile\LayerShapes\Fill.cs" />
<Compile Include="Models\Profile\LayerShapes\Polygon.cs" />
<Compile Include="Models\Profile\LayerShapes\Rectangle.cs" />
<Compile Include="Models\Profile\LayerShapes\LayerShape.cs" />
<Compile Include="Models\Surface\ArtemisLed.cs" /> <Compile Include="Models\Surface\ArtemisLed.cs" />
<Compile Include="Models\Surface\ArtemisSurface.cs" /> <Compile Include="Models\Surface\ArtemisSurface.cs" />
<Compile Include="Models\Surface\ArtemisDevice.cs" /> <Compile Include="Models\Surface\ArtemisDevice.cs" />
@ -180,16 +185,16 @@
<Compile Include="Plugins\Abstract\DeviceProvider.cs" /> <Compile Include="Plugins\Abstract\DeviceProvider.cs" />
<Compile Include="Plugins\Abstract\Module.cs" /> <Compile Include="Plugins\Abstract\Module.cs" />
<Compile Include="Plugins\Abstract\Plugin.cs" /> <Compile Include="Plugins\Abstract\Plugin.cs" />
<Compile Include="Plugins\LayerElement\LayerElement.cs" /> <Compile Include="Plugins\LayerBrush\LayerBrush.cs" />
<Compile Include="Plugins\LayerElement\LayerElementDescriptor.cs" /> <Compile Include="Plugins\LayerBrush\LayerBrushDescriptor.cs" />
<Compile Include="Plugins\LayerElement\LayerElementProvider.cs" /> <Compile Include="Plugins\LayerBrush\LayerBrushProvider.cs" />
<Compile Include="Plugins\LayerElement\LayerElementSettings.cs" /> <Compile Include="Plugins\LayerBrush\LayerBrushSettings.cs" />
<Compile Include="Plugins\LayerElement\LayerElementViewModel.cs" /> <Compile Include="Plugins\LayerBrush\LayerBrushViewModel.cs" />
<Compile Include="Plugins\Models\PluginInfo.cs" /> <Compile Include="Plugins\Models\PluginInfo.cs" />
<Compile Include="Plugins\Models\PluginSetting.cs" /> <Compile Include="Plugins\Models\PluginSetting.cs" />
<Compile Include="Plugins\Models\PluginSettings.cs" /> <Compile Include="Plugins\Models\PluginSettings.cs" />
<Compile Include="Models\Profile\Folder.cs" /> <Compile Include="Models\Profile\Folder.cs" />
<Compile Include="Models\Profile\Abstract\ProfileElement.cs" /> <Compile Include="Models\Profile\ProfileElement.cs" />
<Compile Include="Models\Profile\Layer.cs" /> <Compile Include="Models\Profile\Layer.cs" />
<Compile Include="Models\Profile\Profile.cs" /> <Compile Include="Models\Profile\Profile.cs" />
<Compile Include="Ninject\CoreModule.cs" /> <Compile Include="Ninject\CoreModule.cs" />

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Linq; using System.Linq;
using Artemis.Core.Models.Profile.Abstract;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using SkiaSharp; using SkiaSharp;
@ -92,7 +91,7 @@ namespace Artemis.Core.Models.Profile
public override string ToString() public override string ToString()
{ {
return $"Folder - {nameof(Name)}: {Name}, {nameof(Order)}: {Order}"; return $"[Folder] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
} }
} }
} }

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Artemis.Core.Extensions; using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.Abstract; using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.LayerElement; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json; using Newtonsoft.Json;
using SkiaSharp; using SkiaSharp;
@ -14,7 +14,7 @@ namespace Artemis.Core.Models.Profile
{ {
public sealed class Layer : ProfileElement public sealed class Layer : ProfileElement
{ {
private readonly List<LayerElement> _layerElements; private LayerShape _layerShape;
private List<ArtemisLed> _leds; private List<ArtemisLed> _leds;
public Layer(Profile profile, ProfileElement parent, string name) public Layer(Profile profile, ProfileElement parent, string name)
@ -27,7 +27,6 @@ namespace Artemis.Core.Models.Profile
Name = name; Name = name;
_leds = new List<ArtemisLed>(); _leds = new List<ArtemisLed>();
_layerElements = new List<LayerElement>();
} }
internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity) internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity)
@ -40,61 +39,98 @@ namespace Artemis.Core.Models.Profile
Name = layerEntity.Name; Name = layerEntity.Name;
Order = layerEntity.Order; Order = layerEntity.Order;
switch (layerEntity.ShapeEntity?.Type)
{
case ShapeEntityType.Ellipse:
LayerShape = new Ellipse(this, layerEntity.ShapeEntity);
break;
case ShapeEntityType.Fill:
LayerShape = new Fill(this, layerEntity.ShapeEntity);
break;
case ShapeEntityType.Polygon:
LayerShape = new Polygon(this, layerEntity.ShapeEntity);
break;
case ShapeEntityType.Rectangle:
LayerShape = new Rectangle(this, layerEntity.ShapeEntity);
break;
case null:
LayerShape = null;
break;
default:
throw new ArgumentOutOfRangeException();
}
_leds = new List<ArtemisLed>(); _leds = new List<ArtemisLed>();
_layerElements = new List<LayerElement>();
} }
internal LayerEntity LayerEntity { get; set; } internal LayerEntity LayerEntity { get; set; }
/// <summary>
/// A collection of all the LEDs this layer is assigned to.
/// </summary>
public ReadOnlyCollection<ArtemisLed> Leds => _leds.AsReadOnly(); public ReadOnlyCollection<ArtemisLed> Leds => _leds.AsReadOnly();
public ReadOnlyCollection<LayerElement> LayerElements => _layerElements.AsReadOnly();
public SKRect RenderRectangle { get; set; } /// <summary>
public SKRect AbsoluteRenderRectangle { get; set; } /// A rectangle relative to the surface that contains all the LEDs in this layer.
public SKPath RenderPath { get; set; } /// <para>For rendering, use the RenderRectangle on <see cref="LayerShape" />.</para>
/// </summary>
public SKRect Rectangle { get; private set; }
/// <summary>
/// A zero-based absolute rectangle that contains all the LEDs in this layer.
/// <para>For rendering, use the RenderRectangle on <see cref="LayerShape" />.</para>
/// </summary>
public SKRect AbsoluteRectangle { get; private set; }
/// <summary>
/// A path containing all the LEDs this layer is applied to.
/// <para>For rendering, use the RenderPath on <see cref="LayerShape" />.</para>
/// </summary>
public SKPath Path { get; private set; }
/// <summary>
/// Defines the shape that is rendered by the <see cref="LayerBrush"/>.
/// </summary>
public LayerShape LayerShape
{
get => _layerShape;
set
{
_layerShape = value;
_layerShape.CalculateRenderProperties();
}
}
/// <summary>
/// The brush that will fill the <see cref="LayerShape"/>.
/// </summary>
public LayerBrush LayerBrush { get; internal set; }
public override void Update(double deltaTime) public override void Update(double deltaTime)
{ {
lock (_layerElements) LayerBrush?.Update(deltaTime);
{
foreach (var layerElement in LayerElements)
layerElement.Update(deltaTime);
}
} }
public override void Render(double deltaTime, SKCanvas canvas) public override void Render(double deltaTime, SKCanvas canvas)
{ {
if (RenderPath == null) if (Path == null)
return; return;
lock (_layerElements)
{
canvas.Save(); canvas.Save();
using (var framePath = new SKPath(RenderPath)) LayerBrush?.Render(canvas);
{
canvas.ClipPath(framePath);
foreach (var layerElement in LayerElements)
layerElement.RenderPreProcess(framePath, canvas);
foreach (var layerElement in LayerElements)
layerElement.Render(framePath, canvas);
foreach (var layerElement in LayerElements)
layerElement.RenderPostProcess(framePath, canvas);
}
canvas.Restore(); canvas.Restore();
} }
}
internal override void ApplyToEntity() internal override void ApplyToEntity()
{ {
// Properties
LayerEntity.Id = EntityId; LayerEntity.Id = EntityId;
LayerEntity.ParentId = Parent?.EntityId ?? new Guid(); LayerEntity.ParentId = Parent?.EntityId ?? new Guid();
LayerEntity.Order = Order; LayerEntity.Order = Order;
LayerEntity.Name = Name; LayerEntity.Name = Name;
LayerEntity.ProfileId = Profile.EntityId; LayerEntity.ProfileId = Profile.EntityId;
// LEDs
LayerEntity.Leds.Clear(); LayerEntity.Leds.Clear();
foreach (var artemisLed in Leds) foreach (var artemisLed in Leds)
{ {
@ -106,62 +142,60 @@ namespace Artemis.Core.Models.Profile
LayerEntity.Leds.Add(ledEntity); LayerEntity.Leds.Add(ledEntity);
} }
// Conditions TODO
LayerEntity.Condition.Clear(); LayerEntity.Condition.Clear();
LayerEntity.Elements.Clear(); // Brush
foreach (var layerElement in LayerElements) LayerEntity.BrushEntity = new BrushEntity
{ {
var layerElementEntity = new LayerElementEntity BrushPluginGuid = LayerBrush.Descriptor.LayerBrushProvider.PluginInfo.Guid,
{ BrushType = LayerBrush.GetType().Name,
Id = layerElement.Guid, Configuration = JsonConvert.SerializeObject(LayerBrush.Settings)
PluginGuid = layerElement.Descriptor.LayerElementProvider.PluginInfo.Guid,
LayerElementType = layerElement.GetType().Name,
Configuration = JsonConvert.SerializeObject(layerElement.Settings)
}; };
LayerEntity.Elements.Add(layerElementEntity);
} // Shape
LayerShape.ApplyToEntity();
} }
/// <summary>
/// Adds a new <see cref="ArtemisLed" /> to the layer and updates the render properties.
/// </summary>
/// <param name="led">The LED to add</param>
public void AddLed(ArtemisLed led) public void AddLed(ArtemisLed led)
{ {
_leds.Add(led); _leds.Add(led);
CalculateRenderProperties(); CalculateRenderProperties();
} }
/// <summary>
/// Adds a collection of new <see cref="ArtemisLed" />s to the layer and updates the render properties.
/// </summary>
/// <param name="leds">The LEDs to add</param>
public void AddLeds(IEnumerable<ArtemisLed> leds) public void AddLeds(IEnumerable<ArtemisLed> leds)
{ {
_leds.AddRange(leds); _leds.AddRange(leds);
CalculateRenderProperties(); CalculateRenderProperties();
} }
/// <summary>
/// Removes a <see cref="ArtemisLed" /> from the layer and updates the render properties.
/// </summary>
/// <param name="led">The LED to remove</param>
public void RemoveLed(ArtemisLed led) public void RemoveLed(ArtemisLed led)
{ {
_leds.Remove(led); _leds.Remove(led);
CalculateRenderProperties(); CalculateRenderProperties();
} }
/// <summary>
/// Removes all <see cref="ArtemisLed" />s from the layer and updates the render properties.
/// </summary>
public void ClearLeds() public void ClearLeds()
{ {
_leds.Clear(); _leds.Clear();
CalculateRenderProperties(); CalculateRenderProperties();
} }
internal void AddLayerElement(LayerElement layerElement)
{
lock (_layerElements)
{
_layerElements.Add(layerElement);
}
}
internal void RemoveLayerElement(LayerElement layerElement)
{
lock (_layerElements)
{
_layerElements.Remove(layerElement);
}
}
internal void PopulateLeds(ArtemisSurface surface) internal void PopulateLeds(ArtemisSurface surface)
{ {
var leds = new List<ArtemisLed>(); var leds = new List<ArtemisLed>();
@ -191,20 +225,20 @@ namespace Artemis.Core.Models.Profile
var maxX = Leds.Max(l => l.AbsoluteRenderRectangle.Right); var maxX = Leds.Max(l => l.AbsoluteRenderRectangle.Right);
var maxY = Leds.Max(l => l.AbsoluteRenderRectangle.Bottom); var maxY = Leds.Max(l => l.AbsoluteRenderRectangle.Bottom);
RenderRectangle = SKRect.Create(minX, minY, maxX - minX, maxY - minY); Rectangle = SKRect.Create(minX, minY, maxX - minX, maxY - minY);
AbsoluteRenderRectangle = SKRect.Create(0, 0, maxX - minX, maxY - minY); AbsoluteRectangle = SKRect.Create(0, 0, maxX - minX, maxY - minY);
var path = new SKPath {FillType = SKPathFillType.Winding}; var path = new SKPath {FillType = SKPathFillType.Winding};
foreach (var artemisLed in Leds) foreach (var artemisLed in Leds)
path.AddRect(artemisLed.AbsoluteRenderRectangle); path.AddRect(artemisLed.AbsoluteRenderRectangle);
RenderPath = path; Path = path;
OnRenderPropertiesUpdated(); OnRenderPropertiesUpdated();
} }
public override string ToString() public override string ToString()
{ {
return $"Layer - {nameof(Name)}: {Name}, {nameof(Order)}: {Order}"; return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
} }
#region Events #region Events

View File

@ -0,0 +1,35 @@
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public class Ellipse : LayerShape
{
public Ellipse(Layer layer) : base(layer)
{
}
internal Ellipse(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
{
}
public override void CalculateRenderProperties()
{
var width = Layer.AbsoluteRectangle.Width;
var height = Layer.AbsoluteRectangle.Height;
var rect = SKRect.Create(Position.X * width, Position.Y * height, Size.Width * width, Size.Height * height);
var path = new SKPath();
path.AddOval(rect);
RenderPath = path;
RenderRectangle = path.GetRect();
}
public override void ApplyToEntity()
{
base.ApplyToEntity();
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Ellipse;
}
}
}

View File

@ -0,0 +1,26 @@
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public class Fill : LayerShape
{
public Fill(Layer layer) : base(layer)
{
}
internal Fill(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
{
}
public override void CalculateRenderProperties()
{
RenderPath = Layer.Path;
RenderRectangle = Layer.Path.GetRect();
}
public override void ApplyToEntity()
{
base.ApplyToEntity();
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Fill;
}
}
}

View File

@ -0,0 +1,74 @@
using System;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public abstract class LayerShape
{
protected LayerShape(Layer layer)
{
Layer = layer;
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
}
protected LayerShape(Layer layer, ShapeEntity shapeEntity)
{
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);
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
}
private void LayerOnRenderPropertiesUpdated(object sender, EventArgs e)
{
CalculateRenderProperties();
}
/// <summary>
/// The layer this shape is attached to
/// </summary>
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; set; }
/// <summary>
/// The size of the shape
/// </summary>
public SKSize Size { get; set; }
/// <summary>
/// A render rectangle relative to the layer
/// </summary>
public SKRect RenderRectangle { get; protected set; }
/// <summary>
/// A path relative to the layer
/// </summary>
public SKPath RenderPath { get; protected set; }
public abstract void CalculateRenderProperties();
public virtual void ApplyToEntity()
{
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
};
}
}
}

View File

@ -0,0 +1,45 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public class Polygon : LayerShape
{
public Polygon(Layer layer) : base(layer)
{
}
internal Polygon(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
{
}
/// <summary>
/// The points of this polygon
/// </summary>
public List<SKPoint> Points { get; set; }
/// <summary>
/// The points of this polygon where they need to be rendered inside the layer
/// </summary>
public List<SKPoint> RenderPoints => Points.Select(p => new SKPoint(p.X * Layer.AbsoluteRectangle.Width, p.Y * Layer.AbsoluteRectangle.Height)).ToList();
public override void CalculateRenderProperties()
{
var path = new SKPath();
path.AddPoly(RenderPoints.ToArray());
RenderPath = path;
RenderRectangle = path.GetRect();
}
public override void ApplyToEntity()
{
base.ApplyToEntity();
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Polygon;
Layer.LayerEntity.ShapeEntity.Points = Points.Select(p => new ShapePointEntity { X = p.X, Y = p.Y }).ToList();
}
}
}

View File

@ -0,0 +1,34 @@
using Artemis.Storage.Entities.Profile;
using SkiaSharp;
namespace Artemis.Core.Models.Profile.LayerShapes
{
public class Rectangle : LayerShape
{
public Rectangle(Layer layer) : base(layer)
{
}
internal Rectangle(Layer layer, ShapeEntity shapeEntity) : base(layer, shapeEntity)
{
}
public override void CalculateRenderProperties()
{
var width = Layer.AbsoluteRectangle.Width;
var height = Layer.AbsoluteRectangle.Height;
var rect = SKRect.Create(Position.X * width, Position.Y * height, Size.Width * width, Size.Height * height);
var path = new SKPath();
path.AddRect(rect);
RenderPath = path;
RenderRectangle = path.GetRect();
}
public override void ApplyToEntity()
{
base.ApplyToEntity();
Layer.LayerEntity.ShapeEntity.Type = ShapeEntityType.Rectangle;
}
}
}

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using Artemis.Core.Exceptions; using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.Abstract;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Storage.Entities.Profile; using Artemis.Storage.Entities.Profile;
@ -109,17 +108,17 @@ namespace Artemis.Core.Models.Profile
} }
} }
public override string ToString()
{
return $"{nameof(Order)}: {Order}, {nameof(Name)}: {Name}, {nameof(PluginInfo)}: {PluginInfo}";
}
internal void PopulateLeds(ArtemisSurface surface) internal void PopulateLeds(ArtemisSurface surface)
{ {
foreach (var layer in GetAllLayers()) foreach (var layer in GetAllLayers())
layer.PopulateLeds(surface); layer.PopulateLeds(surface);
} }
public override string ToString()
{
return $"[Profile] {nameof(Name)}: {Name}, {nameof(IsActivated)}: {IsActivated}, {nameof(PluginInfo)}: {PluginInfo}";
}
#region Events #region Events
/// <summary> /// <summary>

View File

@ -2,11 +2,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Artemis.Core.Models.Surface;
using SkiaSharp; using SkiaSharp;
using Stylet; using Stylet;
namespace Artemis.Core.Models.Profile.Abstract namespace Artemis.Core.Models.Profile
{ {
public abstract class ProfileElement : PropertyChangedBase public abstract class ProfileElement : PropertyChangedBase
{ {
@ -132,5 +131,7 @@ namespace Artemis.Core.Models.Profile.Abstract
child.Parent = null; child.Parent = null;
} }
} }
} }
} }

View File

@ -0,0 +1,48 @@
using System;
using Artemis.Core.Models.Profile;
using SkiaSharp;
namespace Artemis.Core.Plugins.LayerBrush
{
public abstract class LayerBrush : IDisposable
{
protected LayerBrush(Layer layer, LayerBrushSettings settings, LayerBrushDescriptor descriptor)
{
Layer = layer;
Settings = settings;
Descriptor = descriptor;
}
public Layer Layer { get; }
public LayerBrushSettings Settings { get; }
public LayerBrushDescriptor Descriptor { get; }
public virtual void Dispose()
{
}
/// <summary>
/// Called by the profile editor to populate the brush properties panel
/// </summary>
/// <returns></returns>
public abstract LayerBrushViewModel GetViewModel();
/// <summary>
/// Called before rendering every frame, write your update logic here
/// </summary>
/// <param name="deltaTime"></param>
public virtual void Update(double deltaTime)
{
}
/// <summary>
/// The main method of rendering anything to the layer. The provided <see cref="SKCanvas" /> is specific to the layer
/// and matches it's width and height.
/// <para>Called during rendering, in the order configured on the layer</para>
/// </summary>
/// <param name="canvas">The layer canvas</param>
public virtual void Render(SKCanvas canvas)
{
}
}
}

View File

@ -0,0 +1,22 @@
using System;
namespace Artemis.Core.Plugins.LayerBrush
{
public class LayerBrushDescriptor
{
internal LayerBrushDescriptor(string displayName, string description, string icon, Type layerBrushType, LayerBrushProvider layerBrushProvider)
{
DisplayName = displayName;
Description = description;
Icon = icon;
LayerBrushType = layerBrushType;
LayerBrushProvider = layerBrushProvider;
}
public string DisplayName { get; }
public string Description { get; }
public string Icon { get; }
public Type LayerBrushType { get; }
public LayerBrushProvider LayerBrushProvider { get; }
}
}

View File

@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
namespace Artemis.Core.Plugins.LayerBrush
{
/// <inheritdoc />
/// <summary>
/// Allows you to create one or more <see cref="LayerBrush" />s usable by profile layers.
/// </summary>
public abstract class LayerBrushProvider : Plugin
{
private readonly List<LayerBrushDescriptor> _layerBrushDescriptors;
protected LayerBrushProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
_layerBrushDescriptors = new List<LayerBrushDescriptor>();
}
public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly();
protected void AddLayerBrushDescriptor<T>(string displayName, string description, string icon) where T : LayerBrush
{
_layerBrushDescriptors.Add(new LayerBrushDescriptor(displayName, description, icon, typeof(T), this));
}
}
}

View File

@ -1,9 +1,9 @@
using System; using System;
using Stylet; using Stylet;
namespace Artemis.Core.Plugins.LayerElement namespace Artemis.Core.Plugins.LayerBrush
{ {
public abstract class LayerElementSettings : PropertyChangedBase public abstract class LayerBrushSettings : PropertyChangedBase
{ {
private Action<Action> _propertyChangedDispatcher = Execute.DefaultPropertyChangedDispatcher; private Action<Action> _propertyChangedDispatcher = Execute.DefaultPropertyChangedDispatcher;

View File

@ -0,0 +1,14 @@
using Stylet;
namespace Artemis.Core.Plugins.LayerBrush
{
public abstract class LayerBrushViewModel : PropertyChangedBase
{
protected LayerBrushViewModel(LayerBrush brush)
{
Brush = brush;
}
public LayerBrush Brush { get; }
}
}

View File

@ -1,75 +0,0 @@
using System;
using Artemis.Core.Models.Profile;
using SkiaSharp;
namespace Artemis.Core.Plugins.LayerElement
{
public abstract class LayerElement : IDisposable
{
protected LayerElement(Layer layer, Guid guid, LayerElementSettings settings, LayerElementDescriptor descriptor)
{
Layer = layer;
Guid = guid;
Settings = settings;
Descriptor = descriptor;
}
public Layer Layer { get; }
public Guid Guid { get; }
public LayerElementSettings Settings { get; }
public LayerElementDescriptor Descriptor { get; }
public virtual void Dispose()
{
}
/// <summary>
/// Called by the profile editor to populate the layer element properties panel
/// </summary>
/// <returns></returns>
public abstract LayerElementViewModel GetViewModel();
/// <summary>
/// Called before rendering every frame, write your update logic here
/// </summary>
/// <param name="deltaTime"></param>
public virtual void Update(double deltaTime)
{
}
/// <summary>
/// Allows you to perform rendering on the surface <see cref="SKCanvas" /> before any layer-clipping is applied
/// <para>Called before rendering, in the order configured on the layer</para>
/// </summary>
/// <param name="framePath"></param>
/// <param name="canvas">The entire surface canvas</param>
public virtual void RenderPreProcess(SKPath framePath, SKCanvas canvas)
{
}
/// <summary>
/// The main method of rendering anything to the layer. The provided <see cref="SKCanvas" /> is specific to the layer
/// and matches it's width and height.
/// <para>Called during rendering, in the order configured on the layer</para>
/// </summary>
/// <param name="framePath"></param>
/// <param name="canvas">The layer canvas</param>
public virtual void Render(SKPath framePath, SKCanvas canvas)
{
}
/// <summary>
/// Allows you to modify the <see cref="SKShader" /> used to draw the layer's <see cref="SKBitmap" /> on the
/// <see cref="SKCanvas" />.
/// <para>Called after rendering, in the order configured on the layer.</para>
/// </summary>
/// <param name="framePath"></param>
/// <param name="canvas"></param>
/// <param name="bitmap">The bitmap created from the layer canvas</param>
/// <param name="shader">The current shader used to draw the bitmap on the surface canvas</param>
/// <returns>The resulting shader used to draw the bitmap on the surface canvas</returns>
public virtual void RenderPostProcess(SKPath framePath, SKCanvas canvas)
{
}
}
}

View File

@ -1,22 +0,0 @@
using System;
namespace Artemis.Core.Plugins.LayerElement
{
public class LayerElementDescriptor
{
internal LayerElementDescriptor(string displayName, string description, string icon, Type layerElementType, LayerElementProvider layerElementProvider)
{
DisplayName = displayName;
Description = description;
Icon = icon;
LayerElementType = layerElementType;
LayerElementProvider = layerElementProvider;
}
public string DisplayName { get; }
public string Description { get; }
public string Icon { get; }
public Type LayerElementType { get; }
public LayerElementProvider LayerElementProvider { get; }
}
}

View File

@ -1,28 +0,0 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
namespace Artemis.Core.Plugins.LayerElement
{
/// <inheritdoc />
/// <summary>
/// Allows you to create one or more <see cref="LayerElement" />s usable by profile layers.
/// </summary>
public abstract class LayerElementProvider : Plugin
{
private readonly List<LayerElementDescriptor> _layerElementDescriptors;
protected LayerElementProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
_layerElementDescriptors = new List<LayerElementDescriptor>();
}
public ReadOnlyCollection<LayerElementDescriptor> LayerElementDescriptors => _layerElementDescriptors.AsReadOnly();
protected void AddLayerElementDescriptor<T>(string displayName, string description, string icon) where T : LayerElement
{
_layerElementDescriptors.Add(new LayerElementDescriptor(displayName, description, icon, typeof(T), this));
}
}
}

View File

@ -1,14 +0,0 @@
using Stylet;
namespace Artemis.Core.Plugins.LayerElement
{
public abstract class LayerElementViewModel : PropertyChangedBase
{
protected LayerElementViewModel(LayerElement layerElement)
{
LayerElement = layerElement;
}
public LayerElement LayerElement { get; }
}
}

View File

@ -1,21 +1,18 @@
using System; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerElement;
namespace Artemis.Core.Services.Interfaces namespace Artemis.Core.Services.Interfaces
{ {
public interface ILayerService : IArtemisService public interface ILayerService : IArtemisService
{ {
/// <summary> /// <summary>
/// Instantiates and adds the <see cref="LayerElement" /> described by the provided /// Instantiates and adds the <see cref="LayerBrush" /> described by the provided
/// <see cref="LayerElementDescriptor" /> to the provided <see cref="Layer" />. /// <see cref="LayerBrushDescriptor" /> to the provided <see cref="Layer" />.
/// </summary> /// </summary>
/// <param name="layer">The layer to add the new layer element to</param> /// <param name="layer">The layer to add the new layer element to</param>
/// <param name="layerElementDescriptor">The descriptor of the new layer element</param> /// <param name="brushDescriptor">The descriptor of the new layer brush</param>
/// <param name="settings">JSON settings to be deserialized and injected into the layer element</param> /// <param name="settings">JSON settings to be deserialized and injected into the layer brush</param>
/// <returns></returns> /// <returns></returns>
LayerElement InstantiateLayerElement(Layer layer, LayerElementDescriptor layerElementDescriptor, string settings = null, Guid? guid = null); LayerBrush InstantiateLayerBrush(Layer layer, LayerBrushDescriptor brushDescriptor, string settings = null);
void RemoveLayerElement(Layer layer, LayerElement layerElement);
} }
} }

View File

@ -3,7 +3,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Exceptions; using Artemis.Core.Plugins.Exceptions;
using Artemis.Core.Plugins.LayerElement; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ninject; using Ninject;
@ -23,16 +23,13 @@ namespace Artemis.Core.Services
_logger = logger; _logger = logger;
} }
public LayerElement InstantiateLayerElement(Layer layer, LayerElementDescriptor layerElementDescriptor, string settings, Guid? guid) public LayerBrush InstantiateLayerBrush(Layer layer, LayerBrushDescriptor brushDescriptor, string settings)
{ {
if (guid == null)
guid = Guid.NewGuid();
// Determine the settings type declared by the layer element // Determine the settings type declared by the layer element
object settingsInstance = null; object settingsInstance = null;
var properties = layerElementDescriptor.LayerElementType.GetProperties(); var properties = brushDescriptor.LayerBrushType.GetProperties();
var settingsType = properties.FirstOrDefault(p => p.Name == "Settings" && var settingsType = properties.FirstOrDefault(p => p.Name == "Settings" &&
p.DeclaringType == layerElementDescriptor.LayerElementType)?.PropertyType; p.DeclaringType == brushDescriptor.LayerBrushType)?.PropertyType;
// Deserialize the settings if provided, check for null in JSON as well // Deserialize the settings if provided, check for null in JSON as well
if (settings != null && settings != "null") if (settings != null && settings != "null")
@ -41,8 +38,8 @@ namespace Artemis.Core.Services
if (settingsType == null) if (settingsType == null)
{ {
throw new ArtemisPluginException( throw new ArtemisPluginException(
layerElementDescriptor.LayerElementProvider.PluginInfo, brushDescriptor.LayerBrushProvider.PluginInfo,
$"Settings where provided but layer element of type {layerElementDescriptor.LayerElementType.Name} has no Settings property." $"Settings where provided but layer element of type {brushDescriptor.LayerBrushType.Name} has no Settings property."
); );
} }
@ -53,8 +50,8 @@ namespace Artemis.Core.Services
catch (JsonSerializationException e) catch (JsonSerializationException e)
{ {
_logger.Warning(e, "Failed to deserialize settings for layer type {type}, resetting element settings - Plugin info: {pluginInfo}", _logger.Warning(e, "Failed to deserialize settings for layer type {type}, resetting element settings - Plugin info: {pluginInfo}",
layerElementDescriptor.LayerElementType.Name, brushDescriptor.LayerBrushType.Name,
layerElementDescriptor.LayerElementProvider.PluginInfo); brushDescriptor.LayerBrushProvider.PluginInfo);
settingsInstance = Activator.CreateInstance(settingsType); settingsInstance = Activator.CreateInstance(settingsType);
} }
@ -68,20 +65,20 @@ namespace Artemis.Core.Services
var arguments = new IParameter[] var arguments = new IParameter[]
{ {
new ConstructorArgument("layer", layer), new ConstructorArgument("layer", layer),
new ConstructorArgument("guid", guid.Value),
new ConstructorArgument("settings", settingsInstance), new ConstructorArgument("settings", settingsInstance),
new ConstructorArgument("descriptor", layerElementDescriptor) new ConstructorArgument("descriptor", brushDescriptor)
}; };
var layerElement = (LayerElement) _kernel.Get(layerElementDescriptor.LayerElementType, arguments); var layerElement = (LayerBrush) _kernel.Get(brushDescriptor.LayerBrushType, arguments);
layer.AddLayerElement(layerElement); layer.LayerBrush = (layerElement);
return layerElement; return layerElement;
} }
public void RemoveLayerElement(Layer layer, LayerElement layerElement) public void RemoveLayerBrush(Layer layer, LayerBrush layerElement)
{ {
layer.RemoveLayerElement(layerElement); var brush = layer.LayerBrush;
layerElement.Dispose(); layer.LayerBrush = null;
brush.Dispose();
} }
} }
} }

View File

@ -4,7 +4,7 @@ using Artemis.Core.Events;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.LayerElement; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces; using Artemis.Core.Services.Storage.Interfaces;
using Artemis.Storage.Repositories.Interfaces; using Artemis.Storage.Repositories.Interfaces;
@ -16,10 +16,10 @@ namespace Artemis.Core.Services.Storage
/// </summary> /// </summary>
public class ProfileService : IProfileService public class ProfileService : IProfileService
{ {
private readonly ILayerService _layerService;
private readonly IPluginService _pluginService; private readonly IPluginService _pluginService;
private readonly IProfileRepository _profileRepository; private readonly IProfileRepository _profileRepository;
private readonly ISurfaceService _surfaceService; private readonly ISurfaceService _surfaceService;
private readonly ILayerService _layerService;
internal ProfileService(IPluginService pluginService, ISurfaceService surfaceService, ILayerService layerService, IProfileRepository profileRepository) internal ProfileService(IPluginService pluginService, ISurfaceService surfaceService, ILayerService layerService, IProfileRepository profileRepository)
{ {
@ -78,7 +78,7 @@ namespace Artemis.Core.Services.Storage
{ {
module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface); module.ChangeActiveProfile(profile, _surfaceService.ActiveSurface);
if (profile != null) if (profile != null)
InstantiateProfileLayerElements(profile); InstantiateProfileLayerBrushes(profile);
} }
public void DeleteProfile(Profile profile) public void DeleteProfile(Profile profile)
@ -102,27 +102,22 @@ namespace Artemis.Core.Services.Storage
_profileRepository.Save(profile.ProfileEntity); _profileRepository.Save(profile.ProfileEntity);
} }
private void InstantiateProfileLayerElements(Profile profile)
{
var layerElementProviders = _pluginService.GetPluginsOfType<LayerElementProvider>();
var descriptors = layerElementProviders.SelectMany(l => l.LayerElementDescriptors).ToList();
foreach (var layer in profile.GetAllLayers()) private void InstantiateProfileLayerBrushes(Profile profile)
{ {
foreach (var elementEntity in layer.LayerEntity.Elements) var layerBrushProviders = _pluginService.GetPluginsOfType<LayerBrushProvider>();
{ var descriptors = layerBrushProviders.SelectMany(l => l.LayerBrushDescriptors).ToList();
// Skip already instantiated layer elements
if (layer.LayerElements.Any(e => e.Guid == elementEntity.Id))
continue;
// Only instantiate brushes for layers without an existing brush instance
foreach (var layer in profile.GetAllLayers().Where(l => l.LayerBrush == null && l.LayerEntity.BrushEntity != null))
{
// Get a matching descriptor // Get a matching descriptor
var descriptor = descriptors.FirstOrDefault(d => d.LayerElementProvider.PluginInfo.Guid == elementEntity.PluginGuid && var descriptor = descriptors.FirstOrDefault(d => d.LayerBrushProvider.PluginInfo.Guid == layer.LayerEntity.BrushEntity.BrushPluginGuid &&
d.LayerElementType.Name == elementEntity.LayerElementType); d.LayerBrushType.Name == layer.LayerEntity.BrushEntity.BrushType);
// If a descriptor that matches if found, instantiate it with the GUID of the element entity // If a descriptor that matches if found, instantiate it with the GUID of the element entity
if (descriptor != null) if (descriptor != null)
_layerService.InstantiateLayerElement(layer, descriptor, elementEntity.Configuration, elementEntity.Id); _layerService.InstantiateLayerBrush(layer, descriptor, layer.LayerEntity.BrushEntity.Configuration);
}
} }
} }
@ -133,11 +128,11 @@ namespace Artemis.Core.Services.Storage
profileModule.ActiveProfile.PopulateLeds(surface); profileModule.ActiveProfile.PopulateLeds(surface);
} }
private void ActiveProfilesInstantiateProfileLayerElements() private void ActiveProfilesInstantiateProfileLayerBrushes()
{ {
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>(); var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList()) foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
InstantiateProfileLayerElements(profileModule.ActiveProfile); InstantiateProfileLayerBrushes(profileModule.ActiveProfile);
} }
#region Event handlers #region Event handlers
@ -155,8 +150,8 @@ namespace Artemis.Core.Services.Storage
private void OnPluginLoaded(object sender, PluginEventArgs e) private void OnPluginLoaded(object sender, PluginEventArgs e)
{ {
if (e.PluginInfo.Instance is LayerElementProvider) if (e.PluginInfo.Instance is LayerBrushProvider)
ActiveProfilesInstantiateProfileLayerElements(); ActiveProfilesInstantiateProfileLayerBrushes();
} }
#endregion #endregion

View File

@ -3,9 +3,9 @@ using Artemis.Core.Plugins.Models;
namespace Artemis.Plugins.LayerElements.Animations namespace Artemis.Plugins.LayerElements.Animations
{ {
public class AnimationLayerElementProvider : LayerElementProvider public class AnimationBrushProvider : BrushProvider
{ {
public AnimationLayerElementProvider(PluginInfo pluginInfo) : base(pluginInfo) public AnimationBrushProvider(PluginInfo pluginInfo) : base(pluginInfo)
{ {
AddLayerElementDescriptor<SlideLayerElement>("Slide animation", "A sliding animation", "ArrowAll"); AddLayerElementDescriptor<SlideLayerElement>("Slide animation", "A sliding animation", "ArrowAll");
AddLayerElementDescriptor<RotationLayerElement>("Rotation animation", "A rotation animation", "CropRotate"); AddLayerElementDescriptor<RotationLayerElement>("Rotation animation", "A rotation animation", "CropRotate");

View File

@ -59,7 +59,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AnimationLayerElementProvider.cs" /> <Compile Include="AnimationBrushProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RotationLayerElement.cs" /> <Compile Include="RotationLayerElement.cs" />
<Compile Include="SlideLayerElement.cs" /> <Compile Include="SlideLayerElement.cs" />

View File

@ -7,13 +7,13 @@ namespace Artemis.Plugins.LayerElements.Animations
{ {
public class RotationLayerElement : LayerElement public class RotationLayerElement : LayerElement
{ {
public RotationLayerElement(Layer layer, Guid guid, LayerElementSettings settings, LayerElementDescriptor descriptor) : base(layer, guid, settings, descriptor) public RotationLayerElement(Layer layer, Guid guid, BrushSettings settings, BrushDescriptor descriptor) : base(layer, guid, settings, descriptor)
{ {
} }
public float Rotation { get; set; } public float Rotation { get; set; }
public override LayerElementViewModel GetViewModel() public override BrushViewModel GetViewModel()
{ {
return null; return null;
} }

View File

@ -7,13 +7,13 @@ namespace Artemis.Plugins.LayerElements.Animations
{ {
public class SlideLayerElement : LayerElement public class SlideLayerElement : LayerElement
{ {
public SlideLayerElement(Layer layer, Guid guid, LayerElementSettings settings, LayerElementDescriptor descriptor) : base(layer, guid, settings, descriptor) public SlideLayerElement(Layer layer, Guid guid, BrushSettings settings, BrushDescriptor descriptor) : base(layer, guid, settings, descriptor)
{ {
} }
public int MovePercentage { get; set; } public int MovePercentage { get; set; }
public override LayerElementViewModel GetViewModel() public override BrushViewModel GetViewModel()
{ {
return null; return null;
} }

View File

@ -7,8 +7,8 @@
<ProjectGuid>{7F4C7AB0-4C9B-452D-AFED-34544C903DEF}</ProjectGuid> <ProjectGuid>{7F4C7AB0-4C9B-452D-AFED-34544C903DEF}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Artemis.Plugins.LayerElements.Noise</RootNamespace> <RootNamespace>Artemis.Plugins.LayerBrushes.Noise</RootNamespace>
<AssemblyName>Artemis.Plugins.LayerElements.Noise</AssemblyName> <AssemblyName>Artemis.Plugins.LayerBrushes.Noise</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
@ -87,11 +87,11 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="NoiseLayerElementSettings.cs" /> <Compile Include="NoiseBrushSettings.cs" />
<Compile Include="NoiseLayerElementViewModel.cs" /> <Compile Include="NoiseBrushViewModel.cs" />
<Compile Include="NoiseLayerElement.cs" /> <Compile Include="NoiseBrush.cs" />
<Compile Include="NoiseLayerElementProvider.cs" /> <Compile Include="NoiseBrushProvider.cs" />
<Compile Include="OpenSimplexNoise.cs" /> <Compile Include="Utilities\OpenSimplexNoise.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -113,7 +113,7 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="NoiseLayerElementView.xaml"> <Page Include="NoiseBrushView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>

View File

@ -1,26 +1,27 @@
using System; using System;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerElement; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Plugins.LayerBrushes.Noise.Utilities;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Plugins.LayerElements.Noise namespace Artemis.Plugins.LayerBrushes.Noise
{ {
public class NoiseLayerElement : LayerElement public class NoiseBrush : LayerBrush
{ {
private const int Scale = 6; private const int Scale = 6;
private static readonly Random Rand = new Random(); private static readonly Random Rand = new Random();
private readonly OpenSimplexNoise _noise; private readonly OpenSimplexNoise _noise;
private float _z; private float _z;
public NoiseLayerElement(Layer layer, Guid guid, NoiseLayerElementSettings settings, LayerElementDescriptor descriptor) : base(layer, guid, settings, descriptor) public NoiseBrush(Layer layer, NoiseBrushSettings settings, LayerBrushDescriptor descriptor) : base(layer, settings, descriptor)
{ {
Settings = settings; Settings = settings;
_z = Rand.Next(0, 4096); _z = Rand.Next(0, 4096);
_noise = new OpenSimplexNoise(Guid.GetHashCode()); _noise = new OpenSimplexNoise(Rand.Next(0, 4096));
} }
public new NoiseLayerElementSettings Settings { get; } public new NoiseBrushSettings Settings { get; }
public override void Update(double deltaTime) public override void Update(double deltaTime)
@ -34,16 +35,16 @@ namespace Artemis.Plugins.LayerElements.Noise
base.Update(deltaTime); base.Update(deltaTime);
} }
public override LayerElementViewModel GetViewModel() public override LayerBrushViewModel GetViewModel()
{ {
return new NoiseLayerElementViewModel(this); return new NoiseBrushViewModel(this);
} }
public override void Render(SKPath framePath, SKCanvas canvas) public override void Render(SKCanvas canvas)
{ {
// Scale down the render path to avoid computing a value for every pixel // Scale down the render path to avoid computing a value for every pixel
var width = (int) (Math.Max(Layer.RenderRectangle.Width, Layer.RenderRectangle.Height) / Scale); var width = (int) (Math.Max(Layer.Rectangle.Width, Layer.Rectangle.Height) / Scale);
var height = (int) (Math.Max(Layer.RenderRectangle.Width, Layer.RenderRectangle.Height) / Scale); var height = (int) (Math.Max(Layer.Rectangle.Width, Layer.Rectangle.Height) / Scale);
var opacity = (float) Math.Round(Settings.Color.Alpha / 255.0, 2, MidpointRounding.AwayFromZero); var opacity = (float) Math.Round(Settings.Color.Alpha / 255.0, 2, MidpointRounding.AwayFromZero);
using (var bitmap = new SKBitmap(new SKImageInfo(width, height))) using (var bitmap = new SKBitmap(new SKImageInfo(width, height)))
{ {
@ -76,7 +77,7 @@ namespace Artemis.Plugins.LayerElements.Noise
using (var sh = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror, SKMatrix.MakeScale(Scale, Scale))) using (var sh = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror, SKMatrix.MakeScale(Scale, Scale)))
using (var paint = new SKPaint {Shader = sh, BlendMode = Settings.BlendMode}) using (var paint = new SKPaint {Shader = sh, BlendMode = Settings.BlendMode})
{ {
canvas.DrawPath(framePath, paint); canvas.DrawPath(Layer.LayerShape.RenderPath, paint);
} }
} }
} }

View File

@ -0,0 +1,26 @@

using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.Models;
namespace Artemis.Plugins.LayerBrushes.Noise
{
public class NoiseBrushProvider : LayerBrushProvider
{
public NoiseBrushProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
AddLayerBrushDescriptor<NoiseBrush>("Noise", "A brush of that shows an animated random noise", "ScatterPlot");
}
public override void EnablePlugin()
{
}
public override void DisablePlugin()
{
}
public override void Dispose()
{
}
}
}

View File

@ -1,9 +1,9 @@
using Artemis.Core.Plugins.LayerElement; using Artemis.Core.Plugins.LayerBrush;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Plugins.LayerElements.Noise namespace Artemis.Plugins.LayerBrushes.Noise
{ {
public class NoiseLayerElementSettings : LayerElementSettings public class NoiseBrushSettings : LayerBrushSettings
{ {
private float _animationSpeed; private float _animationSpeed;
private SKBlendMode _blendMode; private SKBlendMode _blendMode;
@ -11,7 +11,7 @@ namespace Artemis.Plugins.LayerElements.Noise
private float _xScale; private float _xScale;
private float _yScale; private float _yScale;
public NoiseLayerElementSettings() public NoiseBrushSettings()
{ {
// Color = new SKColor(0, 0, 0); // Color = new SKColor(0, 0, 0);
// BlendMode = SKBlendMode.Color; // BlendMode = SKBlendMode.Color;

View File

@ -1,14 +1,14 @@
<UserControl x:Class="Artemis.Plugins.LayerElements.Noise.NoiseLayerElementView" <UserControl x:Class="Artemis.Plugins.LayerBrushes.Noise.NoiseBrushView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:noiseLayer="clr-namespace:Artemis.Plugins.LayerElements.Noise"
xmlns:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared" xmlns:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared" xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
xmlns:noiseBrush="clr-namespace:Artemis.Plugins.LayerBrushes.Noise"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type noiseLayer:NoiseLayerElementViewModel}}"> d:DataContext="{d:DesignInstance {x:Type noiseBrush:NoiseBrushViewModel}}">
<UserControl.Resources> <UserControl.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
@ -41,7 +41,7 @@
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Text="Noise color" /> <TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Text="Noise color" />
</StackPanel> </StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<artemis:ColorPicker Color="{Binding LayerElement.Settings.Color, Converter={StaticResource SKColorToColorConverter}}" Width="100" /> <artemis:ColorPicker Color="{Binding Brush.Settings.Color, Converter={StaticResource SKColorToColorConverter}}" Width="100" />
</StackPanel> </StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid> </Grid>
@ -69,7 +69,7 @@
SelectedValuePath="Value" SelectedValuePath="Value"
DisplayMemberPath="Description" DisplayMemberPath="Description"
Width="100" Width="100"
SelectedValue="{Binding LayerElement.Settings.BlendMode}" /> SelectedValue="{Binding Brush.Settings.BlendMode}" />
</StackPanel> </StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid> </Grid>
@ -89,7 +89,7 @@
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Slider Orientation="Horizontal" TickFrequency="0.5" Minimum="0.5" Maximum="40" Value="{Binding LayerElement.Settings.XScale}" Width="100" /> <Slider Orientation="Horizontal" TickFrequency="0.5" Minimum="0.5" Maximum="40" Value="{Binding Brush.Settings.XScale}" Width="100" />
</StackPanel> </StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid> </Grid>
@ -110,7 +110,7 @@
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Slider Orientation="Horizontal" TickFrequency="0.5" Minimum="0.5" Maximum="40" Value="{Binding LayerElement.Settings.YScale}" Width="100" /> <Slider Orientation="Horizontal" TickFrequency="0.5" Minimum="0.5" Maximum="40" Value="{Binding Brush.Settings.YScale}" Width="100" />
</StackPanel> </StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid> </Grid>
@ -132,7 +132,7 @@
</StackPanel> </StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"> <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Slider Orientation="Horizontal" TickFrequency="1" Minimum="1" Maximum="100" Value="{Binding LayerElement.Settings.AnimationSpeed}" Width="100" /> <Slider Orientation="Horizontal" TickFrequency="1" Minimum="1" Maximum="100" Value="{Binding Brush.Settings.AnimationSpeed}" Width="100" />
</StackPanel> </StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid> </Grid>

View File

@ -0,0 +1,18 @@
using System.Collections.Generic;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Utilities;
using SkiaSharp;
namespace Artemis.Plugins.LayerBrushes.Noise
{
public class NoiseBrushViewModel : LayerBrushViewModel
{
public NoiseBrushViewModel(NoiseBrush brush) : base(brush)
{
Brush = brush;
}
public new NoiseBrush Brush { get; }
public IEnumerable<ValueDescription> BlendModes => EnumUtilities.GetAllValuesAndDescriptions(typeof(SKBlendMode));
}
}

View File

@ -1,25 +0,0 @@
using Artemis.Core.Plugins.LayerElement;
using Artemis.Core.Plugins.Models;
namespace Artemis.Plugins.LayerElements.Noise
{
public class NoiseLayerElementProvider : LayerElementProvider
{
public NoiseLayerElementProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
AddLayerElementDescriptor<NoiseLayerElement>("Noise", "A brush of that shows an animated random noise", "ScatterPlot");
}
public override void EnablePlugin()
{
}
public override void DisablePlugin()
{
}
public override void Dispose()
{
}
}
}

View File

@ -1,18 +0,0 @@
using System.Collections.Generic;
using Artemis.Core.Plugins.LayerElement;
using Artemis.Core.Utilities;
using SkiaSharp;
namespace Artemis.Plugins.LayerElements.Noise
{
public class NoiseLayerElementViewModel : LayerElementViewModel
{
public NoiseLayerElementViewModel(NoiseLayerElement layerElement) : base(layerElement)
{
LayerElement = layerElement;
}
public new NoiseLayerElement LayerElement { get; }
public IEnumerable<ValueDescription> BlendModes => EnumUtilities.GetAllValuesAndDescriptions(typeof(SKBlendMode));
}
}

View File

@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("Artemis.Plugins.LayerElements.Noise")] [assembly: AssemblyTitle("Artemis.Plugins.LayerBrushes.Noise")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace Artemis.Plugins.LayerElements.Noise namespace Artemis.Plugins.LayerBrushes.Noise.Utilities
{ {
public class OpenSimplexNoise public class OpenSimplexNoise
{ {

View File

@ -1,10 +1,10 @@
{ {
"Guid": "61cbbf01-8d69-4ede-a972-f3f269da66d9", "Guid": "61cbbf01-8d69-4ede-a972-f3f269da66d9",
"Name": "Noise layer elements", "Name": "Noise layer brush",
"Version": { "Version": {
"Major": 1, "Major": 1,
"Minor": 0, "Minor": 0,
"Build": 0 "Build": 0
}, },
"Main": "Artemis.Plugins.LayerElements.Noise.dll" "Main": "Artemis.Plugins.LayerBrushes.Noise.dll"
} }

View File

@ -7,8 +7,8 @@
<ProjectGuid>{0F288A66-6EB0-4589-8595-E33A3A3EAEA2}</ProjectGuid> <ProjectGuid>{0F288A66-6EB0-4589-8595-E33A3A3EAEA2}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Artemis.Plugins.LayerElements.Brush</RootNamespace> <RootNamespace>Artemis.Plugins.LayerBrushes.Color</RootNamespace>
<AssemblyName>Artemis.Plugins.LayerElements.Brush</AssemblyName> <AssemblyName>Artemis.Plugins.LayerBrushes.Color</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
@ -87,10 +87,10 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="BrushLayerElementSettings.cs" /> <Compile Include="ColorBrushSettings.cs" />
<Compile Include="BrushLayerElementViewModel.cs" /> <Compile Include="ColorBrushViewModel.cs" />
<Compile Include="BrushLayerElement.cs" /> <Compile Include="ColorBrush.cs" />
<Compile Include="BrushLayerElementProvider.cs" /> <Compile Include="ColorBrushProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -108,7 +108,7 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="BrushLayerElementView.xaml"> <Page Include="ColorBrushView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>

View File

@ -1,25 +0,0 @@
using Artemis.Core.Plugins.LayerElement;
using Artemis.Core.Plugins.Models;
namespace Artemis.Plugins.LayerElements.Brush
{
public class BrushLayerElementProvider : LayerElementProvider
{
public BrushLayerElementProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
AddLayerElementDescriptor<BrushLayerElement>("Brush", "A brush of a specific type and colors", "Brush");
}
public override void EnablePlugin()
{
}
public override void DisablePlugin()
{
}
public override void Dispose()
{
}
}
}

View File

@ -1,17 +0,0 @@
using System.Collections.Generic;
using Artemis.Core.Plugins.LayerElement;
using Artemis.Core.Utilities;
namespace Artemis.Plugins.LayerElements.Brush
{
public class BrushLayerElementViewModel : LayerElementViewModel
{
public BrushLayerElementViewModel(BrushLayerElement layerElement) : base(layerElement)
{
LayerElement = layerElement;
}
public new BrushLayerElement LayerElement { get; }
public IEnumerable<ValueDescription> BrushTypes => EnumUtilities.GetAllValuesAndDescriptions(typeof(BrushType));
}
}

View File

@ -2,19 +2,18 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface; using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.LayerElement;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Plugins.LayerElements.Brush namespace Artemis.Plugins.LayerBrushes.Color
{ {
public class BrushLayerElement : LayerElement public class ColorBrush : LayerBrush
{ {
private SKShader _shader; private SKShader _shader;
private List<SKColor> _testColors; private List<SKColor> _testColors;
private SKPaint _paint; private SKPaint _paint;
public BrushLayerElement(Layer layer, Guid guid, BrushLayerElementSettings settings, LayerElementDescriptor descriptor) : base(layer, guid, settings, descriptor) public ColorBrush(Layer layer, ColorBrushSettings settings, LayerBrushDescriptor descriptor) : base(layer, settings, descriptor)
{ {
Settings = settings; Settings = settings;
@ -34,20 +33,20 @@ namespace Artemis.Plugins.LayerElements.Brush
private void CreateShader() private void CreateShader()
{ {
var center = new SKPoint(Layer.RenderRectangle.MidX, Layer.RenderRectangle.MidY); var center = new SKPoint(Layer.Rectangle.MidX, Layer.Rectangle.MidY);
SKShader shader; SKShader shader;
switch (Settings.BrushType) switch (Settings.GradientType)
{ {
case BrushType.Solid: case GradientType.Solid:
shader = SKShader.CreateColor(_testColors.First()); shader = SKShader.CreateColor(_testColors.First());
break; break;
case BrushType.LinearGradient: case GradientType.LinearGradient:
shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(Layer.RenderRectangle.Width, 0), _testColors.ToArray(), SKShaderTileMode.Repeat); shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(Layer.Rectangle.Width, 0), _testColors.ToArray(), SKShaderTileMode.Repeat);
break; break;
case BrushType.RadialGradient: case GradientType.RadialGradient:
shader = SKShader.CreateRadialGradient(center, Math.Min(Layer.RenderRectangle.Width, Layer.RenderRectangle.Height), _testColors.ToArray(), SKShaderTileMode.Repeat); shader = SKShader.CreateRadialGradient(center, Math.Min(Layer.Rectangle.Width, Layer.Rectangle.Height), _testColors.ToArray(), SKShaderTileMode.Repeat);
break; break;
case BrushType.SweepGradient: case GradientType.SweepGradient:
shader = SKShader.CreateSweepGradient(center, _testColors.ToArray(), null, SKShaderTileMode.Clamp, 0, 360); shader = SKShader.CreateSweepGradient(center, _testColors.ToArray(), null, SKShaderTileMode.Clamp, 0, 360);
break; break;
default: default:
@ -62,16 +61,16 @@ namespace Artemis.Plugins.LayerElements.Brush
oldPaint?.Dispose(); oldPaint?.Dispose();
} }
public new BrushLayerElementSettings Settings { get; } public new ColorBrushSettings Settings { get; }
public override LayerElementViewModel GetViewModel() public override LayerBrushViewModel GetViewModel()
{ {
return new BrushLayerElementViewModel(this); return new ColorBrushViewModel(this);
} }
public override void Render(SKPath framePath, SKCanvas canvas) public override void Render(SKCanvas canvas)
{ {
canvas.DrawPath(framePath, _paint); canvas.DrawPath(Layer.LayerShape.RenderPath, _paint);
} }
} }
} }

View File

@ -0,0 +1,25 @@
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Plugins.Models;
namespace Artemis.Plugins.LayerBrushes.Color
{
public class ColorBrushProvider : LayerBrushProvider
{
public ColorBrushProvider(PluginInfo pluginInfo) : base(pluginInfo)
{
AddLayerBrushDescriptor<ColorBrush>("Color", "A color with an (optional) gradient", "Brush");
}
public override void EnablePlugin()
{
}
public override void DisablePlugin()
{
}
public override void Dispose()
{
}
}
}

View File

@ -1,25 +1,25 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using Artemis.Core.Plugins.LayerElement; using Artemis.Core.Plugins.LayerBrush;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Plugins.LayerElements.Brush namespace Artemis.Plugins.LayerBrushes.Color
{ {
public class BrushLayerElementSettings : LayerElementSettings public class ColorBrushSettings : LayerBrushSettings
{ {
private BrushType _brushType;
private List<SKColor> _colors; private List<SKColor> _colors;
private GradientType _gradientType;
public BrushLayerElementSettings() public ColorBrushSettings()
{ {
BrushType = BrushType.Solid; GradientType = GradientType.Solid;
Colors = new List<SKColor>(); Colors = new List<SKColor>();
} }
public BrushType BrushType public GradientType GradientType
{ {
get => _brushType; get => _gradientType;
set => SetAndNotify(ref _brushType, value); set => SetAndNotify(ref _gradientType, value);
} }
public List<SKColor> Colors public List<SKColor> Colors
@ -29,7 +29,7 @@ namespace Artemis.Plugins.LayerElements.Brush
} }
} }
public enum BrushType public enum GradientType
{ {
[Description("Solid")] [Description("Solid")]
Solid, Solid,

View File

@ -1,13 +1,12 @@
<UserControl x:Class="Artemis.Plugins.LayerElements.Brush.BrushLayerElementView" <UserControl x:Class="Artemis.Plugins.LayerBrushes.Color.ColorBrushView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:colorBrush="clr-namespace:Artemis.Plugins.LayerBrushes.Color"
xmlns:brushLayer="clr-namespace:Artemis.Plugins.LayerElements.Brush"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type brushLayer:BrushLayerElementViewModel}}"> d:DataContext="{d:DesignInstance {x:Type colorBrush:ColorBrushViewModel}}">
<UserControl.Resources> <UserControl.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
@ -47,7 +46,7 @@
ItemsSource="{Binding Path=BrushTypes}" ItemsSource="{Binding Path=BrushTypes}"
SelectedValuePath="Value" SelectedValuePath="Value"
DisplayMemberPath="Description" DisplayMemberPath="Description"
SelectedValue="{Binding Path=LayerElement.Settings.BrushType}" /> SelectedValue="{Binding Path=ColorBrush.Settings.GradientType}" />
</StackPanel> </StackPanel>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" /> <Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource MaterialDesignSeparator}" />
</Grid> </Grid>

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
using Artemis.Core.Plugins.LayerBrush;
using Artemis.Core.Utilities;
namespace Artemis.Plugins.LayerBrushes.Color
{
public class ColorBrushViewModel : LayerBrushViewModel
{
public ColorBrushViewModel(ColorBrush element) : base(element)
{
ColorBrush = element;
}
public new ColorBrush ColorBrush { get; }
public IEnumerable<ValueDescription> BrushTypes => EnumUtilities.GetAllValuesAndDescriptions(typeof(GradientType));
}
}

View File

@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("Artemis.Plugins.LayerElements.Brush")] [assembly: AssemblyTitle("Artemis.Plugins.LayerBrushes.Color")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]

View File

@ -1,10 +1,10 @@
{ {
"Guid": "92a9d6ba-6f7a-4937-94d5-c1d715b4141a", "Guid": "92a9d6ba-6f7a-4937-94d5-c1d715b4141a",
"Name": "Brush layer elements", "Name": "Color layer brush",
"Version": { "Version": {
"Major": 1, "Major": 1,
"Minor": 0, "Minor": 0,
"Build": 0 "Build": 0
}, },
"Main": "Artemis.Plugins.LayerElements.Brush.dll" "Main": "Artemis.Plugins.LayerBrushes.Color.dll"
} }

View File

@ -0,0 +1,11 @@
using System;
namespace Artemis.Storage.Entities.Profile
{
public class BrushEntity
{
public Guid BrushPluginGuid { get; set; }
public string BrushType { get; set; }
public string Configuration { get; set; }
}
}

View File

@ -1,13 +0,0 @@
using System;
namespace Artemis.Storage.Entities.Profile
{
public class LayerElementEntity
{
public Guid Id { get; set; }
public Guid PluginGuid { get; set; }
public string LayerElementType { get; set; }
public string Configuration { get; set; }
}
}

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using LiteDB; using LiteDB;
namespace Artemis.Storage.Entities.Profile namespace Artemis.Storage.Entities.Profile
@ -10,7 +11,6 @@ namespace Artemis.Storage.Entities.Profile
{ {
Leds = new List<LedEntity>(); Leds = new List<LedEntity>();
Condition = new List<ProfileConditionEntity>(); Condition = new List<ProfileConditionEntity>();
Elements = new List<LayerElementEntity>();
} }
public Guid Id { get; set; } public Guid Id { get; set; }
@ -21,11 +21,12 @@ namespace Artemis.Storage.Entities.Profile
public List<LedEntity> Leds { get; set; } public List<LedEntity> Leds { get; set; }
public List<ProfileConditionEntity> Condition { get; set; } public List<ProfileConditionEntity> Condition { get; set; }
public List<LayerElementEntity> Elements { get; set; }
public ShapeEntity ShapeEntity { get; set; }
public BrushEntity BrushEntity { get; set; }
[BsonRef("ProfileEntity")] [BsonRef("ProfileEntity")]
public ProfileEntity Profile { get; set; } public ProfileEntity Profile { get; set; }
public Guid ProfileId { get; set; } public Guid ProfileId { get; set; }
} }
} }

View File

@ -0,0 +1,29 @@
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Profile
{
public class ShapeEntity
{
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 class ShapePointEntity
{
public float X { get; set; }
public float Y { get; set; }
}
public enum ShapeEntityType
{
Ellipse,
Fill,
Polygon,
Rectangle
}
}

View File

@ -174,7 +174,48 @@
<Compile Include="Events\MainWindowFocusChangedEvent.cs" /> <Compile Include="Events\MainWindowFocusChangedEvent.cs" />
<Compile Include="Events\WindowsThemeEventArgs.cs" /> <Compile Include="Events\WindowsThemeEventArgs.cs" />
<Compile Include="Screens\GradientEditor\GradientEditorViewModel.cs" /> <Compile Include="Screens\GradientEditor\GradientEditorViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerElements\Dialogs\AddLayerElementViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\LayerProperties\LayerPropertiesView.xaml.cs">
<DependentUpon>LayerPropertiesView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\LayerPropertiesViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\Timeline\LayerPropertiesTimelineView.xaml.cs">
<DependentUpon>LayerPropertiesTimelineView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\LayerProperties\Timeline\LayerPropertiesTimelineViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\CanvasViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\EllipseToolView.xaml.cs">
<DependentUpon>EllipseToolView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\EllipseToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\FillToolView.xaml.cs">
<DependentUpon>FillToolView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\FillToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\PolygonToolView.xaml.cs">
<DependentUpon>PolygonToolView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\PolygonToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\RectangleToolView.xaml.cs">
<DependentUpon>RectangleToolView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\RectangleToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionAddToolView.xaml.cs">
<DependentUpon>SelectionAddToolView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionAddToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionRemoveToolView.xaml.cs">
<DependentUpon>SelectionRemoveToolView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionRemoveToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionToolView.xaml.cs">
<DependentUpon>SelectionToolView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\ViewpointMoveToolView.xaml.cs">
<DependentUpon>ViewpointMoveToolView.xaml</DependentUpon>
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\ViewpointMoveToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\VisualizationToolViewModel.cs" />
<Compile Include="Screens\Sidebar\SidebarView.xaml.cs"> <Compile Include="Screens\Sidebar\SidebarView.xaml.cs">
<DependentUpon>SidebarView.xaml</DependentUpon> <DependentUpon>SidebarView.xaml</DependentUpon>
</Compile> </Compile>
@ -202,9 +243,6 @@
<Compile Include="Screens\Module\ProfileEditor\Dialogs\ProfileElementRenameViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\Dialogs\ProfileElementRenameViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionsViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionsViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\DisplayConditions\DisplayConditionViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\ElementProperties\ElementPropertiesViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerElements\LayerElementsViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\LayerElements\LayerElementViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\ProfileTree\TreeItem\FolderViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\ProfileTree\TreeItem\FolderViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\ProfileTree\TreeItem\LayerViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\ProfileTree\TreeItem\LayerViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\ProfileTree\ProfileTreeViewModel.cs" /> <Compile Include="Screens\Module\ProfileEditor\ProfileTree\ProfileTreeViewModel.cs" />
@ -269,15 +307,11 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Screens\Module\ProfileEditor\ElementProperties\ElementPropertiesView.xaml"> <Page Include="Screens\Module\ProfileEditor\LayerProperties\LayerPropertiesView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Screens\Module\ProfileEditor\LayerElements\Dialogs\AddLayerElementView.xaml"> <Page Include="Screens\Module\ProfileEditor\LayerProperties\Timeline\LayerPropertiesTimelineView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\LayerElements\LayerElementsView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
@ -301,6 +335,38 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Screens\Module\ProfileEditor\Visualization\Tools\EllipseToolView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\Visualization\Tools\FillToolView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\Visualization\Tools\PolygonToolView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\Visualization\Tools\RectangleToolView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionAddToolView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionRemoveToolView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\Visualization\Tools\SelectionToolView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\Module\ProfileEditor\Visualization\Tools\ViewpointMoveToolView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Screens\News\NewsView.xaml"> <Page Include="Screens\News\NewsView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -436,7 +502,24 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\aero_rotate_br.cur" /> <None Include="Resources\aero_rotate_br.cur" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<None Include="Resources\aero_crosshair.cur" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\aero_crosshair_minus.cur" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\aero_crosshair_plus.cur" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\aero_pen_min.cur" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\aero_pen_plus.cur" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\aero_fill.cur" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent> <PostBuildEvent>

View File

@ -1,4 +1,4 @@
using Artemis.Core.Models.Profile.Abstract; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.UI.Screens.Module; using Artemis.UI.Screens.Module;

View File

@ -60,6 +60,66 @@ namespace Artemis.UI.Properties {
} }
} }
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] aero_crosshair {
get {
object obj = ResourceManager.GetObject("aero_crosshair", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] aero_crosshair_minus {
get {
object obj = ResourceManager.GetObject("aero_crosshair_minus", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] aero_crosshair_plus {
get {
object obj = ResourceManager.GetObject("aero_crosshair_plus", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] aero_fill {
get {
object obj = ResourceManager.GetObject("aero_fill", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] aero_pen_min {
get {
object obj = ResourceManager.GetObject("aero_pen_min", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] aero_pen_plus {
get {
object obj = ResourceManager.GetObject("aero_pen_plus", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Byte[]. /// Looks up a localized resource of type System.Byte[].
/// </summary> /// </summary>

View File

@ -118,6 +118,24 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="aero_crosshair" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\aero_crosshair.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="aero_crosshair_minus" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\aero_crosshair_minus.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="aero_crosshair_plus" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\aero_crosshair_plus.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="aero_fill" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\aero_fill.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="aero_pen_min" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\aero_pen_min.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="aero_pen_plus" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\aero_pen_plus.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="aero_rotate_bl" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="aero_rotate_bl" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\aero_rotate_bl.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>..\Resources\aero_rotate_bl.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,5 +1,5 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.Core.Models.Profile.Abstract; using Artemis.Core.Models.Profile;
using Artemis.UI.ViewModels.Dialogs; using Artemis.UI.ViewModels.Dialogs;
using FluentValidation; using FluentValidation;
using Stylet; using Stylet;

View File

@ -1,27 +0,0 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.ElementProperties.ElementPropertiesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:elementProperties="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.ElementProperties"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type elementProperties:ElementPropertiesViewModel}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Style="{StaticResource MaterialDesignSubheadingTextBlock}" Margin="10 5 0 -4">
Layer element properties
</TextBlock>
<Separator Style="{StaticResource MaterialDesignDarkSeparator}" Margin="8 0" />
</StackPanel>
<ScrollViewer Grid.Row="1">
<ContentControl s:View.Model="{Binding LayerElementViewModel}" Margin="0 0 10 0"/>
</ScrollViewer>
</Grid>
</UserControl>

View File

@ -1,37 +0,0 @@
using System;
using System.ComponentModel;
using Artemis.Core.Plugins.LayerElement;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.ElementProperties
{
public class ElementPropertiesViewModel : ProfileEditorPanelViewModel
{
private readonly IProfileEditorService _profileEditorService;
public ElementPropertiesViewModel(IProfileEditorService profileEditorService)
{
_profileEditorService = profileEditorService;
_profileEditorService.SelectedLayerElementChanged += OnSelectedLayerElementChanged;
}
public LayerElementViewModel LayerElementViewModel { get; set; }
private void OnSelectedLayerElementChanged(object sender, EventArgs e)
{
if (LayerElementViewModel?.LayerElement?.Settings != null)
LayerElementViewModel.LayerElement.Settings.PropertyChanged -= SettingsOnPropertyChanged;
LayerElementViewModel = _profileEditorService.SelectedLayerElement?.GetViewModel();
if (LayerElementViewModel?.LayerElement?.Settings != null)
LayerElementViewModel.LayerElement.Settings.PropertyChanged += SettingsOnPropertyChanged;
}
private void SettingsOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
_profileEditorService.UpdateSelectedProfileElement();
}
}
}

View File

@ -1,45 +0,0 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerElements.Dialogs.AddLayerElementView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:layerElement="clr-namespace:Artemis.Core.Plugins.LayerElement;assembly=Artemis.Core"
xmlns:layerElements="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerElements.Dialogs"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance {x:Type layerElements:AddLayerElementViewModel}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Margin="15">Select a new layer element below</TextBlock>
<ListBox Grid.Row="1" ItemsSource="{Binding LayerElementDescriptors}" SelectedItem="{Binding SelectedLayerElementDescriptor}" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type layerElement:LayerElementDescriptor}">
<Border Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}" VerticalAlignment="Stretch" MouseDown="{s:Action ListBoxItemMouseClick}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<materialDesign:PackIcon Kind="{Binding Icon}" Width="20" Height="20" VerticalAlignment="Center" />
<StackPanel Margin="8 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
<TextBlock FontWeight="Bold" Text="{Binding DisplayName}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="10 15">
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">CANCEL</Button>
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0" Command="{s:Action Accept}">ACCEPT</Button>
</StackPanel>
</Grid>
</UserControl>

View File

@ -1,57 +0,0 @@
using System.Windows.Input;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerElement;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.ViewModels.Dialogs;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerElements.Dialogs
{
public class AddLayerElementViewModel : DialogViewModelBase
{
private readonly ILayerService _layerService;
public AddLayerElementViewModel(IPluginService pluginService, ILayerService layerService, Layer layer)
{
_layerService = layerService;
Layer = layer;
LayerElementDescriptors = new BindableCollection<LayerElementDescriptor>();
var layerElementProviders = pluginService.GetPluginsOfType<LayerElementProvider>();
foreach (var layerElementProvider in layerElementProviders)
LayerElementDescriptors.AddRange(layerElementProvider.LayerElementDescriptors);
}
public Layer Layer { get; }
public LayerElementDescriptor SelectedLayerElementDescriptor { get; set; }
public BindableCollection<LayerElementDescriptor> LayerElementDescriptors { get; set; }
public bool CanAccept => SelectedLayerElementDescriptor != null;
public void Accept()
{
if (Session.IsEnded)
return;
var layerElement = _layerService.InstantiateLayerElement(Layer, SelectedLayerElementDescriptor);
Session.Close(layerElement);
}
public void Cancel()
{
if (Session.IsEnded)
return;
Session.Close();
}
#region View event handlers
public void ListBoxItemMouseClick(object sender, MouseButtonEventArgs args)
{
if (args.ClickCount > 1 && SelectedLayerElementDescriptor != null)
Accept();
}
#endregion
}
}

View File

@ -1,19 +0,0 @@
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.LayerElement;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerElements
{
public class LayerElementViewModel
{
public LayerElementViewModel(LayerElement layerElement)
{
Layer = layerElement.Layer;
LayerElement = layerElement;
LayerElementDescriptor = layerElement.Descriptor;
}
public Layer Layer { get; set; }
public LayerElement LayerElement { get; set; }
public LayerElementDescriptor LayerElementDescriptor { get; set; }
}
}

View File

@ -1,71 +0,0 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerElements.LayerElementsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:layerElements="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerElements"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type layerElements:LayerElementsViewModel}}">
<materialDesign:DialogHost Identifier="LayerElementsDialogHost" CloseOnClickAway="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Style="{StaticResource MaterialDesignSubheadingTextBlock}" Margin="10 5 0 -4">
Layer elements
</TextBlock>
<Separator Style="{StaticResource MaterialDesignDarkSeparator}" Margin="8 0" />
</StackPanel>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding LayerElements}" SelectedItem="{Binding SelectedLayerElement}" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type layerElements:LayerElementViewModel}">
<Border Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<materialDesign:PackIcon Kind="{Binding LayerElementDescriptor.Icon}" Width="20" Height="20" VerticalAlignment="Center" />
<StackPanel Margin="8 0 0 0" Grid.Column="1">
<TextBlock FontWeight="Bold" Text="{Binding LayerElementDescriptor.DisplayName}" />
<TextBlock Text="{Binding LayerElementDescriptor.Description}" />
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel VerticalAlignment="Bottom" Grid.Column="1" Orientation="Vertical" Margin="8">
<Button Style="{StaticResource MaterialDesignToolButton}"
Width="30"
Padding="2 0 2 0"
materialDesign:RippleAssist.IsCentered="True"
ToolTip="Add a new layer element"
Command="{s:Action AddLayerElement}">
<materialDesign:PackIcon Kind="LibraryAdd" />
</Button>
<Button Style="{StaticResource MaterialDesignToolButton}"
Width="30"
Padding="2 0 2 0"
materialDesign:RippleAssist.IsCentered="True"
ToolTip="Delete selected layer element"
Command="{s:Action DeleteSelectedLayerElement}">
<materialDesign:PackIcon Kind="Delete" />
</Button>
</StackPanel>
</Grid>
</Grid>
</materialDesign:DialogHost>
</UserControl>

View File

@ -1,111 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Abstract;
using Artemis.Core.Plugins.LayerElement;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.LayerElements.Dialogs;
using Artemis.UI.Services.Interfaces;
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerElements
{
public class LayerElementsViewModel : ProfileEditorPanelViewModel
{
private readonly IDialogService _dialogService;
private readonly IProfileEditorService _profileEditorService;
private readonly ILayerService _layerService;
private LayerElementViewModel _selectedLayerElement;
public LayerElementsViewModel(IProfileEditorService profileEditorService, ILayerService layerService, IDialogService dialogService)
{
_profileEditorService = profileEditorService;
_layerService = layerService;
_dialogService = dialogService;
LayerElements = new BindableCollection<LayerElementViewModel>();
SelectedProfileElement = _profileEditorService.SelectedProfileElement;
PopulateLayerElements();
_profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged;
_profileEditorService.SelectedLayerElementChanged += OnSelectedLayerElementChanged;
}
public ProfileElement SelectedProfileElement { get; private set; }
public BindableCollection<LayerElementViewModel> LayerElements { get; set; }
public LayerElementViewModel SelectedLayerElement
{
get => _selectedLayerElement;
set
{
_selectedLayerElement = value;
_profileEditorService.ChangeSelectedLayerElement(value?.LayerElement);
}
}
public bool CanAddLayerElement => SelectedProfileElement is Layer;
public bool CanDeleteSelectedLayerElement => SelectedLayerElement != null;
private void OnSelectedLayerElementChanged(object sender, EventArgs e)
{
_selectedLayerElement = LayerElements.FirstOrDefault(l => l.LayerElement == _profileEditorService.SelectedLayerElement);
NotifyOfPropertyChange(() => SelectedLayerElement);
}
private void OnSelectedProfileElementChanged(object sender, EventArgs e)
{
SelectedProfileElement = _profileEditorService.SelectedProfileElement;
PopulateLayerElements();
}
private void PopulateLayerElements()
{
LayerElements.Clear();
if (SelectedProfileElement is Layer layer)
{
foreach (var layerElement in layer.LayerElements)
LayerElements.Add(new LayerElementViewModel(layerElement));
}
}
public async void AddLayerElement()
{
var result = await _dialogService.ShowDialogAt<AddLayerElementViewModel>(
"LayerElementsDialogHost",
new Dictionary<string, object> {{"layer", (Layer) SelectedProfileElement}}
);
if (!(result is LayerElement layerElement))
return;
LayerElements.Add(new LayerElementViewModel(layerElement));
_profileEditorService.UpdateSelectedProfileElement();
}
public async void DeleteSelectedLayerElement()
{
if (SelectedLayerElement == null)
return;
var result = await _dialogService.ShowConfirmDialogAt(
"LayerElementsDialogHost",
"Delete layer element",
"Are you sure you want to delete the selected layer element?"
);
if (!result)
return;
var layerElement = SelectedLayerElement.LayerElement;
var layer = (Layer) SelectedProfileElement;
LayerElements.Remove(SelectedLayerElement);
SelectedLayerElement = null;
_layerService.RemoveLayerElement(layer, layerElement);
_profileEditorService.UpdateSelectedProfileElement();
}
}
}

View File

@ -0,0 +1,12 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.LayerPropertiesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
{
/// <summary>
/// Interaction logic for LayerPropertiesView.xaml
/// </summary>
public partial class LayerPropertiesView : UserControl
{
public LayerPropertiesView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
{
public class LayerPropertiesViewModel : ProfileEditorPanelViewModel
{
}
}

View File

@ -0,0 +1,12 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline.LayerPropertiesTimelineView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
{
/// <summary>
/// Interaction logic for LayerPropertiesTimelineView.xaml
/// </summary>
public partial class LayerPropertiesTimelineView : UserControl
{
public LayerPropertiesTimelineView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
{
class LayerPropertiesTimelineViewModel
{
}
}

View File

@ -80,7 +80,7 @@
<!-- Element properties --> <!-- Element properties -->
<materialDesign:Card Grid.Column="2" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch"> <materialDesign:Card Grid.Column="2" materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch">
<ContentControl s:View.Model="{Binding ElementPropertiesViewModel}" /> <ContentControl s:View.Model="{Binding LayerPropertiesViewModel}" />
</materialDesign:Card> </materialDesign:Card>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -10,8 +10,7 @@ using Artemis.Core.Services;
using Artemis.Core.Services.Storage.Interfaces; using Artemis.Core.Services.Storage.Interfaces;
using Artemis.UI.Screens.Module.ProfileEditor.Dialogs; using Artemis.UI.Screens.Module.ProfileEditor.Dialogs;
using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions; using Artemis.UI.Screens.Module.ProfileEditor.DisplayConditions;
using Artemis.UI.Screens.Module.ProfileEditor.ElementProperties; using Artemis.UI.Screens.Module.ProfileEditor.LayerProperties;
using Artemis.UI.Screens.Module.ProfileEditor.LayerElements;
using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree; using Artemis.UI.Screens.Module.ProfileEditor.ProfileTree;
using Artemis.UI.Screens.Module.ProfileEditor.Visualization; using Artemis.UI.Screens.Module.ProfileEditor.Visualization;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;
@ -41,8 +40,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
DialogService = dialogService; DialogService = dialogService;
DisplayConditionsViewModel = (DisplayConditionsViewModel) viewModels.First(vm => vm is DisplayConditionsViewModel); DisplayConditionsViewModel = (DisplayConditionsViewModel) viewModels.First(vm => vm is DisplayConditionsViewModel);
ElementPropertiesViewModel = (ElementPropertiesViewModel) viewModels.First(vm => vm is ElementPropertiesViewModel); LayerPropertiesViewModel = (LayerPropertiesViewModel) viewModels.First(vm => vm is LayerPropertiesViewModel);
LayerElementsViewModel = (LayerElementsViewModel) viewModels.First(vm => vm is LayerElementsViewModel);
ProfileTreeViewModel = (ProfileTreeViewModel) viewModels.First(vm => vm is ProfileTreeViewModel); ProfileTreeViewModel = (ProfileTreeViewModel) viewModels.First(vm => vm is ProfileTreeViewModel);
ProfileViewModel = (ProfileViewModel) viewModels.First(vm => vm is ProfileViewModel); ProfileViewModel = (ProfileViewModel) viewModels.First(vm => vm is ProfileViewModel);
Profiles = new BindableCollection<Profile>(); Profiles = new BindableCollection<Profile>();
@ -55,8 +53,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
public ProfileModule Module { get; } public ProfileModule Module { get; }
public IDialogService DialogService { get; } public IDialogService DialogService { get; }
public DisplayConditionsViewModel DisplayConditionsViewModel { get; } public DisplayConditionsViewModel DisplayConditionsViewModel { get; }
public ElementPropertiesViewModel ElementPropertiesViewModel { get; } public LayerPropertiesViewModel LayerPropertiesViewModel { get; }
public LayerElementsViewModel LayerElementsViewModel { get; }
public ProfileTreeViewModel ProfileTreeViewModel { get; } public ProfileTreeViewModel ProfileTreeViewModel { get; }
public ProfileViewModel ProfileViewModel { get; } public ProfileViewModel ProfileViewModel { get; }
public BindableCollection<Profile> Profiles { get; set; } public BindableCollection<Profile> Profiles { get; set; }

View File

@ -1,4 +1,4 @@
using Artemis.Core.Models.Profile.Abstract; using Artemis.Core.Models.Profile;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;

View File

@ -1,4 +1,4 @@
using Artemis.Core.Models.Profile.Abstract; using Artemis.Core.Models.Profile;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;

View File

@ -2,7 +2,6 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.Core.Models.Profile; using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.Abstract;
using Artemis.UI.Exceptions; using Artemis.UI.Exceptions;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.Module.ProfileEditor.Dialogs; using Artemis.UI.Screens.Module.ProfileEditor.Dialogs;

View File

@ -0,0 +1,10 @@
using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{
public class CanvasViewModel : PropertyChangedBase
{
public double X { get; set; }
public double Y { get; set; }
}
}

View File

@ -21,8 +21,8 @@
</Grid.LayoutTransform> </Grid.LayoutTransform>
<!-- Device image with fallback --> <!-- Device image with fallback -->
<Image VerticalAlignment="Top" <Image VerticalAlignment="Stretch"
HorizontalAlignment="Left" HorizontalAlignment="Stretch"
Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" /> Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" />
<Rectangle Fill="{DynamicResource MaterialDesignCardBackground}" <Rectangle Fill="{DynamicResource MaterialDesignCardBackground}"

View File

@ -7,7 +7,7 @@ using Stylet;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{ {
public class ProfileDeviceViewModel : PropertyChangedBase public class ProfileDeviceViewModel : CanvasViewModel
{ {
public ProfileDeviceViewModel(ArtemisDevice device) public ProfileDeviceViewModel(ArtemisDevice device)
{ {
@ -21,13 +21,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
public ArtemisDevice Device { get; set; } public ArtemisDevice Device { get; set; }
public bool AddedLeds { get; private set; } public bool AddedLeds { get; private set; }
public double X public new double X
{ {
get => Device.X; get => Device.X;
set => Device.X = value; set => Device.X = value;
} }
public double Y public new double Y
{ {
get => Device.Y; get => Device.Y;
set => Device.Y = value; set => Device.Y = value;

View File

@ -39,14 +39,58 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</UserControl.Resources> </UserControl.Resources>
<Grid ClipToBounds="True"
KeyUp="{s:Action EditorGridKeyUp}" <Grid>
KeyDown="{s:Action EditorGridKeyDown}" <Grid.ColumnDefinitions>
MouseWheel="{s:Action EditorGridMouseWheel}" <ColumnDefinition Width="Auto" />
MouseUp="{s:Action EditorGridMouseClick}" <ColumnDefinition Width="*" />
MouseDown="{s:Action EditorGridMouseClick}" </Grid.ColumnDefinitions>
MouseMove="{s:Action EditorGridMouseMove}" <ToolBarTray Orientation="Vertical" Width="58">
Cursor="{Binding Cursor}" <ToolBar Style="{DynamicResource MaterialDesignToolBar}" ClipToBounds="False" ToolBarTray.IsLocked="True" >
<ListBox SelectedIndex="{Binding ActiveToolIndex}" ToolBar.OverflowMode="Never">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem ToolTip="Pan over different parts of the surface" >
<materialDesign:PackIcon Kind="HandLeft" />
</ListBoxItem>
<ListBoxItem ToolTip="Change layer selection" >
<materialDesign:PackIcon Kind="SelectionDrag" />
</ListBoxItem>
<ListBoxItem ToolTip="Add to layer selection">
<materialDesign:PackIcon Kind="PencilPlusOutline" />
</ListBoxItem>
<ListBoxItem ToolTip="Remove from layer selection">
<materialDesign:PackIcon Kind="PencilMinusOutline" />
</ListBoxItem>
<Separator />
<ListBoxItem ToolTip="Create round shape in layer">
<materialDesign:PackIcon Kind="ShapeCirclePlus" />
</ListBoxItem>
<ListBoxItem ToolTip="Create rectangular shape in layer">
<materialDesign:PackIcon Kind="ShapeRectanglePlus" />
</ListBoxItem>
<ListBoxItem ToolTip="Create polygonal shape in layer">
<materialDesign:PackIcon Kind="ShapePolygonPlus" />
</ListBoxItem>
<ListBoxItem ToolTip="Fill entire layer">
<materialDesign:PackIcon Kind="FormatColourFill" />
</ListBoxItem>
</ListBox>
</ToolBar>
</ToolBarTray>
<Grid Grid.Column="1"
ClipToBounds="True"
KeyUp="{s:Action CanvasKeyUp}"
KeyDown="{s:Action CanvasKeyDown}"
MouseWheel="{s:Action CanvasMouseWheel}"
MouseUp="{s:Action CanvasMouseDown}"
MouseDown="{s:Action CanvasMouseUp}"
MouseMove="{s:Action CanvasMouseMove}"
Cursor="{Binding ActiveToolViewModel.Cursor}"
utilities:SizeObserver.Observe="True" utilities:SizeObserver.Observe="True"
utilities:SizeObserver.ObservedWidth="{Binding PanZoomViewModel.CanvasWidth, Mode=OneWayToSource}" utilities:SizeObserver.ObservedWidth="{Binding PanZoomViewModel.CanvasWidth, Mode=OneWayToSource}"
utilities:SizeObserver.ObservedHeight="{Binding PanZoomViewModel.CanvasHeight, Mode=OneWayToSource}"> utilities:SizeObserver.ObservedHeight="{Binding PanZoomViewModel.CanvasHeight, Mode=OneWayToSource}">
@ -72,54 +116,6 @@
</VisualBrush> </VisualBrush>
</Grid.Background> </Grid.Background>
<Grid.Triggers>
<EventTrigger RoutedEvent="Grid.MouseLeftButtonDown">
<BeginStoryboard>
<Storyboard TargetName="MultiSelectionPath" TargetProperty="Opacity">
<DoubleAnimation From="0" To="1" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Grid.MouseLeftButtonUp">
<BeginStoryboard>
<Storyboard TargetName="MultiSelectionPath" TargetProperty="Opacity">
<DoubleAnimation From="1" To="0" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Create new layer for selection" Command="{s:Action CreateLayer}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="LayersPlus" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Apply selection to layer" Command="{s:Action ApplyToLayer}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Selection" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Select all" Command="{s:Action SelectAll}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="SelectAll" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Inverse selection" Command="{s:Action InverseSelection}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="SelectInverse" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Clear selection" Command="{s:Action ClearSelection}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="SelectOff" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Grid.ContextMenu>
<Grid Name="EditorDisplayGrid"> <Grid Name="EditorDisplayGrid">
<Grid.RenderTransform> <Grid.RenderTransform>
<TransformGroup> <TransformGroup>
@ -147,17 +143,6 @@
</ItemsControl> </ItemsControl>
</Grid> </Grid>
<!-- Multi-selection rectangle -->
<Path Data="{Binding SelectionRectangle}" Opacity="0"
Stroke="{DynamicResource PrimaryHueLightBrush}"
StrokeThickness="1"
Name="MultiSelectionPath"
IsHitTestVisible="False">
<Path.Fill>
<SolidColorBrush Color="{DynamicResource Primary400}" Opacity="0.25" />
</Path.Fill>
</Path>
<StackPanel ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10"> <StackPanel ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10">
<materialDesign:Card Padding="8"> <materialDesign:Card Padding="8">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
@ -190,7 +175,7 @@
</StackPanel> </StackPanel>
<!-- Loading indicator --> <!-- Loading indicator -->
<Grid Background="{StaticResource MaterialDesignPaper}" Style="{StaticResource InitializingFade}"> <Grid Background="{StaticResource MaterialDesignPaper}" Style="{StaticResource InitializingFade}" d:IsHidden="True">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBlock FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center">
Initializing LED visualization... Initializing LED visualization...
@ -199,4 +184,6 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
</Grid> </Grid>
</Grid>
</UserControl> </UserControl>

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using Artemis.Core.Events; using Artemis.Core.Events;
@ -12,13 +11,11 @@ using Artemis.Core.Plugins.Models;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.Core.Services.Storage.Interfaces; using Artemis.Core.Services.Storage.Interfaces;
using Artemis.UI.Events; using Artemis.UI.Events;
using Artemis.UI.Extensions; using Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools;
using Artemis.UI.Screens.Shared; using Artemis.UI.Screens.Shared;
using Artemis.UI.Screens.SurfaceEditor;
using Artemis.UI.Services.Interfaces; using Artemis.UI.Services.Interfaces;
using RGB.NET.Core; using RGB.NET.Core;
using Stylet; using Stylet;
using Point = System.Windows.Point;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{ {
@ -29,25 +26,21 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
private readonly ISurfaceService _surfaceService; private readonly ISurfaceService _surfaceService;
private TimerUpdateTrigger _updateTrigger; private TimerUpdateTrigger _updateTrigger;
public ProfileViewModel(IProfileEditorService profileEditorService, public ProfileViewModel(IProfileEditorService profileEditorService, ISurfaceService surfaceService, ISettingsService settingsService, IEventAggregator eventAggregator)
ISurfaceService surfaceService,
ISettingsService settingsService,
IEventAggregator eventAggregator)
{ {
_profileEditorService = profileEditorService; _profileEditorService = profileEditorService;
_surfaceService = surfaceService; _surfaceService = surfaceService;
_settingsService = settingsService; _settingsService = settingsService;
Devices = new ObservableCollection<ProfileDeviceViewModel>();
Cursor = null;
Execute.PostToUIThread(() => Execute.OnUIThreadSync(() =>
{ {
SelectionRectangle = new RectangleGeometry(); CanvasViewModels = new ObservableCollection<CanvasViewModel>();
PanZoomViewModel = new PanZoomViewModel(); PanZoomViewModel = new PanZoomViewModel();
}); });
ApplySurfaceConfiguration(surfaceService.ActiveSurface); ApplySurfaceConfiguration(surfaceService.ActiveSurface);
CreateUpdateTrigger(); CreateUpdateTrigger();
ActivateToolByIndex(0);
_profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged; _profileEditorService.SelectedProfileElementChanged += OnSelectedProfileElementChanged;
_profileEditorService.SelectedProfileElementUpdated += OnSelectedProfileElementChanged; _profileEditorService.SelectedProfileElementUpdated += OnSelectedProfileElementChanged;
@ -55,13 +48,42 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
} }
public bool IsInitializing { get; private set; } public bool IsInitializing { get; private set; }
public ObservableCollection<ProfileDeviceViewModel> Devices { get; set; } public ObservableCollection<CanvasViewModel> CanvasViewModels { get; set; }
public RectangleGeometry SelectionRectangle { get; set; }
public PanZoomViewModel PanZoomViewModel { get; set; } public PanZoomViewModel PanZoomViewModel { get; set; }
public PluginSetting<bool> HighlightSelectedLayer { get; set; } public PluginSetting<bool> HighlightSelectedLayer { get; set; }
public PluginSetting<bool> PauseRenderingOnFocusLoss { get; set; } public PluginSetting<bool> PauseRenderingOnFocusLoss { get; set; }
public Cursor Cursor { get; set; } public ReadOnlyCollection<ProfileDeviceViewModel> Devices => CanvasViewModels
.Where(vm => vm is ProfileDeviceViewModel)
.Cast<ProfileDeviceViewModel>()
.ToList()
.AsReadOnly();
public VisualizationToolViewModel ActiveToolViewModel
{
get => _activeToolViewModel;
set
{
// Remove the tool from the canvas
if (_activeToolViewModel != null)
CanvasViewModels.Remove(_activeToolViewModel);
// Set the new tool
_activeToolViewModel = value;
// Add the new tool to the canvas
if (_activeToolViewModel != null)
CanvasViewModels.Add(_activeToolViewModel);
}
}
public int ActiveToolIndex
{
get => _activeToolIndex;
set
{
_activeToolIndex = value;
ActivateToolByIndex(value);
}
}
private void CreateUpdateTrigger() private void CreateUpdateTrigger()
{ {
@ -82,12 +104,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
private void ApplySurfaceConfiguration(ArtemisSurface surface) private void ApplySurfaceConfiguration(ArtemisSurface surface)
{ {
List<ArtemisDevice> devices; var devices = new List<ArtemisDevice>();
lock (Devices)
{
devices = new List<ArtemisDevice>();
devices.AddRange(surface.Devices); devices.AddRange(surface.Devices);
}
// Make sure all devices have an up-to-date VM // Make sure all devices have an up-to-date VM
foreach (var surfaceDeviceConfiguration in devices) foreach (var surfaceDeviceConfiguration in devices)
@ -102,9 +120,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{ {
// Gotta call IsInitializing on the UI thread or its never gets picked up // Gotta call IsInitializing on the UI thread or its never gets picked up
IsInitializing = true; IsInitializing = true;
lock (Devices) lock (CanvasViewModels)
{ {
Devices.Add(profileDeviceViewModel); CanvasViewModels.Add(profileDeviceViewModel);
} }
}); });
} }
@ -113,20 +131,21 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
viewModel.Device = surfaceDeviceConfiguration; viewModel.Device = surfaceDeviceConfiguration;
} }
// Sort the devices by ZIndex // Sort the devices by ZIndex
Execute.PostToUIThread(() => Execute.PostToUIThread(() =>
{ {
lock (Devices) lock (CanvasViewModels)
{ {
foreach (var device in Devices.OrderBy(d => d.ZIndex).ToList()) foreach (var device in Devices.OrderBy(d => d.ZIndex).ToList())
Devices.Move(Devices.IndexOf(device), device.ZIndex - 1); CanvasViewModels.Move(CanvasViewModels.IndexOf(device), device.ZIndex - 1);
} }
}); });
} }
private void UpdateLeds(object sender, CustomUpdateData customUpdateData) private void UpdateLeds(object sender, CustomUpdateData customUpdateData)
{ {
lock (Devices) lock (CanvasViewModels)
{ {
if (IsInitializing) if (IsInitializing)
IsInitializing = Devices.Any(d => !d.AddedLeds); IsInitializing = Devices.Any(d => !d.AddedLeds);
@ -166,10 +185,82 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
HighlightSelectedLayer.Save(); HighlightSelectedLayer.Save();
PauseRenderingOnFocusLoss.Save(); PauseRenderingOnFocusLoss.Save();
try
{
_updateTrigger.Stop(); _updateTrigger.Stop();
}
catch (NullReferenceException)
{
// TODO: Remove when fixed in RGB.NET, or avoid double stopping
}
base.OnDeactivate(); base.OnDeactivate();
} }
#region Buttons
private void ActivateToolByIndex(int value)
{
switch (value)
{
case 0:
ActiveToolViewModel = new ViewpointMoveToolViewModel(this, _profileEditorService);
break;
case 1:
ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService);
break;
case 2:
ActiveToolViewModel = new SelectionAddToolViewModel(this, _profileEditorService);
break;
case 3:
ActiveToolViewModel = new SelectionRemoveToolViewModel(this, _profileEditorService);
break;
case 4:
ActiveToolViewModel = new EllipseToolViewModel(this, _profileEditorService);
break;
case 5:
ActiveToolViewModel = new RectangleToolViewModel(this, _profileEditorService);
break;
case 6:
ActiveToolViewModel = new PolygonToolViewModel(this, _profileEditorService);
break;
case 7:
ActiveToolViewModel = new FillToolViewModel(this, _profileEditorService);
break;
}
}
public void ResetZoomAndPan()
{
PanZoomViewModel.Reset();
}
#endregion
#region Mouse
public void CanvasMouseDown(object sender, MouseButtonEventArgs e)
{
ActiveToolViewModel?.MouseDown(sender, e);
}
public void CanvasMouseUp(object sender, MouseButtonEventArgs e)
{
ActiveToolViewModel?.MouseUp(sender, e);
}
public void CanvasMouseMove(object sender, MouseEventArgs e)
{
ActiveToolViewModel?.MouseMove(sender, e);
}
public void CanvasMouseWheel(object sender, MouseWheelEventArgs e)
{
ActiveToolViewModel?.MouseWheel(sender, e);
}
#endregion
#region Context menu actions #region Context menu actions
public bool CanApplyToLayer { get; set; } public bool CanApplyToLayer { get; set; }
@ -209,123 +300,23 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
#endregion #endregion
#region Selection #region Keys
private MouseDragStatus _mouseDragStatus; private int _previousTool;
private Point _mouseDragStartPoint; private int _activeToolIndex;
private VisualizationToolViewModel _activeToolViewModel;
// ReSharper disable once UnusedMember.Global - Called from view public void CanvasKeyDown(object sender, KeyEventArgs e)
public void EditorGridMouseClick(object sender, MouseButtonEventArgs e)
{
if (IsPanKeyDown() || e.ChangedButton == MouseButton.Right)
return;
var position = e.GetPosition((IInputElement) sender);
var relative = PanZoomViewModel.GetRelativeMousePosition(sender, e);
if (e.LeftButton == MouseButtonState.Pressed)
StartMouseDrag(position, relative);
else
StopMouseDrag(position);
}
// ReSharper disable once UnusedMember.Global - Called from view
public void EditorGridMouseMove(object sender, MouseEventArgs e)
{
// If holding down Ctrl, pan instead of move/select
if (IsPanKeyDown())
{
Pan(sender, e);
return;
}
var position = e.GetPosition((IInputElement) sender);
if (_mouseDragStatus == MouseDragStatus.Selecting)
UpdateSelection(position);
}
private void StartMouseDrag(Point position, Point relative)
{
_mouseDragStatus = MouseDragStatus.Selecting;
_mouseDragStartPoint = position;
// Any time dragging starts, start with a new rect
SelectionRectangle.Rect = new Rect();
}
private void StopMouseDrag(Point position)
{
var selectedRect = new Rect(_mouseDragStartPoint, position);
foreach (var device in Devices)
{
foreach (var profileLedViewModel in device.Leds)
{
if (PanZoomViewModel.TransformContainingRect(profileLedViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1)).IntersectsWith(selectedRect))
profileLedViewModel.IsSelected = true;
else if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
profileLedViewModel.IsSelected = false;
}
}
_mouseDragStatus = MouseDragStatus.None;
}
private void UpdateSelection(Point position)
{
if (IsPanKeyDown())
return;
var selectedRect = new Rect(_mouseDragStartPoint, position);
SelectionRectangle.Rect = selectedRect;
foreach (var device in Devices)
{
foreach (var profileLedViewModel in device.Leds)
{
if (PanZoomViewModel.TransformContainingRect(profileLedViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1)).IntersectsWith(selectedRect))
profileLedViewModel.IsSelected = true;
else if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
profileLedViewModel.IsSelected = false;
}
}
}
#endregion
#region Panning and zooming
public void EditorGridMouseWheel(object sender, MouseWheelEventArgs e)
{
PanZoomViewModel.ProcessMouseScroll(sender, e);
}
public void EditorGridKeyDown(object sender, KeyEventArgs e)
{ {
_previousTool = ActiveToolIndex;
if ((e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl) && e.IsDown) if ((e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl) && e.IsDown)
Cursor = Cursors.ScrollAll; ActiveToolViewModel = new ViewpointMoveToolViewModel(this, _profileEditorService);
} }
public void EditorGridKeyUp(object sender, KeyEventArgs e) public void CanvasKeyUp(object sender, KeyEventArgs e)
{ {
if ((e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl) && e.IsUp) if ((e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl) && e.IsUp)
Cursor = null; ActivateToolByIndex(_previousTool);
}
public void Pan(object sender, MouseEventArgs e)
{
PanZoomViewModel.ProcessMouseMove(sender, e);
// Empty the selection rect since it's shown while mouse is down
SelectionRectangle.Rect = Rect.Empty;
}
public void ResetZoomAndPan()
{
PanZoomViewModel.Reset();
}
private bool IsPanKeyDown()
{
return Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);
} }
#endregion #endregion
@ -348,11 +339,18 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
if (PauseRenderingOnFocusLoss == null || ScreenState != ScreenState.Active) if (PauseRenderingOnFocusLoss == null || ScreenState != ScreenState.Active)
return; return;
try
{
if (PauseRenderingOnFocusLoss.Value && !message.IsFocused) if (PauseRenderingOnFocusLoss.Value && !message.IsFocused)
_updateTrigger.Stop(); _updateTrigger.Stop();
else if (PauseRenderingOnFocusLoss.Value && message.IsFocused) else if (PauseRenderingOnFocusLoss.Value && message.IsFocused)
_updateTrigger.Start(); _updateTrigger.Start();
} }
catch (NullReferenceException)
{
// TODO: Remove when fixed in RGB.NET, or avoid double stopping
}
}
#endregion #endregion
} }

View File

@ -0,0 +1,48 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools.EllipseToolView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Canvas>
<Canvas.Triggers>
<EventTrigger RoutedEvent="Canvas.MouseLeftButtonDown">
<BeginStoryboard>
<Storyboard TargetName="Preview" TargetProperty="Opacity">
<DoubleAnimation From="0" To="1" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Canvas.MouseLeftButtonUp">
<BeginStoryboard>
<Storyboard TargetName="Preview" TargetProperty="Opacity">
<DoubleAnimation From="1" To="0" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
<Canvas.ContextMenu>
<ContextMenu>
<MenuItem Header="Ellipse action 1" Command="{s:Action CreateLayer}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="LayersPlus" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Ellipse action 2" Command="{s:Action ApplyToLayer}" CommandParameter="{Binding}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Selection" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Canvas.ContextMenu>
<Ellipse Stroke="{DynamicResource PrimaryHueLightBrush}" StrokeThickness="1" IsHitTestVisible="False" x:Name="Preview" Opacity="1" Width="100" Height="100">
<Ellipse.Fill>
<SolidColorBrush Color="{DynamicResource Primary400}" Opacity="0.25" />
</Ellipse.Fill>
</Ellipse>
</Canvas>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
/// <summary>
/// Interaction logic for EllipseToolView.xaml
/// </summary>
public partial class EllipseToolView : UserControl
{
public EllipseToolView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,18 @@
using System.IO;
using System.Windows.Input;
using Artemis.UI.Properties;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
public class EllipseToolViewModel : VisualizationToolViewModel
{
public EllipseToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
{
using (var stream = new MemoryStream(Resources.aero_crosshair))
{
Cursor = new Cursor(stream);
}
}
}
}

View File

@ -0,0 +1,9 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools.FillToolView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
/// <summary>
/// Interaction logic for FillToolView.xaml
/// </summary>
public partial class FillToolView : UserControl
{
public FillToolView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,39 @@
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.UI.Properties;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
public class FillToolViewModel : VisualizationToolViewModel
{
public FillToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
{
using (var stream = new MemoryStream(Resources.aero_fill))
{
Cursor = new Cursor(stream);
}
}
public override void MouseUp(object sender, MouseButtonEventArgs e)
{
base.MouseUp(sender, e);
// Find out if the click is inside a layer and if so, fill it
var position = e.GetPosition((IInputElement) sender);
var panZoomVm = ProfileViewModel.PanZoomViewModel;
var layer = ProfileEditorService.SelectedProfile
.GetAllLayers()
.FirstOrDefault(l => l.Leds.Any(
led => panZoomVm.TransformContainingRect(led.RgbLed.AbsoluteLedRectangle).Contains(position))
);
if (layer != null)
layer.LayerShape = new Fill(layer);
}
}
}

View File

@ -0,0 +1,12 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools.PolygonToolView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
/// <summary>
/// Interaction logic for PolygonToolView.xaml
/// </summary>
public partial class PolygonToolView : UserControl
{
public PolygonToolView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,18 @@
using System.IO;
using System.Windows.Input;
using Artemis.UI.Properties;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
public class PolygonToolViewModel : VisualizationToolViewModel
{
public PolygonToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
{
using (var stream = new MemoryStream(Resources.aero_crosshair))
{
Cursor = new Cursor(stream);
}
}
}
}

View File

@ -0,0 +1,12 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools.RectangleToolView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
/// <summary>
/// Interaction logic for RectangleToolView.xaml
/// </summary>
public partial class RectangleToolView : UserControl
{
public RectangleToolView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,18 @@
using System.IO;
using System.Windows.Input;
using Artemis.UI.Properties;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
public class RectangleToolViewModel : VisualizationToolViewModel
{
public RectangleToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
{
using (var stream = new MemoryStream(Resources.aero_crosshair))
{
Cursor = new Cursor(stream);
}
}
}
}

View File

@ -0,0 +1,12 @@
<UserControl x:Class="Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools.SelectionAddToolView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
/// <summary>
/// Interaction logic for SelectionAddToolView.xaml
/// </summary>
public partial class SelectionAddToolView : UserControl
{
public SelectionAddToolView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,36 @@
using System.IO;
using System.Windows;
using System.Windows.Input;
using Artemis.UI.Properties;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
public class SelectionAddToolViewModel : VisualizationToolViewModel
{
public SelectionAddToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
{
using (var stream = new MemoryStream(Resources.aero_pen_plus))
{
Cursor = new Cursor(stream);
}
}
public override void MouseUp(object sender, MouseButtonEventArgs e)
{
base.MouseUp(sender, e);
var position = e.GetPosition((IInputElement) sender);
var selectedRect = new Rect(MouseDownStartPosition, position);
foreach (var device in ProfileViewModel.Devices)
{
foreach (var ledViewModel in device.Leds)
{
if (ProfileViewModel.PanZoomViewModel.TransformContainingRect(ledViewModel.Led.RgbLed.AbsoluteLedRectangle).IntersectsWith(selectedRect))
ledViewModel.IsSelected = true;
}
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More