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
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
*
@ -22,33 +22,49 @@
using System.Drawing;
using System.Windows.Forms;
namespace GreenshotPlugin.Controls {
/// <summary>
/// See: http://nickstips.wordpress.com/2010/03/03/c-panel-resets-scroll-position-after-focus-is-lost-and-regained/
/// </summary>
public class NonJumpingPanel : Panel {
protected override Point ScrollToControl(Control activeControl) {
// Returning the current location prevents the panel from
// scrolling to the active control when the panel loses and regains focus
return DisplayRectangle.Location;
}
namespace GreenshotPlugin.Controls
{
/// <summary>
/// See: http://nickstips.wordpress.com/2010/03/03/c-panel-resets-scroll-position-after-focus-is-lost-and-regained/
/// </summary>
public class NonJumpingPanel : Panel
{
protected override Point ScrollToControl(Control activeControl)
{
// Returning the current location prevents the panel from
// scrolling to the active control when the panel loses and regains focus
return DisplayRectangle.Location;
}
/// <summary>
/// Add horizontal scrolling to the panel, when using the wheel and the shift key is pressed
/// </summary>
/// <param name="e">MouseEventArgs</param>
protected override void OnMouseWheel(MouseEventArgs e)
{
if (VScroll && (ModifierKeys & Keys.Shift) == Keys.Shift)
{
VScroll = false;
base.OnMouseWheel(e);
VScroll = true;
}
else
{
base.OnMouseWheel(e);
}
}
}
/// <summary>
/// Add horizontal scrolling to the panel, when using the wheel and the shift key is pressed
/// </summary>
/// <param name="e">MouseEventArgs</param>
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)
{
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)
private bool _controlsDisabledDueToConfirmable;
// Used for tracking the mouse scrollwheel changes
private DateTime _zoomStartTime = DateTime.Now;
/// <summary>
/// All provided zoom values (in percents) in ascending order.
/// </summary>
@ -904,11 +907,33 @@ namespace Greenshot {
/// </summary>
/// <param name="sender"></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();
}
protected override bool ProcessKeyPreview(ref Message msg) {
protected override bool ProcessKeyPreview(ref Message msg) {
// disable default key handling if surface has requested a lock
if (!_surface.KeysLocked) {
return base.ProcessKeyPreview(ref msg);