 <UserControl x:Class="HandBrakeWPF.Views.PictureSettingsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Converters="clr-namespace:HandBrakeWPF.Converters"
             xmlns:controls="clr-namespace:HandBrakeWPF.Controls"
              xmlns:Properties="clr-namespace:HandBrakeWPF.Properties">

    <UserControl.Resources>
        <Converters:BooleanConverter x:Key="boolConverter" />
        <Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
        <Converters:BooleanToHiddenVisibilityConverter x:Key="boolToVisHiddenConverter" />
        <Style TargetType="controls:NumberBox">
            <Setter Property="Height" Value="24" />
        </Style>
    </UserControl.Resources>

    <Border Background="Transparent">
        <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <!-- Size Panel-->
            <StackPanel Name="SizePanel" Orientation="Vertical" VerticalAlignment="Top" Margin="5,0,0,0"  Grid.Column="0" Grid.Row="0">
                <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Size}"  FontWeight="Bold" />

                <!-- Row 1-->
                <StackPanel Orientation="Horizontal" Margin="0,0,5,0">
                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Source}" />
                    <Label Content="{Binding SourceInfo}" Name="sourceResolution"/>
                </StackPanel>

                <!-- Row 2-->
                <StackPanel Orientation="Horizontal" Margin="0,0,5,0">
                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Width}" />
                    <controls:NumberBox Number="{Binding Width, Mode=TwoWay}" UpdateBindingOnTextChange="True" IsEnabled="{Binding WidthControlEnabled}" 
                                        Modulus="{Binding SelectedModulus, Mode=OneWay}"
                                        ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_Width}"  Minimum="0" Width="60"  />
                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Height}" />
                    <controls:NumberBox Number="{Binding Height, Mode=TwoWay}" IsEnabled="{Binding HeightControlEnabled}" UpdateBindingOnTextChange="True" 
                                        Modulus="{Binding SelectedModulus, Mode=OneWay}" 
                                        ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_Height}" Minimum="0" Width="60"  />
                    <CheckBox Content="{x:Static Properties:ResourcesUI.PictureSettingsView_KeepAR}" IsChecked="{Binding MaintainAspectRatio}"
                          Visibility="{Binding ShowKeepAR, Converter={StaticResource boolToVisHiddenConverter}}" ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_KeepAR}"
                          VerticalAlignment="Center" Margin="5,0,0,0" />
                </StackPanel>

                <!-- Row 3-->
                <Grid Margin="0,15,5,0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Anamorphic}" Grid.Row="0" Grid.Column="0" />
                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Modulus}" Grid.Row="1" Grid.Column="0" 
                       Visibility="{Binding ShowModulus, Converter={StaticResource boolToVisConverter}}" />

                    <ComboBox Width="110" Grid.Row="0" ItemsSource="{Binding AnamorphicModes}" SelectedItem="{Binding SelectedAnamorphicMode}" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,5"
                              ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_Anamorphic}" />
                    <ComboBox Width="110" Grid.Row="1" ItemsSource="{Binding ModulusValues}" SelectedItem="{Binding SelectedModulus}" 
                          Visibility="{Binding ShowModulus, Converter={StaticResource boolToVisConverter}}" ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_Modulus}"
                          Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,5" />
                </Grid>

                <!-- Custom Anamoprhic -->
                <Grid Margin="0,15,5,0" Visibility="{Binding ShowCustomAnamorphicControls, Converter={StaticResource boolToVisConverter}}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_DisplayWitdh}" Grid.Row="0" Grid.Column="0" />
                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_PAR}" Grid.Row="1" Grid.Column="0" />

                    <controls:NumberBox Width="60" Number="{Binding DisplayWidth, Mode=TwoWay}" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Margin="0,0,0,5" 
                                    AllowEmpty="False" IsEnabled="{Binding MaintainAspectRatio, Converter={StaticResource boolConverter}, ConverterParameter=true}" />
                    <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1">
                        <controls:NumberBox Width="60" Number="{Binding ParWidth, Mode=TwoWay}" HorizontalAlignment="Left" AllowEmpty="False"
                                                 IsEnabled="{Binding MaintainAspectRatio, Converter={StaticResource boolConverter}, ConverterParameter=true}" Margin="0,0,0,5"
                                                 ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_PAR}"/>
                        <TextBlock Text="X" Margin="10,0,10,0" />
                        <controls:NumberBox Width="60" Number="{Binding ParHeight, Mode=TwoWay}"  HorizontalAlignment="Left" AllowEmpty="False"
                                                 IsEnabled="{Binding MaintainAspectRatio, Converter={StaticResource boolConverter}, ConverterParameter=true}" Margin="0,0,0,5"
                                                 ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_PAR}"/>
                    </StackPanel>
                </Grid>

            </StackPanel>

            <!-- Crop Panel -->
            <StackPanel Name="CropPanel" Margin="15,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Row="0" Grid.RowSpan="2" Grid.Column="1">
                <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Cropping}" FontWeight="Bold" />
                <RadioButton Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Automatic}" IsChecked="{Binding IsCustomCrop, Converter={StaticResource boolConverter}, ConverterParameter=true}" Margin="10,0,0,0"
                             ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_AutoCrop}"  />
                <RadioButton Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Custom}" IsChecked="{Binding IsCustomCrop}" Margin="10,5,0,0"
                             ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_ManualCrop}"  />

                <Grid Margin="0,10,0,0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Top}" Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" />
                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Bottom}" Grid.Row="4" Grid.Column="2" VerticalAlignment="Center" />
                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Left}" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" />
                    <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Right}" Grid.Row="2" Grid.Column="4" HorizontalAlignment="Center" />

                    <controls:NumberBox Width="60" HorizontalAlignment="Left" Margin="0,0,0,5" IsEnabled="{Binding IsCustomCrop}" Grid.Row="1" Grid.Column="2"
                                    Minimum="0" Modulus="2" Number="{Binding CropTop, Mode=TwoWay}" UpdateBindingOnTextChange="True" ShowIncrementButtons="True" AllowEmpty="False"
                                        ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_CropTop}" />

                    <controls:NumberBox Width="60" HorizontalAlignment="Left" Margin="0,0,0,5" IsEnabled="{Binding IsCustomCrop}" Grid.Row="3" Grid.Column="2"
                                    Minimum="0" Modulus="2" Number="{Binding CropBottom, Mode=TwoWay}" UpdateBindingOnTextChange="True" ShowIncrementButtons="True" AllowEmpty="False"
                                        ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_CropBottom}" />

                    <controls:NumberBox Width="60" HorizontalAlignment="Left" Margin="0,0,0,5" IsEnabled="{Binding IsCustomCrop}" Grid.Row="2" Grid.Column="1"
                                    Minimum="0" Modulus="2" Number="{Binding CropLeft, Mode=TwoWay}" UpdateBindingOnTextChange="True" ShowIncrementButtons="True" AllowEmpty="False"
                                      ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_CropLeft}"  />

                    <controls:NumberBox Width="60" HorizontalAlignment="Left" Margin="0,0,0,5" IsEnabled="{Binding IsCustomCrop}" Grid.Row="2" Grid.Column="3"
                                    Minimum="0" Modulus="2" Number="{Binding CropRight, Mode=TwoWay}" UpdateBindingOnTextChange="True" ShowIncrementButtons="True" AllowEmpty="False"
                                        ToolTip="{x:Static Properties:ResourcesTooltips.PictureSettingsView_CropRight}" />

                </Grid>

            </StackPanel>

            <!-- Preview Panel -->
            <StackPanel Name="PreviewPanel" Margin="5,5,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Row="1"  Grid.Column="0">
                <Label Content="{x:Static Properties:ResourcesUI.PictureSettingsView_Output}" FontWeight="Bold" />

                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Label Content="{Binding DisplaySize}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Margin="0,0,0,5"
                       Visibility="{Binding ShowDisplaySize, Converter={StaticResource boolToVisConverter}}" />
                </Grid>
                
            </StackPanel>
        </Grid>
    </Border>
</UserControl>
