mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Implemented profile default loading and rendering without the editor
Changed edit tool rotation to allow rotation past 360 degrees
This commit is contained in:
1 parent
3ea938d69b
commit
5e3eba563b
13 files changed
+116
-41
No files matched your search
+1
@@ -34,6 +34,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.P
|
||||
throw new ArtemisUIException($"This input VM does not support the provided type {layerPropertyViewModel.LayerProperty.Type.Name}");
|
||||
|
||||
LayerPropertyViewModel = layerPropertyViewModel;
|
||||
layerPropertyViewModel.LayerProperty.ValueChanged += (sender, args) => Update();
|
||||
Update();
|
||||
|
||||
Initialized = true;
|
||||
|
||||
@@ -146,6 +146,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||
protected override void OnActivate()
|
||||
{
|
||||
LoadWorkspaceSettings();
|
||||
_profileEditorService.StopRegularRender();
|
||||
Task.Run(LoadProfiles);
|
||||
base.OnActivate();
|
||||
}
|
||||
@@ -153,6 +154,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor
|
||||
protected override void OnDeactivate()
|
||||
{
|
||||
SaveWorkspaceSettings();
|
||||
_profileEditorService.ResumeRegularRender();
|
||||
base.OnDeactivate();
|
||||
}
|
||||
|
||||
|
||||
+31
-17
@@ -20,8 +20,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
private SKPoint _dragOffset;
|
||||
private SKPoint _dragStart;
|
||||
private SKPoint _dragStartAnchor;
|
||||
private double _dragStartAngle;
|
||||
private double _dragAngleOffset;
|
||||
private float _previousDragAngle;
|
||||
private SKSize _dragStartScale;
|
||||
private bool _isDragging;
|
||||
|
||||
@@ -111,8 +110,8 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
// The path starts at 0,0 so there's no simple way to get the position relative to the top-left of the path
|
||||
_dragStart = GetRelativePosition(sender, e).ToSKPoint();
|
||||
_dragStartScale = layer.SizeProperty.CurrentValue;
|
||||
_dragStartAngle = layer.RotationProperty.CurrentValue;
|
||||
_dragAngleOffset = _dragStartAngle - CalculateAngle(_layerEditorService.GetLayerAnchor(layer, true), _dragStart);
|
||||
_previousDragAngle = CalculateAngle(_layerEditorService.GetLayerAnchor(layer, true), _dragStart);
|
||||
|
||||
// Store the original position and do a test to figure out the mouse offset
|
||||
var originalPosition = layer.PositionProperty.CurrentValue;
|
||||
var scaledDragStart = _layerEditorService.GetScaledPoint(layer, _dragStart, true);
|
||||
@@ -358,15 +357,30 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
if (!_isDragging || !(ProfileEditorService.SelectedProfileElement is Layer layer))
|
||||
return;
|
||||
|
||||
var newRotation = CalculateAngle(_layerEditorService.GetLayerAnchor(layer, true), GetRelativePosition(sender, e).ToSKPoint()) + _dragAngleOffset;
|
||||
if (newRotation < 0)
|
||||
newRotation = 360 + newRotation;
|
||||
|
||||
var current = layer.RotationProperty.CurrentValue;
|
||||
|
||||
layer.RotationProperty.SetCurrentValue((int) Math.Round(newRotation, MidpointRounding.AwayFromZero), ProfileEditorService.CurrentTime);
|
||||
Debug.WriteLine($"New rotation: {layer.RotationProperty.CurrentValue} Difference: {(layer.RotationProperty.CurrentValue - current)}");
|
||||
var previousDragAngle = _previousDragAngle;
|
||||
var newRotation = CalculateAngle(_layerEditorService.GetLayerAnchor(layer, true), GetRelativePosition(sender, e).ToSKPoint());
|
||||
_previousDragAngle = newRotation;
|
||||
|
||||
// Allow the user to rotate the shape in increments of 5
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||
newRotation = (float)Math.Round(newRotation / 5f) * 5f;
|
||||
|
||||
var difference = newRotation - previousDragAngle;
|
||||
if (difference < -350)
|
||||
difference += 360;
|
||||
else if (difference > 350)
|
||||
difference -= 360;
|
||||
newRotation = layer.RotationProperty.CurrentValue + difference;
|
||||
|
||||
// Round the end-result to increments of 5 as well, to avoid staying on an offset
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
|
||||
newRotation = (float)Math.Round(newRotation / 5f) * 5f;
|
||||
else
|
||||
newRotation = (float)Math.Round(newRotation, 2, MidpointRounding.AwayFromZero);
|
||||
|
||||
Debug.WriteLine(newRotation);
|
||||
layer.RotationProperty.SetCurrentValue(newRotation, ProfileEditorService.CurrentTime);
|
||||
ProfileEditorService.UpdateProfilePreview();
|
||||
}
|
||||
|
||||
@@ -459,12 +473,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
return Math.Max(0.001f, _dragStartScale.Height + scaleToAdd);
|
||||
}
|
||||
|
||||
private double CalculateAngle(SKPoint start, SKPoint arrival)
|
||||
private float CalculateAngle(SKPoint start, SKPoint arrival)
|
||||
{
|
||||
var radian = Math.Atan2(start.Y - arrival.Y, start.X - arrival.X);
|
||||
var angle = radian * (180 / Math.PI);
|
||||
if (angle < 0.0)
|
||||
angle += 360.0;
|
||||
var radian = (float) Math.Atan2(start.Y - arrival.Y, start.X - arrival.X);
|
||||
var angle = radian * (180f / (float) Math.PI);
|
||||
if (angle < 0f)
|
||||
angle += 360f;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
@@ -47,5 +47,8 @@ namespace Artemis.UI.Services.Interfaces
|
||||
/// Occurs when the profile preview has been updated
|
||||
/// </summary>
|
||||
event EventHandler ProfilePreviewUpdated;
|
||||
|
||||
void StopRegularRender();
|
||||
void ResumeRegularRender();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
|
||||
@@ -9,12 +10,14 @@ namespace Artemis.UI.Services
|
||||
{
|
||||
public class ProfileEditorService : IProfileEditorService
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IProfileService _profileService;
|
||||
private TimeSpan _currentTime;
|
||||
private TimeSpan _lastUpdateTime;
|
||||
|
||||
public ProfileEditorService(IProfileService profileService)
|
||||
public ProfileEditorService(ICoreService coreService, IProfileService profileService)
|
||||
{
|
||||
_coreService = coreService;
|
||||
_profileService = profileService;
|
||||
}
|
||||
|
||||
@@ -75,8 +78,10 @@ namespace Artemis.UI.Services
|
||||
|
||||
// Force layer shape to redraw
|
||||
layer.LayerShape?.CalculateRenderProperties();
|
||||
// Update the brush with the delta (which can now be negative ^^)
|
||||
layer.Update(delta.TotalSeconds);
|
||||
// Manually update the layer's engine and brush
|
||||
foreach (var property in layer.Properties)
|
||||
property.KeyframeEngine?.Update(delta.TotalSeconds);
|
||||
layer.LayerBrush?.Update(delta.TotalSeconds);
|
||||
}
|
||||
|
||||
_lastUpdateTime = CurrentTime;
|
||||
@@ -122,6 +127,16 @@ namespace Artemis.UI.Services
|
||||
public event EventHandler CurrentTimeChanged;
|
||||
public event EventHandler ProfilePreviewUpdated;
|
||||
|
||||
public void StopRegularRender()
|
||||
{
|
||||
_coreService.ModuleUpdatingDisabled = true;
|
||||
}
|
||||
|
||||
public void ResumeRegularRender()
|
||||
{
|
||||
_coreService.ModuleUpdatingDisabled = false;
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedProfileElementUpdated()
|
||||
{
|
||||
SelectedProfileElementUpdated?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
Reference in new issue
Block a user