Windows: Add Animator Class

This commit is contained in:
Jonathan Jenne
2021-03-01 16:37:04 +01:00
parent 035da0a2fe
commit 28747f2344
5 changed files with 246 additions and 0 deletions

72
Windows/Animator.vb Normal file
View File

@@ -0,0 +1,72 @@
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

41
Windows/Animator/frmPopup.Designer.vb generated Normal file
View File

@@ -0,0 +1,41 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmPopup
Inherits System.Windows.Forms.Form
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Wird vom Windows Form-Designer benötigt.
Private components As System.ComponentModel.IContainer
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.SuspendLayout()
'
'frmPopup
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.Yellow
Me.ClientSize = New System.Drawing.Size(30, 30)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.MaximumSize = New System.Drawing.Size(30, 30)
Me.MinimumSize = New System.Drawing.Size(30, 30)
Me.Name = "frmPopup"
Me.Text = "frmPopup"
Me.ResumeLayout(False)
End Sub
End Class

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,3 @@
Public Class frmPopup
End Class

View File

@@ -74,6 +74,13 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="Animator.vb" />
<Compile Include="Animator\frmPopup.Designer.vb">
<DependentUpon>frmPopup.vb</DependentUpon>
</Compile>
<Compile Include="Animator\frmPopup.vb">
<SubType>Form</SubType>
</Compile>
<Compile Include="Drawing.vb" />
<Compile Include="File.vb" />
<Compile Include="Hotkey.vb" />
@@ -97,6 +104,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Animator\frmPopup.resx">
<DependentUpon>frmPopup.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>