<Serializable()> Public MustInherit Class GraphicBase
    Implements IDisposable
    ' グラフィックオブジェクトのベースクラス
    Dim _position As PointF ' オブジェクトの位置
    Dim _size As SizeF         ' オブジェクトの幅・高さ
    Dim _linecolor As Color            ' ペン
    Dim _fillcolor As Color      ' ブラシ

    Public Shared PreviewPen As New Pen(Color.Blue, 0.1F)
    Public Shared OutlinePen As New Pen(Color.Brown, 0.1F)

    Property Position() As PointF
        Get
            Return _position
        End Get
        Set(ByVal Value As PointF)
            _position = Value
        End Set
    End Property

    Property Size() As SizeF
        Get
            Return _size
        End Get
        Set(ByVal Value As SizeF)
            _size = Value
        End Set
    End Property

    Property LineColor() As Color
        Get
            Return _linecolor
        End Get
        Set(ByVal Value As Color)
            _linecolor = Value
        End Set
    End Property

    Property FillColor() As Color
        Get
            Return _fillcolor
        End Get
        Set(ByVal Value As Color)
            _fillcolor = Value
        End Set
    End Property

    Public Overridable Sub Dispose() Implements System.IDisposable.Dispose
    End Sub

    Protected Function GetRectangleF() As RectangleF
        ' 座標、幅・高さから四角形を作る
        ' 幅、高さが負にならないように調整
        Dim startpos As PointF = Position
        Dim sz As SizeF = Size
        If Size.Width < 0 Then
            startpos.X = Position.X + Size.Width
            sz.Width = -Size.Width
        End If
        If Size.Height >= 0 Then
            startpos.Y = Position.Y
            sz.Height = Size.Height
        Else
            startpos.Y = Position.Y + Size.Height
            sz.Height = -Size.Height
        End If
        Return New RectangleF(startpos, sz)
    End Function

    Public Overridable Function isHit(ByVal pos As PointF) As Boolean
        ' このオブジェクトが指定された座標とヒットするかを判定する
        Return GetRectangleF().Contains(pos)
    End Function

    Public Overridable Sub DrawOutline(ByVal g As Graphics)
        ' 選択中のアウトラインの描画
        Dim rc As RectangleF = GetRectangleF()
        g.DrawRectangle(OutlinePen, rc.X, rc.Y, rc.Width, rc.Height)
    End Sub

    Public MustOverride Sub Draw(ByVal g As Graphics, ByVal isPreview As Boolean)

End Class
