1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 17:53:32 +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:
Robert 2020-09-18 20:14:38 +02:00
parent ba80e25d34
commit ce0024a14d
3 changed files with 28 additions and 16 deletions

View File

@ -34,7 +34,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
profileEditorService.SelectedProfileElementUpdated += (sender, args) => Update(); profileEditorService.SelectedProfileElementUpdated += (sender, args) => Update();
profileEditorService.ProfilePreviewUpdated += (sender, args) => Update(); profileEditorService.ProfilePreviewUpdated += (sender, args) => Update();
} }
public SKPath ShapePath public SKPath ShapePath
{ {
get => _shapePath; get => _shapePath;
@ -220,6 +220,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
var anchorDistance = origin == ResizeOrigin.Left var anchorDistance = origin == ResizeOrigin.Left
? shapePath.Bounds.Left - ShapeAnchor.X ? shapePath.Bounds.Left - ShapeAnchor.X
: shapePath.Bounds.Right - 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 anchorOffset = anchorDistance / shapePath.Bounds.Width;
var pixelsToAdd = (position - dragStart).X / anchorOffset; var pixelsToAdd = (position - dragStart).X / anchorOffset;
@ -240,6 +246,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
var anchorDistance = origin == ResizeOrigin.Top var anchorDistance = origin == ResizeOrigin.Top
? shapePath.Bounds.Top - ShapeAnchor.Y ? shapePath.Bounds.Top - ShapeAnchor.Y
: shapePath.Bounds.Bottom - 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 anchorOffset = anchorDistance / shapePath.Bounds.Height;
var pixelsToAdd = (position - dragStart).Y / anchorOffset; 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); var current = start + (GetRelativePosition(sender, e).ToSKPoint() - _dragOffset);
// In order to keep the mouse movement unrotated, counter-act the active rotation // In order to keep the mouse movement unrotated, counter-act the active rotation
var countered = UnTransformPoints(new[] {start, current}, layer, start, true); 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 // 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 // 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); var path = _layerEditorService.GetLayerPath(layer, true, true, true);
// Calculate the (scaled) difference between the old and now position // Calculate the (scaled) difference between the old and now position
var difference = _layerEditorService.GetScaledPoint(layer, _topLeft - path.Points[0], false); var difference = _layerEditorService.GetScaledPoint(layer, _topLeft - path.Points[0], false);
// Apply the difference so that the shape effectively stays in place // 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(); ProfileEditorService.UpdateProfilePreview();
} }

View File

@ -46,7 +46,6 @@
<Rectangle x:Name="ResizeTopCenter" <Rectangle x:Name="ResizeTopCenter"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="Hand" Cursor="Hand"
MouseDown="ResizeOnMouseDown" MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp" MouseUp="ResizeOnMouseUp"
@ -54,7 +53,6 @@
<Rectangle x:Name="ResizeRightCenter" <Rectangle x:Name="ResizeRightCenter"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="Hand" Cursor="Hand"
MouseDown="ResizeOnMouseDown" MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp" MouseUp="ResizeOnMouseUp"
@ -62,7 +60,6 @@
<Rectangle x:Name="ResizeBottomCenter" <Rectangle x:Name="ResizeBottomCenter"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="Hand" Cursor="Hand"
MouseDown="ResizeOnMouseDown" MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp" MouseUp="ResizeOnMouseUp"
@ -70,7 +67,6 @@
<Rectangle x:Name="ResizeLeftCenter" <Rectangle x:Name="ResizeLeftCenter"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="Hand" Cursor="Hand"
MouseDown="ResizeOnMouseDown" MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp" MouseUp="ResizeOnMouseUp"
@ -79,7 +75,6 @@
<Rectangle x:Name="ResizeTopLeft" <Rectangle x:Name="ResizeTopLeft"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="Hand" Cursor="Hand"
MouseDown="ResizeOnMouseDown" MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp" MouseUp="ResizeOnMouseUp"
@ -87,7 +82,6 @@
<Rectangle x:Name="ResizeTopRight" <Rectangle x:Name="ResizeTopRight"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="Hand" Cursor="Hand"
MouseDown="ResizeOnMouseDown" MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp" MouseUp="ResizeOnMouseUp"
@ -95,7 +89,6 @@
<Rectangle x:Name="ResizeBottomRight" <Rectangle x:Name="ResizeBottomRight"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="Hand" Cursor="Hand"
MouseDown="ResizeOnMouseDown" MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp" MouseUp="ResizeOnMouseUp"
@ -103,7 +96,6 @@
<Rectangle x:Name="ResizeBottomLeft" <Rectangle x:Name="ResizeBottomLeft"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="Hand" Cursor="Hand"
MouseDown="ResizeOnMouseDown" MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp" MouseUp="ResizeOnMouseUp"
@ -113,10 +105,13 @@
<Ellipse x:Name="AnchorPoint" <Ellipse x:Name="AnchorPoint"
Fill="White" Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}" Stroke="{DynamicResource SecondaryAccentBrush}"
StrokeThickness="0.5"
Cursor="SizeAll" Cursor="SizeAll"
MouseDown="MoveOnMouseDown" MouseDown="MoveOnMouseDown"
MouseUp="MoveOnMouseUp" 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> </Canvas>
</UserControl> </UserControl>

View File

@ -3,6 +3,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes;
using Artemis.UI.Events; using Artemis.UI.Events;
using SkiaSharp; using SkiaSharp;
@ -164,7 +165,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.UserControls
UpdateControlPosition(control, point); UpdateControlPosition(control, point);
} }
private void UpdateRotateDimensions(FrameworkElement rotateControl) private void UpdateRotateDimensions(Shape rotateControl)
{ {
var controlSize = Math.Max(10 / Zoom, 4); var controlSize = Math.Max(10 / Zoom, 4);
var rotateSize = controlSize * 8; 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); 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); var controlSize = Math.Max(10 / Zoom, 4);
resizeControl.Width = controlSize; resizeControl.Width = controlSize;
resizeControl.Height = controlSize; resizeControl.Height = controlSize;
resizeControl.Margin = new Thickness(controlSize / 2 * -1, controlSize / 2 * -1, 0, 0); resizeControl.Margin = new Thickness(controlSize / 2 * -1, controlSize / 2 * -1, 0, 0);
resizeControl.StrokeThickness = controlSize / 7.5;
} }
#endregion #endregion