|
|
@@ -1,10 +1,19 @@
|
|
|
-using System.Windows;
|
|
|
+using System.IO;
|
|
|
+using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
+using ImageMagick;
|
|
|
+using System.Windows.Media.Imaging;
|
|
|
+using System.Windows.Media;
|
|
|
+using System.Windows.Threading;
|
|
|
using PicView.WPF.ChangeImage;
|
|
|
using PicView.WPF.ConfigureSettings;
|
|
|
+using PicView.WPF.ImageHandling;
|
|
|
using PicView.WPF.Properties;
|
|
|
using PicView.WPF.Shortcuts;
|
|
|
using PicView.WPF.SystemIntegration;
|
|
|
+using PicView.WPF.UILogic.Sizing;
|
|
|
+using PicView.WPF.Views.UserControls.Misc;
|
|
|
+using PicView.WPF.Views.Windows;
|
|
|
using static PicView.WPF.ChangeImage.Navigation;
|
|
|
using static PicView.WPF.UILogic.Loading.LoadContextMenus;
|
|
|
using static PicView.WPF.UILogic.Loading.LoadControls;
|
|
|
@@ -16,13 +25,88 @@ namespace PicView.WPF.UILogic.Loading
|
|
|
{
|
|
|
internal static class StartLoading
|
|
|
{
|
|
|
- internal static async Task LoadedEvent()
|
|
|
+ internal static async Task LoadedEvent(Startup_Window startupWindow)
|
|
|
{
|
|
|
- Pics = new List<string>();
|
|
|
-
|
|
|
+ var spinner = GetSpinWaiter;
|
|
|
+ spinner = new SpinWaiter();
|
|
|
+ startupWindow.TheGrid.Children.Add(spinner);
|
|
|
+ Panel.SetZIndex(spinner, 99);
|
|
|
+ BitmapSource? bitmapSource = null;
|
|
|
+ var image = new Image
|
|
|
+ {
|
|
|
+ Stretch = Stretch.Uniform,
|
|
|
+ };
|
|
|
// Load sizing properties
|
|
|
- MonitorInfo = MonitorSize.GetMonitorSize();
|
|
|
+ MonitorInfo = MonitorSize.GetMonitorSize(startupWindow);
|
|
|
+ if (Settings.Default.AutoFitWindow == false && Settings.Default.Fullscreen == false)
|
|
|
+ {
|
|
|
+ SetLastWindowSize(startupWindow);
|
|
|
+ }
|
|
|
+
|
|
|
+ var args = Environment.GetCommandLineArgs();
|
|
|
|
|
|
+ if (args.Length > 1)
|
|
|
+ {
|
|
|
+ await Task.Run(async () =>
|
|
|
+ {
|
|
|
+ using var magickImage = new MagickImage();
|
|
|
+ magickImage.Ping(args[1]);
|
|
|
+ var thumb = magickImage.GetExifProfile()?.CreateThumbnail();
|
|
|
+ var bitmapThumb = thumb?.ToBitmapSource();
|
|
|
+ bitmapThumb?.Freeze();
|
|
|
+ await startupWindow.Dispatcher.InvokeAsync(() =>
|
|
|
+ {
|
|
|
+ image.Source = bitmapThumb;
|
|
|
+ startupWindow.TheGrid.Children.Add(image);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ bitmapSource = await Image2BitmapSource.ReturnBitmapSourceAsync(new FileInfo(args[1])).ConfigureAwait(false);
|
|
|
+ await startupWindow.Dispatcher.InvokeAsync(() =>
|
|
|
+ {
|
|
|
+ if (Settings.Default.AutoFitWindow)
|
|
|
+ {
|
|
|
+ var size = Core.Calculations.ImageSizeCalculationHelper.GetImageSize(
|
|
|
+ bitmapSource.PixelWidth,
|
|
|
+ bitmapSource.PixelHeight,
|
|
|
+ MonitorInfo.WorkArea.Width,
|
|
|
+ MonitorInfo.WorkArea.Height,
|
|
|
+ 0,
|
|
|
+ Settings.Default.FillImage,
|
|
|
+ 20 * MonitorInfo.DpiScaling,
|
|
|
+ MonitorInfo.DpiScaling,
|
|
|
+ Settings.Default.Fullscreen,
|
|
|
+ 30 * MonitorInfo.DpiScaling,
|
|
|
+ 25 * MonitorInfo.DpiScaling,
|
|
|
+ Settings.Default.IsBottomGalleryShown ? Settings.Default.BottomGalleryItemSize : 0,
|
|
|
+ true,
|
|
|
+ ConfigureWindows.GetMainWindow.ParentContainer.Width,
|
|
|
+ ConfigureWindows.GetMainWindow.ParentContainer.Height,
|
|
|
+ Settings.Default.ScrollEnabled
|
|
|
+ );
|
|
|
+ image.Stretch = Stretch.Fill;
|
|
|
+ image.Width = startupWindow.Width = size.Width;
|
|
|
+ image.Height = startupWindow.Height = size.Height;
|
|
|
+ CenterWindowOnScreen(startupWindow);
|
|
|
+ }
|
|
|
+ image.Source = bitmapSource;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ await startupWindow.Dispatcher.InvokeAsync(() =>
|
|
|
+ {
|
|
|
+ startupWindow.TheGrid.Children.Remove(spinner);
|
|
|
+ var mainWindow = new MainWindow();
|
|
|
+ ConfigureWindows.GetMainWindow = mainWindow;
|
|
|
+ // Determine preferred UI for startup
|
|
|
+ if (Settings.Default.AutoFitWindow == false)
|
|
|
+ {
|
|
|
+ SetLastWindowSize(mainWindow);
|
|
|
+ }
|
|
|
+ mainWindow.MainImage.Source = image.Source;
|
|
|
+ GetSpinWaiter = spinner;
|
|
|
+ mainWindow.ParentContainer.Children.Add(spinner);
|
|
|
+ });
|
|
|
+ Pics = new List<string>();
|
|
|
await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
|
|
|
{
|
|
|
// Set min size to DPI scaling
|
|
|
@@ -31,7 +115,7 @@ namespace PicView.WPF.UILogic.Loading
|
|
|
|
|
|
SetWindowBehavior();
|
|
|
if (Settings.Default.AutoFitWindow == false)
|
|
|
- SetLastWindowSize();
|
|
|
+ SetLastWindowSize(ConfigureWindows.GetMainWindow);
|
|
|
|
|
|
ConfigureWindows.GetMainWindow.Scroller.VerticalScrollBarVisibility = Settings.Default.ScrollEnabled
|
|
|
? ScrollBarVisibility.Auto
|
|
|
@@ -49,45 +133,39 @@ namespace PicView.WPF.UILogic.Loading
|
|
|
= Visibility.Collapsed;
|
|
|
}
|
|
|
});
|
|
|
- await CustomKeybindings.LoadKeybindings().ConfigureAwait(false);
|
|
|
- ConfigColors.UpdateColor();
|
|
|
-
|
|
|
- var args = Environment.GetCommandLineArgs();
|
|
|
-
|
|
|
- // Determine preferred UI for startup
|
|
|
- if (Settings.Default.Fullscreen)
|
|
|
+ if (args.Length > 1)
|
|
|
{
|
|
|
- if (args.Length < 2)
|
|
|
- {
|
|
|
- Settings.Default.Fullscreen = false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
|
|
|
- {
|
|
|
- Fullscreen_Restore(true);
|
|
|
- });
|
|
|
- }
|
|
|
+ await QuickLoad.QuickLoadAsync(args[1], null, bitmapSource).ConfigureAwait(false);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ErrorHandling.Unload(true);
|
|
|
}
|
|
|
|
|
|
- // Load image if possible
|
|
|
- if (args.Length < 2)
|
|
|
+ await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
|
|
|
{
|
|
|
- await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
|
|
|
+ ConfigureWindows.GetMainWindow.Show();
|
|
|
+ if (Settings.Default.Fullscreen)
|
|
|
{
|
|
|
- // Make sure to fix loading spinner showing up
|
|
|
- if (ConfigureWindows.GetMainWindow.MainImage.Source is null)
|
|
|
+ if (args.Length < 2)
|
|
|
{
|
|
|
- GetSpinWaiter.Visibility = Visibility.Collapsed;
|
|
|
+ Settings.Default.Fullscreen = false;
|
|
|
}
|
|
|
- });
|
|
|
- ErrorHandling.Unload(true);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- InitialPath = args[1];
|
|
|
- await QuickLoad.QuickLoadAsync(args[1]).ConfigureAwait(false);
|
|
|
- }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Fullscreen_Restore(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Settings.Default.AutoFitWindow)
|
|
|
+ {
|
|
|
+ ScaleImage.TryFitImage();
|
|
|
+ }
|
|
|
+ startupWindow.Close();
|
|
|
+ });
|
|
|
+
|
|
|
+ await CustomKeybindings.LoadKeybindings().ConfigureAwait(false);
|
|
|
+
|
|
|
+ ConfigColors.UpdateColor();
|
|
|
}
|
|
|
|
|
|
internal static void AddDictionaries()
|