diff --git a/ShareX.ScreenCaptureLib/Animations/ColorBlinkAnimation.cs b/ShareX.ScreenCaptureLib/Animations/ColorBlinkAnimation.cs index 0a15dfbbc..a9729aa7d 100644 --- a/ShareX.ScreenCaptureLib/Animations/ColorBlinkAnimation.cs +++ b/ShareX.ScreenCaptureLib/Animations/ColorBlinkAnimation.cs @@ -55,22 +55,25 @@ public ColorBlinkAnimation() public override bool Update() { - base.Update(); - - current += (float)Elapsed.TotalSeconds * Speed * direction; - - if (current > Max) + if (IsActive) { - current = Max; //Max - (Current - Max); - direction = -1; - } - else if (current < Min) - { - current = Min; //Min + (Min - Current); - direction = 1; - } + base.Update(); - CurrentColor = ColorHelpers.Lerp(FromColor, ToColor, current); + current += (float)Elapsed.TotalSeconds * Speed * direction; + + if (current > Max) + { + current = Max; //Max - (Current - Max); + direction = -1; + } + else if (current < Min) + { + current = Min; //Min + (Min - Current); + direction = 1; + } + + CurrentColor = ColorHelpers.Lerp(FromColor, ToColor, current); + } return IsActive; } diff --git a/ShareX.ScreenCaptureLib/Animations/TwoPointAnimation.cs b/ShareX.ScreenCaptureLib/Animations/PointAnimation.cs similarity index 77% rename from ShareX.ScreenCaptureLib/Animations/TwoPointAnimation.cs rename to ShareX.ScreenCaptureLib/Animations/PointAnimation.cs index 7de81c445..6b60195c4 100644 --- a/ShareX.ScreenCaptureLib/Animations/TwoPointAnimation.cs +++ b/ShareX.ScreenCaptureLib/Animations/PointAnimation.cs @@ -29,7 +29,7 @@ You should have received a copy of the GNU General Public License namespace ShareX.ScreenCaptureLib { - internal class TwoPointAnimation : BaseAnimation + internal class PointAnimation : BaseAnimation { public Point FromPosition { get; set; } public Point ToPosition { get; set; } @@ -39,17 +39,20 @@ internal class TwoPointAnimation : BaseAnimation public override bool Update() { - base.Update(); - - float amount = (float)Timer.Elapsed.TotalSeconds * Speed; - amount = Math.Min(amount, 1); - - if (amount >= 1) + if (IsActive) { - Stop(); - } + base.Update(); - CurrentPosition = (Point)MathHelpers.Lerp(FromPosition, ToPosition, amount); + float amount = (float)Timer.Elapsed.TotalSeconds * Speed; + amount = Math.Min(amount, 1); + + CurrentPosition = (Point)MathHelpers.Lerp(FromPosition, ToPosition, amount); + + if (amount >= 1) + { + Stop(); + } + } return IsActive; } diff --git a/ShareX.ScreenCaptureLib/Animations/RectangleAnimation.cs b/ShareX.ScreenCaptureLib/Animations/RectangleAnimation.cs new file mode 100644 index 000000000..ed4e15c52 --- /dev/null +++ b/ShareX.ScreenCaptureLib/Animations/RectangleAnimation.cs @@ -0,0 +1,65 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (c) 2007-2017 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.Drawing; + +namespace ShareX.ScreenCaptureLib +{ + internal class RectangleAnimation : BaseAnimation + { + public Rectangle FromRectangle { get; set; } + public Rectangle ToRectangle { get; set; } + public float Speed { get; set; } = 1; + + public Rectangle CurrentRectangle { get; private set; } + + public override bool Update() + { + if (IsActive) + { + base.Update(); + + float amount = (float)Timer.Elapsed.TotalSeconds * Speed; + amount = Math.Min(amount, 1); + + int x = (int)MathHelpers.Lerp(FromRectangle.X, ToRectangle.X, amount); + int y = (int)MathHelpers.Lerp(FromRectangle.Y, ToRectangle.Y, amount); + int width = (int)MathHelpers.Lerp(FromRectangle.Width, ToRectangle.Width, amount); + int height = (int)MathHelpers.Lerp(FromRectangle.Height, ToRectangle.Height, amount); + + CurrentRectangle = new Rectangle(x, y, width, height); + + if (amount >= 1) + { + Stop(); + } + } + + return IsActive; + } + } +} \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs index de412c51e..056762bf3 100644 --- a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs @@ -79,7 +79,7 @@ public Color CurrentColor internal List DrawableObjects { get; private set; } internal IContainer components = null; - internal TwoPointAnimation toolbarAnimation, toolbarAnimation2; + internal PointAnimation toolbarAnimation, toolbarAnimation2; private TextureBrush backgroundBrush, backgroundHighlightBrush; private GraphicsPath regionFillPath, regionDrawPath; diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs index f05596987..9a077cd2f 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs @@ -772,7 +772,7 @@ private void MenuForm_Shown(object sender, EventArgs e) { Point clientLocation = CaptureHelpers.ScreenToClient(menuForm.Location); - form.toolbarAnimation = new TwoPointAnimation() + form.toolbarAnimation = new PointAnimation() { FromPosition = new Point(clientLocation.X + menuForm.Width / 2, clientLocation.Y + menuForm.Height + 1), ToPosition = new Point(clientLocation.X, clientLocation.Y + menuForm.Height + 1), @@ -781,7 +781,7 @@ private void MenuForm_Shown(object sender, EventArgs e) form.toolbarAnimation.Start(); - form.toolbarAnimation2 = new TwoPointAnimation() + form.toolbarAnimation2 = new PointAnimation() { FromPosition = new Point(clientLocation.X + menuForm.Width / 2, clientLocation.Y + menuForm.Height + 1), ToPosition = new Point(clientLocation.X + menuForm.Width, clientLocation.Y + menuForm.Height + 1), diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index 28a94448c..17b8b0f3e 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -60,7 +60,8 @@ - + +