Skip to content

Commit

Permalink
Move Top Buttons into own User Control
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed Jan 22, 2024
1 parent 878aa28 commit dc8c9fc
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 55 deletions.
46 changes: 46 additions & 0 deletions NotEnoughAV1Encodes/Controls/MainWindowTopButtons.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<UserControl x:Class="NotEnoughAV1Encodes.Controls.MainWindowTopButtons"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
mc:Ignorable="d"
d:DesignHeight="65" d:DesignWidth="1085">
<Grid>
<Button x:Name="ButtonOpenSource" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="130" Height="45" Background="{Binding Path=Background}" Click="ButtonOpenSource_Click">
<Canvas Height="30" Width="114">
<Image Height="44" Canvas.Left="-6" Canvas.Top="-7" Width="45" Source="/resources/img/video.png"/>
<Label x:Name="LabelSource" Content="{lex:Loc}" Canvas.Left="38" Width="76" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
</Canvas>
</Button>
<Button x:Name="ButtonSetDestination" HorizontalAlignment="Left" Margin="145,10,0,0" VerticalAlignment="Top" Width="130" Height="45" Background="{Binding Path=Background}" Click="ButtonSetDestination_Click">
<Canvas Height="30" Width="120">
<Image Height="44" Canvas.Left="-6" Canvas.Top="-7" Width="45" Source="/resources/img/save.png"/>
<Label x:Name="LabelDestination" Content="{lex:Loc}" Canvas.Left="32" Width="88" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
</Canvas>
</Button>
<Button x:Name="ButtonAddToQueue" Margin="280,10,0,0" VerticalAlignment="Top" Height="45" HorizontalAlignment="Left" Width="180" Background="{Binding Path=Background}" Click="ButtonAddToQueue_Click">
<Canvas Height="30" Width="120">
<Image x:Name="ImageStartStop2" Height="44" Canvas.Left="-23" Canvas.Top="-7" Width="44" Source="/resources/img/queue.png"/>
<Label x:Name="LabelAddToQueue" Content="{lex:Loc}" Canvas.Left="26" Width="122" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
</Canvas>
</Button>
<Button x:Name="ButtonStartStop" Margin="0,10,189,0" VerticalAlignment="Top" Height="45" HorizontalAlignment="Right" Width="118" Background="{Binding Path=Background}" Click="ButtonStartStop_Click">
<Canvas Height="30" Width="120">
<Image x:Name="ImageStartStop" Height="44" Canvas.Left="-6" Canvas.Top="-7" Width="45" Source="/resources/img/start.png"/>
<Label x:Name="LabelStartPauseButton" Content="{lex:Loc}" Canvas.Left="32" Width="78" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
</Canvas>
</Button>
<Button x:Name="ButtonProgramSettings" Margin="0,10,10,0" VerticalAlignment="Top" Height="45" HorizontalAlignment="Right" Width="45" Background="{Binding Path=Background}" Click="ButtonProgramSettings_Click">
<Canvas Height="30" Width="120">
<Image x:Name="ImageStartStop1" Height="44" Canvas.Left="-6" Canvas.Top="-7" Width="45" Source="/resources/img/settings.png"/>
</Canvas>
</Button>
<Button x:Name="ButtonCancelEncode" Margin="0,10,60,0" VerticalAlignment="Top" Height="45" HorizontalAlignment="Right" Width="124" Background="{Binding Path=Background}" Click="ButtonCancelEncode_Click">
<Canvas Height="30" Width="102">
<Label x:Name="LabelCancel" Content="{lex:Loc}" Canvas.Left="30" Width="81" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
<Image Height="44" Canvas.Left="-10" Canvas.Top="-7" Width="44" Source="/resources/img/stop.png"/>
</Canvas>
</Button>
</Grid>
</UserControl>
61 changes: 61 additions & 0 deletions NotEnoughAV1Encodes/Controls/MainWindowTopButtons.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace NotEnoughAV1Encodes.Controls
{
public partial class MainWindowTopButtons : UserControl
{
public event PropertyChangedEventHandler PropertyChanged;

// Button Event Handlers
public event EventHandler OpenSource;
public event EventHandler SetDestination;
public event EventHandler AddToQueue;
public event EventHandler OpenSettings;
public event EventHandler Start;
public event EventHandler Cancel;

// Background for Buttons
public new SolidColorBrush Background { get; set; }

public MainWindowTopButtons()
{
InitializeComponent();
DataContext = this;
}

private void ButtonOpenSource_Click(object sender, RoutedEventArgs e)
{
OpenSource?.Invoke(this, e);
}

private void ButtonSetDestination_Click(object sender, RoutedEventArgs e)
{
SetDestination?.Invoke(this, e);
}

private void ButtonAddToQueue_Click(object sender, RoutedEventArgs e)
{
AddToQueue?.Invoke(this, e);
}

private void ButtonProgramSettings_Click(object sender, RoutedEventArgs e)
{
OpenSettings?.Invoke(this, e);
}

private void ButtonStartStop_Click(object sender, RoutedEventArgs e)
{
Start?.Invoke(this, e);
}

private void ButtonCancelEncode_Click(object sender, RoutedEventArgs e)
{
Cancel?.Invoke(this, e);
}
}
}
50 changes: 15 additions & 35 deletions NotEnoughAV1Encodes/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
xmlns:local="clr-namespace:NotEnoughAV1Encodes"
xmlns:neav1eControls="clr-namespace:NotEnoughAV1Encodes.Controls"
mc:Ignorable="d"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="NotEnoughAV1Encodes"
Expand All @@ -19,24 +20,19 @@
</Window.TaskbarItemInfo>
<Grid>
<Image x:Name="bgImage" Stretch="UniformToFill" />
<Button x:Name="ButtonOpenSource" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="130" Height="45" Click="ButtonOpenSource_Click" Background="{Binding ElementName=ListBoxAudioTracks, Path=Background, UpdateSourceTrigger=PropertyChanged}">
<Canvas Height="30" Width="114">
<Image Height="44" Canvas.Left="-6" Canvas.Top="-7" Width="45" Source="/resources/img/video.png"/>
<Label x:Name="LabelSource" Content="{lex:Loc}" Canvas.Left="38" Width="76" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
</Canvas>
</Button>
<Button x:Name="ButtonSetDestination" HorizontalAlignment="Left" Margin="145,10,0,0" VerticalAlignment="Top" Width="130" Height="45" Click="ButtonSetDestination_Click" Background="{Binding ElementName=ListBoxAudioTracks, Path=Background, UpdateSourceTrigger=PropertyChanged}">
<Canvas Height="30" Width="120">
<Image Height="44" Canvas.Left="-6" Canvas.Top="-7" Width="45" Source="/resources/img/save.png"/>
<Label x:Name="LabelDestination" Content="{lex:Loc}" Canvas.Left="32" Width="88" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
</Canvas>
</Button>
<Button x:Name="ButtonStartStop" Margin="0,10,189,0" VerticalAlignment="Top" Height="45" Click="ButtonStartStop_Click" HorizontalAlignment="Right" Width="118" Background="{Binding ElementName=ListBoxAudioTracks, Path=Background, UpdateSourceTrigger=PropertyChanged}">
<Canvas Height="30" Width="120">
<Image x:Name="ImageStartStop" Height="44" Canvas.Left="-6" Canvas.Top="-7" Width="45" Source="/resources/img/start.png"/>
<Label x:Name="LabelStartPauseButton" Content="{lex:Loc}" Canvas.Left="32" Width="78" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
</Canvas>
</Button>

