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

Merge branch 'development'

This commit is contained in:
Robert 2021-05-09 22:45:41 +02:00
commit 4865254ab6
9 changed files with 133 additions and 75 deletions

View File

@ -119,11 +119,24 @@ namespace Artemis.Core.Services
try try
{ {
_frameStopWatch.Restart(); _frameStopWatch.Restart();
// Render all active modules
SKTexture texture = _rgbService.OpenRender();
lock (_dataModelExpansions) lock (_dataModelExpansions)
{ {
// Update all active modules, check Enabled status because it may go false before before the _dataModelExpansions list is updated // Update all active modules, check Enabled status because it may go false before before the _dataModelExpansions list is updated
foreach (BaseDataModelExpansion dataModelExpansion in _dataModelExpansions.Where(e => e.IsEnabled)) foreach (BaseDataModelExpansion dataModelExpansion in _dataModelExpansions.Where(e => e.IsEnabled))
dataModelExpansion.InternalUpdate(args.DeltaTime); {
try
{
dataModelExpansion.InternalUpdate(args.DeltaTime);
}
catch (Exception e)
{
_updateExceptions.Add(e);
}
}
} }
List<Module> modules; List<Module> modules;
@ -137,10 +150,16 @@ namespace Artemis.Core.Services
// Update all active modules // Update all active modules
foreach (Module module in modules) foreach (Module module in modules)
module.InternalUpdate(args.DeltaTime); {
try
// Render all active modules {
SKTexture texture = _rgbService.OpenRender(); module.InternalUpdate(args.DeltaTime);
}
catch (Exception e)
{
_updateExceptions.Add(e);
}
}
SKCanvas canvas = texture.Surface.Canvas; SKCanvas canvas = texture.Surface.Canvas;
canvas.Save(); canvas.Save();
@ -152,7 +171,16 @@ namespace Artemis.Core.Services
if (!ModuleRenderingDisabled) if (!ModuleRenderingDisabled)
{ {
foreach (Module module in modules.Where(m => m.IsActivated)) foreach (Module module in modules.Where(m => m.IsActivated))
module.InternalRender(args.DeltaTime, canvas, texture.ImageInfo); {
try
{
module.InternalRender(args.DeltaTime, canvas, texture.ImageInfo);
}
catch (Exception e)
{
_updateExceptions.Add(e);
}
}
} }
OnFrameRendering(new FrameRenderingEventArgs(canvas, args.DeltaTime, _rgbService.Surface)); OnFrameRendering(new FrameRenderingEventArgs(canvas, args.DeltaTime, _rgbService.Surface));

View File

@ -100,15 +100,11 @@ namespace Artemis.UI.Shared
// Determine the scale required to fit the desired size of the control // Determine the scale required to fit the desired size of the control
Size measureSize = MeasureDevice(); Size measureSize = MeasureDevice();
double scale = Math.Min(DesiredSize.Width / measureSize.Width, DesiredSize.Height / measureSize.Height); double scale = Math.Min(RenderSize.Width / measureSize.Width, RenderSize.Height / measureSize.Height);
Rect scaledRect = new(0, 0, measureSize.Width * scale, measureSize.Height * scale);
// Center and scale the visualization in the desired bounding box // Scale the visualization in the desired bounding box
if (DesiredSize.Width > 0 && DesiredSize.Height > 0) if (RenderSize.Width > 0 && RenderSize.Height > 0)
{
drawingContext.PushTransform(new TranslateTransform(DesiredSize.Width / 2 - scaledRect.Width / 2, DesiredSize.Height / 2 - scaledRect.Height / 2));
drawingContext.PushTransform(new ScaleTransform(scale, scale)); drawingContext.PushTransform(new ScaleTransform(scale, scale));
}
// Determine the offset required to rotate within bounds // Determine the offset required to rotate within bounds
Rect rotationRect = new(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height); Rect rotationRect = new(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height);

View File

@ -7,17 +7,20 @@
xmlns:s="https://github.com/canton7/Stylet" xmlns:s="https://github.com/canton7/Stylet"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared" xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:converters="clr-namespace:Artemis.UI.Converters"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:PluginPrerequisitesInstallDialogViewModel}"> d:DataContext="{d:DesignInstance local:PluginPrerequisitesInstallDialogViewModel}">
<UserControl.Resources> <UserControl.Resources>
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/> <converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter" />
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
</UserControl.Resources> </UserControl.Resources>
<Grid Margin="16"> <Grid Margin="16">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition MinHeight="150"/> <RowDefinition MinHeight="150" />
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="300" /> <ColumnDefinition Width="300" />
@ -32,7 +35,6 @@
ItemsSource="{Binding Prerequisites}" ItemsSource="{Binding Prerequisites}"
SelectedItem="{Binding ActivePrerequisite, Mode=OneWay}" SelectedItem="{Binding ActivePrerequisite, Mode=OneWay}"
HorizontalContentAlignment="Stretch"> HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type local:PluginPrerequisiteViewModel}"> <DataTemplate DataType="{x:Type local:PluginPrerequisiteViewModel}">
<Border Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}" VerticalAlignment="Stretch"> <Border Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}" VerticalAlignment="Stretch">
@ -75,26 +77,36 @@
HorizontalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
Margin="10 0" Margin="10 0"
IsTabStop="False" IsTabStop="False"
Visibility="{Binding ActivePrerequisite, Converter={StaticResource NullToVisibilityConverter}}"/> Visibility="{Binding ShowProgress, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
<TextBlock Grid.Row="1" <TextBlock Grid.Row="1"
Grid.Column="1" Grid.Column="1"
Style="{StaticResource MaterialDesignBody1TextBlock}" Style="{StaticResource MaterialDesignBody1TextBlock}"
TextWrapping="Wrap" TextWrapping="Wrap"
Margin="10 0" Margin="10 0"
Visibility="{Binding ActivePrerequisite, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}"> Visibility="{Binding ShowIntro, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
In order for this plugin/feature to function certain prerequisites must be met. <LineBreak /><LineBreak /> In order for this plugin/feature to function certain prerequisites must be met. <LineBreak /><LineBreak />
On the left side you can see all prerequisites and whether they are currently met or not. On the left side you can see all prerequisites and whether they are currently met or not.
Clicking install prerequisites will automatically set everything up for you. Clicking install prerequisites will automatically set everything up for you.
</TextBlock> </TextBlock>
<TextBlock Grid.Row="1"
Grid.Column="1"
Style="{StaticResource MaterialDesignBody1TextBlock}"
TextWrapping="Wrap"
Margin="10 0"
Visibility="{Binding ShowFailed, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
Installing <Run Text="{Binding ActivePrerequisite.PluginPrerequisite.Name, Mode=OneWay}" FontWeight="SemiBold" /> failed. <LineBreak /><LineBreak />
You may try again to see if that helps, otherwise install the prerequisite manually or contact the plugin developer.
</TextBlock>
<StackPanel Grid.Row="2" <StackPanel Grid.Row="2"
Grid.Column="0" Grid.Column="0"
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
Orientation="Horizontal" Orientation="Horizontal"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0 8 0 0" Margin="0 8 0 0"
Visibility="{Binding IsFinished, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"> Visibility="{Binding ShowInstall, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
<Button Style="{StaticResource MaterialDesignFlatButton}" <Button Style="{StaticResource MaterialDesignFlatButton}"
Focusable="False" Focusable="False"
IsCancel="True" IsCancel="True"
@ -104,6 +116,7 @@
Style="{StaticResource MaterialDesignFlatButton}" Style="{StaticResource MaterialDesignFlatButton}"
IsDefault="True" IsDefault="True"
Focusable="True" Focusable="True"
IsEnabled="{Binding ShowProgress, Converter={StaticResource InverseBooleanConverter}, Mode=OneWay}"
Command="{s:Action Install}" Command="{s:Action Install}"
Content="INSTALL PREREQUISITES" /> Content="INSTALL PREREQUISITES" />
</StackPanel> </StackPanel>
@ -114,7 +127,7 @@
Orientation="Horizontal" Orientation="Horizontal"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0 8 0 0" Margin="0 8 0 0"
Visibility="{Binding IsFinished, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"> Visibility="{Binding ShowInstall, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
<Button Style="{StaticResource MaterialDesignFlatButton}" <Button Style="{StaticResource MaterialDesignFlatButton}"
Focusable="False" Focusable="False"
IsCancel="True" IsCancel="True"

