Skip to content

Commit 39a39f4

Browse files
committed
Add arrow key support to Hand tool
For easier keyboard-based panning. This commit (working with changes in the last one) should also resolve the keyboard focus issues mentioned in #468. Thank you to @hi5 for catching and reporting!
1 parent 6476f40 commit 39a39f4

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

Controls/pdCanvas.ctl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,11 @@ Private Sub CanvasView_KeyDownCustom(ByVal Shift As ShiftConstants, ByVal vkCode
981981

982982
'Any further processing depends on which tool is currently active
983983
Select Case g_CurrentTool
984-
984+
985+
'Pan/zoom
986+
Case NAV_DRAG
987+
Tools_Move.NotifyKeyDown_HandTool Shift, vkCode, markEventHandled
988+
985989
'Move stuff around
986990
Case NAV_MOVE
987991
Tools_Move.NotifyKeyDown Shift, vkCode, markEventHandled
@@ -1035,7 +1039,7 @@ Private Sub CanvasView_KeyUpCustom(ByVal Shift As ShiftConstants, ByVal vkCode A
10351039

10361040
'Any further processing depends on which tool is currently active
10371041
Select Case g_CurrentTool
1038-
1042+
10391043
'Selection tools use a universal handler
10401044
Case SELECT_RECT, SELECT_CIRC, SELECT_POLYGON, SELECT_LASSO, SELECT_WAND
10411045
SelectionUI.NotifySelectionKeyUp Me, Shift, vkCode, markEventHandled
@@ -1059,6 +1063,10 @@ Private Sub CanvasView_KeyUpCustom(ByVal Shift As ShiftConstants, ByVal vkCode A
10591063

10601064
End Select
10611065

1066+
'Perform a special check for arrow keys. VB may attempt to use these to control on-form navigation,
1067+
' which we do not want.
1068+
If (vkCode = VK_UP) Or (vkCode = VK_DOWN) Or (vkCode = VK_LEFT) Or (vkCode = VK_RIGHT) Then markEventHandled = True
1069+
10621070
End If
10631071

10641072
End Sub
@@ -2527,7 +2535,7 @@ Public Sub SetCursorToCanvasPosition(ByVal newCanvasX As Double, ByVal newCanvas
25272535
End Sub
25282536

25292537
Public Sub SetFocusToCanvasView()
2530-
If CanvasView.Visible Then CanvasView.SetFocus
2538+
If CanvasView.Visible And (Not g_WindowManager Is Nothing) Then g_WindowManager.SetFocusAPI CanvasView.hWnd
25312539
End Sub
25322540

25332541
Private Sub BuildPopupMenu()

Modules/MoveTool.bas

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ Attribute VB_Name = "Tools_Move"
33
'PhotoDemon Move/Size Tool Manager
44
'Copyright 2014-2022 by Tanner Helland
55
'Created: 24/May/14
6-
'Last updated: 09/April/18
7-
'Last update: migrate move tool bits out of pdCanvas and into a dedicated module
6+
'Last updated: 22/December/22
7+
'Last update: add some trivial key-handling bits for the Hand tool (which is a different tool, but it has
8+
' so few features that it's easier to just condense things here)
89
'
910
'This module interfaces between the layer move/size UI and actual layer backend. Look in the relevant
1011
' tool panel form for more details on how the UI relays relevant tool data here.
@@ -110,6 +111,32 @@ Public Sub NotifyKeyDown(ByVal Shift As ShiftConstants, ByVal vkCode As Long, By
110111

111112
End Sub
112113

114+
'We also cover hand tool key behavior in this module, despite it being a separate tool.
115+
' (There is not currently a separate hand-tool module.)
116+
Public Sub NotifyKeyDown_HandTool(ByVal Shift As ShiftConstants, ByVal vkCode As Long, ByRef markEventHandled As Boolean)
117+
118+
'Handle arrow keys as standard scroll events.
119+
If (vkCode = VK_UP) Or (vkCode = VK_DOWN) Or (vkCode = VK_LEFT) Or (vkCode = VK_RIGHT) Then
120+
121+
'Set focus to the canvas (if it isn't already)
122+
FormMain.MainCanvas(0).SetFocusToCanvasView
123+
124+
If (vkCode = VK_UP) Then
125+
FormMain.MainCanvas(0).CanvasView_MouseWheelVertical 0&, 0&, FormMain.MainCanvas(0).GetLastMouseX, FormMain.MainCanvas(0).GetLastMouseY, 1#
126+
ElseIf (vkCode = VK_DOWN) Then
127+
FormMain.MainCanvas(0).CanvasView_MouseWheelVertical 0&, 0&, FormMain.MainCanvas(0).GetLastMouseX, FormMain.MainCanvas(0).GetLastMouseY, -1#
128+
ElseIf (vkCode = VK_LEFT) Then
129+
FormMain.MainCanvas(0).CanvasView_MouseWheelHorizontal 0&, 0&, FormMain.MainCanvas(0).GetLastMouseX, FormMain.MainCanvas(0).GetLastMouseY, -1#
130+
ElseIf (vkCode = VK_RIGHT) Then
131+
FormMain.MainCanvas(0).CanvasView_MouseWheelHorizontal 0&, 0&, FormMain.MainCanvas(0).GetLastMouseX, FormMain.MainCanvas(0).GetLastMouseY, 1#
132+
End If
133+
134+
markEventHandled = True
135+
136+
End If
137+
138+
End Sub
139+
113140
Public Sub NotifyMouseDown(ByRef srcCanvas As pdCanvas, ByVal Shift As ShiftConstants, ByVal imgX As Single, ByVal imgY As Single)
114141

115142
'Failsafe check only

PhotoDemon.vbp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ Description="PhotoDemon Photo Editor"
517517
CompatibleMode="0"
518518
MajorVer=9
519519
MinorVer=1
520-
RevisionVer=84
520+
RevisionVer=88
521521
AutoIncrementVer=1
522522
ServerSupportFiles=0
523523
VersionComments="Copyright 2000-2022 Tanner Helland - photodemon.org"

0 commit comments

Comments
 (0)