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,12 +22,15 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace GreenshotPlugin.Controls { namespace GreenshotPlugin.Controls
{
/// <summary> /// <summary>
/// See: http://nickstips.wordpress.com/2010/03/03/c-panel-resets-scroll-position-after-focus-is-lost-and-regained/ /// See: http://nickstips.wordpress.com/2010/03/03/c-panel-resets-scroll-position-after-focus-is-lost-and-regained/
/// </summary> /// </summary>
public class NonJumpingPanel : Panel { public class NonJumpingPanel : Panel
protected override Point ScrollToControl(Control activeControl) { {
protected override Point ScrollToControl(Control activeControl)
{
// Returning the current location prevents the panel from // Returning the current location prevents the panel from
// scrolling to the active control when the panel loses and regains focus // scrolling to the active control when the panel loses and regains focus
return DisplayRectangle.Location; return DisplayRectangle.Location;
@ -39,6 +42,18 @@ namespace GreenshotPlugin.Controls {
/// <param name="e">MouseEventArgs</param> /// <param name="e">MouseEventArgs</param>
protected override void OnMouseWheel(MouseEventArgs e) protected override void OnMouseWheel(MouseEventArgs e)
{ {
//Check if Scrollbars available and CTRL key pressed -> Zoom IN OUT
if ((VScroll || HScroll) && (ModifierKeys & Keys.Control) == Keys.Control)
{
VScroll = false;
HScroll = false;
base.OnMouseWheel(e);
VScroll = true;
HScroll = true;
}
else
{
//Vertical Scoll with SHIFT key pressed
if (VScroll && (ModifierKeys & Keys.Shift) == Keys.Shift) if (VScroll && (ModifierKeys & Keys.Shift) == Keys.Shift)
{ {
VScroll = false; VScroll = false;
@ -52,3 +67,4 @@ namespace GreenshotPlugin.Controls {
} }
} }
} }
}

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,7 +907,29 @@ 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();
} }