mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 22:34:27 -07:00
Small fixes & comments for some code, mainly the animation stuff of Greenshot.
This commit is contained in:
parent
81092aeffb
commit
b65badf359
9 changed files with 202 additions and 84 deletions
|
@ -32,12 +32,24 @@ namespace Greenshot.Addons.Animation
|
|||
/// </summary>
|
||||
internal class AnimationLeg<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The destination for an animation
|
||||
/// </summary>
|
||||
public T Destination { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Easing mode to use for this animation
|
||||
/// </summary>
|
||||
public EasingModes EasingMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Easing type to use for the animation leg
|
||||
/// </summary>
|
||||
public EasingTypes EasingType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of frames in the leg
|
||||
/// </summary>
|
||||
public int Frames { get; set; }
|
||||
}
|
||||
}
|
|
@ -29,11 +29,11 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Greenshot.Addons.Animation
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for the animation logic, this only implements Properties and a constructor
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type for the animation, like NativePoint/NativeRect/Size</typeparam>
|
||||
public abstract class AnimatorBase<T> : IAnimator
|
||||
/// <summary>
|
||||
/// Base class for the animation logic, this only implements Properties and a constructor
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type for the animation, like NativePoint/NativeRectNative/NativeSize</typeparam>
|
||||
public abstract class AnimatorBase<T> : IAnimator
|
||||
{
|
||||
private readonly Queue<AnimationLeg<T>> _queue = new Queue<AnimationLeg<T>>();
|
||||
|
||||
|
|
59
src/Greenshot.Addons/Animation/EasePower.cs
Normal file
59
src/Greenshot.Addons/Animation/EasePower.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
#region Greenshot GNU General Public License
|
||||
|
||||
// Greenshot - a free and open source screenshot tool
|
||||
// Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom
|
||||
//
|
||||
// For more information see: http://getgreenshot.org/
|
||||
// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
|
||||
//
|
||||
// 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 1 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#endregion
|
||||
|
||||
#region using
|
||||
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Greenshot.Addons.Animation
|
||||
{
|
||||
/// <summary>
|
||||
/// A supporting class to do Pow calculations for easing
|
||||
/// </summary>
|
||||
public static class EasePower
|
||||
{
|
||||
public static double EaseIn(double s, int power)
|
||||
{
|
||||
return Math.Pow(s, power);
|
||||
}
|
||||
|
||||
public static double EaseInOut(double s, int power)
|
||||
{
|
||||
s *= 2;
|
||||
if (s < 1)
|
||||
{
|
||||
return EaseIn(s, power) / 2;
|
||||
}
|
||||
var sign = power % 2 == 0 ? -1 : 1;
|
||||
return sign / 2.0 * (Math.Pow(s - 2, power) + sign * 2);
|
||||
}
|
||||
|
||||
public static double EaseOut(double s, int power)
|
||||
{
|
||||
var sign = power % 2 == 0 ? -1 : 1;
|
||||
return sign * (Math.Pow(s - 1, power) + sign);
|
||||
}
|
||||
}
|
||||
}
|
52
src/Greenshot.Addons/Animation/EaseSine.cs
Normal file
52
src/Greenshot.Addons/Animation/EaseSine.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
#region Greenshot GNU General Public License
|
||||
|
||||
// Greenshot - a free and open source screenshot tool
|
||||
// Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom
|
||||
//
|
||||
// For more information see: http://getgreenshot.org/
|
||||
// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
|
||||
//
|
||||
// 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 1 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#endregion
|
||||
|
||||
#region using
|
||||
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Greenshot.Addons.Animation
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a supporting class to do Sin calculations for the easing
|
||||
/// </summary>
|
||||
public static class EaseSine
|
||||
{
|
||||
public static double EaseIn(double s)
|
||||
{
|
||||
return Math.Sin(s * (Math.PI / 2) - Math.PI / 2) + 1;
|
||||
}
|
||||
|
||||
public static double EaseInOut(double s)
|
||||
{
|
||||
return Math.Sin(s * Math.PI - Math.PI / 2 + 1) / 2;
|
||||
}
|
||||
|
||||
public static double EaseOut(double s)
|
||||
{
|
||||
return Math.Sin(s * (Math.PI / 2));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,12 +29,19 @@ using System;
|
|||
|
||||
namespace Greenshot.Addons.Animation
|
||||
{
|
||||
/// <summary>
|
||||
/// Easing logic, to make the animations more "fluent"
|
||||
/// Adapted from <a href="http://www.robertpenner.com/easing/penner_chapter7_tweening.pdf">here</a>
|
||||
/// </summary>
|
||||
public static class Easing
|
||||
/// <summary>
|
||||
/// Easing logic, to make the animations more "fluent"
|
||||
/// Adapted from <a href="http://www.robertpenner.com/easing/penner_chapter7_tweening.pdf">here</a>
|
||||
/// </summary>
|
||||
public static class Easing
|
||||
{
|
||||
/// <summary>
|
||||
/// Apply "ease" to ubfirnatuin
|
||||
/// </summary>
|
||||
/// <param name="linearStep">double</param>
|
||||
/// <param name="acceleration">double</param>
|
||||
/// <param name="type">double</param>
|
||||
/// <returns>double</returns>
|
||||
public static double Ease(double linearStep, double acceleration, EasingTypes type)
|
||||
{
|
||||
var easedStep = acceleration > 0 ? EaseIn(linearStep, type) : acceleration < 0 ? EaseOut(linearStep, type) : linearStep;
|
||||
|
@ -42,6 +49,12 @@ namespace Greenshot.Addons.Animation
|
|||
return (easedStep - linearStep) * Math.Abs(acceleration) + linearStep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply ease in
|
||||
/// </summary>
|
||||
/// <param name="linearStep">double</param>
|
||||
/// <param name="type">EasingTypes</param>
|
||||
/// <returns>double</returns>
|
||||
public static double EaseIn(double linearStep, EasingTypes type)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -51,24 +64,37 @@ namespace Greenshot.Addons.Animation
|
|||
case EasingTypes.Linear:
|
||||
return linearStep;
|
||||
case EasingTypes.Sine:
|
||||
return Sine.EaseIn(linearStep);
|
||||
return EaseSine.EaseIn(linearStep);
|
||||
case EasingTypes.Quadratic:
|
||||
return Power.EaseIn(linearStep, 2);
|
||||
return EasePower.EaseIn(linearStep, 2);
|
||||
case EasingTypes.Cubic:
|
||||
return Power.EaseIn(linearStep, 3);
|
||||
return EasePower.EaseIn(linearStep, 3);
|
||||
case EasingTypes.Quartic:
|
||||
return Power.EaseIn(linearStep, 4);
|
||||
return EasePower.EaseIn(linearStep, 4);
|
||||
case EasingTypes.Quintic:
|
||||
return Power.EaseIn(linearStep, 5);
|
||||
return EasePower.EaseIn(linearStep, 5);
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply ease in-out
|
||||
/// </summary>
|
||||
/// <param name="linearStep">double</param>
|
||||
/// <param name="easeInType">EasingTypes</param>
|
||||
/// <param name="easeOutType">EasingTypes</param>
|
||||
/// <returns>double</returns>
|
||||
public static double EaseInOut(double linearStep, EasingTypes easeInType, EasingTypes easeOutType)
|
||||
{
|
||||
return linearStep < 0.5 ? EaseInOut(linearStep, easeInType) : EaseInOut(linearStep, easeOutType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply easy in out
|
||||
/// </summary>
|
||||
/// <param name="linearStep">double</param>
|
||||
/// <param name="type">EasingTypes</param>
|
||||
/// <returns>double</returns>
|
||||
public static double EaseInOut(double linearStep, EasingTypes type)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -78,20 +104,26 @@ namespace Greenshot.Addons.Animation
|
|||
case EasingTypes.Linear:
|
||||
return linearStep;
|
||||
case EasingTypes.Sine:
|
||||
return Sine.EaseInOut(linearStep);
|
||||
return EaseSine.EaseInOut(linearStep);
|
||||
case EasingTypes.Quadratic:
|
||||
return Power.EaseInOut(linearStep, 2);
|
||||
return EasePower.EaseInOut(linearStep, 2);
|
||||
case EasingTypes.Cubic:
|
||||
return Power.EaseInOut(linearStep, 3);
|
||||
return EasePower.EaseInOut(linearStep, 3);
|
||||
case EasingTypes.Quartic:
|
||||
return Power.EaseInOut(linearStep, 4);
|
||||
return EasePower.EaseInOut(linearStep, 4);
|
||||
case EasingTypes.Quintic:
|
||||
return Power.EaseInOut(linearStep, 5);
|
||||
return EasePower.EaseInOut(linearStep, 5);
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static double EaseOut(double linearStep, EasingTypes type)
|
||||
/// <summary>
|
||||
/// Apply easy out
|
||||
/// </summary>
|
||||
/// <param name="linearStep">double</param>
|
||||
/// <param name="type">EasingTypes</param>
|
||||
/// <returns>double</returns>
|
||||
public static double EaseOut(double linearStep, EasingTypes type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
@ -100,60 +132,17 @@ namespace Greenshot.Addons.Animation
|
|||
case EasingTypes.Linear:
|
||||
return linearStep;
|
||||
case EasingTypes.Sine:
|
||||
return Sine.EaseOut(linearStep);
|
||||
return EaseSine.EaseOut(linearStep);
|
||||
case EasingTypes.Quadratic:
|
||||
return Power.EaseOut(linearStep, 2);
|
||||
return EasePower.EaseOut(linearStep, 2);
|
||||
case EasingTypes.Cubic:
|
||||
return Power.EaseOut(linearStep, 3);
|
||||
return EasePower.EaseOut(linearStep, 3);
|
||||
case EasingTypes.Quartic:
|
||||
return Power.EaseOut(linearStep, 4);
|
||||
return EasePower.EaseOut(linearStep, 4);
|
||||
case EasingTypes.Quintic:
|
||||
return Power.EaseOut(linearStep, 5);
|
||||
return EasePower.EaseOut(linearStep, 5);
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static class Sine
|
||||
{
|
||||
public static double EaseIn(double s)
|
||||
{
|
||||
return Math.Sin(s * (Math.PI / 2) - Math.PI / 2) + 1;
|
||||
}
|
||||
|
||||
public static double EaseInOut(double s)
|
||||
{
|
||||
return Math.Sin(s * Math.PI - Math.PI / 2 + 1) / 2;
|
||||
}
|
||||
|
||||
public static double EaseOut(double s)
|
||||
{
|
||||
return Math.Sin(s * (Math.PI / 2));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Power
|
||||
{
|
||||
public static double EaseIn(double s, int power)
|
||||
{
|
||||
return Math.Pow(s, power);
|
||||
}
|
||||
|
||||
public static double EaseInOut(double s, int power)
|
||||
{
|
||||
s *= 2;
|
||||
if (s < 1)
|
||||
{
|
||||
return EaseIn(s, power) / 2;
|
||||
}
|
||||
var sign = power % 2 == 0 ? -1 : 1;
|
||||
return sign / 2.0 * (Math.Pow(s - 2, power) + sign * 2);
|
||||
}
|
||||
|
||||
public static double EaseOut(double s, int power)
|
||||
{
|
||||
var sign = power % 2 == 0 ? -1 : 1;
|
||||
return sign * (Math.Pow(s - 1, power) + sign);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,9 @@
|
|||
|
||||
namespace Greenshot.Addons.Animation
|
||||
{
|
||||
/// <summary>
|
||||
/// Define the possible easing modes
|
||||
/// </summary>
|
||||
public enum EasingModes
|
||||
{
|
||||
EaseIn,
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#region using
|
||||
|
||||
using System.Drawing;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -32,18 +32,18 @@ namespace Greenshot.Addons.Animation
|
|||
/// <summary>
|
||||
/// Implementation of the SizeAnimator
|
||||
/// </summary>
|
||||
public class SizeAnimator : AnimatorBase<Size>
|
||||
public class SizeAnimator : AnimatorBase<NativeSize>
|
||||
{
|
||||
public SizeAnimator(Size first, Size last, int frames, EasingTypes easingType = EasingTypes.Linear, EasingModes easingMode = EasingModes.EaseIn)
|
||||
public SizeAnimator(NativeSize first, NativeSize last, int frames, EasingTypes easingType = EasingTypes.Linear, EasingModes easingMode = EasingModes.EaseIn)
|
||||
: base(first, last, frames, easingType, easingMode)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the next frame values
|
||||
/// </summary>
|
||||
/// <returns>Size</returns>
|
||||
public override Size Next()
|
||||
/// <summary>
|
||||
/// Calculate the next frame values
|
||||
/// </summary>
|
||||
/// <returns>NativeSize</returns>
|
||||
public override NativeSize Next()
|
||||
{
|
||||
if (!NextFrame)
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ namespace Greenshot.Addons.Animation
|
|||
double dh = Last.Height - First.Height;
|
||||
var width = First.Width + (int) (easingValue * dw);
|
||||
var height = First.Height + (int) (easingValue * dh);
|
||||
Current = new Size(width, height);
|
||||
Current = new NativeSize(width, height);
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,6 +155,8 @@
|
|||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Animation\EasePower.cs" />
|
||||
<Compile Include="Animation\EaseSine.cs" />
|
||||
<Compile Include="Components\DestinationAttribute.cs" />
|
||||
<Compile Include="Animation\ColorAnimator.cs" />
|
||||
<Compile Include="Animation\Easing.cs" />
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace Greenshot.Forms
|
|||
|
||||
private int _mX;
|
||||
private int _mY;
|
||||
private Point _previousMousePos = Point.Empty;
|
||||
private NativePoint _previousMousePos = NativePoint.Empty;
|
||||
// the window which is selected
|
||||
private bool _showDebugInfo;
|
||||
private RectangleAnimator _windowAnimator;
|
||||
|
@ -423,7 +423,7 @@ namespace Greenshot.Forms
|
|||
/// </summary>
|
||||
/// <param name="currentMouse"></param>
|
||||
/// <returns></returns>
|
||||
private Point FixMouseCoordinates(Point currentMouse)
|
||||
private Point FixMouseCoordinates(NativePoint currentMouse)
|
||||
{
|
||||
switch (_fixMode)
|
||||
{
|
||||
|
@ -455,9 +455,10 @@ namespace Greenshot.Forms
|
|||
/// <param name="e"></param>
|
||||
private void OnMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
// Make sure the mouse coordinates are fixed, when pressing shift
|
||||
_mouseMovePos = FixMouseCoordinates(User32Api.GetCursorLocation());
|
||||
_mouseMovePos = WindowCapture.GetLocationRelativeToScreenBounds(_mouseMovePos);
|
||||
var cursorLocation = User32Api.GetCursorLocation();
|
||||
var relativeCursorPosition = WindowCapture.GetLocationRelativeToScreenBounds(cursorLocation);
|
||||
// Make sure the mouse coordinates are fixed, e.g. when pressing shift
|
||||
_mouseMovePos = FixMouseCoordinates(relativeCursorPosition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -709,7 +710,7 @@ namespace Greenshot.Forms
|
|||
/// <param name="paintEventArgs">PaintEventArgs</param>
|
||||
protected override void OnPaintBackground(PaintEventArgs paintEventArgs)
|
||||
{
|
||||
// Ignore the event, to reduct painting
|
||||
// Ignore the event, to reduce painting
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue