Merge pull request #282 from k41c/release/1.3

Add CTRL+Wheel zoom
This commit is contained in:
Robin Krom 2021-02-19 23:13:08 +01:00 committed by GitHub
commit cd5605d8ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 31 deletions

View file

@ -1,4 +1,4 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
@ -22,33 +22,49 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace GreenshotPlugin.Controls { namespace GreenshotPlugin.Controls
/// <summary> {
/// See: http://nickstips.wordpress.com/2010/03/03/c-panel-resets-scroll-position-after-focus-is-lost-and-regained/ /// <summary>
/// </summary> /// See: http://nickstips.wordpress.com/2010/03/03/c-panel-resets-scroll-position-after-focus-is-lost-and-regained/
public class NonJumpingPanel : Panel { /// </summary>
protected override Point ScrollToControl(Control activeControl) { public class NonJumpingPanel : Panel
// Returning the current location prevents the panel from {
// scrolling to the active control when the panel loses and regains focus protected override Point ScrollToControl(Control activeControl)
return DisplayRectangle.Location; {
} // Returning the current location prevents the panel from
// scrolling to the active control when the panel loses and regains focus
return DisplayRectangle.Location;
}
/// <summary> /// <summary>
/// Add horizontal scrolling to the panel, when using the wheel and the shift key is pressed /// Add horizontal scrolling to the panel, when using the wheel and the shift key is pressed
/// </summary> /// </summary>
/// <param name="e">MouseEventArgs</param> /// <param name="e">MouseEventArgs</param>
protected override void OnMouseWheel(MouseEventArgs e) protected override void OnMouseWheel(MouseEventArgs e)
{ {
if (VScroll && (ModifierKeys & Keys.Shift) == Keys.Shift) //Check if Scrollbars available and CTRL key pressed -> Zoom IN OUT
{ if ((VScroll || HScroll) && (ModifierKeys & Keys.Control) == Keys.Control)
VScroll = false; {
base.OnMouseWheel(e); VScroll = false;
VScroll = true; HScroll = false;
} base.OnMouseWheel(e);
else VScroll = true;
{ HScroll = true;
base.OnMouseWheel(e); }
} else
} {
} //Vertical Scoll with SHIFT key pressed
if (VScroll && (ModifierKeys & Keys.Shift) == Keys.Shift)
{
VScroll = false;
base.OnMouseWheel(e);
VScroll = true;
}
else
{
base.OnMouseWheel(e);
}
}
}
}
} }

View file

@ -66,6 +66,9 @@ namespace Greenshot {
// whether part of the editor controls are disabled depending on selected item(s) // whether part of the editor controls are disabled depending on selected item(s)
private bool _controlsDisabledDueToConfirmable; private bool _controlsDisabledDueToConfirmable;
// Used for tracking the mouse scrollwheel changes
private DateTime _zoomStartTime = DateTime.Now;
/// <summary> /// <summary>
/// All provided zoom values (in percents) in ascending order. /// All provided zoom values (in percents) in ascending order.
/// </summary> /// </summary>
@ -904,11 +907,33 @@ namespace Greenshot {
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void PanelMouseWheel(object sender, MouseEventArgs e) { /// <summary>
/// This is a "work-around" for the MouseWheel event which doesn't get to the panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PanelMouseWheel(object sender, MouseEventArgs e)
{
if (System.Windows.Forms.Control.ModifierKeys.Equals(Keys.Control))
{
if (_zoomStartTime.AddMilliseconds(100) < DateTime.Now) //waiting for next zoom step 100 ms
{
_zoomStartTime = DateTime.Now;
if (e.Delta > 0)
{
ZoomInMenuItemClick(sender, e);
}
else if (e.Delta < 0)
{
ZoomOutMenuItemClick(sender, e);
}
}
}
panel1.Focus(); panel1.Focus();
} }
protected override bool ProcessKeyPreview(ref Message msg) { protected override bool ProcessKeyPreview(ref Message msg) {
// disable default key handling if surface has requested a lock // disable default key handling if surface has requested a lock
if (!_surface.KeysLocked) { if (!_surface.KeysLocked) {
return base.ProcessKeyPreview(ref msg); return base.ProcessKeyPreview(ref msg);