From 503a9daf6375d11081408db3ed7b15f31fa4b722 Mon Sep 17 00:00:00 2001 From: RKrom Date: Thu, 29 Nov 2012 15:17:44 +0000 Subject: [PATCH] Made changes to the animators, there now are different types but still all work linear. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2334 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Forms/CaptureForm.cs | 17 ++--- Greenshot/Helpers/AnimationHelper.cs | 93 +++++++++++++++++++++++----- 2 files changed, 87 insertions(+), 23 deletions(-) diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index 8641686d6..782c4ee02 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -71,8 +71,8 @@ namespace Greenshot.Forms { private bool isZooming = true; private Point previousMousePos = Point.Empty; private FixMode fixMode = FixMode.None; - private AnimationHelper windowAnimator = new AnimationHelper(Rectangle.Empty, Rectangle.Empty, 0); - private AnimationHelper zoomAnimator; + private RectangleAnimator windowAnimator = new RectangleAnimator(Rectangle.Empty, Rectangle.Empty, 0); + private SizeAnimator zoomAnimator; /// /// Property to access the selected capture rectangle @@ -179,7 +179,7 @@ namespace Greenshot.Forms { WindowDetails.ToForeground(this.Handle); this.TopMost = true; - zoomAnimator = new AnimationHelper(new Rectangle(Point.Empty, Size.Empty), new Rectangle(Point.Empty, new Size(200, 200)), 10); + zoomAnimator = new SizeAnimator(Size.Empty, new Size(200, 200), 10); if (timer != null) { timer.Interval = 30; timer.Tick += new EventHandler(timer_Tick); @@ -425,7 +425,7 @@ namespace Greenshot.Forms { Invalidate(invalidateRectangle); } if (selectedCaptureWindow != null && !selectedCaptureWindow.Equals(lastWindow)) { - windowAnimator = new AnimationHelper(lastCaptureRect,captureRect, 5); + windowAnimator = new RectangleAnimator(lastCaptureRect,captureRect, 5); Rectangle invalidateRectangle = new Rectangle(lastCaptureRect.Location, lastCaptureRect.Size); invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE); Invalidate(invalidateRectangle); @@ -451,8 +451,8 @@ namespace Greenshot.Forms { } } if (isZooming && captureMode != CaptureMode.Window) { - Invalidate(ZoomArea(lastPos, zoomAnimator.Current.Size)); - Invalidate(ZoomArea(cursorPos, zoomAnimator.Next().Size)); + Invalidate(ZoomArea(lastPos, zoomAnimator.Current)); + Invalidate(ZoomArea(cursorPos, zoomAnimator.Next())); // TODO: Move this to the Animator, but we need to check how to make sure we have an exact result. //if (zoomSize.Width < 200) { @@ -576,9 +576,10 @@ namespace Greenshot.Forms { Rectangle fixedRect; if (captureMode == CaptureMode.Window) { + // Use the animator fixedRect = windowAnimator.Current; } else { - fixedRect = new Rectangle( captureRect.X, captureRect.Y, captureRect.Width, captureRect.Height); + fixedRect = captureRect; } if (capture.CaptureDetails.CaptureMode == CaptureMode.Video) { @@ -711,7 +712,7 @@ namespace Greenshot.Forms { const int zoomSourceHeight = 25; Rectangle sourceRectangle = new Rectangle(cursorPosOnBitmap.X - (zoomSourceWidth / 2), cursorPosOnBitmap.Y - (zoomSourceHeight / 2), zoomSourceWidth, zoomSourceHeight); - DrawZoom(graphics, sourceRectangle, ZoomArea(cursorPos, zoomAnimator.Current.Size)); + DrawZoom(graphics, sourceRectangle, ZoomArea(cursorPos, zoomAnimator.Current)); } } diff --git a/Greenshot/Helpers/AnimationHelper.cs b/Greenshot/Helpers/AnimationHelper.cs index 7fb627191..aad833568 100644 --- a/Greenshot/Helpers/AnimationHelper.cs +++ b/Greenshot/Helpers/AnimationHelper.cs @@ -24,17 +24,18 @@ using System.Drawing.Drawing2D; namespace Greenshot.Helpers { /// - /// Description of AnimationHelper. + /// Base class for the animation logic, this only implements Properties and a constructor /// - public class AnimationHelper { - private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AnimationHelper)); - private Rectangle first; - private Rectangle last; - private Rectangle current; - private double frames; - private double currentFrame = 0; - - public AnimationHelper(Rectangle first, Rectangle last, int frames) { + /// Type for the animation, like Point/Rectangle/Size + public abstract class AnimatorBase { + private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AnimatorBase)); + protected T first; + protected T last; + protected T current; + protected double frames; + protected double currentFrame = 0; + + public AnimatorBase(T first, T last, int frames) { this.first = first; this.last = last; this.frames = frames; @@ -42,7 +43,7 @@ namespace Greenshot.Helpers { current = first; } - public Rectangle Current { + public T Current { get { return current; } @@ -54,16 +55,28 @@ namespace Greenshot.Helpers { } } - public Rectangle Next() { + public abstract T Next(); + } + + /// + /// Implementation of the RectangleAnimator + /// + public class RectangleAnimator : AnimatorBase { + private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(RectangleAnimator)); + + public RectangleAnimator(Rectangle first, Rectangle last, int frames) : base(first, last, frames) { + } + + public override Rectangle Next() { if (hasNext) { currentFrame++; - + double dx = (last.X - first.X) / frames; double dy = (last.Y - first.Y) / frames; double dw = (last.Width - first.Width) / frames; double dh = (last.Height - first.Height) / frames; - - LOG.DebugFormat("dx {0}, dy {1}, dw {2}, dh {3}", dx ,dy, dw, dh); + + LOG.DebugFormat("dx {0}, dy {1}, dw {2}, dh {3}", dx, dy, dw, dh); int x = first.X + (int)(currentFrame * dx); int y = first.Y + (int)(currentFrame * dy); int width = first.Width + (int)(currentFrame * dw); @@ -74,4 +87,54 @@ namespace Greenshot.Helpers { return current; } } + + /// + /// Implementation of the PointAnimator + /// + public class PointAnimator : AnimatorBase { + private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(RectangleAnimator)); + public PointAnimator(Point first, Point last, int frames) + : base(first, last, frames) { + } + public override Point Next() { + if (hasNext) { + currentFrame++; + + double dx = (last.X - first.X) / frames; + double dy = (last.Y - first.Y) / frames; + + LOG.DebugFormat("dx {0}, dy {1}", dx ,dy); + int x = first.X + (int)(currentFrame * dx); + int y = first.Y + (int)(currentFrame * dy); + current = new Point(x, y); + LOG.DebugFormat("frame {0} : {1}", currentFrame, current); + } + return current; + } + } + + /// + /// Implementation of the SizeAnimator + /// + public class SizeAnimator : AnimatorBase { + private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(RectangleAnimator)); + public SizeAnimator(Size first, Size last, int frames) + : base(first, last, frames) { + } + public override Size Next() { + if (hasNext) { + currentFrame++; + + double dw = (last.Width - first.Width) / frames; + double dh = (last.Height - first.Height) / frames; + + LOG.DebugFormat("dw {0}, dh {1}", dw, dh); + int width = first.Width + (int)(currentFrame * dw); + int height = first.Height + (int)(currentFrame * dh); + current = new Size(width, height); + LOG.DebugFormat("frame {0} : {1}", currentFrame, current); + } + return current; + } + } }