Spinning Topp Logo BlackTopp Studios
inc
mouse.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _inputmouse_h
41 #define _inputmouse_h
42 
43 #include "vector2.h"
44 #include "Input/inputenumerations.h"
45 #include "Input/buttondevice.h"
46 
47 namespace Mezzanine
48 {
49  class Timer;
50  namespace Graphics
51  {
52  class Viewport;
53  class GameWindow;
54  }
55  namespace Input
56  {
57  ///////////////////////////////////////////////////////////////////////////////
58  /// @brief This class represents the mouse input device.
59  ///////////////////////////////////////
60  class MEZZ_LIB Mouse : public ButtonDevice
61  {
62  protected:
63  /// @internal
64  /// @brief A copy of the current MetaCode being tracked for multi-click detection.
66  /// @internal
67  /// @brief The current screen position of the mouse cursor.
69  /// @internal
70  /// @brief The change in the mouse cursor position since the last update.
72  /// @internal
73  /// @brief The viewport that the mouse cursor is currently in.
75  /// @internal
76  /// @brief The timer used to detect multi-clicks.
78  /// @internal
79  /// @brief The current state of the horizontal mouse wheel (if present).
81  /// @internal
82  /// @brief The current state of the vertical mouse wheel (if present).
84 
85  /// @copydoc Device::UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes)
86  void UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes);
87  /// @copydoc Device::VerifySequenceImpl(const MetaCodeContainer& Sequence)
88  void VerifySequenceImpl(const MetaCodeContainer& Sequence) const;
89  /// @copydoc Device::AddPressedButtons(MetaCodeContainer& GeneratedCodes) const
90  void AddPressedButtons(MetaCodeContainer& GeneratedCodes) const;
91  /// @internal
92  /// @brief Checks to see if this code pertains to a button we can track multiple clicks for.
93  Boole IsMultiClickable(const Input::InputCode Code) const;
94  /// @internal
95  /// @brief Converts a standard mouse button code to the appropriate multiclick code for that button.
96  Input::InputCode ConvertToMultiClickCode(const Input::InputCode Code) const;
97  public:
98  /// @brief Class constructor.
99  Mouse();
100  /// @brief Class destructor.
101  virtual ~Mouse();
102 
103  ///////////////////////////////////////////////////////////////////////////////
104  // Query Methods
105 
106  /// @brief Gets a pointer to the current viewport the mouse cursor is hovered over.
107  /// @return Returns a pointer to the hovered viewport.
108  Graphics::Viewport* GetHoveredViewport() const;
109  /// @brief Gets a pointer to the window with the current mouse focus.
110  /// @return Returns a pointer to the window with the current focus.
111  Graphics::GameWindow* GetHoveredWindow() const;
112 
113  /// @brief Gets the position of the mouse cursor relative to the origin of the window with the mouse focus.
114  /// @return Returns a const reference to the mouse's current position on the window.
115  const Vector2& GetWindowPosition() const;
116  /// @brief Gets the X position of the mouse relative to the window.
117  /// @return Returns a real with the current window position on the X axis.
118  Real GetWindowX() const;
119  /// @brief Gets the Y position of the mouse relative to the window.
120  /// @return Returns a real with the current window position on the Y axis.
121  Real GetWindowY() const;
122  /// @brief Gets the position of the mouse cursor relative to the origin of the viewport in the window with the mouse focus.
123  /// @return Returns a vector2 to the mouse's current position on the current viewport.
124  Vector2 GetViewportPosition() const;
125  /// @brief Gets the X position of the mouse relative to the viewport.
126  /// @return Returns a real with the current viewport position on the X axis.
127  Real GetViewportX() const;
128  /// @brief Gets the Y position of the mouse relative to the viewport.
129  /// @return Returns a real with the current viewport position on the Y axis.
130  Real GetViewportY() const;
131  /// @brief Gets the change in the mouse position from the previous update.
132  /// @return Returns a const reference to the change in the mouse position.
133  const Vector2& GetMouseDelta() const;
134  /// @brief Gets the X delta of the mouse position from the last update.
135  /// @return Returns a real with the offset from the previous update on the X axis.
136  Real GetDeltaX() const;
137  /// @brief Gets the Y delta of the mouse position from the last update.
138  /// @return Returns a real with the offset from the previous update on the Y axis.
139  Real GetDeltaY() const;
140 
141  /// @copydoc Device::GetDeviceIndex() const
142  UInt16 GetDeviceIndex() const;
143  /// @copydoc Device::GetButtonState(const UInt16 Button) const
144  const Input::ButtonState& GetButtonState(const UInt16 Button) const;
145  /// @copydoc Device::GetButtonState(const Input::InputCode& Button) const
146  const Input::ButtonState& GetButtonState(const Input::InputCode& Button) const;
147  /// @brief Gets the current state of the vertical mouse wheel.
148  /// @remarks If a mouse doesn't have a mouse wheel this will always report "DIRECTIONALMOTION_UNCHANGED".
149  /// @return Returns a directional motion update of the mouse wheel.
150  const Input::DirectionalMotionState& GetVerticalWheelState() const;
151  /// @brief Gets the current state of the horizontal mouse wheel.
152  /// @remarks If a mouse doesn't have a mouse wheel this will always report "DIRECTIONALMOTION_UNCHANGED".
153  /// @return Returns a directional motion update of the mouse wheel.
154  const Input::DirectionalMotionState& GetHorizontalWheelState() const;
155 
156  ///////////////////////////////////////////////////////////////////////////////
157  // Configuration Methods
158 
159  /// @brief Sets the visibility of the mouse cursor.
160  /// @param Visible Whether or not the cursor is to be visible.
161  void SetCursorVisibility(Boole Visible);
162  /// @brief Gets the current state of the visibility of the cursor.
163  /// @return Returns true if the cursor is visible, false otherwise.
164  Boole GetCursorVisibility();
165  /// @brief Sets whether or not relative mode is enabled.
166  /// @return Returns false if relative mode is not supported on this system. True if the operation was a success.
167  /// @remarks "Relative mode" entails hiding the cursor, locking the position, and only updating the mouse delta position each update.
168  /// This is useful for First Person Shooter style games.
169  /// @param Enable True to enable relative mode, false to disable.
170  Boole SetRelativeMode(Boole Enable);
171  /// @brief Gets whether or not relative mode is enabled.
172  /// @return Returns true if relative mode is enabled, false otherwise.
173  Boole GetRelativeMode();
174  /// @brief Sets the mouse cursor.
175  void SetMouseCursor();
176  /// @brief Gets the current mouse cursor.
177  void GetMouseCursor();
178 
179  ///////////////////////////////////////////////////////////////////////////////
180  // Utility Methods
181 
182  /// @brief Sets the mouse cursor's position to the specified point in the specified window.
183  /// @param Win The window to warp the cursor to.
184  /// @param Position The position on the specified window to warp the cursor to.
185  void WarpCursorToPosition(Graphics::GameWindow* Win, const Vector2& Position);
186  };//Mouse
187  }//Input
188 }//Mezzanine
189 
190 #endif
DirectionalMotionState
An Optional listing of values that can be used in a metacode Indicate spin, digital or binary travel ...
InputCode
The InputCode enum defines all the posible types of inputs.
This class represents the mouse input device.
Definition: mouse.h:60
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Vector2 Position
The current screen position of the mouse cursor.
Definition: mouse.h:68
This is a base class for all input devices with buttons.
Definition: buttondevice.h:53
Graphics::Viewport * CurrentViewport
The viewport that the mouse cursor is currently in.
Definition: mouse.h:74
MetaCode MulticlickCode
A copy of the current MetaCode being tracked for multi-click detection.
Definition: mouse.h:65
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
This class is for creating and managing viewports within a game window.
Definition: viewport.h:65
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
This Determines the kind of user input.
Definition: metacode.h:93
Input::MetaCode::MetaCodeContainer MetaCodeContainer
Convenience datatype for storage of MetaCodes.
Definition: metacode.h:351
Input::DirectionalMotionState HorizontalWheelState
The current state of the horizontal mouse wheel (if present).
Definition: mouse.h:80
A basic timer class to assist in timed operations.
Definition: timer.h:67
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
ButtonState
An Optional listing of value that can be used in a metacode to represent the information of a button ...
Timer * MulticlickTimer
The timer used to detect multi-clicks.
Definition: mouse.h:77
Input::DirectionalMotionState VerticalWheelState
The current state of the vertical mouse wheel (if present).
Definition: mouse.h:83
This class is for creating and managing game windows.
Definition: gamewindow.h:63
Vector2 Delta
The change in the mouse cursor position since the last update.
Definition: mouse.h:71