Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b13fa20

Browse files
committedMar 16, 2015
lab10
1 parent 768c7d5 commit b13fa20

File tree

6 files changed

+215
-12
lines changed

6 files changed

+215
-12
lines changed
 

Diff for: ‎Kinect2Sample/App.xaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:local="using:Kinect2Sample">
6-
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<!--
10+
Styles that define look and feel of Kinect controls
11+
-->
12+
<ResourceDictionary Source="KinectRegionStyles.xaml"/>
13+
</ResourceDictionary.MergedDictionaries>
14+
</ResourceDictionary>
15+
</Application.Resources>
716
</Application>

Diff for: ‎Kinect2Sample/App.xaml.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Windows.UI.Xaml.Input;
1515
using Windows.UI.Xaml.Media;
1616
using Windows.UI.Xaml.Navigation;
17+
using Microsoft.Kinect.Xaml.Controls;
1718

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

@@ -24,6 +25,11 @@ namespace Kinect2Sample
2425
/// </summary>
2526
sealed partial class App : Application
2627
{
28+
/// <summary>
29+
/// Gets the app level KinectRegion element, which is created in App.xaml.cs
30+
/// </summary>
31+
public KinectRegion KinectRegion { get; private set; }
32+
2733
/// <summary>
2834
/// Initializes the singleton application object. This is the first line of authored code
2935
/// executed, and as such is the logical equivalent of main() or WinMain().
@@ -67,8 +73,13 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
6773
//TODO: Load state from previously suspended application
6874
}
6975

70-
// Place the frame in the current Window
71-
Window.Current.Content = rootFrame;
76+
// Create a CursorLayer that listens to KinectPointerPoints/GestureRecognizers
77+
// and works with the affected controls.
78+
KinectRegion = new KinectRegion();
79+
KinectRegion.Content = rootFrame;
80+
81+
// Place the frame in the current Window, with a Kinect cursor layer + user viewer control
82+
Window.Current.Content = KinectRegion;
7283
}
7384

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

96+
8597
/// <summary>
8698
/// Invoked when Navigation to a certain page fails
8799
/// </summary>

Diff for: ‎Kinect2Sample/Kinect2Sample.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
<Generator>MSBuild:Compile</Generator>
7373
<SubType>Designer</SubType>
7474
</ApplicationDefinition>
75+
<Page Include="KinectRegionStyles.xaml">
76+
<Generator>MSBuild:Compile</Generator>
77+
<SubType>Designer</SubType>
78+
</Page>
7579
<Page Include="MainPage.xaml">
7680
<Generator>MSBuild:Compile</Generator>
7781
<SubType>Designer</SubType>
@@ -81,6 +85,12 @@
8185
<SDKReference Include="Microsoft.Kinect.Face, Version=2.0">
8286
<Name>Microsoft.Kinect.Face</Name>
8387
</SDKReference>
88+
<SDKReference Include="Microsoft.Kinect.Toolkit.Input, Version=2.0">
89+
<Name>Microsoft.Kinect.Toolkit.Input</Name>
90+
</SDKReference>
91+
<SDKReference Include="Microsoft.Kinect.Xaml.Controls, Version=2.0">
92+
<Name>Microsoft.Kinect.Xaml.Controls</Name>
93+
</SDKReference>
8494
<SDKReference Include="Microsoft.VCLibs, version=12.0">
8595
<Name>Microsoft Visual C++ 2013 Runtime Package for Windows</Name>
8696
</SDKReference>

