mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2424bfc7d0
@ -15,7 +15,7 @@ namespace Artemis.Core.Models.Profile.KeyframeEngines
|
|||||||
var nextKeyframe = (Keyframe<int>) NextKeyframe;
|
var nextKeyframe = (Keyframe<int>) NextKeyframe;
|
||||||
|
|
||||||
var diff = nextKeyframe.Value - currentKeyframe.Value;
|
var diff = nextKeyframe.Value - currentKeyframe.Value;
|
||||||
return currentKeyframe.Value + diff * KeyframeProgressEased;
|
return (int) Math.Round(currentKeyframe.Value + diff * KeyframeProgressEased, MidpointRounding.AwayFromZero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,12 +132,12 @@ namespace Artemis.Core.Models.Profile
|
|||||||
public LayerProperty<SKSize> SizeProperty { get; private set; }
|
public LayerProperty<SKSize> SizeProperty { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The rotation property of this layer, also found in <see cref="Properties" />
|
/// The rotation property of this layer range 0 - 360, also found in <see cref="Properties" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LayerProperty<int> RotationProperty { get; private set; }
|
public LayerProperty<int> RotationProperty { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The opacity property of this layer, also found in <see cref="Properties" />
|
/// The opacity property of this layer range 0 - 100, also found in <see cref="Properties" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LayerProperty<float> OpacityProperty { get; private set; }
|
public LayerProperty<float> OpacityProperty { get; private set; }
|
||||||
|
|
||||||
@ -158,9 +158,36 @@ namespace Artemis.Core.Models.Profile
|
|||||||
|
|
||||||
canvas.Save();
|
canvas.Save();
|
||||||
canvas.ClipPath(Path);
|
canvas.ClipPath(Path);
|
||||||
|
|
||||||
|
// Apply transformations
|
||||||
|
var anchor = AnchorPointProperty.CurrentValue;
|
||||||
|
var position = PositionProperty.CurrentValue;
|
||||||
|
var size = SizeProperty.CurrentValue;
|
||||||
|
var rotation = RotationProperty.CurrentValue;
|
||||||
|
// Scale the anchor and make it originate from the center of the untranslated layer shape
|
||||||
|
anchor.X = anchor.X * AbsoluteRectangle.Width + LayerShape.RenderRectangle.MidX;
|
||||||
|
anchor.Y = anchor.Y * AbsoluteRectangle.Height + LayerShape.RenderRectangle.MidY;
|
||||||
|
|
||||||
|
canvas.Translate(position.X * AbsoluteRectangle.Width, position.Y * AbsoluteRectangle.Height);
|
||||||
|
canvas.RotateDegrees(rotation, anchor.X, anchor.Y);
|
||||||
|
canvas.Scale(size.Width, size.Height, anchor.X, anchor.Y);
|
||||||
|
|
||||||
// Placeholder
|
// Placeholder
|
||||||
if (LayerShape?.RenderPath != null)
|
if (LayerShape?.RenderPath != null)
|
||||||
canvas.DrawPath(LayerShape.RenderPath, new SKPaint {Color = new SKColor(255, 0, 0)});
|
{
|
||||||
|
var testColors = new List<SKColor>();
|
||||||
|
for (var i = 0; i < 9; i++)
|
||||||
|
{
|
||||||
|
if (i != 8)
|
||||||
|
testColors.Add(SKColor.FromHsv(i * 32, 100, 100));
|
||||||
|
else
|
||||||
|
testColors.Add(SKColor.FromHsv(0, 100, 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
var shader = SKShader.CreateSweepGradient(new SKPoint(LayerShape.RenderRectangle.MidX, LayerShape.RenderRectangle.MidY), testColors.ToArray());
|
||||||
|
canvas.DrawPath(LayerShape.RenderPath, new SKPaint {Shader = shader});
|
||||||
|
}
|
||||||
|
|
||||||
LayerBrush?.Render(canvas);
|
LayerBrush?.Render(canvas);
|
||||||
canvas.Restore();
|
canvas.Restore();
|
||||||
}
|
}
|
||||||
@ -290,7 +317,7 @@ namespace Artemis.Core.Models.Profile
|
|||||||
Path = path;
|
Path = path;
|
||||||
// This is called here so that the shape's render properties are up to date when other code
|
// This is called here so that the shape's render properties are up to date when other code
|
||||||
// responds to OnRenderPropertiesUpdated
|
// responds to OnRenderPropertiesUpdated
|
||||||
LayerShape?.CalculateRenderProperties(PositionProperty.CurrentValue, SizeProperty.CurrentValue);
|
LayerShape?.CalculateRenderProperties();
|
||||||
|
|
||||||
OnRenderPropertiesUpdated();
|
OnRenderPropertiesUpdated();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,18 +13,13 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
|
public override void CalculateRenderProperties()
|
||||||
{
|
{
|
||||||
var width = Layer.AbsoluteRectangle.Width;
|
RenderRectangle = GetUnscaledRectangle();
|
||||||
var height = Layer.AbsoluteRectangle.Height;
|
|
||||||
var rect = SKRect.Create(shapePosition.X * width, shapePosition.Y * height, shapeSize.Width * width, shapeSize.Height * height);
|
|
||||||
|
|
||||||
var path = new SKPath();
|
var path = new SKPath();
|
||||||
path.AddOval(rect);
|
path.AddOval(RenderRectangle);
|
||||||
path.Transform(SKMatrix.MakeTranslation(Layer.Rectangle.Left, Layer.Rectangle.Top));
|
|
||||||
|
|
||||||
RenderPath = path;
|
RenderPath = path;
|
||||||
RenderRectangle = path.GetRect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ApplyToEntity()
|
public override void ApplyToEntity()
|
||||||
|
|||||||
@ -13,11 +13,10 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
|
public override void CalculateRenderProperties()
|
||||||
{
|
{
|
||||||
// TODO: Scale the path? Not sure if desirable
|
RenderRectangle = GetUnscaledRectangle();
|
||||||
RenderPath = Layer.Path;
|
RenderPath = Layer.Path;
|
||||||
RenderRectangle = Layer.Path.GetRect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ApplyToEntity()
|
public override void ApplyToEntity()
|
||||||
|
|||||||
@ -15,6 +15,7 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
|||||||
protected LayerShape(Layer layer, ShapeEntity shapeEntity)
|
protected LayerShape(Layer layer, ShapeEntity shapeEntity)
|
||||||
{
|
{
|
||||||
Layer = layer;
|
Layer = layer;
|
||||||
|
ScaledRectangle = SKRect.Create(shapeEntity.X, shapeEntity.Y, shapeEntity.Width, shapeEntity.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -23,7 +24,13 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
|||||||
public Layer Layer { get; set; }
|
public Layer Layer { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A render rectangle relative to the layer
|
/// A relative and scaled rectangle that defines where the shape is located in relation to the layer's size
|
||||||
|
/// <para>Note: scaled means a range of 0.0 to 1.0. 1.0 being full width/height, 0.5 being half</para>
|
||||||
|
/// </summary>
|
||||||
|
public SKRect ScaledRectangle { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An absolute and scaled render rectangle
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SKRect RenderRectangle { get; protected set; }
|
public SKRect RenderRectangle { get; protected set; }
|
||||||
|
|
||||||
@ -32,56 +39,29 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public SKPath RenderPath { get; protected set; }
|
public SKPath RenderPath { get; protected set; }
|
||||||
|
|
||||||
public abstract void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize);
|
public abstract void CalculateRenderProperties();
|
||||||
|
|
||||||
public virtual void ApplyToEntity()
|
public virtual void ApplyToEntity()
|
||||||
{
|
{
|
||||||
Layer.LayerEntity.ShapeEntity = new ShapeEntity();
|
Layer.LayerEntity.ShapeEntity = new ShapeEntity
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates Position and Size using the provided unscaled rectangle
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="rect">An unscaled rectangle which is relative to the layer (1.0 being full width/height, 0.5 being half).</param>
|
|
||||||
/// <param name="time">
|
|
||||||
/// An optional timespan to indicate where to set the properties, if null the properties' base values
|
|
||||||
/// will be used.
|
|
||||||
/// </param>
|
|
||||||
public void SetFromUnscaledRectangle(SKRect rect, TimeSpan? time)
|
|
||||||
{
|
|
||||||
if (!Layer.Leds.Any())
|
|
||||||
{
|
{
|
||||||
Layer.PositionProperty.SetCurrentValue(SKPoint.Empty, time);
|
X = ScaledRectangle.Left,
|
||||||
Layer.SizeProperty.SetCurrentValue(SKSize.Empty, time);
|
Y = ScaledRectangle.Top,
|
||||||
return;
|
Width = ScaledRectangle.Width,
|
||||||
}
|
Height = ScaledRectangle.Height
|
||||||
|
};
|
||||||
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;
|
|
||||||
|
|
||||||
Layer.PositionProperty.SetCurrentValue(new SKPoint((float) (100f / width * (rect.Left - x)) / 100f, (float) (100f / height * (rect.Top - y)) / 100f), time);
|
|
||||||
Layer.SizeProperty.SetCurrentValue(new SKSize((float) (100f / width * rect.Width) / 100f, (float) (100f / height * rect.Height) / 100f), time);
|
|
||||||
|
|
||||||
CalculateRenderProperties(Layer.PositionProperty.CurrentValue, Layer.SizeProperty.CurrentValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SKRect GetUnscaledRectangle()
|
protected SKRect GetUnscaledRectangle()
|
||||||
{
|
{
|
||||||
if (!Layer.Leds.Any())
|
if (!Layer.Leds.Any())
|
||||||
return SKRect.Empty;
|
return SKRect.Empty;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
return SKRect.Create(
|
return SKRect.Create(
|
||||||
(float) (x + width * Layer.PositionProperty.CurrentValue.X),
|
Layer.AbsoluteRectangle.Left + Layer.AbsoluteRectangle.Width * ScaledRectangle.Left,
|
||||||
(float) (y + height * Layer.PositionProperty.CurrentValue.Y),
|
Layer.AbsoluteRectangle.Top + Layer.AbsoluteRectangle.Height * ScaledRectangle.Top,
|
||||||
(float) (width * Layer.SizeProperty.CurrentValue.Width),
|
Layer.AbsoluteRectangle.Width * ScaledRectangle.Width,
|
||||||
(float) (height * Layer.SizeProperty.CurrentValue.Height)
|
Layer.AbsoluteRectangle.Height * ScaledRectangle.Height
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,31 +74,21 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
|||||||
return;
|
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;
|
|
||||||
|
|
||||||
Layer.AnchorPointProperty.SetCurrentValue(new SKPoint(
|
Layer.AnchorPointProperty.SetCurrentValue(new SKPoint(
|
||||||
(float) (100f / width * (anchor.X - x - Layer.PositionProperty.CurrentValue.X)) / 100f,
|
100f / Layer.AbsoluteRectangle.Width * (anchor.X - Layer.AbsoluteRectangle.Left - Layer.PositionProperty.CurrentValue.X) / 100f,
|
||||||
(float) (100f / height * (anchor.Y - y - Layer.PositionProperty.CurrentValue.Y)) / 100f
|
100f / Layer.AbsoluteRectangle.Height * (anchor.Y - Layer.AbsoluteRectangle.Top - Layer.PositionProperty.CurrentValue.Y) / 100f
|
||||||
), time);
|
), time);
|
||||||
CalculateRenderProperties(Layer.PositionProperty.CurrentValue, Layer.SizeProperty.CurrentValue);
|
CalculateRenderProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SKPoint GetUnscaledAnchor()
|
public SKPoint GetUnscaledAnchor()
|
||||||
{
|
{
|
||||||
if (!Layer.Leds.Any())
|
if (!Layer.Leds.Any())
|
||||||
return SKPoint.Empty;
|
return SKPoint.Empty;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
return new SKPoint(
|
return new SKPoint(
|
||||||
(float) (x + width * (Layer.AnchorPointProperty.CurrentValue.X + Layer.PositionProperty.CurrentValue.X)),
|
Layer.AbsoluteRectangle.Left + Layer.AbsoluteRectangle.Width * (Layer.AnchorPointProperty.CurrentValue.X + Layer.PositionProperty.CurrentValue.X),
|
||||||
(float) (y + height * (Layer.AnchorPointProperty.CurrentValue.Y + Layer.PositionProperty.CurrentValue.Y))
|
Layer.AbsoluteRectangle.Top + Layer.AbsoluteRectangle.Height * (Layer.AnchorPointProperty.CurrentValue.Y + Layer.PositionProperty.CurrentValue.Y)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,9 +23,19 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The points of this polygon where they need to be rendered inside the layer
|
/// The points of this polygon where they need to be rendered inside the layer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<SKPoint> RenderPoints => Points.Select(p => new SKPoint(p.X * Layer.AbsoluteRectangle.Width, p.Y * Layer.AbsoluteRectangle.Height)).ToList();
|
public List<SKPoint> RenderPoints
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
return Points.Select(p => new SKPoint((float) (p.X * width), (float) (p.Y * height))).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
|
public override void CalculateRenderProperties()
|
||||||
{
|
{
|
||||||
var path = new SKPath();
|
var path = new SKPath();
|
||||||
path.AddPoly(RenderPoints.ToArray());
|
path.AddPoly(RenderPoints.ToArray());
|
||||||
|
|||||||
@ -13,17 +13,13 @@ namespace Artemis.Core.Models.Profile.LayerShapes
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void CalculateRenderProperties(SKPoint shapePosition, SKSize shapeSize)
|
public override void CalculateRenderProperties()
|
||||||
{
|
{
|
||||||
var width = Layer.AbsoluteRectangle.Width;
|
RenderRectangle = GetUnscaledRectangle();
|
||||||
var height = Layer.AbsoluteRectangle.Height;
|
|
||||||
var rect = SKRect.Create(shapePosition.X * width, shapePosition.Y * height, shapeSize.Width * width, shapeSize.Height * height);
|
|
||||||
var path = new SKPath();
|
|
||||||
path.AddRect(rect);
|
|
||||||
path.Transform(SKMatrix.MakeTranslation(Layer.Rectangle.Left, Layer.Rectangle.Top));
|
|
||||||
|
|
||||||
|
var path = new SKPath();
|
||||||
|
path.AddRect(RenderRectangle);
|
||||||
RenderPath = path;
|
RenderPath = path;
|
||||||
RenderRectangle = path.GetRect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ApplyToEntity()
|
public override void ApplyToEntity()
|
||||||
|
|||||||
@ -4,6 +4,10 @@ namespace Artemis.Storage.Entities.Profile
|
|||||||
{
|
{
|
||||||
public class ShapeEntity
|
public class ShapeEntity
|
||||||
{
|
{
|
||||||
|
public float X { get; set; }
|
||||||
|
public float Y { get; set; }
|
||||||
|
public float Width { get; set; }
|
||||||
|
public float Height { get; set; }
|
||||||
public ShapeEntityType Type { get; set; }
|
public ShapeEntityType Type { get; set; }
|
||||||
public List<ShapePointEntity> Points { get; set; }
|
public List<ShapePointEntity> Points { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -222,6 +222,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Screens\Sidebar\SidebarViewModel.cs" />
|
<Compile Include="Screens\Sidebar\SidebarViewModel.cs" />
|
||||||
<Compile Include="Services\Interfaces\IProfileEditorService.cs" />
|
<Compile Include="Services\Interfaces\IProfileEditorService.cs" />
|
||||||
|
<Compile Include="Services\LayerShapeService.cs" />
|
||||||
<Compile Include="Services\ProfileEditorService.cs" />
|
<Compile Include="Services\ProfileEditorService.cs" />
|
||||||
<Compile Include="Utilities\ThemeWatcher.cs" />
|
<Compile Include="Utilities\ThemeWatcher.cs" />
|
||||||
<Compile Include="Behaviors\TreeViewSelectionBehavior.cs" />
|
<Compile Include="Behaviors\TreeViewSelectionBehavior.cs" />
|
||||||
|
|||||||
@ -5,9 +5,13 @@ using System.Windows.Media;
|
|||||||
using Artemis.Core.Models.Profile;
|
using Artemis.Core.Models.Profile;
|
||||||
using Artemis.Core.Models.Profile.LayerShapes;
|
using Artemis.Core.Models.Profile.LayerShapes;
|
||||||
using Artemis.Core.Models.Surface;
|
using Artemis.Core.Models.Surface;
|
||||||
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Extensions;
|
using Artemis.UI.Extensions;
|
||||||
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
|
using SkiaSharp.Views.WPF;
|
||||||
|
using Stylet;
|
||||||
using Rectangle = Artemis.Core.Models.Profile.LayerShapes.Rectangle;
|
using Rectangle = Artemis.Core.Models.Profile.LayerShapes.Rectangle;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||||
@ -15,10 +19,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
public class ProfileLayerViewModel : CanvasViewModel
|
public class ProfileLayerViewModel : CanvasViewModel
|
||||||
{
|
{
|
||||||
private readonly IProfileEditorService _profileEditorService;
|
private readonly IProfileEditorService _profileEditorService;
|
||||||
|
private readonly ILayerEditorService _layerEditorService;
|
||||||
|
|
||||||
public ProfileLayerViewModel(Layer layer, IProfileEditorService profileEditorService)
|
public ProfileLayerViewModel(Layer layer, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||||
{
|
{
|
||||||
_profileEditorService = profileEditorService;
|
_profileEditorService = profileEditorService;
|
||||||
|
_layerEditorService = layerEditorService;
|
||||||
Layer = layer;
|
Layer = layer;
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
@ -83,7 +89,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
}
|
}
|
||||||
|
|
||||||
var layerGeometry = group.GetOutlinedPathGeometry();
|
var layerGeometry = group.GetOutlinedPathGeometry();
|
||||||
|
|
||||||
var opacityGeometry = Geometry.Combine(Geometry.Empty, layerGeometry, GeometryCombineMode.Exclude, new TranslateTransform());
|
var opacityGeometry = Geometry.Combine(Geometry.Empty, layerGeometry, GeometryCombineMode.Exclude, new TranslateTransform());
|
||||||
layerGeometry.Freeze();
|
layerGeometry.Freeze();
|
||||||
opacityGeometry.Freeze();
|
opacityGeometry.Freeze();
|
||||||
@ -99,29 +104,31 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var skRect = Layer.LayerShape.GetUnscaledRectangle();
|
Execute.PostToUIThread(() =>
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
case Ellipse _:
|
var rect = _layerEditorService.GetShapeRenderRect(Layer.LayerShape);
|
||||||
shapeGeometry = new EllipseGeometry(rect);
|
var shapeGeometry = Geometry.Empty;
|
||||||
break;
|
switch (Layer.LayerShape)
|
||||||
case Fill _:
|
{
|
||||||
shapeGeometry = LayerGeometry;
|
case Ellipse _:
|
||||||
break;
|
shapeGeometry = new EllipseGeometry(rect);
|
||||||
case Polygon _:
|
break;
|
||||||
// TODO
|
case Fill _:
|
||||||
shapeGeometry = new RectangleGeometry(rect);
|
shapeGeometry = LayerGeometry;
|
||||||
break;
|
break;
|
||||||
case Rectangle _:
|
case Polygon _:
|
||||||
shapeGeometry = new RectangleGeometry(rect);
|
// TODO
|
||||||
break;
|
shapeGeometry = new RectangleGeometry(rect);
|
||||||
}
|
break;
|
||||||
|
case Rectangle _:
|
||||||
shapeGeometry.Freeze();
|
shapeGeometry = new RectangleGeometry(rect);
|
||||||
ShapeGeometry = shapeGeometry;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
shapeGeometry.Transform = _layerEditorService.GetLayerTransformGroup(Layer);
|
||||||
|
shapeGeometry.Freeze();
|
||||||
|
ShapeGeometry = shapeGeometry;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateViewportRectangle()
|
private void CreateViewportRectangle()
|
||||||
|
|||||||
@ -14,6 +14,7 @@ using Artemis.UI.Events;
|
|||||||
using Artemis.UI.Ninject.Factories;
|
using Artemis.UI.Ninject.Factories;
|
||||||
using Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools;
|
using Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools;
|
||||||
using Artemis.UI.Screens.Shared;
|
using Artemis.UI.Screens.Shared;
|
||||||
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using Stylet;
|
using Stylet;
|
||||||
@ -23,6 +24,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>, IHandle<MainWindowKeyEvent>
|
public class ProfileViewModel : ProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>, IHandle<MainWindowKeyEvent>
|
||||||
{
|
{
|
||||||
private readonly IProfileEditorService _profileEditorService;
|
private readonly IProfileEditorService _profileEditorService;
|
||||||
|
private readonly ILayerEditorService _layerEditorService;
|
||||||
private readonly IProfileLayerViewModelFactory _profileLayerViewModelFactory;
|
private readonly IProfileLayerViewModelFactory _profileLayerViewModelFactory;
|
||||||
private readonly ISettingsService _settingsService;
|
private readonly ISettingsService _settingsService;
|
||||||
private readonly ISurfaceService _surfaceService;
|
private readonly ISurfaceService _surfaceService;
|
||||||
@ -32,12 +34,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
private TimerUpdateTrigger _updateTrigger;
|
private TimerUpdateTrigger _updateTrigger;
|
||||||
|
|
||||||
public ProfileViewModel(IProfileEditorService profileEditorService,
|
public ProfileViewModel(IProfileEditorService profileEditorService,
|
||||||
|
ILayerEditorService layerEditorService,
|
||||||
ISurfaceService surfaceService,
|
ISurfaceService surfaceService,
|
||||||
ISettingsService settingsService,
|
ISettingsService settingsService,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
IProfileLayerViewModelFactory profileLayerViewModelFactory)
|
IProfileLayerViewModelFactory profileLayerViewModelFactory)
|
||||||
{
|
{
|
||||||
_profileEditorService = profileEditorService;
|
_profileEditorService = profileEditorService;
|
||||||
|
_layerEditorService = layerEditorService;
|
||||||
_surfaceService = surfaceService;
|
_surfaceService = surfaceService;
|
||||||
_settingsService = settingsService;
|
_settingsService = settingsService;
|
||||||
_profileLayerViewModelFactory = profileLayerViewModelFactory;
|
_profileLayerViewModelFactory = profileLayerViewModelFactory;
|
||||||
@ -46,7 +50,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
{
|
{
|
||||||
CanvasViewModels = new ObservableCollection<CanvasViewModel>();
|
CanvasViewModels = new ObservableCollection<CanvasViewModel>();
|
||||||
DeviceViewModels = new ObservableCollection<ProfileDeviceViewModel>();
|
DeviceViewModels = new ObservableCollection<ProfileDeviceViewModel>();
|
||||||
PanZoomViewModel = new PanZoomViewModel();
|
PanZoomViewModel = new PanZoomViewModel {LimitToZero = false};
|
||||||
});
|
});
|
||||||
|
|
||||||
ApplySurfaceConfiguration(surfaceService.ActiveSurface);
|
ApplySurfaceConfiguration(surfaceService.ActiveSurface);
|
||||||
@ -246,16 +250,17 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
|
|
||||||
private void ActivateToolByIndex(int value)
|
private void ActivateToolByIndex(int value)
|
||||||
{
|
{
|
||||||
|
// Consider using DI if dependencies start to add up
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
ActiveToolViewModel = new ViewpointMoveToolViewModel(this, _profileEditorService);
|
ActiveToolViewModel = new ViewpointMoveToolViewModel(this, _profileEditorService);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
ActiveToolViewModel = new EditToolViewModel(this, _profileEditorService);
|
ActiveToolViewModel = new EditToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService);
|
ActiveToolViewModel = new SelectionToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
ActiveToolViewModel = new SelectionAddToolViewModel(this, _profileEditorService);
|
ActiveToolViewModel = new SelectionAddToolViewModel(this, _profileEditorService);
|
||||||
@ -264,10 +269,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
|||||||
ActiveToolViewModel = new SelectionRemoveToolViewModel(this, _profileEditorService);
|
ActiveToolViewModel = new SelectionRemoveToolViewModel(this, _profileEditorService);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
ActiveToolViewModel = new EllipseToolViewModel(this, _profileEditorService);
|
ActiveToolViewModel = new EllipseToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
ActiveToolViewModel = new RectangleToolViewModel(this, _profileEditorService);
|
ActiveToolViewModel = new RectangleToolViewModel(this, _profileEditorService, _layerEditorService);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
ActiveToolViewModel = new PolygonToolViewModel(this, _profileEditorService);
|
ActiveToolViewModel = new PolygonToolViewModel(this, _profileEditorService);
|
||||||
|
|||||||
@ -10,112 +10,119 @@
|
|||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
d:DataContext="{d:DesignInstance {x:Type local:EditToolViewModel}}">
|
d:DataContext="{d:DesignInstance {x:Type local:EditToolViewModel}}">
|
||||||
<Canvas UseLayoutRounding="False">
|
<Canvas UseLayoutRounding="False">
|
||||||
<!-- The rectangle around the shape that allows modification -->
|
<Canvas>
|
||||||
<Rectangle Width="{Binding ShapeSkRect.Width}"
|
<!-- The rectangle around the shape that allows modification -->
|
||||||
Height="{Binding ShapeSkRect.Height}"
|
<Canvas.RenderTransform>
|
||||||
Canvas.Left="{Binding ShapeSkRect.Left}"
|
<TransformGroup Children="{Binding LayerTransformChildren}" />
|
||||||
Canvas.Top="{Binding ShapeSkRect.Top}"
|
</Canvas.RenderTransform>
|
||||||
Fill="Transparent"
|
<Rectangle Width="{Binding ShapeSkRect.Width}"
|
||||||
Stroke="{DynamicResource PrimaryHueMidBrush}"
|
Height="{Binding ShapeSkRect.Height}"
|
||||||
StrokeThickness="1"
|
Canvas.Left="{Binding ShapeSkRect.Left}"
|
||||||
StrokeDashArray="2 2"
|
Canvas.Top="{Binding ShapeSkRect.Top}"
|
||||||
Cursor="Hand"
|
Fill="Transparent"
|
||||||
MouseDown="{s:Action ShapeEditMouseDown}"
|
Stroke="{DynamicResource PrimaryHueMidBrush}"
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
StrokeThickness="1"
|
||||||
MouseMove="{s:Action Move}" />
|
StrokeDashArray="2 2"
|
||||||
|
Cursor="Hand"
|
||||||
|
MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
|
MouseMove="{s:Action Move}" />
|
||||||
|
|
||||||
<!-- Anchor point -->
|
<!-- Top left display -->
|
||||||
<Ellipse MouseDown="{s:Action ShapeEditMouseDown}"
|
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
<!-- Top left rotate handle -->
|
||||||
MouseMove="{s:Action AnchorMove}"
|
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
Width="6" Height="6" Fill="{DynamicResource SecondaryAccentBrush}" Canvas.Left="{Binding AnchorSkPoint.X}" Canvas.Top="{Binding AnchorSkPoint.Y}" Margin="-3,-3,0,0" Cursor="SizeAll" />
|
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 -->
|
<!-- Top center display -->
|
||||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||||
<!-- Top left rotate handle -->
|
<!-- Top center resize handle -->
|
||||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
MouseMove="{s:Action TopLeftRotate}"
|
MouseMove="{s:Action TopCenterResize}"
|
||||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-12,-12,0,0"
|
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeNS" />
|
||||||
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 -->
|
<!-- Top right display -->
|
||||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||||
<!-- Top center resize handle -->
|
<!-- Top right rotate handle -->
|
||||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
MouseMove="{s:Action TopCenterResize}"
|
MouseMove="{s:Action TopRightRotate}"
|
||||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeNS" />
|
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 -->
|
<!-- Center 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" />
|
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||||
<!-- Top right rotate handle -->
|
<!-- Center right resize handle -->
|
||||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
MouseMove="{s:Action TopRightRotate}"
|
MouseMove="{s:Action CenterRightResize}"
|
||||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Top}" Fill="Transparent" Margin="-3,-12,0,0"
|
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeWE" />
|
||||||
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 -->
|
<!-- Bottom 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" />
|
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||||
<!-- Center right resize handle -->
|
<!-- Bottom right rotate handle -->
|
||||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
MouseMove="{s:Action CenterRightResize}"
|
MouseMove="{s:Action BottomRightRotate}"
|
||||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeWE" />
|
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 -->
|
<!-- Bottom center display -->
|
||||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||||
<!-- Bottom right rotate handle -->
|
<!-- Bottom center resize handle -->
|
||||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
MouseMove="{s:Action BottomRightRotate}"
|
MouseMove="{s:Action BottomCenterResize}"
|
||||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Right}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-3,-3,0,0"
|
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeNS" />
|
||||||
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 -->
|
<!-- Bottom left display -->
|
||||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||||
<!-- Bottom center resize handle -->
|
<!-- Bottom left rotate handle -->
|
||||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
MouseMove="{s:Action BottomCenterResize}"
|
MouseMove="{s:Action BottomLeftRotate}"
|
||||||
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.MidX}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeNS" />
|
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 -->
|
<!-- Center 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" />
|
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
||||||
<!-- Bottom left rotate handle -->
|
<!-- Center left resize handle -->
|
||||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
MouseMove="{s:Action BottomLeftRotate}"
|
MouseMove="{s:Action CenterLeftResize}"
|
||||||
Width="15" Height="15" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-12,-3,0,0"
|
Width="10" Height="10" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="Transparent" Margin="-5,-5,0,0" Cursor="SizeWE" />
|
||||||
Cursor="/Resources/aero_rotate_bl.cur" />
|
</Canvas>
|
||||||
<!-- Bottom left resize handle -->
|
<Canvas>
|
||||||
<Rectangle MouseDown="{s:Action ShapeEditMouseDown}"
|
<!-- Anchor point -->
|
||||||
MouseUp="{s:Action ShapeEditMouseUp}"
|
<Ellipse MouseDown="{s:Action AnchorEditMouseDown}"
|
||||||
MouseMove="{s:Action BottomLeftResize}"
|
MouseUp="{s:Action ShapeEditMouseUp}"
|
||||||
Width="6" Height="6" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.Bottom}" Fill="Transparent" Margin="-3, -3, 0,0" Cursor="SizeNESW" />
|
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"
|
||||||
<!-- Center left display -->
|
Cursor="SizeAll" />
|
||||||
<Rectangle Width="4" Height="4" Canvas.Left="{Binding ShapeSkRect.Left}" Canvas.Top="{Binding ShapeSkRect.MidY}" Fill="{DynamicResource SecondaryAccentBrush}" Margin="-2,-2,0,0" />
|
</Canvas>
|
||||||
<!-- 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>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
@ -3,13 +3,17 @@ using System.Windows;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.Core.Models.Profile;
|
using Artemis.Core.Models.Profile;
|
||||||
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
using SkiaSharp.Views.WPF;
|
||||||
|
using Stylet;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||||
{
|
{
|
||||||
public class EditToolViewModel : VisualizationToolViewModel
|
public class EditToolViewModel : VisualizationToolViewModel
|
||||||
{
|
{
|
||||||
|
private readonly ILayerEditorService _layerEditorService;
|
||||||
private bool _draggingHorizontally;
|
private bool _draggingHorizontally;
|
||||||
private bool _draggingVertically;
|
private bool _draggingVertically;
|
||||||
private double _dragOffsetX;
|
private double _dragOffsetX;
|
||||||
@ -17,8 +21,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
private Point _dragStart;
|
private Point _dragStart;
|
||||||
private bool _isDragging;
|
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;
|
Cursor = Cursors.Arrow;
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
@ -29,6 +35,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
|
|
||||||
public SKRect ShapeSkRect { get; set; }
|
public SKRect ShapeSkRect { get; set; }
|
||||||
public SKPoint AnchorSkPoint { get; set; }
|
public SKPoint AnchorSkPoint { get; set; }
|
||||||
|
public TransformCollection LayerTransformChildren { get; set; }
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
@ -36,12 +43,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
{
|
{
|
||||||
if (layer.LayerShape != null)
|
if (layer.LayerShape != null)
|
||||||
{
|
{
|
||||||
ShapeSkRect = layer.LayerShape.GetUnscaledRectangle();
|
ShapeSkRect = _layerEditorService.GetShapeRenderRect(layer.LayerShape).ToSKRect();
|
||||||
AnchorSkPoint = layer.LayerShape.GetUnscaledAnchor();
|
AnchorSkPoint = layer.LayerShape.GetUnscaledAnchor();
|
||||||
|
Execute.PostToUIThread(() => LayerTransformChildren = _layerEditorService.GetLayerTransformGroup(layer).Children);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ShapeEditMouseDown(object sender, MouseButtonEventArgs e)
|
public void ShapeEditMouseDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
if (_isDragging)
|
if (_isDragging)
|
||||||
@ -51,7 +60,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||||
{
|
{
|
||||||
var dragStartPosition = GetRelativePosition(sender, e);
|
var dragStartPosition = GetRelativePosition(sender, e);
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
_dragOffsetX = skRect.Left - dragStartPosition.X;
|
_dragOffsetX = skRect.Left - dragStartPosition.X;
|
||||||
_dragOffsetY = skRect.Top - dragStartPosition.Y;
|
_dragOffsetY = skRect.Top - dragStartPosition.Y;
|
||||||
_dragStart = dragStartPosition;
|
_dragStart = dragStartPosition;
|
||||||
@ -64,15 +73,29 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
e.Handled = true;
|
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)
|
public void ShapeEditMouseUp(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
((IInputElement) sender).ReleaseMouseCapture();
|
|
||||||
ProfileEditorService.UpdateSelectedProfileElement();
|
ProfileEditorService.UpdateSelectedProfileElement();
|
||||||
|
|
||||||
_isDragging = false;
|
_isDragging = false;
|
||||||
_draggingHorizontally = false;
|
_draggingHorizontally = false;
|
||||||
_draggingVertically = false;
|
_draggingVertically = false;
|
||||||
|
|
||||||
|
((IInputElement) sender).ReleaseMouseCapture();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +105,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var position = GetRelativePosition(sender, e);
|
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();
|
ProfileEditorService.UpdateProfilePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,24 +117,25 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var position = GetRelativePosition(sender, e);
|
var position = GetRelativePosition(sender, e);
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
var x = (float) (position.X + _dragOffsetX);
|
var x = (float) (position.X + _dragOffsetX);
|
||||||
var y = (float) (position.Y + _dragOffsetY);
|
var y = (float) (position.Y + _dragOffsetY);
|
||||||
|
|
||||||
if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
// TODO: Update the translation
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(x, y, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
// if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||||
else
|
// 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);
|
// if (_draggingVertically)
|
||||||
else if (_draggingHorizontally)
|
// layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(skRect.Left, y, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(SKRect.Create(x, skRect.Top, skRect.Width, skRect.Height), ProfileEditorService.CurrentTime);
|
// else if (_draggingHorizontally)
|
||||||
else
|
// 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);
|
// _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();
|
ProfileEditorService.UpdateProfilePreview();
|
||||||
}
|
}
|
||||||
@ -124,7 +150,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var position = GetRelativePosition(sender, e);
|
var position = GetRelativePosition(sender, e);
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||||
{
|
{
|
||||||
// Take the greatest difference
|
// 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);
|
skRect.Left = (float) Math.Min(position.X, skRect.Bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
ApplyShapeResize(skRect);
|
||||||
ProfileEditorService.UpdateProfilePreview();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TopCenterResize(object sender, MouseEventArgs e)
|
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 position = GetRelativePosition(sender, e);
|
||||||
|
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
skRect.Top = (float) Math.Min(position.Y, skRect.Bottom);
|
skRect.Top = (float) Math.Min(position.Y, skRect.Bottom);
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
ApplyShapeResize(skRect);
|
||||||
ProfileEditorService.UpdateProfilePreview();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TopRightRotate(object sender, MouseEventArgs e)
|
public void TopRightRotate(object sender, MouseEventArgs e)
|
||||||
@ -163,7 +187,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var position = GetRelativePosition(sender, e);
|
var position = GetRelativePosition(sender, e);
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||||
{
|
{
|
||||||
// Take the greatest difference
|
// 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);
|
skRect.Right = (float) Math.Max(position.X, skRect.Left);
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
ApplyShapeResize(skRect);
|
||||||
ProfileEditorService.UpdateProfilePreview();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CenterRightResize(object sender, MouseEventArgs e)
|
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 position = GetRelativePosition(sender, e);
|
||||||
|
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
skRect.Right = (float) Math.Max(position.X, skRect.Left);
|
skRect.Right = (float) Math.Max(position.X, skRect.Left);
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
ApplyShapeResize(skRect);
|
||||||
ProfileEditorService.UpdateProfilePreview();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Point GetRelativePosition(object sender, MouseEventArgs mouseEventArgs)
|
|
||||||
{
|
|
||||||
var parent = VisualTreeHelper.GetParent((DependencyObject) sender);
|
|
||||||
return mouseEventArgs.GetPosition((IInputElement) parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BottomRightRotate(object sender, MouseEventArgs e)
|
public void BottomRightRotate(object sender, MouseEventArgs e)
|
||||||
@ -208,7 +224,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var position = GetRelativePosition(sender, e);
|
var position = GetRelativePosition(sender, e);
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||||
{
|
{
|
||||||
// Take the greatest difference
|
// 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);
|
skRect.Right = (float) Math.Max(position.X, skRect.Left);
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
ApplyShapeResize(skRect);
|
||||||
ProfileEditorService.UpdateProfilePreview();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BottomCenterResize(object sender, MouseEventArgs e)
|
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 position = GetRelativePosition(sender, e);
|
||||||
|
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
skRect.Bottom = (float) Math.Max(position.Y, skRect.Top);
|
skRect.Bottom = (float) Math.Max(position.Y, skRect.Top);
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
ApplyShapeResize(skRect);
|
||||||
ProfileEditorService.UpdateProfilePreview();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BottomLeftRotate(object sender, MouseEventArgs e)
|
public void BottomLeftRotate(object sender, MouseEventArgs e)
|
||||||
@ -247,7 +261,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var position = GetRelativePosition(sender, e);
|
var position = GetRelativePosition(sender, e);
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||||
{
|
{
|
||||||
// Take the greatest difference
|
// 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);
|
skRect.Left = (float) Math.Min(position.X, skRect.Right);
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(skRect, ProfileEditorService.CurrentTime);
|
ApplyShapeResize(skRect);
|
||||||
ProfileEditorService.UpdateProfilePreview();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CenterLeftResize(object sender, MouseEventArgs e)
|
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 position = GetRelativePosition(sender, e);
|
||||||
|
|
||||||
var skRect = layer.LayerShape.GetUnscaledRectangle();
|
var skRect = layer.LayerShape.RenderRectangle;
|
||||||
skRect.Left = (float) Math.Min(position.X, skRect.Right);
|
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();
|
ProfileEditorService.UpdateProfilePreview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using System.Windows.Input;
|
|||||||
using Artemis.Core.Models.Profile;
|
using Artemis.Core.Models.Profile;
|
||||||
using Artemis.Core.Models.Profile.LayerShapes;
|
using Artemis.Core.Models.Profile.LayerShapes;
|
||||||
using Artemis.UI.Properties;
|
using Artemis.UI.Properties;
|
||||||
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using SkiaSharp.Views.WPF;
|
using SkiaSharp.Views.WPF;
|
||||||
|
|
||||||
@ -11,10 +12,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
{
|
{
|
||||||
public class EllipseToolViewModel : VisualizationToolViewModel
|
public class EllipseToolViewModel : VisualizationToolViewModel
|
||||||
{
|
{
|
||||||
|
private readonly ILayerEditorService _layerEditorService;
|
||||||
private bool _shiftDown;
|
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))
|
using (var stream = new MemoryStream(Resources.aero_crosshair))
|
||||||
{
|
{
|
||||||
Cursor = new Cursor(stream);
|
Cursor = new Cursor(stream);
|
||||||
@ -48,7 +52,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
layer.LayerShape = new Ellipse(layer);
|
layer.LayerShape = new Ellipse(layer);
|
||||||
|
|
||||||
// Apply the drag rectangle
|
// Apply the drag rectangle
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(DragRectangle.ToSKRect(), ProfileEditorService.CurrentTime);
|
_layerEditorService.SetShapeRenderRect(layer.LayerShape, DragRectangle);
|
||||||
ProfileEditorService.UpdateSelectedProfileElement();
|
ProfileEditorService.UpdateSelectedProfileElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using System.Windows.Input;
|
|||||||
using Artemis.Core.Models.Profile;
|
using Artemis.Core.Models.Profile;
|
||||||
using Artemis.Core.Models.Profile.LayerShapes;
|
using Artemis.Core.Models.Profile.LayerShapes;
|
||||||
using Artemis.UI.Properties;
|
using Artemis.UI.Properties;
|
||||||
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using SkiaSharp.Views.WPF;
|
using SkiaSharp.Views.WPF;
|
||||||
|
|
||||||
@ -11,10 +12,13 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
{
|
{
|
||||||
public class RectangleToolViewModel : VisualizationToolViewModel
|
public class RectangleToolViewModel : VisualizationToolViewModel
|
||||||
{
|
{
|
||||||
|
private readonly ILayerEditorService _layerEditorService;
|
||||||
private bool _shiftDown;
|
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))
|
using (var stream = new MemoryStream(Resources.aero_crosshair))
|
||||||
{
|
{
|
||||||
Cursor = new Cursor(stream);
|
Cursor = new Cursor(stream);
|
||||||
@ -48,7 +52,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
layer.LayerShape = new Rectangle(layer);
|
layer.LayerShape = new Rectangle(layer);
|
||||||
|
|
||||||
// Apply the drag rectangle
|
// Apply the drag rectangle
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(DragRectangle.ToSKRect(), ProfileEditorService.CurrentTime);
|
_layerEditorService.SetShapeRenderRect(layer.LayerShape, DragRectangle);
|
||||||
ProfileEditorService.UpdateSelectedProfileElement();
|
ProfileEditorService.UpdateSelectedProfileElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ using Artemis.Core.Models.Profile;
|
|||||||
using Artemis.Core.Models.Surface;
|
using Artemis.Core.Models.Surface;
|
||||||
using Artemis.UI.Extensions;
|
using Artemis.UI.Extensions;
|
||||||
using Artemis.UI.Properties;
|
using Artemis.UI.Properties;
|
||||||
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
@ -13,8 +14,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
{
|
{
|
||||||
public class SelectionToolViewModel : VisualizationToolViewModel
|
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))
|
using (var stream = new MemoryStream(Resources.aero_crosshair))
|
||||||
{
|
{
|
||||||
Cursor = new Cursor(stream);
|
Cursor = new Cursor(stream);
|
||||||
@ -48,14 +53,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
|||||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||||
{
|
{
|
||||||
// If the layer has a shape, save it's size
|
// If the layer has a shape, save it's size
|
||||||
var shapeSize = SKRect.Empty;
|
var shapeSize = Rect.Empty;
|
||||||
if (layer.LayerShape != null)
|
if (layer.LayerShape != null)
|
||||||
shapeSize = layer.LayerShape.GetUnscaledRectangle();
|
shapeSize = _layerEditorService.GetShapeRenderRect(layer.LayerShape);
|
||||||
layer.ClearLeds();
|
layer.ClearLeds();
|
||||||
layer.AddLeds(selectedLeds);
|
layer.AddLeds(selectedLeds);
|
||||||
// Restore the saved size
|
// Restore the saved size
|
||||||
if (layer.LayerShape != null)
|
if (layer.LayerShape != null)
|
||||||
layer.LayerShape.SetFromUnscaledRectangle(shapeSize, ProfileEditorService.CurrentTime);
|
_layerEditorService.SetShapeRenderRect(layer.LayerShape, shapeSize);
|
||||||
|
|
||||||
ProfileEditorService.UpdateSelectedProfileElement();
|
ProfileEditorService.UpdateSelectedProfileElement();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ namespace Artemis.UI.Screens.Shared
|
|||||||
public double PanY { get; set; }
|
public double PanY { get; set; }
|
||||||
public double CanvasWidth { get; set; }
|
public double CanvasWidth { get; set; }
|
||||||
public double CanvasHeight { get; set; }
|
public double CanvasHeight { get; set; }
|
||||||
|
public bool LimitToZero { get; set; }
|
||||||
|
|
||||||
public Rect BackgroundViewport => new Rect(PanX, PanY, 20, 20);
|
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 position = e.GetPosition((IInputElement) sender);
|
||||||
var delta = LastPanPosition - position;
|
var delta = LastPanPosition - position;
|
||||||
|
|
||||||
PanX = Math.Min(0, PanX - delta.Value.X);
|
if (LimitToZero)
|
||||||
PanY = Math.Min(0, PanY - delta.Value.Y);
|
{
|
||||||
|
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;
|
LastPanPosition = position;
|
||||||
}
|
}
|
||||||
|
|||||||
116
src/Artemis.UI/Services/LayerShapeService.cs
Normal file
116
src/Artemis.UI/Services/LayerShapeService.cs
Normal file
@ -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);
|
baseLayerProperty.KeyframeEngine?.OverrideProgress(CurrentTime);
|
||||||
|
|
||||||
// Force layer shape to redraw
|
// 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 ^^)
|
// Update the brush with the delta (which can now be negative ^^)
|
||||||
layer.Update(delta.TotalSeconds);
|
layer.Update(delta.TotalSeconds);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user