MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mouse.h
1 // © Copyright 2010 - 2014 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 StopWatchTimer;
50  namespace Graphics
51  {
52  class Viewport;
53  class GameWindow;
54  }
55  namespace Input
56  {
57  ///////////////////////////////////////////////////////////////////////////////
58  /// @class Mouse
59  /// @headerfile mouse.h
60  /// @brief This class represents the mouse input device.
61  /// @details
62  ///////////////////////////////////////
63  class MEZZ_LIB Mouse : public ButtonDevice
64  {
65  protected:
66  Graphics::Viewport* CurrentViewport;
67  StopWatchTimer* MulticlickTimer;
68  Input::DirectionalMotionState VerticalWheelState;
69  Input::DirectionalMotionState HorizontalWheelState;
70  Vector2 Position;
71  Vector2 Delta;
72  MetaCode MulticlickCode;
73  /// @copydoc Device::UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes)
74  void UpdateImpl(const MetaCodeContainer& DeltaCodes, MetaCodeContainer& GeneratedCodes);
75  /// @copydoc Device::VerifySequenceImpl(const MetaCodeContainer& Sequence)
76  void VerifySequenceImpl(const MetaCodeContainer& Sequence) const;
77  /// @copydoc Device::AddPressedButtons(MetaCodeContainer& GeneratedCodes) const
78  void AddPressedButtons(MetaCodeContainer& GeneratedCodes) const;
79  /// @internal
80  /// @brief Checks to see if this code pertains to a button we can track multiple clicks for.
81  bool IsMultiClickable(const Input::InputCode Code) const;
82  /// @internal
83  /// @brief Converts a standard mouse button code to the appropriate multiclick code for that button.
84  Input::InputCode ConvertToMultiClickCode(const Input::InputCode Code) const;
85  public:
86  /// @brief Class constructor.
87  Mouse();
88  /// @brief Class destructor.
89  virtual ~Mouse();
90 
91  ///////////////////////////////////////////////////////////////////////////////
92  // Query Methods
93 
94  /// @brief Gets a pointer to the current viewport the mouse cursor is hovered over.
95  /// @return Returns a pointer to the hovered viewport.
96  Graphics::Viewport* GetHoveredViewport() const;
97  /// @brief Gets a pointer to the window with the current mouse focus.
98  /// @return Returns a pointer to the window with the current focus.
99  Graphics::GameWindow* GetHoveredWindow() const;
100 
101  /// @brief Gets the position of the mouse cursor relative to the origin of the window with the mouse focus.
102  /// @return Returns a const reference to the mouse's current position on the window.
103  const Vector2& GetWindowPosition() const;
104  /// @brief Gets the X position of the mouse relative to the window.
105  /// @return Returns a real with the current window position on the X axis.
106  Real GetWindowX() const;
107  /// @brief Gets the Y position of the mouse relative to the window.
108  /// @return Returns a real with the current window position on the Y axis.
109  Real GetWindowY() const;
110  /// @brief Gets the position of the mouse cursor relative to the origin of the viewport in the window with the mouse focus.
111  /// @return Returns a vector2 to the mouse's current position on the current viewport.
112  Vector2 GetViewportPosition() const;
113  /// @brief Gets the X position of the mouse relative to the viewport.
114  /// @return Returns a real with the current viewport position on the X axis.
115  Real GetViewportX() const;
116  /// @brief Gets the Y position of the mouse relative to the viewport.
117  /// @return Returns a real with the current viewport position on the Y axis.
118  Real GetViewportY() const;
119  /// @brief Gets the change in the mouse position from the previous update.
120  /// @return Returns a const reference to the change in the mouse position.
121  const Vector2& GetMouseDelta() const;
122  /// @brief Gets the X delta of the mouse position from the last update.
123  /// @return Returns a real with the offset from the previous update on the X axis.
124  Real GetDeltaX() const;
125  /// @brief Gets the Y delta of the mouse position from the last update.
126  /// @return Returns a real with the offset from the previous update on the Y axis.
127  Real GetDeltaY() const;
128 
129  /// @copydoc Device::GetDeviceIndex() const
130  UInt16 GetDeviceIndex() const;
131  /// @copydoc Device::GetButtonState(const UInt16 Button) const
132  const Input::ButtonState& GetButtonState(const UInt16 Button) const;
133  /// @copydoc Device::GetButtonState(const Input::InputCode& Button) const
134  const Input::ButtonState& GetButtonState(const Input::InputCode& Button) const;
135  /// @brief Gets the current state of the vertical mouse wheel.
136  /// @remarks If a mouse doesn't have a mouse wheel this will always report "DIRECTIONALMOTION_UNCHANGED".
137  /// @return Returns a directional motion update of the mouse wheel.
138  const Input::DirectionalMotionState& GetVerticalWheelState() const;
139  /// @brief Gets the current state of the horizontal mouse wheel.
140  /// @remarks If a mouse doesn't have a mouse wheel this will always report "DIRECTIONALMOTION_UNCHANGED".
141  /// @return Returns a directional motion update of the mouse wheel.
142  const Input::DirectionalMotionState& GetHorizontalWheelState() const;
143 
144  ///////////////////////////////////////////////////////////////////////////////
145  // Configuration Methods
146 
147  /// @brief Sets the visibility of the mouse cursor.
148  /// @param Visible Whether or not the cursor is to be visible.
149  void SetCursorVisibility(bool Visible);
150  /// @brief Gets the current state of the visibility of the cursor.
151  /// @return Returns true if the cursor is visible, false otherwise.
152  bool GetCursorVisibility();
153  /// @brief Sets whether or not relative mode is enabled.
154  /// @return Returns false if relative mode is not supported on this system. True if the operation was a success.
155  /// @remarks "Relative mode" entails hiding the cursor, locking the position, and only updating the mouse delta position each update.
156  /// This is useful for First Person Shooter style games.
157  /// @param Enable True to enable relative mode, false to disable.
158  bool SetRelativeMode(bool Enable);
159  /// @brief Gets whether or not relative mode is enabled.
160  /// @return Returns true if relative mode is enabled, false otherwise.
161  bool GetRelativeMode();
162  /// @brief Sets the mouse cursor.
163  void SetMouseCursor();
164  /// @brief Gets the current mouse cursor.
165  void GetMouseCursor();
166 
167  ///////////////////////////////////////////////////////////////////////////////
168  // Utility Methods
169 
170  /// @brief Sets the mouse cursor's position to the specified point in the specified window.
171  /// @param Win The window to warp the cursor to.
172  /// @param Position The position on the specified window to warp the cursor to.
173  void WarpCursorToPosition(Graphics::GameWindow* Win, const Vector2& Position);
174  };//Mouse
175  }//Input
176 }//Mezzanine
177 
178 #endif