1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 01:42:02 +00:00

Added core usage to WindowsProfileDataModel

This commit is contained in:
SpoinkyNL 2016-06-07 21:32:00 +02:00
parent cc4439126e
commit be70786319
6 changed files with 113 additions and 40 deletions

View File

@ -51,9 +51,9 @@ namespace Artemis.Models
// Render the keyboard layer-by-layer // Render the keyboard layer-by-layer
keyboard = Profile.GenerateBitmap(renderLayers, DataModel, MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(4), false, true); keyboard = Profile.GenerateBitmap(renderLayers, DataModel, MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(4), false, true);
// Render the first enabled mouse (will default to null if renderMice was false) // Render the first enabled mouse (will default to null if renderMice was false)
mouse = Profile.GenerateBrush(renderLayers.FirstOrDefault(l => l.LayerType == LayerType.Mouse), DataModel); mouse = Profile.GenerateBrush(renderLayers.LastOrDefault(l => l.LayerType == LayerType.Mouse), DataModel);
// Render the first enabled headset (will default to null if renderHeadsets was false) // Render the first enabled headset (will default to null if renderHeadsets was false)
headset = Profile.GenerateBrush(renderLayers.FirstOrDefault(l => l.LayerType == LayerType.Headset), DataModel); headset = Profile.GenerateBrush(renderLayers.LastOrDefault(l => l.LayerType == LayerType.Headset), DataModel);
} }
public abstract List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets); public abstract List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets);

View File

@ -22,7 +22,6 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
@ -80,38 +79,28 @@
Grid.Row="4" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes"
OffLabel="No" Margin="0,0,-5,0" Width="114" /> OffLabel="No" Margin="0,0,-5,0" Width="114" />
<!-- Bars amount -->
<TextBlock Grid.Row="5" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center"
Height="16" Margin="0,8">
Bars amount (less bars means thicker bars)
</TextBlock>
<Slider x:Name="Bars" Grid.Row="5" Grid.Column="1" VerticalAlignment="Center"
HorizontalAlignment="Right" Width="110" TickPlacement="BottomRight" TickFrequency="1"
Value="{Binding Path=EffectSettings.Bars, Mode=TwoWay}" Minimum="2" Maximum="21"
SmallChange="1" IsSnapToTickEnabled="True" />
<!-- Sensitivity --> <!-- Sensitivity -->
<TextBlock Grid.Row="6" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" <TextBlock Grid.Row="5" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center"
Height="16" Margin="0,8"> Height="16" Margin="0,8">
Volume sensitivity multiplier Volume sensitivity multiplier
</TextBlock> </TextBlock>
<Slider x:Name="Sensitivity" Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" <Slider x:Name="Sensitivity" Grid.Row="5" Grid.Column="1" VerticalAlignment="Center"
HorizontalAlignment="Right" Width="110" TickPlacement="BottomRight" TickFrequency="1" HorizontalAlignment="Right" Width="110" TickPlacement="BottomRight" TickFrequency="1"
Value="{Binding Path=EffectSettings.Sensitivity, Mode=TwoWay}" Minimum="1" Maximum="10" Value="{Binding Path=EffectSettings.Sensitivity, Mode=TwoWay}" Minimum="1" Maximum="10"
SmallChange="1" IsSnapToTickEnabled="True" /> SmallChange="1" IsSnapToTickEnabled="True" />
<!-- Fade speed --> <!-- Fade speed -->
<TextBlock Grid.Row="7" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" <TextBlock Grid.Row="6" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center"
Height="16" Margin="0,8"> Height="16" Margin="0,8">
Bar fade-out speed Bar fade-out speed
</TextBlock> </TextBlock>
<Slider x:Name="FadeSpeed" Grid.Row="7" Grid.Column="1" VerticalAlignment="Center" <Slider x:Name="FadeSpeed" Grid.Row="6" Grid.Column="1" VerticalAlignment="Center"
HorizontalAlignment="Right" Width="110" TickPlacement="BottomRight" TickFrequency="1" HorizontalAlignment="Right" Width="110" TickPlacement="BottomRight" TickFrequency="1"
Value="{Binding Path=EffectSettings.FadeSpeed, Mode=TwoWay}" Minimum="1" Maximum="3" Value="{Binding Path=EffectSettings.FadeSpeed, Mode=TwoWay}" Minimum="1" Maximum="3"
SmallChange="1" IsSnapToTickEnabled="True" /> SmallChange="1" IsSnapToTickEnabled="True" />
<!-- Buttons --> <!-- Buttons -->
<StackPanel Grid.Column="0" Grid.Row="8" Orientation="Horizontal" VerticalAlignment="Bottom"> <StackPanel Grid.Column="0" Grid.Row="7" Orientation="Horizontal" VerticalAlignment="Bottom">
<Button x:Name="ResetSettings" Content="Reset effect" VerticalAlignment="Top" Width="100" <Button x:Name="ResetSettings" Content="Reset effect" VerticalAlignment="Top" Width="100"
Style="{DynamicResource SquareButtonStyle}" /> Style="{DynamicResource SquareButtonStyle}" />
<Button x:Name="SaveSettings" Content="Save changes" VerticalAlignment="Top" Width="100" <Button x:Name="SaveSettings" Content="Save changes" VerticalAlignment="Top" Width="100"

