<UserControl x:Class="HavenSoft.HexManiac.WPF.Controls.SelectedBlockEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:HavenSoft.HexManiac.WPF.Controls"
             xmlns:res="clr-namespace:HavenSoft.HexManiac.WPF.Resources"
             >
   <Grid>
      <Grid.ColumnDefinitions>
         <ColumnDefinition />
         <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>
      <Grid VerticalAlignment="Center">
         <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
         </Grid.ColumnDefinitions>
         <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
         </Grid.RowDefinitions>
         <local:AngleBorder Direction="Left" Content="Behavior:" Margin="0,0,-2,0" />
         <local:AngleComboBox Direction="Out" Grid.Column="1" SelectedIndex="{Binding Behavior}" ItemsSource="{Binding BehaviorOptions}" Margin="2" />
         <local:AngleBorder Direction="Left" Content="Layer:" Grid.Row="1" Margin="0,0,-2,0" />
         <local:AngleComboBox Direction="Out" Grid.Row="1" Grid.Column="1" SelectedIndex="{Binding Layer}" ItemsSource="{Binding LayerOptions}" Margin="2" />

         <local:AngleBorder Direction="Left" Content="Terrain:" Grid.Row="2" Margin="0,0,-2,0"
            Visibility="{Binding HasTerrainAndEncounter, Converter={StaticResource BoolToVisibility}}" />
         <local:AngleComboBox Direction="Out" Grid.Row="2" Grid.Column="1" Margin="2"
            SelectedIndex="{Binding Terrain}" ItemsSource="{Binding TerrainOptions}"
            Visibility="{Binding HasTerrainAndEncounter, Converter={StaticResource BoolToVisibility}}" />
         <local:AngleBorder Direction="Left" Content="Encounter:" Grid.Row="3" Margin="0,0,-2,0"
            Visibility="{Binding HasTerrainAndEncounter, Converter={StaticResource BoolToVisibility}}" />
         <local:AngleComboBox Direction="Out" Grid.Row="3" Grid.Column="1" Margin="2"
            SelectedIndex="{Binding Encounter}" ItemsSource="{Binding EncounterOptions}"
            Visibility="{Binding HasTerrainAndEncounter, Converter={StaticResource BoolToVisibility}}" />
      </Grid>
      <ContentControl Grid.Column="1" Width="112" Height="112" MouseLeave="MouseExitTiles" MouseWheel="WheelOverImage">
         <ContentControl.Template>
            <ControlTemplate TargetType="ContentControl">
               <Canvas Width="96" Height="96" Margin="8" ClipToBounds="False" Background="{DynamicResource Background}">
                  <Canvas.Resources>
                     <Style TargetType="{x:Type local:PixelImage}">
                        <Setter Property="UseTrueTransparency" Value="True" />
                     </Style>
                     <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
                        <Setter Property="BorderBrush" Value="Transparent" />
                        <Setter Property="BorderThickness" Value="1" />
                        <Setter Property="Background" Value="{DynamicResource Background}" />
                        <Setter Property="Width" Value="8" />
                        <Setter Property="Height" Value="8" />
                        <Setter Property="Padding" Value="0" />
                     </Style>
                     <Style TargetType="Path">
                        <Setter Property="Fill" Value="{DynamicResource Secondary}" />
                        <Setter Property="Stretch" Value="Fill" />
                     </Style>
                  </Canvas.Resources>

                  <Viewbox Canvas.Bottom="95" Canvas.Left="-1" Stretch="Uniform" StretchDirection="DownOnly" Width="48" Height="12">
                     <local:AngleBorder Content="Foreground" Direction="Out" />
                  </Viewbox>
                  <Viewbox Canvas.Bottom="47" Canvas.Left="48" Stretch="Uniform" StretchDirection="DownOnly" Width="48" Height="12">
                     <local:AngleBorder Content="Background" Direction="Out" />
                  </Viewbox>

                  <Button Width="24" Canvas.Left="{Binding FlipHLeft}" Canvas.Top="{Binding FlipHTop}" Command="{res:MethodCommand FlipH}" Visibility="{Binding FlipHVisible, Converter={StaticResource BoolToVisibility}}">
                     <Path Data="{res:Icon ArrowsLeftRight}" />
                  </Button>
                  <Button Height="24" Canvas.Left="{Binding FlipVLeft}" Canvas.Top="{Binding FlipVTop}" Command="{res:MethodCommand FlipV}" Visibility="{Binding FlipVVisible, Converter={StaticResource BoolToVisibility}}">
                     <Path Data="{res:Icon ArrowsUpDown}" />
                  </Button>

                  <local:PixelImage x:Name="LeftTopBack"      DataContext="{Binding LeftTopBack}"      Canvas.Top="48" Canvas.Left="48" MouseEnter="MouseEnterTile" MouseLeftButtonDown="MouseClickTile" MouseRightButtonDown="MouseGrabTile" />
                  <local:PixelImage x:Name="LeftTopFront"     DataContext="{Binding LeftTopFront}"     Canvas.Top="0"  Canvas.Left="0"  MouseEnter="MouseEnterTile" MouseLeftButtonDown="MouseClickTile" MouseRightButtonDown="MouseGrabTile" />
                  <local:PixelImage x:Name="RightTopBack"     DataContext="{Binding RightTopBack}"     Canvas.Top="48" Canvas.Left="72" MouseEnter="MouseEnterTile" MouseLeftButtonDown="MouseClickTile" MouseRightButtonDown="MouseGrabTile" />
                  <local:PixelImage x:Name="RightTopFront"    DataContext="{Binding RightTopFront}"    Canvas.Top="0"  Canvas.Left="24" MouseEnter="MouseEnterTile" MouseLeftButtonDown="MouseClickTile" MouseRightButtonDown="MouseGrabTile" />
                  <local:PixelImage x:Name="LeftBottomBack"   DataContext="{Binding LeftBottomBack}"   Canvas.Top="72" Canvas.Left="48" MouseEnter="MouseEnterTile" MouseLeftButtonDown="MouseClickTile" MouseRightButtonDown="MouseGrabTile" />
                  <local:PixelImage x:Name="LeftBottomFront"  DataContext="{Binding LeftBottomFront}"  Canvas.Top="24" Canvas.Left="0"  MouseEnter="MouseEnterTile" MouseLeftButtonDown="MouseClickTile" MouseRightButtonDown="MouseGrabTile" />
                  <local:PixelImage x:Name="RightBottomBack"  DataContext="{Binding RightBottomBack}"  Canvas.Top="72" Canvas.Left="72" MouseEnter="MouseEnterTile" MouseLeftButtonDown="MouseClickTile" MouseRightButtonDown="MouseGrabTile" />
                  <local:PixelImage x:Name="RightBottomFront" DataContext="{Binding RightBottomFront}" Canvas.Top="24" Canvas.Left="24" MouseEnter="MouseEnterTile" MouseLeftButtonDown="MouseClickTile" MouseRightButtonDown="MouseGrabTile" />

                  <Button Width="16" Height="16" Command="{res:MethodCommand CopyForeground}" Canvas.Left="56" Canvas.Top="8" ToolTip="Copy Foreground Tiles">
                     <Path Data="{res:Icon Copy}" />
                  </Button>
                  <Button Width="16" Height="16" Command="{res:MethodCommand PasteForeground}" Canvas.Left="72" Canvas.Top="24" ToolTip="Paste Foreground Tiles">
                     <Path Data="{res:Icon Paste}" />
                  </Button>
                  <Button Width="16" Height="16" Command="{res:MethodCommand CopyBackground}" Canvas.Left="8" Canvas.Top="56" ToolTip="Copy Background Tiles">
                     <Path Data="{res:Icon Copy}" />
                  </Button>
                  <Button Width="16" Height="16" Command="{res:MethodCommand PasteBackground}" Canvas.Left="24" Canvas.Top="72" ToolTip="Paste Background Tiles">
                     <Path Data="{res:Icon Paste}" />
                  </Button>
               </Canvas>
               <ControlTemplate.Resources>
                  <Storyboard x:Key="AnimateToSplitView">
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopBack"      Storyboard.TargetProperty="(Canvas.Top)"  To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopBack"      Storyboard.TargetProperty="(Canvas.Left)" To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopFront"     Storyboard.TargetProperty="(Canvas.Top)"  To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopFront"     Storyboard.TargetProperty="(Canvas.Left)" To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopBack"     Storyboard.TargetProperty="(Canvas.Top)"  To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopBack"     Storyboard.TargetProperty="(Canvas.Left)" To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopFront"    Storyboard.TargetProperty="(Canvas.Top)"  To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopFront"    Storyboard.TargetProperty="(Canvas.Left)" To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomBack"   Storyboard.TargetProperty="(Canvas.Top)"  To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomBack"   Storyboard.TargetProperty="(Canvas.Left)" To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomFront"  Storyboard.TargetProperty="(Canvas.Top)"  To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomFront"  Storyboard.TargetProperty="(Canvas.Left)" To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomBack"  Storyboard.TargetProperty="(Canvas.Top)"  To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomBack"  Storyboard.TargetProperty="(Canvas.Left)" To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomFront" Storyboard.TargetProperty="(Canvas.Top)"  To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomFront" Storyboard.TargetProperty="(Canvas.Left)" To="24" />
                  </Storyboard>
                  <Storyboard x:Key="AnimateToBackView">
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopBack"      Storyboard.TargetProperty="(Canvas.Top)"  To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopBack"      Storyboard.TargetProperty="(Canvas.Left)" To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopFront"     Storyboard.TargetProperty="(Canvas.Top)"  To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopFront"     Storyboard.TargetProperty="(Canvas.Left)" To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopBack"     Storyboard.TargetProperty="(Canvas.Top)"  To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopBack"     Storyboard.TargetProperty="(Canvas.Left)" To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopFront"    Storyboard.TargetProperty="(Canvas.Top)"  To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopFront"    Storyboard.TargetProperty="(Canvas.Left)" To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomBack"   Storyboard.TargetProperty="(Canvas.Top)"  To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomBack"   Storyboard.TargetProperty="(Canvas.Left)" To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomFront"  Storyboard.TargetProperty="(Canvas.Top)"  To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomFront"  Storyboard.TargetProperty="(Canvas.Left)" To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomBack"  Storyboard.TargetProperty="(Canvas.Top)"  To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomBack"  Storyboard.TargetProperty="(Canvas.Left)" To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomFront" Storyboard.TargetProperty="(Canvas.Top)"  To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomFront" Storyboard.TargetProperty="(Canvas.Left)" To="72" />
                  </Storyboard>
                  <Storyboard x:Key="AnimateToFrontView">
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopBack"      Storyboard.TargetProperty="(Canvas.Top)"  To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopBack"      Storyboard.TargetProperty="(Canvas.Left)" To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopFront"     Storyboard.TargetProperty="(Canvas.Top)"  To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftTopFront"     Storyboard.TargetProperty="(Canvas.Left)" To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopBack"     Storyboard.TargetProperty="(Canvas.Top)"  To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopBack"     Storyboard.TargetProperty="(Canvas.Left)" To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopFront"    Storyboard.TargetProperty="(Canvas.Top)"  To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightTopFront"    Storyboard.TargetProperty="(Canvas.Left)" To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomBack"   Storyboard.TargetProperty="(Canvas.Top)"  To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomBack"   Storyboard.TargetProperty="(Canvas.Left)" To="0"  />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomFront"  Storyboard.TargetProperty="(Canvas.Top)"  To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="LeftBottomFront"  Storyboard.TargetProperty="(Canvas.Left)" To="24" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomBack"  Storyboard.TargetProperty="(Canvas.Top)"  To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomBack"  Storyboard.TargetProperty="(Canvas.Left)" To="72" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomFront" Storyboard.TargetProperty="(Canvas.Top)"  To="48" />
                     <DoubleAnimation DecelerationRatio="1" Duration="0:0:0.5" Storyboard.TargetName="RightBottomFront" Storyboard.TargetProperty="(Canvas.Left)" To="48" />
                  </Storyboard>
               </ControlTemplate.Resources>
            </ControlTemplate>
         </ContentControl.Template>
      </ContentControl>
      <TextBlock Grid.ColumnSpan="2" Height="20" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,-15"
                 Foreground="{DynamicResource Error}" Text="{Binding ErrorText}" Visibility="{Binding HasError, Converter={StaticResource BoolToVisibility}}" />
   </Grid>
</UserControl>
