PageRenderTime 61ms CodeModel.GetById 49ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Source Code/Plugins/CountDownPlugin/CountDownPlugin.vb

#
Visual Basic | 105 lines | 58 code | 15 blank | 32 comment | 0 complexity | 0a0ea24bf293fdc2976f40c40eba03bd MD5 | raw file
  1Imports PluginSupport
  2Imports System.Drawing
  3
  4''' <summary>
  5''' CountDown plugin.
  6''' </summary>
  7Public Class CountDownPlugin
  8    Implements PluginSupport.IPlugin
  9
 10    Private FContext As PluginContextBase = Nothing
 11    Private FEndTime As Date = Now
 12    Private FStartTime As Date = Now
 13    Private FMenuItem As System.Windows.Forms.ToolStripItem = Nothing
 14
 15#Region " Plugin Interface Methods "
 16
 17    ''' <summary>
 18    ''' Returns the name of the plugin.
 19    ''' </summary>
 20    Public ReadOnly Property Name() As String Implements IPlugin.Name
 21        Get
 22            Return "CountDown Plug In"
 23        End Get
 24    End Property
 25
 26    ''' <summary>
 27    ''' Returns the name of the author of the plugin.
 28    ''' </summary>
 29    Public ReadOnly Property Author() As String Implements IPlugin.Author
 30        Get
 31            Return "Nicholas Hill"
 32        End Get
 33    End Property
 34
 35    ''' <summary>
 36    ''' Called when the plugin is initialised.
 37    ''' Use this method to store the given context so that it can be used later.
 38    ''' </summary>
 39    ''' <param name="context">An object by which communication is possible to PowerSong.</param>
 40    Public Sub Initialise(ByVal context As PluginSupport.PluginContextBase) Implements IPlugin.Initialise
 41        FContext = context
 42    End Sub
 43
 44    ''' <summary>
 45    ''' Called when the plugin is installed into a database.
 46    ''' </summary>
 47    Public Sub Install() Implements IPlugin.Install
 48    End Sub
 49
 50    ''' <summary>
 51    ''' Called when the plugin is uninstalled from a database.
 52    ''' </summary>
 53    Public Sub Uninstall() Implements IPlugin.Uninstall
 54    End Sub
 55
 56    ''' <summary>
 57    ''' Called when the PowerSong program opens the database containing the plugin.
 58    ''' </summary>
 59    ''' <remarks></remarks>
 60    Public Sub Start() Implements PluginSupport.IPlugin.Start
 61        FMenuItem = FContext.AddSubMenuItem(PluginContextBase.EMainMenuItem.Tools, "Start &CountDown...", New EventHandler(AddressOf StartCountDown_Click))
 62    End Sub
 63
 64    ''' <summary>
 65    ''' Called when the PowerSong program closes the database containing the plugin.
 66    ''' </summary>
 67    ''' <remarks></remarks>
 68    Public Sub [Stop]() Implements PluginSupport.IPlugin.Stop
 69        If FMenuItem IsNot Nothing Then FMenuItem.Dispose()
 70    End Sub
 71
 72    ''' <summary>
 73    ''' This method allows custom-drawing on the projector screen.
 74    ''' </summary>
 75    ''' <param name="graphics">The graphics object that can be used for drawing.</param>
 76    Public Sub Project(ByVal graphics As System.Drawing.Graphics, ByVal width As Integer, ByVal height As Integer) Implements PluginSupport.IPlugin.Project
 77        Dim SecondsPast As Integer = FEndTime.Subtract(Now).TotalSeconds
 78        If SecondsPast > -1 Then
 79            Dim Minutes As Integer = SecondsPast \ 60
 80            Dim Seconds As Integer = SecondsPast Mod 60
 81            Dim TimeLeft As String = Minutes.ToString + ":" + Seconds.ToString
 82            If Seconds < 10 Then TimeLeft = Minutes.ToString + ":0" + Seconds.ToString
 83            Dim FontSize As Integer = width / 5
 84            graphics.DrawString(TimeLeft, New Font("Consolas", FontSize, FontStyle.Bold), Brushes.Black, 8, height \ 3 + 8)
 85            graphics.DrawString(TimeLeft, New Font("Consolas", FontSize, FontStyle.Bold), Brushes.White, 0, height \ 3)
 86        End If
 87    End Sub
 88
 89#End Region
 90
 91    Private Sub StartCountDown_Click()
 92        Dim Data As String = InputBox("Please enter the number of seconds to count down from:", "CountDown Plugin", "60")
 93        If Not IsNumeric(Data) Then Data = "60"
 94        Dim TimeLeft As Integer = CInt(Data)
 95        FStartTime = Now
 96        FEndTime = Now.AddSeconds(TimeLeft)
 97    End Sub
 98
 99    Public ReadOnly Property Description() As String Implements PluginSupport.IPlugin.Description
100        Get
101            Return "Shows a count down from a specified time, down to zero."
102        End Get
103    End Property
104
105End Class