|
' (続き) 4/4
Partial Public MustInherit Class ContentSnakeBase
'////////Snake付帯情報
'輪郭線描画のためだけに必要な列挙体(Contentの連接方向を表す)
Public Enum Direction
None
Up
Down
Left
Right
End Enum
Private Function GetOppositeDirection(ByVal dr As Direction) As Direction
Select Case dr
Case Direction.None : Return Direction.None
Case Direction.Down : Return Direction.Up
Case Direction.Up : Return Direction.Down
Case Direction.Left : Return Direction.Right
Case Direction.Right : Return Direction.Left
End Select
End Function
'Content達を格納する2次元配列(実体は2重List)
Private AllContents As New TwoDimensionList(Of ContentWrapper)
'Snakeの軌跡を格納するStack
Private SnakeLocus As New Stack(Of ContentWrapper)
'Contentの付帯情報を保存するために用意したクラス
Public Class ContentWrapper
Public WithEvents Content As Control
Public XY As Point
Public PrevDir As Direction = Direction.None
Public NextDir As Direction = Direction.None
Public m_showborderline As Boolean = False
Public m_borderlinewidth As Integer = 5
Public m_borderlinecolor As Color = Color.Beige
Public Parent As ContentSnakeBase
'Contentの輪郭線を描画
Private Sub Content_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Content.Paint
'ContentSnakeBaseの派生クラスに描画処理のチャンスを与える
If Parent IsNot Nothing Then Parent.OnPaintContent(Me, e)
If m_showborderline = False Then Return
Dim c As Control = Me.Content
Dim w As Integer = Me.m_borderlinewidth
'↓連接部分の境界線の幅は narrow*2 になります。適宜変更してください
Dim narrow As Integer = 1
Dim br As New SolidBrush(Me.m_borderlinecolor)
Dim bback As New SolidBrush(c.BackColor)
Dim g As Graphics = e.Graphics
Dim r As Rectangle = c.ClientRectangle
'最初に、四方に太い輪郭線を描画
g.FillRectangle(br, 0, 0, r.Width, w)
g.FillRectangle(br, 0, r.Height - w, r.Width, w)
g.FillRectangle(br, 0, 0, w, r.Height)
g.FillRectangle(br, r.Width - w, 0, w, r.Height)
'次に、連接部分の境界線を細くする
For Each dr As Direction In New Direction() {PrevDir, NextDir}
Select Case dr
Case Direction.Up
g.FillRectangle(bback, w, narrow, r.Width - 2 * w, w - narrow)
Case Direction.Down
g.FillRectangle(bback, w, r.Height - w, r.Width - 2 * w, w - narrow)
Case Direction.Left
g.FillRectangle(bback, narrow, w, w - narrow, r.Height - 2 * w)
Case Direction.Right
g.FillRectangle(bback, r.Width - w, w, w - narrow, r.Height - 2 * w)
End Select
Next
br.Dispose()
bback.Dispose()
End Sub
End Class
'2次元配列を2重Listで代用
Private Class TwoDimensionList(Of T)
Private m_list As New List(Of List(Of T))
' 添え字オーバーを防止するために必要
Private Sub ensureIndexExists(ByVal x As Integer, ByVal y As Integer)
Do While m_list.Count < x + 1
m_list.Add(New List(Of T))
Loop
Dim li As List(Of T) = m_list.Item(x)
Do While li.Count < y + 1
li.Add(Nothing)
Loop
End Sub
Default Public Property Item(ByVal x As Integer, ByVal y As Integer) As T
Get
Me.ensureIndexExists(x, y)
Return m_list.Item(x).Item(y)
End Get
Set(ByVal value As T)
Me.ensureIndexExists(x, y)
m_list.Item(x).Item(y) = value
End Set
End Property
Public Sub ClearAll()
For Each li As List(Of T) In m_list
li.Clear()
Next
m_list.Clear()
End Sub
End Class
End Class
' (続く) 4/4
' 1回の投稿は10KB以内でなければならないようです。
|