'Written by Totem
Namespace GraphItems
'Un oggetto grafico qualsiasi
Public MustInherit Class GraphItemBase
Protected _Color As Color
Public Property Color() As Color
Get
Return _Color
End Get
Set(ByVal Value As Color)
_Color = Value
End Set
End Property
Public MustOverride Sub Draw(ByVal G As Graphics)
End Class
'Una linea
Public Class GraphLine
Inherits GraphItemBase
Private _PTo, _Position As Point
Public Property EndPoint() As Point
Get
Return _PTo
End Get
Set(ByVal Value As Point)
_PTo = Value
End Set
End Property
Public Overridable Property Position() As Point
Get
Return _Position
End Get
Set(ByVal Value As Point)
_Position = Value
End Set
End Property
Sub New(ByVal PFrom As Point, ByVal PTo As Point)
Me.Position = PFrom
Me.EndPoint = PTo
End Sub
'Date le coordinate in pixel, restituisce quelle in punti geometrici
Public Function GetRelativePosition(ByVal Center As Point) As Point
Return New Point(Position.X - Center.X, Center.Y - Position.Y)
End Function
'Date le coordinate in punti geometrici, restituisce quelle in pixel
Public Function GetAbsolutePosition(ByVal Center As Point) As Point
Return New Point(Center.X + Position.X, Center.Y - Position.Y)
End Function
Public Function GetRelativeEndPoint(ByVal Center As Point) As Point
Return New Point(EndPoint.X - Center.X, Center.Y - EndPoint.Y)
End Function
Public Function GetAbsoluteEndPoint(ByVal Center As Point) As Point
Return New Point(Center.X + EndPoint.X, Center.Y - EndPoint.Y)
End Function
Public Sub ToPixel(ByVal PixelsPerDot As Integer)
_Position = New Point(_Position.X * PixelsPerDot, _Position.Y * PixelsPerDot)
_PTo = New Point(_PTo.X * PixelsPerDot, _PTo.Y * PixelsPerDot)
End Sub
Public Overrides Sub Draw(ByVal G As Graphics)
G.DrawLine(New Pen(Me.Color), Position, EndPoint)
End Sub
Public Function Clone() As GraphLine
Return Me.MemberwiseClone()
End Function
End Class
'Una linea con maggiore percentuale di precisione
Public Class ExactGraphLine
Inherits GraphItemBase
Private _XFrom, _YFrom, _XTo, _YTo As Single
Public ReadOnly Property EndPoint() As Point
Get
Return New Point(_XTo, _YTo)
End Get
End Property
Public ReadOnly Property Position() As Point
Get
Return New Point(_XFrom, _YFrom)
End Get
End Property
Public Property StartX() As Single
Get
Return _XFrom
End Get
Set(ByVal Value As Single)
_XFrom = Value
End Set
End Property
Public Property StartY() As Single
Get
Return _YFrom
End Get
Set(ByVal Value As Single)
_YFrom = Value
End Set
End Property
Public Property EndX() As Single
Get
Return _XTo
End Get
Set(ByVal Value As Single)
_XTo = Value
End Set
End Property
Public Property EndY() As Single
Get
Return _YTo
End Get
Set(ByVal Value As Single)
_YTo = Value
End Set
End Property
Sub New(ByVal XFrom As Single, ByVal YFrom As Single, ByVal XTo As Single, ByVal YTo As Single)
_XFrom = XFrom
_XTo = XTo
_YFrom = YFrom
_YTo = YTo
End Sub
Public Sub SetRelativeEndPoint(ByVal Center As Point)
_XTo = _XTo - Center.X
_YTo = Center.Y - _YTo
End Sub
Public Sub SetRelativePosition(ByVal Center As Point)
_XFrom = _XFrom - Center.X
_YFrom = Center.Y - _YFrom
End Sub
Public Sub SetAbsoluteEndPoint(ByVal Center As Point)
_XTo = Center.X + _XTo
_YTo = Center.Y - _YTo
End Sub
Public Sub SetAbsolutePosition(ByVal center As Point)
_XFrom = center.X + _XFrom
_YFrom = center.Y - _YFrom
End Sub
Public Sub ToPixel(ByVal PixelsPerDot As Integer)
_XFrom *= PixelsPerDot
_YFrom *= PixelsPerDot
_XTo *= PixelsPerDot
_YTo *= PixelsPerDot
End Sub
Public Overrides Sub Draw(ByVal G As System.Drawing.Graphics)
G.DrawLine(New Pen(Me.Color), Position, EndPoint)
End Sub
Public Function Clone() As ExactGraphLine
Return Me.MemberwiseClone
End Function
End Class
Public Class GraphString
Inherits GraphItemBase
Private _Position As Point
Private _Text As String
Private _Font As Font
Public Property Position() As Point
Get
Return _Position
End Get
Set(ByVal Value As Point)
_Position = Value
End Set
End Property
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
If Value <> "" Then
_Text = Value
End If
End Set
End Property
Public Property Font() As Font
Get
Return _Font
End Get
Set(ByVal Value As Font)
If Value IsNot Nothing Then
_Font = Value
End If
End Set
End Property
Sub New(ByVal Position As Point, ByVal Text As String, ByVal Font As Font)
Me.Position = Position
Me.Text = Text
Me.Font = Font
End Sub
Public Overrides Sub Draw(ByVal G As System.Drawing.Graphics)
G.DrawString(Me.Text, Me.Font, Brushes.Black, Position.X, Position.Y)
End Sub
End Class
End Namespace