From 1935b72199e8f79e695df3a96fa150e22167b3d4 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 21 Nov 2019 23:01:24 +0100 Subject: [PATCH] Made Device, DeviceLed and Surface implement INotifyPropertChange --- src/Artemis.Core/Artemis.Core.csproj | 15 ++++++ src/Artemis.Core/FodyWeavers.xml | 5 ++ src/Artemis.Core/FodyWeavers.xsd | 54 +++++++++++++++++++ src/Artemis.Core/Models/Surface/Device.cs | 5 +- src/Artemis.Core/Models/Surface/DeviceLed.cs | 3 +- src/Artemis.Core/Models/Surface/Surface.cs | 3 +- src/Artemis.Core/packages.config | 2 + .../GeneralModule.cs | 2 + src/Artemis.UI/Artemis.UI.csproj | 12 ++--- .../SurfaceEditor/SurfaceEditorView.xaml | 4 +- .../SurfaceEditor/SurfaceEditorViewModel.cs | 1 - .../Visualization/SurfaceDeviceView.xaml | 12 +++-- .../Visualization/SurfaceDeviceViewModel.cs | 22 ++------ src/Artemis.UI/packages.config | 4 +- 14 files changed, 107 insertions(+), 37 deletions(-) create mode 100644 src/Artemis.Core/FodyWeavers.xml create mode 100644 src/Artemis.Core/FodyWeavers.xsd diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index 47f0e3e75..d79a29fb2 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -1,5 +1,6 @@  + Debug @@ -81,6 +82,9 @@ ..\packages\Ninject.Extensions.Factory.3.3.2\lib\net45\Ninject.Extensions.Factory.dll + + ..\packages\PropertyChanged.Fody.3.1.3\lib\net40\PropertyChanged.dll + False ..\..\..\RGB.NET\bin\net45\RGB.NET.Brushes.dll @@ -214,5 +218,16 @@ + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/src/Artemis.Core/FodyWeavers.xml b/src/Artemis.Core/FodyWeavers.xml new file mode 100644 index 000000000..ef627f96d --- /dev/null +++ b/src/Artemis.Core/FodyWeavers.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/Artemis.Core/FodyWeavers.xsd b/src/Artemis.Core/FodyWeavers.xsd new file mode 100644 index 000000000..2f1b8aae7 --- /dev/null +++ b/src/Artemis.Core/FodyWeavers.xsd @@ -0,0 +1,54 @@ + + + + + + + + + + + Used to control if the On_PropertyName_Changed feature is enabled. + + + + + Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form. + + + + + Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project. + + + + + Used to control if equality checks should use the Equals method resolved from the base class. + + + + + Used to control if equality checks should use the static Equals method resolved from the base class. + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/src/Artemis.Core/Models/Surface/Device.cs b/src/Artemis.Core/Models/Surface/Device.cs index 89588da6e..d0172c279 100644 --- a/src/Artemis.Core/Models/Surface/Device.cs +++ b/src/Artemis.Core/Models/Surface/Device.cs @@ -1,16 +1,19 @@ using System; using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; using System.Drawing.Drawing2D; using System.Linq; using Artemis.Core.Extensions; using Artemis.Core.Plugins.Abstract; using Artemis.Storage.Entities.Surface; using RGB.NET.Core; +using Stylet; using Rectangle = System.Drawing.Rectangle; namespace Artemis.Core.Models.Surface { - public class Device + public class Device : PropertyChangedBase { internal Device(IRGBDevice rgbDevice, Plugin plugin, Surface surface) { diff --git a/src/Artemis.Core/Models/Surface/DeviceLed.cs b/src/Artemis.Core/Models/Surface/DeviceLed.cs index 13b367b1b..4e9ebb071 100644 --- a/src/Artemis.Core/Models/Surface/DeviceLed.cs +++ b/src/Artemis.Core/Models/Surface/DeviceLed.cs @@ -1,10 +1,11 @@ using System; using RGB.NET.Core; +using Stylet; using Rectangle = System.Drawing.Rectangle; namespace Artemis.Core.Models.Surface { - public class DeviceLed + public class DeviceLed : PropertyChangedBase { public DeviceLed(Led led, Device device) { diff --git a/src/Artemis.Core/Models/Surface/Surface.cs b/src/Artemis.Core/Models/Surface/Surface.cs index b54f6a306..32540db4c 100644 --- a/src/Artemis.Core/Models/Surface/Surface.cs +++ b/src/Artemis.Core/Models/Surface/Surface.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.Linq; using Artemis.Storage.Entities.Surface; using RGB.NET.Core; +using Stylet; namespace Artemis.Core.Models.Surface { - public class Surface + public class Surface : PropertyChangedBase { internal Surface(RGBSurface rgbSurface, string name, double scale) { diff --git a/src/Artemis.Core/packages.config b/src/Artemis.Core/packages.config index f7b7e8272..868ed378e 100644 --- a/src/Artemis.Core/packages.config +++ b/src/Artemis.Core/packages.config @@ -3,12 +3,14 @@ + + diff --git a/src/Artemis.Plugins.Modules.General/GeneralModule.cs b/src/Artemis.Plugins.Modules.General/GeneralModule.cs index fc6db290a..6651745d7 100644 --- a/src/Artemis.Plugins.Modules.General/GeneralModule.cs +++ b/src/Artemis.Plugins.Modules.General/GeneralModule.cs @@ -90,6 +90,8 @@ namespace Artemis.Plugins.Modules.General brush.TranslateTransform((int) Math.Round(device.RenderRectangle.Width / 100.0 * MovePercentage), 0); graphics.FillPath(brush, device.RenderPath); brush.TranslateTransform((int) Math.Round(device.RenderRectangle.Width / 100.0 * MovePercentage) * -1, 0); + + graphics.DrawRectangle(new Pen(Color.Red), device.RenderRectangle); } } diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index e4736ed25..e2139fef1 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -1,6 +1,6 @@  - + Debug @@ -100,8 +100,8 @@ ..\packages\Ninject.Extensions.Factory.3.3.2\lib\net45\Ninject.Extensions.Factory.dll - - ..\packages\PropertyChanged.Fody.3.0.1\lib\net452\PropertyChanged.dll + + ..\packages\PropertyChanged.Fody.3.1.3\lib\net40\PropertyChanged.dll False @@ -379,8 +379,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - + \ No newline at end of file diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.xaml b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.xaml index 7c9c5d7f2..caec7b55b 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.xaml +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.xaml @@ -104,8 +104,8 @@ diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs index b4621bdea..7d5a45074 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorViewModel.cs @@ -15,7 +15,6 @@ using Artemis.UI.Screens.Shared; using Artemis.UI.Screens.SurfaceEditor.Dialogs; using Artemis.UI.Screens.SurfaceEditor.Visualization; using Artemis.UI.Services.Interfaces; -using Ninject.Parameters; using Stylet; namespace Artemis.UI.Screens.SurfaceEditor diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceView.xaml b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceView.xaml index c4877edb5..bbecc7aa5 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceView.xaml +++ b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceView.xaml @@ -19,11 +19,12 @@ - - - - + + + + + + + + diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs index b9878655e..c95efb386 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs @@ -1,12 +1,11 @@ using System; using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; using System.Windows; using System.Windows.Input; using Artemis.Core.Models.Surface; -using PropertyChanged; -using RGB.NET.Core; using Stylet; -using Point = System.Windows.Point; namespace Artemis.UI.Screens.SurfaceEditor.Visualization { @@ -26,24 +25,12 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization foreach (var led in Device.RgbDevice) _leds.Add(new SurfaceLedViewModel(led)); } - - Device.DeviceUpdated += DeviceOnDeviceUpdated; - } - - private void DeviceOnDeviceUpdated(object sender, EventArgs e) - { - NotifyOfPropertyChange(() => RgbDeviceRectangle); - NotifyOfPropertyChange(() => RgbDeviceRectangle.Location.X); - NotifyOfPropertyChange(() => RgbDeviceRectangle.Location.Y); - } public Device Device { get; set; } public SelectionStatus SelectionStatus { get; set; } public Cursor Cursor { get; set; } - public Rectangle RgbDeviceRectangle => Device.RgbDevice.DeviceRectangle; - public IReadOnlyCollection Leds => _leds.AsReadOnly(); public Rect DeviceRectangle => Device.RgbDevice == null @@ -86,10 +73,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization public MouseDevicePosition GetMouseDevicePosition(Point position) { - if ((new Point(0, 0) - position).LengthSquared < 5) - { - return MouseDevicePosition.TopLeft; - } + if ((new Point(0, 0) - position).LengthSquared < 5) return MouseDevicePosition.TopLeft; return MouseDevicePosition.Regular; } diff --git a/src/Artemis.UI/packages.config b/src/Artemis.UI/packages.config index 643aa6fc2..ca3bbebe2 100644 --- a/src/Artemis.UI/packages.config +++ b/src/Artemis.UI/packages.config @@ -4,7 +4,7 @@ - + @@ -13,7 +13,7 @@ - +