From 7244ea454654b4b6d8f97f33174303445edb08ff Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 15 Dec 2017 22:40:06 +0000 Subject: WinGui: Add % Actual Size to the static preview window title. --- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 12 ++--- .../HandBrakeWPF/Properties/Resources.Designer.cs | 11 ++++- win/CS/HandBrakeWPF/Properties/Resources.resx | 5 ++- .../Interfaces/IStaticPreviewViewModel.cs | 4 ++ .../ViewModels/StaticPreviewViewModel.cs | 30 ++++++++----- win/CS/HandBrakeWPF/Views/StaticPreviewView.xaml | 3 +- .../HandBrakeWPF/Views/StaticPreviewView.xaml.cs | 51 +++++++++++++++++++++- 7 files changed, 93 insertions(+), 23 deletions(-) (limited to 'win/CS') diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 7f2a7cbbd..226a6eeb2 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -189,6 +189,11 @@ + + True + True + Resources.resx + ResourcesTooltips.resx True @@ -472,11 +477,6 @@ Code - - True - True - Resources.resx - PublicResXFileCodeGenerator ResourcesTooltips.Designer.cs @@ -489,8 +489,8 @@ PublicResXFileCodeGenerator - Resources.Designer.cs Designer + Resources.Designer.cs stylecop.json diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index c30ec5f3a..947ea86da 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -1423,7 +1423,7 @@ namespace HandBrakeWPF.Properties { } /// - /// Looks up a localized string similar to Preview. + /// Looks up a localized string similar to Preview {0}. /// public static string Preview { get { @@ -1729,6 +1729,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Preview ({0}% actual size). + /// + public static string StaticPreviewView_Title { + get { + return ResourceManager.GetString("StaticPreviewView_Title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Handbrake is already encoding a video! Only one file can be encoded at any one time.. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index c841deee1..f0c3f0316 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -467,7 +467,7 @@ Do you wish to proceed? The entered destination path contained illegal characters and will not be updated. - Preview + Preview {0} Preview (Scaled) @@ -869,4 +869,7 @@ Remaining Time: {4} FPS: {3:000.0}, Avg FPS: {4:000.0} Time Remaining: {5}, Elapsed: {6:d\:hh\:mm\:ss} + + Preview ({0}% actual size) + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IStaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IStaticPreviewViewModel.cs index 06a22ae01..0c1884bb1 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IStaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IStaticPreviewViewModel.cs @@ -9,6 +9,8 @@ namespace HandBrakeWPF.ViewModels.Interfaces { + using System.Windows.Media.Imaging; + using HandBrakeWPF.Services.Scan.Model; using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; @@ -34,6 +36,8 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// bool IsOpen { get; set; } + BitmapImage PreviewImage { get; } + void PreviousPreview(); void NextPreview(); } diff --git a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs index 6f5fc6e5d..4a2d3e2b2 100644 --- a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs @@ -173,7 +173,7 @@ namespace HandBrakeWPF.ViewModels { return; } - this.height = value; + this.height = this.FixHeight(value); this.NotifyOfPropertyChange(() => this.Height); } } @@ -257,7 +257,7 @@ namespace HandBrakeWPF.ViewModels { return; } - this.width = value; + this.width = this.FixWidth(value); this.NotifyOfPropertyChange(() => this.Width); } } @@ -450,7 +450,7 @@ namespace HandBrakeWPF.ViewModels /// /// The update preview frame. /// - [HandleProcessCorruptedStateExceptions] + [HandleProcessCorruptedStateExceptions] public void UpdatePreviewFrame() { // Don't preview for small images. @@ -492,26 +492,32 @@ namespace HandBrakeWPF.ViewModels /// /// The ea. /// - public void PreviewSizeChanged(SizeChangedEventArgs ea) + public int FixWidth(int width) { - // TODO implement window size scaling here. Rect workArea = SystemParameters.WorkArea; - if (ea.NewSize.Width > workArea.Width) + if (width > workArea.Width) { - this.Width = (int)Math.Round(workArea.Width, 0) - 50; - this.Title = Resources.Preview_Scaled; + return (int)Math.Round(workArea.Width, 0) - 50; } - if (ea.NewSize.Height > workArea.Height) + return 100; + } + + public int FixHeight(int height) + { + Rect workArea = SystemParameters.WorkArea; + if (height > workArea.Height) { - this.Height = (int)Math.Round(workArea.Height, 0) - 50; - this.Title = Resources.Preview_Scaled; + return (int)Math.Round(workArea.Height, 0) - 50; } + + return 100; } + #endregion #region Public Method - Live Preview - + #region Public Methods /// diff --git a/win/CS/HandBrakeWPF/Views/StaticPreviewView.xaml b/win/CS/HandBrakeWPF/Views/StaticPreviewView.xaml index c7eb5fb09..2ec3dcaa3 100644 --- a/win/CS/HandBrakeWPF/Views/StaticPreviewView.xaml +++ b/win/CS/HandBrakeWPF/Views/StaticPreviewView.xaml @@ -9,7 +9,6 @@ mc:Ignorable="d" SizeToContent="WidthAndHeight" TextOptions.TextFormattingMode="Display" WindowStartupLocation="CenterScreen" - cal:Message.Attach="[Event SizeChanged] = [Action PreviewSizeChanged($eventArgs)]" Title="{Binding Title}"> @@ -21,7 +20,7 @@ - + public StaticPreviewView() { - InitializeComponent(); + this.InitializeComponent(); + + this.SizeChanged += this.StaticPreviewView_SizeChanged; + this.Title = Properties.Resources.Preview; + } + + private void StaticPreviewView_SizeChanged(object sender, SizeChangedEventArgs e) + { + // Prevent the Window Growing Past Screen Bounds + Rect workArea = SystemParameters.WorkArea; + if (e.NewSize.Width > workArea.Width) + { + this.Width = (int)Math.Round(workArea.Width, 0) - 50; + } + + if (e.NewSize.Height > workArea.Height) + { + this.Height = (int)Math.Round(workArea.Height, 0) - 50; + } + + // Update Window title scale factor. + this.UpdateWindowTitle(); } private void PreviewImage_OnMouseWheel(object sender, MouseWheelEventArgs e) @@ -38,5 +61,31 @@ namespace HandBrakeWPF.Views ((IStaticPreviewViewModel)this.DataContext).PreviousPreview(); } } + + private void UpdateWindowTitle() + { + BitmapImage image = ((IStaticPreviewViewModel)this.DataContext).PreviewImage; + if (image != null && this.previewImage != null && this.previewImage.ActualWidth > 0) + { + double origWidth = Math.Round(image.Width, 0); + double origHeight = Math.Round(image.Height, 0); + + double actualWidth = Math.Round(this.previewImage.ActualWidth, 0); + double actualHeight = Math.Round(this.previewImage.ActualHeight, 0); + + double scaleW = actualWidth / origWidth; + double scaleH = actualHeight / origHeight; + + double scaleFactor = Math.Min(scaleW, scaleH); + + double scalePercentage = Math.Round(100 * scaleFactor, 0); + + this.Title = string.Format(Properties.Resources.StaticPreviewView_Title, scalePercentage); + } + else + { + this.Title = Properties.Resources.Preview; + } + } } } -- cgit v1.2.3