示例#1
0
        /// <summary>
        /// Fits image size based on users screen resolution
        /// or window size
        /// </summary>
        /// <param name="width">The pixel width of the image</param>
        /// <param name="height">The pixel height of the image</param>
        internal static void FitImage(double width, double height)
        {
            if (width <= 0 || height <= 0)
            {
                return;
            }

            double maxWidth, maxHeight;
            var    borderSpaceHeight = Properties.Settings.Default.Fullscreen ? 0 : GetMainWindow.LowerBar.Height + GetMainWindow.TitleBar.Height + 6;
            var    borderSpaceWidth  = Properties.Settings.Default.Fullscreen && Properties.Settings.Default.ShowAltInterfaceButtons ? 0 : 20 * MonitorInfo.DpiScaling;

            var monitorWidth  = (MonitorInfo.WorkArea.Width * MonitorInfo.DpiScaling) - borderSpaceWidth;
            var monitorHeight = (MonitorInfo.WorkArea.Height * MonitorInfo.DpiScaling) - borderSpaceHeight;

            double padding;// Padding to make it feel more comfortable

            if (MonitorInfo.DpiScaling >= 1)
            {
                padding = MonitorInfo.Height - monitorHeight;
                padding = padding < 0 ? 0 : padding;
            }
            else
            {
                padding = 0;
            }

            if (Properties.Settings.Default.PicGallery == 2)
            {
                /// Extra padding for picgallery required
                padding  += picGalleryItem_Size - 50;
                maxWidth  = Math.Min(monitorWidth - padding, width);
                maxHeight = Math.Min(monitorHeight, height);
            }
            else if (Properties.Settings.Default.AutoFitWindow) // If non resizeable behaviour
            {
                if (Properties.Settings.Default.FillImage)      // Max to monitor height if scaling enabled, else go by min pixel width
                {
                    maxWidth  = monitorWidth;
                    maxHeight = monitorHeight;
                }
                else
                {
                    /// Use padding for shown interface
                    maxWidth  = Math.Min(monitorWidth - padding, width);
                    maxHeight = Math.Min(monitorHeight - padding, height);
                }
            }
            else /// Get max width and height, based on window size
            {
                if (Properties.Settings.Default.FillImage)
                {
                    maxWidth  = GetMainWindow.ParentContainer.ActualWidth;
                    maxHeight = GetMainWindow.ParentContainer.ActualHeight;
                }
                else
                {
                    maxWidth  = Math.Min(GetMainWindow.ParentContainer.ActualWidth, width);
                    maxHeight = Math.Min(GetMainWindow.ParentContainer.ActualHeight, height);
                }
            }

            if (Rotateint == 0 || Rotateint == 180) // Standard aspect ratio calculation
            {
                AspectRatio = Math.Min(maxWidth / width, maxHeight / height);
            }
            else // Rotated aspect ratio calculation
            {
                AspectRatio = Math.Min(maxWidth / height, maxHeight / width);
            }

            if (IsScrollEnabled)
            {
                /// Calculate height based on width
                GetMainWindow.MainImage.Width  = maxWidth;
                GetMainWindow.MainImage.Height = maxWidth * height / width;

                /// Set mainWindow.Scroller height to aspect ratio calculation
                GetMainWindow.Scroller.Height = height * AspectRatio;

                /// Update values
                xWidth  = GetMainWindow.MainImage.Width;
                xHeight = GetMainWindow.Scroller.Height;
            }
            else
            {
                /// Reset mainWindow.Scroller's height to auto
                GetMainWindow.Scroller.Height = double.NaN;

                /// Fit image by aspect ratio calculation
                /// and update values
                GetMainWindow.MainImage.Width  = xWidth = width * AspectRatio;
                GetMainWindow.MainImage.Height = xHeight = height * AspectRatio;
            }

            if (GetMainWindow.WindowState == System.Windows.WindowState.Normal)
            {
                /// Update TitleBar
                var interfaceSize = 205 * MonitorInfo.DpiScaling; // logo and buttons width

                if (Properties.Settings.Default.PicGallery == 2)
                {
                    if (xWidth >= monitorWidth - (UC.GetPicGallery.ActualWidth + 5) * 1.88)
                    {
                        // Offset window to not overlap gallery
                        GetMainWindow.Left = ((MonitorInfo.WorkArea.Width - (UC.GetPicGallery.ActualWidth + 5) - (GetMainWindow.ActualWidth * MonitorInfo.DpiScaling)) / 2)
                                             + (MonitorInfo.WorkArea.Left * MonitorInfo.DpiScaling);
                        GetMainWindow.Top = ((MonitorInfo.WorkArea.Height
                                              - (GetMainWindow.Height * MonitorInfo.DpiScaling)) / 2) + (MonitorInfo.WorkArea.Top * MonitorInfo.DpiScaling);
                    }
                    else
                    {
                        CenterWindowOnScreen();
                    }
                }
                else if (Properties.Settings.Default.AutoFitWindow)
                {
                    /// Update mainWindow.TitleBar width to dynamically fit new size
                    var x = Rotateint == 0 || Rotateint == 180 ? Math.Max(xWidth, GetMainWindow.MinWidth) : Math.Max(xHeight, GetMainWindow.MinHeight);
                    GetMainWindow.TitleText.MaxWidth = x - interfaceSize < interfaceSize ? interfaceSize : x - interfaceSize;

                    if (Properties.Settings.Default.KeepCentered)
                    {
                        CenterWindowOnScreen();
                    }
                }
                else
                {
                    /// Fix title width to window size
                    GetMainWindow.TitleText.MaxWidth = GetMainWindow.ActualWidth - interfaceSize;
                }
            }

            if (ZoomLogic.ZoomValue == 1.0)
            {
                ZoomLogic.ResetZoom(false);
            }
        }