View File

@ -4,5 +4,23 @@ namespace Artemis.Modules.Effects.WindowsProfile
{ {
public class WindowsProfileDataModel : IDataModel public class WindowsProfileDataModel : IDataModel
{ {
public CpuDataModel Cpu { get; set; }
public WindowsProfileDataModel()
{
Cpu = new CpuDataModel();
}
}
public class CpuDataModel
{
public int Core1Usage { get; set; }
public int Core2Usage { get; set; }
public int Core3Usage { get; set; }
public int Core4Usage { get; set; }
public int Core5Usage { get; set; }
public int Core6Usage { get; set; }
public int Core7Usage { get; set; }
public int Core8Usage { get; set; }
} }
} }

View File

@ -1,4 +1,6 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Diagnostics;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
using Artemis.Models.Profiles; using Artemis.Models.Profiles;
@ -7,6 +9,9 @@ namespace Artemis.Modules.Effects.WindowsProfile
{ {
public class WindowsProfileModel : EffectModel public class WindowsProfileModel : EffectModel
{ {
private List<PerformanceCounter> _cores;
private int _cpuFrames;
public WindowsProfileModel(MainManager mainManager, WindowsProfileSettings settings) public WindowsProfileModel(MainManager mainManager, WindowsProfileSettings settings)
: base(mainManager, new WindowsProfileDataModel()) : base(mainManager, new WindowsProfileDataModel())
{ {
@ -23,16 +28,68 @@ namespace Artemis.Modules.Effects.WindowsProfile
public override void Enable() public override void Enable()
{ {
// Setup CPU cores
_cores = GetPerformanceCounters();
var coreCount = _cores.Count;
while (coreCount < 8)
{
_cores.Add(null);
coreCount++;
}
Initialized = true; Initialized = true;
} }
public override void Update() public override void Update()
{ {
UpdateCpu();
}
private void UpdateCpu()
{
// CPU is only updated every 15 frames, the performance counter gives 0 if updated too often
_cpuFrames++;
if (_cpuFrames < 16)
return;
_cpuFrames = 0;
var dataModel = (WindowsProfileDataModel)DataModel;
// Update cores, not ideal but data models don't support lists.
if (_cores[0] != null)
dataModel.Cpu.Core1Usage = (int)_cores[0].NextValue();
if (_cores[1] != null)
dataModel.Cpu.Core2Usage = (int)_cores[1].NextValue();
if (_cores[2] != null)
dataModel.Cpu.Core3Usage = (int)_cores[2].NextValue();
if (_cores[3] != null)
dataModel.Cpu.Core4Usage = (int)_cores[3].NextValue();
if (_cores[4] != null)
dataModel.Cpu.Core5Usage = (int)_cores[4].NextValue();
if (_cores[5] != null)
dataModel.Cpu.Core6Usage = (int)_cores[5].NextValue();
if (_cores[6] != null)
dataModel.Cpu.Core7Usage = (int)_cores[6].NextValue();
if (_cores[7] != null)
dataModel.Cpu.Core8Usage = (int)_cores[7].NextValue();
} }
public override List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets) public override List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets)
{ {
return Profile.GetRenderLayers<WindowsProfileDataModel>(DataModel, renderMice, renderHeadsets, true); return Profile.GetRenderLayers<WindowsProfileDataModel>(DataModel, renderMice, renderHeadsets, true);
} }
public static List<PerformanceCounter> GetPerformanceCounters()
{
var performanceCounters = new List<PerformanceCounter>();
var procCount = Environment.ProcessorCount;
for (var i = 0; i < procCount; i++)
{
var pc = new PerformanceCounter("Processor", "% Processor Time", i.ToString());
performanceCounters.Add(pc);
}
return performanceCounters;
}
} }
} }

