Skip to content

Commit

Permalink
Double click video to maximize camera
Browse files Browse the repository at this point in the history
Implement functionality to double click video to maximize video. Double click again to restore default layout
MainViewModel moved to seperate .cs file
  • Loading branch information
mattw01 authored and mattw01 committed Apr 26, 2019
1 parent f5ec4f2 commit 99a0a5e
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 139 deletions.
52 changes: 52 additions & 0 deletions TeslaCamViewer/TeslaCamViewer/DelegateCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace TeslaCamViewer
{
public class DelegateCommand : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;

public event EventHandler CanExecuteChanged;

public DelegateCommand(Action<object> execute)
: this(execute, null)
{
}

public DelegateCommand(Action<object> execute,
Predicate<object> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}

public bool CanExecute(object parameter)
{
if (_canExecute == null)
{
return true;
}

return _canExecute(parameter);
}

public void Execute(object parameter)
{
_execute(parameter);
}

public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, EventArgs.Empty);
}
}
}
}
35 changes: 26 additions & 9 deletions TeslaCamViewer/TeslaCamViewer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:local="clr-namespace:TeslaCamViewer"
mc:Ignorable="d"
Title="TeslaCam Viewer V0.3" TitleCaps="False" Height="525" Width="817"
Title="TeslaCam Viewer V0.4" TitleCaps="False" Height="525" Width="817"
AllowDrop="True" Drop="Window_Drop" KeyUp="MetroWindow_KeyUp"
Loaded="MetroWindow_Loaded">
<Grid>
Expand Down Expand Up @@ -72,7 +72,8 @@
<StackPanel Orientation="Horizontal" Margin="2">
<!--<StackPanel.ContextMenu>
<ContextMenu>
<MenuItem Header="Delete Event" Command="{Binding Command}"/>
<MenuItem Header="Delete Event" Command="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl},
Path=DataContext.DeleteEventCommand}"/>
</ContextMenu>
</StackPanel.ContextMenu>-->
<!--<CheckBox IsChecked="{Binding IsSelected}"/>-->
Expand Down Expand Up @@ -102,23 +103,39 @@
</Grid.RowDefinitions>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="{Binding TopVideoRowHeight}" />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="{Binding BottomVideoRowHeight}" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" >
<MediaElement x:Name="front" LoadedBehavior="Manual" ScrubbingEnabled="True"/>
<MediaElement x:Name="front" LoadedBehavior="Manual" ScrubbingEnabled="True">
<MediaElement.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding SelectFullVideo}"
CommandParameter="{x:Static local:TeslaCamFile+CameraType.FRONT}" />
</MediaElement.InputBindings>
</MediaElement>

</Grid>
<GridSplitter Margin="2" Height="2" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="DarkRed" />
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="{Binding LeftVideoColumnWidth}"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="{Binding RightVideoColumnWidth}"/>
</Grid.ColumnDefinitions>
<MediaElement x:Name="left" Grid.Column="0" LoadedBehavior="Manual" MediaOpened="MediaElement_MediaOpened" MediaEnded="left_MediaEnded" ScrubbingEnabled="True"/>
<MediaElement x:Name="left" Grid.Column="0" LoadedBehavior="Manual" MediaOpened="MediaElement_MediaOpened" MediaEnded="left_MediaEnded" ScrubbingEnabled="True">
<MediaElement.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding SelectFullVideo}"
CommandParameter="{x:Static local:TeslaCamFile+CameraType.LEFT_REPEATER}" />
</MediaElement.InputBindings>
</MediaElement>
<GridSplitter Margin="2 0 2 0" Width="2" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Background="DarkRed" />
<MediaElement x:Name="right" Grid.Column="2" LoadedBehavior="Manual" ScrubbingEnabled="True"/>
<MediaElement x:Name="right" Grid.Column="2" LoadedBehavior="Manual" ScrubbingEnabled="True">
<MediaElement.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" Command="{Binding SelectFullVideo}"
CommandParameter="{x:Static local:TeslaCamFile+CameraType.RIGHT_REPEATER}" />
</MediaElement.InputBindings>
</MediaElement>
</Grid>
</Grid>
<Grid Grid.Row="1">
Expand Down
130 changes: 2 additions & 128 deletions TeslaCamViewer/TeslaCamViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,132 +22,6 @@

