forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AggregateNavigation.h
102 lines (91 loc) · 3.15 KB
/
AggregateNavigation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//--------------------------------------------------------------------------------------
// AggregateNavigation.h
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#include <stdint.h>
//
// Class to aggregate navigation readings multiple controllers
//
class AggregateNavigation
{
public:
AggregateNavigation() : aggregation_(static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::None))
{
}
void Reset()
{
aggregation_ = static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::None);
}
void AddReading(Windows::Xbox::Input::IController^ controller)
{
if (controller == nullptr)
{
return;
}
try
{
auto iNavigation = (Windows::Xbox::Input::INavigationController^)controller;
auto iReading = iNavigation->GetNavigationReading();
if (iReading != nullptr)
{
aggregation_ |= static_cast<uint32_t>(iReading->Buttons);
}
}
catch (Platform::InvalidCastException^)
{
}
}
bool Up()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::Up)) != 0;
}
bool Down()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::Down)) != 0;
}
bool Left()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::Left)) != 0;
}
bool Right()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::Right)) != 0;
}
bool Accept()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::Accept)) != 0;
}
bool Cancel()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::Cancel)) != 0;
}
bool X()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::X)) != 0;
}
bool Y()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::Y)) != 0;
}
bool Menu()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::Menu)) != 0;
}
bool View()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::View)) != 0;
}
bool PreviousPage()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::PreviousPage)) != 0;
}
bool NextPage()
{
return (aggregation_ & static_cast<uint32_t>(Windows::Xbox::Input::NavigationButtons::NextPage)) != 0;
}
private:
uint32_t aggregation_;
};