// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // The Static Preview View Model // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.ViewModels { using System; using System.Windows; using System.Windows.Media.Imaging; using HandBrake.ApplicationServices.Model; using HandBrake.ApplicationServices.Services.Interfaces; using HandBrakeWPF.ViewModels.Interfaces; /// /// The Static Preview View Model /// public class StaticPreviewViewModel : ViewModelBase, IStaticPreviewViewModel { /* * TODO * - Screen needs to be made DPI Aware * - Integrate Video Preview panel. */ #region Fields /// /// The scan service. /// private readonly IScan scanService; /// /// The height. /// private int height; /// /// The preview image. /// private BitmapImage previewImage; /// /// The selected preview image. /// private int selectedPreviewImage; /// /// The width. /// private int width; #endregion #region Constructors and Destructors /// /// Initializes a new instance of the class. /// /// /// The scan service. /// public StaticPreviewViewModel(IScan scanService) { this.scanService = scanService; this.selectedPreviewImage = 1; this.Title = Properties.Resources.Preview; } #endregion #region Public Properties /// /// Gets or sets the height. /// public int Height { get { return this.height; } set { if (value == this.height) { return; } this.height = value; this.NotifyOfPropertyChange(() => this.Height); } } /// /// Gets or sets the preview image. /// public BitmapImage PreviewImage { get { return this.previewImage; } set { if (Equals(value, this.previewImage)) { return; } this.previewImage = value; this.NotifyOfPropertyChange(() => this.PreviewImage); } } /// /// Gets or sets the selected preview image. /// public int SelectedPreviewImage { get { return this.selectedPreviewImage; } set { if (value == this.selectedPreviewImage) { return; } this.selectedPreviewImage = value; this.NotifyOfPropertyChange(() => this.SelectedPreviewImage); this.UpdatePreviewFrame(); } } /// /// Gets or sets the task. /// public EncodeTask Task { get; set; } /// /// Gets the total previews. /// public int TotalPreviews { get { return this.UserSettingService.GetUserSetting(UserSettingConstants.PreviewScanCount) - 1; } } /// /// Gets or sets the width. /// public int Width { get { return this.width; } set { if (value == this.width) { return; } this.width = value; this.NotifyOfPropertyChange(() => this.Width); } } #endregion #region Public Methods and Operators /// /// The update preview frame. /// /// /// The task. /// public void UpdatePreviewFrame(EncodeTask task) { this.Task = task; this.UpdatePreviewFrame(); this.DisplayName = "Picture Preview"; this.Title = Properties.Resources.Preview; } /// /// Gets or sets a value indicating whether is open. /// public bool IsOpen { get; set; } /// /// The update preview frame. /// public void UpdatePreviewFrame() { BitmapImage image = this.scanService.GetPreview(this.Task, this.SelectedPreviewImage); if (image != null) { this.Width = (int)Math.Ceiling(image.Width); this.Height = (int)Math.Ceiling(image.Height); this.PreviewImage = image; } } /// /// The preview size changed. /// /// /// The ea. /// public void PreviewSizeChanged(SizeChangedEventArgs ea) { Rect workArea = SystemParameters.WorkArea; if (ea.NewSize.Width > workArea.Width) { this.Width = (int)Math.Round(workArea.Width, 0) - 20; this.Title = Properties.Resources.Preview_Scaled; } if (ea.NewSize.Height > workArea.Height) { this.Height = (int)Math.Round(workArea.Height, 0) - 20; this.Title = Properties.Resources.Preview_Scaled; } } #endregion } }