Ocean
win/Mouse.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_WIN_MOUSE_H
9 #define META_OCEAN_PLATFORM_WIN_MOUSE_H
10 
11 #include "ocean/platform/win/Win.h"
12 
13 #include "ocean/math/Vector2.h"
14 
15 #include "ocean/platform/Mouse.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Platform
21 {
22 
23 namespace Win
24 {
25 
26 /**
27  * This class implements mouse functionalities.
28  * @ingroup platformwin
29  */
30 class OCEAN_PLATFORM_WIN_EXPORT Mouse : Platform::Mouse
31 {
32  public:
33 
34  /**
35  * Returns whether all specified buttons of the mouse are currently pushed (down) or not.
36  * @param buttons The buttons for that the states are requested (may be a combination of several buttons)
37  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
38  * @return True, if so; also True if no button is provided
39  */
40  static bool allButtonsDown(const Button buttons, const bool synchron = true);
41 
42  /**
43  * Returns whether at least one button of the specified buttons of the mouse is currently pushed (down) or not.
44  * @param buttons The buttons for that the states are requested (may be a combination of several buttons)
45  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
46  * @return True, if so; also True if no button is provided
47  */
48  static bool oneButtonDown(const Button buttons, const bool synchron = true);
49 
50  /**
51  * Returns wheater exactly one (specified button) is currently pushed (down) or not.
52  * @param button One unique button for that the state is requested, must not be a combination of several buttons
53  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
54  * @return True, if so
55  */
56  static bool isButtonDown(const Button button, const bool synchron = true);
57 
58  /**
59  * Returns the current mouse button state for the left, middle and right mouse button.
60  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
61  * @return Current mouse button state
62  */
63  static Button currentMouseButtonState(const bool synchron = true);
64 
65  /**
66  * Returns the current position of the mouse (cursor) in screen coordinates.
67  * @return Mouse screen coordinates
68  */
70 
71  protected:
72 
73  /**
74  * Returns wheater exactly one (specified mouse button) is currently pushed (down) or not.
75  * @param nVirtualKey The virtual key code for that the state is requested
76  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
77  * @return True, if so
78  */
79  static inline bool keyState(const int nVirtualKey, const bool synchron);
80 };
81 
82 inline bool Mouse::keyState(const int nVirtualKey, const bool synchron)
83 {
84  if (synchron)
85  {
86  // MSDN: If the high-order bit is 1, the key is down; otherwise, it is up
87  return (GetKeyState(nVirtualKey) & 0xF0) != 0;
88  }
89  else
90  {
91  return GetAsyncKeyState(nVirtualKey) != 0;
92  }
93 }
94 
95 }
96 
97 }
98 
99 }
100 
101 #endif // META_OCEAN_PLATFORM_WIN_MOUSE_H
This class implements mouse functionalities.
Definition: Mouse.h:27
Button
Definition of individual mouse buttons.
Definition: Mouse.h:34
This class implements mouse functionalities.
Definition: win/Mouse.h:31
static VectorI2 screenPosition()
Returns the current position of the mouse (cursor) in screen coordinates.
static bool keyState(const int nVirtualKey, const bool synchron)
Returns wheater exactly one (specified mouse button) is currently pushed (down) or not.
Definition: win/Mouse.h:82
static bool allButtonsDown(const Button buttons, const bool synchron=true)
Returns whether all specified buttons of the mouse are currently pushed (down) or not.
static bool isButtonDown(const Button button, const bool synchron=true)
Returns wheater exactly one (specified button) is currently pushed (down) or not.
static Button currentMouseButtonState(const bool synchron=true)
Returns the current mouse button state for the left, middle and right mouse button.
static bool oneButtonDown(const Button buttons, const bool synchron=true)
Returns whether at least one button of the specified buttons of the mouse is currently pushed (down) ...
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15