diff --git a/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs b/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs
index aff6a9663..fb6979876 100644
--- a/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs
+++ b/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs
@@ -23,8 +23,13 @@ namespace Artemis.Core.RGB.NET
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
{
var point = renderTarget.Point;
- var pixel = _bitmap.GetPixel((int) point.X, (int) point.Y);
- return new Color(pixel.A, pixel.R, pixel.G, pixel.B);
+ if (_bitmap.Width - 1 >= point.X && _bitmap.Height - 1 >= point.Y)
+ {
+ var pixel = _bitmap.GetPixel((int) point.X, (int) point.Y);
+ return new Color(pixel.A, pixel.R, pixel.G, pixel.B);
+ }
+
+ return new Color(0, 0, 0);
}
public Graphics GetGraphics()
diff --git a/src/Artemis.Plugins.Devices.Corsair/Artemis.Plugins.Devices.Corsair.csproj b/src/Artemis.Plugins.Devices.Corsair/Artemis.Plugins.Devices.Corsair.csproj
index e4e09b61e..b50d61617 100644
--- a/src/Artemis.Plugins.Devices.Corsair/Artemis.Plugins.Devices.Corsair.csproj
+++ b/src/Artemis.Plugins.Devices.Corsair/Artemis.Plugins.Devices.Corsair.csproj
@@ -72,421 +72,6 @@
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PreserveNewest
-
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
-
-
-
-
- PreserveNewest
-
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
PreserveNewest
@@ -496,6 +81,14 @@
- (robocopy $(TargetDir) $(SolutionDir)\Artemis.UI\$(OutDir)\Plugins\$(ProjectName) /E /NFL /NDL /NJH /NJS /nc /ns /np) ^& IF %25ERRORLEVEL%25 LEQ 4 exit /B 0
+ echo Copying resources to plugin output directory
+XCOPY "$(ProjectDir)Images" "$(TargetDir)Images" /s /q /i /y
+XCOPY "$(ProjectDir)Layouts" "$(TargetDir)Layouts" /s /q /i /y
+echo Copying plugin to Artemis.UI output directory
+XCOPY "$(TargetDir.TrimEnd('\'))" "$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)" /s /q /i /y
+
+
+
+
\ No newline at end of file
diff --git a/src/Artemis.Plugins.LayerTypes.Brush/Artemis.Plugins.LayerTypes.Brush.csproj b/src/Artemis.Plugins.LayerTypes.Brush/Artemis.Plugins.LayerTypes.Brush.csproj
index f59eb32e7..2c58a3f9f 100644
--- a/src/Artemis.Plugins.LayerTypes.Brush/Artemis.Plugins.LayerTypes.Brush.csproj
+++ b/src/Artemis.Plugins.LayerTypes.Brush/Artemis.Plugins.LayerTypes.Brush.csproj
@@ -86,6 +86,7 @@
- (robocopy $(TargetDir) $(SolutionDir)\Artemis.UI\$(OutDir)\Plugins\$(ProjectName) /E /NFL /NDL /NJH /NJS /nc /ns /np) ^& IF %25ERRORLEVEL%25 LEQ 4 exit /B 0
+ echo Copying plugin to Artemis.UI output directory
+XCOPY "$(TargetDir.TrimEnd('\'))" "$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)" /s /q /i /y
\ No newline at end of file
diff --git a/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj b/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj
index 4978e43f1..1e9ca81a7 100644
--- a/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj
+++ b/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj
@@ -95,6 +95,7 @@
- (robocopy $(TargetDir) $(SolutionDir)\Artemis.UI\$(OutDir)\Plugins\$(ProjectName) /E /NFL /NDL /NJH /NJS /nc /ns /np) ^& IF %25ERRORLEVEL%25 LEQ 4 exit /B 0
+ echo Copying plugin to Artemis.UI output directory
+XCOPY "$(TargetDir.TrimEnd('\'))" "$(SolutionDir)\Artemis.UI\$(OutDir)Plugins\$(ProjectName)" /s /q /i /y
\ No newline at end of file
diff --git a/src/Artemis.Plugins.Modules.General/GeneralModule.cs b/src/Artemis.Plugins.Modules.General/GeneralModule.cs
index 63e57beda..31652b650 100644
--- a/src/Artemis.Plugins.Modules.General/GeneralModule.cs
+++ b/src/Artemis.Plugins.Modules.General/GeneralModule.cs
@@ -1,18 +1,13 @@
using System;
-using System.Collections.Generic;
using System.Drawing;
-using System.Linq;
-using Artemis.Core;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Modules.General.ViewModels;
-using QRCoder;
using RGB.NET.Core;
using Stylet;
using Color = System.Drawing.Color;
-using Rectangle = System.Drawing.Rectangle;
namespace Artemis.Plugins.Modules.General
{
@@ -20,8 +15,6 @@ namespace Artemis.Plugins.Modules.General
{
private readonly PluginSettings _settings;
private readonly RGBSurface _surface;
- private Dictionary _colors;
- private double _circlePosition;
private Color _color;
public GeneralModule(PluginInfo pluginInfo, IRgbService rgbService, PluginSettings settings) : base(pluginInfo)
@@ -31,10 +24,6 @@ namespace Artemis.Plugins.Modules.General
ExpandsMainDataModel = true;
_surface = rgbService.Surface;
- _colors = new Dictionary();
-
- rgbService.DeviceLoaded += (sender, args) => PopulateColors();
- rgbService.DeviceReloaded += (sender, args) => PopulateColors();
var testSetting = _settings.GetSetting("TestSetting", DateTime.Now);
_color = ColorHelpers.GetRandomRainbowColor();
@@ -42,8 +31,6 @@ namespace Artemis.Plugins.Modules.General
public override void EnablePlugin()
{
- var qrGenerator = new QRCodeGenerator();
- PopulateColors();
}
public override void DisablePlugin()
@@ -52,56 +39,16 @@ namespace Artemis.Plugins.Modules.General
public override void Update(double deltaTime)
{
- if (_colors == null)
- return;
-
- foreach (var surfaceLed in _surface.Leds)
- UpdateLedColor(surfaceLed, deltaTime);
+ _color = ColorHelpers.ShiftColor(_color, (int) (deltaTime * 200));
}
public override void Render(double deltaTime, RGBSurface surface, Graphics graphics)
{
- _circlePosition += deltaTime * 50;
- if (_circlePosition > 600)
- {
- _circlePosition = -200;
- _color = ColorHelpers.GetRandomRainbowColor();
- }
-
- var rect = new Rectangle((int) _circlePosition * 4, 0, 200, (int) surface.Leds.Max(l => l.AbsoluteLedRectangle.Y + l.AbsoluteLedRectangle.Height));
- graphics.FillRectangle(new SolidBrush(_color), rect);
-
-// // Lets do this in the least performant way possible
-// foreach (var surfaceLed in _surface.Leds)
-// {
-// var rectangle = surfaceLed.AbsoluteLedRectangle.ToDrawingRectangle();
-// if (surfaceLed.Id == LedId.Fan1)
-// {
-// graphics.FillRectangle(new SolidBrush(Color.Red), rectangle);
-// }
-// if (surfaceLed.Id == LedId.Fan2)
-// {
-// graphics.FillRectangle(new SolidBrush(Color.Blue), rectangle);
-// }
-// if (surfaceLed.Id == LedId.Fan3)
-// {
-// graphics.FillRectangle(new SolidBrush(Color.Green), rectangle);
-// }
-// }
-
-
- return;
-
// Lets do this in the least performant way possible
foreach (var surfaceLed in _surface.Leds)
{
- if (!_colors.ContainsKey(surfaceLed))
- continue;
-
- var brush = new SolidBrush(_colors[surfaceLed]);
var rectangle = surfaceLed.AbsoluteLedRectangle.ToDrawingRectangle();
- graphics.FillRectangle(brush, rectangle);
- UpdateLedColor(surfaceLed, deltaTime);
+ graphics.FillRectangle(new SolidBrush(_color), rectangle);
}
}
@@ -112,25 +59,6 @@ namespace Artemis.Plugins.Modules.General
public override void Dispose()
{
- _colors = null;
- }
-
- private void UpdateLedColor(Led led, double deltaTime)
- {
- if (_colors.ContainsKey(led))
- _colors[led] = ColorHelpers.ShiftColor(_colors[led], (int) (deltaTime * 200));
- else
- _colors[led] = ColorHelpers.GetRandomRainbowColor();
- }
-
- private void PopulateColors()
- {
- lock (_colors)
- {
- _colors = new Dictionary();
- foreach (var surfaceLed in _surface.Leds)
- _colors.Add(surfaceLed, ColorHelpers.GetRandomRainbowColor());
- }
}
}
}
\ No newline at end of file
diff --git a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbDeviceViewModel.cs b/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbDeviceViewModel.cs
index 251e0c5e0..00020adf3 100644
--- a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbDeviceViewModel.cs
+++ b/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbDeviceViewModel.cs
@@ -4,12 +4,15 @@ using System.Windows;
using System.Windows.Input;
using RGB.NET.Core;
using Stylet;
+using Point = System.Windows.Point;
namespace Artemis.UI.ViewModels.Controls.RgbDevice
{
public class RgbDeviceViewModel : PropertyChangedBase
{
private readonly List _leds;
+ private double _dragOffsetX;
+ private double _dragOffsetY;
public RgbDeviceViewModel(IRGBDevice device)
{
@@ -38,6 +41,44 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
rgbLedViewModel.ColorsEnabled = enabled;
}
+ public void StartMouseDrag(Point mouseStartPosition)
+ {
+ _dragOffsetX = Device.Location.X - mouseStartPosition.X;
+ _dragOffsetY = Device.Location.Y - mouseStartPosition.Y;
+ }
+
+ public void UpdateMouseDrag(Point mousePosition)
+ {
+ var roundedX = Math.Round((mousePosition.X + _dragOffsetX) / 10, 0, MidpointRounding.AwayFromZero) * 10;
+ var roundedY = Math.Round((mousePosition.Y + _dragOffsetY) / 10, 0, MidpointRounding.AwayFromZero) * 10;
+ this.Device.Location = new RGB.NET.Core.Point(roundedX, roundedY);
+ }
+
+ public void FinishMouseDrag(Point mouseEndPosition)
+ {
+ // TODO: Save and update
+ }
+
+ // ReSharper disable once UnusedMember.Global - Called from view
+ public void MouseEnter()
+ {
+ if (SelectionStatus == SelectionStatus.None)
+ {
+ SelectionStatus = SelectionStatus.Hover;
+ Cursor = Cursors.Hand;
+ }
+ }
+
+ // ReSharper disable once UnusedMember.Global - Called from view
+ public void MouseLeave()
+ {
+ if (SelectionStatus == SelectionStatus.Hover)
+ {
+ SelectionStatus = SelectionStatus.None;
+ Cursor = Cursors.Arrow;
+ }
+ }
+
public Rect DeviceRectangle => new Rect(Device.Location.X, Device.Location.Y, Device.Size.Width, Device.Size.Height);
}
diff --git a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs b/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs
index 2dc94e738..051b0993f 100644
--- a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs
+++ b/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs
@@ -20,7 +20,6 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
Update();
}
- [DoNotNotify]
public Led Led { get; }
public double X { get; private set; }
@@ -97,6 +96,8 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
{
if (ColorsEnabled)
{
+ if (Led.Id == LedId.Keyboard_Y)
+ Console.WriteLine();
var newColor = Led.Color.ToMediaColor();
SetColor(newColor);
}
diff --git a/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs b/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs
index 7fc9440c8..55b41984f 100644
--- a/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs
+++ b/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs
@@ -30,7 +30,7 @@ namespace Artemis.UI.ViewModels.Screens
foreach (var surfaceDevice in _rgbService.Surface.Devices)
{
var device = new RgbDeviceViewModel(surfaceDevice) {Cursor = Cursors.Hand};
- device.SetColorsEnabled(false);
+// device.SetColorsEnabled(false);
Devices.Add(device);
}
@@ -48,7 +48,7 @@ namespace Artemis.UI.ViewModels.Screens
if (Devices.All(d => d.Device != e.Device))
{
var device = new RgbDeviceViewModel(e.Device) {Cursor = Cursors.Hand};
- device.SetColorsEnabled(false);
+// device.SetColorsEnabled(false);
Devices.Add(device);
}
});
@@ -60,67 +60,112 @@ namespace Artemis.UI.ViewModels.Screens
rgbDeviceViewModel.Update();
}
- #region Selection
+ #region Mouse actions
- private bool _editorSelecting;
- private Point _selectionStartPoint;
+ private MouseDragStatus _mouseDragStatus;
+ private Point _mouseDragStartPoint;
- private void StartSelection(Point position)
+ private void StartMouseDrag(Point position)
{
- _selectionStartPoint = position;
- _editorSelecting = true;
+ // If drag started on top of a device, initialise dragging
+ var device = Devices.LastOrDefault(d => d.DeviceRectangle.Contains(position));
+ if (device != null)
+ {
+ _mouseDragStatus = MouseDragStatus.Dragging;
+ // If the device is not selected, deselect others and select only this one
+ if (device.SelectionStatus != SelectionStatus.Selected)
+ {
+ foreach (var others in Devices)
+ others.SelectionStatus = SelectionStatus.None;
+ device.SelectionStatus = SelectionStatus.Selected;
+ }
+ foreach (var selectedDevice in Devices.Where(d => d.SelectionStatus == SelectionStatus.Selected))
+ selectedDevice.StartMouseDrag(position);
+ }
+ // Start multi-selection
+ else
+ {
+ _mouseDragStatus = MouseDragStatus.Selecting;
+ _mouseDragStartPoint = position;
+ }
- SelectionRectangle.Rect = new Rect();
+ // While dragging always show an arrow to avoid cursor flicker
Mouse.OverrideCursor = Cursors.Arrow;
+ // Any time dragging starts, start with a new rect
+ SelectionRectangle.Rect = new Rect();
}
- private void StopSelection(Point position)
+ private void StopMouseDrag(Point position)
{
- _editorSelecting = false;
- Mouse.OverrideCursor = null;
-
- var selectedRect = new Rect(_selectionStartPoint, position);
- foreach (var device in Devices)
+ if (_mouseDragStatus == MouseDragStatus.Dragging)
{
- if (device.DeviceRectangle.IntersectsWith(selectedRect))
- device.SelectionStatus = SelectionStatus.Selected;
- else
- device.SelectionStatus = SelectionStatus.None;
}
+ else
+ {
+ var selectedRect = new Rect(_mouseDragStartPoint, position);
+ foreach (var device in Devices)
+ {
+ if (device.DeviceRectangle.IntersectsWith(selectedRect))
+ device.SelectionStatus = SelectionStatus.Selected;
+ else
+ device.SelectionStatus = SelectionStatus.None;
+ }
+ }
+
+ Mouse.OverrideCursor = null;
+ _mouseDragStatus = MouseDragStatus.None;
}
private void UpdateSelection(Point position)
{
- var selectedRect = new Rect(_selectionStartPoint, position);
- SelectionRectangle.Rect = selectedRect;
-
- foreach (var device in Devices)
+ lock (Devices)
{
- if (device.DeviceRectangle.IntersectsWith(selectedRect))
- device.SelectionStatus = SelectionStatus.Selected;
- else
- device.SelectionStatus = SelectionStatus.None;
+ var selectedRect = new Rect(_mouseDragStartPoint, position);
+ SelectionRectangle.Rect = selectedRect;
+
+ foreach (var device in Devices)
+ {
+ if (device.DeviceRectangle.IntersectsWith(selectedRect))
+ device.SelectionStatus = SelectionStatus.Selected;
+ else
+ device.SelectionStatus = SelectionStatus.None;
+ }
}
}
+ private void MoveSelected(Point position)
+ {
+ foreach (var device in Devices.Where(d => d.SelectionStatus == SelectionStatus.Selected))
+ device.UpdateMouseDrag(position);
+ }
+
+ // ReSharper disable once UnusedMember.Global - Called from view
public void EditorGridMouseClick(object sender, MouseEventArgs e)
{
var position = e.GetPosition((IInputElement) sender);
if (e.LeftButton == MouseButtonState.Pressed)
- StartSelection(position);
+ StartMouseDrag(position);
else
- StopSelection(position);
+ StopMouseDrag(position);
}
+ // ReSharper disable once UnusedMember.Global - Called from view
public void EditorGridMouseMove(object sender, MouseEventArgs e)
{
- if (!_editorSelecting)
- return;
-
var position = e.GetPosition((IInputElement) sender);
- UpdateSelection(position);
+ if (_mouseDragStatus == MouseDragStatus.Dragging)
+ MoveSelected(position);
+ else if (_mouseDragStatus == MouseDragStatus.Selecting)
+ UpdateSelection(position);
}
#endregion
}
+
+ internal enum MouseDragStatus
+ {
+ None,
+ Selecting,
+ Dragging
+ }
}
\ No newline at end of file
diff --git a/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml b/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml
index 5c98fa8ef..971a7ff17 100644
--- a/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml
+++ b/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml
@@ -4,12 +4,13 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:rgbDevice="clr-namespace:Artemis.UI.ViewModels.Controls.RgbDevice"
- xmlns:xaml="https://github.com/canton7/Stylet"
+ xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance rgbDevice:RgbDeviceViewModel}"
d:DesignHeight="450" d:DesignWidth="800"
- Cursor="{Binding Cursor}">
-
+ Cursor="{Binding Cursor}"
+ MouseEnter="{s:Action MouseEnter}"
+ MouseLeave="{s:Action MouseLeave}">
@@ -26,42 +27,54 @@
-
+
-
+
+
+
+
+
+
+