mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-07-05 22:40:41 +12:00
Fix and improve fading and transparency
This commit is contained in:
parent
874f583a3a
commit
40871c7e96
|
@ -444,7 +444,11 @@ namespace SystemTrayMenu.Business
|
||||||
IconReader.IsPreloading = false;
|
IconReader.IsPreloading = false;
|
||||||
if (showMenuAfterMainPreload)
|
if (showMenuAfterMainPreload)
|
||||||
{
|
{
|
||||||
AsEnumerable.ToList().ForEach(m => { m.ShowWithFade(); });
|
Menu? menu = menus[0];
|
||||||
|
if (menu != null)
|
||||||
|
{
|
||||||
|
menu.ShowWithFade();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -579,8 +583,14 @@ namespace SystemTrayMenu.Business
|
||||||
{
|
{
|
||||||
if (IsActive() && IsMainUsable)
|
if (IsActive() && IsMainUsable)
|
||||||
{
|
{
|
||||||
AsList.ForEach(m => m.ShowWithFade());
|
|
||||||
timerStillActiveCheck.Stop();
|
timerStillActiveCheck.Stop();
|
||||||
|
|
||||||
|
// Bring transparent menus back
|
||||||
|
foreach (Menu? menu in menus.Where(m => m != null && m.Opacity != 1D))
|
||||||
|
{
|
||||||
|
menu!.ActivateWithFade();
|
||||||
|
}
|
||||||
|
|
||||||
timerStillActiveCheck.Start();
|
timerStillActiveCheck.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -621,7 +631,7 @@ namespace SystemTrayMenu.Business
|
||||||
{
|
{
|
||||||
HideOldMenu(menu, true);
|
HideOldMenu(menu, true);
|
||||||
menus[menu.Level] = menu;
|
menus[menu.Level] = menu;
|
||||||
menu.ShowWithFadeOrTransparent(IsActive());
|
menu.ShowWithFade(!IsActive());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,12 +927,12 @@ namespace SystemTrayMenu.Business
|
||||||
{
|
{
|
||||||
if (!keyboardInput.InUse)
|
if (!keyboardInput.InUse)
|
||||||
{
|
{
|
||||||
AsList.ForEach(menu => menu.ShowTransparent());
|
AsList.ForEach(menu => menu.ShowWithFade(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Config.AlwaysOpenByPin)
|
else if (Config.AlwaysOpenByPin)
|
||||||
{
|
{
|
||||||
AsList.ForEach(menu => menu.ShowTransparent());
|
AsList.ForEach(menu => menu.ShowWithFade(true));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -949,7 +959,7 @@ namespace SystemTrayMenu.Business
|
||||||
joystickHelper.Disable();
|
joystickHelper.Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetScreenBounds(out Rect screenBounds, out bool useCustomLocation, out Menu.StartLocation startLocation)
|
private void GetScreenBounds(out Rect screenBounds, out bool useCustomLocation, out StartLocation startLocation)
|
||||||
{
|
{
|
||||||
if (Settings.Default.AppearAtMouseLocation)
|
if (Settings.Default.AppearAtMouseLocation)
|
||||||
{
|
{
|
||||||
|
@ -985,33 +995,33 @@ namespace SystemTrayMenu.Business
|
||||||
case TaskbarPosition.Left:
|
case TaskbarPosition.Left:
|
||||||
screenBounds.X += taskbar.Size.Width;
|
screenBounds.X += taskbar.Size.Width;
|
||||||
screenBounds.Width -= taskbar.Size.Width;
|
screenBounds.Width -= taskbar.Size.Width;
|
||||||
startLocation = Menu.StartLocation.BottomLeft;
|
startLocation = StartLocation.BottomLeft;
|
||||||
break;
|
break;
|
||||||
case TaskbarPosition.Right:
|
case TaskbarPosition.Right:
|
||||||
screenBounds.Width -= taskbar.Size.Width;
|
screenBounds.Width -= taskbar.Size.Width;
|
||||||
startLocation = Menu.StartLocation.BottomRight;
|
startLocation = StartLocation.BottomRight;
|
||||||
break;
|
break;
|
||||||
case TaskbarPosition.Top:
|
case TaskbarPosition.Top:
|
||||||
screenBounds.Y += taskbar.Size.Height;
|
screenBounds.Y += taskbar.Size.Height;
|
||||||
screenBounds.Height -= taskbar.Size.Height;
|
screenBounds.Height -= taskbar.Size.Height;
|
||||||
startLocation = Menu.StartLocation.TopRight;
|
startLocation = StartLocation.TopRight;
|
||||||
break;
|
break;
|
||||||
case TaskbarPosition.Bottom:
|
case TaskbarPosition.Bottom:
|
||||||
default:
|
default:
|
||||||
screenBounds.Height -= taskbar.Size.Height;
|
screenBounds.Height -= taskbar.Size.Height;
|
||||||
startLocation = Menu.StartLocation.BottomRight;
|
startLocation = StartLocation.BottomRight;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.Default.AppearAtTheBottomLeft)
|
if (Settings.Default.AppearAtTheBottomLeft)
|
||||||
{
|
{
|
||||||
startLocation = Menu.StartLocation.BottomLeft;
|
startLocation = StartLocation.BottomLeft;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AdjustMenusSizeAndLocation(int startLevel)
|
private void AdjustMenusSizeAndLocation(int startLevel)
|
||||||
{
|
{
|
||||||
GetScreenBounds(out Rect screenBounds, out bool useCustomLocation, out Menu.StartLocation startLocation);
|
GetScreenBounds(out Rect screenBounds, out bool useCustomLocation, out StartLocation startLocation);
|
||||||
|
|
||||||
Menu menu;
|
Menu menu;
|
||||||
Menu? menuPredecessor = null;
|
Menu? menuPredecessor = null;
|
||||||
|
@ -1035,7 +1045,7 @@ namespace SystemTrayMenu.Business
|
||||||
!Settings.Default.UseCustomLocation &&
|
!Settings.Default.UseCustomLocation &&
|
||||||
i == 0)
|
i == 0)
|
||||||
{
|
{
|
||||||
const int overlapTolerance = 4;
|
const double overlapTolerance = 4D;
|
||||||
|
|
||||||
// Remember width of the initial menu as we don't want to overlap with it
|
// Remember width of the initial menu as we don't want to overlap with it
|
||||||
if (taskbarPosition == TaskbarPosition.Left)
|
if (taskbarPosition == TaskbarPosition.Left)
|
||||||
|
|
|
@ -16,12 +16,22 @@
|
||||||
</Window.Effect>
|
</Window.Effect>
|
||||||
|
|
||||||
<Window.Triggers>
|
<Window.Triggers>
|
||||||
|
<EventTrigger RoutedEvent="local:Menu.FadeToTransparent">
|
||||||
|
<BeginStoryboard>
|
||||||
|
<Storyboard>
|
||||||
|
<DoubleAnimation
|
||||||
|
Storyboard.TargetProperty="Opacity"
|
||||||
|
From="{Binding Opacity}" To="0.8" Duration="0:0:0.4"
|
||||||
|
Completed="FadeIn_Completed"/>
|
||||||
|
</Storyboard>
|
||||||
|
</BeginStoryboard>
|
||||||
|
</EventTrigger>
|
||||||
<EventTrigger RoutedEvent="local:Menu.FadeIn">
|
<EventTrigger RoutedEvent="local:Menu.FadeIn">
|
||||||
<BeginStoryboard>
|
<BeginStoryboard>
|
||||||
<Storyboard>
|
<Storyboard>
|
||||||
<DoubleAnimation
|
<DoubleAnimation
|
||||||
Storyboard.TargetProperty="Opacity"
|
Storyboard.TargetProperty="Opacity"
|
||||||
From="0.0" To="1.0" Duration="0:0:0.5"
|
From="{Binding Opacity}" To="1.0" Duration="0:0:0.5"
|
||||||
Completed="FadeIn_Completed"/>
|
Completed="FadeIn_Completed"/>
|
||||||
</Storyboard>
|
</Storyboard>
|
||||||
</BeginStoryboard>
|
</BeginStoryboard>
|
||||||
|
@ -31,7 +41,7 @@
|
||||||
<Storyboard>
|
<Storyboard>
|
||||||
<DoubleAnimation
|
<DoubleAnimation
|
||||||
Storyboard.TargetProperty="Opacity"
|
Storyboard.TargetProperty="Opacity"
|
||||||
From="1.0" To="0.0" Duration="0:0:0.25"
|
From="{Binding Opacity}" To="0.0" Duration="0:0:0.25"
|
||||||
Completed="FadeOut_Completed"/>
|
Completed="FadeOut_Completed"/>
|
||||||
</Storyboard>
|
</Storyboard>
|
||||||
</BeginStoryboard>
|
</BeginStoryboard>
|
||||||
|
|
|
@ -28,6 +28,9 @@ namespace SystemTrayMenu.UserInterface
|
||||||
{
|
{
|
||||||
private const int CornerRadius = 10;
|
private const int CornerRadius = 10;
|
||||||
|
|
||||||
|
private static readonly RoutedEvent FadeToTransparentEvent = EventManager.RegisterRoutedEvent(
|
||||||
|
nameof(FadeToTransparent), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Menu));
|
||||||
|
|
||||||
private static readonly RoutedEvent FadeInEvent = EventManager.RegisterRoutedEvent(
|
private static readonly RoutedEvent FadeInEvent = EventManager.RegisterRoutedEvent(
|
||||||
nameof(FadeIn), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Menu));
|
nameof(FadeIn), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Menu));
|
||||||
|
|
||||||
|
@ -305,6 +308,12 @@ namespace SystemTrayMenu.UserInterface
|
||||||
|
|
||||||
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseClick;
|
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseClick;
|
||||||
|
|
||||||
|
internal event RoutedEventHandler FadeToTransparent
|
||||||
|
{
|
||||||
|
add { AddHandler(FadeToTransparentEvent, value); }
|
||||||
|
remove { RemoveHandler(FadeToTransparentEvent, value); }
|
||||||
|
}
|
||||||
|
|
||||||
internal event RoutedEventHandler FadeIn
|
internal event RoutedEventHandler FadeIn
|
||||||
{
|
{
|
||||||
add { AddHandler(FadeInEvent, value); }
|
add { AddHandler(FadeInEvent, value); }
|
||||||
|
@ -460,31 +469,25 @@ namespace SystemTrayMenu.UserInterface
|
||||||
SetCounts(foldersCount, filesCount);
|
SetCounts(foldersCount, filesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ShowWithFadeOrTransparent(bool formActiveFormIsMenu)
|
internal void ActivateWithFade()
|
||||||
{
|
{
|
||||||
if (formActiveFormIsMenu)
|
if (Settings.Default.UseFading)
|
||||||
{
|
{
|
||||||
ShowWithFade();
|
isFading = true;
|
||||||
|
RaiseEvent(new(routedEvent: FadeInEvent));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ShowTransparent();
|
Opacity = 1D;
|
||||||
|
FadeIn_Completed(this, new());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ShowWithFade() => Fading_Show(false);
|
internal void ShowWithFade(bool transparency = false)
|
||||||
|
|
||||||
internal void ShowTransparent() => Fading_Show(true);
|
|
||||||
|
|
||||||
internal void Fading_Show(bool transparency)
|
|
||||||
{
|
{
|
||||||
timerUpdateIcons.Start();
|
timerUpdateIcons.Start();
|
||||||
|
|
||||||
if (Level == 0)
|
if (Level > 0)
|
||||||
{
|
|
||||||
Activate();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
ShowActivated = false;
|
ShowActivated = false;
|
||||||
}
|
}
|
||||||
|
@ -497,8 +500,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
isFading = true;
|
isFading = true;
|
||||||
if (transparency)
|
if (transparency)
|
||||||
{
|
{
|
||||||
// TODO: FADING: Instead setting of opacity 100% only go up to 80% (Temporarily go to 100% as well)
|
RaiseEvent(new(routedEvent: FadeToTransparentEvent));
|
||||||
RaiseEvent(new(routedEvent: FadeInEvent));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -517,8 +519,6 @@ namespace SystemTrayMenu.UserInterface
|
||||||
if (Settings.Default.UseFading)
|
if (Settings.Default.UseFading)
|
||||||
{
|
{
|
||||||
isFading = true;
|
isFading = true;
|
||||||
|
|
||||||
// TODO: FADING: Instead starting at opacity 100% it should start with 80% due to transparency setting
|
|
||||||
RaiseEvent(new(routedEvent: FadeOutEvent));
|
RaiseEvent(new(routedEvent: FadeOutEvent));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -545,7 +545,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
StartLocation startLocation,
|
StartLocation startLocation,
|
||||||
bool useCustomLocation)
|
bool useCustomLocation)
|
||||||
{
|
{
|
||||||
Point originLocation = new(0.0D, 0.0D);
|
Point originLocation = new(0D, 0D);
|
||||||
|
|
||||||
// Update the height and width
|
// Update the height and width
|
||||||
AdjustDataGridViewHeight(menuPredecessor, bounds.Height);
|
AdjustDataGridViewHeight(menuPredecessor, bounds.Height);
|
||||||
|
@ -599,7 +599,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
void AdjustWindowPositionInternal(in Point originLocation)
|
void AdjustWindowPositionInternal(in Point originLocation)
|
||||||
{
|
{
|
||||||
double scaling = Math.Round(Scaling.Factor, 0, MidpointRounding.AwayFromZero);
|
double scaling = Math.Round(Scaling.Factor, 0, MidpointRounding.AwayFromZero);
|
||||||
double overlappingOffset = 0.0D;
|
double overlappingOffset = 0D;
|
||||||
|
|
||||||
// Make sure we have latest values of own window size
|
// Make sure we have latest values of own window size
|
||||||
UpdateLayout();
|
UpdateLayout();
|
||||||
|
|
Loading…
Reference in a new issue