mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-29 08:41:12 +13:00
Re-add rotating loading icon
This commit is contained in:
parent
3b28cc168b
commit
384e2e1d74
4 changed files with 25 additions and 89 deletions
|
@ -6,7 +6,6 @@ namespace SystemTrayMenu.Helper
|
|||
{
|
||||
using System;
|
||||
using System.Windows.Threading;
|
||||
using SystemTrayMenu.Utilities;
|
||||
|
||||
public class Fading : IDisposable
|
||||
{
|
||||
|
|
|
@ -113,35 +113,5 @@ namespace SystemTrayMenu.Helper
|
|||
using FileStream outputStream = new(outputPath, FileMode.OpenOrCreate);
|
||||
return ConvertToIcon(inputStream, outputStream, size, preserveAspectRatio);
|
||||
}
|
||||
|
||||
public static Image RotateImage(Image img, float rotationAngle)
|
||||
{
|
||||
// create an empty Bitmap image
|
||||
Bitmap bmp = new(img.Width, img.Height);
|
||||
|
||||
// turn the Bitmap into a Graphics object
|
||||
Graphics gfx = Graphics.FromImage(bmp);
|
||||
|
||||
// now we set the rotation point to the center of our image
|
||||
gfx.TranslateTransform(0.5f + ((float)bmp.Width / 2), 0.5f + ((float)bmp.Height / 2));
|
||||
|
||||
// now rotate the image
|
||||
gfx.RotateTransform(rotationAngle);
|
||||
|
||||
gfx.TranslateTransform(0.5f - ((float)bmp.Width / 2), 0.5f - ((float)bmp.Height / 2));
|
||||
|
||||
// set the InterpolationMode to HighQualityBicubic so to ensure a high
|
||||
// quality image once it is transformed to the specified size
|
||||
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
|
||||
// now draw our new image onto the graphics object
|
||||
gfx.DrawImage(img, new Point(0, 0));
|
||||
|
||||
// dispose of our Graphics object
|
||||
gfx.Dispose();
|
||||
|
||||
// return the image
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,6 +107,25 @@
|
|||
|
||||
<DockPanel x:Name="tableLayoutPanelBottom" DockPanel.Dock="Bottom" Margin="12,4">
|
||||
<Label x:Name="labelItems" Content="0 items" Padding="0" DockPanel.Dock="Left" FontWeight="Bold" VerticalAlignment="Center" Margin="0,0,10,0"/>
|
||||
|
||||
<Image x:Name="pictureBoxLoading" Width="18" Height="18" DockPanel.Dock="Right"
|
||||
HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" d:Visibility="Visible" Visibility="Collapsed">
|
||||
<Image.RenderTransform>
|
||||
<RotateTransform x:Name="LoadingRotation" Angle="0" />
|
||||
</Image.RenderTransform>
|
||||
<Image.Triggers>
|
||||
<EventTrigger RoutedEvent="Loaded">
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation
|
||||
Storyboard.TargetName="LoadingRotation"
|
||||
Storyboard.TargetProperty="(RotateTransform.Angle)"
|
||||
From="0.0" To="360.0" Duration="0:0:1" RepeatBehavior="Forever" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</Image.Triggers>
|
||||
</Image>
|
||||
<Button x:Name="buttonRestart" Width="18" Height="18" Padding="0" DockPanel.Dock="Right" HorizontalAlignment="Right" BorderBrush="{x:Null}" Background="{x:Null}" Click="PictureBoxRestart_MouseClick" >
|
||||
<Image x:Name="pictureBoxRestart" Source="{StaticResource ic_fluent_arrow_sync_24_regularDrawingImage}"/>
|
||||
</Button>
|
||||
|
|
|
@ -8,29 +8,20 @@ namespace SystemTrayMenu.UserInterface
|
|||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using SystemTrayMenu.DataClasses;
|
||||
using SystemTrayMenu.DllImports;
|
||||
using SystemTrayMenu.Helper;
|
||||
using SystemTrayMenu.Utilities;
|
||||
using Windows.UI.Composition;
|
||||
using Color = System.Drawing.Color;
|
||||
using Image = System.Windows.Controls.Image;
|
||||
using Point = System.Drawing.Point;
|
||||
|
||||
/// <summary>
|
||||
|
@ -46,9 +37,6 @@ namespace SystemTrayMenu.UserInterface
|
|||
private readonly Fading fading = new();
|
||||
private bool isShowing;
|
||||
private bool directionToRight;
|
||||
#if TODO
|
||||
private int rotationAngle;
|
||||
#endif
|
||||
private bool mouseDown;
|
||||
private Point lastLocation;
|
||||
#if TODO
|
||||
|
@ -119,35 +107,6 @@ namespace SystemTrayMenu.UserInterface
|
|||
|
||||
txtTitle.Text = myname;
|
||||
|
||||
#if TODO
|
||||
foreach (KeyValuePair<Image, string> pair in
|
||||
new List<KeyValuePair<Image, string>>()
|
||||
{
|
||||
new KeyValuePair<Image, string>(pictureBoxSearch, myname + ".Resources.SystemTrayMenu.png"),
|
||||
new KeyValuePair<Image, string>(pictureBoxOpenFolder, myname + ".Resources.SystemTrayMenu.png"),
|
||||
new KeyValuePair<Image, string>(pictureBoxMenuAlwaysOpen, myname + ".Resources.SystemTrayMenu.png"),
|
||||
new KeyValuePair<Image, string>(pictureBoxSettings, myname + ".Resources.SystemTrayMenu.png"),
|
||||
new KeyValuePair<Image, string>(pictureBoxRestart, myname + ".Resources.SystemTrayMenu.png"),
|
||||
})
|
||||
{
|
||||
Image control = pair.Key;
|
||||
using (Stream? imgstream = myassembly.GetManifestResourceStream(pair.Value))
|
||||
{
|
||||
if (imgstream != null)
|
||||
{
|
||||
BitmapImage imageSource = new BitmapImage();
|
||||
imageSource.BeginInit();
|
||||
imageSource.StreamSource = imgstream;
|
||||
imageSource.EndInit();
|
||||
|
||||
control.Source = imageSource;
|
||||
}
|
||||
}
|
||||
|
||||
control.Width = Scaling.Scale(control.Width);
|
||||
control.Height = Scaling.Scale(control.Height);
|
||||
}
|
||||
#else
|
||||
foreach (FrameworkElement control in
|
||||
new List<FrameworkElement>()
|
||||
{
|
||||
|
@ -160,12 +119,12 @@ namespace SystemTrayMenu.UserInterface
|
|||
pictureBoxOpenFolder,
|
||||
pictureBoxSettings,
|
||||
pictureBoxRestart,
|
||||
pictureBoxLoading,
|
||||
})
|
||||
{
|
||||
control.Width = Scaling.Scale(control.Width);
|
||||
control.Height = Scaling.Scale(control.Height);
|
||||
}
|
||||
#endif
|
||||
|
||||
labelTitle.FontSize = Scaling.ScaleFontByPoints(8.25F);
|
||||
textBoxSearch.FontSize = Scaling.ScaleFontByPoints(8.25F);
|
||||
|
@ -475,13 +434,11 @@ namespace SystemTrayMenu.UserInterface
|
|||
labelItems.Content = Translator.GetText("loading");
|
||||
buttonMenuAlwaysOpen.Visibility = Visibility.Visible;
|
||||
buttonOpenFolder.Visibility = Visibility.Collapsed;
|
||||
#if TODO
|
||||
pictureBoxMenuAlwaysOpen.Paint -= PictureBoxMenuAlwaysOpen_Paint;
|
||||
pictureBoxMenuAlwaysOpen.Paint += LoadingMenu_Paint;
|
||||
timerUpdateIcons.Tick -= TimerUpdateIcons_Tick;
|
||||
timerUpdateIcons.Tick += (sender, e) => pictureBoxMenuAlwaysOpen.Invalidate();
|
||||
timerUpdateIcons.Interval = 15;
|
||||
#endif
|
||||
|
||||
// Todo: use embedded resources that we can assign image in XAML already
|
||||
pictureBoxLoading.Source = (ImageSource)new IconToImageSourceConverter().Convert(
|
||||
SystemTrayMenu.Resources.StaticResources.LoadingIcon, typeof(ImageSource), null, CultureInfo.InvariantCulture);
|
||||
pictureBoxLoading.Visibility = Visibility.Visible;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1312,15 +1269,6 @@ namespace SystemTrayMenu.UserInterface
|
|||
PictureBox pictureBox = (PictureBox)sender;
|
||||
e.Graphics.DrawImage(AppColors.BitmapSearch, new Rectangle(Point.Empty, pictureBox.ClientSize));
|
||||
}
|
||||
|
||||
private void LoadingMenu_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
PictureBox pictureBox = (PictureBox)sender;
|
||||
rotationAngle += 5;
|
||||
e.Graphics.DrawImage(
|
||||
ImagingHelper.RotateImage(Resources.StaticResources.LoadingIcon.ToBitmap(), rotationAngle),
|
||||
new Rectangle(Point.Empty, new Size(pictureBox.ClientSize.Width - 2, pictureBox.ClientSize.Height - 2)));
|
||||
}
|
||||
#endif
|
||||
private void TimerUpdateIcons_Tick(object? sender, EventArgs e)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue