mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
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:
parent
a1931b790d
commit
e8196928e1
3 changed files with 138 additions and 55 deletions
|
@ -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 Size zoomSize = new Size(20, 20);
|
private AnimationHelper windowAnimator = new AnimationHelper(Rectangle.Empty, Rectangle.Empty, 0);
|
||||||
private bool isAnimating = true;
|
private AnimationHelper zoomAnimator;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Property to access the selected capture rectangle
|
/// Property to access the selected capture rectangle
|
||||||
|
@ -178,6 +178,8 @@ namespace Greenshot.Forms {
|
||||||
// Fix missing focus
|
// Fix missing focus
|
||||||
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);
|
||||||
if (timer != null) {
|
if (timer != null) {
|
||||||
timer.Interval = 30;
|
timer.Interval = 30;
|
||||||
timer.Tick += new EventHandler(timer_Tick);
|
timer.Tick += new EventHandler(timer_Tick);
|
||||||
|
@ -331,7 +333,7 @@ namespace Greenshot.Forms {
|
||||||
void updateFrame() {
|
void updateFrame() {
|
||||||
Point lastPos = cursorPos.Clone();
|
Point lastPos = cursorPos.Clone();
|
||||||
cursorPos = mouseMovePos.Clone();
|
cursorPos = mouseMovePos.Clone();
|
||||||
if (lastPos.Equals(cursorPos) && !isAnimating) {
|
if (selectedCaptureWindow != null && lastPos.Equals(cursorPos) && !zoomAnimator.hasNext && !windowAnimator.hasNext) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,8 +400,8 @@ namespace Greenshot.Forms {
|
||||||
// Here we correct for text-size
|
// Here we correct for text-size
|
||||||
|
|
||||||
// Calculate the size
|
// Calculate the size
|
||||||
int textForWidth = Math.Max(Math.Abs(mX - cursorPosOnBitmap.X), Math.Abs(mX - lastPos.X));
|
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 - lastPos.Y));
|
int textForHeight = Math.Max(Math.Abs(mY - cursorPosOnBitmap.Y), Math.Abs(mY - lastPosOnBitmap.Y));
|
||||||
|
|
||||||
using (Font rulerFont = new Font(FontFamily.GenericSansSerif, 8)) {
|
using (Font rulerFont = new Font(FontFamily.GenericSansSerif, 8)) {
|
||||||
Size measureWidth = TextRenderer.MeasureText(textForWidth.ToString(), rulerFont);
|
Size measureWidth = TextRenderer.MeasureText(textForWidth.ToString(), rulerFont);
|
||||||
|
@ -412,20 +414,23 @@ namespace Greenshot.Forms {
|
||||||
Invalidate(invalidateRectangle);
|
Invalidate(invalidateRectangle);
|
||||||
} else {
|
} else {
|
||||||
if (captureMode == CaptureMode.Window) {
|
if (captureMode == CaptureMode.Window) {
|
||||||
if (selectedCaptureWindow != null && !selectedCaptureWindow.Equals(lastWindow)) {
|
|
||||||
// Using a 50 Pixel offset to the left, top, to make sure the text is invalidated too
|
// Using a 50 Pixel offset to the left, top, to make sure the text is invalidated too
|
||||||
const int SAFETY_SIZE = 50;
|
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)) {
|
||||||
|
windowAnimator = new AnimationHelper(lastCaptureRect,captureRect, 5);
|
||||||
Rectangle invalidateRectangle = new Rectangle(lastCaptureRect.Location, lastCaptureRect.Size);
|
Rectangle invalidateRectangle = new Rectangle(lastCaptureRect.Location, lastCaptureRect.Size);
|
||||||
invalidateRectangle.X -= SAFETY_SIZE/2;
|
invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE);
|
||||||
invalidateRectangle.Y -= SAFETY_SIZE/2;
|
|
||||||
invalidateRectangle.Width += SAFETY_SIZE;
|
|
||||||
invalidateRectangle.Height += SAFETY_SIZE;
|
|
||||||
Invalidate(invalidateRectangle);
|
Invalidate(invalidateRectangle);
|
||||||
invalidateRectangle = new Rectangle(captureRect.Location, captureRect.Size);
|
invalidateRectangle = new Rectangle(captureRect.Location, captureRect.Size);
|
||||||
invalidateRectangle.X -= SAFETY_SIZE/2;
|
invalidateRectangle.Inflate(SAFETY_SIZE, SAFETY_SIZE);
|
||||||
invalidateRectangle.Y -= SAFETY_SIZE/2;
|
|
||||||
invalidateRectangle.Width += SAFETY_SIZE;
|
|
||||||
invalidateRectangle.Height += SAFETY_SIZE;
|
|
||||||
Invalidate(invalidateRectangle);
|
Invalidate(invalidateRectangle);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -446,19 +451,23 @@ namespace Greenshot.Forms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isZooming && captureMode != CaptureMode.Window) {
|
if (isZooming && captureMode != CaptureMode.Window) {
|
||||||
Invalidate(ZoomArea(lastPos, zoomSize));
|
Invalidate(ZoomArea(lastPos, zoomAnimator.Current.Size));
|
||||||
if (zoomSize.Width < 200) {
|
Invalidate(ZoomArea(cursorPos, zoomAnimator.Next().Size));
|
||||||
zoomSize.Width += (220-zoomSize.Width)/5;
|
|
||||||
zoomSize.Height += (220-zoomSize.Height)/5;
|
// TODO: Check what this should accomplish
|
||||||
} else {
|
//if (zoomSize.Width < 200) {
|
||||||
isAnimating = false;
|
// zoomSize.Width += (220-zoomSize.Width)/5;
|
||||||
}
|
// zoomSize.Height += (220-zoomSize.Height)/5;
|
||||||
Invalidate(ZoomArea(cursorPos, zoomSize));
|
//} }
|
||||||
}
|
|
||||||
// Force update "now"
|
// Force update "now"
|
||||||
Update();
|
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) {
|
private Point GetAbsoluteLocation(Point screenLocation) {
|
||||||
Point ret = screenLocation.Clone();
|
Point ret = screenLocation.Clone();
|
||||||
ret.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y);
|
ret.Offset(-capture.ScreenBounds.X, -capture.ScreenBounds.Y);
|
||||||
|
@ -520,43 +529,32 @@ namespace Greenshot.Forms {
|
||||||
path.AddEllipse(destinationRectangle);
|
path.AddEllipse(destinationRectangle);
|
||||||
using (Region clipRegion = new Region(path)) {
|
using (Region clipRegion = new Region(path)) {
|
||||||
graphics.Clip = clipRegion;
|
graphics.Clip = clipRegion;
|
||||||
graphics.FillRectangle(backgroundBrush,destinationRectangle);
|
graphics.FillRectangle(backgroundBrush, destinationRectangle);
|
||||||
graphics.DrawImage(capturedImage, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel);
|
graphics.DrawImage(capturedImage, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int pixelThickness = destinationRectangle.Width / sourceRectangle.Width;
|
int pixelThickness = destinationRectangle.Width / sourceRectangle.Width;
|
||||||
using (Pen pen = new Pen(Color.White, 1)) {
|
using (Pen pen = new Pen(Color.Black, pixelThickness)) {
|
||||||
using(Brush brush = new SolidBrush(Color.Black)) {
|
|
||||||
int halfWidth = destinationRectangle.Width / 2;
|
int halfWidth = destinationRectangle.Width / 2;
|
||||||
int halfWidthEnd = (destinationRectangle.Width / 2) - (pixelThickness / 2);
|
int halfWidthEnd = (destinationRectangle.Width / 2) - (pixelThickness / 2);
|
||||||
int halfHeight = destinationRectangle.Height / 2;
|
int halfHeight = destinationRectangle.Height / 2;
|
||||||
int halfHeightEnd = (destinationRectangle.Height / 2) - (pixelThickness / 2);
|
int halfHeightEnd = (destinationRectangle.Height / 2) - (pixelThickness / 2);
|
||||||
|
|
||||||
int drawAtHeight = destinationRectangle.Y + halfHeight - (pixelThickness / 2);
|
int drawAtHeight = destinationRectangle.Y + halfHeight;
|
||||||
int drawAtWidth = destinationRectangle.X + halfWidth - (pixelThickness / 2);
|
int drawAtWidth = destinationRectangle.X + halfWidth;
|
||||||
int padding = pixelThickness;
|
|
||||||
|
|
||||||
// Vertical top to middle
|
// Vertical top to middle
|
||||||
graphics.FillRectangle(brush, drawAtWidth, destinationRectangle.Y + padding, pixelThickness, halfHeightEnd - 2*padding);
|
graphics.DrawLine(pen, drawAtWidth, destinationRectangle.Y, drawAtWidth, destinationRectangle.Y + halfHeightEnd);
|
||||||
graphics.DrawRectangle(pen, drawAtWidth, destinationRectangle.Y + padding, pixelThickness, halfHeightEnd - 2*padding);
|
|
||||||
// Vertical middle + 1 to bottom
|
// Vertical middle + 1 to bottom
|
||||||
graphics.FillRectangle(brush, drawAtWidth, destinationRectangle.Y + halfHeightEnd + pixelThickness + padding, pixelThickness, halfHeightEnd - 2*padding);
|
graphics.DrawLine(pen, drawAtWidth, destinationRectangle.Y + halfHeightEnd + pixelThickness, drawAtWidth, destinationRectangle.Y + destinationRectangle.Height);
|
||||||
graphics.DrawRectangle(pen, drawAtWidth, destinationRectangle.Y + halfHeightEnd + pixelThickness + padding, pixelThickness, halfHeightEnd - 2*padding);
|
|
||||||
// Horizontal left to middle
|
// Horizontal left to middle
|
||||||
graphics.FillRectangle(brush, destinationRectangle.X + padding, drawAtHeight, halfWidthEnd - 2*padding, pixelThickness);
|
graphics.DrawLine(pen, destinationRectangle.X, drawAtHeight, destinationRectangle.X + halfWidthEnd, drawAtHeight);
|
||||||
graphics.DrawRectangle(pen, destinationRectangle.X + padding, drawAtHeight, halfWidthEnd - 2*padding, pixelThickness);
|
|
||||||
// Horizontal middle + 1 to right
|
// Horizontal middle + 1 to right
|
||||||
graphics.FillRectangle(brush, destinationRectangle.X + halfWidthEnd + pixelThickness + padding, drawAtHeight, halfWidthEnd - 2*padding, pixelThickness);
|
graphics.DrawLine(pen, destinationRectangle.X + halfWidthEnd + pixelThickness, drawAtHeight, destinationRectangle.X + destinationRectangle.Width, drawAtHeight);
|
||||||
graphics.DrawRectangle(pen, destinationRectangle.X + halfWidthEnd + pixelThickness + padding, drawAtHeight, halfWidthEnd - 2*padding, pixelThickness);
|
|
||||||
|
|
||||||
pen.Width = 2;
|
|
||||||
graphics.DrawEllipse(pen, destinationRectangle);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Paint the actual visible parts
|
/// Paint the actual visible parts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -574,7 +572,14 @@ namespace Greenshot.Forms {
|
||||||
|
|
||||||
if (mouseDown || captureMode == CaptureMode.Window) {
|
if (mouseDown || captureMode == CaptureMode.Window) {
|
||||||
captureRect.Intersect(new Rectangle(Point.Empty, capture.ScreenBounds.Size)); // crop what is outside the screen
|
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) {
|
if (capture.CaptureDetails.CaptureMode == CaptureMode.Video) {
|
||||||
graphics.FillRectangle(RedOverlayBrush, fixedRect);
|
graphics.FillRectangle(RedOverlayBrush, fixedRect);
|
||||||
} else {
|
} else {
|
||||||
|
@ -698,7 +703,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, zoomSize));
|
DrawZoom(graphics, sourceRectangle, ZoomArea(cursorPos, zoomAnimator.Current.Size));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@
|
||||||
<DependentUpon>MovableShowColorForm.cs</DependentUpon>
|
<DependentUpon>MovableShowColorForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
<Compile Include="Helpers\AnimationHelper.cs" />
|
||||||
<Compile Include="Helpers\AviHelper.cs" />
|
<Compile Include="Helpers\AviHelper.cs" />
|
||||||
<Compile Include="Helpers\CaptureHelper.cs" />
|
<Compile Include="Helpers\CaptureHelper.cs" />
|
||||||
<Compile Include="Helpers\Colors.cs" />
|
<Compile Include="Helpers\Colors.cs" />
|
||||||
|
|
77
Greenshot/Helpers/AnimationHelper.cs
Normal file
77
Greenshot/Helpers/AnimationHelper.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue