Skip to content

Commit

Permalink
Implement spinning indicator when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed May 9, 2023
1 parent 1efc016 commit e90ad65
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
16 changes: 4 additions & 12 deletions PicView/ChangeImage/LoadPic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using PicView.UILogic;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using PicView.UILogic.Loading;
using static PicView.ChangeImage.ErrorHandling;
using static PicView.ChangeImage.Navigation;
using static PicView.ChangeTitlebar.SetTitle;
Expand Down Expand Up @@ -324,15 +326,8 @@ internal static async Task LoadPicAtIndexAsync(int index, FileInfo? fileInfo = n
/// <param name="showLoading"></param>
internal static void LoadingPreview(FileInfo fileInfo, bool showLoading = true)
{
var isLogo = false;
var thumb = Thumbnails.GetThumb(FolderIndex, fileInfo);
if (thumb is null)
{
thumb = ImageFunctions.ShowLogo() ?? ImageFunctions.ImageErrorMessage();
isLogo = true;
}

var bitmapSourceHolder = new Thumbnails.LogoOrThumbHolder(thumb, isLogo);
ConfigureWindows.GetMainWindow.Dispatcher.Invoke(DispatcherPriority.Send, () =>
{
if (showLoading)
Expand All @@ -342,12 +337,9 @@ internal static void LoadingPreview(FileInfo fileInfo, bool showLoading = true)
}

ConfigureWindows.GetMainWindow.MainImage.Cursor = Cursors.Wait;
GetSpinWaiter.Visibility = Visibility.Visible;

ConfigureWindows.GetMainWindow.MainImage.Source = bitmapSourceHolder.Thumb;
// Set to logo size or don't allow image size to stretch the whole screen, fixes when opening new image from unloaded status
if (!bitmapSourceHolder.isLogo && !(XWidth < 1)) return;
ConfigureWindows.GetMainWindow.MainImage.Width = Thumbnails.LogoOrThumbHolder.Size;
ConfigureWindows.GetMainWindow.MainImage.Height = Thumbnails.LogoOrThumbHolder.Size;
ConfigureWindows.GetMainWindow.MainImage.Source = thumb;
});
}

Expand Down
9 changes: 9 additions & 0 deletions PicView/ChangeImage/QuickLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using PicView.SystemIntegration;
using PicView.UILogic;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
Expand Down Expand Up @@ -66,6 +67,14 @@ await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
ConfigureWindows.GetMainWindow.MainImage.Source = errorImage);
}

await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
{
if (UC.GetSpinWaiter is { IsVisible: true })
{
UC.GetSpinWaiter.Visibility = Visibility.Collapsed;
}
});

Pics = FileList(fileInfo);
FolderIndex = Pics.IndexOf(fileInfo.FullName);

Expand Down
5 changes: 5 additions & 0 deletions PicView/ChangeImage/UpdateImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
{
ConfigureWindows.GetMainWindow.MainImage.Source = preLoadValue.BitmapSource;
}

if (GetSpinWaiter is {IsVisible: true})
{
GetSpinWaiter.Visibility = Visibility.Collapsed;
}
}, DispatcherPriority.Send);

var titleString = TitleString(preLoadValue.BitmapSource.PixelWidth, preLoadValue.BitmapSource.PixelHeight,
Expand Down
6 changes: 6 additions & 0 deletions PicView/UILogic/Loading/LoadControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,10 @@ internal static void LoadQuickResize()
Trace.WriteLine(nameof(GetQuickResize) + " loaded ");
#endif
}

internal static void LoadSpinWaiter()
{
GetSpinWaiter = new SpinWaiter();
ConfigureWindows.GetMainWindow.ParentContainer.Children.Add(GetSpinWaiter);
}
}
2 changes: 1 addition & 1 deletion PicView/UILogic/Loading/StartLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ internal static void AddUiElementsAndUpdateValues()
LoadImageSettingsMenu();
LoadQuickSettingsMenu();
LoadToolsAndEffectsMenu();
LoadAutoScrollSign();
LoadTooltipStyle();
LoadSpinWaiter();

// Initialize things!
InitializeZoom();
Expand Down
5 changes: 5 additions & 0 deletions PicView/UILogic/TransformImage/Scroll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using PicView.UILogic.Loading;
using static PicView.UILogic.Sizing.ScaleImage;
using static PicView.UILogic.Tooltip;
using static PicView.UILogic.UC;
Expand Down Expand Up @@ -67,6 +68,10 @@ internal static void ShowAutoScrollSign()
{
return;
}
if (GetAutoScrollSign is null)
{
LoadControls.LoadAutoScrollSign();
}
Canvas.SetTop(GetAutoScrollSign, AutoScrollOrigin.Value.Y);
Canvas.SetLeft(GetAutoScrollSign, AutoScrollOrigin.Value.X);
GetAutoScrollSign.Visibility = Visibility.Visible;
Expand Down
1 change: 1 addition & 0 deletions PicView/UILogic/UC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal static class UC
internal static ColorPicker? GetColorPicker { get; set; }
internal static GripButton? GetGripButton { get; set; }
internal static QuickResize? GetQuickResize { get; set; }
internal static SpinWaiter? GetSpinWaiter { get; set; }

private static bool _imageSettingsMenuOpen;
private static bool _fileMenuOpen;
Expand Down

0 comments on commit e90ad65

Please sign in to comment.