1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

Profile editor use RGB.NET's pretty update trigger

This commit is contained in:
Robert 2019-11-13 19:43:43 +01:00
parent aa1cd70fd1
commit 44eaa6ac40
5 changed files with 26 additions and 22 deletions

View File

@ -68,10 +68,10 @@ namespace Artemis.Plugins.Modules.General
public override void Render(double deltaTime, Surface surface, Graphics graphics) public override void Render(double deltaTime, Surface surface, Graphics graphics)
{ {
// Per-device coloring, slower // Per-device coloring, slower
// RenderPerDevice(surface, graphics); RenderPerDevice(surface, graphics);
// Per-LED coloring, slowest // Per-LED coloring, slowest
RenderPerLed(surface, graphics); // RenderPerLed(surface, graphics);
} }
public void RenderFullSurface(Surface surface, Graphics graphics) public void RenderFullSurface(Surface surface, Graphics graphics)

View File

@ -1,4 +1,5 @@
using System.Collections.ObjectModel; using System;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Timers; using System.Timers;
using System.Windows; using System.Windows;
@ -7,17 +8,22 @@ using System.Windows.Media;
using Artemis.Core.Events; using Artemis.Core.Events;
using Artemis.Core.Models.Surface; using Artemis.Core.Models.Surface;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage; using Artemis.Core.Services.Storage;
using Artemis.UI.ViewModels.Screens; using Artemis.UI.ViewModels.Screens;
using Artemis.UI.ViewModels.Utilities; using Artemis.UI.ViewModels.Utilities;
using RGB.NET.Core;
using Stylet; using Stylet;
using Point = System.Windows.Point;
namespace Artemis.UI.ViewModels.Controls.ProfileEditor namespace Artemis.UI.ViewModels.Controls.ProfileEditor
{ {
public class ProfileEditorViewModel : ModuleViewModel public class ProfileEditorViewModel : ModuleViewModel
{ {
public ProfileEditorViewModel(Module module, ISurfaceService surfaceService, ICoreService coreService) : base(module, "Profile Editor") private TimerUpdateTrigger _updateTrigger;
public ProfileEditorViewModel(Module module, ISurfaceService surfaceService, ISettingsService settingsService) : base(module, "Profile Editor")
{ {
surfaceService.ActiveSurfaceConfigurationChanged += OnActiveSurfaceConfigurationChanged; surfaceService.ActiveSurfaceConfigurationChanged += OnActiveSurfaceConfigurationChanged;
Devices = new ObservableCollection<ProfileDeviceViewModel>(); Devices = new ObservableCollection<ProfileDeviceViewModel>();
@ -29,10 +35,12 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor
ApplySurfaceConfiguration(surfaceService.ActiveSurface); ApplySurfaceConfiguration(surfaceService.ActiveSurface);
_timer = new Timer(1000.0 / 15) {AutoReset = true}; // Borrow RGB.NET's update trigger, update up to 25 FPS, ignore higher settings than that
_timer.Elapsed += UpdateLeds; var targetFps = Math.Min(settingsService.GetSetting("TargetFrameRate", 25).Value, 25);
// Remove _updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / targetFps };
_timer.Start(); _updateTrigger.Update += UpdateLeds;
_updateTrigger.Start();
} }
public ObservableCollection<ProfileDeviceViewModel> Devices { get; set; } public ObservableCollection<ProfileDeviceViewModel> Devices { get; set; }
@ -44,7 +52,7 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor
ApplySurfaceConfiguration(e.Surface); ApplySurfaceConfiguration(e.Surface);
} }
private void UpdateLeds(object sender, ElapsedEventArgs e) private void UpdateLeds(object sender, CustomUpdateData customUpdateData)
{ {
foreach (var profileDeviceViewModel in Devices) foreach (var profileDeviceViewModel in Devices)
profileDeviceViewModel.Update(); profileDeviceViewModel.Update();
@ -67,13 +75,13 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor
protected override void OnActivate() protected override void OnActivate()
{ {
_timer.Start(); _updateTrigger.Start();
base.OnActivate(); base.OnActivate();
} }
protected override void OnDeactivate() protected override void OnDeactivate()
{ {
_timer.Stop(); _updateTrigger.Stop();
base.OnDeactivate(); base.OnDeactivate();
} }
@ -81,7 +89,6 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor
private MouseDragStatus _mouseDragStatus; private MouseDragStatus _mouseDragStatus;
private Point _mouseDragStartPoint; private Point _mouseDragStartPoint;
private Timer _timer;
// ReSharper disable once UnusedMember.Global - Called from view // ReSharper disable once UnusedMember.Global - Called from view
public void EditorGridMouseClick(object sender, MouseEventArgs e) public void EditorGridMouseClick(object sender, MouseEventArgs e)

View File

@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.UI.Views.Controls.ProfileEditor.ProfileDeviceView" <UserControl x:Class="Artemis.UI.Views.Controls.ProfileEditor.ProfileDeviceView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@ -15,7 +15,7 @@
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<!-- Device image with fallback --> <!-- Device image with fallback -->
<Image Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}" /> <Image Source="{Binding Device.RgbDevice.DeviceInfo.Image, Converter={StaticResource NullToImageConverter}}"/>
<Rectangle Fill="{DynamicResource ControlBackgroundBrush}" <Rectangle Fill="{DynamicResource ControlBackgroundBrush}"
Stroke="{DynamicResource ControlBorderBrush}" Stroke="{DynamicResource ControlBorderBrush}"

View File

@ -12,10 +12,10 @@
<UserControl.Resources> <UserControl.Resources>
<Converters:NullToImageConverter x:Key="NullToImageConverter" /> <Converters:NullToImageConverter x:Key="NullToImageConverter" />
</UserControl.Resources> </UserControl.Resources>
<Grid Width="{Binding Width}" Height="{Binding Height}" ClipToBounds="False"> <Canvas Width="{Binding Width}" Height="{Binding Height}">
<Grid.Background> <Canvas.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center" Stretch="Fill" ImageSource="{Binding Led.Image, Converter={StaticResource NullToImageConverter}}" /> <ImageBrush AlignmentX="Center" AlignmentY="Center" Stretch="Fill" ImageSource="{Binding Led.Image, Converter={StaticResource NullToImageConverter}}" />
</Grid.Background> </Canvas.Background>
<Path Data="{Binding DisplayGeometry}" ClipToBounds="False"> <Path Data="{Binding DisplayGeometry}" ClipToBounds="False">
<Path.Fill> <Path.Fill>
@ -27,6 +27,5 @@
<SolidColorBrush Color="{Binding DisplayColor}" /> <SolidColorBrush Color="{Binding DisplayColor}" />
</Path.Fill> </Path.Fill>
</Path> </Path>
</Canvas>
</Grid>
</UserControl> </UserControl>

View File

@ -28,9 +28,7 @@
Background="Transparent" Background="Transparent"
RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.BitmapScalingMode="HighQuality"
Margin="0,0,-10,0"> Margin="0,0,-10,0">
<Image Source="{StaticResource BowIcon}" <Image Source="{StaticResource BowIcon}" Stretch="Uniform" Margin="6" />
Stretch="Uniform"
Margin="6" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</metro:MetroWindow.IconTemplate> </metro:MetroWindow.IconTemplate>