Skip to content

Commit

Permalink
Port Arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
nikeee committed Oct 28, 2024
1 parent 3d6f803 commit 86640cc
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 160 deletions.
118 changes: 74 additions & 44 deletions src/HolzShots.Legacy/Drawing/Tools/Arrow.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ Imports HolzShots.UI.Controls

Namespace Drawing.Tools
Friend Class Arrow
Implements ITool(Of ToolSettingsBase)
Implements ITool(Of ArrowSettings)

Private _arrowFirstPoint As Vector2
Private _arrowSecondPoint As Vector2
Private ReadOnly _arrowDrawPoints(3) As Point
Const ArrowRotationConstant As Single = 2.2 * Math.PI / 1.2
Private _arrowBtwn2 As Vector2
Private _arrowBetween2 As Vector2

Private _beginCoordinates As Point
Public Property BeginCoordinates As Point Implements ITool(Of ToolSettingsBase).BeginCoordinates
Public Property BeginCoordinates As Point Implements ITool(Of ArrowSettings).BeginCoordinates
Get
Return _beginCoordinates
End Get
Expand All @@ -27,7 +27,7 @@ Namespace Drawing.Tools
End Property

Private _endCoordinates As Point
Public Property EndCoordinates As Point Implements ITool(Of ToolSettingsBase).EndCoordinates
Public Property EndCoordinates As Point Implements ITool(Of ArrowSettings).EndCoordinates
Get
Return _endCoordinates
End Get
Expand All @@ -40,65 +40,95 @@ Namespace Drawing.Tools
End Property

Private Shared ReadOnly TheCursor As New Cursor(My.Resources.crossMedium.GetHicon())
Public ReadOnly Property ToolType As PaintPanel.ShotEditorTool = PaintPanel.ShotEditorTool.Arrow Implements ITool(Of ToolSettingsBase).ToolType
Public ReadOnly Property Cursor As Cursor = TheCursor Implements ITool(Of ToolSettingsBase).Cursor
Public ReadOnly Property SettingsControl As ISettingsControl(Of ToolSettingsBase) = Nothing Implements ITool(Of ToolSettingsBase).SettingsControl
Public ReadOnly Property ToolType As PaintPanel.ShotEditorTool = PaintPanel.ShotEditorTool.Arrow Implements ITool(Of ArrowSettings).ToolType
Public ReadOnly Property Cursor As Cursor = TheCursor Implements ITool(Of ArrowSettings).Cursor
Private ReadOnly _settingsControl As ISettingsControl(Of ArrowSettings)
Public ReadOnly Property SettingsControl As ISettingsControl(Of ArrowSettings) Implements ITool(Of ArrowSettings).SettingsControl
Get
Return _settingsControl
End Get
End Property

Public Sub RenderFinalImage(ByRef rawImage As Image, sender As PaintPanel) Implements ITool(Of ToolSettingsBase).RenderFinalImage
If _arrowFirstPoint = Vector2.Zero OrElse _arrowSecondPoint = Vector2.Zero Then Return
Sub New()
Dim arrowWidth = Math.Clamp(My.Settings.ArrowWidth, ArrowSettings.MinimumWidth, ArrowSettings.MaximumWidth)
If arrowWidth <> My.Settings.ArrowWidth Then
My.Settings.ArrowWidth = arrowWidth
My.Settings.Save()
End If

Using g = Graphics.FromImage(rawImage)
g.SmoothingMode = SmoothingMode.AntiAlias
_settingsControl = New ArrowSettingsControl(
New ArrowSettings(
My.Settings.ArrowWidth,
My.Settings.ArrowColor
)
)
End Sub