namespace TeslaCamViewer
{

public class MainWindowViewModel : INotifyPropertyChanged
{
public ObservableCollection<TeslaCamDirectoryCollection> ListItems { get; set; }
public TeslaCamFileSet CurrentPlaybackFile { get; set; }

private double _DisplayPlaybackSpeed;
public double DisplayPlaybackSpeed
{
get
{
return this._DisplayPlaybackSpeed;
}
set
{
if (value != this._DisplayPlaybackSpeed)
{
this._DisplayPlaybackSpeed = value;
NotifyPropertyChanged();
NotifyPropertyChanged("CalculatedPlaybackSpeed");
}
}
}
public double CalculatedPlaybackSpeed
{
get
{
if (DisplayPlaybackSpeed < 0)
{
double calculatedMin = 0.25;
double calculatedMax = 1.00;
double displayMin = -50;
double displayMax = 0;

double calc = (calculatedMax - calculatedMin) / (displayMax - displayMin) * (DisplayPlaybackSpeed - displayMax) + calculatedMax;
return calc;
}
else
return this.DisplayPlaybackSpeed + 1.0;
}
set
{
}
}

private string _LeftStatusText;
public string LeftStatusText
{
get
{
return this._LeftStatusText;
}

set
{
if (value != this._LeftStatusText)
{
this._LeftStatusText = value;
NotifyPropertyChanged();
}
}
}
private string _RightStatusText;
public string RightStatusText
{
get
{
return this._RightStatusText;
}

set
{
if (value != this._RightStatusText)
{
this._RightStatusText = value;
NotifyPropertyChanged();
}
}
}
public bool EnableAutoSearch
{
get
{
return Properties.Settings.Default.EnableAutoSearch;
}
set
{
Properties.Settings.Default.EnableAutoSearch = value;
Properties.Settings.Default.Save();
}
}
public bool EnableAutoPlaylist
{
get
{
return Properties.Settings.Default.EnableAutoPlaylist;
}
set
{
Properties.Settings.Default.EnableAutoPlaylist = value;
Properties.Settings.Default.Save();
}
}
public VideoViewModel VideoModel { get; set; }
public MainWindowViewModel()
{
this.ListItems = new ObservableCollection<TeslaCamDirectoryCollection>();
this.VideoModel = new VideoViewModel();
}
public event PropertyChangedEventHandler PropertyChanged;

private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}

public void LoadFileSet(TeslaCamFileSet set)
{
this.VideoModel.LoadFileSet(set);
this.CurrentPlaybackFile = set;
}
}

public class VideoViewModel
{
public MediaElement left;
Expand Down Expand Up @@ -367,7 +241,7 @@ from dir in dirs
}
catch (Exception ex)
{
await this.ShowMessageAsync("Could not load TeslaCam Drive", $"An error ocurred: {ex.Message}");
this.ShowMessageAsync("Could not load TeslaCam Drive", "An error ocurred: " + ex.Message).Wait();
}
}

Expand Down Expand Up @@ -428,7 +302,7 @@ private async void MetroWindow_Loaded(object sender, RoutedEventArgs e)

private void about_Menu_Click(object sender, RoutedEventArgs e)
{
this.ShowMessageAsync("TeslaCam Viewer V0.3", "TeslaCam Viewer V0.3 Copyright 2019 mattw\n\nSee LICENCES.txt for more information.");
this.ShowMessageAsync("TeslaCam Viewer V0.4", "TeslaCam Viewer V0.4 Copyright 2019 mattw\n\nSee LICENCES.txt for more information.");
}

private void viewOnGitHub_Menu_Click(object sender, RoutedEventArgs e)
Expand Down
Loading

0 comments on commit 99a0a5e

Please sign in to comment.