54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using System;
|
|
using JD.VideoPlayer.WPF.Settings;
|
|
using Plume.Icons;
|
|
using Plume.Interfaces.WPF;
|
|
using Action = Plume.Interfaces.WPF.Actions.Action;
|
|
|
|
namespace JD.VideoPlayer.WPF.Actions
|
|
{
|
|
public class AspectRatioAction : Action
|
|
{
|
|
private readonly AspectRatio _aspectRatio;
|
|
|
|
/// <inheritdoc />
|
|
public AspectRatioAction(AspectRatio aspectRatio) :
|
|
base(GetText(aspectRatio), $"Change aspect ratio to {GetText(aspectRatio)}", GetIcon(aspectRatio))
|
|
{
|
|
_aspectRatio = aspectRatio;
|
|
GroupName = nameof(AspectRatio);
|
|
IsCheckable = true;
|
|
IsChecked = ((IWpfApplication) System.Windows.Application.Current).SettingsManager.Get<VideoPlayerSettings>()?.AspectRatio == aspectRatio;
|
|
Icon = GetIcon(aspectRatio);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void TryExecute()
|
|
{
|
|
var settings = Context.SettingsManager.Get<VideoPlayerSettings>();
|
|
if (settings != null)
|
|
{
|
|
settings.AspectRatio = _aspectRatio;
|
|
}
|
|
}
|
|
|
|
private static Icon GetIcon(AspectRatio aspectRatio)
|
|
{
|
|
switch (aspectRatio)
|
|
{
|
|
case AspectRatio.Stretch: return new Uri("/JD.VideoPlayer.WPF;Component/Resources/aspect-stretch.png", UriKind.Relative);
|
|
default: return new Uri("/JD.VideoPlayer.WPF;Component/Resources/aspect-wide.png", UriKind.Relative);
|
|
}
|
|
}
|
|
|
|
private static string GetText(AspectRatio aspectRatio)
|
|
{
|
|
return $"Ratio : {aspectRatio}";
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override bool CanExecute()
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|