wabbajack/Wabbajack/Views/Common/CpuView.xaml.cs

90 lines
3.5 KiB
C#
Raw Normal View History

2019-12-08 22:30:49 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
2019-12-08 22:30:49 +00:00
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
2019-12-08 22:30:49 +00:00
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Lib;
using System.Windows.Controls.Primitives;
using System.Reactive.Linq;
2020-02-08 04:35:08 +00:00
using Wabbajack.Common;
2019-11-07 05:33:08 +00:00
namespace Wabbajack
{
/// <summary>
2019-12-08 22:30:49 +00:00
/// Interaction logic for CpuView.xaml
2019-11-07 05:33:08 +00:00
/// </summary>
public partial class CpuView : UserControlRx<ICpuStatusVM>
2019-11-07 05:33:08 +00:00
{
2020-02-08 04:35:08 +00:00
public Percent ProgressPercent
{
2020-02-08 04:35:08 +00:00
get => (Percent)GetValue(ProgressPercentProperty);
set => SetValue(ProgressPercentProperty, value);
}
2020-02-08 04:35:08 +00:00
public static readonly DependencyProperty ProgressPercentProperty = DependencyProperty.Register(nameof(ProgressPercent), typeof(Percent), typeof(CpuView),
new FrameworkPropertyMetadata(default(Percent), WireNotifyPropertyChanged));
public MainSettings SettingsHook
{
get => (MainSettings)GetValue(SettingsHookProperty);
set => SetValue(SettingsHookProperty, value);
}
public static readonly DependencyProperty SettingsHookProperty = DependencyProperty.Register(nameof(SettingsHook), typeof(MainSettings), typeof(CpuView),
2020-01-20 21:59:26 +00:00
new FrameworkPropertyMetadata(default(SettingsVM), WireNotifyPropertyChanged));
private bool _ShowingSettings;
public bool ShowingSettings { get => _ShowingSettings; set => this.RaiseAndSetIfChanged(ref _ShowingSettings, value); }
2019-12-08 22:30:49 +00:00
public CpuView()
2019-11-07 05:33:08 +00:00
{
InitializeComponent();
this.WhenActivated(disposable =>
{
Observable.CombineLatest(
this.WhenAny(x => x.ControlGrid.IsMouseOver),
this.WhenAny(x => x.SettingsHook.Performance.Manual)
.StartWith(true),
resultSelector: (over, manual) => over && !manual)
2020-02-08 04:35:08 +00:00
.Select(showing => showing ? Visibility.Visible : Visibility.Collapsed)
.BindToStrict(this, x => x.SettingsBar.Visibility)
.DisposeWith(disposable);
2020-02-08 04:35:08 +00:00
this.WhenAny(x => x.ViewModel.StatusList)
.BindToStrict(this, x => x.CpuListControl.ItemsSource)
.DisposeWith(disposable);
2020-02-08 04:35:08 +00:00
this.Bind(this.ViewModel, x => x.MWVM.Settings.Performance.TargetUsage, x => x.TargetPercentageSlider.Value)
.DisposeWith(disposable);
2020-02-08 04:35:08 +00:00
this.WhenAny(x => x.ViewModel.MWVM.Settings.Performance.TargetUsage)
.Select(p => p.ToString(0))
.BindToStrict(this, x => x.PercentageText.Text)
.DisposeWith(disposable);
this.WhenAny(x => x.ViewModel.CurrentCpuCount)
.DistinctUntilChanged()
2020-02-08 04:35:08 +00:00
.Select(x => $"{x.CurrentCPUs} / {x.DesiredCPUs}")
.BindToStrict(this, x => x.CpuCountText.Text)
.DisposeWith(disposable);
// Progress
this.WhenAny(x => x.ProgressPercent)
.Select(p => p.Value)
.BindToStrict(this, x => x.HeatedBorderRect.Opacity)
.DisposeWith(disposable);
});
2019-11-07 05:33:08 +00:00
}
}
}