View File

@ -13,18 +13,16 @@ namespace Artemis.UI.Screens.Plugins
{ {
public class PluginPrerequisitesInstallDialogViewModel : DialogViewModelBase public class PluginPrerequisitesInstallDialogViewModel : DialogViewModelBase
{ {
private readonly IDialogService _dialogService;
private readonly List<IPrerequisitesSubject> _subjects;
private PluginPrerequisiteViewModel _activePrerequisite; private PluginPrerequisiteViewModel _activePrerequisite;
private bool _canInstall;
private bool _isFinished;
private CancellationTokenSource _tokenSource; private CancellationTokenSource _tokenSource;
private bool _showProgress;
private bool _showIntro = true;
private bool _showFailed;
private bool _showInstall = true;
private bool _canInstall;
public PluginPrerequisitesInstallDialogViewModel(List<IPrerequisitesSubject> subjects, IPrerequisitesVmFactory prerequisitesVmFactory, IDialogService dialogService) public PluginPrerequisitesInstallDialogViewModel(List<IPrerequisitesSubject> subjects, IPrerequisitesVmFactory prerequisitesVmFactory, IDialogService dialogService)
{ {
_subjects = subjects;
_dialogService = dialogService;
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(); Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>();
foreach (IPrerequisitesSubject prerequisitesSubject in subjects) foreach (IPrerequisitesSubject prerequisitesSubject in subjects)
Prerequisites.AddRange(prerequisitesSubject.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, false))); Prerequisites.AddRange(prerequisitesSubject.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, false)));
@ -41,18 +39,36 @@ namespace Artemis.UI.Screens.Plugins
set => SetAndNotify(ref _activePrerequisite, value); set => SetAndNotify(ref _activePrerequisite, value);
} }
public bool ShowProgress
{
get => _showProgress;
set => SetAndNotify(ref _showProgress, value);
}
public bool ShowIntro
{
get => _showIntro;
set => SetAndNotify(ref _showIntro, value);
}
public bool ShowFailed
{
get => _showFailed;
set => SetAndNotify(ref _showFailed, value);
}
public bool ShowInstall
{
get => _showInstall;
set => SetAndNotify(ref _showInstall, value);
}
public bool CanInstall public bool CanInstall
{ {
get => _canInstall; get => _canInstall;
set => SetAndNotify(ref _canInstall, value); set => SetAndNotify(ref _canInstall, value);
} }
public bool IsFinished
{
get => _isFinished;
set => SetAndNotify(ref _isFinished, value);
}
#region Overrides of DialogViewModelBase #region Overrides of DialogViewModelBase
/// <inheritdoc /> /// <inheritdoc />
@ -67,6 +83,10 @@ namespace Artemis.UI.Screens.Plugins
public async void Install() public async void Install()
{ {
CanInstall = false; CanInstall = false;
ShowFailed = false;
ShowIntro = false;
ShowProgress = true;
_tokenSource = new CancellationTokenSource(); _tokenSource = new CancellationTokenSource();
try try
@ -80,27 +100,20 @@ namespace Artemis.UI.Screens.Plugins
ActivePrerequisite = pluginPrerequisiteViewModel; ActivePrerequisite = pluginPrerequisiteViewModel;
await ActivePrerequisite.Install(_tokenSource.Token); await ActivePrerequisite.Install(_tokenSource.Token);
if (!ActivePrerequisite.IsMet)
{
CanInstall = true;
ShowFailed = true;
ShowProgress = false;
return;
}
// Wait after the task finished for the user to process what happened // Wait after the task finished for the user to process what happened
if (pluginPrerequisiteViewModel != Prerequisites.Last()) if (pluginPrerequisiteViewModel != Prerequisites.Last())
await Task.Delay(1000); await Task.Delay(1000);
} }
if (Prerequisites.All(p => p.IsMet)) ShowInstall = false;
{
IsFinished = true;
return;
}
// This shouldn't be happening and the experience isn't very nice for the user (too lazy to make a nice UI for such an edge case)
// but at least give some feedback
Session?.Close(false);
await _dialogService.ShowConfirmDialog(
"Plugin prerequisites",
"All prerequisites are installed but some still aren't met. \r\nPlease try again or contact the plugin creator.",
"Confirm",
""
);
await Show(_dialogService, _subjects);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
@ -108,7 +121,6 @@ namespace Artemis.UI.Screens.Plugins
} }
finally finally
{ {
CanInstall = true;
_tokenSource.Dispose(); _tokenSource.Dispose();
_tokenSource = null; _tokenSource = null;
} }

