1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Fixed LED borders, need to focus on perf now

This commit is contained in:
Robert 2019-11-12 22:41:34 +01:00
parent 79a77794a5
commit ee5c5c1d74
4 changed files with 52 additions and 54 deletions

View File

@ -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<ProfileDeviceViewModel>();
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<ProfileDeviceViewModel> 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)

View File

@ -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;

View File

@ -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

View File

@ -1,15 +1,14 @@
<UserControl
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}"
ToolTipService.IsEnabled="{Binding ColorsEnabled}">
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}">
<UserControl.Resources>
<Converters:NullToImageConverter x:Key="NullToImageConverter"/>
</UserControl.Resources>
@ -18,15 +17,12 @@
<ImageBrush AlignmentX="Center" AlignmentY="Center" Stretch="Fill" ImageSource="{Binding Led.Image, Converter={StaticResource NullToImageConverter}}" />
</Grid.Background>
<Path Data="{Binding DisplayGeometry}" ClipToBounds="False" Visibility="{Binding ColorsEnabled, Converter={StaticResource BoolToVisibilityConverter}}">
<Path.Fill>
<SolidColorBrush Color="{Binding DisplayColor}" Opacity="0.25" />
</Path.Fill>
</Path>
<Path Data="{Binding StrokeGeometry}" ClipToBounds="False" Visibility="{Binding ColorsEnabled, Converter={StaticResource BoolToVisibilityConverter}}">
<Path.Fill>
<SolidColorBrush Color="{Binding DisplayColor}" />
</Path.Fill>
<Path Data="{Binding DisplayGeometry}"
Clip="{Binding Data, RelativeSource={RelativeSource Self}}"
ClipToBounds="False"
Fill="{Binding FillBrush}"
Stroke="{Binding BorderBrush}"
StrokeThickness="2">
</Path>
</Grid>
</UserControl>