diff --git a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs index e25a147cf..aebf093da 100644 --- a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs +++ b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileEditorViewModel.cs @@ -1,5 +1,6 @@ using System.Collections.ObjectModel; using System.Linq; +using System.Timers; using System.Windows; using System.Windows.Input; using System.Windows.Media; @@ -19,7 +20,6 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor public ProfileEditorViewModel(Module module, ISurfaceService surfaceService, ICoreService coreService) : base(module, "Profile Editor") { surfaceService.ActiveSurfaceConfigurationChanged += OnActiveSurfaceConfigurationChanged; - coreService.FrameRendered += CoreServiceOnFrameRendered; Devices = new ObservableCollection(); Execute.OnUIThread(() => { @@ -28,8 +28,11 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor }); ApplySurfaceConfiguration(surfaceService.ActiveSurface); + + _timer = new Timer(1000.0 / 15) {AutoReset = true}; + _timer.Elapsed += UpdateLeds; } - + public ObservableCollection Devices { get; set; } public RectangleGeometry SelectionRectangle { get; set; } public PanZoomViewModel PanZoomViewModel { get; set; } @@ -39,7 +42,7 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor ApplySurfaceConfiguration(e.Surface); } - private void CoreServiceOnFrameRendered(object sender, FrameRenderedEventArgs e) + private void UpdateLeds(object sender, ElapsedEventArgs e) { foreach (var profileDeviceViewModel in Devices) profileDeviceViewModel.Update(); @@ -60,10 +63,23 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor } } + protected override void OnActivate() + { + _timer.Start(); + base.OnActivate(); + } + + protected override void OnDeactivate() + { + _timer.Stop(); + base.OnDeactivate(); + } + #region Selection private MouseDragStatus _mouseDragStatus; private Point _mouseDragStartPoint; + private Timer _timer; // ReSharper disable once UnusedMember.Global - Called from view public void EditorGridMouseClick(object sender, MouseEventArgs e) diff --git a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs index b3fa52017..9e7cdc86a 100644 --- a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs +++ b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs @@ -4,7 +4,6 @@ using System.Windows.Media; using Artemis.UI.Extensions; using RGB.NET.Core; using Stylet; -using Color = System.Windows.Media.Color; namespace Artemis.UI.ViewModels.Controls.ProfileEditor { @@ -14,8 +13,12 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor { Led = led; - Execute.OnUIThread(CreateLedGeometry); - Update(); + Execute.OnUIThread(() => + { + CreateLedGeometry(); + FillBrush = new SolidColorBrush { Opacity = 0.25 }; + BorderBrush = new SolidColorBrush(); + }); } public Led Led { get; } @@ -26,9 +29,9 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor public double Height { get; private set; } public Geometry DisplayGeometry { get; private set; } - public Geometry StrokeGeometry { get; private set; } - public Color DisplayColor { get; private set; } - public bool ColorsEnabled { get; set; } = true; + public SolidColorBrush FillBrush { get; set; } + public SolidColorBrush BorderBrush { get; set; } + public string Tooltip => $"{Led.Id} - {Led.LedRectangle}"; @@ -66,35 +69,19 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor GeometryCombineMode.Union, new ScaleTransform(Led.LedRectangle.Width, Led.LedRectangle.Height) ); - - // Create a smaller version of the display geometry - var innerGeometry = Geometry.Combine( - Geometry.Empty, - geometry, - GeometryCombineMode.Union, - new TransformGroup - { - Children = new TransformCollection - { - new ScaleTransform(Led.LedRectangle.Width - 2, Led.LedRectangle.Height - 2), - new TranslateTransform(1, 1) - } - } - ); - // Stroke geometry is the display geometry excluding the inner geometry - StrokeGeometry = Geometry.Combine( - DisplayGeometry, - innerGeometry, - GeometryCombineMode.Exclude, - null - ); } public void Update() { var newColor = Led.Color.ToMediaColor(); - if (!DisplayColor.Equals(newColor)) - DisplayColor = newColor; + Execute.OnUIThread(() => + { + if (!FillBrush.Color.Equals(newColor)) + { + FillBrush.Color = newColor; + BorderBrush.Color = newColor; + } + }); if (Math.Abs(Led.LedRectangle.X - X) > 0.1) X = Led.LedRectangle.X; diff --git a/src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs b/src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs index 302f8664f..b978ddd2b 100644 --- a/src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs +++ b/src/Artemis.UI/ViewModels/Screens/ModuleRootViewModel.cs @@ -1,6 +1,5 @@ using Artemis.Core.Plugins.Abstract; using Artemis.UI.Ninject.Factories; -using Artemis.UI.ViewModels.Controls.ProfileEditor; using Stylet; namespace Artemis.UI.ViewModels.Screens diff --git a/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileLedView.xaml b/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileLedView.xaml index e6bd1eba1..7ea215399 100644 --- a/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileLedView.xaml +++ b/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileLedView.xaml @@ -1,15 +1,14 @@  + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:profileEditor="clr-namespace:Artemis.UI.ViewModels.Controls.ProfileEditor" + xmlns:Converters="clr-namespace:Artemis.UI.Converters" x:Class="Artemis.UI.Views.Controls.ProfileEditor.ProfileLedView" + mc:Ignorable="d" + d:DataContext="{d:DesignInstance {x:Type profileEditor:ProfileLedViewModel}}" + d:DesignHeight="25" d:DesignWidth="25" + ToolTip="{Binding Tooltip}"> @@ -18,15 +17,12 @@ - - - - - - - - - + \ No newline at end of file