View File

@ -114,7 +114,8 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
ShowColors="True" ShowColors="True"
LedClicked="{s:Action OnLedClicked}"/> LedClicked="{s:Action OnLedClicked}"
Margin="20"/>
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" <TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Visibility="{Binding Device.Layout.RgbLayout.Author, Converter={StaticResource NullToVisibilityConverter}}" Visibility="{Binding Device.Layout.RgbLayout.Author, Converter={StaticResource NullToVisibilityConverter}}"

View File

@ -1,17 +1,17 @@
<UserControl <UserControl
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"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:tabs="clr-namespace:Artemis.UI.Screens.Settings.Device.Tabs" xmlns:tabs="clr-namespace:Artemis.UI.Screens.Settings.Device.Tabs"
xmlns:converters="clr-namespace:Artemis.UI.Converters" xmlns:converters="clr-namespace:Artemis.UI.Converters"
x:Class="Artemis.UI.Screens.Settings.Device.Tabs.DeviceLedsTabView" x:Class="Artemis.UI.Screens.Settings.Device.Tabs.DeviceLedsTabView"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance {x:Type tabs:DeviceLedsTabViewModel}}"> d:DataContext="{d:DesignInstance {x:Type tabs:DeviceLedsTabViewModel}}">
<UserControl.Resources> <UserControl.Resources>
<converters:UriToFileNameConverter x:Key="UriToFileNameConverter"/> <converters:UriToFileNameConverter x:Key="UriToFileNameConverter" />
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<DataGrid ItemsSource="{Binding LedViewModels}" <DataGrid ItemsSource="{Binding LedViewModels}"
@ -20,8 +20,8 @@
IsReadOnly="True" IsReadOnly="True"
CanUserAddRows="False" CanUserAddRows="False"
AutoGenerateColumns="False" AutoGenerateColumns="False"
materialDesign:DataGridAssist.CellPadding="5" materialDesign:DataGridAssist.CellPadding="16 5 5 5"
materialDesign:DataGridAssist.ColumnHeaderPadding="5" materialDesign:DataGridAssist.ColumnHeaderPadding="16 5 5 5"
CanUserResizeRows="False" CanUserResizeRows="False"
VirtualizingStackPanel.VirtualizationMode="Standard" VirtualizingStackPanel.VirtualizationMode="Standard"
Margin="10"> Margin="10">
@ -32,10 +32,10 @@
</DataGrid.Resources> </DataGrid.Resources>
<DataGrid.Columns> <DataGrid.Columns>
<materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.Id}" Header="LED ID" Width="Auto" /> <materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.Id}" Header="LED ID" Width="Auto" />
<materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.Color}" Header="Color (ARGB)" Width="Auto" /> <materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.Color}" Header="Color (ARGB)" Width="Auto" CanUserSort="False" />
<materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.Layout.Image, Converter={StaticResource UriToFileNameConverter}, Mode=OneWay}" Header="Image file" /> <materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.Layout.Image, Converter={StaticResource UriToFileNameConverter}, Mode=OneWay}" Header="Image file" CanUserSort="False" />
<materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.Shape}" Header="Shape" /> <materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.Shape}" Header="Shape" />
<materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.Size}" Header="Size" Width="Auto" /> <materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.Size}" Header="Size" Width="Auto" CanUserSort="False" />
<materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.CustomData}" Header="LED data" Width="Auto" /> <materialDesign:DataGridTextColumn Binding="{Binding ArtemisLed.RgbLed.CustomData}" Header="LED data" Width="Auto" />
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>