View File

@ -1,4 +1,5 @@
using System.ComponentModel; using System.ComponentModel;
using Artemis.Events;
using Artemis.InjectionFactories; using Artemis.InjectionFactories;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
@ -10,7 +11,7 @@ using Caliburn.Micro;
namespace Artemis.Modules.Effects.WindowsProfile namespace Artemis.Modules.Effects.WindowsProfile
{ {
// TODO: This effect is a hybrid between a regular effect and a game, may want to clean this up // TODO: This effect is a hybrid between a regular effect and a game, may want to clean this up
public sealed class WindowsProfileViewModel : EffectViewModel public sealed class WindowsProfileViewModel : EffectViewModel, IHandle<ActiveEffectChanged>
{ {
public WindowsProfileViewModel(MainManager main, IEventAggregator events, IProfileEditorVmFactory pFactory, public WindowsProfileViewModel(MainManager main, IEventAggregator events, IProfileEditorVmFactory pFactory,
ProfilePreviewModel profilePreviewModel) ProfilePreviewModel profilePreviewModel)
@ -20,10 +21,11 @@ namespace Artemis.Modules.Effects.WindowsProfile
PFactory = pFactory; PFactory = pFactory;
ProfilePreviewModel = profilePreviewModel; ProfilePreviewModel = profilePreviewModel;
EffectSettings = ((WindowsProfileModel)EffectModel).Settings; EffectSettings = ((WindowsProfileModel)EffectModel).Settings;
ProfileEditor = PFactory.CreateProfileEditorVm(events, main, (WindowsProfileModel)EffectModel, ProfileEditor = PFactory.CreateProfileEditorVm(events, main, (WindowsProfileModel)EffectModel,
((WindowsProfileSettings)EffectSettings).LastProfile); ((WindowsProfileSettings)EffectSettings).LastProfile);
ProfilePreviewModel.Profile = ProfileEditor.SelectedProfile; ProfilePreviewModel.Profile = ProfileEditor.SelectedProfile;
events.Subscribe(this);
ProfileEditor.PropertyChanged += ProfileUpdater; ProfileEditor.PropertyChanged += ProfileUpdater;
MainManager.EffectManager.EffectModels.Add(EffectModel); MainManager.EffectManager.EffectModels.Add(EffectModel);
} }
@ -58,6 +60,11 @@ namespace Artemis.Modules.Effects.WindowsProfile
base.OnDeactivate(close); base.OnDeactivate(close);
ProfileEditor.ProfileViewModel.Deactivate(); ProfileEditor.ProfileViewModel.Deactivate();
} }
public void Handle(ActiveEffectChanged message)
{
NotifyOfPropertyChange(() => EffectEnabled);
}
} }
public class WindowsProfileSettings : GameSettings public class WindowsProfileSettings : GameSettings

View File

