File size: 5,242 Bytes
b1b3bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Imports System.Collections.Generic
Imports System.Linq
Imports System.Xml.Linq
Imports DWSIM.Interfaces
Imports Interfaces = DWSIM.Interfaces
Imports DWSIM.DrawingTools.Point
Imports DWSIM.Interfaces.Enums.GraphicObjects

Namespace GraphicObjects

    Public MustInherit Class GraphicObjectExtension

        Implements IGraphicObjectExtension, ICustomXMLSerialization

        Public Function GetPaint(color As SKColor)

            Dim p As New SKPaint

            With p
                .IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
                .Color = color
                .IsStroke = False
            End With

            Return p

        End Function

        Public Function GetStrokePaint(color As SKColor, StrokeWidth As Single)

            Dim p As New SKPaint

            With p
                .IsAntialias = GlobalSettings.Settings.DrawingAntiAlias
                .Color = color
                .IsStroke = True
                .StrokeWidth = StrokeWidth
            End With

            Return p

        End Function

        Public Function MeasureString(text As String, paint As SKPaint) As SKSize

            Dim trect As New SKRect(0, 0, 2, 2)
            paint.GetTextPath(text, 0, 0).GetBounds(trect)

            Return New SKSize(trect.Width, trect.Height)

        End Function

        Public Overridable Function LoadData(data As System.Collections.Generic.List(Of System.Xml.Linq.XElement)) As Boolean Implements ICustomXMLSerialization.LoadData

            XMLSerializer.XMLSerializer.Deserialize(Me, data)

            Return True

        End Function

        Public Overridable Function SaveData() As System.Collections.Generic.List(Of System.Xml.Linq.XElement) Implements ICustomXMLSerialization.SaveData

            Dim elements As List(Of XElement) = XMLSerializer.XMLSerializer.Serialize(Me)
            Dim ci As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture

            Return elements

        End Function

        Public Function GetBoundsRectangle() As SKRect
            Return New SKRect(Owner.X + RelativePosition.X, Owner.Y + RelativePosition.Y, Width, Height)
        End Function

        Public Shared Function ReturnInstance(typename As String) As IGraphicObjectExtension
            Dim t As Type = Type.GetType(typename, False)
            If Not t Is Nothing Then Return Activator.CreateInstance(t) Else Return Nothing
        End Function

#Region "Constructors"

        Public Sub New()

        End Sub

        Public Sub New(ByVal position As SKPoint, owner As IGraphicObject)

            Me.New()
            _relposition = New Point(position.X, position.Y)
            Me.Owner = owner

        End Sub

#End Region

        Public Sub DrawRoundRect(ByVal g As Object, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal radius As Integer, ByVal myBrush As SKPaint)

            If width / 2 < radius Then
                radius = width / 2 - 2
            ElseIf height / 2 < radius Then
                radius = height / 2 - 2
            End If

            Dim gp As SKPath = New SKPath()

            gp.AddRoundedRect(New SKRect(x, y, x + width, y + height), radius, radius, SKPathDirection.Clockwise)

            gp.Close()

            DirectCast(g, SKCanvas).DrawPath(gp, myBrush)

        End Sub

        Public Property Active As Boolean Implements IGraphicObjectExtension.Active

        Public Function Clone() As IGraphicObjectExtension Implements IGraphicObjectExtension.Clone
            Return Nothing
        End Function

        Public Property Description As String Implements IGraphicObjectExtension.Description

        Public MustOverride Sub Draw(surface As Object) Implements IGraphicObjectExtension.Draw

        Public Property Height As Integer Implements IGraphicObjectExtension.Height

        Public Function HitTest(zoomedSelection As Object) As Boolean Implements IGraphicObjectExtension.HitTest

            Dim rect As SKRect = DirectCast(zoomedSelection, SKRect)

            Return rect.Left <= Owner.X + RelativePosition.X And rect.Top <= Owner.Y + RelativePosition.Y And rect.Right >= Owner.X + RelativePosition.X + Width And rect.Bottom >= Owner.Y + RelativePosition.Y + Height

        End Function

        Public Property Name As String Implements IGraphicObjectExtension.Name

        Public Property Owner As IGraphicObject Implements IGraphicObjectExtension.Owner

        Private _relposition As New Point

        Public Property RelativePosition As IPoint Implements IGraphicObjectExtension.RelativePosition
            Get
                Return _relposition
            End Get
            Set(value As IPoint)
                _relposition = value
            End Set
        End Property

        Public Property Selected As Boolean Implements IGraphicObjectExtension.Selected

        Public Property Tag As String Implements IGraphicObjectExtension.Tag

        Public Property Width As Integer Implements IGraphicObjectExtension.Width

    End Class

End Namespace