<?xml version="1.0" encoding="utf-8"?>

<!--
This is the master template for standard menu screens:
A header text, left the menu, under the menu a small video preview,
at the right side the content pane and at the bottom the current play control.

Usage:

  <Include
      xmlns="www.team-mediaportal.com/2008/mpf/directx"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Source="screens\master_menu.xaml">
    <Include.Resources>
      <ResourceWrapper x:Key="Header_Text">
        [Header text]
      </ResourceWrapper>
      <ControlTemplate x:Key="Contents_Template">
        [UI element to be displayed in the content area]
      </ControlTemplate>
    </Include.Resources>
  </Include>

Parameters which have to be accessible by a DynamicResource lookup:
 - Header_Text (String): The text to be displayed as header
 - Contents_Template (ConrolTemplate): Template for element to be displayed
   in the content area at the right side
-->

<Include
    xmlns="www.team-mediaportal.com/2008/mpf/directx"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Source="screens\master_bare.xaml"
    xmlns:mp_special_controls="clr-namespace:MediaPortal.UI.SkinEngine.SpecialElements.Controls;assembly=SkinEngine"
    >
  <Include.Resources>
    <Model x:Key="MenuModel" Id="9E9D0CD9-4FDB-4c0f-A0C4-F356E151BDE0"/>
    
    <!-- Defines the default margins for the content area -->
    <ResourceWrapper x:Key="DefaultContentMargin" Resource="0,210,-4,-35" />
    
    <!-- Header has to be defined by the includer: "Header_Text" -->

    <!-- Client_Template -->
    <ControlTemplate x:Key="Client_Template">
      <Grid x:Name="MainPanel" Margin="0,-73,-5,-87" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Image Canvas.Left="0" Canvas.Top="300" Width="1920" Height="740" Stretch="Fill" Source="panel_thumbs_noinfo.png" Margin="-45,0,-33,0">
            <Image.IsVisible>
              <Binding Source="{StaticResource ViewModeModel}" Path="LayoutType"
                       Converter="{StaticResource ExpressionValueConverter}" ConverterParameter="{}{0} != {LayoutType}.{CoverLayout}"/>
            </Image.IsVisible>
        </Image>

        <Image Canvas.Left="0" Canvas.Top="300" Width="1920" Height="740" Stretch="Fill" Source="panel_thumbs_coverflow.png" Margin="-45,0,-33,0">
            <Image.IsVisible>
              <Binding Source="{StaticResource ViewModeModel}" Path="LayoutType"
                       Converter="{StaticResource ExpressionValueConverter}" ConverterParameter="{}{0} = {LayoutType}.{CoverLayout}"/>
            </Image.IsVisible>
        </Image>
       
        <!-- Order matters here: The content grid has to be the last control to fill the rest of the space -->
        <Grid x:Name="ContentPanel" SetFocusPrio="DefaultHigh">
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>
          <Control x:Name="ContentViewer" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,60,0,0"
                   Template="{DynamicResource ResourceKey=Contents_Template}" SetFocus="true"/>
        </Grid>

        <Grid x:Name="LeftPanel" Margin="-550,-130,10,5" VerticalAlignment="Stretch"
              Width="550" HorizontalAlignment="Left">
          <Grid.IsVisible>
            <Binding Source="{StaticResource ViewModeModel}" Path="LayoutType"
                     Converter="{StaticResource ExpressionValueConverter}" ConverterParameter="{}{0} != {LayoutType}.{CoverLayout}"/>
          </Grid.IsVisible>
          <Grid.Resources>
            <Storyboard x:Key="SlideInStoryboard" FillBehavior="HoldEnd">
              <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" FillBehavior="HoldEnd" Storyboard.TargetName="LeftPanel" Storyboard.TargetProperty="RenderTransform.X">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.20" Value="550"/>
              </DoubleAnimationUsingKeyFrames>
            </Storyboard>
          </Grid.Resources>
          <Grid.Triggers>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
              <Trigger.EnterActions>
                <TriggerCommand Command="{Command Source={StaticResource MenuModel}, Path=OpenMenu}"/>
              </Trigger.EnterActions>
              <Trigger.ExitActions>
                <TriggerCommand Command="{Command Source={StaticResource MenuModel}, Path=CloseMenu}"/>
              </Trigger.ExitActions>
            </Trigger>
            <!-- Setting default state of menu to hidden -->
            <EventTrigger RoutedEvent="Screen.Show">
              <TriggerCommand Command="{Command Source={StaticResource MenuModel}, Path=CloseMenu}"/>
            </EventTrigger>
            <!-- Slide-In animation when the MenuModel.ShowMenu gets true -->
            <DataTrigger Binding="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}" Value="True">
              <DataTrigger.EnterActions>
                <BeginStoryboard x:Name="SlideIn_BeginStoryboard" Storyboard="{ThemeResource SlideInStoryboard}"/>
              </DataTrigger.EnterActions>
              <DataTrigger.ExitActions>
                <StopStoryboard BeginStoryboardName="SlideIn_BeginStoryboard"/>
              </DataTrigger.ExitActions>
              <Setter TargetName="MainMenu" Property="SetFocusPrio" Value="Highest" />
              <Setter TargetName="MainMenu" Property="SetFocus" Value="True" />
            </DataTrigger>
          </Grid.Triggers>          
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="550"/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>
          <Grid.RenderTransform>
            <TranslateTransform X="0"/>
          </Grid.RenderTransform>
          <Image Source="menu_fade.png" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="-65,-168,-50,-50">
          </Image>
          <!--Image Source="menu_bg.png" Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,10,-60,10">   
          </Image-->
          <Rectangle RadiusX="{ThemeResource DialogBorderCornerRadius}" RadiusY="{ThemeResource DialogBorderCornerRadius}"
                     HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,67,0">
            <Rectangle.Fill>
              <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="{ThemeResource DialogBackgroundGradient1Color}"/>
                <GradientStop Color="{ThemeResource DialogBackgroundGradient2Color}" Offset="1"/>
              </LinearGradientBrush>
            </Rectangle.Fill>
          </Rectangle>       
          <ListView x:Name="MainMenu" Style="{ThemeResource HiddenMenuListViewStyle}" Margin="20,10,80,10"
              HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SetFocusPrio="Default"
              ItemsSource="{Binding Source={StaticResource MenuModel},Path=MenuItems,Mode=OneTime}"
              IsEnabled="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}">
            <ListView.Resources>
              <CommandBridge x:Key="Menu_Command" Command="{Binding Path=Command,Mode=OneTime}"/>
            </ListView.Resources>
          </ListView>
          <Button x:Name="MenuShowButton" Content="Menu" Style="{ThemeResource ButtonWideStyle_GrowOnly}"
                  Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Height="180" Margin="20,0,0,0"
                  IsEnabled="{Binding Source={StaticResource MenuModel},Path=!IsMenuOpen}"
                  Command="{Command Source={StaticResource MenuModel}, Path=ToggleMenu}">
            <Image Source="hiddenmenu_tab.png" Stretch="Uniform" Margin="0,0,0,0"/>
          </Button>
        </Grid>

        <Grid x:Name="TopPanel" Margin="0,-1100,10,5" VerticalAlignment="Top"
              Width="550" HorizontalAlignment="Center">
          <Grid.IsVisible>
            <Binding Source="{StaticResource ViewModeModel}" Path="LayoutType"
                     Converter="{StaticResource ExpressionValueConverter}" ConverterParameter="{}{0} == {LayoutType}.{CoverLayout}"/>
          </Grid.IsVisible>
          <Grid.Resources>
            <Storyboard x:Key="SlideDownStoryboard" FillBehavior="HoldEnd">
              <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" FillBehavior="HoldEnd" Storyboard.TargetName="TopPanel" Storyboard.TargetProperty="RenderTransform.Y">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.20" Value="850"/>
              </DoubleAnimationUsingKeyFrames>
            </Storyboard>
          </Grid.Resources>
          <Grid.Triggers>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
              <Trigger.EnterActions>
                <TriggerCommand Command="{Command Source={StaticResource MenuModel}, Path=OpenMenu}"/>
              </Trigger.EnterActions>
              <Trigger.ExitActions>
                <TriggerCommand Command="{Command Source={StaticResource MenuModel}, Path=CloseMenu}"/>
              </Trigger.ExitActions>
            </Trigger>
            <!-- Setting default state of menu to hidden -->
            <EventTrigger RoutedEvent="Screen.Show">
              <TriggerCommand Command="{Command Source={StaticResource MenuModel}, Path=CloseMenu}"/>
            </EventTrigger>
            <!-- Slide-In animation when the MenuModel.ShowMenu gets true -->
            <DataTrigger Binding="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}" Value="True">
              <DataTrigger.EnterActions>
                <BeginStoryboard x:Name="SlideDown_BeginStoryboard" Storyboard="{ThemeResource SlideDownStoryboard}"/>
              </DataTrigger.EnterActions>
              <DataTrigger.ExitActions>
                <StopStoryboard BeginStoryboardName="SlideDown_BeginStoryboard"/>
              </DataTrigger.ExitActions>
              <Setter TargetName="TopMenu" Property="SetFocusPrio" Value="Highest" />
              <Setter TargetName="TopMenu" Property="SetFocus" Value="True" />
            </DataTrigger>
          </Grid.Triggers>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="550"/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition Height="800"/>
          </Grid.RowDefinitions>
          <Grid.RenderTransform>
            <TranslateTransform Y="0"/>
          </Grid.RenderTransform>
          <!--Image Source="menu_fade.png" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="-65,-168,-50,-50">
          </Image-->
          <Rectangle RadiusX="{ThemeResource DialogBorderCornerRadius}" RadiusY="{ThemeResource DialogBorderCornerRadius}"
                     HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,67,0">
            <Rectangle.Fill>
              <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="{ThemeResource DialogBackgroundGradient1Color}"/>
                <GradientStop Color="{ThemeResource DialogBackgroundGradient2Color}" Offset="1"/>
              </LinearGradientBrush>
            </Rectangle.Fill>
          </Rectangle>
          <ListView x:Name="TopMenu" Style="{ThemeResource HiddenMenuListViewStyle}" Margin="20,10,80,10"
              HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SetFocusPrio="Default"
              ItemsSource="{Binding Source={StaticResource MenuModel},Path=MenuItems,Mode=OneTime}"
              IsEnabled="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}">
            <ListView.Resources>
              <CommandBridge x:Key="Menu_Command" Command="{Binding Path=Command,Mode=OneTime}"/>
            </ListView.Resources>
          </ListView>
          <Button x:Name="MenuShowTopButton" Content="Menu" Style="{ThemeResource ButtonWideStyle_GrowOnly}"
                  Grid.Row="0" Grid.Column="0" VerticalAlignment="Bottom" Height="60" Margin="0,0,0,0"
                  IsEnabled="{Binding Source={StaticResource MenuModel},Path=!IsMenuOpen}"
                  Command="{Command Source={StaticResource MenuModel}, Path=ToggleMenu}">
            <Image Source="hiddenmenu_tab_up.png" Stretch="Uniform" Margin="-40,57,0,-57"/>
          </Button>
        </Grid>
        
        <KeyBinding Key="Info" Command="{Command Source={StaticResource MenuModel}, Path=ToggleMenu}"/>
        <KeyBinding Key="Escape" Command="{Command Source={StaticResource MenuModel}, Path=ToggleMenu}" IsEnabled="{Binding Source={StaticResource MenuModel},Path=IsMenuOpen}"/>
      </Grid>
    </ControlTemplate>
  </Include.Resources>
</Include>