<neav1eControls:MainWindowTopButtons
x:Name="TopButtonsControl"
OpenSource="ButtonOpenSource_Click"
SetDestination="ButtonSetDestination_Click"
AddToQueue="ButtonAddToQueue_Click"
OpenSettings="ButtonProgramSettings_Click"
Start="ButtonStartStop_Click"
Cancel="ButtonCancelEncode_Click"
Background="{Binding ElementName=ListBoxAudioTracks, Path=Background, UpdateSourceTrigger=PropertyChanged}"/>



<mah:MetroTabControl x:Name="TabControl" Margin="0,60,0,0" >
<TabItem x:Name="TabItemSummary" Header="{lex:Loc}">
<Grid>
Expand Down Expand Up @@ -1355,22 +1351,6 @@
</Grid>
</TabItem>
</mah:MetroTabControl>
<Button x:Name="ButtonProgramSettings" Margin="0,10,10,0" VerticalAlignment="Top" Height="45" Click="ButtonProgramSettings_Click" HorizontalAlignment="Right" Width="45" Background="{Binding ElementName=ListBoxAudioTracks, Path=Background, UpdateSourceTrigger=PropertyChanged}">
<Canvas Height="30" Width="120">
<Image x:Name="ImageStartStop1" Height="44" Canvas.Left="-6" Canvas.Top="-7" Width="45" Source="/resources/img/settings.png"/>
</Canvas>
</Button>
<Button x:Name="ButtonCancelEncode" Margin="0,10,60,0" VerticalAlignment="Top" Height="45" Click="ButtonCancelEncode_Click" HorizontalAlignment="Right" Width="124" Background="{Binding ElementName=ListBoxAudioTracks, Path=Background, UpdateSourceTrigger=PropertyChanged}">
<Canvas Height="30" Width="102">
<Label x:Name="LabelCancel" Content="{lex:Loc}" Canvas.Left="30" Width="81" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
<Image Height="44" Canvas.Left="-10" Canvas.Top="-7" Width="44" Source="/resources/img/stop.png"/>
</Canvas>
</Button>
<Button x:Name="ButtonAddToQueue" Margin="280,10,0,0" VerticalAlignment="Top" Height="45" HorizontalAlignment="Left" Width="180" Click="ButtonAddToQueue_Click" Background="{Binding ElementName=ListBoxAudioTracks, Path=Background, UpdateSourceTrigger=PropertyChanged}">
<Canvas Height="30" Width="120">
<Image x:Name="ImageStartStop2" Height="44" Canvas.Left="-23" Canvas.Top="-7" Width="44" Source="/resources/img/queue.png"/>
<Label x:Name="LabelAddToQueue" Content="{lex:Loc}" Canvas.Left="26" Width="122" Height="30" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="14"/>
</Canvas>
</Button>

