forked from PavelTorgashov/FastColoredTextBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGifImageStyle.vb
70 lines (62 loc) · 2.87 KB
/
GifImageStyle.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Imports FastColoredTextBoxNS
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Namespace TesterVB
Friend Class GifImageStyle
Inherits TextStyle
Private parent As FastColoredTextBox
Private timer As Timer
Public Property ImagesByText() As Dictionary(Of String, Image)
Public Sub New(parent As FastColoredTextBox)
MyBase.New(Nothing, Nothing, FontStyle.Regular)
Me.ImagesByText = New Dictionary(Of String, Image)()
Me.parent = parent
Me.timer = New Timer()
Me.timer.Interval = 100
AddHandler Me.timer.Tick, Sub()
ImageAnimator.UpdateFrames()
parent.Invalidate()
End Sub
Me.timer.Start()
End Sub
Public Sub StartAnimation()
For Each image As Image In Me.ImagesByText.Values
If ImageAnimator.CanAnimate(image) Then
ImageAnimator.Animate(image, New EventHandler(AddressOf Me.OnFrameChanged))
End If
Next
End Sub
Private Sub OnFrameChanged(sender As Object, args As EventArgs)
End Sub
Public Overrides Sub Draw(gr As Graphics, position As Point, range As Range)
Dim text As String = range.Text
Dim iChar As Integer = range.Start.iChar
While text <> ""
Dim replaced As Boolean = False
For Each pair As KeyValuePair(Of String, Image) In Me.ImagesByText
If text.StartsWith(pair.Key) Then
Dim i As Single = CSng(pair.Key.Length * range.tb.CharWidth) / CSng(pair.Value.Width)
If i > 1.0F Then
i = 1.0F
End If
text = text.Substring(pair.Key.Length)
Dim rect As RectangleF = New RectangleF(CSng(position.X + range.tb.CharWidth * pair.Key.Length / 2) - CSng(pair.Value.Width) * i / 2.0F, CSng(position.Y), CSng(pair.Value.Width) * i, CSng(pair.Value.Height) * i)
gr.DrawImage(pair.Value, rect)
position.Offset(range.tb.CharWidth * pair.Key.Length, 0)
replaced = True
iChar += pair.Key.Length
Exit For
End If
Next
If Not replaced AndAlso text.Length > 0 Then
Dim r As Range = New Range(range.tb, iChar, range.Start.iLine, iChar + 1, range.Start.iLine)
MyBase.Draw(gr, position, r)
position.Offset(range.tb.CharWidth, 0)
text = text.Substring(1)
End If
End While
End Sub
End Class
End Namespace