diff --git a/src/Greenshot.Addons/Animation/AnimationLeg.cs b/src/Greenshot.Addons/Animation/AnimationLeg.cs index 97484d103..097c600ed 100644 --- a/src/Greenshot.Addons/Animation/AnimationLeg.cs +++ b/src/Greenshot.Addons/Animation/AnimationLeg.cs @@ -32,12 +32,24 @@ namespace Greenshot.Addons.Animation /// internal class AnimationLeg { + /// + /// The destination for an animation + /// public T Destination { get; set; } + /// + /// Easing mode to use for this animation + /// public EasingModes EasingMode { get; set; } + /// + /// Easing type to use for the animation leg + /// public EasingTypes EasingType { get; set; } + /// + /// Number of frames in the leg + /// public int Frames { get; set; } } } \ No newline at end of file diff --git a/src/Greenshot.Addons/Animation/AnimatorBase.cs b/src/Greenshot.Addons/Animation/AnimatorBase.cs index 819ff19be..779a7ce76 100644 --- a/src/Greenshot.Addons/Animation/AnimatorBase.cs +++ b/src/Greenshot.Addons/Animation/AnimatorBase.cs @@ -29,11 +29,11 @@ using System.Collections.Generic; namespace Greenshot.Addons.Animation { - /// - /// Base class for the animation logic, this only implements Properties and a constructor - /// - /// Type for the animation, like NativePoint/NativeRect/Size - public abstract class AnimatorBase : IAnimator + /// + /// Base class for the animation logic, this only implements Properties and a constructor + /// + /// Type for the animation, like NativePoint/NativeRectNative/NativeSize + public abstract class AnimatorBase : IAnimator { private readonly Queue> _queue = new Queue>(); diff --git a/src/Greenshot.Addons/Animation/EasePower.cs b/src/Greenshot.Addons/Animation/EasePower.cs new file mode 100644 index 000000000..82abe6d93 --- /dev/null +++ b/src/Greenshot.Addons/Animation/EasePower.cs @@ -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 . + +#endregion + +#region using + +using System; + +#endregion + +namespace Greenshot.Addons.Animation +{ + /// + /// A supporting class to do Pow calculations for easing + /// + 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); + } + } +} \ No newline at end of file diff --git a/src/Greenshot.Addons/Animation/EaseSine.cs b/src/Greenshot.Addons/Animation/EaseSine.cs new file mode 100644 index 000000000..b220f48f6 --- /dev/null +++ b/src/Greenshot.Addons/Animation/EaseSine.cs @@ -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 . + +#endregion + +#region using + +using System; + +#endregion + +namespace Greenshot.Addons.Animation +{ + /// + /// This is a supporting class to do Sin calculations for the easing + /// + 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)); + } + } +} \ No newline at end of file diff --git a/src/Greenshot.Addons/Animation/Easing.cs b/src/Greenshot.Addons/Animation/Easing.cs index a20d38fa8..4e4633116 100644 --- a/src/Greenshot.Addons/Animation/Easing.cs +++ b/src/Greenshot.Addons/Animation/Easing.cs @@ -29,12 +29,19 @@ using System; namespace Greenshot.Addons.Animation { - /// - /// Easing logic, to make the animations more "fluent" - /// Adapted from here - /// - public static class Easing + /// + /// Easing logic, to make the animations more "fluent" + /// Adapted from here + /// + public static class Easing { + /// + /// Apply "ease" to ubfirnatuin + /// + /// double + /// double + /// double + /// double 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; } + /// + /// Apply ease in + /// + /// double + /// EasingTypes + /// double 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(); } + /// + /// Apply ease in-out + /// + /// double + /// EasingTypes + /// EasingTypes + /// double public static double EaseInOut(double linearStep, EasingTypes easeInType, EasingTypes easeOutType) { return linearStep < 0.5 ? EaseInOut(linearStep, easeInType) : EaseInOut(linearStep, easeOutType); } + /// + /// Apply easy in out + /// + /// double + /// EasingTypes + /// double 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) + /// + /// Apply easy out + /// + /// double + /// EasingTypes + /// double + 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); - } - } } } \ No newline at end of file diff --git a/src/Greenshot.Addons/Animation/EasingModes.cs b/src/Greenshot.Addons/Animation/EasingModes.cs index 9d7544fae..c7f61fd75 100644 --- a/src/Greenshot.Addons/Animation/EasingModes.cs +++ b/src/Greenshot.Addons/Animation/EasingModes.cs @@ -23,6 +23,9 @@ namespace Greenshot.Addons.Animation { + /// + /// Define the possible easing modes + /// public enum EasingModes { EaseIn, diff --git a/src/Greenshot.Addons/Animation/SizeAnimator.cs b/src/Greenshot.Addons/Animation/SizeAnimator.cs index 037a62912..d89b61f7e 100644 --- a/src/Greenshot.Addons/Animation/SizeAnimator.cs +++ b/src/Greenshot.Addons/Animation/SizeAnimator.cs @@ -23,7 +23,7 @@ #region using -using System.Drawing; +using Dapplo.Windows.Common.Structs; #endregion @@ -32,18 +32,18 @@ namespace Greenshot.Addons.Animation /// /// Implementation of the SizeAnimator /// - public class SizeAnimator : AnimatorBase + public class SizeAnimator : AnimatorBase { - 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) { } - /// - /// Calculate the next frame values - /// - /// Size - public override Size Next() + /// + /// Calculate the next frame values + /// + /// NativeSize + 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; } } diff --git a/src/Greenshot.Addons/Greenshot.Addons.csproj b/src/Greenshot.Addons/Greenshot.Addons.csproj index 08cd1d951..f3d1ade53 100644 --- a/src/Greenshot.Addons/Greenshot.Addons.csproj +++ b/src/Greenshot.Addons/Greenshot.Addons.csproj @@ -155,6 +155,8 @@ + + diff --git a/src/Greenshot/Forms/CaptureForm.cs b/src/Greenshot/Forms/CaptureForm.cs index ee2885b37..8a0a2929a 100644 --- a/src/Greenshot/Forms/CaptureForm.cs +++ b/src/Greenshot/Forms/CaptureForm.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 /// /// /// - private Point FixMouseCoordinates(Point currentMouse) + private Point FixMouseCoordinates(NativePoint currentMouse) { switch (_fixMode) { @@ -455,9 +455,10 @@ namespace Greenshot.Forms /// 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); } /// @@ -709,7 +710,7 @@ namespace Greenshot.Forms /// PaintEventArgs protected override void OnPaintBackground(PaintEventArgs paintEventArgs) { - // Ignore the event, to reduct painting + // Ignore the event, to reduce painting } ///