Sub HitTest(SV2D As ScrollView2D, MovedButton As Button) As Boolean
' Check the movment against margins
Dim ViewLeft As Int = MovedButton.Left
Dim ViewTop As Int = MovedButton.Top
Dim ViewWidth As Int = MovedButton.Width
Dim ViewHeight As Int = MovedButton.Height
If ViewLeft < InnerMargin Then Return True
If ViewTop < InnerMargin Then Return True
If ViewLeft + ViewWidth > SV2D.Width - InnerMargin Then Return True
If ViewTop + ViewHeight > SV2D.Height - InnerMargin Then Return True
For x = 0 To SV2D.Panel.NumberOfViews - 1
Dim Left, Width, Height, Top As Int
Dim TempView As Button
TempView = SV2D.Panel.GetView(x)
If TempView = MovedButton Then Continue
' Add margins
Left = TempView.Left - InnerMargin
Top = TempView.Top - InnerMargin
Width = TempView.Width + (InnerMargin * 2) ' Add the left and right margin
Height = TempView.Height + (InnerMargin * 2) ' Add the top and bottom margin
' Check for hit in LeftTop corner
If ViewLeft > Left AND ViewLeft < (Left + Width) AND ViewTop > Top AND ViewTop < (Top + Height) Then Return True
' Check for hit in LeftBottom corner
If ViewLeft > Left AND ViewLeft < (Left + Width) AND (ViewTop + ViewHeight) > Top AND (ViewTop + ViewHeight) < (Top + Height) Then Return True
' Check for hit in RightTop corner
If (ViewLeft + ViewWidth) > Left AND (ViewLeft + ViewWidth) < (Left + Width) AND ViewTop > Top AND ViewTop < (Top + Height) Then Return True
' Check for hit in RightBottom corner
If (ViewLeft + ViewWidth) > Left AND (ViewLeft + ViewWidth) < (Left + Width) AND (ViewTop + ViewHeight) > Top AND (ViewTop + ViewHeight) < (Top + Height) Then Return True
Next
Return False
End Sub