Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
MGraphing - GraphItem.vb

GraphItem.vb

Caricato da: Totem
Scarica il programma completo

  1. 'Written by Totem
  2. Namespace GraphItems
  3.     'Un oggetto grafico qualsiasi
  4.     Public MustInherit Class GraphItemBase
  5.         Protected _Color As Color
  6.  
  7.         Public Property Color() As Color
  8.             Get
  9.                 Return _Color
  10.             End Get
  11.             Set(ByVal Value As Color)
  12.                 _Color = Value
  13.             End Set
  14.         End Property
  15.  
  16.         Public MustOverride Sub Draw(ByVal G As Graphics)
  17.     End Class
  18.  
  19.     'Una linea
  20.     Public Class GraphLine
  21.         Inherits GraphItemBase
  22.         Private _PTo, _Position As Point
  23.  
  24.         Public Property EndPoint() As Point
  25.             Get
  26.                 Return _PTo
  27.             End Get
  28.             Set(ByVal Value As Point)
  29.                 _PTo = Value
  30.             End Set
  31.         End Property
  32.  
  33.         Public Overridable Property Position() As Point
  34.             Get
  35.                 Return _Position
  36.             End Get
  37.             Set(ByVal Value As Point)
  38.                 _Position = Value
  39.             End Set
  40.         End Property
  41.  
  42.         Sub New(ByVal PFrom As Point, ByVal PTo As Point)
  43.             Me.Position = PFrom
  44.             Me.EndPoint = PTo
  45.         End Sub
  46.  
  47.         'Date le coordinate in pixel, restituisce quelle in punti geometrici
  48.         Public Function GetRelativePosition(ByVal Center As Point) As Point
  49.             Return New Point(Position.X - Center.X, Center.Y - Position.Y)
  50.         End Function
  51.  
  52.         'Date le coordinate in punti geometrici, restituisce quelle in pixel
  53.         Public Function GetAbsolutePosition(ByVal Center As Point) As Point
  54.             Return New Point(Center.X + Position.X, Center.Y - Position.Y)
  55.         End Function
  56.  
  57.         Public Function GetRelativeEndPoint(ByVal Center As Point) As Point
  58.             Return New Point(EndPoint.X - Center.X, Center.Y - EndPoint.Y)
  59.         End Function
  60.  
  61.         Public Function GetAbsoluteEndPoint(ByVal Center As Point) As Point
  62.             Return New Point(Center.X + EndPoint.X, Center.Y - EndPoint.Y)
  63.         End Function
  64.  
  65.         Public Sub ToPixel(ByVal PixelsPerDot As Integer)
  66.             _Position = New Point(_Position.X * PixelsPerDot, _Position.Y * PixelsPerDot)
  67.             _PTo = New Point(_PTo.X * PixelsPerDot, _PTo.Y * PixelsPerDot)
  68.         End Sub
  69.  
  70.         Public Overrides Sub Draw(ByVal G As Graphics)
  71.             G.DrawLine(New Pen(Me.Color), Position, EndPoint)
  72.         End Sub
  73.  
  74.         Public Function Clone() As GraphLine
  75.             Return Me.MemberwiseClone()
  76.         End Function
  77.     End Class
  78.  
  79.     'Una linea con maggiore percentuale di precisione
  80.     Public Class ExactGraphLine
  81.         Inherits GraphItemBase
  82.         Private _XFrom, _YFrom, _XTo, _YTo As Single
  83.  
  84.         Public ReadOnly Property EndPoint() As Point
  85.             Get
  86.                 Return New Point(_XTo, _YTo)
  87.             End Get
  88.         End Property
  89.  
  90.         Public ReadOnly Property Position() As Point
  91.             Get
  92.                 Return New Point(_XFrom, _YFrom)
  93.             End Get
  94.         End Property
  95.  
  96.         Public Property StartX() As Single
  97.             Get
  98.                 Return _XFrom
  99.             End Get
  100.             Set(ByVal Value As Single)
  101.                 _XFrom = Value
  102.             End Set
  103.         End Property
  104.  
  105.         Public Property StartY() As Single
  106.             Get
  107.                 Return _YFrom
  108.             End Get
  109.             Set(ByVal Value As Single)
  110.                 _YFrom = Value
  111.             End Set
  112.         End Property
  113.  
  114.         Public Property EndX() As Single
  115.             Get
  116.                 Return _XTo
  117.             End Get
  118.             Set(ByVal Value As Single)
  119.                 _XTo = Value
  120.             End Set
  121.         End Property
  122.  
  123.         Public Property EndY() As Single
  124.             Get
  125.                 Return _YTo
  126.             End Get
  127.             Set(ByVal Value As Single)
  128.                 _YTo = Value
  129.             End Set
  130.         End Property
  131.  
  132.         Sub New(ByVal XFrom As Single, ByVal YFrom As Single, ByVal XTo As Single, ByVal YTo As Single)
  133.             _XFrom = XFrom
  134.             _XTo = XTo
  135.             _YFrom = YFrom
  136.             _YTo = YTo
  137.         End Sub
  138.  
  139.         Public Sub SetRelativeEndPoint(ByVal Center As Point)
  140.             _XTo = _XTo - Center.X
  141.             _YTo = Center.Y - _YTo
  142.         End Sub
  143.  
  144.         Public Sub SetRelativePosition(ByVal Center As Point)
  145.             _XFrom = _XFrom - Center.X
  146.             _YFrom = Center.Y - _YFrom
  147.         End Sub
  148.  
  149.         Public Sub SetAbsoluteEndPoint(ByVal Center As Point)
  150.             _XTo = Center.X + _XTo
  151.             _YTo = Center.Y - _YTo
  152.         End Sub
  153.  
  154.         Public Sub SetAbsolutePosition(ByVal center As Point)
  155.             _XFrom = center.X + _XFrom
  156.             _YFrom = center.Y - _YFrom
  157.         End Sub
  158.  
  159.         Public Sub ToPixel(ByVal PixelsPerDot As Integer)
  160.             _XFrom *= PixelsPerDot
  161.             _YFrom *= PixelsPerDot
  162.             _XTo *= PixelsPerDot
  163.             _YTo *= PixelsPerDot
  164.         End Sub
  165.  
  166.         Public Overrides Sub Draw(ByVal G As System.Drawing.Graphics)
  167.             G.DrawLine(New Pen(Me.Color), Position, EndPoint)
  168.         End Sub
  169.  
  170.         Public Function Clone() As ExactGraphLine
  171.             Return Me.MemberwiseClone
  172.         End Function
  173.     End Class
  174.  
  175.     Public Class GraphString
  176.         Inherits GraphItemBase
  177.         Private _Position As Point
  178.         Private _Text As String
  179.         Private _Font As Font
  180.  
  181.         Public Property Position() As Point
  182.             Get
  183.                 Return _Position
  184.             End Get
  185.             Set(ByVal Value As Point)
  186.                 _Position = Value
  187.             End Set
  188.         End Property
  189.  
  190.         Public Property Text() As String
  191.             Get
  192.                 Return _Text
  193.             End Get
  194.             Set(ByVal Value As String)
  195.                 If Value <> "" Then
  196.                     _Text = Value
  197.                 End If
  198.             End Set
  199.         End Property
  200.  
  201.         Public Property Font() As Font
  202.             Get
  203.                 Return _Font
  204.             End Get
  205.             Set(ByVal Value As Font)
  206.                 If Value IsNot Nothing Then
  207.                     _Font = Value
  208.                 End If
  209.             End Set
  210.         End Property
  211.  
  212.         Sub New(ByVal Position As Point, ByVal Text As String, ByVal Font As Font)
  213.             Me.Position = Position
  214.             Me.Text = Text
  215.             Me.Font = Font
  216.         End Sub
  217.  
  218.         Public Overrides Sub Draw(ByVal G As System.Drawing.Graphics)
  219.             G.DrawString(Me.Text, Me.Font, Brushes.Black, Position.X, Position.Y)
  220.         End Sub
  221.     End Class
  222. End Namespace