mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 10:47:02 -07:00
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
This commit is contained in:
parent
e84b6c8dd4
commit
94efe04377
3 changed files with 153 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
114
Greenshot/Forms/ZoomForm.cs
Normal file
114
Greenshot/Forms/ZoomForm.cs
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 {
|
||||
/// <summary>
|
||||
/// This form will show the area around the mouse of the current capture
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -181,6 +181,7 @@
|
|||
</Compile>
|
||||
<None Include="App.config" />
|
||||
<None Include="Helpers\AviHelper.cs" />
|
||||
<Compile Include="Forms\ZoomForm.cs" />
|
||||
<Compile Include="Helpers\CaptureHelper.cs" />
|
||||
<Compile Include="Helpers\Colors.cs" />
|
||||
<Compile Include="Helpers\CopyData.cs" />
|
||||
|
@ -206,7 +207,6 @@
|
|||
<Compile Include="Helpers\UpdateHelper.cs" />
|
||||
<Compile Include="Helpers\EnvironmentInfo.cs" />
|
||||
<Compile Include="Helpers\GuiRectangle.cs" />
|
||||
<Compile Include="Helpers\LogHelper.cs" />
|
||||
<Compile Include="Helpers\MailHelper.cs" />
|
||||
<Compile Include="Helpers\PluginHelper.cs" />
|
||||
<Compile Include="Helpers\PrintHelper.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue