Implemented gif exportation and added some style (again)
This commit is contained in:
21
GifResizer/Views/Converter/VisibleWhenNullConverter.cs
Normal file
21
GifResizer/Views/Converter/VisibleWhenNullConverter.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace GifResizer.Views.Converter;
|
||||
|
||||
public class VisibleWhenNullConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
bool invert = parameter?.ToString() == "invert";
|
||||
bool isVisible = invert ? value != null : value == null;
|
||||
|
||||
return isVisible ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -4,70 +4,124 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:gif="http://wpfanimatedgif.codeplex.com"
|
||||
xmlns:converter="clr-namespace:GifResizer.Views.Converter"
|
||||
mc:Ignorable="d"
|
||||
Title="Gif resizer" Height="480" Width="640"
|
||||
ResizeMode="NoResize">
|
||||
|
||||
<Grid>
|
||||
<Window.Resources>
|
||||
<converter:VisibleWhenNullConverter x:Key="VisibleWhenNullConverter"/>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid x:Name="MainContainer">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="3*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border Grid.Row="0" BorderBrush="Gray"
|
||||
BorderThickness="1"
|
||||
CornerRadius="5"
|
||||
Margin="10 10 10 5">
|
||||
<Grid Style="{StaticResource DarkGrid}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="3*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Image gif:ImageBehavior.AnimatedSource="{Binding FilePath}"
|
||||
Stretch="Uniform"
|
||||
Visibility="{Binding FilePath}"/>
|
||||
|
||||
<Button Grid.Row="0"
|
||||
Style="{StaticResource LinkButtonStyle}"
|
||||
Click="BrowseButton_Click"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock Text="Browse files"
|
||||
Width="Auto"
|
||||
Height="Auto"
|
||||
TextDecorations="Underline"/>
|
||||
</Button>
|
||||
<TextBlock Grid.Row="1"
|
||||
Margin="0,0,0,5"
|
||||
Text="{Binding FilePath,
|
||||
TargetNullValue=No file selected,
|
||||
FallbackValue=Gif filepath...}"
|
||||
Width="Auto"
|
||||
Height="Auto"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border Grid.Row="1" BorderBrush="Gray"
|
||||
<Border Grid.Row="0"
|
||||
BorderBrush="Gray"
|
||||
BorderThickness="1"
|
||||
CornerRadius="5"
|
||||
Padding="5"
|
||||
Margin="10 5 10 10">
|
||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox Content="112x112" IsChecked="True" Margin="10"/>
|
||||
<CheckBox Content="500x500" IsChecked="True" Margin="10"/>
|
||||
<CheckBox Content="1000x1000" IsChecked="True" Margin="10"/>
|
||||
</StackPanel>
|
||||
<Button
|
||||
Style="{StaticResource ButtonStyle}"
|
||||
Content="Resize"
|
||||
Click="ResizeButton_Click"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
Margin="10 10 10 5">
|
||||
|
||||
<!-- GIF -->
|
||||
<Grid x:Name="GifPreview"
|
||||
Style="{StaticResource DarkGrid}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="4*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Image Grid.Column="0" gif:ImageBehavior.AnimatedSource="{Binding FilePath}"
|
||||
Stretch="UniformToFill"
|
||||
Visibility="{
|
||||
Binding FilePath,
|
||||
Converter={StaticResource VisibleWhenNullConverter},
|
||||
ConverterParameter=invert
|
||||
}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<Button Grid.Column="0"
|
||||
Style="{StaticResource LinkButtonStyle}"
|
||||
Click="BrowseButton_Click"
|
||||
Visibility="{
|
||||
Binding FilePath,
|
||||
Converter={StaticResource VisibleWhenNullConverter}
|
||||
}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock
|
||||
Text="Browse files..."
|
||||
Width="Auto"
|
||||
Height="Auto"
|
||||
TextDecorations="Underline"/>
|
||||
</Button>
|
||||
|
||||
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch"/>
|
||||
|
||||
<Grid Grid.Column="1" Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="75*"/>
|
||||
<RowDefinition Height="25*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel x:Name="GifInfo" Grid.Row="0">
|
||||
<StackPanel Margin="0 0 0 15">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0">Location</TextBlock>
|
||||
<TextBlock Text="{Binding FilePath}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Grid.Column="0">Width</TextBlock>
|
||||
<TextBlock Grid.Row="0" Grid.Column="2">Height</TextBlock>
|
||||
<TextBox Grid.Row="1" Grid.Column="0" Text="{Binding GifWidth}"></TextBox>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding GifHeight}"></TextBox>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<Rectangle Grid.Row="1"
|
||||
Height="1"
|
||||
Fill="Gray"
|
||||
VerticalAlignment="Top"/>
|
||||
|
||||
<StackPanel x:Name="Actions" Grid.Row="1" Orientation="Vertical"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Center">
|
||||
|
||||
<TextBlock VerticalAlignment="Top" Margin="0 0 0 5">Common formats</TextBlock>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding CommonFormats}" Margin="0 0 0 5">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox Content="{Binding}"
|
||||
IsChecked="{Binding Checked}"
|
||||
Margin="0 0 10 5"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Button
|
||||
Style="{StaticResource ButtonStyle}"
|
||||
Content="Resize"
|
||||
Click="ResizeButton_Click"
|
||||
VerticalAlignment="Bottom"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using GifResizer.ViewModels;
|
||||
using Microsoft.Win32;
|
||||
|
||||
@@ -31,21 +32,21 @@ public partial class MainWindow : Window
|
||||
|
||||
if (fileDialog.ShowDialog() == true)
|
||||
{
|
||||
_mainViewModel.FilePath = fileDialog.FileName;
|
||||
_mainViewModel.LoadGifData(fileDialog.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DisplayErrorMessage("An error occured while selecting the GIF file: " + ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ResizeButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mainViewModel.ResizeGif(128,128);
|
||||
_mainViewModel.ResizeGif();
|
||||
DisplaySuccessMessage("Resize successful!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -53,8 +54,18 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
private void IntegerOnly(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !int.TryParse(e.Text, out _);
|
||||
}
|
||||
|
||||
private void DisplayErrorMessage(string message)
|
||||
{
|
||||
MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
private void DisplaySuccessMessage(string message)
|
||||
{
|
||||
MessageBox.Show(message, "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user