From 7d7cb0eee03afe9bfd331d4eee4815a55eb93a4e Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Tue, 23 Feb 2021 09:21:12 +0100 Subject: [PATCH] add extended line cap configuration --- Pilz.UI/PaintingControl/ArrowLineCapProps.vb | 15 +++++++++++++ .../PaintingControl/DefaultDrawMethodes.vb | 17 ++++++++++++--- .../PaintingControl/DefaultLineCapProps.vb | 13 ++++++++++++ .../LineCapConfigurationArgs.vb | 21 +++++++++++++++++++ Pilz.UI/PaintingControl/LineCapProps.vb | 7 +++++++ Pilz.UI/PaintingControl/PaintingObject.vb | 4 ++-- 6 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 Pilz.UI/PaintingControl/ArrowLineCapProps.vb create mode 100644 Pilz.UI/PaintingControl/DefaultLineCapProps.vb create mode 100644 Pilz.UI/PaintingControl/LineCapConfigurationArgs.vb create mode 100644 Pilz.UI/PaintingControl/LineCapProps.vb diff --git a/Pilz.UI/PaintingControl/ArrowLineCapProps.vb b/Pilz.UI/PaintingControl/ArrowLineCapProps.vb new file mode 100644 index 0000000..66b23aa --- /dev/null +++ b/Pilz.UI/PaintingControl/ArrowLineCapProps.vb @@ -0,0 +1,15 @@ +Imports System.Drawing +Imports System.Drawing.Drawing2D + +Public Class ArrowLineCapProps + Inherits LineCapProps + + Public Property Size As New Size(10, 10) + Public Property IsFilles As Boolean = True + + Friend Overrides Function Configure() As LineCapConfigurationArgs + Dim cap As New AdjustableArrowCap(Size.Width, Size.Height, IsFilles) + Return New LineCapConfigurationArgs(cap) + End Function + +End Class diff --git a/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb b/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb index a72d154..3f54473 100644 --- a/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb +++ b/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb @@ -113,10 +113,21 @@ Public Class DefaultDrawMethodes Public Shared Sub DrawLine(e As PaintingObjectPaintEventArgs) Dim obj As PaintingObject = e.PaintingObject Dim p2 As New Pen(obj.OutlineColor, obj.OutlineThicknes) With { - .DashStyle = obj.OutlineDashStyle, - .StartCap = obj.LineStartCap, - .EndCap = obj.LineEndCap + .DashStyle = obj.OutlineDashStyle } + + If obj.LineStartCap IsNot Nothing Then + Dim args As LineCapConfigurationArgs = obj.LineStartCap.Configure + p2.StartCap = args.LineCap + p2.CustomStartCap = args.CustomLineCap + End If + + If obj.LineEndCap IsNot Nothing Then + Dim args As LineCapConfigurationArgs = obj.LineEndCap.Configure + p2.EndCap = args.LineCap + p2.CustomEndCap = args.CustomLineCap + End If + p2.Alignment = PenAlignment.Center Dim no As PointF = New PointF(e.X, e.Y) e.Graphics.DrawLine(p2, no, no + obj.Size) diff --git a/Pilz.UI/PaintingControl/DefaultLineCapProps.vb b/Pilz.UI/PaintingControl/DefaultLineCapProps.vb new file mode 100644 index 0000000..eef0c92 --- /dev/null +++ b/Pilz.UI/PaintingControl/DefaultLineCapProps.vb @@ -0,0 +1,13 @@ +Imports System.Drawing.Drawing2D + +Public Class DefaultLineCapProps + Inherits LineCapProps + + Public Property LineCap As LineCap = LineCap.Flat + Public Property CustomLineCap As CustomLineCap = Nothing + + Friend Overrides Function Configure() As LineCapConfigurationArgs + Return New LineCapConfigurationArgs(LineCap, CustomLineCap) + End Function + +End Class diff --git a/Pilz.UI/PaintingControl/LineCapConfigurationArgs.vb b/Pilz.UI/PaintingControl/LineCapConfigurationArgs.vb new file mode 100644 index 0000000..2369439 --- /dev/null +++ b/Pilz.UI/PaintingControl/LineCapConfigurationArgs.vb @@ -0,0 +1,21 @@ +Imports System.Drawing.Drawing2D + +Public Class LineCapConfigurationArgs + + Public ReadOnly Property LineCap As LineCap + Public ReadOnly Property CustomLineCap As CustomLineCap + + Public Sub New(lineCap As LineCap) + Me.New(lineCap, Nothing) + End Sub + + Public Sub New(customLineCap As CustomLineCap) + Me.New(Nothing, customLineCap) + End Sub + + Public Sub New(lineCap As LineCap, customLineCap As CustomLineCap) + Me.LineCap = lineCap + Me.CustomLineCap = customLineCap + End Sub + +End Class diff --git a/Pilz.UI/PaintingControl/LineCapProps.vb b/Pilz.UI/PaintingControl/LineCapProps.vb new file mode 100644 index 0000000..6d48807 --- /dev/null +++ b/Pilz.UI/PaintingControl/LineCapProps.vb @@ -0,0 +1,7 @@ +Imports System.Drawing + +Public MustInherit Class LineCapProps + + Friend MustOverride Function Configure() As LineCapConfigurationArgs + +End Class diff --git a/Pilz.UI/PaintingControl/PaintingObject.vb b/Pilz.UI/PaintingControl/PaintingObject.vb index 6e35b35..8e430ee 100644 --- a/Pilz.UI/PaintingControl/PaintingObject.vb +++ b/Pilz.UI/PaintingControl/PaintingObject.vb @@ -19,8 +19,8 @@ Imports Newtonsoft.Json Public Property OutlineColor As Color = Color.DarkBlue Public Property OutlineThicknes As Single = 1 Public Property OutlineDashStyle As DashStyle = DashStyle.Solid - Public Property LineStartCap As LineCap = LineCap.Flat - Public Property LineEndCap As LineCap = LineCap.Flat + Public Property LineStartCap As LineCapProps = Nothing + Public Property LineEndCap As LineCapProps = Nothing Private _Text As String = "" Public Property TextPosition As TextPosition = TextPosition.FullCenter