Skip to content

Commit

Permalink
Fix zooming with Ctrl-MouseWheel.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Jan 3, 2021
1 parent a441389 commit 478c2f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
19 changes: 19 additions & 0 deletions Pinta.Gui.Widgets/Widgets/Canvas/CanvasWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

using System;
using System.Diagnostics.CodeAnalysis;
using Gdk;
using Gtk;
using Pinta.Core;
using Pinta.Gui.Widgets;
Expand All @@ -34,6 +35,7 @@ namespace Pinta
{
public class CanvasWindow : Grid
{
private Document document;
private Ruler horizontal_ruler;
private Ruler vertical_ruler;
private ScrolledWindow scrolled_window;
Expand All @@ -43,6 +45,8 @@ public class CanvasWindow : Grid

public CanvasWindow (Document document)
{
this.document = document;

Build (document);

scrolled_window.Hadjustment.ValueChanged += UpdateRulerRange;
Expand Down Expand Up @@ -136,6 +140,8 @@ private void Build (Document document)
ShadowType = ShadowType.None
};

vp.ScrollEvent += ViewPort_ScrollEvent;

Canvas = new PintaCanvas (this, document) {
Name = "canvas",
CanDefault = true,
Expand Down Expand Up @@ -170,5 +176,18 @@ private void Build (Document document)
horizontal_ruler.Visible = false;
vertical_ruler.Visible = false;
}

private void ViewPort_ScrollEvent (object o, ScrollEventArgs args)
{
// Allow the user to zoom in/out with Ctrl-Mousewheel
if (args.Event.State.IsControlPressed () && args.Event.Direction == ScrollDirection.Smooth) {
if (args.Event.DeltaX > 0 || args.Event.DeltaY < 0)
document.Workspace.ZoomInFromMouseScroll (new Cairo.PointD (args.Event.X, args.Event.Y));
else if (args.Event.DeltaX < 0 || args.Event.DeltaY > 0)
document.Workspace.ZoomOutFromMouseScroll (new Cairo.PointD (args.Event.X, args.Event.Y));

args.RetVal = true;
}
}
}
}
34 changes: 0 additions & 34 deletions Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class PintaCanvas : DrawingArea
private readonly Document document;

private Cairo.ImageSurface? canvas;
private int h_scroll_amount = 92;

public CanvasWindow CanvasWindow { get; private set; }

Expand Down Expand Up @@ -159,39 +158,6 @@ protected override bool OnDrawn (Cairo.Context context)
return true;
}

protected override bool OnScrollEvent (EventScroll evnt)
{
// Allow the user to zoom in/out with Ctrl-Mousewheel
if (evnt.State.FilterModifierKeys () == ModifierType.ControlMask) {
switch (evnt.Direction) {
case ScrollDirection.Down:
case ScrollDirection.Right:
document.Workspace.ZoomOutFromMouseScroll (new Cairo.PointD (evnt.X, evnt.Y));
return true;
case ScrollDirection.Left:
case ScrollDirection.Up:
document.Workspace.ZoomInFromMouseScroll (new Cairo.PointD (evnt.X, evnt.Y));
return true;
}
}

// Allow the user to scroll left/right with Shift-Mousewheel
if (evnt.State.FilterModifierKeys () == ModifierType.ShiftMask) {
switch (evnt.Direction) {
case ScrollDirection.Down:
case ScrollDirection.Right:
document.Workspace.ScrollCanvas (h_scroll_amount, 0);
return true;
case ScrollDirection.Up:
case ScrollDirection.Left:
document.Workspace.ScrollCanvas (-h_scroll_amount, 0);
return true;
}
}

return base.OnScrollEvent (evnt);
}

private void SetRequisition (Size size)
{
WidthRequest = size.Width;
Expand Down

0 comments on commit 478c2f1

Please sign in to comment.