File size: 15,500 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
'Copyright (C) 2002 Microsoft Corporation
'All rights reserved.
'
'THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
'EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
'MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
'Date: June 2002
'Author: Duncan Mackenzie
'
'Requires the release version of .NET Framework

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports DWSIM.Interfaces.Enums.GraphicObjects

Namespace GraphicObjects

    <Serializable()> _
    Public Class GraphicObjectCollection

        Inherits List(Of GraphicObject)

        Protected m_HorizRes As Integer = 72
        Protected m_VertRes As Integer = 72

        Public Sub DrawSelectedObject(ByVal g As Graphics, _
                ByVal selectedObject As GraphicObject, _
                ByVal Scale As Single)

            Dim gCon1, gCon2 As Drawing2D.GraphicsContainer

            gCon1 = g.BeginContainer

            g.ScaleTransform(Scale, Scale, _
                Drawing.Drawing2D.MatrixOrder.Append)

            gCon2 = g.BeginContainer

            g.PageUnit = GraphicsUnit.Pixel

            If Not selectedObject Is Nothing Then

                Dim hoverRect As New Rectangle
                With hoverRect
                    Select Case selectedObject.ObjectType
                        Case ObjectType.GO_Animation, ObjectType.GO_MasterTable, ObjectType.GO_Image, ObjectType.GO_Table, ObjectType.GO_FloatingTable, ObjectType.GO_Text, ObjectType.GO_SpreadsheetTable, ObjectType.GO_Rectangle
                            .X = selectedObject.X - 10
                            .Y = selectedObject.Y - 10
                            .Height = selectedObject.Height + 20
                            .Width = selectedObject.Width + 20
                            'Dim strdist As SizeF = g.MeasureString(selectedObject.Tag, New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel, 0, False), New PointF(0, 0), New StringFormat(StringFormatFlags.NoClip, 0))
                        Case Else
                            .X = selectedObject.X - 10
                            .Y = selectedObject.Y - 10
                            .Height = selectedObject.Height + 30
                            .Width = selectedObject.Width + 20
                            Dim strdist As SizeF = g.MeasureString(selectedObject.Tag, New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel, 0, False), New PointF(0, 0), New StringFormat(StringFormatFlags.NoClip, 0))
                            If strdist.Width > selectedObject.Width Then
                                .X = selectedObject.X + (selectedObject.Width - strdist.Width) / 2 - 10
                                .Width = strdist.Width + 20
                            End If
                    End Select
                End With

                Dim myOriginalMatrix As Drawing2D.Matrix
                myOriginalMatrix = g.Transform()
                If selectedObject.Rotation <> 0 Then
                    myOriginalMatrix.RotateAt(selectedObject.Rotation, New PointF(hoverRect.X + hoverRect.Width / 2, hoverRect.Y + hoverRect.Height / 2), _
                       Drawing2D.MatrixOrder.Append)
                    g.Transform = myOriginalMatrix
                End If
                g.PageUnit = GraphicsUnit.Pixel
                Dim color1, color2, color3 As Color
                color1 = Color.FromArgb(50, 130, 185, 200)
                color2 = Color.FromArgb(70, 2, 100, 130)
                color3 = Color.FromArgb(50, 2, 100, 130)
                If hoverRect.Width > 0 Then
                    Dim gbrush As New Drawing2D.LinearGradientBrush(hoverRect, color1, color2, LinearGradientMode.Vertical)
                    DrawRoundRect(g, New Pen(color3, 1), hoverRect.X, hoverRect.Y, hoverRect.Width, hoverRect.Height, 15, gbrush)
                    'g.Transform = myOriginalMatrix
                End If

            End If

            g.EndContainer(gCon2)
            g.EndContainer(gCon1)

        End Sub

        Public Sub DrawRoundRect(ByVal g As Graphics, ByVal p As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal radius As Integer, ByVal myBrush As Brush)

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

            Dim gp As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath

            gp.AddLine(x + radius, y, x + width - radius, y)
            gp.AddArc(x + width - radius, y, radius, radius, 270, 90)
            gp.AddLine(x + width, y + radius, x + width, y + height - radius)
            gp.AddArc(x + width - radius, y + height - radius, radius, radius, 0, 90)
            gp.AddLine(x + width - radius, y + height, x + radius, y + height)
            gp.AddArc(x, y + height - radius, radius, radius, 90, 90)
            gp.AddLine(x, y + height - radius, x, y + radius)
            gp.AddArc(x, y, radius, radius, 180, 90)

            gp.CloseFigure()

            g.DrawPath(p, gp)
            g.FillPath(myBrush, gp)

            gp.Dispose()

        End Sub

        Public Sub DrawObjects(ByVal g As Graphics, ByVal Scale As Single, transparent As Boolean)
            Dim drawObj As GraphicObject
            Dim i As Integer
            Dim gCon As Drawing2D.GraphicsContainer
            Dim myOriginalMatrix As Drawing2D.Matrix
            myOriginalMatrix = g.Transform()
            gCon = g.BeginContainer()
            g.PageUnit = GraphicsUnit.Pixel
            g.ScaleTransform(Scale, Scale)
            Dim oldlinecolor, oldfillcolor, oldgradcolor1, oldgradcolor2 As Color
            If Me.Count > 0 Then
                For i = 0 To Me.Count - 1
                    drawObj = CType(Me.Item(i), GraphicObject)
                    If drawObj.ObjectType = ObjectType.GO_Rectangle Then
                        If transparent And Not drawObj.Selected Then
                            With DirectCast(drawObj, RectangleGraphic)
                                oldlinecolor = .LineColor
                                oldfillcolor = .FillColor
                                oldgradcolor1 = .GradientColor1
                                oldgradcolor2 = .GradientColor2
                                .LineColor = Color.FromArgb(50, .LineColor)
                                .FillColor = Color.FromArgb(50, .FillColor)
                                .GradientColor1 = Color.FromArgb(50, .GradientColor1)
                                .GradientColor2 = Color.FromArgb(50, .GradientColor2)
                            End With
                        End If
                        If drawObj.DrawOverride IsNot Nothing Then
                            drawObj.DrawOverride.Invoke(g)
                        Else
                            drawObj.Draw(g)
                        End If
                        If transparent And Not drawObj.Selected Then
                            With DirectCast(drawObj, RectangleGraphic)
                                .LineColor = oldlinecolor
                                .FillColor = oldfillcolor
                                .GradientColor1 = oldgradcolor1
                                .GradientColor2 = oldgradcolor2
                            End With
                        End If
                    End If
                Next
                For i = 0 To Me.Count - 1
                    drawObj = CType(Me.Item(i), GraphicObject)
                    If drawObj.ObjectType = ObjectType.Nenhum Then
                        If TypeOf drawObj Is ShapeGraphic And transparent And Not drawObj.Selected Then
                            With DirectCast(drawObj, ShapeGraphic)
                                oldlinecolor = .LineColor
                                oldfillcolor = .FillColor
                                oldgradcolor1 = .GradientColor1
                                oldgradcolor2 = .GradientColor2
                                .LineColor = Color.FromArgb(50, .LineColor)
                                .FillColor = Color.FromArgb(50, .FillColor)
                                .GradientColor1 = Color.FromArgb(50, .GradientColor1)
                                .GradientColor2 = Color.FromArgb(50, .GradientColor2)
                                .SemiTransparent = True
                            End With
                        End If
                        If drawObj.ObjectType <> ObjectType.GO_Rectangle Then
                            If drawObj.DrawOverride IsNot Nothing Then
                                drawObj.DrawOverride.Invoke(g)
                            Else
                                drawObj.Draw(g)
                            End If
                        End If
                        If TypeOf drawObj Is ShapeGraphic And transparent And Not drawObj.Selected Then
                            With DirectCast(drawObj, ShapeGraphic)
                                .LineColor = oldlinecolor
                                .FillColor = oldfillcolor
                                .GradientColor1 = oldgradcolor1
                                .GradientColor2 = oldgradcolor2
                                .SemiTransparent = False
                            End With
                        End If
                    End If
                Next
                For i = 0 To Me.Count - 1
                    drawObj = CType(Me.Item(i), GraphicObject)
                    If drawObj.ObjectType <> Interfaces.Enums.GraphicObjects.ObjectType.Nenhum Then
                        If TypeOf drawObj Is ShapeGraphic And transparent And Not drawObj.Selected Then
                            With DirectCast(drawObj, ShapeGraphic)
                                oldlinecolor = .LineColor
                                oldfillcolor = .FillColor
                                oldgradcolor1 = .GradientColor1
                                oldgradcolor2 = .GradientColor2
                                .SemiTransparent = True
                            End With
                        End If
                        If drawObj.ObjectType <> ObjectType.GO_Rectangle Then
                            If drawObj.DrawOverride IsNot Nothing Then
                                drawObj.DrawOverride.Invoke(g)
                            Else
                                drawObj.Draw(g)
                            End If
                        End If
                        If TypeOf drawObj Is ShapeGraphic And transparent And Not drawObj.Selected Then
                            With DirectCast(drawObj, ShapeGraphic)
                                .LineColor = oldlinecolor
                                .FillColor = oldfillcolor
                                .GradientColor1 = oldgradcolor1
                                .GradientColor2 = oldgradcolor2
                                .SemiTransparent = False
                            End With
                        End If
                    End If
                Next
            End If
            g.EndContainer(gCon)
            g.Transform = myOriginalMatrix
        End Sub

        Public Sub PrintObjects(ByVal g As Graphics, ByVal dx As Integer, ByVal dy As Integer)
            Dim drawObj As GraphicObject
            Dim i As Integer
            g.PageUnit = GraphicsUnit.Pixel
            If Me.Count > 0 Then
                For i = 0 To Me.Count - 1
                    drawObj = CType(Me.Item(i), GraphicObject)
                    drawObj.X += dx
                    drawObj.Y += dy
                    drawObj.Draw(g)
                Next
                For i = 0 To Me.Count - 1
                    drawObj = CType(Me.Item(i), GraphicObject)
                    drawObj.X -= dx
                    drawObj.Y -= dy
                Next
            End If
        End Sub

        Public Function FindObjectAtPoint(ByVal pt As Point) As GraphicObject

            Dim objlist As New List(Of GraphicObject)

            Dim drawObj As GraphicObject
            Dim i As Integer
            If Me.Count > 0 Then
                For i = Me.Count - 1 To 0 Step -1
                    drawObj = CType(Me.Item(i), GraphicObject)
                    If drawObj.HitTest(pt.ToSDPoint) Then
                        objlist.Add(drawObj)
                    End If
                Next
            End If

            If objlist.Count > 1 Then
                For Each obj In objlist
                    If obj.ObjectType <> ObjectType.GO_Rectangle Then Return obj
                Next
            ElseIf objlist.Count = 1 Then
                Return objlist(0)
            Else
                Return Nothing
            End If
            Return Nothing

        End Function

        Public Function FindObjectWithName(ByVal name As String) As GraphicObject

            Dim drawObj As GraphicObject
            Dim i As Integer
            If Me.Count > 0 Then
                For i = Me.Count - 1 To 0 Step -1
                    drawObj = CType(Me.Item(i), GraphicObject)
                    If drawObj.Name = name Then
                        Return drawObj
                        Exit For
                    End If
                Next
            End If
            Return Nothing

        End Function

        Public Function FindObjectWithTag(ByVal tag As String) As GraphicObject

            Dim i As Integer
            If Me.Count > 0 Then
                For i = Me.Count - 1 To 0 Step -1
                    If Me.Item(i).Tag = tag Then
                        Return Me.Item(i)
                        Exit For
                    End If
                Next
            End If
            Return Nothing

        End Function

        Public Property HorizontalResolution() As Integer
            Get
                Return m_HorizRes
            End Get
            Set(ByVal Value As Integer)
                m_HorizRes = Value
            End Set
        End Property

        Public Property VerticalResolution() As Integer
            Get
                Return m_VertRes
            End Get
            Set(ByVal Value As Integer)
                m_VertRes = Value
            End Set
        End Property

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal value As GraphicObjectCollection)
            MyBase.New()
            Me.AddRange(value)
        End Sub

        Public Sub New(ByVal value() As GraphicObject)
            MyBase.New()
            Me.AddRange(value)
        End Sub

        Public Overloads Sub AddRange(ByVal value() As GraphicObject)
            Dim i As Integer = 0
            Do While (i < value.Length)
                Me.Add(value(i))
                i = (i + 1)
            Loop
        End Sub

        Public Overloads Sub AddRange(ByVal value As GraphicObjectCollection)
            Dim i As Integer = 0
            Do While (i < value.Count)
                Me.Add(value(i))
                i = (i + 1)
            Loop
        End Sub

    End Class

End Namespace