Skip to content

Commit

Permalink
Fix starting up in fullscreen mode and refactor window logic and wind…
Browse files Browse the repository at this point in the history
…ow resizing
  • Loading branch information
Ruben2776 committed Oct 17, 2024
1 parent f5090ea commit cd9ce51
Show file tree
Hide file tree
Showing 23 changed files with 522 additions and 453 deletions.
1 change: 1 addition & 0 deletions src/PicView.Avalonia.Win32/Views/AboutWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
Foreground="{DynamicResource MainTextColor}"
Height="28"
LineHeight="28"
Padding="30,0,0,0"
Text="{CompiledBinding About}"
TextAlignment="Center"
x:Name="TitleText" />
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Avalonia.Win32/Views/KeybindingsWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
Classes="txt"
Foreground="{DynamicResource MainTextColor}"
LineHeight="28"
Padding="30,0,0,0"
Text="{CompiledBinding ApplicationShortcuts}"
TextAlignment="Center"
x:Name="TitleText" />
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Avalonia.Win32/Views/SettingsWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
Classes="txt"
Foreground="{DynamicResource MainTextColor}"
LineHeight="28"
Padding="30,0,0,0"
Text="{CompiledBinding Settings,
Mode=OneWay}"
TextAlignment="Center"
Expand Down
31 changes: 6 additions & 25 deletions src/PicView.Avalonia.Win32/Views/WinMainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Avalonia.Controls.ApplicationLifetimes;
using PicView.Avalonia.UI;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Config;
using ReactiveUI;

namespace PicView.Avalonia.Win32.Views;

Expand All @@ -23,31 +23,12 @@ public WinMainWindow()
// Keep window position when resizing
ClientSizeProperty.Changed.Subscribe(size =>
{
WindowHelper.HandleWindowResize(this, size);
});

this.WhenAnyValue(x => x.WindowState).Subscribe(state =>
{
switch (state)
{
case WindowState.Normal:
SettingsHelper.Settings.WindowProperties.Maximized = false;
SettingsHelper.Settings.WindowProperties.Fullscreen = false;
break;
case WindowState.Minimized:
break;
case WindowState.Maximized:
WindowHelper.Maximize();
break;
case WindowState.FullScreen:
//WindowHelper.Fullscreen(DataContext as MainViewModel, Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime);
break;
}
WindowResizing.HandleWindowResize(this, size);
});
ScalingChanged += (_, _) =>
{
ScreenHelper.UpdateScreenSize(this);
WindowHelper.SetSize(DataContext as MainViewModel);
WindowResizing.SetSize(DataContext as MainViewModel);
};
PointerExited += (_, _) =>
{
Expand All @@ -61,14 +42,14 @@ public WinMainWindow()

desktop.ShutdownRequested += async (_, e) =>
{
await WindowHelper.WindowClosingBehavior(this);
await WindowFunctions.WindowClosingBehavior(this);
};
}

protected override async void OnClosing(WindowClosingEventArgs e)
{
e.Cancel = true;
await WindowHelper.WindowClosingBehavior(this);
await WindowFunctions.WindowClosingBehavior(this);
base.OnClosing(e);
}

Expand All @@ -89,6 +70,6 @@ private void Control_OnSizeChanged(object? sender, SizeChangedEventArgs e)
return;
}
var wm = (MainViewModel)DataContext;
WindowHelper.SetSize(wm);
WindowResizing.SetSize(wm);
}
}
3 changes: 2 additions & 1 deletion src/PicView.Avalonia.Win32/Views/WinTitleBar.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Media;
using PicView.Avalonia.UI;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Config;

namespace PicView.Avalonia.Win32.Views;
Expand Down Expand Up @@ -98,6 +99,6 @@ private void MoveWindow(PointerPressedEventArgs e)
{
return;
}
WindowHelper.WindowDragAndDoubleClickBehavior((Window)VisualRoot, e);
WindowFunctions.WindowDragAndDoubleClickBehavior((Window)VisualRoot, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using PicView.Avalonia.Gallery;
using PicView.Avalonia.UI;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Config;
using PicView.Core.Gallery;
using ReactiveUI;
Expand Down Expand Up @@ -174,7 +175,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
{
IsVisible = true;
Opacity = 1;
WindowHelper.SetSize(vm);
WindowResizing.SetSize(vm);
UIHelper.GetGalleryView.BlurMask.BlurEnabled = false;
vm.GalleryItemMargin = new Thickness(2,0);
});
Expand Down Expand Up @@ -208,7 +209,7 @@ private async Task BottomToClosedAnimation()
}
await Dispatcher.UIThread.InvokeAsync(() =>
{
WindowHelper.SetSize(vm);
WindowResizing.SetSize(vm);
UIHelper.GetGalleryView.BlurMask.BlurEnabled = false;
});

