Ocean
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_MOUSE_H
9 #define META_OCEAN_PLATFORM_MOUSE_H
10 
12 
13 #include "ocean/math/Vector2.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Platform
19 {
20 
21 /**
22  * This class implements mouse functionalities.
23  * Not available on the following platforms: Android, IOS.
24  * @ingroup platform
25  */
26 class OCEAN_PLATFORM_EXPORT Mouse
27 {
28  public:
29 
30  /**
31  * Definition of individual mouse buttons.
32  */
33  enum Button
34  {
35  /// No key.
37  /// The left mouse button.
38  BUTTON_LEFT = (1 << 0),
39  /// The middle mouse button.
40  BUTTON_MIDDLE = (1 << 1),
41  /// The right mouse button.
42  BUTTON_RIGHT = (1 << 2),
43  /// Last key value.
44  BUTTON_LAST_UNIQUE_VALUE = (1 << 2)
45  };
46 
47  public:
48 
49  /**
50  * Returns whether all specified buttons of the mouse are currently pushed (down) or not.
51  * @param buttons The buttons for that the states are requested (may be a combination of several buttons)
52  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
53  * @return True, if so; also True if no button is provided
54  */
55  static bool allButtonsDown(const Button buttons, const bool synchron = true);
56 
57  /**
58  * Returns whether at least one button of the specified buttons of the mouse is currently pushed (down) or not.
59  * @param buttons The buttons for that the states are requested (may be a combination of several buttons)
60  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
61  * @return True, if so; also True if no button is provided
62  */
63  static bool oneButtonDown(const Button buttons, const bool synchron = true);
64 
65  /**
66  * Returns whether exactly one (specified button) is currently pushed (down) or not.
67  * @param button One unique button for that the state is requested, must not be a combination of several buttons
68  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
69  * @return True, if so
70  */
71  static bool isButtonDown(const Button button, const bool synchron = true);
72 
73  /**
74  * Returns the current mouse button state for the left, middle and right mouse button.
75  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
76  * @return Current mouse button state
77  */
78  static Button currentMouseButtonState(const bool synchron = true);
79 
80  /**
81  * Returns the current position of the mouse/cursor in screen coordinates.
82  * @param invalidPosition The invalid mouse/cursor position if currently no mouse/cursor position exists or can be determined.
83  * @return Mouse screen coordinates
84  */
86 
87  protected:
88 
89 #ifdef _WINDOWS
90 
91  /**
92  * Returns whether exactly one (specified button) is currently pushed (down) or not (specialization for Windows).
93  * @sa isButtonDown()
94  * @param button One unique button for that the state is requested, must not be a combination of several buttons
95  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
96  * @return True, if so
97  */
98  static bool isButtonDownWindows(const Button button, const bool synchron = true);
99 
100  /**
101  * Returns whether exactly one (specified key) is currently pushed (down) or not.
102  * @param nVirtualKey The virtual key code for that the state is requested
103  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
104  * @return True, if so
105  */
106  static bool keyStateWindows(const int nVirtualKey, const bool synchron);
107 
108  /**
109  * Returns the current position of the mouse/cursor in screen coordinates (specialization for Windows).
110  * @sa screenPosition()
111  * @param invalidPosition The invalid mouse/cursor position if currently no mouse/cursor position exists or can be determined.
112  * @return Mouse screen coordinates
113  */
115 
116 #elif defined(__APPLE__)
117 
118  /**
119  * Returns whether exactly one (specified button) is currently pushed (down) or not (specialization for Apple platforms).
120  * @sa isButtonDown()
121  * @param button One unique button for that the state is requested, must not be a combination of several buttons
122  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
123  * @return True, if so
124  */
125  static bool isButtonDownApple(const Button button, const bool synchron = true);
126 
127  /**
128  * Returns the current position of the mouse/cursor in screen coordinates (specialization for Apple platforms).
129  * @sa screenPosition()
130  * @param invalidPosition The invalid mouse/cursor position if currently no mouse/cursor position exists or can be determined.
131  * @return Mouse screen coordinates
132  */
134 
135 #endif // defined(_WINDOWS)
136 };
137 
138 }
139 
140 }
141 
142 #endif // META_OCEAN_PLATFORM_MOUSE_H
This class provides basic numeric functionalities.
Definition: Numeric.h:57
This class implements mouse functionalities.
Definition: Mouse.h:27
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) ...
static bool isButtonDown(const Button button, const bool synchron=true)
Returns whether exactly one (specified button) is currently pushed (down) or not.
static bool isButtonDownApple(const Button button, const bool synchron=true)
Returns whether exactly one (specified button) is currently pushed (down) or not (specialization for ...
static VectorI2 screenPosition(const VectorI2 &invalidPosition=VectorI2(NumericT< int >::minValue(), NumericT< int >::minValue()))
Returns the current position of the mouse/cursor in screen coordinates.
static VectorI2 screenPositionApple(const VectorI2 &invalidPosition=VectorI2(NumericT< int >::minValue(), NumericT< int >::minValue()))
Returns the current position of the mouse/cursor in screen coordinates (specialization for Apple plat...
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 keyStateWindows(const int nVirtualKey, const bool synchron)
Returns whether exactly one (specified key) is currently pushed (down) or not.
static bool isButtonDownWindows(const Button button, const bool synchron=true)
Returns whether exactly one (specified button) is currently pushed (down) or not (specialization for ...
static VectorI2 screenPositionWindows(const VectorI2 &invalidPosition=VectorI2(NumericT< int >::minValue(), NumericT< int >::minValue()))
Returns the current position of the mouse/cursor in screen coordinates (specialization for Windows).
Button
Definition of individual mouse buttons.
Definition: Mouse.h:34
static Button currentMouseButtonState(const bool synchron=true)
Returns the current mouse button state for the left, middle and right mouse button.
VectorT2< int > VectorI2
Definition of a 2D vector with integer values.
Definition: Vector2.h:49
@ BUTTON_MIDDLE
Middle button.
Definition: SceneDescription.h:82
@ BUTTON_NONE
Definition: SceneDescription.h:78
@ BUTTON_RIGHT
Right button.
Definition: SceneDescription.h:84
@ BUTTON_LEFT
Left button.
Definition: SceneDescription.h:80
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15