Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,14 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc

# vim
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
Session.vim
.netrwhist
*~
tags
35 changes: 35 additions & 0 deletions ShadowClip/GUI/Converters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
Expand Down Expand Up @@ -72,6 +73,40 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
}
}

public class ShotTime
{
public double Time { get; set; }
public Thickness Margin { get; set; }
}
internal class ShotTimesConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var none = Enumerable.Empty<ShotTime>();
if (!(values[0] is IEnumerable<double> times)) return none;
if (!(values[1] is TimeSpan duration)) return none;
if (!(values[2] is double width)) return none;
if (duration.Ticks == 0) return none;

return times.Select(time =>
{
var fraction = time / duration.TotalSeconds;
var offset = fraction * width - 4;

return new ShotTime
{
Margin = new Thickness(offset, 0, 0, 0),
Time = time
};
});
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

internal class StateToBoolConverter : ParamConverter<State>
{
public override object Convert(State state, string parameter)
Expand Down
101 changes: 69 additions & 32 deletions ShadowClip/GUI/VideoView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
xmlns:cal="http://www.caliburnproject.org"
xmlns:gui="clr-namespace:ShadowClip.GUI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
d:DesignHeight="300" d:DesignWidth="700">
<UserControl.Resources>
<gui:MaxLengthConverter x:Key="MaxLength" />
<gui:PlayActionCoverter x:Key="PlayActionCoverter" />
<gui:IntegerSecondsConverter x:Key="IntegerSecondsConverter" />
<gui:DurationMarginConverter x:Key="DurationMarginConverter" />
<gui:ShotTimesConverter x:Key="ShotTimesConverter" />
<gui:VideoZoomConverter x:Key="VideoZoomConverter" />
</UserControl.Resources>
<Grid cal:Message.Attach="[Event PreviewKeyDown] = [Action KeyPressed($eventArgs)]">
Expand Down Expand Up @@ -71,36 +72,69 @@
<ComboBoxItem Tag="4">4x</ComboBoxItem>
</ComboBox>
</StackPanel>

</StackPanel>
<Border Grid.Column="1" Height="40" BorderThickness="2" Background="LightGreen"
cal:Message.Attach="[Event PreviewMouseUp] = [Action PreviewClicked()]">
<Border.Margin>
<MultiBinding Converter="{StaticResource DurationMarginConverter}">
<Binding Path="StartPosition" />
<Binding Path="EndPosition" />
<Binding Path="Duration" />
<Binding Path="ActualWidth" ElementName="VideoSlider" />
</MultiBinding>
</Border.Margin>
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Text="Preview" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Slider Grid.Row="0" Grid.Column="1" Name="VideoSlider" VerticalAlignment="Top"
cal:Message.Attach="

<StackPanel Grid.Column="1">
<TextBlock Visibility="{Binding IsFindingShots, Converter={StaticResource BooleanToVisibilityConverter}}" Text="Searching video for shots..." HorizontalAlignment="Center"/>
<ItemsControl>
<ItemsControl.ItemsSource>
<MultiBinding Converter="{StaticResource ShotTimesConverter}">
<Binding Path="ShotTimes" />
<Binding Path="Duration" />
<Binding Path="ActualWidth" ElementName="VideoSlider" />
</MultiBinding>
</ItemsControl.ItemsSource>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid ShowGridLines="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="FrameworkElement.Margin" Value="{Binding Margin}" />
</Style>
</ItemsControl.ItemContainerStyle>

<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Height="20" Width="8" HorizontalAlignment="Left" Cursor="Hand"
cal:Message.Attach="GoTo($dataContext)" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Grid>
<Border Height="40" BorderThickness="2" Background="LightGreen"
cal:Message.Attach="[Event PreviewMouseUp] = [Action PreviewClicked()]">
<Border.Margin>
<MultiBinding Converter="{StaticResource DurationMarginConverter}">
<Binding Path="StartPosition" />
<Binding Path="EndPosition" />
<Binding Path="Duration" />
<Binding Path="ActualWidth" ElementName="VideoSlider" />
</MultiBinding>
</Border.Margin>
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Text="Preview" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Slider Grid.Row="0" Name="VideoSlider" VerticalAlignment="Top"
cal:Message.Attach="
[Event PreviewMouseDown] = [Action SliderClicked()];
[Event PreviewMouseUp] = [Action SliderReleased()]"
Maximum="{Binding Duration, Converter={StaticResource MaxLength}}"
Value="{Binding CurrentPosition}" HorizontalAlignment="Stretch"
IsMoveToPointEnabled="True" />
Maximum="{Binding Duration, Converter={StaticResource MaxLength}}"
Value="{Binding CurrentPosition}" HorizontalAlignment="Stretch"
IsMoveToPointEnabled="True" />
</Grid>
</StackPanel>

<StackPanel Grid.Row="0" Grid.Column="2" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="{Binding Position, StringFormat=mm\\:ss}" />
Expand Down Expand Up @@ -133,13 +167,16 @@
MinWidth="30" />
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Upload Clip" Name="Upload" />
<Button Content="Copy Screenshot" Name="Screenshot" />
<Button Content="Upload Clip" x:Name="Upload" />
<Button Content="Copy Screenshot" x:Name="Screenshot" />
</StackPanel>
</StackPanel>
<TextBox x:Name="NonZero" Height="23" TextWrapping="Wrap" Text="{Binding IsScopeFrame}" HorizontalAlignment="Right" Width="188"/>
<Label Content="Is Scope Frame?" HorizontalAlignment="Left" Width="98"/>
<TextBox Height="71" TextWrapping="Wrap" Text="{Binding WordString}"/>
</StackPanel>


</Grid>

</Grid>
</UserControl>
</UserControl>
15 changes: 15 additions & 0 deletions ShadowClip/GUI/VideoView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ShadowClip.GUI
{
public partial class VideoView
{
public VideoView()
{
InitializeComponent();
}

private void CheckBox_Checked(object sender, System.Windows.RoutedEventArgs e)
{

}
}
}
30 changes: 27 additions & 3 deletions ShadowClip/GUI/VideoViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Windows;
Expand All @@ -7,22 +8,27 @@
using System.Windows.Threading;
using Caliburn.Micro;
using ShadowClip.GUI.UploadDialog;
using ShadowClip.services;
using System.Threading;
using System.Threading.Tasks;

namespace ShadowClip.GUI
{
public sealed class VideoViewModel : Screen, IHandle<FileSelected>
{
private readonly IDialogBuilder _dialogBuilder;
private readonly IShotFinder _shotFinder;
private readonly TimeSpan _frameTime = TimeSpan.FromTicks(166667);
private readonly ISettings _settings;
private FileInfo _currentFile;
private bool _playingWhileClicked;
private VideoView _videoView;

public VideoViewModel(IEventAggregator eventAggregator, ISettings settings, IDialogBuilder dialogBuilder)
public VideoViewModel(IEventAggregator eventAggregator, ISettings settings, IDialogBuilder dialogBuilder, IShotFinder shotFinder)
{
_settings = settings;
_dialogBuilder = dialogBuilder;
_shotFinder = shotFinder;
eventAggregator.Subscribe(this);
}

Expand All @@ -32,6 +38,10 @@ public VideoViewModel(IEventAggregator eventAggregator, ISettings settings, IDia

public bool IsMuted { get; set; }

public IEnumerable<double> ShotTimes { get; set; }

public bool IsFindingShots { get; set; }

public MediaElement VideoPlayer => _videoView.Video;

public MediaState CurrentMediaState => VideoPlayer.GetMediaState();
Expand Down Expand Up @@ -69,6 +79,15 @@ public void Handle(FileSelected message)
VideoPlayer.Source = new Uri(message.File.FullName);
VideoPlayer.Play();
SetPostion(TimeSpan.Zero);
ShotTimes = new double[0];
FindShotTimesAsync();
}

private async void FindShotTimesAsync()
{
IsFindingShots = true;
ShotTimes = await _shotFinder.GetShotTimes(VideoPlayer.Source.AbsolutePath);
IsFindingShots = false;
}

public void OnIsMutedChanged()
Expand All @@ -91,6 +110,11 @@ public void MarkEnd()
EndPosition = Position;
}

public void GoTo(ShotTime shotTime)
{
CurrentPosition = shotTime.Time;
}

private void SetPostion(TimeSpan position)
{
VideoPlayer.Pause();
Expand Down Expand Up @@ -226,8 +250,8 @@ public void SliderReleased()
public void Screenshot()
{
var screenShot = VideoPlayer.GetScreenShot(Zoom);

Clipboard.SetImage(screenShot);

}

public void PreviewClicked()
Expand All @@ -247,4 +271,4 @@ public void PreviewClicked()
timer.Start();
}
}
}
}
70 changes: 70 additions & 0 deletions ShadowClip/Properties/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.

<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on and is
is designed to work with. Uncomment the appropriate elements and Windows will
automatically selected the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>
Loading