/Source Code/Projection/Projectlet.vb
Visual Basic | 314 lines | 247 code | 60 blank | 7 comment | 0 complexity | fb08eb47b7175c59669d9f3fc724ed04 MD5 | raw file
- Imports System.Drawing.Drawing2D
- Imports PowerSong.SongDatabase.Style
- Imports PowerSong.SongDatabase.ProjectletStyle
- Imports PowerSong.SongDatabase.Style.ETextAlignment
- Imports PowerSong.SongDatabase.Items
-
- Public Class Projectlet
-
- Public Function PopulateTags(ByVal item As BaseItem, _
- ByVal activeVerseIndex As Integer) As String
-
- If activeVerseIndex < 0 OrElse activeVerseIndex >= item.Parts.Count Then Return String.Empty
-
- ' Compose an authors string
- Dim Authors As String = String.Empty
- If TypeOf item Is SongItem Then
- For Each Author As String In DirectCast(item, SongItem).Authors
- If Authors = "" Then Authors = Author Else Authors += ", " + Author
- Next
- End If
-
- ' Replace tags
- Dim Result As String = FContentFormat
- Result = Result.Replace(DATE_TAG, Now.ToShortDateString)
- Result = Result.Replace(TIME_TAG, Now.ToShortTimeString)
- Result = Result.Replace(TITLE_TAG, item.Title)
- Result = Result.Replace(VERSE_TAG, item.Parts(activeVerseIndex))
- Result = Result.Replace(SIMPLE_COPYRIGHT_TAG, item.CopyrightLine)
- Result = Result.Replace(AUTHORS_TAG, Authors)
- Return Result
-
- End Function
-
- Private FCategory As String = String.Empty
-
- Public ReadOnly Property Category() As String
- Get
- Return FCategory
- End Get
- End Property
-
- Private FArea As New RectangleF(0.05, 0.05, 0.9, 0.9)
-
- Public Property Area() As RectangleF
- Get
- Return FArea
- End Get
- Set(ByVal value As RectangleF)
- FArea = value
- FRenderedVerses = New List(Of Integer)
- FCurrentVerse = -1
- End Set
- End Property
-
- Private FPreviousText As String = String.Empty
-
- Friend Property PreviousText() As String
- Get
- Return FPreviousText
- End Get
- Set(ByVal value As String)
- FPreviousText = value
- End Set
- End Property
-
- Private FText As String = String.Empty
-
- Public Property Text() As String
- Get
- Return FText
- End Get
- Set(ByVal value As String)
- FPreviousText = FText
- FText = value
- FRenderedVerses = New List(Of Integer)
- FCurrentVerse = -1
- End Set
- End Property
-
- Private FFont As Font = SystemFonts.DefaultFont
-
- Public Property Font() As Font
- Get
- Return FFont
- End Get
- Set(ByVal value As Font)
- FFont = value
- FProjectingFont = value
- FRenderedVerses = New List(Of Integer)
- FCurrentVerse = -1
- End Set
- End Property
-
- Private FProjectingFont As Font = SystemFonts.DefaultFont
-
- Friend Property ProjectingFont() As Font
- Get
- Return FProjectingFont
- End Get
- Set(ByVal value As Font)
- FProjectingFont = value
- End Set
- End Property
-
- Private FFontFormat As New StringFormat
-
- Public Property FontFormat() As StringFormat
- Get
- Return FFontFormat
- End Get
- Set(ByVal value As StringFormat)
- FFontFormat = value
- FRenderedVerses = New List(Of Integer)
- FCurrentVerse = -1
- End Set
- End Property
-
- Private FFontColour As Color = Color.White
-
- Public Property FontColour() As Color
- Get
- Return FFontColour
- End Get
- Set(ByVal value As Color)
- FFontColour = value
- FRenderedVerses = New List(Of Integer)
- FCurrentVerse = -1
- End Set
- End Property
-
- Private FFontEffect As ETextEffect = ETextEffect.Shadow
-
- Public Property FontEffect() As ETextEffect
- Get
- Return FFontEffect
- End Get
- Set(ByVal value As ETextEffect)
- FFontEffect = value
- FRenderedVerses = New List(Of Integer)
- FCurrentVerse = -1
- End Set
- End Property
-
- Private FFontEffectColour As Color = Color.Black
-
- Public Property FontEffectColour() As Color
- Get
- Return FFontEffectColour
- End Get
- Set(ByVal value As Color)
- FFontEffectColour = value
- FRenderedVerses = New List(Of Integer)
- FCurrentVerse = -1
- End Set
- End Property
-
- Private FDisplayOption As EDisplayOption = EDisplayOption.Always
-
- Public Property DisplayOption() As EDisplayOption
- Get
- Return FDisplayOption
- End Get
- Set(ByVal value As EDisplayOption)
- FDisplayOption = value
- FRenderedVerses = New List(Of Integer)
- FCurrentVerse = -1
- End Set
- End Property
-
- Private FContentFormat As String = String.Empty
-
- Public Property ContentFormat() As String
- Get
- Return FContentFormat
- End Get
- Set(ByVal value As String)
- FContentFormat = value
- End Set
- End Property
-
- Private FCurrentVerse As Integer = -1
- Private FRenderedVerses As New List(Of Integer)
-
- Public Sub New(ByVal category As String, ByVal contentFormat As String)
-
- FCategory = category
- FContentFormat = contentFormat
- FFontFormat.Alignment = StringAlignment.Center
- FFontFormat.LineAlignment = StringAlignment.Center
-
- End Sub
-
- Public Sub SetStyle(ByVal style As SongDatabase.ProjectletStyle)
-
- Area = style.Area
- Font = New Font(style.FontName, style.FontSize, style.FontStyle, GraphicsUnit.Pixel)
- FontColour = style.FontColour
- FontEffect = style.FontEffect
- FontEffectColour = style.FontEffectColour
- DisplayOption = style.DisplayOption
- FontFormat = CreateFontFormat(style.Alignment)
- ContentFormat = style.Content
-
- End Sub
-
- Public Shared Function CreateFontFormat(ByVal alignment As ETextAlignment) As StringFormat
-
- Dim Result As New StringFormat
-
- ' Set horizontal alignment
- Select Case alignment
- Case TopLeft, MiddleLeft, BottomLeft : Result.Alignment = StringAlignment.Near
- Case TopMiddle, MiddleMiddle, BottomMiddle : Result.Alignment = StringAlignment.Center
- Case TopRight, MiddleRight, BottomRight : Result.Alignment = StringAlignment.Far
- End Select
-
- ' Set vertical alignment
- Select Case alignment
- Case TopLeft, TopMiddle, TopRight : Result.LineAlignment = StringAlignment.Near
- Case MiddleLeft, MiddleMiddle, MiddleRight : Result.LineAlignment = StringAlignment.Center
- Case BottomLeft, BottomMiddle, BottomRight : Result.LineAlignment = StringAlignment.Far
- End Select
-
- Return Result
-
- End Function
-
- Public Sub DrawText(ByVal graphics As Graphics, _
- ByVal size As Size, _
- ByVal opacity As Byte, _
- ByVal text As String, _
- ByVal verseIndex As Integer, _
- ByVal verseCount As Integer)
-
- If verseIndex <> FCurrentVerse Then
- If Not FRenderedVerses.Contains(FCurrentVerse) Then FRenderedVerses.Add(FCurrentVerse)
- FCurrentVerse = verseIndex
- End If
-
- ' Determine whether or not to display the text based on the verse or iteration
- Dim DoDisplay As Boolean = True
- Select Case FDisplayOption
- Case EDisplayOption.FirstVerse : DoDisplay = verseIndex = 0
- Case EDisplayOption.SecondVerse : DoDisplay = verseIndex = 1
- Case EDisplayOption.LastVerse : DoDisplay = verseIndex = verseCount - 1
- Case EDisplayOption.FirstVerseOnce : DoDisplay = verseIndex = 0 AndAlso Not FRenderedVerses.Contains(verseIndex)
- Case EDisplayOption.SecondVerseOnce : DoDisplay = verseIndex = 1 AndAlso Not FRenderedVerses.Contains(verseIndex)
- Case EDisplayOption.LastVerseOnce : DoDisplay = verseIndex = verseCount - 1 AndAlso Not FRenderedVerses.Contains(verseIndex)
- Case EDisplayOption.Never : DoDisplay = False
- End Select
-
- ' Don't display the verse under these conditions
- If Not DoDisplay Then Exit Sub
- If text = "" Then Exit Sub
-
- ' Determine the projectlet screen area
- Dim ScreenArea As New Rectangle(FArea.Left * size.Width, _
- FArea.Top * size.Height, _
- FArea.Width * size.Width, _
- FArea.Height * size.Height)
-
- Dim Font As Font = FProjectingFont
-
- Dim FontCol As Color = Color.FromArgb(opacity, FFontColour.R, FFontColour.G, FFontColour.B)
- Dim EffectCol As Color = Color.FromArgb(opacity, FFontEffectColour.R, FFontEffectColour.G, FFontEffectColour.B)
-
- Select Case FFontEffect
-
- Case ETextEffect.Shadow
- Dim DeviantSize As Integer = ScreenArea.Width / 200
- ScreenArea.X += DeviantSize
- ScreenArea.Y += DeviantSize
- graphics.DrawString(text, Font, New SolidBrush(EffectCol), ScreenArea, FFontFormat)
- ScreenArea.X -= DeviantSize
- ScreenArea.Y -= DeviantSize
- graphics.DrawString(text, Font, New SolidBrush(FontCol), ScreenArea, FFontFormat)
-
- Case ETextEffect.InnerOutline
- Dim OutlineWidth As Integer = ScreenArea.Width / 300
- Dim Path As New GraphicsPath
- Path.AddString(text, Font.FontFamily, Font.Style, Font.Size, ScreenArea, FFontFormat)
- graphics.FillPath(New SolidBrush(FontCol), Path)
- graphics.DrawPath(New Pen(EffectCol, OutlineWidth), Path)
-
- Case ETextEffect.Outline
- Dim OutlineWidth As Integer = Math.Max(Math.Min(ScreenArea.Width / 400, 4), 1)
- Dim Brush As New SolidBrush(EffectCol)
- For X As Integer = -OutlineWidth To OutlineWidth
- For Y As Integer = -OutlineWidth To OutlineWidth
- If X <> 0 AndAlso Y <> 0 Then
- Dim newArea As New Rectangle(ScreenArea.X + X, ScreenArea.Y + Y, ScreenArea.Width, ScreenArea.Height)
- graphics.DrawString(text, Font, Brush, newArea, FFontFormat)
- End If
- Next
- Next
- graphics.DrawString(text, Font, New SolidBrush(FontCol), ScreenArea, FFontFormat)
-
- Case ETextEffect.OutlineBox
- Dim PenWidth As Integer = ScreenArea.Width / 150
- graphics.DrawRectangle(New Pen(FFontEffectColour, PenWidth), ScreenArea)
- graphics.DrawString(text, Font, New SolidBrush(FontCol), ScreenArea, FFontFormat)
-
- Case ETextEffect.FilledBox
- graphics.FillRectangle(New SolidBrush(FFontEffectColour), ScreenArea)
- graphics.DrawString(text, Font, New SolidBrush(FontCol), ScreenArea, FFontFormat)
-
- Case Else
- graphics.DrawString(text, Font, New SolidBrush(FontCol), ScreenArea, FFontFormat)
-
- End Select
-
- End Sub
-
- End Class