Expand All @@ -225,7 +226,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
{
Height = to;
IsVisible = false;
WindowHelper.SetSize(vm);
WindowResizing.SetSize(vm);
});
_isAnimating = false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/PicView.Avalonia/Navigation/NavigationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using PicView.Avalonia.Keybindings;
using PicView.Avalonia.UI;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.ArchiveHandling;
using PicView.Core.Config;
using PicView.Core.Gallery;
Expand Down Expand Up @@ -507,7 +508,7 @@ private static async Task PreviewPicAndLoadGallery(FileInfo fileInfo, MainViewMo
vm.ImageType = imageModel.ImageType;
await Dispatcher.UIThread.InvokeAsync(() =>
{
WindowHelper.SetSize(imageModel.PixelWidth, imageModel.PixelHeight, 0,0, imageModel.Rotation, vm);
WindowResizing.SetSize(imageModel.PixelWidth, imageModel.PixelHeight, 0,0, imageModel.Rotation, vm);
});

if (files is null)
Expand Down
5 changes: 3 additions & 2 deletions src/PicView.Avalonia/Navigation/QuickLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using PicView.Avalonia.ImageHandling;
using PicView.Avalonia.UI;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Config;
using PicView.Core.FileHandling;
using PicView.Core.Gallery;
Expand Down Expand Up @@ -46,10 +47,10 @@ public static async Task QuickLoadAsync(MainViewModel vm, string file)
await Dispatcher.UIThread.InvokeAsync(() =>
{
vm.ImageViewer.SetTransform(imageModel.EXIFOrientation);
WindowHelper.SetSize(imageModel.PixelWidth, imageModel.PixelHeight, secondaryPreloadValue?.ImageModel?.PixelWidth ?? 0, secondaryPreloadValue?.ImageModel?.PixelHeight ?? 0, imageModel.Rotation, vm);
WindowResizing.SetSize(imageModel.PixelWidth, imageModel.PixelHeight, secondaryPreloadValue?.ImageModel?.PixelWidth ?? 0, secondaryPreloadValue?.ImageModel?.PixelHeight ?? 0, imageModel.Rotation, vm);
if (SettingsHelper.Settings.WindowProperties.AutoFit)
{
WindowHelper.CenterWindowOnScreen();
WindowFunctions.CenterWindowOnScreen();
}
}, DispatcherPriority.Send);

Expand Down
7 changes: 4 additions & 3 deletions src/PicView.Avalonia/Navigation/Slideshow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using PicView.Avalonia.Keybindings;
using PicView.Avalonia.UI;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Config;
using PicView.Core.Navigation;
using Timer = System.Timers.Timer;
Expand Down Expand Up @@ -43,10 +44,10 @@ public static void StopSlideshow(MainViewModel vm)

if (!SettingsHelper.Settings.WindowProperties.Fullscreen)
{
WindowHelper.Restore(vm, Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime);
WindowFunctions.Restore(vm, Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime);
if (SettingsHelper.Settings.WindowProperties.AutoFit)
{
WindowHelper.CenterWindowOnScreen();
WindowFunctions.CenterWindowOnScreen();
}
}

Expand Down Expand Up @@ -100,7 +101,7 @@ private static async Task Start(MainViewModel vm, double seconds)

if (!SettingsHelper.Settings.WindowProperties.Fullscreen)
{
await WindowHelper.ToggleFullscreen(vm, false);
await WindowFunctions.ToggleFullscreen(vm, false);
}

await vm.ImageIterator.NextIteration(NavigateTo.Next);
Expand Down
7 changes: 4 additions & 3 deletions src/PicView.Avalonia/Navigation/UpdateImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using PicView.Avalonia.ImageHandling;
using PicView.Avalonia.UI;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Config;
using PicView.Core.Gallery;
using PicView.Core.Navigation;
Expand Down Expand Up @@ -56,7 +57,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
vm.ImageType = preLoadValue.ImageModel.ImageType;
WindowHelper.SetSize(preLoadValue.ImageModel.PixelWidth, preLoadValue.ImageModel.PixelHeight,
WindowResizing.SetSize(preLoadValue.ImageModel.PixelWidth, preLoadValue.ImageModel.PixelHeight,
nextPreloadValue?.ImageModel?.PixelWidth ?? 0, nextPreloadValue?.ImageModel?.PixelHeight ?? 0,
preLoadValue.ImageModel.Rotation, vm);
Expand All @@ -68,7 +69,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>

if (SettingsHelper.Settings.WindowProperties.KeepCentered)
{
await Dispatcher.UIThread.InvokeAsync(() => { WindowHelper.CenterWindowOnScreen(); });
await Dispatcher.UIThread.InvokeAsync(() => { WindowFunctions.CenterWindowOnScreen(); });
}

if (vm.SelectedGalleryItemIndex != index)
Expand Down Expand Up @@ -139,7 +140,7 @@ public static void SetSingleImage(object source, ImageType imageType, string nam

Dispatcher.UIThread.Invoke(() =>
{
WindowHelper.SetSize(width, height, 0, 0, 0, vm);
WindowResizing.SetSize(width, height, 0, 0, 0, vm);
});

if (vm.RotationAngle != 0)
Expand Down
33 changes: 23 additions & 10 deletions src/PicView.Avalonia/UI/FunctionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using PicView.Avalonia.ImageTransformations;
using PicView.Avalonia.Navigation;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Config;
using PicView.Core.FileHandling;
using PicView.Core.ImageDecoding;
Expand Down Expand Up @@ -66,6 +67,7 @@ public static Task<Func<Task>> GetFunctionByName(string functionName)

// Window functions
"Fullscreen" => Fullscreen,
"ToggleFullscreen" => ToggleFullscreen,
"SetTopMost" => SetTopMost,
"Close" => Close,
"ToggleInterface" => ToggleInterface,
Expand Down Expand Up @@ -426,7 +428,7 @@ public static async Task Close()

if (SettingsHelper.Settings.WindowProperties.Fullscreen)
{
await WindowHelper.MaximizeRestore();
await WindowFunctions.MaximizeRestore();
return;
}
if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
Expand Down Expand Up @@ -457,7 +459,7 @@ public static async Task Center()
// TODO: scroll to center when the gallery is open
await Dispatcher.UIThread.InvokeAsync(() =>
{
WindowHelper.CenterWindowOnScreen();
WindowFunctions.CenterWindowOnScreen();
});
}

Expand Down Expand Up @@ -508,36 +510,47 @@ public static Task SettingsWindow()

public static async Task Stretch()
{
await WindowHelper.Stretch(Vm);
await WindowFunctions.Stretch(Vm);
}
public static async Task AutoFitWindow()
{
await WindowHelper.ToggleAutoFit(Vm);
await WindowFunctions.ToggleAutoFit(Vm);
}

public static async Task AutoFitWindowAndStretch()
{
await WindowHelper.AutoFitAndStretch(Vm);
await WindowFunctions.AutoFitAndStretch(Vm);
}

public static async Task NormalWindow()
{
await WindowHelper.NormalWindow(Vm);
await WindowFunctions.NormalWindow(Vm);
}

public static async Task NormalWindowAndStretch()
{
await WindowHelper.NormalWindowStretch(Vm);
await WindowFunctions.NormalWindowStretch(Vm);
}

public static async Task Fullscreen()
public static async Task ToggleFullscreen()
{
if (Vm is null)
{
return;
}

await WindowHelper.ToggleFullscreen(Vm);
await WindowFunctions.ToggleFullscreen(Vm);
}

public static Task Fullscreen()
{
if (Vm is null)
{
return Task.CompletedTask;
}

WindowFunctions.Fullscreen(Vm, Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime);
return Task.CompletedTask;
}

public static async Task SetTopMost()
Expand All @@ -547,7 +560,7 @@ public static async Task SetTopMost()
return;
}

await WindowHelper.ToggleTopMost(Vm);
await WindowFunctions.ToggleTopMost(Vm);
}

#endregion
Expand Down
5 changes: 3 additions & 2 deletions src/PicView.Avalonia/UI/HideInterfaceLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using PicView.Avalonia.Gallery;
using PicView.Avalonia.Navigation;
using PicView.Avalonia.ViewModels;
using PicView.Avalonia.WindowBehavior;
using PicView.Core.Calculations;
using PicView.Core.Config;
using PicView.Core.Gallery;
Expand Down Expand Up @@ -85,7 +86,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
}
}

WindowHelper.SetSize(vm);
WindowResizing.SetSize(vm);
UIHelper.CloseMenus(vm);
await SettingsHelper.SaveSettingsAsync();
}
Expand All @@ -111,7 +112,7 @@ public static async Task ToggleBottomToolbar(MainViewModel vm)
}
await Dispatcher.UIThread.InvokeAsync(() =>
{
WindowHelper.SetSize(vm);
WindowResizing.SetSize(vm);
});

await SettingsHelper.SaveSettingsAsync();
Expand Down
Loading

0 comments on commit cd9ce51

Please sign in to comment.