Skip to content

Commit

Permalink
View > Show extras > Smart Guides now implemented
Browse files Browse the repository at this point in the history
Relates to #498 .

Like Photoshop, PhotoDemon can now overlay lines on the main canvas (when moving or resizing layers).  These lines show you which edge(s) are being snapped and what they are being snapped to.

This feature can be toggled from the `View > Show extras > Smart Guides` menu.  It is enabled by default on new installs.
  • Loading branch information
tannerhelland committed Apr 23, 2024
1 parent c741cf6 commit 832e8d4
Show file tree
Hide file tree
Showing 4 changed files with 429 additions and 25 deletions.
45 changes: 45 additions & 0 deletions Modules/Drawing.bas
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,51 @@ Public Sub DrawLayerRotateNode(ByRef dstCanvas As pdCanvas, ByRef srcImage As pd

End Sub

Public Sub DrawSmartGuides(ByRef dstCanvas As pdCanvas, ByRef srcImage As pdImage)

'Drawing smart guides is *optional*
If (Not m_ShowSmartGuides) Then Exit Sub

Dim smartGuideLine() As PointFloat
ReDim smartGuideLine(0 To 1) As PointFloat

'Look for an active x-guide
If Snap.IsSnapped_X() Then

Snap.GetSnappedX_SmartGuide smartGuideLine(0), smartGuideLine(1)

'Convert the smart guidelines coordinates into viewport space
Drawing.ConvertListOfImageCoordsToCanvasCoords dstCanvas, srcImage, smartGuideLine, False

'Use pd2D to perform the render
Dim cSurface As pd2DSurface
Drawing2D.QuickCreateSurfaceFromDC cSurface, dstCanvas.hDC, True

PD2D.DrawLineF_FromPtF cSurface, m_PenUIBaseHighlight, smartGuideLine(0), smartGuideLine(1)
PD2D.DrawLineF_FromPtF cSurface, m_PenUITopHighlight, smartGuideLine(0), smartGuideLine(1)

Set cSurface = Nothing

End If

'Same for y
If Snap.IsSnapped_Y() Then

Snap.GetSnappedY_SmartGuide smartGuideLine(0), smartGuideLine(1)
Drawing.ConvertListOfImageCoordsToCanvasCoords dstCanvas, srcImage, smartGuideLine, False

'Dim cSurface As pd2DSurface
Drawing2D.QuickCreateSurfaceFromDC cSurface, dstCanvas.hDC, True

PD2D.DrawLineF_FromPtF cSurface, m_PenUIBaseHighlight, smartGuideLine(0), smartGuideLine(1)
PD2D.DrawLineF_FromPtF cSurface, m_PenUITopHighlight, smartGuideLine(0), smartGuideLine(1)

Set cSurface = Nothing

End If

End Sub

Public Function Get_ShowSmartGuides() As Boolean
Get_ShowSmartGuides = m_ShowSmartGuides
End Function
Expand Down
10 changes: 9 additions & 1 deletion Modules/MoveTool.bas
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Option Explicit
' of directly querying the associated UI elements.
Private m_DrawLayerBorders As Boolean, m_DrawCornerNodes As Boolean, m_DrawRotateNodes As Boolean

'Set to TRUE when LMB mouse is actively down; FALSE when LMB is not
Private m_LMBDown As Boolean

'Same goes for various selection-related move settings (for moving selected pixels). These are simple
' flags whose value is relayed from the Move/Size options panel.
Private m_SelectionDefaultCut As Boolean, m_SelectionSampleMerged As Boolean
Expand All @@ -31,6 +34,7 @@ Public Sub DrawCanvasUI(ByRef dstCanvas As pdCanvas, ByRef srcImage As pdImage,
If (Tools_Move.GetDrawLayerBorders() Or srcIsTextLayer) Then Drawing.DrawLayerBoundaries dstCanvas, srcImage, srcImage.GetActiveLayer
If (Tools_Move.GetDrawLayerCornerNodes() Or srcIsTextLayer) Then Drawing.DrawLayerCornerNodes dstCanvas, srcImage, srcImage.GetActiveLayer, curPOI
If (Tools_Move.GetDrawLayerRotateNodes() Or srcIsTextLayer) Then Drawing.DrawLayerRotateNode dstCanvas, srcImage, srcImage.GetActiveLayer, curPOI
If (m_LMBDown And Drawing.Get_ShowSmartGuides()) Then Drawing.DrawSmartGuides dstCanvas, srcImage
End Sub

Public Sub NotifyKeyDown(ByVal Shift As ShiftConstants, ByVal vkCode As Long, ByRef markEventHandled As Boolean)
Expand Down Expand Up @@ -143,6 +147,8 @@ Public Sub NotifyMouseDown(ByRef srcCanvas As pdCanvas, ByVal Shift As ShiftCons
'Failsafe check only
If (Not PDImages.IsImageActive) Then Exit Sub

m_LMBDown = True

'See if a selection is active. If it is, we need to see if the user has clicked within the selected region.
' (If they have, we will allow them to move just the *selected* pixels.)
Dim useSelectedPixels As Boolean: useSelectedPixels = False
Expand Down Expand Up @@ -294,7 +300,9 @@ Public Function NotifyMouseMove(ByVal lmbDown As Boolean, ByVal Shift As ShiftCo
End Function

Public Sub NotifyMouseUp(ByVal Button As PDMouseButtonConstants, ByVal Shift As ShiftConstants, ByVal imgX As Single, ByVal imgY As Single, ByVal numOfMouseMovements As Long)


m_LMBDown = False

'Pass a final transform request to the layer handler. This will initiate Undo/Redo creation, among other things.
If (numOfMouseMovements > 0) Then Tools.TransformCurrentLayer imgX, imgY, PDImages.GetActiveImage(), PDImages.GetActiveImage.GetActiveLayer, FormMain.MainCanvas(0), (Shift And vbShiftMask), True

Expand Down

0 comments on commit 832e8d4

Please sign in to comment.