Skip to content

Commit

Permalink
Added control window
Browse files Browse the repository at this point in the history
  • Loading branch information
changbowen committed Mar 5, 2016
1 parent 5c29da5 commit 0a01d8f
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 19 deletions.
33 changes: 33 additions & 0 deletions ControlWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Window x:Class="ControlWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding Mode=OneTime, Source={StaticResource control}, StringFormat='\{0} (F1)'}" Height="140" Width="355.786" ResizeMode="CanMinimize" Closing="Window_Closing" Icon="KenBurns.ico" PreviewKeyDown="Window_PreviewKeyDown">
<Canvas>
<Button x:Name="Btn_SwitchImage" Canvas.Left="10" Canvas.Top="10" Width="196" Height="24">
<Button.Content>
<Run Text="{Binding Mode=OneTime, Source={StaticResource switch_image}, StringFormat='\{0} (Ctrl+P)'}"></Run>
</Button.Content>
</Button>
<Button x:Name="Btn_SwitchAudio" Canvas.Left="10" Canvas.Top="39" Width="196" Height="24">
<Button.Content>
<Run Text="{Binding Mode=OneTime, Source={StaticResource switch_music}, StringFormat='\{0} (Shift+P)'}"></Run>
</Button.Content>
</Button>
<Button x:Name="Btn_Restart" Canvas.Left="10" Canvas.Top="68" Width="196" Height="24">
<Button.Content>
<Run Text="{Binding Mode=OneTime, Source={StaticResource restart}, StringFormat='\{0} (Ctrl+R)'}"></Run>
</Button.Content>
</Button>
<Button x:Name="Btn_Options" Canvas.Left="211" Canvas.Top="10" Width="118" Height="24">
<Button.Content>
<Run Text="{Binding Mode=OneTime, Source={StaticResource options}, StringFormat='\{0} (F12)'}"></Run>
</Button.Content>
</Button>
<Button x:Name="Btn_EditSlide" Canvas.Left="211" Canvas.Top="39" Width="118" Height="24">
<Button.Content>
<Run Text="{Binding Mode=OneTime, Source={StaticResource edit slides}, StringFormat='\{0} (F11)'}"></Run>
</Button.Content>
</Button>
<Button x:Name="Btn_Exit" Content="{StaticResource exit}" Canvas.Left="211" Canvas.Top="68" Width="118" Height="24"/>
</Canvas>
</Window>
71 changes: 71 additions & 0 deletions ControlWindow.xaml.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Public Class ControlWindow
Public Shared reallyclose As Boolean = False

Private Sub Window_Closing(sender As Object, e As ComponentModel.CancelEventArgs)
If Not reallyclose Then
e.Cancel = True
Me.Hide()
End If
End Sub

Private Sub Btn_SwitchImage_Click(sender As Object, e As RoutedEventArgs) Handles Btn_SwitchImage.Click
Task.Run(Sub()
Dispatcher.Invoke(Sub() Btn_SwitchImage.IsEnabled = False)
Dispatcher.Invoke(Sub() Btn_Restart.IsEnabled = False)
System.Threading.Thread.Sleep(3000)
Dispatcher.Invoke(Sub() Btn_SwitchImage.IsEnabled = True)
Dispatcher.Invoke(Sub() Btn_Restart.IsEnabled = True)
End Sub)
Dim mainwin As MainWindow = Me.Owner
mainwin.SwitchImage()
End Sub

Private Sub Btn_SwitchAudio_Click(sender As Object, e As RoutedEventArgs) Handles Btn_SwitchAudio.Click
Task.Run(Sub()
Dispatcher.Invoke(Sub() Btn_SwitchAudio.IsEnabled = False)
Dispatcher.Invoke(Sub() Btn_Restart.IsEnabled = False)
System.Threading.Thread.Sleep(3000)
Dispatcher.Invoke(Sub() Btn_SwitchAudio.IsEnabled = True)
Dispatcher.Invoke(Sub() Btn_Restart.IsEnabled = True)
End Sub)
Dim mainwin As MainWindow = Me.Owner
mainwin.SwitchAudio()
End Sub

Private Sub Btn_Restart_Click(sender As Object, e As RoutedEventArgs) Handles Btn_Restart.Click
Task.Run(Sub()
Dispatcher.Invoke(Sub() Btn_SwitchImage.IsEnabled = False)
Dispatcher.Invoke(Sub() Btn_SwitchAudio.IsEnabled = False)
Dispatcher.Invoke(Sub() Btn_Restart.IsEnabled = False)
System.Threading.Thread.Sleep(3000)
Dispatcher.Invoke(Sub() Btn_SwitchImage.IsEnabled = True)
Dispatcher.Invoke(Sub() Btn_SwitchAudio.IsEnabled = True)
Dispatcher.Invoke(Sub() Btn_Restart.IsEnabled = True)
End Sub)
Dim mainwin As MainWindow = Me.Owner
mainwin.RestartAll()
End Sub

Private Sub Btn_Options_Click(sender As Object, e As RoutedEventArgs) Handles Btn_Options.Click
Dim optwin As New OptWindow
optwin.ShowDialog()
optwin.Close()
End Sub

Private Sub Btn_EditSlide_Click(sender As Object, e As RoutedEventArgs) Handles Btn_EditSlide.Click
Dim editwin As New EditWindow
editwin.ShowDialog()
editwin.Close()
End Sub

Private Sub Btn_Exit_Click(sender As Object, e As RoutedEventArgs) Handles Btn_Exit.Click
Dim mainwin As MainWindow = Me.Owner
mainwin.Close()
End Sub

