mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-10-03 10:36:30 +13:00
Fix and improve fading and transparency
This commit is contained in:
parent
874f583a3a
commit
40871c7e96
3 changed files with 55 additions and 35 deletions
|
@ -444,7 +444,11 @@ namespace SystemTrayMenu.Business
|
|||
IconReader.IsPreloading = false;
|
||||
if (showMenuAfterMainPreload)
|
||||
{
|
||||
AsEnumerable.ToList().ForEach(m => { m.ShowWithFade(); });
|
||||
Menu? menu = menus[0];
|
||||
if (menu != null)
|
||||
{
|
||||
menu.ShowWithFade();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -579,8 +583,14 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
if (IsActive() && IsMainUsable)
|
||||
{
|
||||
AsList.ForEach(m => m.ShowWithFade());
|
||||
timerStillActiveCheck.Stop();
|
||||
|
||||
// Bring transparent menus back
|
||||
foreach (Menu? menu in menus.Where(m => m != null && m.Opacity != 1D))
|
||||
{
|
||||
menu!.ActivateWithFade();
|
||||
}
|
||||
|
||||
timerStillActiveCheck.Start();
|
||||
}
|
||||
}
|
||||
|
@ -621,7 +631,7 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
HideOldMenu(menu, true);
|
||||
menus[menu.Level] = menu;
|
||||
menu.ShowWithFadeOrTransparent(IsActive());
|
||||
menu.ShowWithFade(!IsActive());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -917,12 +927,12 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
if (!keyboardInput.InUse)
|
||||
{
|
||||
AsList.ForEach(menu => menu.ShowTransparent());
|
||||
AsList.ForEach(menu => menu.ShowWithFade(true));
|
||||
}
|
||||
}
|
||||
else if (Config.AlwaysOpenByPin)
|
||||
{
|
||||
AsList.ForEach(menu => menu.ShowTransparent());
|
||||
AsList.ForEach(menu => menu.ShowWithFade(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -949,7 +959,7 @@ namespace SystemTrayMenu.Business
|
|||
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)
|
||||
{
|
||||
|
@ -985,33 +995,33 @@ namespace SystemTrayMenu.Business
|
|||
case TaskbarPosition.Left:
|
||||
screenBounds.X += taskbar.Size.Width;
|
||||
screenBounds.Width -= taskbar.Size.Width;
|
||||
startLocation = Menu.StartLocation.BottomLeft;
|
||||
startLocation = StartLocation.BottomLeft;
|
||||
break;
|
||||
case TaskbarPosition.Right:
|
||||
screenBounds.Width -= taskbar.Size.Width;
|
||||
startLocation = Menu.StartLocation.BottomRight;
|
||||
startLocation = StartLocation.BottomRight;
|
||||
break;
|
||||
case TaskbarPosition.Top:
|
||||
screenBounds.Y += taskbar.Size.Height;
|
||||
screenBounds.Height -= taskbar.Size.Height;
|
||||
startLocation = Menu.StartLocation.TopRight;
|
||||
startLocation = StartLocation.TopRight;
|
||||
break;
|
||||
case TaskbarPosition.Bottom:
|
||||
default:
|
||||
screenBounds.Height -= taskbar.Size.Height;
|
||||
startLocation = Menu.StartLocation.BottomRight;
|
||||
startLocation = StartLocation.BottomRight;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Settings.Default.AppearAtTheBottomLeft)
|
||||
{
|
||||
startLocation = Menu.StartLocation.BottomLeft;
|
||||
startLocation = StartLocation.BottomLeft;
|
||||
}
|
||||
}
|
||||
|
||||
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? menuPredecessor = null;
|
||||
|
@ -1035,7 +1045,7 @@ namespace SystemTrayMenu.Business
|
|||
!Settings.Default.UseCustomLocation &&
|
||||
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
|
||||
if (taskbarPosition == TaskbarPosition.Left)
|
||||
|
|
|
@ -16,12 +16,22 @@
|
|||
</Window.Effect>
|
||||
|
||||
<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">
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation
|
||||
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"/>
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
|
@ -31,7 +41,7 @@
|
|||
<Storyboard>
|
||||
<DoubleAnimation
|
||||
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"/>
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
|
|
|
@ -28,6 +28,9 @@ namespace SystemTrayMenu.UserInterface
|
|||
{
|
||||
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(
|
||||
nameof(FadeIn), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Menu));
|
||||
|
||||
|
@ -305,6 +308,12 @@ namespace SystemTrayMenu.UserInterface
|
|||
|
||||
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseClick;
|
||||
|
||||
internal event RoutedEventHandler FadeToTransparent
|
||||
{
|
||||
add { AddHandler(FadeToTransparentEvent, value); }
|
||||
remove { RemoveHandler(FadeToTransparentEvent, value); }
|
||||
}
|
||||
|
||||
internal event RoutedEventHandler FadeIn
|
||||
{
|
||||
add { AddHandler(FadeInEvent, value); }
|
||||
|
@ -460,31 +469,25 @@ namespace SystemTrayMenu.UserInterface
|
|||
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
|
||||
{
|
||||
ShowTransparent();
|
||||
Opacity = 1D;
|
||||
FadeIn_Completed(this, new());
|
||||
}
|
||||
}
|
||||
|
||||
internal void ShowWithFade() => Fading_Show(false);
|
||||
|
||||
internal void ShowTransparent() => Fading_Show(true);
|
||||
|
||||
internal void Fading_Show(bool transparency)
|
||||
internal void ShowWithFade(bool transparency = false)
|
||||
{
|
||||
timerUpdateIcons.Start();
|
||||
|
||||
if (Level == 0)
|
||||
{
|
||||
Activate();
|
||||
}
|
||||
else
|
||||
if (Level > 0)
|
||||
{
|
||||
ShowActivated = false;
|
||||
}
|
||||
|
@ -497,8 +500,7 @@ namespace SystemTrayMenu.UserInterface
|
|||
isFading = true;
|
||||
if (transparency)
|
||||
{
|
||||
// TODO: FADING: Instead setting of opacity 100% only go up to 80% (Temporarily go to 100% as well)
|
||||
RaiseEvent(new(routedEvent: FadeInEvent));
|
||||
RaiseEvent(new(routedEvent: FadeToTransparentEvent));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -517,8 +519,6 @@ namespace SystemTrayMenu.UserInterface
|
|||
if (Settings.Default.UseFading)
|
||||
{
|
||||
isFading = true;
|
||||
|
||||
// TODO: FADING: Instead starting at opacity 100% it should start with 80% due to transparency setting
|
||||
RaiseEvent(new(routedEvent: FadeOutEvent));
|
||||
}
|
||||
else
|
||||
|
@ -545,7 +545,7 @@ namespace SystemTrayMenu.UserInterface
|
|||
StartLocation startLocation,
|
||||
bool useCustomLocation)
|
||||
{
|
||||
Point originLocation = new(0.0D, 0.0D);
|
||||
Point originLocation = new(0D, 0D);
|
||||
|
||||
// Update the height and width
|
||||
AdjustDataGridViewHeight(menuPredecessor, bounds.Height);
|
||||
|
@ -599,7 +599,7 @@ namespace SystemTrayMenu.UserInterface
|
|||
void AdjustWindowPositionInternal(in Point originLocation)
|
||||
{
|
||||
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
|
||||
UpdateLayout();
|
||||
|
|
Loading…
Reference in a new issue