Skip to content
Browse files

Merge pull request #47 from don-mccomb/bug1080302

[Fixes bug #1080302 and #1074877] Fix handling of key presses for Tools.
  • Loading branch information...
2 parents 3235aab + d981b46 commit f446bcc033f16c40b7c6ca91f31fad35818db630 @cameronwhite cameronwhite committed Dec 1, 2012
Showing with 53 additions and 21 deletions.
  1. +6 −12 Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs
  2. +1 −7 Pinta.Tools/Tools/CloneStampTool.cs
  3. +46 −2 Pinta/MainWindow.cs
View
18 Pinta.Gui.Widgets/Widgets/Canvas/PintaCanvas.cs
@@ -79,10 +79,6 @@ public PintaCanvas ()
if (PintaCore.Tools.CurrentTool != null)
PintaCore.Tools.CurrentTool.DoMouseMove (sender, e, point);
};
-
- // Handle key press/release events
- KeyPressEvent += new KeyPressEventHandler (PintaCanvas_KeyPressEvent);
- KeyReleaseEvent += new KeyReleaseEventHandler (PintaCanvas_KeyReleaseEvent);
}
#region Protected Methods
@@ -183,14 +179,7 @@ private void SetRequisition (Size size)
QueueResize ();
}
- [GLib.ConnectBefore]
- private void PintaCanvas_KeyReleaseEvent (object o, KeyReleaseEventArgs e)
- {
- PintaCore.Tools.CurrentTool.DoKeyRelease (this, e);
- }
-
- [GLib.ConnectBefore]
- private void PintaCanvas_KeyPressEvent (object o, KeyPressEventArgs e)
+ public void DoKeyPressEvent (object o, KeyPressEventArgs e)
{
// Give the current tool a chance to handle the key press
PintaCore.Tools.CurrentTool.DoKeyPress (this, e);
@@ -201,6 +190,11 @@ private void PintaCanvas_KeyPressEvent (object o, KeyPressEventArgs e)
PintaCore.Tools.SetCurrentTool (e.Event.Key);
}
+ public void DoKeyReleaseEvent (object o, KeyReleaseEventArgs e)
+ {
+ PintaCore.Tools.CurrentTool.DoKeyRelease (this, e);
+ }
+
/// <summary>
/// Filters out all modifier keys except Ctrl/Shift/Alt. This prevents Caps Lock, Num Lock, etc
/// from appearing as active modifier keys.
View
8 Pinta.Tools/Tools/CloneStampTool.cs
@@ -66,13 +66,7 @@ protected override void OnBuildToolBar(Gtk.Toolbar tb)
base.OnBuildToolBar(tb);
// Change the cursor when the BrushWidth is changed.
- brush_width.ComboBox.Changed += HandleBrushWidthComboBoxChanged;
- }
-
- void HandleBrushWidthComboBoxChanged (object sender, EventArgs e)
- {
- SetCursor (DefaultCursor);
- PintaCore.Chrome.Canvas.GrabFocus ();
+ brush_width.ComboBox.Changed += (sender, e) => SetCursor (DefaultCursor);
}
protected override void OnMouseDown (Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
View
48 Pinta/MainWindow.cs
@@ -40,7 +40,9 @@ public class MainWindow
ScrolledWindow sw;
DockFrame dock;
Menu show_pad;
-
+
+ CanvasPad canvas_pad;
+
ActionHandlers dialog_handlers;
public MainWindow ()
@@ -80,12 +82,54 @@ public MainWindow ()
window_shell.DeleteEvent += MainWindow_DeleteEvent;
window_shell.DragDataReceived += MainWindow_DragDataReceived;
+ window_shell.KeyPressEvent += MainWindow_KeyPressEvent;
+ window_shell.KeyReleaseEvent += MainWindow_KeyReleaseEvent;
+
// TODO: These need to be [re]moved when we redo zoom support
PintaCore.Actions.View.ZoomToWindow.Activated += new EventHandler (ZoomToWindow_Activated);
PintaCore.Actions.View.ZoomToSelection.Activated += new EventHandler (ZoomToSelection_Activated);
PintaCore.Workspace.ActiveDocumentChanged += ActiveDocumentChanged;
}
+ [GLib.ConnectBefore]
+ void MainWindow_KeyPressEvent (object o, KeyPressEventArgs e)
+ {
+ // Give the Canvas (and by extension the tools)
+ // first shot at handling the event if
+ // the mouse pointer is on the canvas
+ if (IsMouseOnCanvas() || canvas_pad.Canvas.HasFocus)
+ {
+ canvas_pad.Canvas.DoKeyPressEvent (o, e);
+ }
+ }
+
+ [GLib.ConnectBefore]
+ void MainWindow_KeyReleaseEvent (object o, KeyReleaseEventArgs e)
+ {
+ // Give the Canvas (and by extension the tools)
+ // first shot at handling the event if
+ // the mouse pointer is on the canvas
+ if (IsMouseOnCanvas() || canvas_pad.Canvas.HasFocus)
+ {
+ canvas_pad.Canvas.DoKeyReleaseEvent (o, e);
+ }
+ }
+
+ // Check if the mouse pointer is on the canvas
+ private bool IsMouseOnCanvas()
+ {
+ int x = 0;
+ int y = 0;
+
+ // Get the position of the mouse pointer relative
+ // to canvas scrolled window top-left corner
+ sw.GetPointer (out x, out y);
+
+ // Check if the pointer is on the canvas
+ return (x > 0) && (x < sw.Allocation.Width) &&
+ (y > 0) && (y < sw.Allocation.Height);
+ }
+
// Called when an extension node is added or removed
private void OnExtensionChanged (object s, ExtensionNodeEventArgs args)
{
@@ -227,7 +271,7 @@ private void CreateDockAndPads (HBox container)
palettepad.Initialize (dock, show_pad);
// Canvas pad
- var canvas_pad = new CanvasPad ();
+ canvas_pad = new CanvasPad ();
canvas_pad.Initialize (dock, show_pad);
sw = canvas_pad.ScrolledWindow;

0 comments on commit f446bcc

Please sign in to comment.
Something went wrong with that request. Please try again.