diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index a20ca29a5..8a9bce577 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 Size zoomSize = new Size(20, 20); - private bool isAnimating = true; + private AnimationHelper windowAnimator = new AnimationHelper(Rectangle.Empty, Rectangle.Empty, 0); + private AnimationHelper zoomAnimator; /// /// Property to access the selected capture rectangle @@ -178,6 +178,8 @@ namespace Greenshot.Forms { // Fix missing focus 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); if (timer != null) { timer.Interval = 30; timer.Tick += new EventHandler(timer_Tick); @@ -331,7 +333,7 @@ namespace Greenshot.Forms { void updateFrame() { Point lastPos = cursorPos.Clone(); cursorPos = mouseMovePos.Clone(); - if (lastPos.Equals(cursorPos) && !isAnimating) { + if (selectedCaptureWindow != null && lastPos.Equals(cursorPos) && !zoomAnimator.hasNext && !windowAnimator.hasNext) { return; } @@ -398,8 +400,8 @@ namespace Greenshot.Forms { // Here we correct for text-size // Calculate the size - int textForWidth = Math.Max(Math.Abs(mX - cursorPosOnBitmap.X), Math.Abs(mX - lastPos.X)); - int textForHeight = Math.Max(Math.Abs(mY - cursorPosOnBitmap.Y), Math.Abs(mY - lastPos.Y)); + int textForWidth = Math.Max(Math.Abs(mX - cursorPosOnBitmap.X), Math.Abs(mX - lastPosOnBitmap.X)); + int textForHeight = Math.Max(Math.Abs(mY - cursorPosOnBitmap.Y), Math.Abs(mY - lastPosOnBitmap.Y)); using (Font rulerFont = new Font(FontFamily.GenericSansSerif, 8)) { Size measureWidth = TextRenderer.MeasureText(textForWidth.ToString(), rulerFont); @@ -412,20 +414,23 @@ namespace Greenshot.Forms { Invalidate(invalidateRectangle); } else { if (captureMode == CaptureMode.Window) { + // Using a 50 Pixel offset to the left, top, to make sure the text is invalidated too + const int SAFETY_SIZE = 25; + if (windowAnimator.hasNext) { + Rectangle invalidateRectangle = windowAnimator.Current; + invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE); + Invalidate(invalidateRectangle); + invalidateRectangle = windowAnimator.Next(); + invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE); + Invalidate(invalidateRectangle); + } if (selectedCaptureWindow != null && !selectedCaptureWindow.Equals(lastWindow)) { - // Using a 50 Pixel offset to the left, top, to make sure the text is invalidated too - const int SAFETY_SIZE = 50; + windowAnimator = new AnimationHelper(lastCaptureRect,captureRect, 5); Rectangle invalidateRectangle = new Rectangle(lastCaptureRect.Location, lastCaptureRect.Size); - invalidateRectangle.X -= SAFETY_SIZE/2; - invalidateRectangle.Y -= SAFETY_SIZE/2; - invalidateRectangle.Width += SAFETY_SIZE; - invalidateRectangle.Height += SAFETY_SIZE; + invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE); Invalidate(invalidateRectangle); invalidateRectangle = new Rectangle(captureRect.Location, captureRect.Size); - invalidateRectangle.X -= SAFETY_SIZE/2; - invalidateRectangle.Y -= SAFETY_SIZE/2; - invalidateRectangle.Width += SAFETY_SIZE; - invalidateRectangle.Height += SAFETY_SIZE; + invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE); Invalidate(invalidateRectangle); } } else { @@ -446,19 +451,23 @@ namespace Greenshot.Forms { } } if (isZooming && captureMode != CaptureMode.Window) { - Invalidate(ZoomArea(lastPos, zoomSize)); - if (zoomSize.Width < 200) { - zoomSize.Width += (220-zoomSize.Width)/5; - zoomSize.Height += (220-zoomSize.Height)/5; - } else { - isAnimating = false; - } - Invalidate(ZoomArea(cursorPos, zoomSize)); - } + Invalidate(ZoomArea(lastPos, zoomAnimator.Current.Size)); + Invalidate(ZoomArea(cursorPos, zoomAnimator.Next().Size)); + + // TODO: Check what this should accomplish + //if (zoomSize.Width < 200) { + // zoomSize.Width += (220-zoomSize.Width)/5; + // zoomSize.Height += (220-zoomSize.Height)/5; + //} } // Force update "now" Update(); } + /// + /// Get the absolute location for the supplied screen location + /// + /// + /// Absolute location private Point GetAbsoluteLocation(Point screenLocation) { Point ret = screenLocation.Clone(); ret.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y); @@ -520,41 +529,30 @@ namespace Greenshot.Forms { path.AddEllipse(destinationRectangle); using (Region clipRegion = new Region(path)) { graphics.Clip = clipRegion; - graphics.FillRectangle(backgroundBrush,destinationRectangle); + graphics.FillRectangle(backgroundBrush, destinationRectangle); graphics.DrawImage(capturedImage, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel); } } int pixelThickness = destinationRectangle.Width / sourceRectangle.Width; - using (Pen pen = new Pen(Color.White, 1)) { - using(Brush brush = new SolidBrush(Color.Black)) { - int halfWidth = destinationRectangle.Width / 2; - int halfWidthEnd = (destinationRectangle.Width / 2) - (pixelThickness / 2); - int halfHeight = destinationRectangle.Height / 2; - int halfHeightEnd = (destinationRectangle.Height / 2) - (pixelThickness / 2); - - int drawAtHeight = destinationRectangle.Y + halfHeight - (pixelThickness / 2); - int drawAtWidth = destinationRectangle.X + halfWidth - (pixelThickness / 2); - int padding = pixelThickness; - - // Vertical top to middle - graphics.FillRectangle(brush, drawAtWidth, destinationRectangle.Y + padding, pixelThickness, halfHeightEnd - 2*padding); - graphics.DrawRectangle(pen, drawAtWidth, destinationRectangle.Y + padding, pixelThickness, halfHeightEnd - 2*padding); - // Vertical middle + 1 to bottom - graphics.FillRectangle(brush, drawAtWidth, destinationRectangle.Y + halfHeightEnd + pixelThickness + padding, pixelThickness, halfHeightEnd - 2*padding); - graphics.DrawRectangle(pen, drawAtWidth, destinationRectangle.Y + halfHeightEnd + pixelThickness + padding, pixelThickness, halfHeightEnd - 2*padding); - // Horizontal left to middle - graphics.FillRectangle(brush, destinationRectangle.X + padding, drawAtHeight, halfWidthEnd - 2*padding, pixelThickness); - graphics.DrawRectangle(pen, destinationRectangle.X + padding, drawAtHeight, halfWidthEnd - 2*padding, pixelThickness); - // Horizontal middle + 1 to right - graphics.FillRectangle(brush, destinationRectangle.X + halfWidthEnd + pixelThickness + padding, drawAtHeight, halfWidthEnd - 2*padding, pixelThickness); - graphics.DrawRectangle(pen, destinationRectangle.X + halfWidthEnd + pixelThickness + padding, drawAtHeight, halfWidthEnd - 2*padding, pixelThickness); - - pen.Width = 2; - graphics.DrawEllipse(pen, destinationRectangle); - } + using (Pen pen = new Pen(Color.Black, pixelThickness)) { + int halfWidth = destinationRectangle.Width / 2; + int halfWidthEnd = (destinationRectangle.Width / 2) - (pixelThickness / 2); + int halfHeight = destinationRectangle.Height / 2; + int halfHeightEnd = (destinationRectangle.Height / 2) - (pixelThickness / 2); + + int drawAtHeight = destinationRectangle.Y + halfHeight; + int drawAtWidth = destinationRectangle.X + halfWidth; + + // Vertical top to middle + graphics.DrawLine(pen, drawAtWidth, destinationRectangle.Y, drawAtWidth, destinationRectangle.Y + halfHeightEnd); + // Vertical middle + 1 to bottom + graphics.DrawLine(pen, drawAtWidth, destinationRectangle.Y + halfHeightEnd + pixelThickness, drawAtWidth, destinationRectangle.Y + destinationRectangle.Height); + // Horizontal left to middle + graphics.DrawLine(pen, destinationRectangle.X, drawAtHeight, destinationRectangle.X + halfWidthEnd, drawAtHeight); + // Horizontal middle + 1 to right + graphics.DrawLine(pen, destinationRectangle.X + halfWidthEnd + pixelThickness, drawAtHeight, destinationRectangle.X + destinationRectangle.Width, drawAtHeight); } - } /// @@ -574,7 +572,14 @@ namespace Greenshot.Forms { if (mouseDown || captureMode == CaptureMode.Window) { captureRect.Intersect(new Rectangle(Point.Empty, capture.ScreenBounds.Size)); // crop what is outside the screen - Rectangle fixedRect = new Rectangle( captureRect.X, captureRect.Y, captureRect.Width, captureRect.Height ); + + Rectangle fixedRect; + if (captureMode == CaptureMode.Window) { + fixedRect = windowAnimator.Current; + } else { + fixedRect = new Rectangle( captureRect.X, captureRect.Y, captureRect.Width, captureRect.Height); + } + if (capture.CaptureDetails.CaptureMode == CaptureMode.Video) { graphics.FillRectangle(RedOverlayBrush, fixedRect); } else { @@ -698,7 +703,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, zoomSize)); + DrawZoom(graphics, sourceRectangle, ZoomArea(cursorPos, zoomAnimator.Current.Size)); } } diff --git a/Greenshot/Greenshot.csproj b/Greenshot/Greenshot.csproj index 5ba3d9966..b1477aaf1 100644 --- a/Greenshot/Greenshot.csproj +++ b/Greenshot/Greenshot.csproj @@ -180,6 +180,7 @@ MovableShowColorForm.cs + diff --git a/Greenshot/Helpers/AnimationHelper.cs b/Greenshot/Helpers/AnimationHelper.cs new file mode 100644 index 000000000..7fb627191 --- /dev/null +++ b/Greenshot/Helpers/AnimationHelper.cs @@ -0,0 +1,77 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/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 . + */ +using System; +using System.Drawing; +using System.Drawing.Drawing2D; + +namespace Greenshot.Helpers { + /// + /// Description of AnimationHelper. + /// + 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) { + this.first = first; + this.last = last; + this.frames = frames; + LOG.DebugFormat("First {0} Last {1} frames {2}", first, last, frames); + current = first; + } + + public Rectangle Current { + get { + return current; + } + } + + public bool hasNext { + get { + return currentFrame < frames; + } + } + + public 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); + int x = first.X + (int)(currentFrame * dx); + int y = first.Y + (int)(currentFrame * dy); + int width = first.Width + (int)(currentFrame * dw); + int height = first.Height + (int)(currentFrame * dh); + current = new Rectangle(x, y, width, height); + LOG.DebugFormat("frame {0} : {1}", currentFrame, current); + } + return current; + } + } +}