Added RectangleAnimation class

This commit is contained in:
Jaex 2017-04-03 03:57:37 +03:00
parent d5dd455498
commit 5ad7cabca4
6 changed files with 100 additions and 28 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}
}
}

View file

@ -79,7 +79,7 @@ public Color CurrentColor
internal List<DrawableObject> DrawableObjects { get; private set; }
internal IContainer components = null;
internal TwoPointAnimation toolbarAnimation, toolbarAnimation2;
internal PointAnimation toolbarAnimation, toolbarAnimation2;
private TextureBrush backgroundBrush, backgroundHighlightBrush;
private GraphicsPath regionFillPath, regionDrawPath;

View file

@ -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),

View file

@ -60,7 +60,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Animations\BaseAnimation.cs" />
<Compile Include="Animations\TwoPointAnimation.cs" />
<Compile Include="Animations\PointAnimation.cs" />
<Compile Include="Animations\RectangleAnimation.cs" />
<Compile Include="Shapes\AnnotationOptions.cs" />
<Compile Include="Enums.cs" />
<Compile Include="Forms\RegionCaptureSimpleAnnotateForm.cs">