mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Removed separate shape size
This commit is contained in:
1 parent
f528e882c4
commit
c0957a3075
34 files changed
+81
-862
No files matched your search
@@ -1,7 +1,6 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.LayerShapes;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.UI.Services.Interfaces
|
||||
@@ -22,13 +21,6 @@ namespace Artemis.UI.Services.Interfaces
|
||||
/// <returns></returns>
|
||||
Point GetLayerAnchorPosition(Layer layer);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the layer shape's bounds, corrected for the current render scale.
|
||||
/// </summary>
|
||||
/// <param name="layerShape"></param>
|
||||
/// <returns></returns>
|
||||
Rect GetLayerShapeBounds(LayerShape layerShape);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a WPF transform group that contains all the transformations required to render the provided layer.
|
||||
/// Note: Run on UI thread.
|
||||
@@ -47,14 +39,6 @@ namespace Artemis.UI.Services.Interfaces
|
||||
/// <returns></returns>
|
||||
SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base properties of the given shape to match the provided unscaled rectangle. The rectangle is corrected
|
||||
/// for the current render scale, anchor property and size property.
|
||||
/// </summary>
|
||||
/// <param name="layerShape"></param>
|
||||
/// <param name="rect"></param>
|
||||
void SetShapeBaseFromRectangle(LayerShape layerShape, Rect rect);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new point scaled to the layer.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.LayerShapes;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using SkiaSharp;
|
||||
@@ -33,28 +31,14 @@ namespace Artemis.UI.Services
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rect GetLayerShapeBounds(LayerShape layerShape)
|
||||
{
|
||||
// Adjust the render rectangle for the difference in render scale
|
||||
var renderScale = _settingsService.GetSetting("Core.RenderScale", 1.0).Value;
|
||||
return new Rect(
|
||||
layerShape.Bounds.Left / renderScale * 1,
|
||||
layerShape.Bounds.Top / renderScale * 1,
|
||||
Math.Max(0, layerShape.Bounds.Width / renderScale * 1),
|
||||
Math.Max(0, layerShape.Bounds.Height / renderScale * 1)
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Point GetLayerAnchorPosition(Layer layer)
|
||||
{
|
||||
var layerBounds = GetLayerBounds(layer);
|
||||
var shapeBounds = GetLayerShapeBounds(layer.LayerShape).ToSKRect();
|
||||
var layerBounds = GetLayerBounds(layer).ToSKRect();
|
||||
var positionProperty = layer.PositionProperty.CurrentValue;
|
||||
|
||||
// Start at the center of the shape
|
||||
var position = new Point(shapeBounds.MidX, shapeBounds.MidY);
|
||||
var position = new Point(layerBounds.MidX, layerBounds.MidY);
|
||||
|
||||
// Apply translation
|
||||
position.X += positionProperty.X * layerBounds.Width;
|
||||
@@ -67,7 +51,6 @@ namespace Artemis.UI.Services
|
||||
public TransformGroup GetLayerTransformGroup(Layer layer)
|
||||
{
|
||||
var layerBounds = GetLayerBounds(layer).ToSKRect();
|
||||
var shapeBounds = GetLayerShapeBounds(layer.LayerShape).ToSKRect();
|
||||
|
||||
// Apply transformation like done by the core during layer rendering.
|
||||
// The order in which translations are applied are different because the UI renders the shape inside
|
||||
@@ -77,8 +60,8 @@ namespace Artemis.UI.Services
|
||||
var anchorProperty = layer.AnchorPointProperty.CurrentValue;
|
||||
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = anchorPosition.X - shapeBounds.MidX - anchorProperty.X * layerBounds.Width;
|
||||
var y = anchorPosition.Y - shapeBounds.MidY - anchorProperty.Y * layerBounds.Height;
|
||||
var x = anchorPosition.X - layerBounds.MidX - anchorProperty.X * layerBounds.Width;
|
||||
var y = anchorPosition.Y - layerBounds.MidY - anchorProperty.Y * layerBounds.Height;
|
||||
|
||||
var transformGroup = new TransformGroup();
|
||||
transformGroup.Children.Add(new TranslateTransform(x, y));
|
||||
@@ -92,18 +75,17 @@ namespace Artemis.UI.Services
|
||||
public SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation)
|
||||
{
|
||||
var layerBounds = GetLayerBounds(layer).ToSKRect();
|
||||
var shapeBounds = GetLayerShapeBounds(layer.LayerShape).ToSKRect();
|
||||
|
||||
// Apply transformation like done by the core during layer rendering (same differences apply as in GetLayerTransformGroup)
|
||||
var anchorPosition = GetLayerAnchorPosition(layer).ToSKPoint();
|
||||
var anchorProperty = layer.AnchorPointProperty.CurrentValue;
|
||||
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = anchorPosition.X - shapeBounds.MidX - anchorProperty.X * layerBounds.Width;
|
||||
var y = anchorPosition.Y - shapeBounds.MidY - anchorProperty.Y * layerBounds.Height;
|
||||
var x = anchorPosition.X - layerBounds.MidX - anchorProperty.X * layerBounds.Width;
|
||||
var y = anchorPosition.Y - layerBounds.MidY - anchorProperty.Y * layerBounds.Height;
|
||||
|
||||
var path = new SKPath();
|
||||
path.AddRect(shapeBounds);
|
||||
path.AddRect(layerBounds);
|
||||
if (includeTranslation)
|
||||
path.Transform(SKMatrix.MakeTranslation(x, y));
|
||||
if (includeScale)
|
||||
@@ -114,46 +96,6 @@ namespace Artemis.UI.Services
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetShapeBaseFromRectangle(LayerShape layerShape, Rect rect)
|
||||
{
|
||||
if (!layerShape.Layer.Leds.Any())
|
||||
{
|
||||
layerShape.ScaledRectangle = SKRect.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
var layerBounds = GetLayerBounds(layerShape.Layer).ToSKRect();
|
||||
var shapeBounds = GetLayerShapeBounds(layerShape).ToSKRect();
|
||||
|
||||
var rectangle = SKRect.Create(
|
||||
(float) rect.Left - layerBounds.Left,
|
||||
(float) rect.Top - layerBounds.Top,
|
||||
(float) rect.Width,
|
||||
(float) rect.Height
|
||||
);
|
||||
|
||||
// Adjust the provided rect for the difference in render scale
|
||||
var anchorPosition = GetLayerAnchorPosition(layerShape.Layer).ToSKPoint();
|
||||
var anchorProperty = layerShape.Layer.AnchorPointProperty.CurrentValue;
|
||||
var sizeProperty = layerShape.Layer.SizeProperty.CurrentValue;
|
||||
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = anchorPosition.X - shapeBounds.MidX - anchorProperty.X * layerBounds.Width;
|
||||
var y = anchorPosition.Y - shapeBounds.MidY - anchorProperty.Y * layerBounds.Height;
|
||||
rectangle.Offset(x * -1, y * -1);
|
||||
|
||||
// TODO: Determine the new position of the anchor and scale the rectangle to the current scale
|
||||
|
||||
layerShape.ScaledRectangle = SKRect.Create(
|
||||
rectangle.Left / layerBounds.Width,
|
||||
rectangle.Top / layerBounds.Height,
|
||||
rectangle.Width / layerBounds.Width,
|
||||
rectangle.Height / layerBounds.Height
|
||||
);
|
||||
layerShape.CalculateRenderProperties();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public SKPoint GetScaledPoint(Layer layer, SKPoint point, bool absolute)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user