From 716a0052206767382550ebbf4c8484163f75c802 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 25 May 2019 17:40:54 +0300 Subject: [PATCH] Show task status with subtle glow top of task panels --- ShareX.HelpersLib/Helpers/MathHelpers.cs | 10 +-- ShareX/Controls/TaskPanel.Designer.cs | 4 +- ShareX/Controls/TaskPanel.cs | 8 ++ ShareX/Controls/TaskRoundedCornerPanel.cs | 95 +++++++++++++++++++++++ ShareX/Controls/TaskView.cs | 5 ++ ShareX/ShareX.csproj | 3 + ShareX/TaskManager.cs | 2 + 7 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 ShareX/Controls/TaskRoundedCornerPanel.cs diff --git a/ShareX.HelpersLib/Helpers/MathHelpers.cs b/ShareX.HelpersLib/Helpers/MathHelpers.cs index 27dfe2ec7..404555a2b 100644 --- a/ShareX.HelpersLib/Helpers/MathHelpers.cs +++ b/ShareX.HelpersLib/Helpers/MathHelpers.cs @@ -132,16 +132,16 @@ public static int Random(int min, int max) } } - public static int RandomPick(params int[] nums) - { - return nums[Random(nums.Length - 1)]; - } - public static int RandomAdd(int num, int min, int max) { return num + Random(min, max); } + public static T RandomPick(params T[] nums) + { + return nums[Random(nums.Length - 1)]; + } + /// /// Returns a random number between 0 and max (inclusive) generated with a cryptographic PRNG. /// diff --git a/ShareX/Controls/TaskPanel.Designer.cs b/ShareX/Controls/TaskPanel.Designer.cs index 12f754414..076cb3fbe 100644 --- a/ShareX/Controls/TaskPanel.Designer.cs +++ b/ShareX/Controls/TaskPanel.Designer.cs @@ -31,7 +31,7 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.pThumbnail = new ShareX.HelpersLib.RoundedCornerPanel(); + this.pThumbnail = new ShareX.TaskRoundedCornerPanel(); this.pbProgress = new ShareX.HelpersLib.BlackStyleProgressBar(); this.pbThumbnail = new System.Windows.Forms.PictureBox(); this.lblFilename = new ShareX.HelpersLib.BlackStyleLabel(); @@ -115,7 +115,7 @@ private void InitializeComponent() #endregion - private HelpersLib.RoundedCornerPanel pThumbnail; + private ShareX.TaskRoundedCornerPanel pThumbnail; private HelpersLib.BlackStyleLabel lblFilename; private HelpersLib.BlackStyleProgressBar pbProgress; private System.Windows.Forms.PictureBox pbThumbnail; diff --git a/ShareX/Controls/TaskPanel.cs b/ShareX/Controls/TaskPanel.cs index 9513c7f9c..ecd9185e8 100644 --- a/ShareX/Controls/TaskPanel.cs +++ b/ShareX/Controls/TaskPanel.cs @@ -225,6 +225,14 @@ public void UpdateProgress() } } + public void UpdateStatus() + { + if (Task.Info != null) + { + pThumbnail.UpdateStatusColor(Task.Status); + } + } + public void ClearThumbnail() { Image temp = pbThumbnail.Image; diff --git a/ShareX/Controls/TaskRoundedCornerPanel.cs b/ShareX/Controls/TaskRoundedCornerPanel.cs new file mode 100644 index 000000000..fc2875a22 --- /dev/null +++ b/ShareX/Controls/TaskRoundedCornerPanel.cs @@ -0,0 +1,95 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2019 ShareX Team + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using ShareX.HelpersLib; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShareX +{ + public class TaskRoundedCornerPanel : RoundedCornerPanel + { + public Color StatusColor { get; private set; } = Color.Transparent; + + public void UpdateStatusColor(TaskStatus status) + { + Color previousStatusColor = StatusColor; + + switch (status) + { + case TaskStatus.Completed: + case TaskStatus.Stopped: + StatusColor = Color.CornflowerBlue; + break; + case TaskStatus.Failed: + StatusColor = Color.IndianRed; + break; + case TaskStatus.History: + StatusColor = Color.Transparent; + break; + default: + StatusColor = Color.PaleGreen; + break; + } + + if (previousStatusColor != StatusColor) + { + Invalidate(); + } + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + if (StatusColor.A > 0) + { + Graphics g = e.Graphics; + + g.PixelOffsetMode = PixelOffsetMode.Half; + + using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, ClientRectangle.Width, 1), Color.Black, Color.Black, + LinearGradientMode.Horizontal)) + { + ColorBlend cb = new ColorBlend(); + cb.Positions = new float[] { 0, 0.3f, 0.7f, 1 }; + cb.Colors = new Color[] { Color.Transparent, StatusColor, StatusColor, Color.Transparent }; + brush.InterpolationColors = cb; + + using (Pen pen = new Pen(brush)) + { + g.DrawLine(pen, new Point(0, 0), new Point(ClientRectangle.Width - 1, 0)); + } + } + } + } + } +} \ No newline at end of file diff --git a/ShareX/Controls/TaskView.cs b/ShareX/Controls/TaskView.cs index a023b02c9..609f9b872 100644 --- a/ShareX/Controls/TaskView.cs +++ b/ShareX/Controls/TaskView.cs @@ -143,5 +143,10 @@ public void UpdateProgressVisible(WorkerTask task, bool visible) panel.ProgressVisible = visible; } } + + public void UpdateStatus(WorkerTask task) + { + FindPanel(task)?.UpdateStatus(); + } } } \ No newline at end of file diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index ccefa8e84..4cb327ed0 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -167,6 +167,9 @@ TaskPanel.cs + + Component + UserControl diff --git a/ShareX/TaskManager.cs b/ShareX/TaskManager.cs index 26ccccf7c..35b2f5079 100644 --- a/ShareX/TaskManager.cs +++ b/ShareX/TaskManager.cs @@ -265,6 +265,7 @@ private static void task_UploadStarted(WorkerTask task) TaskView.UpdateFilename(task); TaskView.UpdateThumbnail(task); TaskView.UpdateProgressVisible(task, true); + TaskView.UpdateStatus(task); } } @@ -360,6 +361,7 @@ private static void task_TaskCompleted(WorkerTask task) TaskView.UpdateFilename(task); TaskView.UpdateThumbnail(task); TaskView.UpdateProgressVisible(task, false); + TaskView.UpdateStatus(task); } ListViewItem lvi = FindListViewItem(task);