-
Notifications
You must be signed in to change notification settings - Fork 463
Expand file tree
/
Copy pathMouse.h
More file actions
194 lines (157 loc) · 5.65 KB
/
Copy pathMouse.h
File metadata and controls
194 lines (157 loc) · 5.65 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//--------------------------------------------------------------------------------------
// File: Mouse.h
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//
// https://go.microsoft.com/fwlink/?LinkId=248929
// https://go.microsoft.com/fwlink/?LinkID=615561
//--------------------------------------------------------------------------------------
#pragma once
#if !defined(USING_XINPUT) && !defined(USING_GAMEINPUT) && !defined(USING_COREWINDOW)
#ifdef _GAMING_DESKTOP
#include <grdk.h>
#endif
#if (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES)) || (defined(_GAMING_DESKTOP) && (_GRDK_EDITION >= 220600))
#define USING_GAMEINPUT
#elif (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)) || (defined(_XBOX_ONE) && defined(_TITLE))
#define USING_COREWINDOW
#endif
#endif // !USING_XINPUT && !USING_GAMEINPUT && !USING_WINDOWS_GAMING_INPUT
#ifdef USING_GAMEINPUT
#include <GameInput.h>
#if defined(_MSC_VER) && (defined(_GAMING_XBOX) || defined(GAMEINPUT_API_VERSION))
#pragma comment(lib,"gameinput.lib")
#endif
#endif
#include <cstdint>
#include <memory>
#ifdef USING_COREWINDOW
namespace ABI { namespace Windows { namespace UI { namespace Core { struct ICoreWindow; } } } }
#endif
#ifndef DIRECTX_TOOLKIT_API
#ifdef DIRECTX_TOOLKIT_EXPORT
#ifdef __GNUC__
#define DIRECTX_TOOLKIT_API __attribute__ ((dllexport))
#else
#define DIRECTX_TOOLKIT_API __declspec(dllexport)
#endif
#elif defined(DIRECTX_TOOLKIT_IMPORT)
#ifdef __GNUC__
#define DIRECTX_TOOLKIT_API __attribute__ ((dllimport))
#else
#define DIRECTX_TOOLKIT_API __declspec(dllimport)
#endif
#else
#define DIRECTX_TOOLKIT_API
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#endif
namespace DirectX
{
class Mouse
{
public:
DIRECTX_TOOLKIT_API Mouse() noexcept(false);
DIRECTX_TOOLKIT_API Mouse(Mouse&&) noexcept;
DIRECTX_TOOLKIT_API Mouse& operator= (Mouse&&) noexcept;
Mouse(Mouse const&) = delete;
Mouse& operator=(Mouse const&) = delete;
DIRECTX_TOOLKIT_API virtual ~Mouse();
enum Mode : uint32_t
{
MODE_ABSOLUTE = 0,
MODE_RELATIVE,
};
struct State
{
bool leftButton;
bool middleButton;
bool rightButton;
bool xButton1;
bool xButton2;
int x;
int y;
int scrollWheelValue;
Mode positionMode;
};
class DIRECTX_TOOLKIT_API ButtonStateTracker
{
public:
enum ButtonState : uint32_t
{
UP = 0, // Button is up
HELD = 1, // Button is held down
RELEASED = 2, // Button was just released
PRESSED = 3, // Buton was just pressed
};
ButtonState leftButton;
ButtonState middleButton;
ButtonState rightButton;
ButtonState xButton1;
ButtonState xButton2;
#ifdef _PREFAST_
#pragma prefast(push)
#pragma prefast(disable : 26495, "Reset() performs the initialization")
#endif
ButtonStateTracker() noexcept { Reset(); }
#ifdef _PREFAST_
#pragma prefast(pop)
#endif
void __cdecl Update(const State& state) noexcept;
void __cdecl Reset() noexcept;
State __cdecl GetLastState() const noexcept { return lastState; }
private:
State lastState;
};
// Retrieve the current state of the mouse
DIRECTX_TOOLKIT_API State __cdecl GetState() const;
// Resets the accumulated scroll wheel value
DIRECTX_TOOLKIT_API void __cdecl ResetScrollWheelValue() noexcept;
// Sets mouse mode (defaults to absolute)
DIRECTX_TOOLKIT_API void __cdecl SetMode(Mode mode);
// Signals the end of frame (recommended, but optional)
DIRECTX_TOOLKIT_API void __cdecl EndOfInputFrame() noexcept;
// Feature detection
DIRECTX_TOOLKIT_API bool __cdecl IsConnected() const;
// Cursor visibility
DIRECTX_TOOLKIT_API bool __cdecl IsVisible() const noexcept;
DIRECTX_TOOLKIT_API void __cdecl SetVisible(bool visible);
#ifdef USING_COREWINDOW
DIRECTX_TOOLKIT_API void __cdecl SetWindow(ABI::Windows::UI::Core::ICoreWindow* window);
#ifdef __cplusplus_winrt
inline void __cdecl SetWindow(Windows::UI::Core::CoreWindow^ window)
{
// See https://msdn.microsoft.com/en-us/library/hh755802.aspx
SetWindow(reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow*>(window));
}
#endif
#ifdef CPPWINRT_VERSION
inline void __cdecl SetWindow(winrt::Windows::UI::Core::CoreWindow window)
{
// See https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/interop-winrt-abi
SetWindow(reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow*>(winrt::get_abi(window)));
}
#endif
DIRECTX_TOOLKIT_API static void __cdecl SetDpi(float dpi);
#elif defined(WM_USER)
DIRECTX_TOOLKIT_API void __cdecl SetWindow(HWND window);
DIRECTX_TOOLKIT_API static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam);
#ifdef _GAMING_XBOX
DIRECTX_TOOLKIT_API static void __cdecl SetResolution(float scale);
#endif
#endif
// Singleton
DIRECTX_TOOLKIT_API static Mouse& __cdecl Get();
private:
// Private implementation.
class Impl;
std::unique_ptr<Impl> pImpl;
};
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif