浏览代码

Multi monitor support and misc stuff

Ruben Hyldgaard Negendahl 7 年之前
父节点
当前提交
bee4b22d4a

二进制
Extra/Screenshot2.png


二进制
Extra/gnosis.PNG


+ 19 - 5
PicView/MainWindow.xaml.cs

@@ -234,8 +234,6 @@ namespace PicView
             functionsMenu.DeletePermButton.Click += (s, x) => DeleteFile(PicPath, false);
             functionsMenu.ReloadButton.Click += (s, x) => Reload();
             functionsMenu.ReloadButton.Click += Toggle_Functions_menu;
-            functionsMenu.RenameFileButton.Click += (s, x) => ToolsWindow();
-            functionsMenu.RenameFileButton.Click += Toggle_Functions_menu;
             functionsMenu.ResetZoomButton.Click += (s, x) => ResetZoom();
             functionsMenu.SlideshowButton.Click += (s, x) => LoadSlideshow();
             functionsMenu.SlideshowButton.Click += Toggle_Functions_menu;
@@ -782,8 +780,24 @@ namespace PicView
         /// </summary>
         private void CenterWindowOnScreen()
         {
-            Top = (SystemParameters.WorkArea.Height - Height) / 2;
-            Left = (SystemParameters.WorkArea.Width - Width) / 2;
+            // https://stackoverflow.com/a/32599760
+
+            //get the current monitor
+            var currentMonitor = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).Handle);
+
+            //find out if our app is being scaled by the monitor
+            PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow);
+            double dpiScaling = (source != null && source.CompositionTarget != null ? source.CompositionTarget.TransformFromDevice.M11 : 1);
+
+            //get the available area of the monitor
+            System.Drawing.Rectangle workArea = currentMonitor.WorkingArea;
+            var workAreaWidth = (int)Math.Floor(workArea.Width * dpiScaling);
+            var workAreaHeight = (int)Math.Floor(workArea.Height * dpiScaling);
+
+            //move to the centre
+            Application.Current.MainWindow.Left = (((workAreaWidth - (Width * dpiScaling)) / 2) + (workArea.Left * dpiScaling));
+            Application.Current.MainWindow.Top = (((workAreaHeight - (Height * dpiScaling)) / 2) + (workArea.Top * dpiScaling));
+            
         }
 
         /// <summary>
@@ -1239,7 +1253,7 @@ namespace PicView
                 img.Width = xWidth;
                 img.Height = xHeight;
 
-                img.Source = GetBitmapSourceThumb(Pics[FolderIndex]);
+                img.Source = Preloader.Contains(Pics[FolderIndex])? Preloader.Load(Pics[FolderIndex]) : GetBitmapSourceThumb(Pics[FolderIndex]);
             }));
             Progress(FolderIndex, Pics.Count);
             FastPicRunning = true;

+ 1 - 0
PicView/PicVIew.csproj

@@ -100,6 +100,7 @@
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml" />
     <Reference Include="Microsoft.CSharp" />
     <Reference Include="System.Core" />

+ 18 - 18
PicView/lib/ImageManager.cs

@@ -27,13 +27,13 @@ namespace PicView.lib
                 magick.Quality = 100;
                 magick.ColorSpace = ColorSpace.Transparent;
 
-                var mrs = new MagickReadSettings()
-                {
-                    Density = new Density(300, 300),
-                };
-
                 if (extension.ToLower() == ".svg")
                 {
+                    var mrs = new MagickReadSettings()
+                    {
+                        Density = new Density(300, 300),
+                    };
+
                     // Make background transparent
                     mrs.Format = MagickFormat.Svg;
                     mrs.BackgroundColor = MagickColors.Transparent;
@@ -70,6 +70,19 @@ namespace PicView.lib
             var ext = Path.GetExtension(path).ToLower();
             switch (ext)
             {
+                // Standards
+                case ".jpg":
+                case ".jpeg":
+                case ".jpe":
+                case ".png":
+                case ".bmp":
+                case ".tif":
+                case ".tiff":
+                case ".gif":
+                case ".ico":
+                case ".wdp":
+                    return Helper.GetWindowsThumbnail(path);
+
                 // Non-standards
                 case ".svg":
                 case ".psd":
@@ -189,19 +202,6 @@ namespace PicView.lib
                 case ".yuv":
                     return GetMagickImage(path, 60, 55);
 
-                // Standards
-                case ".jpg":
-                case ".jpeg":
-                case ".jpe":
-                case ".png":
-                case ".bmp":
-                case ".tif":
-                case ".tiff":
-                case ".gif":
-                case ".ico":
-                case ".wdp":
-                    return Helper.GetWindowsThumbnail(path);
-
                 // Non supported
                 default:
                     return null;

+ 18 - 16
PicView/lib/Preloader.cs

@@ -79,32 +79,34 @@ namespace PicView.lib
         /// </summary>
         internal static void Clear()
         {
-            var array = Sources.Keys.ToArray();
-
-            var timer = new DispatcherTimer
-            (
-                TimeSpan.FromSeconds(20), DispatcherPriority.Loaded, (s, e) => {
-                    for (int i = 0; i < array.Length; i++)
-                    {
-                        Remove(array[i]);
-                    }
-                    GC.Collect();
-                },
-                Application.Current.Dispatcher
-            );
-            timer.Start();
+            // Add elemnts to Clear method and set timer to fast
+            Clear(Sources.Keys.ToArray(), true);
         }
 
         /// <summary>
         /// Removes specific keys and clears them when app is idle
         /// </summary>
         /// <param name="array"></param>
-        internal static void Clear(string[] array)
+        internal static void Clear(string[] array, bool fast = false)
         {
+            // Set time to clear the images
+            var timeInSeconds = 420; // 7 min
+            
+            // clear faster if it contains a lot of images or if fast == true
+            if (Sources.Count > 100)
+            {
+                timeInSeconds = 60;
+            }
+            else if (fast)
+            {
+                timeInSeconds = 20;
+            }
+
             var timer = new DispatcherTimer
             (
-                TimeSpan.FromSeconds(25), DispatcherPriority.Loaded, (s, e) =>
+                TimeSpan.FromSeconds(timeInSeconds), DispatcherPriority.Background, (s, e) =>
                 {
+                    // Remove elements
                     for (int i = 0; i < array.Length; i++)
                     {
                         Remove(array[i]);

+ 0 - 22
PicView/lib/UserControls/Menus/FunctionsMenu.xaml

@@ -225,28 +225,6 @@
                         </Path>
                     </Button>
 
-                    <Button
-                        x:Name="RenameFileButton"
-                        Width="42"
-                        Height="42"
-                        Margin="0,0,4,0"
-                        Style="{StaticResource MetroAlphaFlatButton}"
-                        ToolTip="Rename file [Not implemented]">
-                        <Canvas>
-                            <Path
-                                Canvas.Left="-13"
-                                Canvas.Top="-15"
-                                Width="28"
-                                Height="30"
-                                Data="M6 0l-1 1 2 2 1-1-2-2zm-2 2l-4 4v2h2l4-4-2-2z"
-                                Stretch="Fill">
-                                <Path.Fill>
-                                    <SolidColorBrush x:Name="RenameFileBrush" Color="{StaticResource MainColor}" />
-                                </Path.Fill>
-                            </Path>
-                        </Canvas>
-                    </Button>
-
                     <Button
                         x:Name="FileDetailsButton"
                         Width="42"

+ 0 - 33
PicView/lib/UserControls/Menus/FunctionsMenu.xaml.cs

@@ -23,11 +23,6 @@ namespace PicView.lib.UserControls.Menus
             FileDetailsButton.MouseLeave += FileDetailsButtonMouseLeave;
             FileDetailsButton.PreviewMouseLeftButtonDown += FileDetailsButtonMouseButtonDown;
 
-            //RenameFileButton
-            RenameFileButton.MouseEnter += RenameFileButtonMouseOver;
-            RenameFileButton.MouseLeave += RenameFileButtonMouseLeave;
-            RenameFileButton.PreviewMouseLeftButtonDown += RenameFileButtonMouseButtonDown;
-
             //HelpButton
             Help.MouseEnter += HelpButtonMouseOver;
             Help.MouseLeave += HelpButtonMouseLeave;
@@ -271,34 +266,6 @@ namespace PicView.lib.UserControls.Menus
         }
 
         //ToolsWindow Button
-        private void RenameFileButtonMouseOver(object sender, MouseEventArgs e)
-        {
-            AnimationHelper.MouseEnterColorEvent(
-                mainColor.A,
-                mainColor.R,
-                mainColor.G,
-                mainColor.B,
-                RenameFileBrush,
-                false
-            );
-        }
-
-        private void RenameFileButtonMouseButtonDown(object sender, MouseButtonEventArgs e)
-        {
-            AnimationHelper.PreviewMouseLeftButtonDownColorEvent(RenameFileBrush, false);
-        }
-
-        private void RenameFileButtonMouseLeave(object sender, MouseEventArgs e)
-        {
-            AnimationHelper.MouseLeaveColorEvent(
-                mainColor.A,
-                mainColor.R,
-                mainColor.G,
-                mainColor.B,
-                RenameFileBrush,
-                false
-            );
-        }
 
         // File Details Button
         private void FileDetailsButtonMouseOver(object sender, MouseEventArgs e)