diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index d79a29fb2..2d01db23d 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -218,16 +218,13 @@ - - - + 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/Models/Surface/Device.cs b/src/Artemis.Core/Models/Surface/Device.cs index d0172c279..be1dae749 100644 --- a/src/Artemis.Core/Models/Surface/Device.cs +++ b/src/Artemis.Core/Models/Surface/Device.cs @@ -1,7 +1,5 @@ using System; using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics; using System.Drawing.Drawing2D; using System.Linq; using Artemis.Core.Extensions; @@ -24,6 +22,7 @@ namespace Artemis.Core.Models.Surface Leds = rgbDevice.Select(l => new DeviceLed(l, this)).ToList().AsReadOnly(); Rotation = 0; + Scale = 1; ZIndex = 1; ApplyToEntity(); @@ -42,10 +41,10 @@ namespace Artemis.Core.Models.Surface public Rectangle RenderRectangle { get; private set; } public GraphicsPath RenderPath { get; private set; } - public IRGBDevice RgbDevice { get; private set; } + public IRGBDevice RgbDevice { get; } public Plugin Plugin { get; } - public Surface Surface { get; private set; } - public DeviceEntity DeviceEntity { get; private set; } + public Surface Surface { get; } + public DeviceEntity DeviceEntity { get; } public ReadOnlyCollection Leds { get; set; } public double X @@ -77,7 +76,7 @@ namespace Artemis.Core.Models.Surface get => DeviceEntity.ZIndex; set => DeviceEntity.ZIndex = value; } - + internal void ApplyToEntity() { // Other properties are computed @@ -99,8 +98,8 @@ namespace Artemis.Core.Models.Surface RenderRectangle = new Rectangle( (int) Math.Round(RgbDevice.Location.X * Surface.Scale, MidpointRounding.AwayFromZero), (int) Math.Round(RgbDevice.Location.Y * Surface.Scale, MidpointRounding.AwayFromZero), - (int) Math.Round(RgbDevice.Size.Width * Surface.Scale, MidpointRounding.AwayFromZero), - (int) Math.Round(RgbDevice.Size.Height * Surface.Scale, MidpointRounding.AwayFromZero) + (int) Math.Round(RgbDevice.DeviceRectangle.Size.Width * Surface.Scale, MidpointRounding.AwayFromZero), + (int) Math.Round(RgbDevice.DeviceRectangle.Size.Height * Surface.Scale, MidpointRounding.AwayFromZero) ); if (!Leds.Any()) @@ -114,13 +113,14 @@ namespace Artemis.Core.Models.Surface path.FillMode = FillMode.Winding; RenderPath = path; } - + public override string ToString() { return $"[{RgbDevice.DeviceInfo.DeviceType}] {RgbDevice.DeviceInfo.DeviceName} - {X}.{Y}.{ZIndex}"; } public event EventHandler DeviceUpdated; + protected virtual void OnDeviceUpdated() { DeviceUpdated?.Invoke(this, EventArgs.Empty); diff --git a/src/Artemis.Plugins.Modules.General/GeneralModule.cs b/src/Artemis.Plugins.Modules.General/GeneralModule.cs index 6651745d7..7f69ac188 100644 --- a/src/Artemis.Plugins.Modules.General/GeneralModule.cs +++ b/src/Artemis.Plugins.Modules.General/GeneralModule.cs @@ -6,6 +6,7 @@ using System.Linq; using Artemis.Core.Models.Surface; using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Models; +using Artemis.Core.Services.Storage.Interfaces; using Artemis.Plugins.Modules.General.ViewModels; using Device = Artemis.Core.Models.Surface.Device; @@ -16,7 +17,7 @@ namespace Artemis.Plugins.Modules.General private readonly ColorBlend _rainbowColorBlend; private readonly PluginSettings _settings; - public GeneralModule(PluginInfo pluginInfo, PluginSettings settings) : base(pluginInfo) + public GeneralModule(PluginInfo pluginInfo, PluginSettings settings, ISurfaceService surfaceService) : base(pluginInfo) { _settings = settings; DisplayName = "General"; @@ -38,6 +39,8 @@ namespace Artemis.Plugins.Modules.General else _rainbowColorBlend.Colors[i] = ColorHelpers.ColorFromHSV(0, 1, 1); } + + surfaceService.SurfaceConfigurationUpdated += (sender, args) => DeviceBrushes.Clear(); } public int[] Hues { get; set; } diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index e2139fef1..5a9c8562e 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -150,6 +150,7 @@ + @@ -375,12 +376,12 @@ + 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/Extensions/RgbRectangleExtensions.cs b/src/Artemis.UI/Extensions/RgbRectangleExtensions.cs new file mode 100644 index 000000000..a85cefb63 --- /dev/null +++ b/src/Artemis.UI/Extensions/RgbRectangleExtensions.cs @@ -0,0 +1,18 @@ +using System.Windows; +using RGB.NET.Core; + +namespace Artemis.UI.Extensions +{ + public static class RgbRectangleExtensions + { + public static Rect ToWindowsRect(this Rectangle rectangle, double scale) + { + return new Rect( + (int) (rectangle.Location.X * scale), + (int) (rectangle.Location.Y * scale), + (int) (rectangle.Size.Width * scale), + (int) (rectangle.Size.Height * scale) + ); + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs index 8ec78d52c..64f54d755 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/ProfileEditorViewModel.cs @@ -20,7 +20,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor { private readonly IProfileService _profileService; private readonly IDialogService _dialogService; - private Profile _selectedProfile; public ProfileEditorViewModel(ProfileModule module, ICollection viewModels, IProfileService profileService, IDialogService dialogService) { @@ -39,7 +38,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor Items.AddRange(viewModels); - module.ActiveProfileChanged += ModuleOnActiveProfileChanged; + module.ActiveProfileChanged += ModuleOnActiveProfileChanged; } public ProfileModule Module { get; } @@ -50,28 +49,24 @@ namespace Artemis.UI.Screens.Module.ProfileEditor public ProfileViewModel ProfileViewModel { get; } public BindableCollection Profiles { get; set; } - public Profile SelectedProfile { - get => _selectedProfile; - set - { - if (_selectedProfile == value) - return; - - var old = _selectedProfile; - _selectedProfile = value; - ChangeActiveProfile(old); - } + get => Module.ActiveProfile; + set => ChangeSelectedProfile(value); } - private void ChangeActiveProfile(Profile oldProfile) + private void ChangeSelectedProfile(Profile profile) { - Module.ChangeActiveProfile(_selectedProfile); - if (_selectedProfile != null) - _profileService.UpdateProfile(_selectedProfile, false); + if (profile == Module.ActiveProfile) + return; + + var oldProfile = Module.ActiveProfile; + Module.ChangeActiveProfile(profile); + if (oldProfile != null) _profileService.UpdateProfile(oldProfile, false); + if (profile != null) + _profileService.UpdateProfile(profile, false); } public bool CanDeleteActiveProfile => SelectedProfile != null && Profiles.Count > 1; @@ -107,7 +102,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor var newActiveProfile = index - 1 > -1 ? Profiles[index - 1] : Profiles[index + 1]; // Activate the new active profile - Module.ChangeActiveProfile(newActiveProfile); + SelectedProfile = newActiveProfile; // Remove the old one Profiles.Remove(profile); diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileDeviceView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileDeviceView.xaml index 74fabaf5a..af09e06c0 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileDeviceView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileDeviceView.xaml @@ -13,16 +13,21 @@ - + + + + + + - + + Visibility="{Binding Device.RgbDevice.DeviceInfo.Image, ConverterParameter=Inverted, Converter={StaticResource NullToVisibilityConverter}}" /> - + diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedView.xaml index 668515d7c..33dc4a283 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedView.xaml @@ -12,7 +12,7 @@ - + diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedViewModel.cs b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedViewModel.cs index a9c54d356..ad154e7f2 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedViewModel.cs +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileLedViewModel.cs @@ -13,10 +13,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization public ProfileLedViewModel(Led led) { Led = led; - X = Led.Location.X; - Y = Led.Location.Y; - Width = Led.Size.Width; - Height = Led.Size.Height; + + // Don't want ActualLocation here since rotation is done in XAML + X = Led.Location.X * Led.Device.Scale.Horizontal; + Y = Led.Location.Y * Led.Device.Scale.Vertical; + Width = Led.ActualSize.Width; + Height = Led.ActualSize.Height; Execute.OnUIThread(CreateLedGeometry); } @@ -63,17 +65,18 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization private void CreateRectangleGeometry() { - DisplayGeometry = new RectangleGeometry(new Rect(0.5, 0.5, Led.Size.Width - 1, Led.Size.Height - 1)); + + DisplayGeometry = new RectangleGeometry(new Rect(0.5, 0.5, Width - 1, Height - 1)); } private void CreateCircleGeometry() { - DisplayGeometry = new EllipseGeometry(new Rect(0.5, 0.5, Led.Size.Width - 1, Led.Size.Height - 1)); + DisplayGeometry = new EllipseGeometry(new Rect(0.5, 0.5, Width - 1, Height - 1)); } private void CreateKeyCapGeometry() { - DisplayGeometry = new RectangleGeometry(new Rect(1, 1, Led.Size.Width - 2, Led.Size.Height - 2), 1.6, 1.6); + DisplayGeometry = new RectangleGeometry(new Rect(1, 1, Width - 2, Height - 2), 1.6, 1.6); } private void CreateCustomGeometry(double deflateAmount) @@ -88,7 +91,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization { Children = new TransformCollection { - new ScaleTransform(Led.Size.Width - deflateAmount, Led.Size.Height - deflateAmount), + new ScaleTransform(Width - deflateAmount, Height - deflateAmount), new TranslateTransform(deflateAmount / 2, deflateAmount / 2) } } diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileView.xaml index 9a62e9eda..99344e47d 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/ProfileView.xaml @@ -43,8 +43,7 @@ MouseDown="{s:Action EditorGridMouseClick}" MouseMove="{s:Action EditorGridMouseMove}"> - + @@ -102,9 +101,7 @@ - + diff --git a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.xaml b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.xaml index caec7b55b..00d3d0156 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.xaml +++ b/src/Artemis.UI/Screens/SurfaceEditor/SurfaceEditorView.xaml @@ -50,8 +50,7 @@ MouseMove="{s:Action EditorGridMouseMove}" Cursor="{Binding Cursor}"> - + @@ -91,8 +90,7 @@ - + @@ -110,9 +108,7 @@ - + diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceView.xaml b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceView.xaml index bbecc7aa5..61af2a9be 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceView.xaml +++ b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceView.xaml @@ -19,47 +19,47 @@ - - - + + + - - + - - + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs index c95efb386..4cfd0a746 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceDeviceViewModel.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; using System.Windows; using System.Windows.Input; using Artemis.Core.Models.Surface; @@ -35,7 +33,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization public Rect DeviceRectangle => Device.RgbDevice == null ? new Rect() - : new Rect(Device.X, Device.Y, Device.RgbDevice.Size.Width, Device.RgbDevice.Size.Height); + : new Rect(Device.X, Device.Y, Device.RgbDevice.DeviceRectangle.Size.Width, Device.RgbDevice.DeviceRectangle.Size.Height); public void StartMouseDrag(Point mouseStartPosition) { diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceLedViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceLedViewModel.cs index 19269b7f5..63135f86b 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceLedViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Visualization/SurfaceLedViewModel.cs @@ -1,4 +1,5 @@ -using RGB.NET.Core; +using System.ComponentModel; +using RGB.NET.Core; using Stylet; namespace Artemis.UI.Screens.SurfaceEditor.Visualization @@ -9,6 +10,8 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization { Led = led; ApplyLedToViewModel(); + + Led.PropertyChanged += OnLedOnPropertyChanged; } public Led Led { get; set; } @@ -18,12 +21,18 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization public double Width { get; set; } public double Height { get; set; } + private void OnLedOnPropertyChanged(object sender, PropertyChangedEventArgs args) + { + if (args.PropertyName == "Location" || args.PropertyName == "ActualSize") ApplyLedToViewModel(); + } + public void ApplyLedToViewModel() { - X = Led.Location.X; - Y = Led.Location.Y; - Width = Led.Size.Width; - Height = Led.Size.Height; + // Don't want ActualLocation here since rotation is done in XAML + X = Led.Location.X * Led.Device.Scale.Horizontal; + Y = Led.Location.Y * Led.Device.Scale.Vertical; + Width = Led.ActualSize.Width; + Height = Led.ActualSize.Height; } } } \ No newline at end of file