73 lines
2.4 KiB
VB.net
73 lines
2.4 KiB
VB.net
Imports System.Drawing
|
|
Imports System.Windows.Forms
|
|
|
|
Public Class Animator
|
|
Public Const DEFAULT_FONT_OPACITY = 0.5
|
|
Public Const DEFAULT_FORM_SIZE = 30
|
|
Public Const DEFAULT_FORM_FADE_SPEED = 10
|
|
Public Const DEFAULT_FORM_FADE_INTERVAL = 250
|
|
|
|
Public Property FormSize As Integer
|
|
Public Property FadeInterval As Integer
|
|
Public Property FadeSpeed As Integer
|
|
Public Property FormOpacity As Double
|
|
Public Property FormColor As Color
|
|
|
|
Public Sub New()
|
|
_FormSize = DEFAULT_FORM_SIZE
|
|
_FadeSpeed = DEFAULT_FORM_FADE_SPEED
|
|
_FadeInterval = DEFAULT_FORM_FADE_INTERVAL
|
|
_FormOpacity = DEFAULT_FONT_OPACITY
|
|
_FormColor = Color.FromArgb(255, 214, 49)
|
|
End Sub
|
|
|
|
Public Sub Highlight(Position As Point)
|
|
Dim oForm = GetPopup(Position)
|
|
oForm.Show()
|
|
FadeIn(oForm, _FormOpacity, _FadeSpeed / 2)
|
|
Dim oTimer As New Timer With {.Interval = _FadeInterval}
|
|
AddHandler oTimer.Tick, Sub()
|
|
FadeOut(oForm, _FadeSpeed * 2)
|
|
oTimer.Stop()
|
|
End Sub
|
|
oTimer.Start()
|
|
End Sub
|
|
|
|
Private Function GetPopup(CursorPosition As Point) As frmPopup
|
|
Dim oFormLocation = New Point(CursorPosition.X - (_FormSize / 2), CursorPosition.Y - (_FormSize / 2))
|
|
Dim oFormSize = New Size(_FormSize, _FormSize)
|
|
|
|
Return New frmPopup() With {
|
|
.Location = oFormLocation,
|
|
.StartPosition = FormStartPosition.Manual,
|
|
.Size = oFormSize,
|
|
.MaximumSize = oFormSize,
|
|
.MinimumSize = oFormSize,
|
|
.Opacity = 0,
|
|
.ShowInTaskbar = False,
|
|
.BackColor = _FormColor
|
|
}
|
|
End Function
|
|
|
|
Private Async Sub FadeIn(ByVal o As Form, finalOpacity As Double, ByVal Optional interval As Integer = 80)
|
|
While o.Opacity < finalOpacity
|
|
Await Task.Delay(interval)
|
|
o.Opacity += 0.05
|
|
Debug.WriteLine("Fading in, Opacity: " & o.Opacity)
|
|
End While
|
|
|
|
o.Opacity = finalOpacity
|
|
End Sub
|
|
|
|
Private Async Sub FadeOut(ByVal o As Form, ByVal Optional interval As Integer = 80)
|
|
While o.Opacity > 0.0
|
|
Await Task.Delay(interval)
|
|
o.Opacity -= 0.05
|
|
Debug.WriteLine("Fading out, Opacity: " & o.Opacity)
|
|
End While
|
|
|
|
o.Opacity = 0
|
|
End Sub
|
|
|
|
End Class
|