Diff for: ‎Kinect2Sample/KinectRegionStyles.xaml

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
2+
<ResourceDictionary
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:k="using:Microsoft.Kinect.Xaml.Controls">
6+
7+
<ExponentialEase x:Key="VisualStateEasingFunction" Exponent="7" />
8+
9+
<Style TargetType="k:KinectRegion">
10+
<Setter Property="Template">
11+
<Setter.Value>
12+
<ControlTemplate TargetType="k:KinectRegion">
13+
<Border
14+
Background="{TemplateBinding Background}"
15+
BorderBrush="{TemplateBinding BorderBrush}"
16+
BorderThickness="{TemplateBinding BorderThickness}"
17+
>
18+
<Grid>
19+
<ContentPresenter x:Name="contentHolder" />
20+
21+
<!-- only change from default KinectRegion style,
22+
is the addition of a user viewer under cursor layer,
23+
but above content -->
24+
<k:KinectUserViewer Height="100" Width="121"
25+
HorizontalAlignment="Center"
26+
VerticalAlignment="Top" />
27+
28+
<Canvas x:Name="cursorRenderingLayer" Background="{x:Null}"/>
29+
</Grid>
30+
</Border>
31+
</ControlTemplate>
32+
</Setter.Value>
33+
</Setter>
34+
</Style>
35+
36+
<!--
37+
BackButtons have a small visible area.
38+
The changes in this style (change margin to padding, set kinectpressinset,
39+
add border to template to support padding) enable a larger hit test region
40+
for HandPointers
41+
-->
42+
<Style x:Key="KinectBackButtonStyle" TargetType="Button">
43+
<Setter Property="MinWidth" Value="48"/>
44+
<Setter Property="MinHeight" Value="48"/>
45+
<Setter Property="Padding" Value="36,56,36,36" />
46+
<Setter Property="k:KinectRegion.KinectPressInset" Value="36,56,36,36" />
47+
<Setter Property="VerticalAlignment" Value="Top"/>
48+
<Setter Property="FontFamily" Value="Segoe UI Symbol"/>
49+
<Setter Property="FontWeight" Value="Normal"/>
50+
<Setter Property="FontSize" Value="56"/>
51+
<Setter Property="AutomationProperties.AutomationId" Value="BackButton"/>
52+
<Setter Property="AutomationProperties.Name" Value="Back"/>
53+
<Setter Property="AutomationProperties.ItemType" Value="Navigation Button"/>
54+
<Setter Property="Template">
55+
<Setter.Value>
56+
<ControlTemplate TargetType="Button">
57+
<Grid x:Name="RootGrid">
58+
<Border Padding="{TemplateBinding Padding}" Background="Transparent">
59+
<Grid Margin="-1,-16,0,0">
60+
<TextBlock x:Name="BackgroundGlyph" Text="&#xE0A8;" Foreground="{StaticResource BackButtonBackgroundThemeBrush}"/>
61+
<TextBlock x:Name="NormalGlyph" Text="&#xE071;" Foreground="{StaticResource BackButtonForegroundThemeBrush}"/>
62+
<TextBlock x:Name="ArrowGlyph" Text="&#xE0A6;" Foreground="{StaticResource BackButtonPressedForegroundThemeBrush}" Opacity="0"/>
63+
</Grid>
64+
</Border>
65+
<Rectangle
66+
x:Name="FocusVisualWhite"
67+
IsHitTestVisible="False"
68+
Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
69+
StrokeEndLineCap="Square"
70+
StrokeDashArray="1,1"
71+
Opacity="0"
72+
StrokeDashOffset="1.5"/>
73+
<Rectangle
74+
x:Name="FocusVisualBlack"
75+
IsHitTestVisible="False"
76+
Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
77+
StrokeEndLineCap="Square"
78+
StrokeDashArray="1,1"
79+
Opacity="0"
80+
StrokeDashOffset="0.5"/>
81+
82+
<VisualStateManager.VisualStateGroups>
83+
<VisualStateGroup x:Name="CommonStates">
84+
<VisualState x:Name="Normal" />
85+
<VisualState x:Name="PointerOver">
86+
<Storyboard>
87+
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
88+
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackButtonPointerOverBackgroundThemeBrush}"/>
89+
</ObjectAnimationUsingKeyFrames>
90+
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NormalGlyph" Storyboard.TargetProperty="Foreground">
91+
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackButtonPointerOverForegroundThemeBrush}"/>
92+
</ObjectAnimationUsingKeyFrames>
93+
</Storyboard>
94+
</VisualState>
95+
<VisualState x:Name="Pressed">
96+
<Storyboard>
97+
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
98+
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BackButtonForegroundThemeBrush}"/>
99+
</ObjectAnimationUsingKeyFrames>
100+
<DoubleAnimation
101+
Storyboard.TargetName="ArrowGlyph"
102+
Storyboard.TargetProperty="Opacity"
103+
To="1"
104+
Duration="0"/>
105+
<DoubleAnimation
106+
Storyboard.TargetName="NormalGlyph"
107+
Storyboard.TargetProperty="Opacity"
108+
To="0"
109+
Duration="0"/>
110+
</Storyboard>
111+
</VisualState>
112+
<VisualState x:Name="Disabled">
113+
<Storyboard>
114+
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Visibility">
115+
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
116+
</ObjectAnimationUsingKeyFrames>
117+
</Storyboard>
118+
</VisualState>
119+
</VisualStateGroup>
120+
<VisualStateGroup x:Name="FocusStates">
121+
<VisualState x:Name="Focused">
122+
<Storyboard>
123+
<DoubleAnimation
124+
Storyboard.TargetName="FocusVisualWhite"
125+
Storyboard.TargetProperty="Opacity"
126+
To="1"
127+
Duration="0"/>
128+
<DoubleAnimation
129+
Storyboard.TargetName="FocusVisualBlack"
130+
Storyboard.TargetProperty="Opacity"
131+
To="1"
132+
Duration="0"/>
133+
</Storyboard>
134+
</VisualState>
135+
<VisualState x:Name="Unfocused" />
136+
<VisualState x:Name="PointerFocused" />
137+
</VisualStateGroup>
138+
</VisualStateManager.VisualStateGroups>
139+
</Grid>
140+
</ControlTemplate>
141+
</Setter.Value>
142+
</Setter>
143+
</Style>
144+
145+
</ResourceDictionary>

