Changes which calculate the amount of frames according to the time the animation should take, this makes the animation run equally long on all systems (independent of the refresh rate)

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2354 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-12-05 08:39:27 +00:00
commit 1ba5015305

View file

@ -49,6 +49,7 @@ namespace Greenshot.Forms {
private static Pen OverlayPen = new Pen(Color.FromArgb(50, Color.Black));
private static CaptureForm currentForm = null;
private static Brush backgroundBrush = null;
private static int vRefresh = 0;
static CaptureForm() {
Image backgroundForTransparency = GreenshotPlugin.Core.GreenshotResources.getImage("Checkerboard.Image");
@ -73,6 +74,30 @@ namespace Greenshot.Forms {
private RectangleAnimator windowAnimator = null;
private RectangleAnimator zoomAnimator = null;
/// <summary>
/// Vertical Refresh Rate
/// </summary>
private static int VRefresh {
get {
if (vRefresh == 0) {
// get te hDC of the desktop to get the VREFRESH
IntPtr hDCDesktop = User32.GetWindowDC(User32.GetDesktopWindow());
vRefresh = GDI32.GetDeviceCaps(hDCDesktop, DeviceCaps.VREFRESH);
User32.ReleaseDC(hDCDesktop);
}
return vRefresh;
}
}
/// <summary>
/// Calculate the amount of frames that an animation takes
/// </summary>
/// <param name="milliseconds"></param>
/// <returns></returns>
private static int calculateFrames(int milliseconds) {
return milliseconds / VRefresh;
}
/// <summary>
/// Property to access the selected capture rectangle
/// </summary>
@ -125,12 +150,6 @@ namespace Greenshot.Forms {
}
currentForm = this;
// get te hDC of the desktop to get the VREFRESH
IntPtr hDCDesktop = User32.GetWindowDC(User32.GetDesktopWindow());
int vRefesh = GDI32.GetDeviceCaps(hDCDesktop, DeviceCaps.VREFRESH);
User32.ReleaseDC(hDCDesktop);
LOG.DebugFormat("VRefresh {0}", vRefesh);
// comment this out if the timer should not be used
timer = new Timer();
@ -177,10 +196,10 @@ namespace Greenshot.Forms {
// Initialize the animations, the window capture zooms out from the cursor to the window under the cursor
if (captureMode == CaptureMode.Window) {
windowAnimator = new RectangleAnimator(new Rectangle(cursorPos, Size.Empty), captureRect, 10, EasingType.Quintic, EasingMode.EaseOut);
windowAnimator = new RectangleAnimator(new Rectangle(cursorPos, Size.Empty), captureRect, calculateFrames(700), EasingType.Quintic, EasingMode.EaseOut);
}
// Initialize the zoom with a invalid position
zoomAnimator = new RectangleAnimator(Rectangle.Empty, new Rectangle(int.MaxValue, int.MaxValue, 0, 0), 20, EasingType.Quintic, EasingMode.EaseOut);
zoomAnimator = new RectangleAnimator(Rectangle.Empty, new Rectangle(int.MaxValue, int.MaxValue, 0, 0), calculateFrames(1000), EasingType.Quintic, EasingMode.EaseOut);
VerifyZoomAnimation(cursorPos, false);
this.SuspendLayout();
this.Bounds = capture.ScreenBounds;
@ -191,7 +210,7 @@ namespace Greenshot.Forms {
this.TopMost = true;
if (timer != null) {
timer.Interval = 1000/vRefesh;
timer.Interval = 1000/VRefresh;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
@ -259,9 +278,9 @@ namespace Greenshot.Forms {
// Set the window capture mode
captureMode = CaptureMode.Window;
// "Fade out" Zoom
zoomAnimator.ChangeDestination(new Rectangle(Point.Empty, Size.Empty), 20);
zoomAnimator.ChangeDestination(new Rectangle(Point.Empty, Size.Empty));
// "Fade in" window
windowAnimator = new RectangleAnimator(new Rectangle(cursorPos, Size.Empty), captureRect, 10, EasingType.Quintic, EasingMode.EaseOut);
windowAnimator = new RectangleAnimator(new Rectangle(cursorPos, Size.Empty), captureRect, calculateFrames(700), EasingType.Quintic, EasingMode.EaseOut);
captureRect = Rectangle.Empty;
break;
case CaptureMode.Window:
@ -270,7 +289,7 @@ namespace Greenshot.Forms {
// "Fade out" window
windowAnimator.ChangeDestination(new Rectangle(cursorPos, Size.Empty));
// Fade in zoom
zoomAnimator = new RectangleAnimator(Rectangle.Empty, new Rectangle(int.MaxValue, int.MaxValue, 0, 0), 20, EasingType.Quintic, EasingMode.EaseOut);
zoomAnimator = new RectangleAnimator(Rectangle.Empty, new Rectangle(int.MaxValue, int.MaxValue, 0, 0), calculateFrames(1000), EasingType.Quintic, EasingMode.EaseOut);
VerifyZoomAnimation(cursorPos, false);
captureRect = Rectangle.Empty;
break;