1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Drag and drop polish

This commit is contained in:
SpoinkyNL 2016-05-23 20:28:03 +02:00
parent cc10f46e63
commit d9ab9d5af3
7 changed files with 71 additions and 42 deletions

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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;
}

View File

@ -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);
}
/// <summary>
@ -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)