Browse Source

Improved Splash and Grid Refresh Animations

Frank van den Bos 2 years ago
parent
commit
2b473c6698

+ 19 - 30
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -16,6 +16,7 @@ using System.Windows.Controls;
 using System.Windows.Data;
 using System.Windows.Input;
 using System.Windows.Media;
+using System.Windows.Media.Animation;
 using System.Windows.Media.Imaging;
 using System.Windows.Threading;
 using InABox.Clients;
@@ -350,7 +351,9 @@ namespace InABox.DynamicGrid
 
         private readonly Grid Layout;
         private readonly Label Loading;
-
+        
+        private DoubleAnimation LoadingFader = new DoubleAnimation(1d, 0.2d, new Duration(TimeSpan.FromSeconds(2))) { AutoReverse = true };
+        
         protected Dictionary<string, CoreTable> Lookups = new();
         //private readonly Button MultiEdit;
         private readonly Button Paste;
@@ -495,8 +498,15 @@ namespace InABox.DynamicGrid
             Loading.SetValue(Panel.ZIndexProperty, 999);
             Loading.SetValue(Grid.RowProperty, 1);
             Loading.FontSize = 14.0F;
-            Loading.Tag = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(50) };
-
+            LoadingFader.Completed += (sender, args) =>
+            {
+                if (Loading.Visibility == Visibility.Visible)
+                {
+                    Logger.Send(LogType.Information, this.GetType().EntityName().Split(".").Last(), "Loading Fader Restarting");
+                    Loading.BeginAnimation(Label.OpacityProperty, LoadingFader);
+                }
+            };
+            
             Help = CreateButton(Wpf.Resources.help.AsBitmapImage(Color.White));
             Help.Margin = new Thickness(0, 2, 2, 0);
             Help.SetValue(DockPanel.DockProperty, Dock.Right);
@@ -1897,31 +1907,8 @@ namespace InABox.DynamicGrid
             var cursor = UseWaitCursor ? new WaitCursor() : null;
 
             Loading.Visibility = Visibility.Visible;
-            double opacity = 1.0F;
-            var bFading = true;
-            var timer = (DispatcherTimer)Loading.Tag;
-            Loading.Tag = timer;
-            timer.Tick += (o, e) =>
-            {
-                if (bFading)
-                    opacity -= 0.05F;
-                else
-                    opacity += 0.05F;
-                if (opacity >= 1.0F)
-                {
-                    opacity = 1.0F;
-                    bFading = true;
-                }
-                else if (opacity <= 0.2F)
-                {
-                    opacity = 0.2F;
-                    bFading = false;
-                }
-
-                Loading.Opacity = opacity;
-            };
-            timer.IsEnabled = true;
-
+            Loading.BeginAnimation(Label.OpacityProperty, LoadingFader);
+            
             bRefreshing = true;
 
             // Yo, please don't remove this.
@@ -1981,6 +1968,9 @@ namespace InABox.DynamicGrid
                 {
                     ProcessData(reloadcolumns, reloaddata);
                     DoAfterReload();
+                    
+                    Loading.BeginAnimation(Label.OpacityProperty, null);
+                    Loading.Visibility = Visibility.Collapsed;
                 }
             }
 
@@ -2156,9 +2146,8 @@ namespace InABox.DynamicGrid
 
             UpdateRecordCount();
 
+            Loading.BeginAnimation(Label.OpacityProperty, null);
             Loading.Visibility = Visibility.Collapsed;
-            var timer = (DispatcherTimer)Loading.Tag;
-            timer.IsEnabled = false;
         }
 
         private void UpdateRecordCount()

+ 1 - 2
inabox.wpf/ProgressWindow/ProgressForm.xaml

@@ -20,9 +20,8 @@
                 <RowDefinition Height="*" />
                 <RowDefinition Height="Auto" />
             </Grid.RowDefinitions>
-            <Image x:Name="Splash" Margin="20,10,20,10" Stretch="Uniform" Source="../Resources/splash.png" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
+            <Image x:Name="Splash" Margin="20,10,20,10" Stretch="Uniform" Source="../Resources/splash.png" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
             
-
             <Label
                 Grid.Row="1"
                 FontSize="14"

+ 3 - 5
inabox.wpf/ProgressWindow/ProgressForm.xaml.cs

@@ -14,8 +14,7 @@ namespace InABox.WPF
     {
         private ImageSource? _image = null;
 
-        private DoubleAnimation _fadein = new DoubleAnimation(1d, new Duration(TimeSpan.FromSeconds(3)));
-        private DoubleAnimation _fadeout = new DoubleAnimation(0.2d, new Duration(TimeSpan.FromSeconds(3)));
+        private DoubleAnimation _fader = new DoubleAnimation(1d, 0.1d, new Duration(TimeSpan.FromSeconds(2))) { AutoReverse = true };
 
         public ProgressForm()
         {
@@ -23,9 +22,8 @@ namespace InABox.WPF
             Topmost = true;
             Loaded += (sender, args) =>
             {
-                _fadeout.Completed += (o, e) => Splash.BeginAnimation(Image.OpacityProperty, _fadein);
-                _fadein.Completed += (o, e) => Splash.BeginAnimation(Image.OpacityProperty, _fadeout);
-                Splash.BeginAnimation(Image.OpacityProperty, _fadeout);
+                _fader.Completed += (o, e) => Splash.BeginAnimation(Image.OpacityProperty, _fader);
+                Splash.BeginAnimation(Image.OpacityProperty, _fader);
             };
         }