From 94efe043778601572ad43af4f6373cbdcae5775b Mon Sep 17 00:00:00 2001 From: RKrom Date: Tue, 13 Nov 2012 08:19:41 +0000 Subject: [PATCH] Applied zoom patch, currently needs to be activated by pressing "Z" in the capture form. This will change later. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2272 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Forms/CaptureForm.cs | 38 +++++++++++ Greenshot/Forms/ZoomForm.cs | 114 +++++++++++++++++++++++++++++++++ Greenshot/Greenshot.csproj | 2 +- 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 Greenshot/Forms/ZoomForm.cs diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index 2b61e4913..7d9a3877c 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -61,6 +61,7 @@ namespace Greenshot.Forms { private Point previousMousePos = Point.Empty; private FixMode fixMode = FixMode.None; + private ZoomForm zoomForm = null; public Rectangle CaptureRectangle { get { @@ -91,6 +92,7 @@ namespace Greenshot.Forms { // clean up this.FormClosed += delegate { + RemoveZoom(); currentForm = null; LOG.Debug("Remove CaptureForm from currentForm"); }; @@ -127,6 +129,30 @@ namespace Greenshot.Forms { this.TopMost = true; } + private void CreateZoom() { + if (zoomForm == null) { + zoomForm = new ZoomForm(capture); + zoomForm.Show(); + WindowDetails.ToForeground(zoomForm.Handle); + + // Fix missing focus issue + WindowDetails.ToForeground(this.Handle); + this.TopMost = false; + zoomForm.TopMost = true; + Activate(); + } + } + + private void RemoveZoom() { + if (zoomForm != null) { + zoomForm.Close(); + // Fix missing focus issue + WindowDetails.ToForeground(this.Handle); + this.TopMost = true; + zoomForm = null; + } + } + #region key handling void CaptureFormKeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.ShiftKey) { @@ -148,6 +174,13 @@ namespace Greenshot.Forms { // Toggle mouse cursor capture.CursorVisible = !capture.CursorVisible; Invalidate(); + } else if (e.KeyCode == Keys.Z) { + // Toggle zoom + if (zoomForm == null) { + CreateZoom(); + } else { + RemoveZoom(); + } } else if (e.KeyCode == Keys.Space) { switch (captureMode) { case CaptureMode.Region: @@ -231,6 +264,11 @@ namespace Greenshot.Forms { bool horizontalMove = false; bool verticalMove = false; + // Change the zoom location + if (zoomForm != null) { + zoomForm.MouseLocation = cursorPos; + } + if (lastPos.X != cursorPos.X) { horizontalMove = true; } diff --git a/Greenshot/Forms/ZoomForm.cs b/Greenshot/Forms/ZoomForm.cs new file mode 100644 index 000000000..59dcdc875 --- /dev/null +++ b/Greenshot/Forms/ZoomForm.cs @@ -0,0 +1,114 @@ +/* + * 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.Collections.Generic; +using System.Windows.Forms; +using System.Drawing; +using Greenshot.Plugin; +using System.Drawing.Drawing2D; +using GreenshotPlugin.Controls; + +namespace Greenshot.Forms { + /// + /// This form will show the area around the mouse of the current capture + /// + public class ZoomForm : FormWithoutActivation { + private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ZoomForm)); + private ICapture captureToZoom = null; + private Point mouseLocation = Point.Empty; + + public ZoomForm(ICapture captureToZoom) { + InitializeComponent(); + this.captureToZoom = captureToZoom; + Zoom = 400; + } + + public Point MouseLocation { + get { + return mouseLocation; + } + set { + mouseLocation = value; + this.Location = new Point(mouseLocation.X + 20, mouseLocation.Y + 20); + this.Invalidate(); + } + } + + public int Zoom { + get; + set; + } + + protected override void OnPaint(PaintEventArgs e) { + if (captureToZoom == null || captureToZoom.Image == null) { + return; + } + Graphics graphics = e.Graphics; + graphics.SmoothingMode = SmoothingMode.None; + graphics.InterpolationMode = InterpolationMode.NearestNeighbor; + graphics.CompositingQuality = CompositingQuality.HighSpeed; + graphics.PixelOffsetMode = PixelOffsetMode.None; + Rectangle clipRectangle = e.ClipRectangle; + float zoom = (float)100 / (float)Zoom; + + int sourceWidth = (int)(Width * zoom); + int sourceHeight = (int)(Height * zoom); + Rectangle sourceRectangle = new Rectangle(MouseLocation.X - (sourceHeight / 2), MouseLocation.Y - (sourceHeight / 2), sourceWidth, sourceHeight); + Rectangle destinationRectangle = new Rectangle(0, 0, Width, Height); + graphics.DrawImage(captureToZoom.Image, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel); + + int pixelThickness = Zoom / 100; + using (Pen pen = new Pen(Color.Black, pixelThickness)) { + int halfWidth = (Width >> 1) - (pixelThickness >> 1); + int halfWidthEnd = (Width >> 1) - pixelThickness; + int halfHeight = (Height >> 1) - (pixelThickness >> 1); + int halfHeightEnd = (Height >> 1) - pixelThickness; + graphics.DrawLine(pen, halfWidth, 0, halfWidth, halfHeightEnd); + graphics.DrawLine(pen, halfWidth, halfHeightEnd + pixelThickness, halfWidth, Height); + graphics.DrawLine(pen, 0, halfHeight, halfWidthEnd, halfHeight); + graphics.DrawLine(pen, halfWidthEnd + pixelThickness, halfHeight, Width, halfHeight); + } + } + + private void InitializeComponent() { + this.SuspendLayout(); + // + // ZoomForm + // + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; + this.ClientSize = new System.Drawing.Size(100, 100); + this.ControlBox = false; + this.DoubleBuffered = true; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.MinimumSize = new Size(50, 50); + this.Name = "Zoom"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.TopMost = true; + this.ResumeLayout(false); + } + } +} diff --git a/Greenshot/Greenshot.csproj b/Greenshot/Greenshot.csproj index 14dfa0c6c..991c044fd 100644 --- a/Greenshot/Greenshot.csproj +++ b/Greenshot/Greenshot.csproj @@ -181,6 +181,7 @@ + @@ -206,7 +207,6 @@ -