Made devices aware of the plugin that loaded them

Fixed Corsair LL Fans layout
Expanded render events
Added identify option to device settings, must move this to be reusable though
This commit is contained in:
SpoinkyNL committed 2019-11-03 11:38:28 +01:00
1 parent af2612f294
commit 6ebceacd13
23 files changed
+400 -229

No files matched your search

+2 -2
View File
@@ -184,7 +184,7 @@
<Compile Include="ViewModels\Screens\DebugViewModel.cs" />
<Compile Include="ViewModels\Screens\SurfaceEditorViewModel.cs" />
<Compile Include="ViewModels\Interfaces\IEditorViewModel.cs" />
<Compile Include="ViewModels\Controls\Settings\RgbDeviceSettingsViewModel.cs" />
<Compile Include="ViewModels\Controls\Settings\DeviceSettingsViewModel.cs" />
<Compile Include="ViewModels\Interfaces\IHomeViewModel.cs" />
<Compile Include="ViewModels\Interfaces\IScreenViewModel.cs" />
<Compile Include="ViewModels\Screens\HomeViewModel.cs" />
@@ -235,7 +235,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Controls\Settings\RgbDeviceSettingsView.xaml">
<Page Include="Views\Controls\Settings\DeviceSettingsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@@ -0,0 +1,76 @@
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Models.Surface;
using Artemis.Core.Services.Interfaces;
using Humanizer;
namespace Artemis.UI.ViewModels.Controls.Settings
{
public class DeviceSettingsViewModel
{
private readonly ICoreService _coreService;
public DeviceSettingsViewModel(Device device, ICoreService coreService)
{
_coreService = coreService;
Device = device;
Type = Device.RgbDevice.DeviceInfo.DeviceType.ToString().Humanize();
Name = Device.RgbDevice.DeviceInfo.Model;
Manufacturer = Device.RgbDevice.DeviceInfo.Manufacturer;
IsDeviceEnabled = true;
}
public Device Device { get; }
public string Type { get; set; }
public string Name { get; set; }
public string Manufacturer { get; set; }
public bool IsDeviceEnabled { get; set; }
public void Identify()
{
BlinkDevice(0);
}
private void BlinkDevice(int blinkCount)
{
// Draw a white overlay over the device
void DrawOverlay(object sender, FrameRenderingEventArgs args)
{
using (var g = Graphics.FromImage(args.Bitmap))
{
g.FillPath(new SolidBrush(Color.White), Device.RenderPath);
}
}
_coreService.FrameRendering += DrawOverlay;
// After 200ms, stop drawing the overlay
Task.Run(async () =>
{
await Task.Delay(200);
_coreService.FrameRendering -= DrawOverlay;
if (blinkCount < 5)
{
// After another 200ms, draw the overlay again, repeat six times
await Task.Delay(200);
BlinkDevice(blinkCount + 1);
}
});
}
public void ShowDeviceDebugger()
{
}
public void OpenPluginDirectory()
{
Process.Start(Device.Plugin.PluginInfo.Directory.FullName);
}
}
}
@@ -1,25 +0,0 @@
using Humanizer;
using RGB.NET.Core;
namespace Artemis.UI.ViewModels.Controls.Settings
{
public class RgbDeviceSettingsViewModel
{
public IRGBDevice Device { get; }
public RgbDeviceSettingsViewModel(IRGBDevice device)
{
Device = device;
Type = Device.DeviceInfo.DeviceType.ToString().Humanize();
Name = Device.DeviceInfo.Model;
Manufacturer = Device.DeviceInfo.Manufacturer;
Enabled = true;
}
public string Type { get; set; }
public string Name { get; set; }
public string Manufacturer { get; set; }
public bool Enabled { get; set; }
}
}
@@ -22,6 +22,7 @@ namespace Artemis.UI.ViewModels.Screens
_rgbService = rgbService;
_coreService.FrameRendered += CoreServiceOnFrameRendered;
_coreService.FrameRendering += CoreServiceOnFrameRendering;
}
public ImageSource CurrentFrame { get; set; }
@@ -33,20 +34,25 @@ namespace Artemis.UI.ViewModels.Screens
GC.WaitForPendingFinalizers();
}
private void CoreServiceOnFrameRendered(object sender, FrameEventArgs e)
private void CoreServiceOnFrameRendered(object sender, FrameRenderedEventArgs e)
{
var imageSource = ImageSourceFromBitmap(e.Bitmap);
imageSource.Freeze();
CurrentFps = Math.Round(1.0 / e.DeltaTime, 2);
Execute.OnUIThread(() =>
{
CurrentFrame = imageSource;
});
}
private void CoreServiceOnFrameRendering(object sender, FrameRenderingEventArgs e)
{
CurrentFps = Math.Round(1.0 / e.DeltaTime, 2);
}
protected override void OnClose()
{
_coreService.FrameRendered -= CoreServiceOnFrameRendered;
_coreService.FrameRendering -= CoreServiceOnFrameRendering;
base.OnClose();
}
@@ -1,6 +1,7 @@
using Artemis.Core.Events;
using System.Windows.Media;
using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage;
using Artemis.UI.ViewModels.Controls.Settings;
using Artemis.UI.ViewModels.Interfaces;
using Ninject;
@@ -11,30 +12,42 @@ namespace Artemis.UI.ViewModels.Screens
public class SettingsViewModel : Screen, ISettingsViewModel
{
private readonly IKernel _kernel;
private readonly ICoreService _coreService;
private readonly ISurfaceService _surfaceService;
private readonly IWindowManager _windowManager;
private readonly ISettingsService _settingsService;
public SettingsViewModel(IKernel kernel, IRgbService rgbService, IWindowManager windowManager, ISettingsService settingsService)
public SettingsViewModel(IKernel kernel, ICoreService coreService, ISurfaceService surfaceService, IWindowManager windowManager, ISettingsService settingsService)
{
_kernel = kernel;
_coreService = coreService;
_surfaceService = surfaceService;
_windowManager = windowManager;
DeviceSettingsViewModels = new BindableCollection<RgbDeviceSettingsViewModel>();
foreach (var device in rgbService.LoadedDevices)
DeviceSettingsViewModels.Add(new RgbDeviceSettingsViewModel(device));
_settingsService = settingsService;
rgbService.DeviceLoaded += UpdateDevices;
DeviceSettingsViewModels = new BindableCollection<DeviceSettingsViewModel>();
RenderScale = _settingsService.GetSetting("RenderScale", 1.0).Value;
TargetFrameRate = _settingsService.GetSetting("FrameRate", 25).Value;
}
public BindableCollection<RgbDeviceSettingsViewModel> DeviceSettingsViewModels { get; set; }
public BindableCollection<DeviceSettingsViewModel> DeviceSettingsViewModels { get; set; }
public string Title => "Settings";
public double RenderScale { get; set; }
public int TargetFrameRate { get; set; }
protected override void OnActivate()
{
DeviceSettingsViewModels.Clear();
foreach (var device in _surfaceService.ActiveSurface.Devices)
DeviceSettingsViewModels.Add(new DeviceSettingsViewModel(device, _coreService));
base.OnActivate();
}
public void ShowDebugger()
{
_windowManager.ShowWindow(_kernel.Get<DebugViewModel>());
}
private void UpdateDevices(object sender, DeviceEventArgs deviceEventArgs)
{
DeviceSettingsViewModels.Add(new RgbDeviceSettingsViewModel(deviceEventArgs.Device));
}
}
}
@@ -0,0 +1,60 @@
<UserControl x:Class="Artemis.UI.Views.Controls.Settings.DeviceSettingsView"
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:settings="clr-namespace:Artemis.UI.ViewModels.Controls.Settings"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
d:DataContext="{d:DesignInstance settings:DeviceSettingsViewModel}"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<materialDesign:Card Width="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="140" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Height="140" Width="196" Fill="{DynamicResource MaterialDesignPaper}" />
<Image Grid.Row="0" Source="{Binding Device.RgbDevice.DeviceInfo.Image}" Height="130" Width="190" RenderOptions.BitmapScalingMode="HighQuality" />
<Button Grid.Row="0"
Style="{StaticResource MaterialDesignFloatingActionMiniButton}"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Margin="0 0 16 -20"
ToolTip="Identify"
Command="{s:Action Identify}">
<materialDesign:PackIcon Kind="AlarmLight" />
</Button>
<StackPanel Grid.Row="1" Margin="8 24 8 0">
<TextBlock FontWeight="Bold" Text="{Binding Device.RgbDevice.DeviceInfo.Model}" />
<TextBlock TextWrapping="Wrap" VerticalAlignment="Center">
<Run Text="{Binding Device.RgbDevice.DeviceInfo.Manufacturer, Mode=OneWay}" />
-
<Run Text="{Binding Device.RgbDevice.DeviceInfo.DeviceType, Mode=OneWay}" />
</TextBlock>
</StackPanel>
<StackPanel HorizontalAlignment="Right" Grid.Row="2" Orientation="Horizontal" Margin="8">
<CheckBox Style="{StaticResource MaterialDesignCheckBox}" IsChecked="{Binding IsDeviceEnabled}">
Device enabled
</CheckBox>
<materialDesign:PopupBox Style="{StaticResource MaterialDesignToolPopupBox}" Padding="2 0 2 0">
<StackPanel>
<Button Content="Show device debugger" Command="{s:Action ShowDeviceDebugger}" />
<Button Content="Open plugin directory" Command="{s:Action OpenPluginDirectory}" />
</StackPanel>
</materialDesign:PopupBox>
</StackPanel>
</Grid>
</materialDesign:Card>
</UserControl>
@@ -1,94 +0,0 @@
<UserControl x:Class="Artemis.UI.Views.Controls.Settings.RgbDeviceSettingsView"
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:settings="clr-namespace:Artemis.UI.ViewModels.Controls.Settings"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
d:DataContext="{d:DesignInstance settings:RgbDeviceSettingsViewModel}"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<materialDesign:Card
Width="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="140" />
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Height="140" Width="196" Fill="{DynamicResource MaterialDesignPaper}"></Rectangle>
<Image
Grid.Row="0"
Source="{Binding Device.DeviceInfo.Image}"
Height="130"
Width="190" RenderOptions.BitmapScalingMode="HighQuality"/>
<Button
Grid.Row="0"
Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Margin="0 0 16 -20"
ToolTip="Identify"
Command="{s:Action Identity}">
<materialDesign:PackIcon Kind="AlarmLight" />
</Button>
<StackPanel
Grid.Row="1"
Margin="8 24 8 0">
<TextBlock FontWeight="Bold" Text="{Binding Device.DeviceInfo.Model}" />
<TextBlock TextWrapping="Wrap" VerticalAlignment="Center">
<Run Text="{Binding Device.DeviceInfo.Manufacturer, Mode=OneWay}" />
-
<Run Text="{Binding Device.DeviceInfo.DeviceType, Mode=OneWay}" />
</TextBlock>
</StackPanel>
<StackPanel
HorizontalAlignment="Right"
Grid.Row="2"
Orientation="Horizontal"
Margin="8">
<Button
Style="{StaticResource MaterialDesignToolButton}"
Width="30"
Padding="2 0 2 0"
materialDesign:RippleAssist.IsCentered="True">
<materialDesign:PackIcon
Kind="ShareVariant" />
</Button>
<Button
Style="{StaticResource MaterialDesignToolButton}"
Width="30"
Padding="2 0 2 0"
materialDesign:RippleAssist.IsCentered="True">
<materialDesign:PackIcon
Kind="Heart" />
</Button>
<materialDesign:PopupBox
Style="{StaticResource MaterialDesignToolPopupBox}"
Padding="2 0 2 0">
<StackPanel>
<Button
Content="More" />
<Button
Content="Options" />
</StackPanel>
</materialDesign:PopupBox>
</StackPanel>
</Grid>
</materialDesign:Card>
</UserControl>
+31 -2
View File
@@ -22,6 +22,35 @@
<TextBlock Style="{StaticResource MaterialDesignHeadlineTextBlock}">General</TextBlock>
<StackPanel>
<TextBlock>General settings like start up with Windows etc.</TextBlock>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Bottom" Grid.Row="0" Grid.Column="0">Render scale</TextBlock>
<Slider Minimum="0.10"
Maximum="1"
TickFrequency="0.05"
Grid.Row="1"
Grid.Column="0"
Style="{StaticResource MaterialDesignDiscreteSlider}"
ToolTip="MaterialDesignDiscreteSlider"
Value="{Binding RenderScale}" />
<TextBlock VerticalAlignment="Bottom" Grid.Row="0" Grid.Column="1">Target framerate</TextBlock>
<Slider Minimum="5"
Maximum="60"
Grid.Row="1"
Grid.Column="1"
Style="{StaticResource MaterialDesignDiscreteSlider}"
ToolTip="MaterialDesignDiscreteSlider"
Value="{Binding TargetFrameRate}" />
</Grid>
<Button Command="{s:Action ShowDebugger}" Style="{StaticResource MaterialDesignRaisedButton}" HorizontalAlignment="Left" Margin="0, 10, 0, 0">
Show debugger
@@ -35,7 +64,7 @@
<ItemsControl ItemsSource="{Binding DeviceSettingsViewModels}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
@@ -52,5 +81,5 @@
</Grid>
</StackPanel>
</ScrollViewer>
</UserControl>