mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Allow setting toast window duration as 0 which will start fading immediately
This commit is contained in:
parent
6d7141f62a
commit
58cf68ea87
2 changed files with 25 additions and 13 deletions
|
@ -36,8 +36,8 @@ public class NotificationForm : Form
|
|||
public NotificationFormConfig ToastConfig { get; private set; }
|
||||
|
||||
private int windowOffset = 3;
|
||||
private bool mouseInside;
|
||||
private bool durationEnd;
|
||||
private bool isMouseInside;
|
||||
private bool isDurationEnd;
|
||||
private bool closingAnimation = true;
|
||||
private int closingAnimationDuration = 2000;
|
||||
private int closingAnimationInterval = 50;
|
||||
|
@ -71,16 +71,28 @@ public NotificationForm(int duration, ContentAlignment placement, Size size, Not
|
|||
NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X,
|
||||
position.Y + Screen.PrimaryScreen.WorkingArea.Y, size.Width, size.Height, SetWindowPosFlags.SWP_NOACTIVATE);
|
||||
|
||||
tDuration.Interval = duration;
|
||||
tDuration.Start();
|
||||
if (duration <= 0)
|
||||
{
|
||||
DurationEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
tDuration.Interval = duration;
|
||||
tDuration.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void tDuration_Tick(object sender, EventArgs e)
|
||||
{
|
||||
durationEnd = true;
|
||||
DurationEnd();
|
||||
}
|
||||
|
||||
private void DurationEnd()
|
||||
{
|
||||
isDurationEnd = true;
|
||||
tDuration.Stop();
|
||||
|
||||
if (!mouseInside)
|
||||
if (!isMouseInside)
|
||||
{
|
||||
StartClosing();
|
||||
}
|
||||
|
@ -124,7 +136,7 @@ protected override void OnPaint(PaintEventArgs e)
|
|||
{
|
||||
g.DrawImage(ToastConfig.Image, 1, 1, ToastConfig.Image.Width, ToastConfig.Image.Height);
|
||||
|
||||
if (mouseInside && !string.IsNullOrEmpty(ToastConfig.URL))
|
||||
if (isMouseInside && !string.IsNullOrEmpty(ToastConfig.URL))
|
||||
{
|
||||
Rectangle textRect = new Rectangle(0, 0, rect.Width, 40);
|
||||
|
||||
|
@ -153,7 +165,7 @@ protected override void OnPaint(PaintEventArgs e)
|
|||
|
||||
public static void Show(int duration, ContentAlignment placement, Size size, NotificationFormConfig config)
|
||||
{
|
||||
if (duration > 0 && size.Width > 0 && size.Height > 0)
|
||||
if (size.Width > 0 && size.Height > 0)
|
||||
{
|
||||
config.Image = ImageHelpers.LoadImage(config.FilePath);
|
||||
|
||||
|
@ -205,7 +217,7 @@ private void NotificationForm_MouseClick(object sender, MouseEventArgs e)
|
|||
|
||||
private void NotificationForm_MouseEnter(object sender, EventArgs e)
|
||||
{
|
||||
mouseInside = true;
|
||||
isMouseInside = true;
|
||||
Refresh();
|
||||
|
||||
tOpacity.Stop();
|
||||
|
@ -214,10 +226,10 @@ private void NotificationForm_MouseEnter(object sender, EventArgs e)
|
|||
|
||||
private void NotificationForm_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
mouseInside = false;
|
||||
isMouseInside = false;
|
||||
Refresh();
|
||||
|
||||
if (durationEnd)
|
||||
if (isDurationEnd)
|
||||
{
|
||||
StartClosing();
|
||||
}
|
||||
|
|
|
@ -394,7 +394,7 @@ public class TaskSettingsAdvanced
|
|||
|
||||
private float toastWindowDuration;
|
||||
|
||||
[Category("After upload / Notifications"), DefaultValue(4f), Description("Specify how long should toast notification window will stay on screen (in seconds).")]
|
||||
[Category("After upload / Notifications"), DefaultValue(3f), Description("Specify how long should toast notification window will stay on screen (in seconds).")]
|
||||
public float ToastWindowDuration
|
||||
{
|
||||
get
|
||||
|
@ -403,7 +403,7 @@ public float ToastWindowDuration
|
|||
}
|
||||
set
|
||||
{
|
||||
toastWindowDuration = Math.Max(value, 1f);
|
||||
toastWindowDuration = Math.Max(value, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue