Skip to content

Commit

Permalink
Add precision cursor support to pencil tool
Browse files Browse the repository at this point in the history
Relates to #425

Still TODO is clone stamp tool, but it's a little more involved due to the "dual cursor" nature of the tool
  • Loading branch information
tannerhelland committed Aug 30, 2022
1 parent 3cc574a commit 7f46205
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion Modules/Clonestamp.bas
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,9 @@ Public Sub CommitBrushResults()

End Sub

'Render the current brush outline to the canvas, using the stored mouse coordinates as the brush's position
'Render the current brush outline to the canvas, using the stored mouse coordinates as the brush's position.
' (As of August 2022, Caps Lock can be used to toggle between precision and outline modes; this mimics Photoshop.
' See https://github.com/tannerhelland/PhotoDemon/issues/425 for details.)
Public Sub RenderBrushOutline(ByRef targetCanvas As pdCanvas)

'If a brush outline doesn't exist, create one now
Expand Down
34 changes: 25 additions & 9 deletions Modules/PencilTool.bas
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,19 @@ Public Sub RenderBrushOutline(ByRef targetCanvas As pdCanvas)
Dim brushTooSmall As Boolean
brushTooSmall = (onScreenSize < 7#)

'Like Photoshop, the CAPS LOCK key can be used to toggle between brush outlines and "precision" cursor mode.
' In "precision" mode, we only draw a target cursor.
Dim renderInPrecisionMode As Boolean
renderInPrecisionMode = brushTooSmall Or OS.IsVirtualKeyDown_Synchronous(VK_CAPITAL, True)

'Borrow a pair of UI pens from the main rendering module
Dim innerPen As pd2DPen, outerPen As pd2DPen
Drawing.BorrowCachedUIPens outerPen, innerPen

'Create other required pd2D drawing tools (a surface)
Dim cSurface As pd2DSurface
Drawing2D.QuickCreateSurfaceFromDC cSurface, targetCanvas.hDC, True
cSurface.SetSurfacePixelOffset P2_PO_Normal

'If the user is holding down the SHIFT key, paint a line between the end of the previous stroke and the current
' mouse position. This helps communicate that shift+clicking will string together separate strokes.
Expand All @@ -514,23 +520,33 @@ Public Sub RenderBrushOutline(ByRef targetCanvas As pdCanvas)
Else

'Paint a target cursor - but *only* if the mouse is not currently down!
Dim crossLength As Single, outerCrossBorder As Single
Dim crossLength As Single, crossDistanceFromCenter As Single, outerCrossBorder As Single
crossLength = 3!
outerCrossBorder = 0.5!
crossDistanceFromCenter = 4!
outerCrossBorder = 0.25!

If (Not m_MouseDown) And renderInPrecisionMode Then

If (Not m_MouseDown) Then
outerPen.SetPenLineCap P2_LC_Round
innerPen.SetPenLineCap P2_LC_Round
PD2D.DrawLineF cSurface, outerPen, cursX, cursY - crossLength - outerCrossBorder, cursX, cursY + crossLength + outerCrossBorder
PD2D.DrawLineF cSurface, outerPen, cursX - crossLength - outerCrossBorder, cursY, cursX + crossLength + outerCrossBorder, cursY
PD2D.DrawLineF cSurface, innerPen, cursX, cursY - crossLength, cursX, cursY + crossLength
PD2D.DrawLineF cSurface, innerPen, cursX - crossLength, cursY, cursX + crossLength, cursY

'Four "beneath" lines
PD2D.DrawLineF cSurface, outerPen, cursX, cursY - crossDistanceFromCenter + outerCrossBorder, cursX, cursY - crossDistanceFromCenter - crossLength - outerCrossBorder
PD2D.DrawLineF cSurface, outerPen, cursX, cursY + crossDistanceFromCenter - outerCrossBorder, cursX, cursY + crossDistanceFromCenter + crossLength + outerCrossBorder
PD2D.DrawLineF cSurface, outerPen, cursX - crossDistanceFromCenter + outerCrossBorder, cursY, cursX - crossDistanceFromCenter - crossLength - outerCrossBorder, cursY
PD2D.DrawLineF cSurface, outerPen, cursX + crossDistanceFromCenter - outerCrossBorder, cursY, cursX + crossDistanceFromCenter + crossLength + outerCrossBorder, cursY

'Four "above" lines
PD2D.DrawLineF cSurface, innerPen, cursX, cursY - crossDistanceFromCenter, cursX, cursY - crossDistanceFromCenter - crossLength
PD2D.DrawLineF cSurface, innerPen, cursX, cursY + crossDistanceFromCenter, cursX, cursY + crossDistanceFromCenter + crossLength
PD2D.DrawLineF cSurface, innerPen, cursX - crossDistanceFromCenter, cursY, cursX - crossDistanceFromCenter - crossLength, cursY
PD2D.DrawLineF cSurface, innerPen, cursX + crossDistanceFromCenter, cursY, cursX + crossDistanceFromCenter + crossLength, cursY

End If

End If

'If size allows, render a transformed brush outline onto the canvas as well
If (Not brushTooSmall) Then
If (Not renderInPrecisionMode) Then

'Get a copy of the current brush outline, transformed into position
Dim copyOfBrushOutline As pd2DPath
Expand Down
2 changes: 1 addition & 1 deletion PhotoDemon.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ Description="PhotoDemon Photo Editor"
CompatibleMode="0"
MajorVer=8
MinorVer=9
RevisionVer=1731
RevisionVer=1732
AutoIncrementVer=1
ServerSupportFiles=0
VersionComments="Copyright 2000-2022 Tanner Helland - photodemon.org"
Expand Down

0 comments on commit 7f46205

Please sign in to comment.