示例#2
0
        /// <summary>
        /// Fits image size based on users screen resolution
        /// or window size
        /// </summary>
        /// <param name="width">The pixel width of the image</param>
        /// <param name="height">The pixel height of the image</param>
        internal static void FitImage(double width, double height)
        {
            // TODO improve sizing for high DPI cases

            if (width <= 0 || height <= 0)
            {
                return;
            }

            var showInterface = Properties.Settings.Default.ShowInterface;

            double maxWidth, maxHeight;
            var    borderSpaceHeight = showInterface ? LoadWindows.GetMainWindow.LowerBar.Height + LoadWindows.GetMainWindow.TitleBar.Height + 6 : 6;
            var    borderSpaceWidth  = 20 * MonitorInfo.DpiScaling; // Based on UI borders

            var monitorWidth  = (MonitorInfo.WorkArea.Width * MonitorInfo.DpiScaling) - borderSpaceWidth;
            var monitorHeight = (MonitorInfo.WorkArea.Height * MonitorInfo.DpiScaling) - borderSpaceHeight;

            var padding = MonitorInfo.Height - monitorHeight; // Padding to make it feel more comfortable

            padding = padding < 0 ? 0 : padding;

            if (Properties.Settings.Default.PicGallery == 2)
            {
                /// Extra padding for picgallery required
                padding  += picGalleryItem_Size - 50;
                maxWidth  = Math.Min(monitorWidth - padding, width);
                maxHeight = Math.Min(monitorHeight, height);
            }
            else if (Properties.Settings.Default.AutoFitWindow) // If non resizeable behaviour
            {
                if (Properties.Settings.Default.FillImage)      // Max to monitor height if scaling enabled, else go by min pixel width
                {
                    maxWidth  = monitorWidth;
                    maxHeight = monitorHeight;
                }
                else
                {
                    /// Use padding for shown interface
                    maxWidth  = Math.Min(monitorWidth - padding, width);
                    maxHeight = Math.Min(monitorHeight - padding, height);
                }
            }
            else /// Get max width and height, based on window size
            {
                if (Properties.Settings.Default.FillImage)
                {
                    maxWidth  = LoadWindows.GetMainWindow.ParentContainer.ActualWidth;
                    maxHeight = LoadWindows.GetMainWindow.ParentContainer.ActualHeight;
                }
                else
                {
                    maxWidth = Math.Min(LoadWindows.GetMainWindow.Width, width);

                    if (showInterface)
                    {
                        /// Use padding for shown interface
                        maxHeight = Math.Min(LoadWindows.GetMainWindow.Height - padding, height);
                    }
                    else
                    {
                        maxHeight = Math.Min(LoadWindows.GetMainWindow.Height, height);
                    }
                }
            }

            if (Rotateint == 0 || Rotateint == 180) // Standard aspect ratio calculation
            {
                AspectRatio = Math.Min(maxWidth / width, maxHeight / height);
            }
            else // Rotated aspect ratio calculation
            {
                AspectRatio = Math.Min(maxWidth / height, maxHeight / width);
            }

            if (IsScrollEnabled)
            {
                /// Calculate height based on width
                LoadWindows.GetMainWindow.MainImage.Width  = maxWidth;
                LoadWindows.GetMainWindow.MainImage.Height = maxWidth * height / width;

                /// Set mainWindow.Scroller height to aspect ratio calculation
                LoadWindows.GetMainWindow.Scroller.Height = height * AspectRatio;

                /// Update values
                xWidth  = LoadWindows.GetMainWindow.MainImage.Width;
                xHeight = LoadWindows.GetMainWindow.Scroller.Height;
            }
            else
            {
                /// Reset mainWindow.Scroller's height to auto
                LoadWindows.GetMainWindow.Scroller.Height = double.NaN;

                /// Fit image by aspect ratio calculation
                /// and update values
                LoadWindows.GetMainWindow.MainImage.Width  = xWidth = width * AspectRatio;
                LoadWindows.GetMainWindow.MainImage.Height = xHeight = height * AspectRatio;
            }

            if (!Properties.Settings.Default.Fullscreen)
            {
                /// Update TitleBar
                var interfaceSize = 190 * MonitorInfo.DpiScaling; // logo and buttons width

                if (Properties.Settings.Default.PicGallery == 2)
                {
                    if (xWidth >= monitorWidth - (picGalleryItem_Size + 200))
                    {
                        // Offset window to not overlap gallery
                        LoadWindows.GetMainWindow.Left = ((MonitorInfo.WorkArea.Width - picGalleryItem_Size - (LoadWindows.GetMainWindow.ActualWidth * MonitorInfo.DpiScaling)) / 2)
                                                         + (MonitorInfo.WorkArea.Left * MonitorInfo.DpiScaling);
                        LoadWindows.GetMainWindow.Top = ((MonitorInfo.WorkArea.Height
                                                          - (LoadWindows.GetMainWindow.Height * MonitorInfo.DpiScaling)) / 2) + (MonitorInfo.WorkArea.Top * MonitorInfo.DpiScaling);
                    }
                    else
                    {
                        CenterWindowOnScreen();
                    }
                }
                else if (Properties.Settings.Default.AutoFitWindow)
                {
                    /// Update mainWindow.TitleBar width to dynamically fit new size
                    var x = Rotateint == 0 || Rotateint == 180 ? Math.Max(xWidth, LoadWindows.GetMainWindow.MinWidth) : Math.Max(xHeight, LoadWindows.GetMainWindow.MinHeight);
                    LoadWindows.GetMainWindow.TitleText.MaxWidth = x - interfaceSize < interfaceSize ? interfaceSize : x - interfaceSize;

                    CenterWindowOnScreen();
                }
                else
                {
                    /// Fix title width to window size
                    LoadWindows.GetMainWindow.TitleText.MaxWidth = LoadWindows.GetMainWindow.ActualWidth - interfaceSize;
                }
            }

            if (ZoomLogic.ZoomValue == 1.0)
            {
                ZoomLogic.ResetZoom(false);
            }
        }