</Grid>
</mah:MetroWindow>
41 changes: 21 additions & 20 deletions NotEnoughAV1Encodes/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ private void ButtonCropPreviewBackward_Click(object sender, RoutedEventArgs e)
LoadCropPreview(index);
}

private void ButtonCancelEncode_Click(object sender, RoutedEventArgs e)
private void ButtonCancelEncode_Click(object sender, EventArgs e)
{
if (cancellationTokenSource == null) return;
try
{
cancellationTokenSource.Cancel();
ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/start.png", UriKind.Relative));
ButtonAddToQueue.IsEnabled = true;
TopButtonsControl.ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/start.png", UriKind.Relative));
TopButtonsControl.ButtonAddToQueue.IsEnabled = true;
ButtonRemoveSelectedQueueItem.IsEnabled = true;
ButtonEditSelectedItem.IsEnabled = true;
ButtonClearQueue.IsEnabled = true;
Expand All @@ -219,7 +219,7 @@ private void ButtonCancelEncode_Click(object sender, RoutedEventArgs e)
catch { }
}

private void ButtonProgramSettings_Click(object sender, RoutedEventArgs e)
private void ButtonProgramSettings_Click(object sender, EventArgs e)
{
Views.ProgramSettings programSettings = new(settingsDB);
programSettings.ShowDialog();
Expand Down Expand Up @@ -258,7 +258,7 @@ private void QueueMenuItemOpenOutputDir_Click(object sender, RoutedEventArgs e)
catch { }
}

private void ButtonOpenSource_Click(object sender, RoutedEventArgs e)
private void ButtonOpenSource_Click(object sender, EventArgs e)
{
Views.OpenSource openSource = new(settingsDB.Theme);
openSource.ShowDialog();
Expand Down Expand Up @@ -488,7 +488,7 @@ private void SingleFileInput(string path)
CreateCropPreviewsOnLoad();
}

private void ButtonSetDestination_Click(object sender, RoutedEventArgs e)
private void ButtonSetDestination_Click(object sender, EventArgs e)
{
string fileName = "";

Expand Down Expand Up @@ -532,7 +532,7 @@ private void ButtonSetDestination_Click(object sender, RoutedEventArgs e)
}
}

