From d9ab9d5af3682a9fd9276b7b748dd0df44f6bdf2 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 23 May 2016 20:28:03 +0200 Subject: [PATCH] Drag and drop polish --- .../DeviceProviders/Corsair/CorsairMice.cs | 17 +++++- .../DeviceProviders/Corsair/CorsairRGB.cs | 8 +-- .../Corsair/CorsiarHeadsets.cs | 16 ++++- .../Artemis/Models/Profiles/ProfileModel.cs | 3 +- .../Properties/DynamicPropertiesModel.cs | 7 ++- .../Utilities/Layers/AnimationUpdater.cs | 4 +- .../ViewModels/ProfileEditorViewModel.cs | 58 ++++++++++--------- 7 files changed, 71 insertions(+), 42 deletions(-) diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs index 22bac4888..55fc2be6d 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs @@ -6,19 +6,27 @@ using Artemis.Utilities; using CUE.NET; using CUE.NET.Devices.Generic.Enums; using CUE.NET.Exceptions; +using Ninject.Extensions.Logging; namespace Artemis.DeviceProviders.Corsair { internal class CorsairMice : DeviceProvider { - public CorsairMice() + public ILogger Logger { get; set; } + + public CorsairMice(ILogger logger) { + Logger = logger; Type = DeviceType.Mouse; } public override bool TryEnable() { CanUse = CanInitializeSdk(); + if (CanUse) + CueSDK.MouseSDK.UpdateMode = UpdateMode.Manual; + + Logger.Debug("Attempted to enable Corsair mice. CanUse: {0}", CanUse); return CanUse; } @@ -34,7 +42,7 @@ namespace Artemis.DeviceProviders.Corsair return; var leds = CueSDK.MouseSDK.Leds.Count(); - var rect = new Rect(new Size(leds*5, leds*5)); + var rect = new Rect(new Size(leds*20, leds* 20)); var img = brush.Dispatcher.Invoke(() => { var visual = new DrawingVisual(); @@ -47,9 +55,12 @@ namespace Artemis.DeviceProviders.Corsair // Color each LED according to one of the pixels foreach (var corsairLed in CueSDK.MouseSDK.Leds) { - corsairLed.Color = img.GetPixel(ledIndex*5, ledIndex*5); + corsairLed.Color = ledIndex == 0 + ? img.GetPixel(0, 0) + : img.GetPixel((ledIndex + 1) * 20 - 1, (ledIndex + 1) * 20 - 1); ledIndex++; } + CueSDK.MouseSDK.Update(true); } diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs index e23e0d8cb..025c4f7c8 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs @@ -70,22 +70,22 @@ namespace Artemis.DeviceProviders.Corsair case "K95 RGB": Height = 7; Width = 25; - PreviewSettings = new PreviewSettings(626, 175, new Thickness(0, -15, 0, 0), Resources.k95); + PreviewSettings = new PreviewSettings(676, 190, new Thickness(0, -15, 0, 0), Resources.k95); break; case "K70 RGB": Height = 7; Width = 21; - PreviewSettings = new PreviewSettings(626, 195, new Thickness(0, -25, 0, 0), Resources.k70); + PreviewSettings = new PreviewSettings(676, 195, new Thickness(0, -25, 0, 0), Resources.k70); break; case "K65 RGB": Height = 7; Width = 18; - PreviewSettings = new PreviewSettings(610, 240, new Thickness(0, -30, 0, 0), Resources.k65); + PreviewSettings = new PreviewSettings(660, 240, new Thickness(0, -30, 0, 0), Resources.k65); break; case "STRAFE RGB": Height = 6; Width = 22; - PreviewSettings = new PreviewSettings(620, 215, new Thickness(0, -15, 0, 0), Resources.strafe); + PreviewSettings = new PreviewSettings(670, 215, new Thickness(0, -15, 0, 0), Resources.strafe); break; } } diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsiarHeadsets.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsiarHeadsets.cs index 352c8eeb5..120d8945d 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsiarHeadsets.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsiarHeadsets.cs @@ -6,19 +6,27 @@ using Artemis.Utilities; using CUE.NET; using CUE.NET.Devices.Generic.Enums; using CUE.NET.Exceptions; +using Ninject.Extensions.Logging; namespace Artemis.DeviceProviders.Corsair { internal class CorsairHeadsets : DeviceProvider { - public CorsairHeadsets() + public CorsairHeadsets(ILogger logger) { + Logger = logger; Type = DeviceType.Headset; } + public ILogger Logger { get; set; } + public override bool TryEnable() { CanUse = CanInitializeSdk(); + if (CanUse) + CueSDK.HeadsetSDK.UpdateMode = UpdateMode.Manual; + + Logger.Debug("Attempted to enable Corsair headset. CanUse: {0}", CanUse); return CanUse; } @@ -34,7 +42,7 @@ namespace Artemis.DeviceProviders.Corsair return; var leds = CueSDK.HeadsetSDK.Leds.Count(); - var rect = new Rect(new Size(leds * 5, leds * 5)); + var rect = new Rect(new Size(leds*20, leds*20)); var img = brush.Dispatcher.Invoke(() => { var visual = new DrawingVisual(); @@ -47,7 +55,9 @@ namespace Artemis.DeviceProviders.Corsair // Color each LED according to one of the pixels foreach (var corsairLed in CueSDK.HeadsetSDK.Leds) { - corsairLed.Color = img.GetPixel(ledIndex * 5, ledIndex * 5); + corsairLed.Color = ledIndex == 0 + ? img.GetPixel(0, 0) + : img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1); ledIndex++; } CueSDK.HeadsetSDK.Update(true); diff --git a/Artemis/Artemis/Models/Profiles/ProfileModel.cs b/Artemis/Artemis/Models/Profiles/ProfileModel.cs index 7e4325c94..578aa6e10 100644 --- a/Artemis/Artemis/Models/Profiles/ProfileModel.cs +++ b/Artemis/Artemis/Models/Profiles/ProfileModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Windows; @@ -146,7 +147,7 @@ namespace Artemis.Models.Profiles layers.Add(layerModel); layers.AddRange(layerModel.GetAllLayers()); } - + return layers; } } diff --git a/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs index 19144b291..c54452f6c 100644 --- a/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs +++ b/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs @@ -74,7 +74,12 @@ namespace Artemis.Models.Profiles.Properties private void ApplyHeight(KeyboardPropertiesModel properties, double percentage) { - properties.Height = percentage*properties.Height; + var newHeight = percentage*properties.Height; + var difference = properties.Height - newHeight; + properties.Height = newHeight; + + if (LayerPropertyOptions == LayerPropertyOptions.Downwards) + properties.Y = properties.Y + difference; } private void ApplyOpacity(KeyboardPropertiesModel properties, double percentage) diff --git a/Artemis/Artemis/Utilities/Layers/AnimationUpdater.cs b/Artemis/Artemis/Utilities/Layers/AnimationUpdater.cs index 0f745ca77..9745bb90e 100644 --- a/Artemis/Artemis/Utilities/Layers/AnimationUpdater.cs +++ b/Artemis/Artemis/Utilities/Layers/AnimationUpdater.cs @@ -14,7 +14,7 @@ namespace Artemis.Utilities.Layers if (animateProperties.Animation == LayerAnimation.SlideRight || animateProperties.Animation == LayerAnimation.SlideLeft) { - if (progress > animateProperties.Width*scale) + if (progress + 1 >= animateProperties.Width*scale) progress = 0; } @@ -22,7 +22,7 @@ namespace Artemis.Utilities.Layers if (animateProperties.Animation == LayerAnimation.SlideDown || animateProperties.Animation == LayerAnimation.SlideUp) { - if (progress > animateProperties.Height*scale) + if (progress + 1 >= animateProperties.Height*scale) progress = 0; } diff --git a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs index 6b4068740..2837e393e 100644 --- a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs @@ -154,13 +154,13 @@ namespace Artemis.ViewModels public void DragOver(IDropInfo dropInfo) { - var sourceItem = dropInfo.Data as LayerModel; - var targetItem = dropInfo.TargetItem as LayerModel; - if (sourceItem == null || targetItem == null) + var source = dropInfo.Data as LayerModel; + var target = dropInfo.TargetItem as LayerModel; + if (source == null || target == null || source == target) return; if (dropInfo.InsertPosition == RelativeInsertPosition.TargetItemCenter && - targetItem.LayerType == LayerType.Folder) + target.LayerType == LayerType.Folder) { dropInfo.DropTargetAdorner = typeof(DropTargetMetroHighlightAdorner); dropInfo.Effects = DragDropEffects.Copy; @@ -174,42 +174,45 @@ namespace Artemis.ViewModels public void Drop(IDropInfo dropInfo) { - var sourceItem = dropInfo.Data as LayerModel; - var targetItem = dropInfo.TargetItem as LayerModel; - if (sourceItem == null || targetItem == null || sourceItem == targetItem) + var source = dropInfo.Data as LayerModel; + var target = dropInfo.TargetItem as LayerModel; + if (source == null || target == null || source == target) return; - if (dropInfo.InsertPosition == RelativeInsertPosition.TargetItemCenter && - targetItem.LayerType == LayerType.Folder) - { - // Insert into folder - + // Don't allow a folder to become it's own child, that's just weird + if (target.Parent == source) return; - } // Remove the source from it's old profile/parent - if (sourceItem.Parent == null) - sourceItem.Profile.Layers.Remove(sourceItem); + if (source.Parent == null) + source.Profile.Layers.Remove(source); else - sourceItem.Parent.Children.Remove(sourceItem); + source.Parent.Children.Remove(source); - // Insert the source into it's new profile/parent and update the order - if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem) - sourceItem.Order = targetItem.Order + 1; - else - sourceItem.Order = targetItem.Order - 1; - if (targetItem.Parent == null) + if (dropInfo.InsertPosition == RelativeInsertPosition.TargetItemCenter && + target.LayerType == LayerType.Folder) { - targetItem.Profile.Layers.Add(sourceItem); - targetItem.Profile.FixOrder(); + // Insert into folder + source.Order = -1; + target.Children.Add(source); + target.FixOrder(); } else { - targetItem.Parent.Children.Add(sourceItem); - targetItem.Parent.FixOrder(); + // Insert the source into it's new profile/parent and update the order + if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem) + source.Order = target.Order + 1; + else + source.Order = target.Order - 1; + if (target.Parent == null) + target.Profile.Layers.Add(source); + else + target.Parent.Children.Add(source); } - UpdateLayerList(sourceItem); + target.Profile?.FixOrder(); + target.Parent?.FixOrder(); + UpdateLayerList(source); } /// @@ -424,7 +427,6 @@ namespace Artemis.ViewModels var y = pos.Y/((double) ActiveKeyboard.PreviewSettings.Height/ActiveKeyboard.Height); var hoverLayer = SelectedProfile.GetEnabledLayers() - .OrderBy(l => l.Order) .Where(l => l.MustDraw()) .FirstOrDefault(l => ((KeyboardPropertiesModel) l.Properties) .GetRect(1)