Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:58:15

0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 //    you must not claim that you wrote the original software.
0015 //    If you use this software in a product, an acknowledgment
0016 //    in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 //    and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024 
0025 #ifndef SFML_MOUSE_HPP
0026 #define SFML_MOUSE_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Window/Export.hpp>
0032 #include <SFML/System/Vector2.hpp>
0033 
0034 
0035 namespace sf
0036 {
0037 class WindowBase;
0038 
0039 ////////////////////////////////////////////////////////////
0040 /// \brief Give access to the real-time state of the mouse
0041 ///
0042 ////////////////////////////////////////////////////////////
0043 class SFML_WINDOW_API Mouse
0044 {
0045 public:
0046 
0047     ////////////////////////////////////////////////////////////
0048     /// \brief Mouse buttons
0049     ///
0050     ////////////////////////////////////////////////////////////
0051     enum Button
0052     {
0053         Left,       //!< The left mouse button
0054         Right,      //!< The right mouse button
0055         Middle,     //!< The middle (wheel) mouse button
0056         XButton1,   //!< The first extra mouse button
0057         XButton2,   //!< The second extra mouse button
0058 
0059         ButtonCount //!< Keep last -- the total number of mouse buttons
0060     };
0061 
0062     ////////////////////////////////////////////////////////////
0063     /// \brief Mouse wheels
0064     ///
0065     ////////////////////////////////////////////////////////////
0066     enum Wheel
0067     {
0068         VerticalWheel,  //!< The vertical mouse wheel
0069         HorizontalWheel //!< The horizontal mouse wheel
0070     };
0071 
0072     ////////////////////////////////////////////////////////////
0073     /// \brief Check if a mouse button is pressed
0074     ///
0075     /// \warning Checking the state of buttons Mouse::XButton1 and
0076     /// Mouse::XButton2 is not supported on Linux with X11.
0077     ///
0078     /// \param button Button to check
0079     ///
0080     /// \return True if the button is pressed, false otherwise
0081     ///
0082     ////////////////////////////////////////////////////////////
0083     static bool isButtonPressed(Button button);
0084 
0085     ////////////////////////////////////////////////////////////
0086     /// \brief Get the current position of the mouse in desktop coordinates
0087     ///
0088     /// This function returns the global position of the mouse
0089     /// cursor on the desktop.
0090     ///
0091     /// \return Current position of the mouse
0092     ///
0093     ////////////////////////////////////////////////////////////
0094     static Vector2i getPosition();
0095 
0096     ////////////////////////////////////////////////////////////
0097     /// \brief Get the current position of the mouse in window coordinates
0098     ///
0099     /// This function returns the current position of the mouse
0100     /// cursor, relative to the given window.
0101     ///
0102     /// \param relativeTo Reference window
0103     ///
0104     /// \return Current position of the mouse
0105     ///
0106     ////////////////////////////////////////////////////////////
0107     static Vector2i getPosition(const WindowBase& relativeTo);
0108 
0109     ////////////////////////////////////////////////////////////
0110     /// \brief Set the current position of the mouse in desktop coordinates
0111     ///
0112     /// This function sets the global position of the mouse
0113     /// cursor on the desktop.
0114     ///
0115     /// \param position New position of the mouse
0116     ///
0117     ////////////////////////////////////////////////////////////
0118     static void setPosition(const Vector2i& position);
0119 
0120     ////////////////////////////////////////////////////////////
0121     /// \brief Set the current position of the mouse in window coordinates
0122     ///
0123     /// This function sets the current position of the mouse
0124     /// cursor, relative to the given window.
0125     ///
0126     /// \param position New position of the mouse
0127     /// \param relativeTo Reference window
0128     ///
0129     ////////////////////////////////////////////////////////////
0130     static void setPosition(const Vector2i& position, const WindowBase& relativeTo);
0131 };
0132 
0133 } // namespace sf
0134 
0135 
0136 #endif // SFML_MOUSE_HPP
0137 
0138 
0139 ////////////////////////////////////////////////////////////
0140 /// \class sf::Mouse
0141 /// \ingroup window
0142 ///
0143 /// sf::Mouse provides an interface to the state of the
0144 /// mouse. It only contains static functions (a single
0145 /// mouse is assumed), so it's not meant to be instantiated.
0146 ///
0147 /// This class allows users to query the mouse state at any
0148 /// time and directly, without having to deal with a window and
0149 /// its events. Compared to the MouseMoved, MouseButtonPressed
0150 /// and MouseButtonReleased events, sf::Mouse can retrieve the
0151 /// state of the cursor and the buttons at any time
0152 /// (you don't need to store and update a boolean on your side
0153 /// in order to know if a button is pressed or released), and you
0154 /// always get the real state of the mouse, even if it is
0155 /// moved, pressed or released when your window is out of focus
0156 /// and no event is triggered.
0157 ///
0158 /// The setPosition and getPosition functions can be used to change
0159 /// or retrieve the current position of the mouse pointer. There are
0160 /// two versions: one that operates in global coordinates (relative
0161 /// to the desktop) and one that operates in window coordinates
0162 /// (relative to a specific window).
0163 ///
0164 /// Usage example:
0165 /// \code
0166 /// if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
0167 /// {
0168 ///     // left click...
0169 /// }
0170 ///
0171 /// // get global mouse position
0172 /// sf::Vector2i position = sf::Mouse::getPosition();
0173 ///
0174 /// // set mouse position relative to a window
0175 /// sf::Mouse::setPosition(sf::Vector2i(100, 200), window);
0176 /// \endcode
0177 ///
0178 /// \see sf::Joystick, sf::Keyboard, sf::Touch
0179 ///
0180 ////////////////////////////////////////////////////////////