mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Added core usage to WindowsProfileDataModel
This commit is contained in:
parent
cc4439126e
commit
be70786319
@ -51,9 +51,9 @@ namespace Artemis.Models
|
||||
// Render the keyboard layer-by-layer
|
||||
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)
|
||||
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)
|
||||
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);
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
|
||||
</Grid.RowDefinitions>
|
||||
@ -80,38 +79,28 @@
|
||||
Grid.Row="4" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes"
|
||||
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 -->
|
||||
<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">
|
||||
Volume sensitivity multiplier
|
||||
</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"
|
||||
Value="{Binding Path=EffectSettings.Sensitivity, Mode=TwoWay}" Minimum="1" Maximum="10"
|
||||
SmallChange="1" IsSnapToTickEnabled="True" />
|
||||
|
||||
<!-- 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">
|
||||
Bar fade-out speed
|
||||
</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"
|
||||
Value="{Binding Path=EffectSettings.FadeSpeed, Mode=TwoWay}" Minimum="1" Maximum="3"
|
||||
SmallChange="1" IsSnapToTickEnabled="True" />
|
||||
|
||||
<!-- 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"
|
||||
Style="{DynamicResource SquareButtonStyle}" />
|
||||
<Button x:Name="SaveSettings" Content="Save changes" VerticalAlignment="Top" Width="100"
|
||||
|
||||
@ -4,5 +4,23 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
{
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Artemis.Managers;
|
||||
using Artemis.Models;
|
||||
using Artemis.Models.Profiles;
|
||||
@ -7,6 +9,9 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
{
|
||||
public class WindowsProfileModel : EffectModel
|
||||
{
|
||||
private List<PerformanceCounter> _cores;
|
||||
private int _cpuFrames;
|
||||
|
||||
public WindowsProfileModel(MainManager mainManager, WindowsProfileSettings settings)
|
||||
: base(mainManager, new WindowsProfileDataModel())
|
||||
{
|
||||
@ -23,16 +28,68 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
// Setup CPU cores
|
||||
_cores = GetPerformanceCounters();
|
||||
var coreCount = _cores.Count;
|
||||
while (coreCount < 8)
|
||||
{
|
||||
_cores.Add(null);
|
||||
coreCount++;
|
||||
}
|
||||
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using Artemis.Events;
|
||||
using Artemis.InjectionFactories;
|
||||
using Artemis.Managers;
|
||||
using Artemis.Models;
|
||||
@ -10,7 +11,7 @@ using Caliburn.Micro;
|
||||
namespace Artemis.Modules.Effects.WindowsProfile
|
||||
{
|
||||
// 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,
|
||||
ProfilePreviewModel profilePreviewModel)
|
||||
@ -20,10 +21,11 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
PFactory = pFactory;
|
||||
ProfilePreviewModel = profilePreviewModel;
|
||||
EffectSettings = ((WindowsProfileModel)EffectModel).Settings;
|
||||
|
||||
ProfileEditor = PFactory.CreateProfileEditorVm(events, main, (WindowsProfileModel)EffectModel,
|
||||
((WindowsProfileSettings)EffectSettings).LastProfile);
|
||||
ProfilePreviewModel.Profile = ProfileEditor.SelectedProfile;
|
||||
|
||||
events.Subscribe(this);
|
||||
ProfileEditor.PropertyChanged += ProfileUpdater;
|
||||
MainManager.EffectManager.EffectModels.Add(EffectModel);
|
||||
}
|
||||
@ -58,6 +60,11 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
base.OnDeactivate(close);
|
||||
ProfileEditor.ProfileViewModel.Deactivate();
|
||||
}
|
||||
|
||||
public void Handle(ActiveEffectChanged message)
|
||||
{
|
||||
NotifyOfPropertyChange(() => EffectEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
public class WindowsProfileSettings : GameSettings
|
||||
|
||||
@ -91,7 +91,7 @@ namespace Artemis.ViewModels.Profiles
|
||||
if (_blurProgress > 2)
|
||||
_blurProgress = 0;
|
||||
_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)
|
||||
{
|
||||
@ -120,12 +120,12 @@ namespace Artemis.ViewModels.Profiles
|
||||
if (accentColor == null)
|
||||
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
|
||||
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
|
||||
layerRect.Inflate(-0.2, -0.2);
|
||||
|
||||
@ -188,15 +188,17 @@ namespace Artemis.ViewModels.Profiles
|
||||
var timeSinceDown = DateTime.Now - _downTime;
|
||||
if (!(timeSinceDown.TotalMilliseconds < 500))
|
||||
return;
|
||||
if (_draggingLayer != null)
|
||||
return;
|
||||
|
||||
var keyboard = _deviceManager.ActiveKeyboard;
|
||||
var pos = e.GetPosition((Image) e.OriginalSource);
|
||||
var x = pos.X/((double) keyboard.PreviewSettings.Width/keyboard.Width);
|
||||
var y = pos.Y/((double) keyboard.PreviewSettings.Height/keyboard.Height);
|
||||
var pos = e.GetPosition((Image)e.OriginalSource);
|
||||
var x = pos.X / ((double)keyboard.PreviewSettings.Width / keyboard.Width);
|
||||
var y = pos.Y / ((double)keyboard.PreviewSettings.Height / keyboard.Height);
|
||||
|
||||
var hoverLayer = SelectedProfile.GetLayers()
|
||||
.Where(l => l.MustDraw())
|
||||
.FirstOrDefault(l => ((KeyboardPropertiesModel) l.Properties)
|
||||
.FirstOrDefault(l => ((KeyboardPropertiesModel)l.Properties)
|
||||
.GetRect(1)
|
||||
.Contains(x, y));
|
||||
|
||||
@ -212,13 +214,13 @@ namespace Artemis.ViewModels.Profiles
|
||||
if (SelectedProfile == null)
|
||||
return;
|
||||
|
||||
var pos = e.GetPosition((Image) e.OriginalSource);
|
||||
var pos = e.GetPosition((Image)e.OriginalSource);
|
||||
var keyboard = _deviceManager.ActiveKeyboard;
|
||||
var x = pos.X/((double) keyboard.PreviewSettings.Width/keyboard.Width);
|
||||
var y = pos.Y/((double) keyboard.PreviewSettings.Height/keyboard.Height);
|
||||
var x = pos.X / ((double)keyboard.PreviewSettings.Width / keyboard.Width);
|
||||
var y = pos.Y / ((double)keyboard.PreviewSettings.Height / keyboard.Height);
|
||||
var hoverLayer = SelectedProfile.GetLayers()
|
||||
.Where(l => l.MustDraw())
|
||||
.FirstOrDefault(l => ((KeyboardPropertiesModel) l.Properties)
|
||||
.FirstOrDefault(l => ((KeyboardPropertiesModel)l.Properties)
|
||||
.GetRect(1).Contains(x, y));
|
||||
|
||||
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
|
||||
if (hoverLayer == SelectedLayer)
|
||||
{
|
||||
var rect = ((KeyboardPropertiesModel) hoverLayer.Properties).GetRect(1);
|
||||
var rect = ((KeyboardPropertiesModel)hoverLayer.Properties).GetRect(1);
|
||||
KeyboardPreviewCursor =
|
||||
Math.Sqrt(Math.Pow(x - rect.BottomRight.X, 2) + Math.Pow(y - rect.BottomRight.Y, 2)) < 0.6
|
||||
? Cursors.SizeNWSE
|
||||
@ -278,8 +280,8 @@ namespace Artemis.ViewModels.Profiles
|
||||
// Setup the dragging state on mouse press
|
||||
if (_draggingLayerOffset == null && hoverLayer != null && e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var layerRect = ((KeyboardPropertiesModel) hoverLayer.Properties).GetRect(1);
|
||||
var selectedProps = (KeyboardPropertiesModel) SelectedLayer.Properties;
|
||||
var layerRect = ((KeyboardPropertiesModel)hoverLayer.Properties).GetRect(1);
|
||||
var selectedProps = (KeyboardPropertiesModel)SelectedLayer.Properties;
|
||||
|
||||
_draggingLayerOffset = new Point(x - selectedProps.X, y - selectedProps.Y);
|
||||
_draggingLayer = hoverLayer;
|
||||
@ -291,13 +293,13 @@ namespace Artemis.ViewModels.Profiles
|
||||
if (_draggingLayerOffset == null || _draggingLayer == null || (_draggingLayer != SelectedLayer))
|
||||
return;
|
||||
|
||||
var draggingProps = (KeyboardPropertiesModel) _draggingLayer?.Properties;
|
||||
var draggingProps = (KeyboardPropertiesModel)_draggingLayer?.Properties;
|
||||
|
||||
// If no setup or reset was done, handle the actual dragging action
|
||||
if (_resizing)
|
||||
{
|
||||
draggingProps.Width = (int) Math.Round(x - draggingProps.X);
|
||||
draggingProps.Height = (int) Math.Round(y - draggingProps.Y);
|
||||
draggingProps.Width = (int)Math.Round(x - draggingProps.X);
|
||||
draggingProps.Height = (int)Math.Round(y - draggingProps.Y);
|
||||
if (draggingProps.Width < 1)
|
||||
draggingProps.Width = 1;
|
||||
if (draggingProps.Height < 1)
|
||||
@ -305,8 +307,8 @@ namespace Artemis.ViewModels.Profiles
|
||||
}
|
||||
else
|
||||
{
|
||||
draggingProps.X = (int) Math.Round(x - _draggingLayerOffset.Value.X);
|
||||
draggingProps.Y = (int) Math.Round(y - _draggingLayerOffset.Value.Y);
|
||||
draggingProps.X = (int)Math.Round(x - _draggingLayerOffset.Value.X);
|
||||
draggingProps.Y = (int)Math.Round(y - _draggingLayerOffset.Value.Y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user