@ -91,7 +91,7 @@ namespace Artemis.ViewModels.Profiles
if (_blurProgress > 2) if (_blurProgress > 2)
_blurProgress = 0; _blurProgress = 0;
_blurProgress = _blurProgress + 0.025; _blurProgress = _blurProgress + 0.025;
BlurRadius = (Math.Sin(_blurProgress*Math.PI) + 1)*10 + 10; BlurRadius = (Math.Sin(_blurProgress * Math.PI) + 1) * 10 + 10;
if (SelectedProfile == null || _deviceManager.ActiveKeyboard == null) if (SelectedProfile == null || _deviceManager.ActiveKeyboard == null)
{ {
@ -120,12 +120,12 @@ namespace Artemis.ViewModels.Profiles
if (accentColor == null) if (accentColor == null)
return; return;
var pen = new Pen(new SolidColorBrush((Color) accentColor), 0.4); var pen = new Pen(new SolidColorBrush((Color)accentColor), 0.4);
// Draw the selection outline and resize indicator // Draw the selection outline and resize indicator
if (SelectedLayer != null && SelectedLayer.MustDraw()) if (SelectedLayer != null && SelectedLayer.MustDraw())
{ {
var layerRect = ((KeyboardPropertiesModel) SelectedLayer.Properties).GetRect(); var layerRect = ((KeyboardPropertiesModel)SelectedLayer.Properties).GetRect();
// Deflate the rect so that the border is drawn on the inside // Deflate the rect so that the border is drawn on the inside
layerRect.Inflate(-0.2, -0.2); layerRect.Inflate(-0.2, -0.2);
@ -188,15 +188,17 @@ namespace Artemis.ViewModels.Profiles
var timeSinceDown = DateTime.Now - _downTime; var timeSinceDown = DateTime.Now - _downTime;
if (!(timeSinceDown.TotalMilliseconds < 500)) if (!(timeSinceDown.TotalMilliseconds < 500))
return; return;
if (_draggingLayer != null)
return;
var keyboard = _deviceManager.ActiveKeyboard; var keyboard = _deviceManager.ActiveKeyboard;
var pos = e.GetPosition((Image) e.OriginalSource); var pos = e.GetPosition((Image)e.OriginalSource);
var x = pos.X/((double) keyboard.PreviewSettings.Width/keyboard.Width); var x = pos.X / ((double)keyboard.PreviewSettings.Width / keyboard.Width);
var y = pos.Y/((double) keyboard.PreviewSettings.Height/keyboard.Height); var y = pos.Y / ((double)keyboard.PreviewSettings.Height / keyboard.Height);
var hoverLayer = SelectedProfile.GetLayers() var hoverLayer = SelectedProfile.GetLayers()
.Where(l => l.MustDraw()) .Where(l => l.MustDraw())
.FirstOrDefault(l => ((KeyboardPropertiesModel) l.Properties) .FirstOrDefault(l => ((KeyboardPropertiesModel)l.Properties)
.GetRect(1) .GetRect(1)
.Contains(x, y)); .Contains(x, y));
@ -212,13 +214,13 @@ namespace Artemis.ViewModels.Profiles
if (SelectedProfile == null) if (SelectedProfile == null)
return; return;
var pos = e.GetPosition((Image) e.OriginalSource); var pos = e.GetPosition((Image)e.OriginalSource);
var keyboard = _deviceManager.ActiveKeyboard; var keyboard = _deviceManager.ActiveKeyboard;
var x = pos.X/((double) keyboard.PreviewSettings.Width/keyboard.Width); var x = pos.X / ((double)keyboard.PreviewSettings.Width / keyboard.Width);
var y = pos.Y/((double) keyboard.PreviewSettings.Height/keyboard.Height); var y = pos.Y / ((double)keyboard.PreviewSettings.Height / keyboard.Height);
var hoverLayer = SelectedProfile.GetLayers() var hoverLayer = SelectedProfile.GetLayers()
.Where(l => l.MustDraw()) .Where(l => l.MustDraw())
.FirstOrDefault(l => ((KeyboardPropertiesModel) l.Properties) .FirstOrDefault(l => ((KeyboardPropertiesModel)l.Properties)
.GetRect(1).Contains(x, y)); .GetRect(1).Contains(x, y));
HandleDragging(e, x, y, hoverLayer); HandleDragging(e, x, y, hoverLayer);
@ -233,7 +235,7 @@ namespace Artemis.ViewModels.Profiles
// Turn the mouse pointer into a hand if hovering over an active layer // Turn the mouse pointer into a hand if hovering over an active layer
if (hoverLayer == SelectedLayer) if (hoverLayer == SelectedLayer)
{ {
var rect = ((KeyboardPropertiesModel) hoverLayer.Properties).GetRect(1); var rect = ((KeyboardPropertiesModel)hoverLayer.Properties).GetRect(1);
KeyboardPreviewCursor = KeyboardPreviewCursor =
Math.Sqrt(Math.Pow(x - rect.BottomRight.X, 2) + Math.Pow(y - rect.BottomRight.Y, 2)) < 0.6 Math.Sqrt(Math.Pow(x - rect.BottomRight.X, 2) + Math.Pow(y - rect.BottomRight.Y, 2)) < 0.6
? Cursors.SizeNWSE ? Cursors.SizeNWSE
@ -278,8 +280,8 @@ namespace Artemis.ViewModels.Profiles
// Setup the dragging state on mouse press // Setup the dragging state on mouse press
if (_draggingLayerOffset == null && hoverLayer != null && e.LeftButton == MouseButtonState.Pressed) if (_draggingLayerOffset == null && hoverLayer != null && e.LeftButton == MouseButtonState.Pressed)
{ {
var layerRect = ((KeyboardPropertiesModel) hoverLayer.Properties).GetRect(1); var layerRect = ((KeyboardPropertiesModel)hoverLayer.Properties).GetRect(1);
var selectedProps = (KeyboardPropertiesModel) SelectedLayer.Properties; var selectedProps = (KeyboardPropertiesModel)SelectedLayer.Properties;
_draggingLayerOffset = new Point(x - selectedProps.X, y - selectedProps.Y); _draggingLayerOffset = new Point(x - selectedProps.X, y - selectedProps.Y);
_draggingLayer = hoverLayer; _draggingLayer = hoverLayer;
@ -291,13 +293,13 @@ namespace Artemis.ViewModels.Profiles
if (_draggingLayerOffset == null || _draggingLayer == null || (_draggingLayer != SelectedLayer)) if (_draggingLayerOffset == null || _draggingLayer == null || (_draggingLayer != SelectedLayer))
return; return;
var draggingProps = (KeyboardPropertiesModel) _draggingLayer?.Properties; var draggingProps = (KeyboardPropertiesModel)_draggingLayer?.Properties;
// If no setup or reset was done, handle the actual dragging action // If no setup or reset was done, handle the actual dragging action
if (_resizing) if (_resizing)
{ {
draggingProps.Width = (int) Math.Round(x - draggingProps.X); draggingProps.Width = (int)Math.Round(x - draggingProps.X);
draggingProps.Height = (int) Math.Round(y - draggingProps.Y); draggingProps.Height = (int)Math.Round(y - draggingProps.Y);
if (draggingProps.Width < 1) if (draggingProps.Width < 1)
draggingProps.Width = 1; draggingProps.Width = 1;
if (draggingProps.Height < 1) if (draggingProps.Height < 1)
@ -305,8 +307,8 @@ namespace Artemis.ViewModels.Profiles
} }
else else
{ {
draggingProps.X = (int) Math.Round(x - _draggingLayerOffset.Value.X); draggingProps.X = (int)Math.Round(x - _draggingLayerOffset.Value.X);
draggingProps.Y = (int) Math.Round(y - _draggingLayerOffset.Value.Y); draggingProps.Y = (int)Math.Round(y - _draggingLayerOffset.Value.Y);
} }
} }