Skip to content

Commit

Permalink
lab10
Browse files Browse the repository at this point in the history
  • Loading branch information
jesse-nsquared committed Mar 16, 2015
1 parent 768c7d5 commit b13fa20
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 12 deletions.
11 changes: 10 additions & 1 deletion Kinect2Sample/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Kinect2Sample">

<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define look and feel of Kinect controls
-->
<ResourceDictionary Source="KinectRegionStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
16 changes: 14 additions & 2 deletions Kinect2Sample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.Kinect.Xaml.Controls;

// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227

Expand All @@ -24,6 +25,11 @@ namespace Kinect2Sample
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Gets the app level KinectRegion element, which is created in App.xaml.cs
/// </summary>
public KinectRegion KinectRegion { get; private set; }

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
Expand Down Expand Up @@ -67,8 +73,13 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
//TODO: Load state from previously suspended application
}

// Place the frame in the current Window
Window.Current.Content = rootFrame;
// Create a CursorLayer that listens to KinectPointerPoints/GestureRecognizers
// and works with the affected controls.
KinectRegion = new KinectRegion();
KinectRegion.Content = rootFrame;

// Place the frame in the current Window, with a Kinect cursor layer + user viewer control
Window.Current.Content = KinectRegion;
}

if (rootFrame.Content == null)
Expand All @@ -82,6 +93,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
Window.Current.Activate();
}


/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Kinect2Sample/Kinect2Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="KinectRegionStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="MainPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -81,6 +85,12 @@
<SDKReference Include="Microsoft.Kinect.Face, Version=2.0">
<Name>Microsoft.Kinect.Face</Name>
</SDKReference>
<SDKReference Include="Microsoft.Kinect.Toolkit.Input, Version=2.0">
<Name>Microsoft.Kinect.Toolkit.Input</Name>
</SDKReference>
<SDKReference Include="Microsoft.Kinect.Xaml.Controls, Version=2.0">
<Name>Microsoft.Kinect.Xaml.Controls</Name>
</SDKReference>
<SDKReference Include="Microsoft.VCLibs, version=12.0">
<Name>Microsoft Visual C++ 2013 Runtime Package for Windows</Name>
</SDKReference>
Expand Down
145 changes: 145 additions & 0 deletions Kinect2Sample/KinectRegionStyles.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:k="using:Microsoft.Kinect.Xaml.Controls">

<ExponentialEase x:Key="VisualStateEasingFunction" Exponent="7" />

<Style TargetType="k:KinectRegion">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="k:KinectRegion">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
>
<Grid>
<ContentPresenter x:Name="contentHolder" />

<!-- only change from default KinectRegion style,
is the addition of a user viewer under cursor layer,
but above content -->
<k:KinectUserViewer Height="100" Width="121"
HorizontalAlignment="Center"
VerticalAlignment="Top" />

