Skip to content

Commit

Permalink
Notification: Adding an option to auto dispose notification after dur…
Browse files Browse the repository at this point in the history
…ation end or double click, fixing XML.
  • Loading branch information
L33T committed Feb 18, 2015
1 parent 458e166 commit 3011c3a
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions Notifications/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public enum NotificationState
/// </summary>
/// <param name="text">Display Text</param>
/// <param name="duration">Duration (-1 for Infinite)</param>
public Notification(string text, int duration = -0x1)
/// <param name="dispose">Auto Dispose after notification duration end</param>
public Notification(string text, int duration = -0x1, bool dispose = false)
{
// Setting GUID
id = Guid.NewGuid().ToString("N");
Expand All @@ -64,6 +65,7 @@ public Notification(string text, int duration = -0x1)
Text = text;
state = NotificationState.Idle;
border = true;
autoDispose = dispose;

// Preload Text
Font.PreloadText(text);
Expand Down Expand Up @@ -336,6 +338,11 @@ private static Vector2[] GetBorder(float x, float y, float w, float h)
/// </summary>
private bool border;

/// <summary>
/// Locally saved bool which indicates if notification will be disposed after finishing
/// </summary>
private readonly bool autoDispose;

#endregion

#region Required Functions
Expand Down Expand Up @@ -451,8 +458,11 @@ public void OnUpdate()

if (!flashing && duration > 0x0 && TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
{
Update = false;
Draw = false;
Update = Draw = false;
if (autoDispose)
{
Dispose();
}

Notifications.Free(handler);

Expand Down Expand Up @@ -495,8 +505,11 @@ public void OnUpdate()
{
if (TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
{
Update = false;
Draw = false;
Update = Draw = false;
if (autoDispose)
{
Dispose();
}

Notifications.Free(handler);

Expand Down Expand Up @@ -535,8 +548,11 @@ public void OnUpdate()
{
if (TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
{
Update = false;
Draw = false;
Update = Draw = false;
if (autoDispose)
{
Dispose();
}

Notifications.Free(handler);

Expand Down Expand Up @@ -726,8 +742,11 @@ public void OnWndProc(WndEventArgs args)

Notifications.Free(handler);

Draw = false;
Update = false;
Draw = Update = false;
if (autoDispose)
{
Dispose();
}
return;
}
clickTick = Utils.TickCount;
Expand Down Expand Up @@ -761,7 +780,7 @@ public void Dispose()
/// <summary>
/// Safe disposal callback
/// </summary>
/// <param name="safe">Is Finailized</param>
/// <param name="safe">Is Pre-Finailized / Safe (values not cleared by GC)</param>
private void Dispose(bool safe)
{
if (Notifications.IsValidNotification(this))
Expand Down Expand Up @@ -816,4 +835,4 @@ private void Dispose(bool safe)

#endregion
}
}
}

0 comments on commit 3011c3a

Please sign in to comment.