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
This commit is contained in:
RKrom 2012-11-29 15:17:44 +00:00
commit 503a9daf63
2 changed files with 87 additions and 23 deletions

View file

@ -71,8 +71,8 @@ namespace Greenshot.Forms {
private bool isZooming = true; private bool isZooming = true;
private Point previousMousePos = Point.Empty; private Point previousMousePos = Point.Empty;
private FixMode fixMode = FixMode.None; private FixMode fixMode = FixMode.None;
private AnimationHelper windowAnimator = new AnimationHelper(Rectangle.Empty, Rectangle.Empty, 0); private RectangleAnimator windowAnimator = new RectangleAnimator(Rectangle.Empty, Rectangle.Empty, 0);
private AnimationHelper zoomAnimator; private SizeAnimator zoomAnimator;
/// <summary> /// <summary>
/// Property to access the selected capture rectangle /// Property to access the selected capture rectangle
@ -179,7 +179,7 @@ namespace Greenshot.Forms {
WindowDetails.ToForeground(this.Handle); WindowDetails.ToForeground(this.Handle);
this.TopMost = true; 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) { if (timer != null) {
timer.Interval = 30; timer.Interval = 30;
timer.Tick += new EventHandler(timer_Tick); timer.Tick += new EventHandler(timer_Tick);
@ -425,7 +425,7 @@ namespace Greenshot.Forms {
Invalidate(invalidateRectangle); Invalidate(invalidateRectangle);
} }
if (selectedCaptureWindow != null && !selectedCaptureWindow.Equals(lastWindow)) { 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); Rectangle invalidateRectangle = new Rectangle(lastCaptureRect.Location, lastCaptureRect.Size);
invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE); invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE);
Invalidate(invalidateRectangle); Invalidate(invalidateRectangle);
@ -451,8 +451,8 @@ namespace Greenshot.Forms {
} }
} }
if (isZooming && captureMode != CaptureMode.Window) { if (isZooming && captureMode != CaptureMode.Window) {
Invalidate(ZoomArea(lastPos, zoomAnimator.Current.Size)); Invalidate(ZoomArea(lastPos, zoomAnimator.Current));
Invalidate(ZoomArea(cursorPos, zoomAnimator.Next().Size)); 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. // TODO: Move this to the Animator, but we need to check how to make sure we have an exact result.
//if (zoomSize.Width < 200) { //if (zoomSize.Width < 200) {
@ -576,9 +576,10 @@ namespace Greenshot.Forms {
Rectangle fixedRect; Rectangle fixedRect;
if (captureMode == CaptureMode.Window) { if (captureMode == CaptureMode.Window) {
// Use the animator
fixedRect = windowAnimator.Current; fixedRect = windowAnimator.Current;
} else { } else {
fixedRect = new Rectangle( captureRect.X, captureRect.Y, captureRect.Width, captureRect.Height); fixedRect = captureRect;
} }
if (capture.CaptureDetails.CaptureMode == CaptureMode.Video) { if (capture.CaptureDetails.CaptureMode == CaptureMode.Video) {
@ -711,7 +712,7 @@ namespace Greenshot.Forms {
const int zoomSourceHeight = 25; const int zoomSourceHeight = 25;
Rectangle sourceRectangle = new Rectangle(cursorPosOnBitmap.X - (zoomSourceWidth / 2), cursorPosOnBitmap.Y - (zoomSourceHeight / 2), zoomSourceWidth, zoomSourceHeight); 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));
} }
} }

View file

@ -24,17 +24,18 @@ using System.Drawing.Drawing2D;
namespace Greenshot.Helpers { namespace Greenshot.Helpers {
/// <summary> /// <summary>
/// Description of AnimationHelper. /// Base class for the animation logic, this only implements Properties and a constructor
/// </summary> /// </summary>
public class AnimationHelper { /// <typeparam name="T">Type for the animation, like Point/Rectangle/Size</typeparam>
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AnimationHelper)); public abstract class AnimatorBase<T> {
private Rectangle first; private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AnimatorBase<T>));
private Rectangle last; protected T first;
private Rectangle current; protected T last;
private double frames; protected T current;
private double currentFrame = 0; protected double frames;
protected double currentFrame = 0;
public AnimationHelper(Rectangle first, Rectangle last, int frames) {
public AnimatorBase(T first, T last, int frames) {
this.first = first; this.first = first;
this.last = last; this.last = last;
this.frames = frames; this.frames = frames;
@ -42,7 +43,7 @@ namespace Greenshot.Helpers {
current = first; current = first;
} }
public Rectangle Current { public T Current {
get { get {
return current; return current;
} }
@ -54,16 +55,28 @@ namespace Greenshot.Helpers {
} }
} }
public Rectangle Next() { public abstract T Next();
}
/// <summary>
/// Implementation of the RectangleAnimator
/// </summary>
public class RectangleAnimator : AnimatorBase<Rectangle> {
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) { if (hasNext) {
currentFrame++; currentFrame++;
double dx = (last.X - first.X) / frames; double dx = (last.X - first.X) / frames;
double dy = (last.Y - first.Y) / frames; double dy = (last.Y - first.Y) / frames;
double dw = (last.Width - first.Width) / frames; double dw = (last.Width - first.Width) / frames;
double dh = (last.Height - first.Height) / 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 x = first.X + (int)(currentFrame * dx);
int y = first.Y + (int)(currentFrame * dy); int y = first.Y + (int)(currentFrame * dy);
int width = first.Width + (int)(currentFrame * dw); int width = first.Width + (int)(currentFrame * dw);
@ -74,4 +87,54 @@ namespace Greenshot.Helpers {
return current; return current;
} }
} }
/// <summary>
/// Implementation of the PointAnimator
/// </summary>
public class PointAnimator : AnimatorBase<Point> {
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;
}
}
/// <summary>
/// Implementation of the SizeAnimator
/// </summary>
public class SizeAnimator : AnimatorBase<Size> {
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;
}
}
} }