From 464ff68252d2a245102842e699ae9da034d4367c Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Wed, 8 Apr 2020 03:50:52 +0200 Subject: [PATCH] #72, #73, version 0.9.2.18 --- Business/SystemTrayMenu.cs | 21 ++--- Helpers/Fading.cs | 171 +++++++++++++++++++------------------ Properties/AssemblyInfo.cs | 4 +- 3 files changed, 95 insertions(+), 101 deletions(-) diff --git a/Business/SystemTrayMenu.cs b/Business/SystemTrayMenu.cs index 4eb88ed..9e39371 100644 --- a/Business/SystemTrayMenu.cs +++ b/Business/SystemTrayMenu.cs @@ -111,23 +111,14 @@ namespace SystemTrayMenu MenuData menuData = (MenuData)e.Result; if (menuData.Validity == MenuDataValidity.Valid) { - DisposeMenu(menus[0]); //maybe not necessary + DisposeMenu(menus[0]); + menus[0].Visible = false; // resets activated menus[0] = CreateMenu(menuData, Path.GetFileName(Config.Path)); menus[0].AdjustLocationAndSize(screen); Menus().ToList().ForEach(m => { m.ShowWithFade(); }); - menus[0].VisibleChanged += WhenVisibleActivate; - menus[0].Visible = false; // resets activated - menus[0].Visible = true; // resets activated - void WhenVisibleActivate(object senderM, EventArgs eM) - { - if (menus[0].Visible) - { - menus[0].VisibleChanged -= WhenVisibleActivate; - menus[0].Activate(); - menus[0].SetTitleColorActive(); - NativeMethods.ForceForegroundWindow(menus[0].Handle); - } - } + menus[0].Activate(); + menus[0].SetTitleColorActive(); + NativeMethods.ForceForegroundWindow(menus[0].Handle); } openCloseState = OpenCloseState.Default; @@ -143,9 +134,9 @@ namespace SystemTrayMenu } } -#warning #72, #73 First start slower than others menus[0] = CreateMenu(ReadMenu(worker, Config.Path, 0), Path.GetFileName(Config.Path)); + menus[0].AdjustLocationAndSize(screen); DisposeMenu(menus[0]); } diff --git a/Helpers/Fading.cs b/Helpers/Fading.cs index fde3606..2c823e7 100644 --- a/Helpers/Fading.cs +++ b/Helpers/Fading.cs @@ -31,75 +31,10 @@ namespace SystemTrayMenu.UserInterface internal Fading() { timer.Interval = Interval60FPS; - timer.Tick += FadeStep; - void FadeStep(object sender, EventArgs e) + timer.Tick += Tick; + void Tick(object sender, EventArgs e) { - switch (state) - { - case FadingState.Show: - if (!visible) - { - visible = true; - Show?.Invoke(); - opacity = 0; - ChangeOpacity?.Invoke(this, opacity); - } - else if (opacity < ShownMinus) - { - opacity += StepIn; - ChangeOpacity?.Invoke(this, opacity); - } - else if (opacity != Shown) - { - opacity = Shown; - ChangeOpacity?.Invoke(this, Shown); - StartStopTimer(FadingState.Idle); - } - break; - case FadingState.ShowTransparent: - if (!visible) - { - visible = true; - Show?.Invoke(); - opacity = 0; - ChangeOpacity?.Invoke(this, opacity); - } - else if (opacity < TransparentMinus) - { - opacity += StepIn; - ChangeOpacity?.Invoke(this, opacity); - } - else if (opacity > TransparentPlus) - { - opacity -= StepOut; - ChangeOpacity?.Invoke(this, opacity); - } - else if (opacity != Transparent) - { - ChangeOpacity?.Invoke(this, Transparent); - StartStopTimer(FadingState.Idle); - } - break; - case FadingState.Hide: - if (opacity > StepOut) - { - opacity -= StepOut; - ChangeOpacity?.Invoke(this, opacity); - } - else if (visible) - { - opacity = 0; - ChangeOpacity?.Invoke(this, opacity); - visible = false; - Hide?.Invoke(); - StartStopTimer(FadingState.Idle); - } - break; - case FadingState.Idle: - default: - StartStopTimer(FadingState.Idle); - break; - } + FadeStep(); } } @@ -111,29 +46,97 @@ namespace SystemTrayMenu.UserInterface private void StartStopTimer(FadingState state) { #warning if too many threads throw some away? win32 exception if too fast here - lock (lockTimerEnable) + if (state == FadingState.Idle) { - if (state == FadingState.Idle) + this.state = state; + timer.Stop(); + } + else + { + ShowAtLeastTransparentBeforeHideItAgain(); + void ShowAtLeastTransparentBeforeHideItAgain() { - this.state = state; - timer.Stop(); - } - else - { - ShowAtLeastTransparentBeforeHideItAgain(); - void ShowAtLeastTransparentBeforeHideItAgain() + if (state == FadingState.Hide) { - if (state == FadingState.Hide) + while (opacity < TransparentMinus) { - while (opacity < TransparentMinus) - { - Application.DoEvents(); - } + Application.DoEvents(); } } - this.state = state; - timer.Start(); } + this.state = state; + timer.Start(); + FadeStep(); + } + } + + private void FadeStep() + { + switch (state) + { + case FadingState.Show: + if (!visible) + { + visible = true; + Show?.Invoke(); + opacity = 0; + ChangeOpacity?.Invoke(this, opacity); + } + else if (opacity < ShownMinus) + { + opacity += StepIn; + ChangeOpacity?.Invoke(this, opacity); + } + else if (opacity != Shown) + { + opacity = Shown; + ChangeOpacity?.Invoke(this, Shown); + StartStopTimer(FadingState.Idle); + } + break; + case FadingState.ShowTransparent: + if (!visible) + { + visible = true; + Show?.Invoke(); + opacity = 0; + ChangeOpacity?.Invoke(this, opacity); + } + else if (opacity < TransparentMinus) + { + opacity += StepIn; + ChangeOpacity?.Invoke(this, opacity); + } + else if (opacity > TransparentPlus) + { + opacity -= StepOut; + ChangeOpacity?.Invoke(this, opacity); + } + else if (opacity != Transparent) + { + ChangeOpacity?.Invoke(this, Transparent); + StartStopTimer(FadingState.Idle); + } + break; + case FadingState.Hide: + if (opacity > StepOut) + { + opacity -= StepOut; + ChangeOpacity?.Invoke(this, opacity); + } + else if (visible) + { + opacity = 0; + ChangeOpacity?.Invoke(this, opacity); + visible = false; + Hide?.Invoke(); + StartStopTimer(FadingState.Idle); + } + break; + case FadingState.Idle: + default: + StartStopTimer(FadingState.Idle); + break; } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 5d81d12..a1543a7 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -35,5 +35,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.9.2.17")] -[assembly: AssemblyFileVersion("0.9.2.17")] +[assembly: AssemblyVersion("0.9.2.18")] +[assembly: AssemblyFileVersion("0.9.2.18")]