View File

@ -7,6 +7,7 @@ using Artemis.Core;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
using Ookii.Dialogs.Wpf; using Ookii.Dialogs.Wpf;
using RGB.NET.Core;
using SkiaSharp; using SkiaSharp;
using Stylet; using Stylet;
@ -105,6 +106,8 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs
Device.RedScale = RedScale / 100f; Device.RedScale = RedScale / 100f;
Device.GreenScale = GreenScale / 100f; Device.GreenScale = GreenScale / 100f;
Device.BlueScale = BlueScale / 100f; Device.BlueScale = BlueScale / 100f;
_rgbService.Surface.Update(true);
} }
public void BrowseCustomLayout(object sender, MouseEventArgs e) public void BrowseCustomLayout(object sender, MouseEventArgs e)

View File

@ -55,8 +55,8 @@
CanUserAddRows="False" CanUserAddRows="False"
AutoGenerateColumns="False" AutoGenerateColumns="False"
CanUserResizeRows="False" CanUserResizeRows="False"
materialDesign:DataGridAssist.CellPadding="8" materialDesign:DataGridAssist.CellPadding="16 5 5 5"
materialDesign:DataGridAssist.ColumnHeaderPadding="8" materialDesign:DataGridAssist.ColumnHeaderPadding="16 5 5 5"
VirtualizingPanel.VirtualizationMode="Standard" VirtualizingPanel.VirtualizationMode="Standard"
Margin="10"> Margin="10">
<DataGrid.Columns> <DataGrid.Columns>

View File

@ -30,7 +30,12 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Rectangle Grid.Row="0" Fill="{DynamicResource MaterialDesignPaper}" /> <Rectangle Grid.Row="0" Fill="{DynamicResource MaterialDesignPaper}" />
<shared:DeviceVisualizer Device="{Binding Device}" RenderOptions.BitmapScalingMode="HighQuality" Grid.Row="0" Height="130" Width="190" /> <shared:DeviceVisualizer VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="10"
Device="{Binding Device}"
RenderOptions.BitmapScalingMode="HighQuality"
Grid.Row="0" />
<Button Grid.Row="0" <Button Grid.Row="0"
Style="{StaticResource MaterialDesignFloatingActionMiniButton}" Style="{StaticResource MaterialDesignFloatingActionMiniButton}"
HorizontalAlignment="Right" HorizontalAlignment="Right"