Dim pen As New Pen(sender.ArrowColor) With {
.Width = If(sender.ArrowWidth <= 0, _arrowBtwn2.Length / 90, sender.ArrowWidth),
.EndCap = LineCap.Triangle,
Private Function CreatePen(settings As ArrowSettings, endCap As LineCap) As Pen
Return New Pen(settings.Color) With {
.Width = If(settings.Width <= 0, _arrowBetween2.Length / 90, settings.Width),
.EndCap = endCap,
.StartCap = LineCap.Round
}
End Function

g.DrawLine(pen, _arrowDrawPoints(0), _arrowDrawPoints(1))
pen.EndCap = LineCap.Round
g.DrawLine(pen, _arrowDrawPoints(1), _arrowDrawPoints(2))
g.DrawLine(pen, _arrowDrawPoints(1), _arrowDrawPoints(3))
Public Sub RenderFinalImage(ByRef rawImage As Image, sender As PaintPanel) Implements ITool(Of ArrowSettings).RenderFinalImage
If _arrowFirstPoint = Vector2.Zero OrElse _arrowSecondPoint = Vector2.Zero Then
Return
End If

Using g = Graphics.FromImage(rawImage)
g.SmoothingMode = SmoothingMode.AntiAlias

Using pen As Pen = CreatePen(_settingsControl.Settings, LineCap.Triangle)
g.DrawLine(pen, _arrowDrawPoints(0), _arrowDrawPoints(1))
pen.EndCap = LineCap.Round
g.DrawLine(pen, _arrowDrawPoints(1), _arrowDrawPoints(2))
g.DrawLine(pen, _arrowDrawPoints(1), _arrowDrawPoints(3))
End Using
End Using
End Sub

Public Sub RenderPreview(rawImage As Image, g As Graphics, sender As PaintPanel) Implements ITool(Of ToolSettingsBase).RenderPreview
Public Sub RenderPreview(rawImage As Image, g As Graphics, sender As PaintPanel) Implements ITool(Of ArrowSettings).RenderPreview

_arrowSecondPoint = New Vector2(EndCoordinates.X, EndCoordinates.Y)
If _arrowFirstPoint <> Vector2.Zero AndAlso _arrowSecondPoint <> Vector2.Zero Then
If _arrowFirstPoint <> _arrowSecondPoint Then
_arrowBtwn2 = _arrowSecondPoint - _arrowFirstPoint
Dim btwn = Vector2.Normalize(_arrowBtwn2) * _arrowBtwn2.Length / 5
Dim c = btwn.Rotate(ArrowRotationConstant) + _arrowFirstPoint
Dim d = btwn.Rotate(-ArrowRotationConstant) + _arrowFirstPoint
_arrowDrawPoints(0) = _arrowSecondPoint.ToPoint2D()
_arrowDrawPoints(1) = _arrowFirstPoint.ToPoint2D()
_arrowDrawPoints(2) = c.ToPoint2D()
_arrowDrawPoints(3) = d.ToPoint2D()

End If
If _arrowSecondPoint <> Vector2.Zero Then
g.SmoothingMode = SmoothingMode.AntiAlias
Dim pen As New Pen(sender.ArrowColor) With {
.Width = If(sender.ArrowWidth <= 0, _arrowBtwn2.Length / 90, sender.ArrowWidth),
.EndCap = LineCap.Round,
.StartCap = LineCap.Round
}
g.DrawLine(pen, _arrowDrawPoints(0), _arrowDrawPoints(1))
g.DrawLine(pen, _arrowDrawPoints(1), _arrowDrawPoints(2))
g.DrawLine(pen, _arrowDrawPoints(1), _arrowDrawPoints(3))
End If
If _arrowFirstPoint = Vector2.Zero OrElse _arrowSecondPoint = Vector2.Zero Then
Return
End If

If _arrowFirstPoint <> _arrowSecondPoint Then
_arrowBetween2 = _arrowSecondPoint - _arrowFirstPoint

Dim between = Vector2.Normalize(_arrowBetween2) * _arrowBetween2.Length / 5
Dim c = between.Rotate(ArrowRotationConstant) + _arrowFirstPoint
Dim d = between.Rotate(-ArrowRotationConstant) + _arrowFirstPoint
_arrowDrawPoints(0) = _arrowSecondPoint.ToPoint2D()
_arrowDrawPoints(1) = _arrowFirstPoint.ToPoint2D()
_arrowDrawPoints(2) = c.ToPoint2D()
_arrowDrawPoints(3) = d.ToPoint2D()

End If

If _arrowSecondPoint = Vector2.Zero Then
Return
End If

g.SmoothingMode = SmoothingMode.AntiAlias
Using pen As Pen = CreatePen(_settingsControl.Settings, LineCap.Round)
g.DrawLine(pen, _arrowDrawPoints(0), _arrowDrawPoints(1))
g.DrawLine(pen, _arrowDrawPoints(1), _arrowDrawPoints(2))
g.DrawLine(pen, _arrowDrawPoints(1), _arrowDrawPoints(3))
End Using
End Sub

Public Sub MouseOnlyMoved(rawImage As Image, ByRef currentCursor As Cursor, e As MouseEventArgs) Implements ITool(Of ToolSettingsBase).MouseOnlyMoved
Public Sub MouseOnlyMoved(rawImage As Image, ByRef currentCursor As Cursor, e As MouseEventArgs) Implements ITool(Of ArrowSettings).MouseOnlyMoved
' Nothing to do here
End Sub
Public Sub MouseClicked(rawImage As Image, e As Point, ByRef currentCursor As Cursor, trigger As Control) Implements ITool(Of ToolSettingsBase).MouseClicked
Public Sub MouseClicked(rawImage As Image, e As Point, ByRef currentCursor As Cursor, trigger As Control) Implements ITool(Of ArrowSettings).MouseClicked
' Nothing to do here
End Sub
Public Sub Dispose() Implements ITool(Of ToolSettingsBase).Dispose
Public Sub Dispose() Implements ITool(Of ArrowSettings).Dispose
End Sub
End Class
End Namespace
17 changes: 0 additions & 17 deletions src/HolzShots.Legacy/UI/Controls/PaintPanel.vb
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ Namespace UI.Controls
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Property EllipseColor As Color

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Property ArrowColor As Color

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Property ArrowWidth As Integer
Get
Return _arrowWidth
End Get
Set(value As Integer)
_arrowWidth = value
If CurrentTool = ShotEditorTool.Arrow Then
CurrentTool = ShotEditorTool.None
CurrentTool = ShotEditorTool.Arrow
End If
End Set
End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Property BrightenColor As Color

Expand Down
77 changes: 0 additions & 77 deletions src/HolzShots.Legacy/UI/ShotEditor.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions src/HolzShots.Legacy/UI/ShotEditor.vb
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ Namespace UI

EllipseSettingsPanel.BackColor = Color.Transparent
BrightenSettingsPanel.BackColor = Color.Transparent
ArrowSettingsPanel.BackColor = Color.Transparent
CurrentToolSettingsPanel.BackColor = Color.Transparent

Dim focusColor As Color = BackColor

BlackWhiteTracker.BackColor = focusColor
ArrowWidthSlider.BackColor = focusColor

EllipseBar.BackColor = focusColor
EllipseOrRectangle.BackColor = focusColor
Expand Down Expand Up @@ -143,7 +141,6 @@ Namespace UI
#Region "Settings and stuff"

Private Sub LoadToolSettings()
LoadArrow()
LoadEllipse()
LoadBrighten()
EnlistUploaderPlugins()
Expand All @@ -165,13 +162,6 @@ Namespace UI
End Sub


Private Sub LoadArrow()
ArrowColorviewer.Color = My.Settings.ArrowColor
ThePanel.ArrowColor = ArrowColorviewer.Color
ArrowWidthSlider.Value = Math.Clamp(My.Settings.ArrowWidth, ArrowWidthSlider.Minimum, ArrowWidthSlider.Maximum)
ArrowWidthSliderScroll()
End Sub

Private Sub LoadEllipse()
EllipseColorSelector.Color = HolzShots.My.Settings.EllipseColor
If HolzShots.My.Settings.EllipseWidth > 100 OrElse HolzShots.My.Settings.EllipseWidth <= 0 Then
Expand Down Expand Up @@ -271,8 +261,6 @@ Namespace UI

HolzShots.My.Settings.BrightenColor = BigColorViewer1.Color

HolzShots.My.Settings.ArrowColor = ArrowColorviewer.Color
HolzShots.My.Settings.ArrowWidth = ArrowWidthSlider.Value
HolzShots.My.Settings.UseBoxInsteadOfCirlce = ThePanel.UseBoxInsteadOfCircle

HolzShots.My.Settings.Save()
Expand All @@ -290,7 +278,6 @@ Namespace UI

Private Sub AddSettingsPanels()
_activator = New PanelActivator()
_activator.AddPanel(PaintPanel.ShotEditorTool.Arrow, ArrowSettingsPanel)
_activator.AddPanel(PaintPanel.ShotEditorTool.Brighten, BrightenSettingsPanel)
_activator.AddPanel(PaintPanel.ShotEditorTool.Ellipse, EllipseSettingsPanel)
_activator.AddPanel(PaintPanel.ShotEditorTool.LegacyNew, CurrentToolSettingsPanel)
Expand Down Expand Up @@ -451,19 +438,10 @@ Namespace UI
End If
End Sub

Private Sub ArrowColorViewerColorChanged(sender As Object, c As Color) Handles ArrowColorviewer.ColorChanged
ThePanel.ArrowColor = c
End Sub

Private Sub DrawCursorClick() Handles DrawCursor.Click
ThePanel.DrawCursor = DrawCursor.Checked
End Sub

Private Sub ArrowWidthSliderScroll() Handles ArrowWidthSlider.Scroll
ArrowWidthLabel.Text = If(ArrowWidthSlider.Value = 0, "Auto", $"{ArrowWidthSlider.Value}px")
ThePanel.ArrowWidth = ArrowWidthSlider.Value
End Sub

Private Sub ShotEditorResize() Handles Me.Resize
ThePanel.VerticalLinealBox.Invalidate()
ThePanel.HorizontalLinealBox.Invalidate()
Expand Down
Loading

0 comments on commit 86640cc

Please sign in to comment.