Updated for RGB.NET's changes regarding rotation

This commit is contained in:
SpoinkyNL committed 2019-11-21 08:45:38 +01:00
1 parent 97907c97eb
commit 086f2fc1f9
19 files changed
+175 -88

No files matched your search

+46 -1
View File
@@ -1,10 +1,16 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile.Abstract;
using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Interfaces;
using Artemis.Core.Services.Interfaces;
using Artemis.Storage.Entities.Profile;
using Device = Artemis.Core.Models.Surface.Device;
namespace Artemis.Core.Models.Profile
{
@@ -18,6 +24,7 @@ namespace Artemis.Core.Models.Profile
Profile = profile;
ParentFolder = folder;
Name = name;
Leds = new List<DeviceLed>();
}
internal Layer(Profile profile, Folder folder, LayerEntity layerEntity, IPluginService pluginService)
@@ -28,6 +35,7 @@ namespace Artemis.Core.Models.Profile
Profile = profile;
ParentFolder = folder;
LayerType = pluginService.GetLayerTypeByGuid(layerEntity.LayerTypeGuid);
Leds = new List<DeviceLed>();
}
internal LayerEntity LayerEntity { get; set; }
@@ -36,9 +44,13 @@ namespace Artemis.Core.Models.Profile
public Profile Profile { get; }
public Folder ParentFolder { get; }
public List<DeviceLed> Leds { get; private set; }
public LayerType LayerType { get; private set; }
public ILayerTypeConfiguration LayerTypeConfiguration { get; set; }
public Rectangle RenderRectangle { get; set; }
public GraphicsPath RenderPath { get; set; }
public override void Update(double deltaTime)
{
if (LayerType == null)
@@ -71,10 +83,22 @@ namespace Artemis.Core.Models.Profile
LayerEntity.Name = Name;
LayerEntity.ProfileId = Profile.EntityId;
// TODO: LEDs, conditions, elements
}
public void ApplySurface(Surface.Surface surface)
{
var leds = new List<DeviceLed>();
foreach (var surfaceDevice in surface.Devices)
{
var deviceHash = surfaceDevice.RgbDevice.GetDeviceHashCode();
leds.AddRange(surfaceDevice.Leds.Where(dl => LayerEntity.Leds.Any(l => l.DeviceHash == deviceHash && l.LedName == dl.RgbLed.ToString())));
}
Leds = leds;
CalculateRenderProperties();
}
public void UpdateLayerType(LayerType layerType)
{
if (LayerType != null)
@@ -88,6 +112,27 @@ namespace Artemis.Core.Models.Profile
LayerType = layerType;
}
internal void CalculateRenderProperties()
{
if (!Leds.Any())
{
// TODO: Create an empty rectangle and path
return;
}
// Determine to top-left and bottom-right
var minX = Leds.Min(l => l.AbsoluteRenderRectangle.X);
var minY = Leds.Min(l => l.AbsoluteRenderRectangle.Y);
var maxX = Leds.Max(l => l.AbsoluteRenderRectangle.X);
var maxY = Leds.Max(l => l.AbsoluteRenderRectangle.Y);
RenderRectangle = new Rectangle(minX, minY, maxX - minX, maxY - minY);
var path = new GraphicsPath();
path.AddRectangles(Leds.Select(l => l.AbsoluteRenderRectangle).ToArray());
RenderPath = path;
}
public override string ToString()
{
return $"{nameof(Profile)}: {Profile}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
@@ -139,5 +139,11 @@ namespace Artemis.Core.Models.Profile
}
#endregion
public void ApplySurface(Surface.Surface surface)
{
foreach (var layer in GetAllLayers())
layer.ApplySurface(surface);
}
}
}
+6 -3
View File
@@ -24,7 +24,7 @@ namespace Artemis.Core.Models.Surface
ZIndex = 1;
ApplyToEntity();
CalculateRenderRectangle();
CalculateRenderProperties();
}
internal Device(IRGBDevice rgbDevice, Plugin plugin, Surface surface, DeviceEntity deviceEntity)
@@ -78,10 +78,12 @@ namespace Artemis.Core.Models.Surface
internal void ApplyToRgbDevice()
{
RgbDevice.Location = new Point(DeviceEntity.X, DeviceEntity.Y);
CalculateRenderRectangle();
RgbDevice.Rotation = DeviceEntity.Rotation;
CalculateRenderProperties();
}
internal void CalculateRenderRectangle()
internal void CalculateRenderProperties()
{
RenderRectangle = new Rectangle(
(int) Math.Round(RgbDevice.Location.X * Surface.Scale, MidpointRounding.AwayFromZero),
@@ -98,6 +100,7 @@ namespace Artemis.Core.Models.Surface
var path = new GraphicsPath();
path.AddRectangles(Leds.Select(l => l.AbsoluteRenderRectangle).ToArray());
path.FillMode = FillMode.Winding;
RenderPath = path;
}
@@ -0,0 +1,38 @@
using System;
using RGB.NET.Core;
using Rectangle = System.Drawing.Rectangle;
namespace Artemis.Core.Models.Surface
{
public class DeviceLed
{
public DeviceLed(Led led, Device device)
{
RgbLed = led;
Device = device;
CalculateRenderRectangle();
}
public Led RgbLed { get; }
public Device Device { get; }
public Rectangle RenderRectangle { get; private set; }
public Rectangle AbsoluteRenderRectangle { get; private set; }
public void CalculateRenderRectangle()
{
RenderRectangle = new Rectangle(
(int) Math.Round(RgbLed.LedRectangle.Location.X * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.LedRectangle.Location.Y * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.LedRectangle.Size.Width * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.LedRectangle.Size.Height * Device.Surface.Scale, MidpointRounding.AwayFromZero)
);
AbsoluteRenderRectangle = new Rectangle(
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Location.X * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Location.Y * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Size.Width * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Size.Height * Device.Surface.Scale, MidpointRounding.AwayFromZero)
);
}
}
}
-38
View File
@@ -1,38 +0,0 @@
using System;
using RGB.NET.Core;
using Rectangle = System.Drawing.Rectangle;
namespace Artemis.Core.Models.Surface
{
public class DeviceLed
{
public DeviceLed(Led led, Device device)
{
RgbLed = led;
Device = device;
CalculateRenderRectangle();
}
public Led RgbLed { get; }
public Device Device { get; }
public Rectangle RenderRectangle { get; private set; }
public Rectangle AbsoluteRenderRectangle { get; private set; }
public void CalculateRenderRectangle()
{
RenderRectangle = new Rectangle(
(int) Math.Round(RgbLed.LedRectangle.X * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.LedRectangle.Y * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.LedRectangle.Width * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.LedRectangle.Height * Device.Surface.Scale, MidpointRounding.AwayFromZero)
);
AbsoluteRenderRectangle = new Rectangle(
(int) Math.Round(RgbLed.AbsoluteLedRectangle.X * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Y * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Width * Device.Surface.Scale, MidpointRounding.AwayFromZero),
(int) Math.Round(RgbLed.AbsoluteLedRectangle.Height * Device.Surface.Scale, MidpointRounding.AwayFromZero)
);
}
}
}
+1 -1
View File
@@ -65,7 +65,7 @@ namespace Artemis.Core.Models.Surface
{
Scale = value;
foreach (var device in Devices)
device.CalculateRenderRectangle();
device.CalculateRenderProperties();
OnScaleChanged();
}