Private Sub Window_PreviewKeyDown(sender As Object, e As KeyEventArgs)
If e.Key = Key.Escape Then
Me.Hide()
End If
End Sub
End Class
Binary file modified Ken Burns Slideshow.v12.suo
Binary file not shown.
7 changes: 7 additions & 0 deletions Ken Burns Slideshow.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ControlWindow.xaml.vb">
<DependentUpon>ControlWindow.xaml</DependentUpon>
</Compile>
<Compile Include="EditWindow.xaml.vb">
<DependentUpon>EditWindow.xaml</DependentUpon>
</Compile>
<Compile Include="OptWindow.xaml.vb">
<DependentUpon>OptWindow.xaml</DependentUpon>
</Compile>
<Page Include="ControlWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="EditWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
75 changes: 56 additions & 19 deletions MainWindow.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Class MainWindow
Dim moveon As Boolean = True
Dim aborting As Boolean = False
Dim worker_pic As Thread
Dim ctrlwindow As Window
Public Shared framerate As UInteger = 60
Public Shared duration As UInteger = 7 'only serves as a store. program will read duration value from picmove_sec.
Public Shared folders_image As New List(Of String)
Expand Down Expand Up @@ -213,7 +214,6 @@ Class MainWindow

tb_date0.FontSize = Me.Height / 12
tb_date1.FontSize = Me.Height / 12

Me.Background = Brushes.Black

Select Case transit
Expand Down Expand Up @@ -337,10 +337,22 @@ Class MainWindow
End Sub).ContinueWith(Sub()
LoadNextImg()
worker_pic.Start()
Dispatcher.Invoke(Sub()
If ctrlwindow Is Nothing Then
ctrlwindow = New ControlWindow
ctrlwindow.Owner = Me
End If
ctrlwindow.Show()
End Sub)
End Sub)
ElseIf loadmode = 0 Then
LoadNextImg()
worker_pic.Start()
If ctrlwindow Is Nothing Then
ctrlwindow = New ControlWindow
ctrlwindow.Owner = Me
End If
ctrlwindow.Show()
Else
Me.Close()
End If
Expand All @@ -352,7 +364,7 @@ Class MainWindow
ExecState_Set = True
End Sub

Public Function RandomNum(min As UInteger, max As UInteger, neg As Boolean)
Private Function RandomNum(min As UInteger, max As UInteger, neg As Boolean)
If neg Then
If ran.Next(2) = 0 Then
Return -ran.Next(min, max)
Expand Down Expand Up @@ -865,37 +877,53 @@ Class MainWindow
Dim editwin As New EditWindow
editwin.ShowDialog()
editwin.Close()
ElseIf e.Key = Key.F1 Then
If ctrlwindow Is Nothing Then
ctrlwindow = New ControlWindow
ctrlwindow.Owner = Me
End If
ctrlwindow.Show()
ElseIf e.Key = Key.P Then
If worker_pic IsNot Nothing AndAlso worker_pic.IsAlive Then
If Keyboard.Modifiers = ModifierKeys.Control Then 'pause image
If moveon = True Then
moveon = False
Else
moveon = True
End If
ElseIf Keyboard.Modifiers = ModifierKeys.Shift Then 'fadeout audio only
If Not audiofading Then
If playing Then
Task.Run(AddressOf FadeoutAudio)
Else
Task.Run(AddressOf FadeinAudio)
End If
End If
End If
If Keyboard.Modifiers = ModifierKeys.Control Then 'pause image
SwitchImage()
ElseIf Keyboard.Modifiers = ModifierKeys.Shift Then 'fadeout audio only
SwitchAudio()
End If
ElseIf e.Key = Key.R AndAlso Keyboard.Modifiers = ModifierKeys.Control AndAlso aborting = False Then
RestartAll()
'ElseIf e.Key = Key.S AndAlso Keyboard.Modifiers = ModifierKeys.Control AndAlso aborting = False Then
' RestartAll()
End If
End Sub

Friend Sub SwitchImage()
If worker_pic IsNot Nothing AndAlso worker_pic.IsAlive Then
If moveon = True Then
moveon = False
Else
moveon = True
End If
End If
End Sub

Friend Sub SwitchAudio()
If worker_pic IsNot Nothing AndAlso worker_pic.IsAlive Then
If Not audiofading Then
If playing Then
Task.Run(AddressOf FadeoutAudio)
Else
Task.Run(AddressOf FadeinAudio)
End If
End If
End If
End Sub

Private Sub RestartAll()
Friend Sub RestartAll()
If worker_pic IsNot Nothing AndAlso worker_pic.IsAlive Then
aborting = True
Task.Run(AddressOf FadeoutAudio)
Task.Run(Sub()
moveon = True
Dim black As Rectangle
Dispatcher.Invoke(Sub()
black = New Rectangle
Expand Down Expand Up @@ -941,6 +969,13 @@ Class MainWindow
worker_pic.Priority = ThreadPriority.Lowest
aborting = False
worker_pic.Start()
Dispatcher.Invoke(Sub()
If ctrlwindow Is Nothing Then
ctrlwindow = New ControlWindow
ctrlwindow.Owner = Me
End If
ctrlwindow.Show()
End Sub)
End Sub)
End If
End Sub
Expand Down Expand Up @@ -983,6 +1018,8 @@ Class MainWindow
End Sub

Private Sub Window_Closing(sender As Object, e As ComponentModel.CancelEventArgs)
ControlWindow.reallyclose = True
If ctrlwindow IsNot Nothing Then ctrlwindow.Close()
If ExecState_Set Then SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS)
End Sub

Expand Down
Binary file modified bin/Release/Ken Burns Slideshow.exe
Binary file not shown.

0 comments on commit 0a01d8f

Please sign in to comment.