From dafcce6568b44457fe2e373d163a6b4d56e9866f Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 9 Aug 2015 02:15:46 +0300 Subject: [PATCH] Added region capture border glowing for non active regions --- .../Forms/RectangleRegion.cs | 8 +- .../RegionHelpers/GlowColorTimer.cs | 77 +++++++++++++++++++ .../ShareX.ScreenCaptureLib.csproj | 1 + 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 ShareX.ScreenCaptureLib/RegionHelpers/GlowColorTimer.cs diff --git a/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs b/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs index 6d2d958ea..5749e38db 100644 --- a/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs +++ b/ShareX.ScreenCaptureLib/Forms/RectangleRegion.cs @@ -68,6 +68,8 @@ public Color CurrentColor #endregion Screen ruler + private GlowTimer glowTimer = new GlowTimer(); + public RectangleRegion() { AreaManager = new AreaManager(this); @@ -183,6 +185,7 @@ public override void Prepare() protected override void Update() { base.Update(); + glowTimer.Update(); AreaManager.Update(); } @@ -206,7 +209,10 @@ protected override void Draw(Graphics g) } } - g.DrawPath(borderPen, regionDrawPath); + using (Pen glowingBorderPen = new Pen(glowTimer.GetColor())) + { + g.DrawPath(glowingBorderPen, regionDrawPath); + } /* if (areas.Count > 1) diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/GlowColorTimer.cs b/ShareX.ScreenCaptureLib/RegionHelpers/GlowColorTimer.cs new file mode 100644 index 000000000..3fefd583c --- /dev/null +++ b/ShareX.ScreenCaptureLib/RegionHelpers/GlowColorTimer.cs @@ -0,0 +1,77 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright © 2007-2015 ShareX Developers + + 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.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; + +namespace ShareX.ScreenCaptureLib +{ + public class GlowTimer + { + public float Max = 1; + public float Min = 0; + public float Current = 0; + + private Stopwatch timer; + private TimeSpan previousTime; + private int direction = 1; + private float increase = 0.75f; + + public GlowTimer() + { + timer = Stopwatch.StartNew(); + } + + public void Update() + { + TimeSpan totalElapsed = timer.Elapsed; + TimeSpan elapsed = totalElapsed - previousTime; + previousTime = totalElapsed; + + Current += (float)elapsed.TotalSeconds * increase * direction; + + if (Current > Max) + { + Current = Max - (Current - Max); + direction = -1; + } + else if (Current < Min) + { + Current = Min + (Min - Current); + direction = 1; + } + } + + public Color GetColor() + { + return ColorHelpers.Lerp(Color.FromArgb(30, 30, 30), Color.FromArgb(100, 100, 100), Current); + } + } +} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index 65a811a73..7adefb355 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -60,6 +60,7 @@ +