Show outlines for all layers

Rotation fixes
Movement fixes
This commit is contained in:
Robert committed 2020-02-06 15:48:37 +01:00
1 parent 07d9a5f784
commit 5478c2531e
7 files changed
+53 -49

No files matched your search

@@ -18,8 +18,9 @@ namespace Artemis.UI.Services.Interfaces
/// Returns the layer's anchor, corrected for the current render scale.
/// </summary>
/// <param name="layer"></param>
/// <param name="positionOverride"></param>
/// <returns></returns>
Point GetLayerAnchorPosition(Layer layer);
Point GetLayerAnchorPosition(Layer layer, SKPoint? positionOverride = null);
/// <summary>
/// Creates a WPF transform group that contains all the transformations required to render the provided layer.
@@ -36,8 +37,9 @@ namespace Artemis.UI.Services.Interfaces
/// <param name="includeTranslation"></param>
/// <param name="includeScale"></param>
/// <param name="includeRotation"></param>
/// <param name="anchorOverride"></param>
/// <returns></returns>
SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation);
SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation, SKPoint? anchorOverride = null);
/// <summary>
/// Returns a new point scaled to the layer.
@@ -47,5 +49,7 @@ namespace Artemis.UI.Services.Interfaces
/// <param name="absolute"></param>
/// <returns></returns>
SKPoint GetScaledPoint(Layer layer, SKPoint point, bool absolute);
SKPoint GetDragOffset(Layer layer, SKPoint dragStart);
}
}
@@ -32,10 +32,12 @@ namespace Artemis.UI.Services
}
/// <inheritdoc />
public Point GetLayerAnchorPosition(Layer layer)
public Point GetLayerAnchorPosition(Layer layer, SKPoint? positionOverride = null)
{
var layerBounds = GetLayerBounds(layer).ToSKRect();
var positionProperty = layer.PositionProperty.CurrentValue;
if (positionOverride != null)
positionProperty = positionOverride.Value;
// Start at the center of the shape
var position = new Point(layerBounds.MidX, layerBounds.MidY);
@@ -72,12 +74,15 @@ namespace Artemis.UI.Services
}
/// <inheritdoc />
public SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation)
public SKPath GetLayerPath(Layer layer, bool includeTranslation, bool includeScale, bool includeRotation, SKPoint? anchorOverride = null)
{
var layerBounds = GetLayerBounds(layer).ToSKRect();
// Apply transformation like done by the core during layer rendering (same differences apply as in GetLayerTransformGroup)
var anchorPosition = GetLayerAnchorPosition(layer).ToSKPoint();
if (anchorOverride != null)
anchorPosition = anchorOverride.Value;
var anchorProperty = layer.AnchorPointProperty.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
@@ -113,5 +118,19 @@ namespace Artemis.UI.Services
100f / layer.Bounds.Height * (float) (point.Y * renderScale) / 100f
);
}
public SKPoint GetDragOffset(Layer layer, SKPoint dragStart)
{
// Figure out what the top left will be if the shape moves to the current cursor position
var scaledDragStart = GetScaledPoint(layer, dragStart, true);
var tempAnchor = GetLayerAnchorPosition(layer, scaledDragStart).ToSKPoint();
var tempTopLeft = GetLayerPath(layer, true, true, true, tempAnchor)[0];
// Get the shape's position
var topLeft = GetLayerPath(layer, true, true, true)[0];
// The difference between the two is the offset
return topLeft - tempTopLeft;
}
}
}