mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Profile editor - Improved anchor point visibility
Profile editor - Fixed resizing if the resize handle is on the same position as the anchor Profile editor - Added shift modifier to drag anchor point in increments Profile editor - Fixed the layer sometimes moving when moving the anchor
This commit is contained in:
parent
ba80e25d34
commit
ce0024a14d
@ -34,7 +34,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
profileEditorService.SelectedProfileElementUpdated += (sender, args) => Update();
|
||||
profileEditorService.ProfilePreviewUpdated += (sender, args) => Update();
|
||||
}
|
||||
|
||||
|
||||
public SKPath ShapePath
|
||||
{
|
||||
get => _shapePath;
|
||||
@ -220,6 +220,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
var anchorDistance = origin == ResizeOrigin.Left
|
||||
? shapePath.Bounds.Left - ShapeAnchor.X
|
||||
: shapePath.Bounds.Right - ShapeAnchor.X;
|
||||
|
||||
// Don't resize if the distance to the anchor is too small, that'll result in a NaN value
|
||||
// this might happen if the anchor is at X -0.5 and the drag handle is on the left side or vice versa
|
||||
if (Math.Abs(anchorDistance) < 0.001)
|
||||
return _dragStartScale.Width;
|
||||
|
||||
var anchorOffset = anchorDistance / shapePath.Bounds.Width;
|
||||
|
||||
var pixelsToAdd = (position - dragStart).X / anchorOffset;
|
||||
@ -240,6 +246,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
var anchorDistance = origin == ResizeOrigin.Top
|
||||
? shapePath.Bounds.Top - ShapeAnchor.Y
|
||||
: shapePath.Bounds.Bottom - ShapeAnchor.Y;
|
||||
|
||||
// Don't resize if the distance to the anchor is too small, that'll result in a NaN value
|
||||
// this might happen if the anchor is at Y -0.5 and the drag handle is on the top side or vice versa
|
||||
if (Math.Abs(anchorDistance) < 0.001)
|
||||
return _dragStartScale.Width;
|
||||
|
||||
var anchorOffset = anchorDistance / shapePath.Bounds.Height;
|
||||
|
||||
var pixelsToAdd = (position - dragStart).Y / anchorOffset;
|
||||
@ -353,16 +365,19 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
var current = start + (GetRelativePosition(sender, e).ToSKPoint() - _dragOffset);
|
||||
// In order to keep the mouse movement unrotated, counter-act the active rotation
|
||||
var countered = UnTransformPoints(new[] {start, current}, layer, start, true);
|
||||
var scaled = _layerEditorService.GetScaledPoint(layer, countered[1], false);
|
||||
|
||||
// If shift is held down, round down to 1 decimal to allow moving the anchor in big increments
|
||||
var decimals = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) ? 1 : 3;
|
||||
var scaled = RoundPoint(_layerEditorService.GetScaledPoint(layer, countered[1], false), decimals);
|
||||
|
||||
// Update the anchor point, this causes the shape to move
|
||||
layer.Transform.AnchorPoint.SetCurrentValue(RoundPoint(scaled, 3), ProfileEditorService.CurrentTime);
|
||||
layer.Transform.AnchorPoint.SetCurrentValue(scaled, ProfileEditorService.CurrentTime);
|
||||
// TopLeft is not updated yet and acts as a snapshot of the top-left before changing the anchor
|
||||
var path = _layerEditorService.GetLayerPath(layer, true, true, true);
|
||||
// Calculate the (scaled) difference between the old and now position
|
||||
var difference = _layerEditorService.GetScaledPoint(layer, _topLeft - path.Points[0], false);
|
||||
// Apply the difference so that the shape effectively stays in place
|
||||
layer.Transform.Position.SetCurrentValue(RoundPoint(layer.Transform.Position.CurrentValue + difference, 3), ProfileEditorService.CurrentTime);
|
||||
layer.Transform.Position.SetCurrentValue(layer.Transform.Position.CurrentValue + difference, ProfileEditorService.CurrentTime);
|
||||
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
}
|
||||
|
||||
@ -46,7 +46,6 @@
|
||||
<Rectangle x:Name="ResizeTopCenter"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="Hand"
|
||||
MouseDown="ResizeOnMouseDown"
|
||||
MouseUp="ResizeOnMouseUp"
|
||||
@ -54,7 +53,6 @@
|
||||
<Rectangle x:Name="ResizeRightCenter"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="Hand"
|
||||
MouseDown="ResizeOnMouseDown"
|
||||
MouseUp="ResizeOnMouseUp"
|
||||
@ -62,7 +60,6 @@
|
||||
<Rectangle x:Name="ResizeBottomCenter"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="Hand"
|
||||
MouseDown="ResizeOnMouseDown"
|
||||
MouseUp="ResizeOnMouseUp"
|
||||
@ -70,7 +67,6 @@
|
||||
<Rectangle x:Name="ResizeLeftCenter"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="Hand"
|
||||
MouseDown="ResizeOnMouseDown"
|
||||
MouseUp="ResizeOnMouseUp"
|
||||
@ -79,7 +75,6 @@
|
||||
<Rectangle x:Name="ResizeTopLeft"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="Hand"
|
||||
MouseDown="ResizeOnMouseDown"
|
||||
MouseUp="ResizeOnMouseUp"
|
||||
@ -87,7 +82,6 @@
|
||||
<Rectangle x:Name="ResizeTopRight"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="Hand"
|
||||
MouseDown="ResizeOnMouseDown"
|
||||
MouseUp="ResizeOnMouseUp"
|
||||
@ -95,7 +89,6 @@
|
||||
<Rectangle x:Name="ResizeBottomRight"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="Hand"
|
||||
MouseDown="ResizeOnMouseDown"
|
||||
MouseUp="ResizeOnMouseUp"
|
||||
@ -103,7 +96,6 @@
|
||||
<Rectangle x:Name="ResizeBottomLeft"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="Hand"
|
||||
MouseDown="ResizeOnMouseDown"
|
||||
MouseUp="ResizeOnMouseUp"
|
||||
@ -113,10 +105,13 @@
|
||||
<Ellipse x:Name="AnchorPoint"
|
||||
Fill="White"
|
||||
Stroke="{DynamicResource SecondaryAccentBrush}"
|
||||
StrokeThickness="0.5"
|
||||
Cursor="SizeAll"
|
||||
MouseDown="MoveOnMouseDown"
|
||||
MouseUp="MoveOnMouseUp"
|
||||
MouseMove="MoveOnMouseMove" />
|
||||
MouseMove="MoveOnMouseMove" RenderTransformOrigin="0.5 0.5">
|
||||
<Ellipse.RenderTransform>
|
||||
<ScaleTransform ScaleX="1.5" ScaleY="1.5"></ScaleTransform>
|
||||
</Ellipse.RenderTransform>
|
||||
</Ellipse>
|
||||
</Canvas>
|
||||
</UserControl>
|
||||
@ -3,6 +3,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Artemis.UI.Events;
|
||||
using SkiaSharp;
|
||||
|
||||
@ -164,7 +165,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.UserControls
|
||||
UpdateControlPosition(control, point);
|
||||
}
|
||||
|
||||
private void UpdateRotateDimensions(FrameworkElement rotateControl)
|
||||
private void UpdateRotateDimensions(Shape rotateControl)
|
||||
{
|
||||
var controlSize = Math.Max(10 / Zoom, 4);
|
||||
var rotateSize = controlSize * 8;
|
||||
@ -174,13 +175,14 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.UserControls
|
||||
rotateControl.Margin = new Thickness(rotateSize / 2 * -1, rotateSize / 2 * -1, 0, 0);
|
||||
}
|
||||
|
||||
private void UpdateResizeDimensions(FrameworkElement resizeControl)
|
||||
private void UpdateResizeDimensions(Shape resizeControl)
|
||||
{
|
||||
var controlSize = Math.Max(10 / Zoom, 4);
|
||||
|
||||
resizeControl.Width = controlSize;
|
||||
resizeControl.Height = controlSize;
|
||||
resizeControl.Margin = new Thickness(controlSize / 2 * -1, controlSize / 2 * -1, 0, 0);
|
||||
resizeControl.StrokeThickness = controlSize / 7.5;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user