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