Adjusted anchor calculations for simplified render process

Project cleanup
This commit is contained in:
Robert committed 2020-01-31 12:05:45 +01:00
1 parent fd9dd626f8
commit 588c25f8c1
25 files changed
+160 -167

No files matched your search

@@ -61,7 +61,7 @@
<Button Style="{StaticResource MaterialDesignIconForegroundButton}" ToolTip="Next frame" Command="{s:Action GoToNextFrame}" Focusable="False">
<materialDesign:PackIcon Kind="SkipNext" />
</Button>
<ToggleButton Style="{StaticResource MaterialDesignFlatToggleButton}"
<ToggleButton Style="{StaticResource MaterialDesignFlatToggleButton}"
ToolTip="Repeat after last keyframe"
IsChecked="{Binding RepeatAfterLastKeyframe}"
Focusable="False">
@@ -103,12 +103,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
public void PlayFromStart()
{
if (!IsActive)
return;
if (Playing)
Pause();
if (!Playing)
_profileEditorService.CurrentTime = TimeSpan.Zero;
_profileEditorService.CurrentTime = TimeSpan.Zero;
Play();
}
@@ -196,7 +196,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
if (!activeProfile.IsActivated)
_profileService.ActivateProfile(Module, activeProfile);
});
}
}
}
@@ -5,12 +5,9 @@ using System.Windows.Media;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.Core.Models.Surface;
using Artemis.Core.Services;
using Artemis.UI.Extensions;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using RGB.NET.Core;
using SkiaSharp.Views.WPF;
using Stylet;
using Rectangle = Artemis.Core.Models.Profile.LayerShapes.Rectangle;
@@ -18,8 +15,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{
public class ProfileLayerViewModel : CanvasViewModel
{
private readonly IProfileEditorService _profileEditorService;
private readonly ILayerEditorService _layerEditorService;
private readonly IProfileEditorService _profileEditorService;
public ProfileLayerViewModel(Layer layer, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
{
@@ -145,13 +142,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
return;
}
var x = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.X);
var y = Layer.Leds.Min(l => l.RgbLed.AbsoluteLedRectangle.Location.Y);
var width = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.X + l.RgbLed.AbsoluteLedRectangle.Size.Width) - x;
var height = Layer.Leds.Max(l => l.RgbLed.AbsoluteLedRectangle.Location.Y + l.RgbLed.AbsoluteLedRectangle.Size.Height) - y;
var rect = new Rect(x, y, width, height);
ViewportRectangle = rect;
var rect = _layerEditorService.GetLayerBounds(Layer);
ViewportRectangle = new Rect(0, 0, rect.Width, rect.Height);
}
private Geometry CreateRectangleGeometry(ArtemisLed led)
@@ -14,7 +14,6 @@ using Artemis.UI.Events;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools;
using Artemis.UI.Screens.Shared;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using RGB.NET.Core;
using Stylet;
@@ -23,8 +22,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
{
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>, IHandle<MainWindowKeyEvent>
{
private readonly IProfileEditorService _profileEditorService;
private readonly ILayerEditorService _layerEditorService;
private readonly IProfileEditorService _profileEditorService;
private readonly IProfileLayerViewModelFactory _profileLayerViewModelFactory;
private readonly ISettingsService _settingsService;
private readonly ISurfaceService _surfaceService;
@@ -4,7 +4,6 @@ using System.Windows.Input;
using System.Windows.Media;
using Artemis.Core.Models.Profile;
using Artemis.UI.Events;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using SkiaSharp;
using SkiaSharp.Views.WPF;
@@ -45,7 +44,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
LayerBounds = _layerEditorService.GetLayerBounds(layer);
ShapePath = _layerEditorService.GetLayerPath(layer, true, true, true);
ShapeAnchor = _layerEditorService.GetLayerAnchor(layer).ToSKPoint();
ShapeAnchor = _layerEditorService.GetLayerAnchorPosition(layer).ToSKPoint();
Execute.PostToUIThread(() =>
{
var shapeGeometry = new RectangleGeometry(_layerEditorService.GetLayerShapeBounds(layer.LayerShape))
@@ -59,7 +58,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;
@@ -69,7 +68,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
_rotating = true;
if (ProfileEditorService.SelectedProfileElement is Layer layer)
_previousDragAngle = CalculateAngle(_layerEditorService.GetLayerAnchor(layer), GetRelativePosition(sender, e.MouseEventArgs));
_previousDragAngle = CalculateAngle(_layerEditorService.GetLayerAnchorPosition(layer), GetRelativePosition(sender, e.MouseEventArgs));
else
_previousDragAngle = 0;
}
@@ -86,7 +85,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
return;
var previousDragAngle = _previousDragAngle;
var newRotation = CalculateAngle(_layerEditorService.GetLayerAnchor(layer), GetRelativePosition(sender, e.MouseEventArgs));
var newRotation = CalculateAngle(_layerEditorService.GetLayerAnchorPosition(layer), GetRelativePosition(sender, e.MouseEventArgs));
_previousDragAngle = newRotation;
// Allow the user to rotate the shape in increments of 5
@@ -280,7 +279,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).ToSKPoint() - topLeft;
_dragStartAnchor = _layerEditorService.GetLayerAnchorPosition(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;
@@ -1,13 +1,10 @@
using System.Diagnostics;
using System.IO;
using System.IO;
using System.Windows;
using System.Windows.Input;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.UI.Properties;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using SkiaSharp.Views.WPF;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
@@ -1,12 +1,9 @@
using System;
using System.Diagnostics;
using System.IO;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.UI.Properties;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
@@ -4,9 +4,7 @@ using System.Windows.Input;
using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.UI.Properties;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using SkiaSharp.Views.WPF;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
@@ -15,7 +13,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
private readonly ILayerEditorService _layerEditorService;
private bool _shiftDown;
public RectangleToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
public RectangleToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
: base(profileViewModel, profileEditorService)
{
_layerEditorService = layerEditorService;
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
@@ -8,10 +7,8 @@ using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface;
using Artemis.UI.Extensions;
using Artemis.UI.Properties;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using SkiaSharp;
using SkiaSharp.Views.WPF;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
@@ -62,11 +59,11 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
var remainingLeds = layer.Leds.Except(selectedLeds).ToList();
layer.ClearLeds();
layer.AddLeds(remainingLeds);
// Restore the saved size
if (layer.LayerShape != null)
layer.LayerShape.SetFromUnscaledRectangle(shapeSize);
ProfileEditorService.UpdateSelectedProfileElement();
}
}
@@ -7,7 +7,6 @@ using Artemis.Core.Models.Profile;
using Artemis.Core.Models.Surface;
using Artemis.UI.Extensions;
using Artemis.UI.Properties;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using SkiaSharp;
@@ -28,7 +27,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
}
public Rect DragRectangle { get; set; }
public override void MouseUp(object sender, MouseButtonEventArgs e)
{
base.MouseUp(sender, e);
@@ -12,25 +12,25 @@
Cursor="/Resources/aero_rotate.cur"
MouseDown="RotationOnMouseDown"
MouseUp="RotationOnMouseUp"
MouseMove="RotationOnMouseMove"/>
MouseMove="RotationOnMouseMove" />
<Ellipse x:Name="RotateTopRight"
Fill="Transparent"
Cursor="/Resources/aero_rotate.cur"
MouseDown="RotationOnMouseDown"
MouseUp="RotationOnMouseUp"
MouseMove="RotationOnMouseMove"/>
MouseMove="RotationOnMouseMove" />
<Ellipse x:Name="RotateBottomRight"
Fill="Transparent"
Cursor="/Resources/aero_rotate.cur"
MouseDown="RotationOnMouseDown"
MouseUp="RotationOnMouseUp"
MouseMove="RotationOnMouseMove"/>
MouseMove="RotationOnMouseMove" />
<Ellipse x:Name="RotateBottomLeft"
Fill="Transparent"
Cursor="/Resources/aero_rotate.cur"
MouseDown="RotationOnMouseDown"
MouseUp="RotationOnMouseUp"
MouseMove="RotationOnMouseMove"/>
MouseMove="RotationOnMouseMove" />
<!-- The part of the layer's shape that is inside the layer -->
<Path x:Name="LayerShapeOutline"
Data="{Binding ShapeGeometry, Mode=OneWay}"
@@ -51,7 +51,7 @@
Cursor="Hand"
MouseDown="ResizeOnMouseDown"
MouseUp="ResizeOnMouseUp"
MouseMove="ResizeOnMouseMove"/>
MouseMove="ResizeOnMouseMove" />
<Rectangle x:Name="ResizeRightCenter"
Fill="White"
Stroke="{DynamicResource SecondaryAccentBrush}"
@@ -118,6 +118,6 @@
Cursor="SizeAll"
MouseDown="MoveOnMouseDown"
MouseUp="MoveOnMouseUp"
MouseMove="MoveOnMouseMove"/>
MouseMove="MoveOnMouseMove" />
</Canvas>
</UserControl>
@@ -4,7 +4,6 @@ using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.UI.Events;
using Artemis.UI.Utilities;
using SkiaSharp;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.UserControls
@@ -38,7 +37,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.UserControls
get => (double) GetValue(ZoomProperty);
set => SetValue(ZoomProperty, value);
}
public SKPath ShapePath
{
get => (SKPath) GetValue(ShapePathProperty);
@@ -64,7 +63,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.UserControls
layerShapeControl.SetCurrentValue(ZoomProperty, e.NewValue);
layerShapeControl.UpdateDimensions();
}
private static void ShapePathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var layerShapeControl = (LayerShapeControl) d;
@@ -51,7 +51,7 @@ namespace Artemis.UI.Screens.Shared
}
else
{
PanX = absoluteX - relative.X * Zoom;
PanX = absoluteX - relative.X * Zoom;
PanY = absoluteY - relative.Y * Zoom;
}
}