Made Device, DeviceLed and Surface implement INotifyPropertChange

This commit is contained in:
SpoinkyNL committed 2019-11-21 23:01:24 +01:00
1 parent 9f0d5fd7e0
commit 1935b72199
14 files changed
+107 -37

No files matched your search

@@ -104,8 +104,8 @@
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding RgbDeviceRectangle.Location.X}" />
<Setter Property="Canvas.Top" Value="{Binding RgbDeviceRectangle.Location.Y}" />
<Setter Property="Canvas.Left" Value="{Binding Device.X}" />
<Setter Property="Canvas.Top" Value="{Binding Device.Y}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
@@ -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
@@ -19,11 +19,12 @@
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
</UserControl.Resources>
<Grid>
<Grid.LayoutTransform>
<RotateTransform Angle="{Binding Device.RgbDevice.Rotation.Degrees}"></RotateTransform>
</Grid.LayoutTransform>
<!-- Device image with fallback -->
<Image Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" />
<Image Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" VerticalAlignment="Top" HorizontalAlignment="Left">
<Image.LayoutTransform>
<RotateTransform Angle="{Binding Device.Rotation}" />
</Image.LayoutTransform>
</Image>
<Rectangle Fill="{DynamicResource ControlBackgroundBrush}"
Stroke="{DynamicResource ControlBorderBrush}"
@@ -38,6 +39,9 @@
<!-- LEDs -->
<ItemsControl ItemsSource="{Binding Leds}">
<ItemsControl.LayoutTransform>
<RotateTransform Angle="{Binding Device.Rotation}" />
</ItemsControl.LayoutTransform>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
@@ -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<SurfaceLedViewModel> 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;
}