diff --git a/ZKuP/Helper.cs b/ZKuP/Helper.cs index aed1517..c861247 100644 --- a/ZKuP/Helper.cs +++ b/ZKuP/Helper.cs @@ -1,4 +1,5 @@ -using Microsoft.Win32; +using MahApps.Metro.Controls; +using Microsoft.Win32; using System; using System.Collections; using System.Collections.Generic; @@ -36,6 +37,7 @@ namespace ZKuP { public static double width = 0; public static double height = 0; + public static double scale = 0; public static bool? IsFileLocked(FileInfo file) { try @@ -809,54 +811,67 @@ namespace ZKuP return GetCell(grid, rowContainer, column); } + + internal static void initScaler(double Width, double Height) + { + width = Width; + height = Height; + } + static double lastDpiScale = -1; static bool _isCurrentlyScaled = false; internal static async void CheckScale(Window mainWindow) { - var dpi = VisualTreeHelper.GetDpi(mainWindow); - double dpiScale = dpi.DpiScaleX; // or DpiScaleY - - - double scaledWidth = width * dpiScale; - double scaledHeight = height * dpiScale; - - var screen = WpfScreenHelper.Screen.FromHandle(new WindowInteropHelper(mainWindow).Handle); - var workingArea = screen.WorkingArea; - - bool needsScaling = (width * dpiScale) > workingArea.Width || (height * dpiScale) > workingArea.Height; - - lastDpiScale = dpiScale; - - if (needsScaling) + if (!(width == 0 || height == 0)) { - // Calculate the scale to fit in working area - double scaleX = workingArea.Width / width; - double scaleY = workingArea.Height / height; - double scale = Math.Min(scaleX, scaleY); + var dpi = VisualTreeHelper.GetDpi(mainWindow); + double dpiScale = dpi.DpiScaleX; // or DpiScaleY - scale = Math.Round(scale * 4) / 4.0; - mainWindow.MinWidth = scale * width; - mainWindow.MinHeight = scale * height; - mainWindow.LayoutTransform = new ScaleTransform(scale, scale); + double scaledWidth = width * dpiScale; + double scaledHeight = height * dpiScale; - mainWindow.Width = mainWindow.MinWidth; - mainWindow.Height = mainWindow.MinHeight; + var screen = WpfScreenHelper.Screen.FromHandle(new WindowInteropHelper(mainWindow).Handle); + var workingArea = screen.WorkingArea; - TextOptions.SetTextFormattingMode(mainWindow, TextFormattingMode.Display); - TextOptions.SetTextRenderingMode(mainWindow, TextRenderingMode.ClearType); - _isCurrentlyScaled = true; - } - else if (_isCurrentlyScaled) - { - // Reset to normal scale - mainWindow.LayoutTransform = Transform.Identity; + bool needsScaling = (width * dpiScale) > workingArea.Width || (height * dpiScale) > workingArea.Height; - mainWindow.MinWidth = width != 0 ? width : mainWindow.MinWidth; - mainWindow.MinHeight = height != 0 ? height : mainWindow.MinHeight; + lastDpiScale = dpiScale; - TextOptions.SetTextFormattingMode(mainWindow, TextFormattingMode.Ideal); - TextOptions.SetTextRenderingMode(mainWindow, TextRenderingMode.Auto); + if (needsScaling && !_isCurrentlyScaled) + { + // Calculate the scale to fit in working area + double scaleX = width / workingArea.Width; + double scaleY = height / workingArea.Height; + scale = Math.Min(scaleX, scaleY); + + scale = Math.Round(scale * 4) / 4.0; + + mainWindow.MinWidth = scale * width; + mainWindow.MinHeight = scale * height; + mainWindow.LayoutTransform = new ScaleTransform(scale, scale); + + + mainWindow.Width = mainWindow.MinWidth; + mainWindow.Height = mainWindow.MinHeight; + + TextOptions.SetTextFormattingMode(mainWindow, TextFormattingMode.Display); + TextOptions.SetTextRenderingMode(mainWindow, TextRenderingMode.ClearType); + _isCurrentlyScaled = true; + } + else if (_isCurrentlyScaled && !needsScaling) + { + // Reset to normal scale + mainWindow.LayoutTransform = Transform.Identity; + + mainWindow.MinWidth = width != 0 ? width : mainWindow.MinWidth; + mainWindow.MinHeight = height != 0 ? height : mainWindow.MinHeight; + + TextOptions.SetTextFormattingMode(mainWindow, TextFormattingMode.Ideal); + TextOptions.SetTextRenderingMode(mainWindow, TextRenderingMode.Auto); + + _isCurrentlyScaled = false; + } } } diff --git a/ZKuP/MainWindow.xaml b/ZKuP/MainWindow.xaml index 0ff015f..deee3b0 100644 --- a/ZKuP/MainWindow.xaml +++ b/ZKuP/MainWindow.xaml @@ -607,7 +607,7 @@ - + diff --git a/ZKuP/MainWindow.xaml.cs b/ZKuP/MainWindow.xaml.cs index c77311a..e0b71bb 100644 --- a/ZKuP/MainWindow.xaml.cs +++ b/ZKuP/MainWindow.xaml.cs @@ -43,7 +43,7 @@ namespace ZKuP PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - public const string Version = "5.1.0.4"; + public const string Version = "5.1.0.5"; public static Roles LoggedInRole { get; private set; } = Roles.None; @@ -291,8 +291,7 @@ namespace ZKuP if (actualheight <= 191) gridBackground.RowDefinitions[1].Height = new GridLength(maxheight); //gridSpinner.Visibility = Visibility.Collapsed; - Helper.width = this.MinWidth; - Helper.height = this.MinHeight; + Helper.initScaler(this.MinWidth, this.MinHeight); connTimer.Interval = TimeSpan.FromSeconds(2); @@ -3038,10 +3037,10 @@ namespace ZKuP Point splitterPosition = splitter.TransformToAncestor(window).Transform(new Point(0, 0)); - if (splitterPosition.Y > (this.ActualHeight - 190)) + if (splitterPosition.Y > ((this.ActualHeight - 190) / Helper.scale)) { e.Handled = true; // Bewegung stoppen - gridRowTop.Height = new GridLength(this.ActualHeight - 160 - 190); + gridRowTop.Height = new GridLength((this.ActualHeight - 160 - 190) / Helper.scale); } }