<Canvas x:Name="cursorRenderingLayer" Background="{x:Null}"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<!--
BackButtons have a small visible area.
The changes in this style (change margin to padding, set kinectpressinset,
add border to template to support padding) enable a larger hit test region
for HandPointers
-->
<Style x:Key="KinectBackButtonStyle" TargetType="Button">
<Setter Property="MinWidth" Value="48"/>
<Setter Property="MinHeight" Value="48"/>
<Setter Property="Padding" Value="36,56,36,36" />
<Setter Property="k:KinectRegion.KinectPressInset" Value="36,56,36,36" />
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="FontFamily" Value="Segoe UI Symbol"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="56"/>
<Setter Property="AutomationProperties.AutomationId" Value="BackButton"/>
<Setter Property="AutomationProperties.Name" Value="Back"/>
<Setter Property="AutomationProperties.ItemType" Value="Navigation Button"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="RootGrid">
<Border Padding="{TemplateBinding Padding}" Background="Transparent">
<Grid Margin="-1,-16,0,0">
<TextBlock x:Name="BackgroundGlyph" Text="&#xE0A8;" Foreground="{StaticResource BackButtonBackgroundThemeBrush}"/>
<TextBlock x:Name="NormalGlyph" Text="&#xE071;" Foreground="{StaticResource BackButtonForegroundThemeBrush}"/>
<TextBlock x:Name="ArrowGlyph" Text="&#xE0A6;" Foreground="{StaticResource BackButtonPressedForegroundThemeBrush}" Opacity="0"/>
</Grid>
</Border>
<Rectangle
x:Name="FocusVisualWhite"
IsHitTestVisible="False"
Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
StrokeEndLineCap="Square"
StrokeDashArray="1,1"
Opacity="0"
StrokeDashOffset="1.5"/>
<Rectangle
x:Name="FocusVisualBlack"
IsHitTestVisible="False"
Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
StrokeEndLineCap="Square"
StrokeDashArray="1,1"
Opacity="0"
StrokeDashOffset="0.5"/>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackButtonPointerOverBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NormalGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackButtonPointerOverForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackButtonForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation
Storyboard.TargetName="ArrowGlyph"
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0"/>
<DoubleAnimation
Storyboard.TargetName="NormalGlyph"
Storyboard.TargetProperty="Opacity"
To="0"
Duration="0"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="FocusVisualWhite"
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0"/>
<DoubleAnimation
Storyboard.TargetName="FocusVisualBlack"
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused" />
<VisualState x:Name="PointerFocused" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>
8 changes: 7 additions & 1 deletion Kinect2Sample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
<Grid Margin="30">
<Grid x:Name="RootGrid" Margin="30">
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition Height="*"/>
Expand Down Expand Up @@ -104,6 +104,12 @@
</Button>
</StackPanel>
</ScrollViewer>
<Button x:Name="FullScreenBackButton" Style="{StaticResource KinectBackButtonStyle}"
Grid.Row="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="FullScreenBackButton_Click"
Visibility="Collapsed"/>
</Grid>
</Grid>
</Page>
37 changes: 29 additions & 8 deletions Kinect2Sample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,12 @@ public MainPage()

this.InitializeComponent();

// new
this.Loaded += MainPage_Loaded;
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
SetupCurrentDisplay(DEFAULT_DISPLAYFRAMETYPE);
SetupCurrentDisplay(DEFAULT_DISPLAYFRAMETYPE, false);

SetupCatAssets();
}
Expand Down Expand Up @@ -288,8 +287,25 @@ private void SetupCatAssets()
}
}

private void SetupCurrentDisplay(DisplayFrameType newDisplayFrameType)
private void SetupCurrentDisplay(DisplayFrameType newDisplayFrameType, bool isFullScreen = true)
{
if (isFullScreen)
{
RootGrid.RowDefinitions.Clear();
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0)});
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0) });
FullScreenBackButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
}
else
{
RootGrid.RowDefinitions.Clear();
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(70) });
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(100) });
FullScreenBackButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}

CurrentDisplayFrameType = newDisplayFrameType;
// Frames used by more than one type are declared outside the switch
FrameDescription colorFrameDescription = null;
Expand Down Expand Up @@ -990,15 +1006,20 @@ private void InfraredFaceButton_Click(object sender, RoutedEventArgs e)
SetupCurrentDisplay(DisplayFrameType.FaceOnInfrared);
}

[Guid("905a0fef-bc53-11df-8c49-001e4fc686da"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IBufferByteAccess
private void FaceGameButton_Click(object sender, RoutedEventArgs e)
{
unsafe void Buffer(out byte* pByte);
SetupCurrentDisplay(DisplayFrameType.FaceGame);
}

private void FaceGameButton_Click(object sender, RoutedEventArgs e)
private void FullScreenBackButton_Click(object sender, RoutedEventArgs e)
{
SetupCurrentDisplay(DisplayFrameType.FaceGame);
SetupCurrentDisplay(CurrentDisplayFrameType, false);
}

[Guid("905a0fef-bc53-11df-8c49-001e4fc686da"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IBufferByteAccess
{
unsafe void Buffer(out byte* pByte);
}
}
}

0 comments on commit b13fa20

Please sign in to comment.