using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.Core;
using Tango.Core.DI;
using Tango.FSE.Common;
using Tango.FSE.Common.Resolution;
using Tango.Settings;
namespace Tango.FSE.UI.Resolution
{
///
/// Represents the default implementation.
///
///
///
[TangoCreateWhenRegistered]
public class DefaultResolutionService : ExtendedObject, IResolutionService
{
private FSESettings _settings;
///
/// Occurs when predefined resolution mode has changed.
///
public event EventHandler ResolutionModeChanged;
///
/// Occurs when the resolution/window size has changed.
///
public event EventHandler ResolutionChanged;
private ResolutionMode resolution;
///
/// Gets the current resolution mode.
///
public ResolutionMode Resolution
{
get
{
return resolution;
}
private set
{
resolution = value;
RaisePropertyChangedAuto();
}
}
private bool _AdaptiveTransformMode;
///
/// Gets or sets a value indicating whether the application is currently scaling it self using a transform.
///
public bool AdaptiveScalingMode
{
get { return _AdaptiveTransformMode; }
set { _AdaptiveTransformMode = value; RaisePropertyChangedAuto(); }
}
private bool isLowResolution;
///
/// Gets a value indicating whether the current resolution mode is low.
///
public bool IsLowResolution
{
get
{
return isLowResolution;
}
private set
{
isLowResolution = value;
RaisePropertyChangedAuto();
}
}
private bool isHighResolution;
///
/// Gets a value indicating whether the current resolution mode is high.
///
public bool IsHighResolution
{
get
{
return isHighResolution;
}
private set
{
isHighResolution = value;
RaisePropertyChangedAuto();
}
}
private double resolutionWidth;
///
/// Gets the resolution width.
///
public double ResolutionWidth
{
get
{
return resolutionWidth;
}
private set
{
resolutionWidth = value;
RaisePropertyChangedAuto();
}
}
private double resolutionHeight;
///
/// Gets the resolution height.
///
public double ResolutionHeight
{
get
{
return resolutionHeight;
}
private set
{
resolutionHeight = value;
RaisePropertyChangedAuto();
}
}
///
/// Initializes a new instance of the class.
///
/// The window.
public DefaultResolutionService(Window window)
{
if (window != null)
{
window.SizeChanged += Window_SizeChanged;
}
_settings = SettingsManager.Default.GetOrCreate();
}
///
/// Initializes a new instance of the class.
///
[TangoInject]
public DefaultResolutionService() : this(Application.Current.MainWindow)
{
}
///
/// Handles the application main window size changed event.
///
/// The source of the event.
/// The instance containing the event data.
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
ResolutionMode previousMode = Resolution;
if (AdaptiveScalingMode)
{
isHighResolution = true;
IsLowResolution = false;
ResolutionWidth = 1920;
ResolutionHeight = 1080;
Resolution = ResolutionMode.High;
if (Resolution != previousMode)
{
LogManager.Log($"Application resolution mode changed to: {Resolution}, size: {ResolutionWidth}x{ResolutionHeight}.");
ResolutionModeChanged?.Invoke(this, Resolution);
}
return;
}
var size = e.NewSize;
ResolutionWidth = size.Width;
ResolutionHeight = size.Height;
IsHighResolution = ResolutionWidth > 1599 && ResolutionHeight > 800;
IsLowResolution = !isHighResolution;
Resolution = IsHighResolution ? ResolutionMode.High : ResolutionMode.Low;
if (Resolution != previousMode)
{
LogManager.Log($"Application resolution mode changed to: {Resolution}, size: {ResolutionWidth}x{ResolutionHeight}.");
ResolutionModeChanged?.Invoke(this, Resolution);
}
ResolutionChanged?.Invoke(this, e);
}
}
}