private void ButtonStartStop_Click(object sender, RoutedEventArgs e)
private void ButtonStartStop_Click(object sender, EventArgs e)
{
if (ListBoxQueue.Items.Count == 0)
{
Expand All @@ -543,13 +543,13 @@ private void ButtonStartStop_Click(object sender, RoutedEventArgs e)
{
if (ProgramState is 0 or 2)
{
ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/pause.png", UriKind.Relative));
LabelStartPauseButton.Content = LocalizedStrings.Instance["Pause"];
TopButtonsControl.ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/pause.png", UriKind.Relative));
TopButtonsControl.LabelStartPauseButton.Content = LocalizedStrings.Instance["Pause"];

// Main Start
if (ProgramState is 0)
{
ButtonAddToQueue.IsEnabled = false;
TopButtonsControl.ButtonAddToQueue.IsEnabled = false;
ButtonRemoveSelectedQueueItem.IsEnabled = false;
ButtonEditSelectedItem.IsEnabled = false;
ButtonClearQueue.IsEnabled = false;
Expand All @@ -572,8 +572,8 @@ private void ButtonStartStop_Click(object sender, RoutedEventArgs e)
else if (ProgramState is 1)
{
ProgramState = 2;
ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/resume.png", UriKind.Relative));
LabelStartPauseButton.Content = LocalizedStrings.Instance["Resume"];
TopButtonsControl.ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/resume.png", UriKind.Relative));
TopButtonsControl.LabelStartPauseButton.Content = LocalizedStrings.Instance["Resume"];

// Pause all PIDs
foreach (int pid in Global.LaunchedPIDs)
Expand All @@ -588,7 +588,7 @@ private void ButtonStartStop_Click(object sender, RoutedEventArgs e)
}
}

private void ButtonAddToQueue_Click(object sender, RoutedEventArgs e)
private void ButtonAddToQueue_Click(object sender, EventArgs e)
{
PreAddToQueue();
}
Expand Down Expand Up @@ -1848,8 +1848,8 @@ private void AutoPauseResume()
// Pause
if (time < 40.0)
{
Dispatcher.Invoke(() => ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/resume.png", UriKind.Relative)));
Dispatcher.Invoke(() => LabelStartPauseButton.Content = LocalizedStrings.Instance["Resume"]);
Dispatcher.Invoke(() => TopButtonsControl.ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/resume.png", UriKind.Relative)));
Dispatcher.Invoke(() => TopButtonsControl.LabelStartPauseButton.Content = LocalizedStrings.Instance["Resume"]);
Dispatcher.Invoke(() => Title = "NEAV1E - " + LocalizedStrings.Instance["ToggleSwitchAutoPauseResume"] + " => Paused");

// Pause all PIDs
Expand All @@ -1867,8 +1867,8 @@ private void AutoPauseResume()
// Resume
if (time > 60.0)
{
Dispatcher.Invoke(() => ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/pause.png", UriKind.Relative)));
Dispatcher.Invoke(() => LabelStartPauseButton.Content = LocalizedStrings.Instance["Pause"]);
Dispatcher.Invoke(() => TopButtonsControl.ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/pause.png", UriKind.Relative)));
Dispatcher.Invoke(() => TopButtonsControl.LabelStartPauseButton.Content = LocalizedStrings.Instance["Pause"]);
Dispatcher.Invoke(() => Title = "NEAV1E - " + LocalizedStrings.Instance["ToggleSwitchAutoPauseResume"] + " => Encoding");

// Resume all PIDs
Expand Down Expand Up @@ -2882,9 +2882,9 @@ private async Task MainStartAsync(CancellationToken _cancelToken)
catch (OperationCanceledException) { }

ProgramState = 0;
ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/start.png", UriKind.Relative));
LabelStartPauseButton.Content = LocalizedStrings.Instance["LabelStartPauseButton"];
ButtonAddToQueue.IsEnabled = true;
TopButtonsControl.ImageStartStop.Source = new BitmapImage(new Uri(@"/NotEnoughAV1Encodes;component/resources/img/start.png", UriKind.Relative));
TopButtonsControl.LabelStartPauseButton.Content = LocalizedStrings.Instance["LabelStartPauseButton"];
TopButtonsControl.ButtonAddToQueue.IsEnabled = true;
ButtonRemoveSelectedQueueItem.IsEnabled = true;
ButtonEditSelectedItem.IsEnabled = true;
ButtonClearQueue.IsEnabled = true;
Expand Down Expand Up @@ -3036,5 +3036,6 @@ private void UpdateTaskbarProgress()
catch { }
}
#endregion

}
}

0 comments on commit dc8c9fc

Please sign in to comment.