Diff for: ‎Kinect2Sample/MainPage.xaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</Page.Resources>
3030

3131
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
32-
<Grid Margin="30">
32+
<Grid x:Name="RootGrid" Margin="30">
3333
<Grid.RowDefinitions>
3434
<RowDefinition Height="70"/>
3535
<RowDefinition Height="*"/>
@@ -104,6 +104,12 @@
104104
</Button>
105105
</StackPanel>
106106
</ScrollViewer>
107+
<Button x:Name="FullScreenBackButton" Style="{StaticResource KinectBackButtonStyle}"
108+
Grid.Row="1"
109+
HorizontalAlignment="Left"
110+
VerticalAlignment="Top"
111+
Click="FullScreenBackButton_Click"
112+
Visibility="Collapsed"/>
107113
</Grid>
108114
</Grid>
109115
</Page>

Diff for: ‎Kinect2Sample/MainPage.xaml.cs

+29-8
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,12 @@ public MainPage()
227227

228228
this.InitializeComponent();
229229

230-
// new
231230
this.Loaded += MainPage_Loaded;
232231
}
233232

234233
void MainPage_Loaded(object sender, RoutedEventArgs e)
235234
{
236-
SetupCurrentDisplay(DEFAULT_DISPLAYFRAMETYPE);
235+
SetupCurrentDisplay(DEFAULT_DISPLAYFRAMETYPE, false);
237236

238237
SetupCatAssets();
239238
}
@@ -288,8 +287,25 @@ private void SetupCatAssets()
288287
}
289288
}
290289

291-
private void SetupCurrentDisplay(DisplayFrameType newDisplayFrameType)
290+
private void SetupCurrentDisplay(DisplayFrameType newDisplayFrameType, bool isFullScreen = true)
292291
{
292+
if (isFullScreen)
293+
{
294+
RootGrid.RowDefinitions.Clear();
295+
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0)});
296+
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
297+
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(0) });
298+
FullScreenBackButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
299+
}
300+
else
301+
{
302+
RootGrid.RowDefinitions.Clear();
303+
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(70) });
304+
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
305+
RootGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(100) });
306+
FullScreenBackButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
307+
}
308+
293309
CurrentDisplayFrameType = newDisplayFrameType;
294310
// Frames used by more than one type are declared outside the switch
295311
FrameDescription colorFrameDescription = null;
@@ -990,15 +1006,20 @@ private void InfraredFaceButton_Click(object sender, RoutedEventArgs e)
9901006
SetupCurrentDisplay(DisplayFrameType.FaceOnInfrared);
9911007
}
9921008

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

999-
private void FaceGameButton_Click(object sender, RoutedEventArgs e)
1014+
private void FullScreenBackButton_Click(object sender, RoutedEventArgs e)
10001015
{
1001-
SetupCurrentDisplay(DisplayFrameType.FaceGame);
1016+
SetupCurrentDisplay(CurrentDisplayFrameType, false);
1017+
}
1018+
1019+
[Guid("905a0fef-bc53-11df-8c49-001e4fc686da"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
1020+
interface IBufferByteAccess
1021+
{
1022+
unsafe void Buffer(out byte* pByte);
10021023
}
10031024
}
10041025
}

0 commit comments

Comments
 (0)
Please sign in to comment.