mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Core - Simplified and improved render scaling
This commit is contained in:
1 parent
18359c443f
commit
186d012087
10 files changed
+63
-99
No files matched your search
@@ -14,8 +14,8 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public class ArtemisDevice : CorePropertyChanged
|
||||
{
|
||||
private SKPath? _renderPath;
|
||||
private SKRect _renderRectangle;
|
||||
private SKPath? _path;
|
||||
private SKRect _rectangle;
|
||||
|
||||
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider, ArtemisSurface surface)
|
||||
{
|
||||
@@ -58,21 +58,21 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rectangle covering the device, sized to match the render scale
|
||||
/// Gets the rectangle covering the device
|
||||
/// </summary>
|
||||
public SKRect RenderRectangle
|
||||
public SKRect Rectangle
|
||||
{
|
||||
get => _renderRectangle;
|
||||
private set => SetAndNotify(ref _renderRectangle, value);
|
||||
get => _rectangle;
|
||||
private set => SetAndNotify(ref _rectangle, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path surrounding the device, sized to match the render scale
|
||||
/// Gets the path surrounding the device
|
||||
/// </summary>
|
||||
public SKPath? RenderPath
|
||||
public SKPath? Path
|
||||
{
|
||||
get => _renderPath;
|
||||
private set => SetAndNotify(ref _renderPath, value);
|
||||
get => _path;
|
||||
private set => SetAndNotify(ref _path, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -239,24 +239,18 @@ namespace Artemis.Core
|
||||
|
||||
internal void CalculateRenderProperties()
|
||||
{
|
||||
RenderRectangle = SKRect.Create(
|
||||
(RgbDevice.Location.X * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.Location.Y * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.DeviceRectangle.Size.Width * Surface.Scale).RoundToInt(),
|
||||
(RgbDevice.DeviceRectangle.Size.Height * Surface.Scale).RoundToInt()
|
||||
);
|
||||
|
||||
Rectangle = RgbDevice.DeviceRectangle.ToSKRect();
|
||||
if (!Leds.Any())
|
||||
return;
|
||||
|
||||
foreach (ArtemisLed led in Leds)
|
||||
led.CalculateRenderRectangle();
|
||||
led.CalculateRectangles();
|
||||
|
||||
SKPath path = new SKPath {FillType = SKPathFillType.Winding};
|
||||
foreach (ArtemisLed artemisLed in Leds)
|
||||
path.AddRect(artemisLed.AbsoluteRenderRectangle);
|
||||
path.AddRect(artemisLed.AbsoluteRectangle);
|
||||
|
||||
RenderPath = path;
|
||||
Path = path;
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
@@ -8,14 +8,14 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public class ArtemisLed : CorePropertyChanged
|
||||
{
|
||||
private SKRect _absoluteRenderRectangle;
|
||||
private SKRect _renderRectangle;
|
||||
private SKRect _absoluteRectangle;
|
||||
private SKRect _rectangle;
|
||||
|
||||
internal ArtemisLed(Led led, ArtemisDevice device)
|
||||
{
|
||||
RgbLed = led;
|
||||
Device = device;
|
||||
CalculateRenderRectangle();
|
||||
CalculateRectangles();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,38 +29,27 @@ namespace Artemis.Core
|
||||
public ArtemisDevice Device { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rectangle covering the LED, sized to match the render scale and positioned relative to the
|
||||
/// <see cref="Device" />
|
||||
/// Gets the rectangle covering the LED positioned relative to the<see cref="Device" />
|
||||
/// </summary>
|
||||
public SKRect RenderRectangle
|
||||
public SKRect Rectangle
|
||||
{
|
||||
get => _renderRectangle;
|
||||
private set => SetAndNotify(ref _renderRectangle, value);
|
||||
get => _rectangle;
|
||||
private set => SetAndNotify(ref _rectangle, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rectangle covering the LED, sized to match the render scale
|
||||
/// Gets the rectangle covering the LED
|
||||
/// </summary>
|
||||
public SKRect AbsoluteRenderRectangle
|
||||
public SKRect AbsoluteRectangle
|
||||
{
|
||||
get => _absoluteRenderRectangle;
|
||||
private set => SetAndNotify(ref _absoluteRenderRectangle, value);
|
||||
get => _absoluteRectangle;
|
||||
private set => SetAndNotify(ref _absoluteRectangle, value);
|
||||
}
|
||||
|
||||
internal void CalculateRenderRectangle()
|
||||
internal void CalculateRectangles()
|
||||
{
|
||||
RenderRectangle = SKRect.Create(
|
||||
(RgbLed.LedRectangle.Location.X * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.LedRectangle.Location.Y * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.LedRectangle.Size.Width * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.LedRectangle.Size.Height * Device.Surface.Scale).RoundToInt()
|
||||
);
|
||||
AbsoluteRenderRectangle = SKRect.Create(
|
||||
(RgbLed.AbsoluteLedRectangle.Location.X * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.AbsoluteLedRectangle.Location.Y * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.AbsoluteLedRectangle.Size.Width * Device.Surface.Scale).RoundToInt(),
|
||||
(RgbLed.AbsoluteLedRectangle.Size.Height * Device.Surface.Scale).RoundToInt()
|
||||
);
|
||||
Rectangle = RgbLed.LedRectangle.ToSKRect();
|
||||
AbsoluteRectangle = RgbLed.AbsoluteLedRectangle.ToSKRect();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -16,28 +16,25 @@ namespace Artemis.Core
|
||||
private ReadOnlyDictionary<Led, ArtemisLed> _ledMap = new ReadOnlyDictionary<Led, ArtemisLed>(new Dictionary<Led, ArtemisLed>());
|
||||
private bool _isActive;
|
||||
private string _name;
|
||||
private double _scale;
|
||||
|
||||
internal ArtemisSurface(RGBSurface rgbSurface, string name, double scale)
|
||||
internal ArtemisSurface(RGBSurface rgbSurface, string name)
|
||||
{
|
||||
SurfaceEntity = new SurfaceEntity {DeviceEntities = new List<DeviceEntity>()};
|
||||
EntityId = Guid.NewGuid();
|
||||
RgbSurface = rgbSurface;
|
||||
|
||||
_name = name;
|
||||
_scale = scale;
|
||||
_isActive = false;
|
||||
|
||||
ApplyToEntity();
|
||||
}
|
||||
|
||||
internal ArtemisSurface(RGBSurface rgbSurface, SurfaceEntity surfaceEntity, double scale)
|
||||
internal ArtemisSurface(RGBSurface rgbSurface, SurfaceEntity surfaceEntity)
|
||||
{
|
||||
SurfaceEntity = surfaceEntity;
|
||||
EntityId = surfaceEntity.Id;
|
||||
RgbSurface = rgbSurface;
|
||||
|
||||
_scale = scale;
|
||||
_name = surfaceEntity.Name;
|
||||
_isActive = surfaceEntity.IsActive;
|
||||
}
|
||||
@@ -47,15 +44,6 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public RGBSurface RgbSurface { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scale at which this surface is rendered
|
||||
/// </summary>
|
||||
public double Scale
|
||||
{
|
||||
get => _scale;
|
||||
private set => SetAndNotify(ref _scale, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the surface
|
||||
/// </summary>
|
||||
@@ -96,19 +84,6 @@ namespace Artemis.Core
|
||||
internal SurfaceEntity SurfaceEntity { get; set; }
|
||||
internal Guid EntityId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Updates the scale of the surface
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public void UpdateScale(double value)
|
||||
{
|
||||
Scale = value;
|
||||
foreach (ArtemisDevice device in Devices)
|
||||
device.CalculateRenderProperties();
|
||||
|
||||
OnScaleChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="Led" />
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user