mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
82a1208f8d
19 files changed
+467
-270
No files matched your search
@@ -222,6 +222,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Screens\Sidebar\SidebarViewModel.cs" />
|
||||
<Compile Include="Services\Interfaces\IProfileEditorService.cs" />
|
||||
<Compile Include="Services\LayerShapeService.cs" />
|
||||
<Compile Include="Services\ProfileEditorService.cs" />
|
||||
<Compile Include="Utilities\ThemeWatcher.cs" />
|
||||
<Compile Include="Behaviors\TreeViewSelectionBehavior.cs" />
|
||||
|
||||
+31
-24
@@ -5,9 +5,13 @@ 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;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
@@ -15,10 +19,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
public class ProfileLayerViewModel : CanvasViewModel
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly ILayerEditorService _layerEditorService;
|
||||
|
||||
public ProfileLayerViewModel(Layer layer, IProfileEditorService profileEditorService)
|
||||
public ProfileLayerViewModel(Layer layer, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_layerEditorService = layerEditorService;
|
||||
Layer = layer;
|
||||
|
||||
Update();
|
||||
@@ -83,7 +89,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
}
|
||||
|
||||
var layerGeometry = group.GetOutlinedPathGeometry();
|
||||
|
||||
var opacityGeometry = Geometry.Combine(Geometry.Empty, layerGeometry, GeometryCombineMode.Exclude, new TranslateTransform());
|
||||
layerGeometry.Freeze();
|
||||
opacityGeometry.Freeze();
|
||||
@@ -99,29 +104,31 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
return;
|
||||
}
|
||||
|
||||
var skRect = Layer.LayerShape.GetUnscaledRectangle();
|
||||
var rect = new Rect(skRect.Left, skRect.Top, Math.Max(0, skRect.Width), Math.Max(0, skRect.Height));
|
||||
|
||||
var shapeGeometry = Geometry.Empty;
|
||||
switch (Layer.LayerShape)
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
case Ellipse _:
|
||||
shapeGeometry = new EllipseGeometry(rect);
|
||||
break;
|
||||
case Fill _:
|
||||
shapeGeometry = LayerGeometry;
|
||||
break;
|
||||
case Polygon _:
|
||||
// TODO
|
||||
shapeGeometry = new RectangleGeometry(rect);
|
||||
break;
|
||||
case Rectangle _:
|
||||
shapeGeometry = new RectangleGeometry(rect);
|
||||
break;
|
||||
}
|
||||
|
||||
shapeGeometry.Freeze();
|
||||
ShapeGeometry = shapeGeometry;
|
||||
var rect = _layerEditorService.GetShapeRenderRect(Layer.LayerShape);
|
||||
var shapeGeometry = Geometry.Empty;
|
||||
switch (Layer.LayerShape)
|
||||
{
|
||||
case Ellipse _:
|
||||
shapeGeometry = new EllipseGeometry(rect);
|
||||
break;
|
||||
case Fill _:
|
||||
shapeGeometry = LayerGeometry;
|
||||
break;
|
||||
case Polygon _:
|
||||
// TODO
|
||||
shapeGeometry = new RectangleGeometry(rect);
|
||||
break;
|
||||
case Rectangle _:
|
||||
shapeGeometry = new RectangleGeometry(rect);
|
||||
break;
|
||||
}
|
||||
|
||||
shapeGeometry.Transform = _layerEditorService.GetLayerTransformGroup(Layer);
|
||||
shapeGeometry.Freeze();
|
||||
ShapeGeometry = shapeGeometry;
|
||||
});
|
||||
}
|
||||
|
||||
private void CreateViewportRectangle()
|
||||
|
||||
@@ -14,6 +14,7 @@ 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,6 +24,7 @@ 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 IProfileLayerViewModelFactory _profileLayerViewModelFactory;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
@@ -32,12 +34,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
private TimerUpdateTrigger _updateTrigger;
|
||||
|
||||
public ProfileViewModel(IProfileEditorService profileEditorService,
|
||||
ILayerEditorService layerEditorService,
|
||||
ISurfaceService surfaceService,
|
||||
ISettingsService settingsService,
|
||||
IEventAggregator eventAggregator,
|
||||
IProfileLayerViewModelFactory profileLayerViewModelFactory)
|
||||
{
|
||||
_profileEditorService = profileEditorService;
|
||||
_layerEditorService = layerEditorService;
|
||||
_surfaceService = surfaceService;
|
||||
_settingsService = settingsService;
|
||||
_profileLayerViewModelFactory = profileLayerViewModelFactory;
|
||||
@@ -46,7 +50,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
{
|
||||
CanvasViewModels = new ObservableCollection<CanvasViewModel>();
|
||||
DeviceViewModels = new ObservableCollection<ProfileDeviceViewModel>();
|
||||
PanZoomViewModel = new PanZoomViewModel();
|
||||
PanZoomViewModel = new PanZoomViewModel {LimitToZero = false};
|
||||
});
|
||||
|
||||
ApplySurfaceConfiguration(surfaceService.ActiveSurface);
|
||||
@@ -246,16 +250,17 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
private void ActivateToolByIndex(int value)
|
||||
{
|
||||
// Consider using DI if dependencies start to add up
|
||||
switch (value)
|
||||
{
|
||||
case 0:
|
||||
ActiveToolViewModel = new ViewpointMoveToolViewModel(this, _profileEditorService);
|
||||
break;
|
||||
case 1:
|
||||
ActiveToolViewModel = new EditToolViewModel(this, _profileEditorService);
|
||||
ActiveToolViewModel = new EditToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||
break;
|
||||
case 2:
|
||||
ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService);
|
||||
ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||
break;
|
||||
case 3:
|
||||
ActiveToolViewModel = new SelectionAddToolViewModel(this, _profileEditorService);
|
||||
@@ -264,10 +269,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
ActiveToolViewModel = new SelectionRemoveToolViewModel(this, _profileEditorService);
|
||||
break;
|
||||
case 6:
|
||||
ActiveToolViewModel = new EllipseToolViewModel(this, _profileEditorService);
|
||||
ActiveToolViewModel = new EllipseToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||
break;
|
||||
case 7:
|
||||
ActiveToolViewModel = new RectangleToolViewModel(this, _profileEditorService);
|
||||
ActiveToolViewModel = new RectangleToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||
break;
|
||||
case 8:
|
||||
ActiveToolViewModel = new PolygonToolViewModel(this, _profileEditorService);
|
||||
|
||||
+106
-99
@@ -10,112 +10,119 @@
|
||||
d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type local:EditToolViewModel}}">
|
||||
<Canvas UseLayoutRounding="False">
|
||||
<!-- The rectangle around the shape that allows modification -->
|
||||
<Rectangle Width="{Binding ShapeSkRect.Width}"
|
||||
Height="{Binding ShapeSkRect.Height}"
|
||||
Canvas.Left="{Binding ShapeSkRect.Left}"
|
||||
Canvas.Top="{Binding ShapeSkRect.Top}"
|
||||
Fill="Transparent"
|
||||
Stroke="{DynamicResource PrimaryHueMidBrush}"
|
||||
StrokeThickness="1"
|
||||
StrokeDashArray="2 2"
|
||||
Cursor="Hand"
|
||||
MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action Move}" />
|
||||
<Canvas>
|
||||
<!-- The rectangle around the shape that allows modification -->
|
||||
<Canvas.RenderTransform>
|
||||
<TransformGroup Children="{Binding LayerTransformChildren}" />
|
||||
</Canvas.RenderTransform>
|
||||
<Rectangle Width="{Binding ShapeSkRect.Width}"
|
||||
Height="{Binding ShapeSkRect.Height}"
|
||||
Canvas.Left="{Binding ShapeSkRect.Left}"
|
||||
Canvas.Top="{Binding ShapeSkRect.Top}"
|
||||
Fill="Transparent"
|
||||
Stroke="{DynamicResource PrimaryHueMidBrush}"
|
||||
StrokeThickness="1"
|
||||
StrokeDashArray="2 2"
|
||||
Cursor="Hand"
|
||||
MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action Move}" />
|
||||
|
||||
<!-- Anchor point -->
|
||||
<Ellipse MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action AnchorMove}"
|
||||
Width="6" Height="6" Fill="{DynamicResource SecondaryAccentBrush}" Canvas.Left="{Binding AnchorSkPoint.X}" Canvas.Top="{Binding AnchorSkPoint.Y}" Margin="-3,-3,0,0" Cursor="SizeAll" />
|
||||
<!-- Top left display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Top left rotate handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopLeftRotate}"
|
||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-12,-12,0,0"
|
||||
Cursor="/Resources/aero_rotate_tl.cur" />
|
||||
<!-- Top left resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopLeftResize}"
|
||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-3,-3,0,0" Cursor="SizeNWSE" />
|
||||
|
||||
<!-- Top left display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Top left rotate handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopLeftRotate}"
|
||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-12,-12,0,0"
|
||||
Cursor="/Resources/aero_rotate_tl.cur" />
|
||||
<!-- Top left resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopLeftResize}"
|
||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-3,-3,0,0" Cursor="SizeNWSE" />
|
||||
<!-- Top center display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Top center resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopCenterResize}"
|
||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeNS" />
|
||||
|
||||
<!-- Top center display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Top center resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopCenterResize}"
|
||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeNS" />
|
||||
<!-- Top right display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Top right rotate handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopRightRotate}"
|
||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-3,-12,0,0"
|
||||
Cursor="/Resources/aero_rotate_tr.cur" />
|
||||
<!-- Top right resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopRightResize}"
|
||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-3,-3,0,0" Cursor="SizeNESW" />
|
||||
|
||||
<!-- Top right display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Top right rotate handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopRightRotate}"
|
||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-3,-12,0,0"
|
||||
Cursor="/Resources/aero_rotate_tr.cur" />
|
||||
<!-- Top right resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action TopRightResize}"
|
||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-3,-3,0,0" Cursor="SizeNESW" />
|
||||
<!-- Center right display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Center right resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action CenterRightResize}"
|
||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeWE" />
|
||||
|
||||
<!-- Center right display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Center right resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action CenterRightResize}"
|
||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeWE" />
|
||||
<!-- Bottom right display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Bottom right rotate handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomRightRotate}"
|
||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-3,-3,0,0"
|
||||
Cursor="/Resources/aero_rotate_br.cur" />
|
||||
<!-- Bottom right resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomRightResize}"
|
||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-3,-3,0,0" Cursor="SizeNWSE" />
|
||||
|
||||
<!-- Bottom right display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Bottom right rotate handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomRightRotate}"
|
||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-3,-3,0,0"
|
||||
Cursor="/Resources/aero_rotate_br.cur" />
|
||||
<!-- Bottom right resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomRightResize}"
|
||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-3,-3,0,0" Cursor="SizeNWSE" />
|
||||
<!-- Bottom center display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Bottom center resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomCenterResize}"
|
||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeNS" />
|
||||
|
||||
<!-- Bottom center display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Bottom center resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomCenterResize}"
|
||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeNS" />
|
||||
<!-- Bottom left display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Bottom left rotate handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomLeftRotate}"
|
||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-12,-3,0,0"
|
||||
Cursor="/Resources/aero_rotate_bl.cur" />
|
||||
<!-- Bottom left resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomLeftResize}"
|
||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-3, -3, 0,0" Cursor="SizeNESW" />
|
||||
|
||||
<!-- Bottom left display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Bottom left rotate handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomLeftRotate}"
|
||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-12,-3,0,0"
|
||||
Cursor="/Resources/aero_rotate_bl.cur" />
|
||||
<!-- Bottom left resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action BottomLeftResize}"
|
||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-3, -3, 0,0" Cursor="SizeNESW" />
|
||||
|
||||
<!-- Center left display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Center left resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action CenterLeftResize}"
|
||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeWE" />
|
||||
<!-- Center left display -->
|
||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||
<!-- Center left resize handle -->
|
||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action CenterLeftResize}"
|
||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeWE" />
|
||||
</Canvas>
|
||||
<Canvas>
|
||||
<!-- Anchor point -->
|
||||
<Ellipse MouseDown="{s:Action AnchorEditMouseDown}"
|
||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||
MouseMove="{s:Action AnchorMove}"
|
||||
Width="6" Height="6" Fill="{DynamicResource SecondaryAccentBrush}" Canvas.Left="{Binding AnchorSkPoint.X}" Canvas.Top="{Binding AnchorSkPoint.Y}" Margin="-3,-3,0,0"
|
||||
Cursor="SizeAll" />
|
||||
</Canvas>
|
||||
</Canvas>
|
||||
</UserControl>
|
||||
+87
-49
@@ -3,13 +3,17 @@ using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.UI.Services;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp.Views.WPF;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
public class EditToolViewModel : VisualizationToolViewModel
|
||||
{
|
||||
private readonly ILayerEditorService _layerEditorService;
|
||||
private bool _draggingHorizontally;
|
||||
private bool _draggingVertically;
|
||||
private double _dragOffsetX;
|
||||
@@ -17,8 +21,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
private Point _dragStart;
|
||||
private bool _isDragging;
|
||||
|
||||
public EditToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
|
||||
public EditToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
: base(profileViewModel, profileEditorService)
|
||||
{
|
||||
_layerEditorService = layerEditorService;
|
||||
Cursor = Cursors.Arrow;
|
||||
Update();
|
||||
|
||||
@@ -29,6 +35,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
|
||||
public SKRect ShapeSkRect { get; set; }
|
||||
public SKPoint AnchorSkPoint { get; set; }
|
||||
public TransformCollection LayerTransformChildren { get; set; }
|
||||
|
||||
private void Update()
|
||||
{
|
||||
@@ -36,12 +43,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
if (layer.LayerShape != null)
|
||||
{
|
||||
ShapeSkRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
ShapeSkRect = _layerEditorService.GetShapeRenderRect(layer.LayerShape).ToSKRect();
|
||||
AnchorSkPoint = layer.LayerShape.GetUnscaledAnchor();
|
||||
Execute.PostToUIThread(() => LayerTransformChildren = _layerEditorService.GetLayerTransformGroup(layer).Children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ShapeEditMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (_isDragging)
|
||||
@@ -51,7 +60,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||
{
|
||||
var dragStartPosition = GetRelativePosition(sender, e);
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
_dragOffsetX = skRect.Left - dragStartPosition.X;
|
||||
_dragOffsetY = skRect.Top - dragStartPosition.Y;
|
||||
_dragStart = dragStartPosition;
|
||||
@@ -64,15 +73,29 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
public void AnchorEditMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (_isDragging)
|
||||
return;
|
||||
|
||||
// Use the regular mousedown
|
||||
ShapeEditMouseDown(sender, e);
|
||||
// Override the drag offset
|
||||
var dragStartPosition = GetRelativePosition(sender, e);
|
||||
_dragOffsetX = AnchorSkPoint.X - dragStartPosition.X;
|
||||
_dragOffsetY = AnchorSkPoint.Y - dragStartPosition.Y;
|
||||
_dragStart = dragStartPosition;
|
||||
}
|
||||
|
||||
public void ShapeEditMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
((IInputElement) sender).ReleaseMouseCapture();
|
||||
ProfileEditorService.UpdateSelectedProfileElement();
|
||||
|
||||
_isDragging = false;
|
||||
_draggingHorizontally = false;
|
||||
_draggingVertically = false;
|
||||
|
||||
((IInputElement) sender).ReleaseMouseCapture();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -82,7 +105,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
layer.LayerShape.SetFromUnscaledAnchor(new SKPoint((float) position.X, (float) position.Y), ProfileEditorService.CurrentTime);
|
||||
var x = (float) (position.X + _dragOffsetX);
|
||||
var y = (float) (position.Y + _dragOffsetY);
|
||||
layer.LayerShape.SetFromUnscaledAnchor(new SKPoint(x, y), ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
}
|
||||
|
||||
@@ -92,24 +117,25 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
var x = (float) (position.X + _dragOffsetX);
|
||||
var y = (float) (position.Y + _dragOffsetY);
|
||||
|
||||
if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||
layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(x, y, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
||||
else
|
||||
{
|
||||
if (_draggingVertically)
|
||||
layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(skRect.Left, y, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
||||
else if (_draggingHorizontally)
|
||||
layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(x, skRect.Top, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
||||
else
|
||||
{
|
||||
_draggingHorizontally = Math.Abs(position.X - _dragStart.X) > Math.Abs(position.Y - _dragStart.Y);
|
||||
_draggingVertically = Math.Abs(position.X - _dragStart.X) < Math.Abs(position.Y - _dragStart.Y);
|
||||
}
|
||||
}
|
||||
// TODO: Update the translation
|
||||
// if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||
// layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(x, y, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
||||
// else
|
||||
// {
|
||||
// if (_draggingVertically)
|
||||
// layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(skRect.Left, y, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
||||
// else if (_draggingHorizontally)
|
||||
// layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(x, skRect.Top, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
||||
// else
|
||||
// {
|
||||
// _draggingHorizontally = Math.Abs(position.X - _dragStart.X) > Math.Abs(position.Y - _dragStart.Y);
|
||||
// _draggingVertically = Math.Abs(position.X - _dragStart.X) < Math.Abs(position.Y - _dragStart.Y);
|
||||
// }
|
||||
// }
|
||||
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
}
|
||||
@@ -124,7 +150,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||
{
|
||||
// Take the greatest difference
|
||||
@@ -136,8 +162,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
skRect.Left = (float) Math.Min(position.X, skRect.Bottom);
|
||||
}
|
||||
|
||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
ApplyShapeResize(skRect);
|
||||
}
|
||||
|
||||
public void TopCenterResize(object sender, MouseEventArgs e)
|
||||
@@ -147,10 +172,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
skRect.Top = (float) Math.Min(position.Y, skRect.Bottom);
|
||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
ApplyShapeResize(skRect);
|
||||
}
|
||||
|
||||
public void TopRightRotate(object sender, MouseEventArgs e)
|
||||
@@ -163,7 +187,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||
{
|
||||
// Take the greatest difference
|
||||
@@ -175,8 +199,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
skRect.Right = (float) Math.Max(position.X, skRect.Left);
|
||||
}
|
||||
|
||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
ApplyShapeResize(skRect);
|
||||
}
|
||||
|
||||
public void CenterRightResize(object sender, MouseEventArgs e)
|
||||
@@ -186,16 +209,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
skRect.Right = (float) Math.Max(position.X, skRect.Left);
|
||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
}
|
||||
|
||||
private Point GetRelativePosition(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
var parent = VisualTreeHelper.GetParent((DependencyObject) sender);
|
||||
return mouseEventArgs.GetPosition((IInputElement) parent);
|
||||
ApplyShapeResize(skRect);
|
||||
}
|
||||
|
||||
public void BottomRightRotate(object sender, MouseEventArgs e)
|
||||
@@ -208,7 +224,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||
{
|
||||
// Take the greatest difference
|
||||
@@ -220,8 +236,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
skRect.Right = (float) Math.Max(position.X, skRect.Left);
|
||||
}
|
||||
|
||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
ApplyShapeResize(skRect);
|
||||
}
|
||||
|
||||
public void BottomCenterResize(object sender, MouseEventArgs e)
|
||||
@@ -231,10 +246,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
skRect.Bottom = (float) Math.Max(position.Y, skRect.Top);
|
||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
ApplyShapeResize(skRect);
|
||||
}
|
||||
|
||||
public void BottomLeftRotate(object sender, MouseEventArgs e)
|
||||
@@ -247,7 +261,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||
{
|
||||
// Take the greatest difference
|
||||
@@ -259,8 +273,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
skRect.Left = (float) Math.Min(position.X, skRect.Right);
|
||||
}
|
||||
|
||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
ApplyShapeResize(skRect);
|
||||
}
|
||||
|
||||
public void CenterLeftResize(object sender, MouseEventArgs e)
|
||||
@@ -270,9 +283,34 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
|
||||
var position = GetRelativePosition(sender, e);
|
||||
|
||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
||||
var skRect = layer.LayerShape.RenderRectangle;
|
||||
skRect.Left = (float) Math.Min(position.X, skRect.Right);
|
||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
||||
ApplyShapeResize(skRect);
|
||||
}
|
||||
|
||||
private Point GetRelativePosition(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
var parent = VisualTreeHelper.GetParent((DependencyObject) sender);
|
||||
return mouseEventArgs.GetPosition((IInputElement) parent);
|
||||
}
|
||||
|
||||
private void ApplyShapeResize(SKRect newRect)
|
||||
{
|
||||
if (!(ProfileEditorService.SelectedProfileElement is Layer layer))
|
||||
return;
|
||||
|
||||
// TODO: Apply the translation
|
||||
// Store the original position to create an offset for the anchor
|
||||
// var original = layer.PositionProperty.CurrentValue;
|
||||
// layer.LayerShape.SetFromUnscaledRectangle(newRect, ProfileEditorService.CurrentTime);
|
||||
// var updated = layer.PositionProperty.CurrentValue;
|
||||
// // Apply the offset to the anchor so it stays in at same spot
|
||||
// layer.AnchorPointProperty.SetCurrentValue(new SKPoint(
|
||||
// layer.AnchorPointProperty.CurrentValue.X + (original.X - updated.X),
|
||||
// layer.AnchorPointProperty.CurrentValue.Y + (original.Y - updated.Y)
|
||||
// ), ProfileEditorService.CurrentTime);
|
||||
|
||||
// Update the preview
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -4,6 +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;
|
||||
|
||||
@@ -11,10 +12,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
public class EllipseToolViewModel : VisualizationToolViewModel
|
||||
{
|
||||
private readonly ILayerEditorService _layerEditorService;
|
||||
private bool _shiftDown;
|
||||
|
||||
public EllipseToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
|
||||
public EllipseToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
: base(profileViewModel, profileEditorService)
|
||||
{
|
||||
_layerEditorService = layerEditorService;
|
||||
using (var stream = new MemoryStream(Resources.aero_crosshair))
|
||||
{
|
||||
Cursor = new Cursor(stream);
|
||||
@@ -48,7 +52,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
layer.LayerShape = new Ellipse(layer);
|
||||
|
||||
// Apply the drag rectangle
|
||||
layer.LayerShape.SetFromUnscaledRectangle(DragRectangle.ToSKRect(), ProfileEditorService.CurrentTime);
|
||||
_layerEditorService.SetShapeRenderRect(layer.LayerShape, DragRectangle);
|
||||
ProfileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -4,6 +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;
|
||||
|
||||
@@ -11,10 +12,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
public class RectangleToolViewModel : VisualizationToolViewModel
|
||||
{
|
||||
private readonly ILayerEditorService _layerEditorService;
|
||||
private bool _shiftDown;
|
||||
|
||||
public RectangleToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
|
||||
public RectangleToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
: base(profileViewModel, profileEditorService)
|
||||
{
|
||||
_layerEditorService = layerEditorService;
|
||||
using (var stream = new MemoryStream(Resources.aero_crosshair))
|
||||
{
|
||||
Cursor = new Cursor(stream);
|
||||
@@ -48,7 +52,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
layer.LayerShape = new Rectangle(layer);
|
||||
|
||||
// Apply the drag rectangle
|
||||
layer.LayerShape.SetFromUnscaledRectangle(DragRectangle.ToSKRect(), ProfileEditorService.CurrentTime);
|
||||
_layerEditorService.SetShapeRenderRect(layer.LayerShape, DragRectangle);
|
||||
ProfileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-4
@@ -6,6 +6,7 @@ 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;
|
||||
|
||||
@@ -13,8 +14,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
public class SelectionToolViewModel : VisualizationToolViewModel
|
||||
{
|
||||
public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
|
||||
private readonly ILayerEditorService _layerEditorService;
|
||||
|
||||
public SelectionToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
: base(profileViewModel, profileEditorService)
|
||||
{
|
||||
_layerEditorService = layerEditorService;
|
||||
using (var stream = new MemoryStream(Resources.aero_crosshair))
|
||||
{
|
||||
Cursor = new Cursor(stream);
|
||||
@@ -48,14 +53,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||
{
|
||||
// If the layer has a shape, save it's size
|
||||
var shapeSize = SKRect.Empty;
|
||||
var shapeSize = Rect.Empty;
|
||||
if (layer.LayerShape != null)
|
||||
shapeSize = layer.LayerShape.GetUnscaledRectangle();
|
||||
shapeSize = _layerEditorService.GetShapeRenderRect(layer.LayerShape);
|
||||
layer.ClearLeds();
|
||||
layer.AddLeds(selectedLeds);
|
||||
// Restore the saved size
|
||||
if (layer.LayerShape != null)
|
||||
layer.LayerShape.SetFromUnscaledRectangle(shapeSize, ProfileEditorService.CurrentTime);
|
||||
_layerEditorService.SetShapeRenderRect(layer.LayerShape, shapeSize);
|
||||
|
||||
ProfileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Artemis.UI.Screens.Shared
|
||||
public double PanY { get; set; }
|
||||
public double CanvasWidth { get; set; }
|
||||
public double CanvasHeight { get; set; }
|
||||
public bool LimitToZero { get; set; }
|
||||
|
||||
public Rect BackgroundViewport => new Rect(PanX, PanY, 20, 20);
|
||||
|
||||
@@ -61,8 +62,16 @@ namespace Artemis.UI.Screens.Shared
|
||||
var position = e.GetPosition((IInputElement) sender);
|
||||
var delta = LastPanPosition - position;
|
||||
|
||||
PanX = Math.Min(0, PanX - delta.Value.X);
|
||||
PanY = Math.Min(0, PanY - delta.Value.Y);
|
||||
if (LimitToZero)
|
||||
{
|
||||
PanX = Math.Min(0, PanX - delta.Value.X);
|
||||
PanY = Math.Min(0, PanY - delta.Value.Y);
|
||||
}
|
||||
else
|
||||
{
|
||||
PanX -= delta.Value.X;
|
||||
PanY -= delta.Value.Y;
|
||||
}
|
||||
|
||||
LastPanPosition = position;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.LayerShapes;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp.Views.WPF;
|
||||
|
||||
namespace Artemis.UI.Services
|
||||
{
|
||||
public class LayerEditorService : ILayerEditorService
|
||||
{
|
||||
private readonly ISettingsService _settingsService;
|
||||
|
||||
public LayerEditorService(ISettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rect GetShapeRenderRect(LayerShape layerShape)
|
||||
{
|
||||
// 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)
|
||||
);
|
||||
}
|
||||
|
||||
public Rect GetLayerRenderRect(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.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)
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetShapeRenderRect(LayerShape layerShape, Rect rect)
|
||||
{
|
||||
if (!layerShape.Layer.Leds.Any())
|
||||
{
|
||||
layerShape.ScaledRectangle = SKRect.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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
|
||||
);
|
||||
layerShape.CalculateRenderProperties();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public TransformGroup GetLayerTransformGroup(Layer layer)
|
||||
{
|
||||
var layerRect = GetLayerRenderRect(layer).ToSKRect();
|
||||
var shapeRect = GetShapeRenderRect(layer.LayerShape).ToSKRect();
|
||||
|
||||
// Apply transformation like done by the core during layer rendering
|
||||
var anchor = layer.AnchorPointProperty.CurrentValue;
|
||||
var position = layer.PositionProperty.CurrentValue;
|
||||
var size = layer.SizeProperty.CurrentValue;
|
||||
var rotation = layer.RotationProperty.CurrentValue;
|
||||
// Scale the anchor and make it originate from the center of the untranslated layer shape
|
||||
anchor.X = anchor.X * layerRect.Width + shapeRect.MidX;
|
||||
anchor.Y = anchor.Y * layerRect.Height + shapeRect.MidY;
|
||||
|
||||
var transformGroup = new TransformGroup();
|
||||
transformGroup.Children.Add(new ScaleTransform(size.Width, size.Height, anchor.X, anchor.Y));
|
||||
transformGroup.Children.Add(new RotateTransform(rotation, anchor.X, anchor.Y));
|
||||
transformGroup.Children.Add(new TranslateTransform(position.X * layerRect.Width, position.Y * layerRect.Height));
|
||||
|
||||
return transformGroup;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ILayerEditorService : IArtemisUIService
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns an absolute and scaled rectangle for the given shape that is corrected for the current render scale.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Rect GetShapeRenderRect(LayerShape layerShape);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the render rectangle of the given shape to match the provided unscaled rectangle. The rectangle is corrected
|
||||
/// for the current render scale.
|
||||
/// </summary>
|
||||
/// <param name="layerShape"></param>
|
||||
/// <param name="rect"></param>
|
||||
void SetShapeRenderRect(LayerShape layerShape, Rect rect);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a WPF transform group that contains all the transformations required to render the provided layer.
|
||||
/// Note: Run on UI thread.
|
||||
/// </summary>
|
||||
/// <param name="layer"></param>
|
||||
/// <returns></returns>
|
||||
TransformGroup GetLayerTransformGroup(Layer layer);
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace Artemis.UI.Services
|
||||
baseLayerProperty.KeyframeEngine?.OverrideProgress(CurrentTime);
|
||||
|
||||
// Force layer shape to redraw
|
||||
layer.LayerShape?.CalculateRenderProperties(layer.PositionProperty.CurrentValue, layer.SizeProperty.CurrentValue);
|
||||
layer.LayerShape?.CalculateRenderProperties();
|
||||
// Update the brush with the delta (which can now be negative ^^)
|
||||
layer.Update(delta.TotalSeconds);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user