// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Interaction logic for StaticPreviewView.xaml // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Views { using System; using System.Windows; using System.Windows.Input; using System.Windows.Media.Imaging; using HandBrakeWPF.ViewModels.Interfaces; /// /// Interaction logic for StaticPreviewView.xaml /// public partial class StaticPreviewView : Window { /// /// Initializes a new instance of the class. /// public StaticPreviewView() { 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) { if (e.Delta > 1) { ((IStaticPreviewViewModel)this.DataContext).NextPreview(); } else { ((IStaticPreviewViewModel)this.DataContext).PreviousPreview(); } } private void UpdateWindowTitle() { BitmapSource 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; } } } }