Skip to content

Commit

Permalink
Fixed scaling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDotH committed Mar 28, 2023
1 parent 8d98832 commit 192fec3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion OpenLyricsClient/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void OnFrameworkInitializationCompleted()
desktop.Startup += Startup;
desktop.Exit += Exit;

//manager.SetScaling(1);
manager.OnlyScaleOnStartup = true;
manager.SetScaling(WindowUtils.GetScalingFactor());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Reactive;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using OpenLyricsClient.Frontend.Scaling;
using ReactiveUI;
using IViewModel = OpenLyricsClient.Frontend.Scaling.IViewModel;

Expand Down Expand Up @@ -74,11 +76,14 @@ private void FullButtonAction()
this._prevWidth = desktop.MainWindow.Width;
this._prevHeight = desktop.MainWindow.Height;
desktop.MainWindow.WindowState = WindowState.FullScreen;

this._isFullScreen = true;
}
else
{

desktop.MainWindow.WindowState = WindowState.Normal;

desktop.MainWindow.Width = this._prevWidth;
desktop.MainWindow.Height = this._prevHeight;
this._isFullScreen = false;
Expand Down
24 changes: 24 additions & 0 deletions OpenLyricsClient/Frontend/Scaling/ScalingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace OpenLyricsClient.Frontend.Scaling;
/// </summary>
public class ScalingManager
{
private static ScalingManager _instance;

private const double minimumScaling = 0.2d;

private double previousScaling = 1d;
Expand Down Expand Up @@ -54,6 +56,7 @@ public class ScalingManager
/// <param name="viewModel">The <see cref="IViewModel"/> implemented by the view model belonging to the <paramref name="window"/>.</param>
public ScalingManager(ScalableWindow window, IViewModel viewModel)
{
_instance = this;
this.viewModel = viewModel;
this.window = window;
ScalableMainWindow = new ScalableObject(window);
Expand Down Expand Up @@ -100,6 +103,7 @@ public ScalingManager(ScalableWindow window, IViewModel viewModel)
private double windowScalingFactor = 1d;
private Point mouseDownPosition = default;
private bool windowNeedsRefresh = false;
private bool onlyScaleOnStartup = false;

private void Window_EndResize(object? sender, PointerReleasedEventArgs e)
{
Expand Down Expand Up @@ -149,6 +153,9 @@ private void Window_PositionChanged(object? sender, PixelPointEventArgs e)

private void Window_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (onlyScaleOnStartup)
return;

Type propertyType = e.Property.PropertyType;
if (propertyType == typeof(WindowState))
{
Expand Down Expand Up @@ -308,4 +315,21 @@ public static void RegisterControls(Queue<IEnumerable<ILogical>> logicals, Bindi
}
}
}

public bool OnlyScaleOnStartup
{
get => onlyScaleOnStartup;
set => onlyScaleOnStartup = value;
}

public bool WindowNeedsRefresh
{
get => windowNeedsRefresh;
set => windowNeedsRefresh = value;
}

public static ScalingManager Instance
{
get => _instance;
}
}
4 changes: 2 additions & 2 deletions OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ private void DataContextOnPropertyChanged(object? sender, PropertyChangedEventAr
if (e.PropertyName.IsNullOrEmpty())
return;

if (DataValidator.ValidateData(this._lyricsPageViewModel?.Artwork!) &&
!this._lyricsPageViewModel!.Artwork.IsNullOrEmpty() &&
if (DataValidator.ValidateData(this._lyricsPageViewModel.Artwork!) &&
!this._lyricsPageViewModel.Artwork.IsNullOrEmpty() &&
e.PropertyName!.Equals("Artwork") &&
!this._oldImagePath.Equals(this._lyricsPageViewModel.Artwork))
{
Expand Down
1 change: 1 addition & 0 deletions OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ private void InputElement_OnPointerPressed(object? sender, PointerPressedEventAr
public override event EventHandler<PointerPressedEventArgs> BeginResize;
public override event EventHandler<PointerEventArgs> Resize;
public override event EventHandler<PointerReleasedEventArgs> EndResize;

}
}

0 comments on commit 192fec3

Please sign in to comment.