Skip to content

Commit

Permalink
Show loading window on different thread and changed it's design
Browse files Browse the repository at this point in the history
  • Loading branch information
CPKreu committed Jul 27, 2023
1 parent 01f0230 commit 0a01840
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/PixiEditor/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ protected override void OnStartup(StartupEventArgs e)
}
#endif

LoadingWindow loadingWindow = new();
loadingWindow.Show();
LoadingWindow.ShowInNewThread();

AddNativeAssets();

Expand All @@ -66,11 +65,11 @@ protected override void OnStartup(StartupEventArgs e)
extensionLoader.LoadExtensions();

MainWindow = new MainWindow(extensionLoader);
MainWindow.ContentRendered += (sender, args) =>
MainWindow.ContentRendered += (_, _) =>
{
loadingWindow.Close();
LoadingWindow.Instance.SafeClose();
MainWindow.Activate();
};

MainWindow.Show();
}

Expand Down
25 changes: 17 additions & 8 deletions src/PixiEditor/Views/LoadingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@
xmlns:gif="http://wpfanimatedgif.codeplex.com"
mc:Ignorable="d" ShowInTaskbar="False" WindowStyle="None"
ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
Title="LoadingWindow" Height="200" Width="200">
<Grid Background="{StaticResource MainColor}">
<Image
gif:ImageBehavior.AnimatedSource="/Images/Processing.gif"
HorizontalAlignment="Center" VerticalAlignment="Center"
Height="50"
gif:ImageBehavior.AnimationSpeedRatio="1.5"/>
</Grid>
Title="LoadingWindow" Height="180" Width="160"
Background="Transparent"
AllowsTransparency="True"
x:Name="Window">
<Border Background="{StaticResource AccentColor}"
BorderBrush="{StaticResource MainColor}" BorderThickness="1.5"
CornerRadius="10">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Image
gif:ImageBehavior.AnimatedSource="{Binding LoadingImage, ElementName=Window}"
Height="70"
gif:ImageBehavior.AnimationSpeedRatio="1.5"/>
<TextBlock Foreground="White" Text="PixiEditor"
FontFamily="Roboto" FontWeight="900" FontSize="28"
Margin="0,10,0,0"/>
</StackPanel>
</Border>
</Window>
31 changes: 31 additions & 0 deletions src/PixiEditor/Views/LoadingWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;

namespace PixiEditor.Views;

public partial class LoadingWindow : Window
{
public static LoadingWindow Instance { get; private set; }

public ImageSource LoadingImage { get; } = new BitmapImage(new Uri("pack://application:,,,/images/processing.gif"));

public LoadingWindow()
{
InitializeComponent();
}

public static void ShowInNewThread()
{
var thread = new Thread(ThreadStart) { IsBackground = true };

thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}

public void SafeClose()
{
Dispatcher.Invoke(Close);
}

private static void ThreadStart()
{
Instance = new LoadingWindow();
Instance.Show();

Instance.Closed += (_, _) =>
Instance.Dispatcher.InvokeShutdown();

Dispatcher.Run();
}
}

1 change: 0 additions & 1 deletion src/PixiEditor/Views/UserControls/SteamOverlay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public SteamOverlay()
}

private void CreateFadeTimer()

{
StopFadeTimer();
_fadeTimer = new DispatcherTimer(DispatcherPriority.Render) { Interval = TimeSpan.FromSeconds(1f) };
Expand Down

0 comments on commit 0a01840

Please sign in to comment.