Added AnimationHelper to support the animations, this is still an initial form. Made the interactive mode work with this.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2331 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-11-28 21:25:46 +00:00
commit e8196928e1
3 changed files with 138 additions and 55 deletions

View file

@ -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;
/// <summary>
/// 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();
}
/// <summary>
/// Get the absolute location for the supplied screen location
/// </summary>
/// <param name="screenLocation"></param>
/// <returns>Absolute location</returns>
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);
}
}
/// <summary>
@ -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));
}
}

View file

@ -180,6 +180,7 @@
<DependentUpon>MovableShowColorForm.cs</DependentUpon>
</Compile>
<None Include="App.config" />
<Compile Include="Helpers\AnimationHelper.cs" />
<Compile Include="Helpers\AviHelper.cs" />
<Compile Include="Helpers\CaptureHelper.cs" />
<Compile Include="Helpers\Colors.cs" />

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Greenshot.Helpers {
/// <summary>
/// Description of AnimationHelper.
/// </summary>
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;
}
}
}