mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Simplified the different properties used for layer/shape rendering
Cleaned up UI layer shape service
This commit is contained in:
1 parent
f57aca3475
commit
fd9dd626f8
17 files changed
+192
-284
No files matched your search
+1
-1
@@ -44,7 +44,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
||||
{
|
||||
LayerPropertyViewModel.LayerProperty.SetCurrentValue(value, ProfileEditorService.CurrentTime);
|
||||
// Force the keyframe engine to update, the edited keyframe might affect the current keyframe progress
|
||||
LayerPropertyViewModel.LayerProperty.KeyframeEngine.Update(0);
|
||||
LayerPropertyViewModel.LayerProperty.KeyframeEngine?.Update(0);
|
||||
|
||||
ProfileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
@@ -32,32 +32,35 @@
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Canvas Style="{StaticResource SelectedStyle}">
|
||||
<!-- The part of the layer's shape that falls outside the layer -->
|
||||
<Path Data="{Binding ShapeGeometry, Mode=OneWay}">
|
||||
<Path.Fill>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.05" />
|
||||
</Path.Fill>
|
||||
<Path.Stroke>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.15" />
|
||||
</Path.Stroke>
|
||||
</Path>
|
||||
<!-- The shape is inside the layer's bounds -->
|
||||
<Canvas Canvas.Left="{Binding LayerBounds.X}" Canvas.Top="{Binding LayerBounds.Y}">
|
||||
<!-- The part of the layer's shape that falls outside the layer -->
|
||||
<Path Data="{Binding ShapeGeometry, Mode=OneWay}">
|
||||
<Path.Fill>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.05" />
|
||||
</Path.Fill>
|
||||
<Path.Stroke>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.15" />
|
||||
</Path.Stroke>
|
||||
</Path>
|
||||
|
||||
<!-- The part of the layer's shape that is inside the layer -->
|
||||
<Path Data="{Binding ShapeGeometry, Mode=OneWay}">
|
||||
<Path.Fill>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.15" />
|
||||
</Path.Fill>
|
||||
<Path.Stroke>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" />
|
||||
</Path.Stroke>
|
||||
<Path.OpacityMask>
|
||||
<VisualBrush Viewport="{Binding ViewportRectangle}" ViewportUnits="Absolute">
|
||||
<VisualBrush.Visual>
|
||||
<Path Data="{Binding LayerGeometry, Mode=OneWay}" ClipToBounds="False" Fill="Black" />
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</Path.OpacityMask>
|
||||
</Path>
|
||||
<!-- The part of the layer's shape that is inside the layer -->
|
||||
<Path Data="{Binding ShapeGeometry, Mode=OneWay}">
|
||||
<Path.Fill>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.15" />
|
||||
</Path.Fill>
|
||||
<Path.Stroke>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" />
|
||||
</Path.Stroke>
|
||||
<Path.OpacityMask>
|
||||
<VisualBrush Viewport="{Binding ViewportRectangle}" ViewportUnits="Absolute">
|
||||
<VisualBrush.Visual>
|
||||
<Path Data="{Binding LayerGeometry, Mode=OneWay}" ClipToBounds="False" Fill="Black" />
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</Path.OpacityMask>
|
||||
</Path>
|
||||
</Canvas>
|
||||
|
||||
<Path Data="{Binding LayerGeometry, Mode=OneWay}" ClipToBounds="False" StrokeThickness="1.5" StrokeLineJoin="Round" x:Name="LayerPath">
|
||||
<Path.Stroke>
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
public Layer Layer { get; }
|
||||
|
||||
public Rect LayerBounds { get; set; }
|
||||
public Geometry LayerGeometry { get; set; }
|
||||
public Geometry OpacityGeometry { get; set; }
|
||||
public Geometry ShapeGeometry { get; set; }
|
||||
@@ -55,6 +56,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
{
|
||||
if (!Layer.Leds.Any())
|
||||
{
|
||||
LayerBounds = Rect.Empty;
|
||||
LayerGeometry = Geometry.Empty;
|
||||
OpacityGeometry = Geometry.Empty;
|
||||
ViewportRectangle = Rect.Empty;
|
||||
@@ -91,6 +93,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
var layerGeometry = group.GetOutlinedPathGeometry();
|
||||
var opacityGeometry = Geometry.Combine(Geometry.Empty, layerGeometry, GeometryCombineMode.Exclude, new TranslateTransform());
|
||||
|
||||
LayerBounds = _layerEditorService.GetLayerBounds(Layer);
|
||||
LayerGeometry = layerGeometry;
|
||||
OpacityGeometry = opacityGeometry;
|
||||
}
|
||||
@@ -105,27 +108,27 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
var rect = _layerEditorService.GetShapeUntransformedRect(Layer.LayerShape);
|
||||
var bounds = _layerEditorService.GetLayerShapeBounds(Layer.LayerShape);
|
||||
var shapeGeometry = Geometry.Empty;
|
||||
switch (Layer.LayerShape)
|
||||
{
|
||||
case Ellipse _:
|
||||
shapeGeometry = new EllipseGeometry(rect);
|
||||
shapeGeometry = new EllipseGeometry(bounds);
|
||||
break;
|
||||
case Fill _:
|
||||
// Shape originates from the center so compensate the geometry for that, create a copy
|
||||
shapeGeometry = LayerGeometry.Clone();
|
||||
// Add a transformation
|
||||
shapeGeometry.Transform = new TranslateTransform(rect.Left - shapeGeometry.Bounds.Left, rect.Top - shapeGeometry.Bounds.Top);
|
||||
shapeGeometry.Transform = new TranslateTransform(bounds.Left - shapeGeometry.Bounds.Left, bounds.Top - shapeGeometry.Bounds.Top);
|
||||
// Apply the transformation so that it won't be overridden
|
||||
shapeGeometry = shapeGeometry.GetOutlinedPathGeometry();
|
||||
break;
|
||||
case Polygon _:
|
||||
// TODO
|
||||
shapeGeometry = new RectangleGeometry(rect);
|
||||
shapeGeometry = new RectangleGeometry(bounds);
|
||||
break;
|
||||
case Rectangle _:
|
||||
shapeGeometry = new RectangleGeometry(rect);
|
||||
shapeGeometry = new RectangleGeometry(bounds);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type local:EditToolViewModel}}">
|
||||
<Canvas UseLayoutRounding="False">
|
||||
<userControls:LayerShapeControl Zoom="{Binding ProfileViewModel.PanZoomViewModel.Zoom}"
|
||||
<userControls:LayerShapeControl Canvas.Left="{Binding LayerBounds.Left}"
|
||||
Canvas.Top="{Binding LayerBounds.Top}"
|
||||
Zoom="{Binding ProfileViewModel.PanZoomViewModel.Zoom}"
|
||||
ShapePath="{Binding ShapePath}"
|
||||
ShapeAnchor="{Binding ShapeAnchor}"
|
||||
ShapeGeometry="{Binding ShapeGeometry}"
|
||||
|
||||
+9
-7
@@ -33,6 +33,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
profileEditorService.ProfilePreviewUpdated += (sender, args) => Update();
|
||||
}
|
||||
|
||||
public Rect LayerBounds { get; set; }
|
||||
public SKPath ShapePath { get; set; }
|
||||
public SKPoint ShapeAnchor { get; set; }
|
||||
public RectangleGeometry ShapeGeometry { get; set; }
|
||||
@@ -42,11 +43,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
if (!(ProfileEditorService.SelectedProfileElement is Layer layer))
|
||||
return;
|
||||
|
||||
LayerBounds = _layerEditorService.GetLayerBounds(layer);
|
||||
ShapePath = _layerEditorService.GetLayerPath(layer, true, true, true);
|
||||
ShapeAnchor = _layerEditorService.GetLayerAnchor(layer, true);
|
||||
ShapeAnchor = _layerEditorService.GetLayerAnchor(layer).ToSKPoint();
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
var shapeGeometry = new RectangleGeometry(_layerEditorService.GetShapeUntransformedRect(layer.LayerShape))
|
||||
var shapeGeometry = new RectangleGeometry(_layerEditorService.GetLayerShapeBounds(layer.LayerShape))
|
||||
{
|
||||
Transform = _layerEditorService.GetLayerTransformGroup(layer)
|
||||
};
|
||||
@@ -57,7 +59,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
// Store the last top-left for easy later on
|
||||
_topLeft = _layerEditorService.GetLayerPath(layer, true, true, true).Points[0];
|
||||
}
|
||||
|
||||
|
||||
#region Rotation
|
||||
|
||||
private bool _rotating;
|
||||
@@ -67,7 +69,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
_rotating = true;
|
||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||
_previousDragAngle = CalculateAngle(_layerEditorService.GetLayerAnchor(layer, true), GetRelativePosition(sender, e.MouseEventArgs).ToSKPoint());
|
||||
_previousDragAngle = CalculateAngle(_layerEditorService.GetLayerAnchor(layer), GetRelativePosition(sender, e.MouseEventArgs));
|
||||
else
|
||||
_previousDragAngle = 0;
|
||||
}
|
||||
@@ -84,7 +86,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
|
||||
var previousDragAngle = _previousDragAngle;
|
||||
var newRotation = CalculateAngle(_layerEditorService.GetLayerAnchor(layer, true), GetRelativePosition(sender, e.MouseEventArgs).ToSKPoint());
|
||||
var newRotation = CalculateAngle(_layerEditorService.GetLayerAnchor(layer), GetRelativePosition(sender, e.MouseEventArgs));
|
||||
_previousDragAngle = newRotation;
|
||||
|
||||
// Allow the user to rotate the shape in increments of 5
|
||||
@@ -278,7 +280,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
// Measure from the top-left of the shape (without rotation)
|
||||
_dragOffset = topLeft + (dragStartPosition - topLeft);
|
||||
// Get the absolute layer anchor and make it relative to the unrotated shape
|
||||
_dragStartAnchor = _layerEditorService.GetLayerAnchor(layer, true) - topLeft;
|
||||
_dragStartAnchor = _layerEditorService.GetLayerAnchor(layer).ToSKPoint() - topLeft;
|
||||
// Ensure the anchor starts in the center of the shape it is now relative to
|
||||
_dragStartAnchor.X -= path.Bounds.Width / 2f;
|
||||
_dragStartAnchor.Y -= path.Bounds.Height / 2f;
|
||||
@@ -390,7 +392,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return mouseEventArgs.GetPosition((IInputElement) parent);
|
||||
}
|
||||
|
||||
private float CalculateAngle(SKPoint start, SKPoint arrival)
|
||||
private float CalculateAngle(Point start, Point arrival)
|
||||
{
|
||||
var radian = (float) Math.Atan2(start.Y - arrival.Y, start.X - arrival.X);
|
||||
var angle = radian * (180f / (float) Math.PI);
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
layer.LayerShape = new Fill(layer);
|
||||
|
||||
// Apply the full layer rectangle
|
||||
_layerEditorService.SetShapeBaseFromRectangle(layer.LayerShape, _layerEditorService.GetLayerRect(layer));
|
||||
_layerEditorService.SetShapeBaseFromRectangle(layer.LayerShape, _layerEditorService.GetLayerBounds(layer));
|
||||
ProfileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,121 +21,56 @@ namespace Artemis.UI.Services
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rect GetLayerRenderRect(Layer layer)
|
||||
public Rect GetLayerBounds(Layer layer)
|
||||
{
|
||||
// Adjust the render rectangle for the difference in render scale
|
||||
var renderScale = _settingsService.GetSetting("Core.RenderScale", 1.0).Value;
|
||||
return new Rect(
|
||||
layer.Rectangle.Left / renderScale * 1,
|
||||
layer.Rectangle.Top / renderScale * 1,
|
||||
Math.Max(0, layer.Rectangle.Width / renderScale * 1),
|
||||
Math.Max(0, layer.Rectangle.Height / renderScale * 1)
|
||||
layer.Bounds.Left / renderScale * 1,
|
||||
layer.Bounds.Top / renderScale * 1,
|
||||
Math.Max(0, layer.Bounds.Width / renderScale * 1),
|
||||
Math.Max(0, layer.Bounds.Height / renderScale * 1)
|
||||
);
|
||||
}
|
||||
|
||||
public Rect GetLayerRect(Layer layer)
|
||||
/// <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(
|
||||
layer.AbsoluteRectangle.Left / renderScale * 1,
|
||||
layer.AbsoluteRectangle.Top / renderScale * 1,
|
||||
Math.Max(0, layer.AbsoluteRectangle.Width / renderScale * 1),
|
||||
Math.Max(0, layer.AbsoluteRectangle.Height / renderScale * 1)
|
||||
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 SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation)
|
||||
public Point GetLayerAnchor(Layer layer)
|
||||
{
|
||||
var layerRect = GetLayerRenderRect(layer).ToSKRect();
|
||||
var shapeRect = GetShapeUntransformedRect(layer.LayerShape).ToSKRect();
|
||||
|
||||
// Apply transformation like done by the core during layer rendering
|
||||
var anchor = GetLayerAnchor(layer, true);
|
||||
var relativeAnchor = GetLayerAnchor(layer, false);
|
||||
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = layer.PositionProperty.CurrentValue.X * layerRect.Width - shapeRect.Width / 2 - relativeAnchor.X;
|
||||
var y = layer.PositionProperty.CurrentValue.Y * layerRect.Height - shapeRect.Height / 2 - relativeAnchor.Y;
|
||||
|
||||
var path = new SKPath();
|
||||
path.AddRect(shapeRect);
|
||||
if (includeTranslation)
|
||||
path.Transform(SKMatrix.MakeTranslation(x, y));
|
||||
if (includeScale)
|
||||
path.Transform(SKMatrix.MakeScale(layer.SizeProperty.CurrentValue.Width, layer.SizeProperty.CurrentValue.Height, anchor.X, anchor.Y));
|
||||
if (includeRotation)
|
||||
path.Transform(SKMatrix.MakeRotationDegrees(layer.RotationProperty.CurrentValue, anchor.X, anchor.Y));
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public void ReverseLayerPath(Layer layer, SKPath path)
|
||||
{
|
||||
var layerRect = GetLayerRenderRect(layer).ToSKRect();
|
||||
var shapeRect = GetShapeUntransformedRect(layer.LayerShape).ToSKRect();
|
||||
|
||||
// Apply transformation like done by the core during layer rendering
|
||||
var anchor = GetLayerAnchor(layer, true);
|
||||
var relativeAnchor = GetLayerAnchor(layer, false);
|
||||
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = layer.PositionProperty.CurrentValue.X * layerRect.Width - shapeRect.Width / 2 - relativeAnchor.X;
|
||||
var y = layer.PositionProperty.CurrentValue.Y * layerRect.Height - shapeRect.Height / 2 - relativeAnchor.Y;
|
||||
|
||||
SKMatrix.MakeScale(layer.SizeProperty.CurrentValue.Width, layer.SizeProperty.CurrentValue.Height, anchor.X, anchor.Y).TryInvert(out var scale);
|
||||
|
||||
path.Transform(SKMatrix.MakeRotationDegrees(layer.RotationProperty.CurrentValue * -1, anchor.X, anchor.Y));
|
||||
path.Transform(scale);
|
||||
path.Transform(SKMatrix.MakeTranslation(x * -1, y * -1));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public SKPoint GetLayerAnchor(Layer layer, bool absolute)
|
||||
{
|
||||
var layerRect = GetLayerRect(layer);
|
||||
if (absolute)
|
||||
{
|
||||
var position = layer.PositionProperty.CurrentValue;
|
||||
position.X = (float) (position.X * layerRect.Width);
|
||||
position.Y = (float) (position.Y * layerRect.Height);
|
||||
var shapeRect = GetShapeUntransformedRect(layer.LayerShape);
|
||||
return new SKPoint((float) (position.X + shapeRect.Left), (float) (position.Y + shapeRect.Top));
|
||||
}
|
||||
var layerBounds = GetLayerBounds(layer);
|
||||
|
||||
// TODO figure out what else is needed, position should matter here
|
||||
var anchor = layer.AnchorPointProperty.CurrentValue;
|
||||
anchor.X = (float) (anchor.X * layerRect.Width);
|
||||
anchor.Y = (float) (anchor.Y * layerRect.Height);
|
||||
return new SKPoint(anchor.X, anchor.Y);
|
||||
}
|
||||
anchor.X = (float) (anchor.X * layerBounds.Width);
|
||||
anchor.Y = (float) (anchor.Y * layerBounds.Height);
|
||||
|
||||
public void SetLayerAnchor(Layer layer, SKPoint point, bool absolute, TimeSpan? time)
|
||||
{
|
||||
var layerRect = GetLayerRect(layer);
|
||||
if (absolute)
|
||||
{
|
||||
var shapeRect = GetShapeUntransformedRect(layer.LayerShape);
|
||||
var position = new SKPoint((float) ((point.X - shapeRect.Left) / layerRect.Width), (float) ((point.Y - shapeRect.Top) / layerRect.Height));
|
||||
layer.PositionProperty.SetCurrentValue(position, time);
|
||||
}
|
||||
|
||||
var anchor = new SKPoint((float) (point.X / layerRect.Width), (float) (point.Y / layerRect.Height));
|
||||
layer.AnchorPointProperty.SetCurrentValue(anchor, time);
|
||||
return new Point(anchor.X * layerBounds.Width, anchor.Y * layerBounds.Height);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public TransformGroup GetLayerTransformGroup(Layer layer)
|
||||
{
|
||||
var layerRect = GetLayerRenderRect(layer).ToSKRect();
|
||||
var shapeRect = GetShapeUntransformedRect(layer.LayerShape).ToSKRect();
|
||||
var layerBounds = GetLayerBounds(layer).ToSKRect();
|
||||
var shapeBounds = GetLayerShapeBounds(layer.LayerShape).ToSKRect();
|
||||
|
||||
// Apply transformation like done by the core during layer rendering
|
||||
var anchor = GetLayerAnchor(layer, true);
|
||||
var anchor = GetLayerAnchor(layer);
|
||||
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = layer.PositionProperty.CurrentValue.X * layerRect.Width - shapeRect.Width / 2 - GetLayerAnchor(layer, false).X;
|
||||
var y = layer.PositionProperty.CurrentValue.Y * layerRect.Height - shapeRect.Height / 2 - GetLayerAnchor(layer, false).Y;
|
||||
var x = layer.PositionProperty.CurrentValue.X * layerBounds.Width - shapeBounds.Width / 2 - anchor.X;
|
||||
var y = layer.PositionProperty.CurrentValue.Y * layerBounds.Height - shapeBounds.Height / 2 - anchor.Y;
|
||||
|
||||
var transformGroup = new TransformGroup();
|
||||
transformGroup.Children.Add(new TranslateTransform(x, y));
|
||||
@@ -146,27 +81,30 @@ namespace Artemis.UI.Services
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rect GetShapeUntransformedRect(LayerShape layerShape)
|
||||
public SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation)
|
||||
{
|
||||
if (layerShape == null)
|
||||
return Rect.Empty;
|
||||
var layerBounds = GetLayerBounds(layer).ToSKRect();
|
||||
var shapeBounds = GetLayerShapeBounds(layer.LayerShape).ToSKRect();
|
||||
|
||||
// Adjust the render rectangle for the difference in render scale
|
||||
var renderScale = _settingsService.GetSetting("Core.RenderScale", 1.0).Value;
|
||||
return new Rect(
|
||||
layerShape.RenderRectangle.Left / renderScale * 1,
|
||||
layerShape.RenderRectangle.Top / renderScale * 1,
|
||||
Math.Max(0, layerShape.RenderRectangle.Width / renderScale * 1),
|
||||
Math.Max(0, layerShape.RenderRectangle.Height / renderScale * 1)
|
||||
);
|
||||
// Apply transformation like done by the core during layer rendering
|
||||
var anchor = GetLayerAnchor(layer).ToSKPoint();
|
||||
|
||||
// Translation originates from the unscaled center of the shape and is tied to the anchor
|
||||
var x = layer.PositionProperty.CurrentValue.X * layerBounds.Width - shapeBounds.Width / 2 - anchor.X;
|
||||
var y = layer.PositionProperty.CurrentValue.Y * layerBounds.Height - shapeBounds.Height / 2 - anchor.Y;
|
||||
|
||||
var path = new SKPath();
|
||||
path.AddRect(shapeBounds);
|
||||
if (includeTranslation)
|
||||
path.Transform(SKMatrix.MakeTranslation(x, y));
|
||||
if (includeScale)
|
||||
path.Transform(SKMatrix.MakeScale(layer.SizeProperty.CurrentValue.Width, layer.SizeProperty.CurrentValue.Height, anchor.X, anchor.Y));
|
||||
if (includeRotation)
|
||||
path.Transform(SKMatrix.MakeRotationDegrees(layer.RotationProperty.CurrentValue, anchor.X, anchor.Y));
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rect GetShapeTransformedRect(LayerShape layerShape)
|
||||
{
|
||||
var path = GetLayerPath(layerShape.Layer, true, true, false);
|
||||
return path.Bounds.ToRect();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetShapeBaseFromRectangle(LayerShape layerShape, Rect rect)
|
||||
@@ -177,16 +115,16 @@ namespace Artemis.UI.Services
|
||||
return;
|
||||
}
|
||||
|
||||
var layerRect = GetLayerRenderRect(layerShape.Layer).ToSKRect();
|
||||
var layerBounds = GetLayerBounds(layerShape.Layer).ToSKRect();
|
||||
|
||||
// Compensate for the current value of the position transformation
|
||||
rect.X += rect.Width / 2;
|
||||
rect.X -= layerRect.Width * layerShape.Layer.PositionProperty.CurrentValue.X;
|
||||
rect.X += layerRect.Width * layerShape.Layer.AnchorPointProperty.CurrentValue.X * layerShape.Layer.SizeProperty.CurrentValue.Width;
|
||||
rect.X -= layerBounds.Width * layerShape.Layer.PositionProperty.CurrentValue.X;
|
||||
rect.X += layerBounds.Width * layerShape.Layer.AnchorPointProperty.CurrentValue.X * layerShape.Layer.SizeProperty.CurrentValue.Width;
|
||||
|
||||
rect.Y += rect.Height / 2;
|
||||
rect.Y -= layerRect.Height * layerShape.Layer.PositionProperty.CurrentValue.Y;
|
||||
rect.Y += layerRect.Height * layerShape.Layer.AnchorPointProperty.CurrentValue.Y * layerShape.Layer.SizeProperty.CurrentValue.Height;
|
||||
rect.Y -= layerBounds.Height * layerShape.Layer.PositionProperty.CurrentValue.Y;
|
||||
rect.Y += layerBounds.Height * layerShape.Layer.AnchorPointProperty.CurrentValue.Y * layerShape.Layer.SizeProperty.CurrentValue.Height;
|
||||
|
||||
// Compensate for the current value of the size transformation
|
||||
rect.Height /= layerShape.Layer.SizeProperty.CurrentValue.Height;
|
||||
@@ -195,10 +133,10 @@ namespace Artemis.UI.Services
|
||||
// Adjust the provided rect for the difference in render scale
|
||||
var renderScale = _settingsService.GetSetting("Core.RenderScale", 1.0).Value;
|
||||
layerShape.ScaledRectangle = SKRect.Create(
|
||||
100f / layerShape.Layer.AbsoluteRectangle.Width * ((float) (rect.Left * renderScale) - layerShape.Layer.AbsoluteRectangle.Left) / 100f,
|
||||
100f / layerShape.Layer.AbsoluteRectangle.Height * ((float) (rect.Top * renderScale) - layerShape.Layer.AbsoluteRectangle.Top) / 100f,
|
||||
100f / layerShape.Layer.AbsoluteRectangle.Width * (float) (rect.Width * renderScale) / 100f,
|
||||
100f / layerShape.Layer.AbsoluteRectangle.Height * (float) (rect.Height * renderScale) / 100f
|
||||
100f / layerShape.Layer.Bounds.Width * ((float) (rect.Left * renderScale) - layerShape.Layer.Bounds.Left) / 100f,
|
||||
100f / layerShape.Layer.Bounds.Height * ((float) (rect.Top * renderScale) - layerShape.Layer.Bounds.Top) / 100f,
|
||||
100f / layerShape.Layer.Bounds.Width * (float) (rect.Width * renderScale) / 100f,
|
||||
100f / layerShape.Layer.Bounds.Height * (float) (rect.Height * renderScale) / 100f
|
||||
);
|
||||
layerShape.CalculateRenderProperties();
|
||||
}
|
||||
@@ -210,14 +148,14 @@ namespace Artemis.UI.Services
|
||||
if (absolute)
|
||||
{
|
||||
return new SKPoint(
|
||||
100f / layer.AbsoluteRectangle.Width * ((float) (point.X * renderScale) - layer.AbsoluteRectangle.Left) / 100f,
|
||||
100f / layer.AbsoluteRectangle.Height * ((float) (point.Y * renderScale) - layer.AbsoluteRectangle.Top) / 100f
|
||||
100f / layer.Bounds.Width * ((float) (point.X * renderScale) - layer.Bounds.Left) / 100f,
|
||||
100f / layer.Bounds.Height * ((float) (point.Y * renderScale) - layer.Bounds.Top) / 100f
|
||||
);
|
||||
}
|
||||
|
||||
return new SKPoint(
|
||||
100f / layer.AbsoluteRectangle.Width * (float) (point.X * renderScale) / 100f,
|
||||
100f / layer.AbsoluteRectangle.Height * (float) (point.Y * renderScale) / 100f
|
||||
100f / layer.Bounds.Width * (float) (point.X * renderScale) / 100f,
|
||||
100f / layer.Bounds.Height * (float) (point.Y * renderScale) / 100f
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -225,40 +163,25 @@ namespace Artemis.UI.Services
|
||||
public interface ILayerEditorService : IArtemisUIService
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns an relative and scaled rectangle for the given layer that is corrected for the current render scale.
|
||||
/// Returns the layer's bounds, corrected for the current render scale.
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
/// <returns></returns>
|
||||
Rect GetLayerRenderRect(Layer layer);
|
||||
Rect GetLayerBounds(Layer layer);
|
||||
|
||||
/// <summary>
|
||||
/// Returns an absolute and scaled rectangle for the given layer that is corrected for the current render scale.
|
||||
/// Returns the layer's anchor, corrected for the current render scale.
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
/// <returns></returns>
|
||||
Rect GetLayerRect(Layer layer);
|
||||
Point GetLayerAnchor(Layer layer);
|
||||
|
||||
/// <summary>
|
||||
/// Returns an absolute and scaled rectangular path for the given layer that is corrected for the current render scale.
|
||||
/// Returns the layer shape's bounds, corrected for the current render scale.
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
/// <param name="includeTranslation"></param>
|
||||
/// <param name="includeScale"></param>
|
||||
/// <param name="includeRotation"></param>
|
||||
/// <param name="layerShape"></param>
|
||||
/// <returns></returns>
|
||||
SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation);
|
||||
|
||||
void ReverseLayerPath(Layer layer, SKPath path);
|
||||
|
||||
/// <summary>
|
||||
/// Returns an absolute and scaled anchor for the given layer, optionally with the translation applied.
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
/// <param name="absolute"></param>
|
||||
/// <returns></returns>
|
||||
SKPoint GetLayerAnchor(Layer layer, bool absolute);
|
||||
|
||||
void SetLayerAnchor(Layer layer, SKPoint point, bool absolute, TimeSpan? time);
|
||||
Rect GetLayerShapeBounds(LayerShape layerShape);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a WPF transform group that contains all the transformations required to render the provided layer.
|
||||
@@ -269,18 +192,14 @@ namespace Artemis.UI.Services
|
||||
TransformGroup GetLayerTransformGroup(Layer layer);
|
||||
|
||||
/// <summary>
|
||||
/// Returns an absolute and scaled rectangle for the given shape that is corrected for the current render scale without
|
||||
/// any transformations applied.
|
||||
/// Returns an absolute and scaled rectangular path for the given layer that is corrected for the current render scale.
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
/// <param name="includeTranslation"></param>
|
||||
/// <param name="includeScale"></param>
|
||||
/// <param name="includeRotation"></param>
|
||||
/// <returns></returns>
|
||||
Rect GetShapeUntransformedRect(LayerShape layerShape);
|
||||
|
||||
/// <summary>
|
||||
/// Returns an absolute and scaled rectangle for the given shape that is corrected for the current render scale with
|
||||
/// translation and scale transformations applied.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Rect GetShapeTransformedRect(LayerShape layerShape);
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user