|
|
|||
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_CURSOR_HPP 0026 #define SFML_CURSOR_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Window/Export.hpp> 0032 #include <SFML/System/NonCopyable.hpp> 0033 #include <SFML/System/Vector2.hpp> 0034 0035 namespace sf 0036 { 0037 namespace priv 0038 { 0039 class CursorImpl; 0040 } 0041 0042 //////////////////////////////////////////////////////////// 0043 /// \brief Cursor defines the appearance of a system cursor 0044 /// 0045 //////////////////////////////////////////////////////////// 0046 class SFML_WINDOW_API Cursor : NonCopyable 0047 { 0048 public: 0049 0050 //////////////////////////////////////////////////////////// 0051 /// \brief Enumeration of the native system cursor types 0052 /// 0053 /// Refer to the following table to determine which cursor 0054 /// is available on which platform. 0055 /// 0056 /// Type | Linux | Mac OS X | Windows | 0057 /// ------------------------------------|:-----:|:--------:|:--------:| 0058 /// sf::Cursor::Arrow | yes | yes | yes | 0059 /// sf::Cursor::ArrowWait | no | no | yes | 0060 /// sf::Cursor::Wait | yes | no | yes | 0061 /// sf::Cursor::Text | yes | yes | yes | 0062 /// sf::Cursor::Hand | yes | yes | yes | 0063 /// sf::Cursor::SizeHorizontal | yes | yes | yes | 0064 /// sf::Cursor::SizeVertical | yes | yes | yes | 0065 /// sf::Cursor::SizeTopLeftBottomRight | no | yes* | yes | 0066 /// sf::Cursor::SizeBottomLeftTopRight | no | yes* | yes | 0067 /// sf::Cursor::SizeLeft | yes | yes** | yes** | 0068 /// sf::Cursor::SizeRight | yes | yes** | yes** | 0069 /// sf::Cursor::SizeTop | yes | yes** | yes** | 0070 /// sf::Cursor::SizeBottom | yes | yes** | yes** | 0071 /// sf::Cursor::SizeTopLeft | yes | yes** | yes** | 0072 /// sf::Cursor::SizeTopRight | yes | yes** | yes** | 0073 /// sf::Cursor::SizeBottomLeft | yes | yes** | yes** | 0074 /// sf::Cursor::SizeBottomRight | yes | yes** | yes** | 0075 /// sf::Cursor::SizeAll | yes | no | yes | 0076 /// sf::Cursor::Cross | yes | yes | yes | 0077 /// sf::Cursor::Help | yes | yes* | yes | 0078 /// sf::Cursor::NotAllowed | yes | yes | yes | 0079 /// 0080 /// * These cursor types are undocumented so may not 0081 /// be available on all versions, but have been tested on 10.13 0082 /// 0083 /// ** On Windows and macOS, double-headed arrows are used 0084 /// 0085 //////////////////////////////////////////////////////////// 0086 enum Type 0087 { 0088 Arrow, //!< Arrow cursor (default) 0089 ArrowWait, //!< Busy arrow cursor 0090 Wait, //!< Busy cursor 0091 Text, //!< I-beam, cursor when hovering over a field allowing text entry 0092 Hand, //!< Pointing hand cursor 0093 SizeHorizontal, //!< Horizontal double arrow cursor 0094 SizeVertical, //!< Vertical double arrow cursor 0095 SizeTopLeftBottomRight, //!< Double arrow cursor going from top-left to bottom-right 0096 SizeBottomLeftTopRight, //!< Double arrow cursor going from bottom-left to top-right 0097 SizeLeft, //!< Left arrow cursor on Linux, same as SizeHorizontal on other platforms 0098 SizeRight, //!< Right arrow cursor on Linux, same as SizeHorizontal on other platforms 0099 SizeTop, //!< Up arrow cursor on Linux, same as SizeVertical on other platforms 0100 SizeBottom, //!< Down arrow cursor on Linux, same as SizeVertical on other platforms 0101 SizeTopLeft, //!< Top-left arrow cursor on Linux, same as SizeTopLeftBottomRight on other platforms 0102 SizeBottomRight, //!< Bottom-right arrow cursor on Linux, same as SizeTopLeftBottomRight on other platforms 0103 SizeBottomLeft, //!< Bottom-left arrow cursor on Linux, same as SizeBottomLeftTopRight on other platforms 0104 SizeTopRight, //!< Top-right arrow cursor on Linux, same as SizeBottomLeftTopRight on other platforms 0105 SizeAll, //!< Combination of SizeHorizontal and SizeVertical 0106 Cross, //!< Crosshair cursor 0107 Help, //!< Help cursor 0108 NotAllowed //!< Action not allowed cursor 0109 }; 0110 0111 public: 0112 0113 //////////////////////////////////////////////////////////// 0114 /// \brief Default constructor 0115 /// 0116 /// This constructor doesn't actually create the cursor; 0117 /// initially the new instance is invalid and must not be 0118 /// used until either loadFromPixels() or loadFromSystem() 0119 /// is called and successfully created a cursor. 0120 /// 0121 //////////////////////////////////////////////////////////// 0122 Cursor(); 0123 0124 //////////////////////////////////////////////////////////// 0125 /// \brief Destructor 0126 /// 0127 /// This destructor releases the system resources 0128 /// associated with this cursor, if any. 0129 /// 0130 //////////////////////////////////////////////////////////// 0131 ~Cursor(); 0132 0133 //////////////////////////////////////////////////////////// 0134 /// \brief Create a cursor with the provided image 0135 /// 0136 /// \a pixels must be an array of \a width by \a height pixels 0137 /// in 32-bit RGBA format. If not, this will cause undefined behavior. 0138 /// 0139 /// If \a pixels is null or either \a width or \a height are 0, 0140 /// the current cursor is left unchanged and the function will 0141 /// return false. 0142 /// 0143 /// In addition to specifying the pixel data, you can also 0144 /// specify the location of the hotspot of the cursor. The 0145 /// hotspot is the pixel coordinate within the cursor image 0146 /// which will be located exactly where the mouse pointer 0147 /// position is. Any mouse actions that are performed will 0148 /// return the window/screen location of the hotspot. 0149 /// 0150 /// \warning On Unix platforms which do not support colored 0151 /// cursors, the pixels are mapped into a monochrome 0152 /// bitmap: pixels with an alpha channel to 0 are 0153 /// transparent, black if the RGB channel are close 0154 /// to zero, and white otherwise. 0155 /// 0156 /// \param pixels Array of pixels of the image 0157 /// \param size Width and height of the image 0158 /// \param hotspot (x,y) location of the hotspot 0159 /// \return true if the cursor was successfully loaded; 0160 /// false otherwise 0161 /// 0162 //////////////////////////////////////////////////////////// 0163 bool loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot); 0164 0165 //////////////////////////////////////////////////////////// 0166 /// \brief Create a native system cursor 0167 /// 0168 /// Refer to the list of cursor available on each system 0169 /// (see sf::Cursor::Type) to know whether a given cursor is 0170 /// expected to load successfully or is not supported by 0171 /// the operating system. 0172 /// 0173 /// \param type Native system cursor type 0174 /// \return true if and only if the corresponding cursor is 0175 /// natively supported by the operating system; 0176 /// false otherwise 0177 /// 0178 //////////////////////////////////////////////////////////// 0179 bool loadFromSystem(Type type); 0180 0181 private: 0182 0183 friend class WindowBase; 0184 0185 //////////////////////////////////////////////////////////// 0186 /// \brief Get access to the underlying implementation 0187 /// 0188 /// This is primarily designed for sf::Window::setMouseCursor, 0189 /// hence the friendship. 0190 /// 0191 /// \return a reference to the OS-specific implementation 0192 /// 0193 //////////////////////////////////////////////////////////// 0194 const priv::CursorImpl& getImpl() const; 0195 0196 private: 0197 0198 //////////////////////////////////////////////////////////// 0199 // Member data 0200 //////////////////////////////////////////////////////////// 0201 priv::CursorImpl* m_impl; //!< Platform-specific implementation of the cursor 0202 }; 0203 0204 } // namespace sf 0205 0206 0207 #endif // SFML_CURSOR_HPP 0208 0209 0210 //////////////////////////////////////////////////////////// 0211 /// \class sf::Cursor 0212 /// \ingroup window 0213 /// 0214 /// \warning Features related to Cursor are not supported on 0215 /// iOS and Android. 0216 /// 0217 /// This class abstracts the operating system resources 0218 /// associated with either a native system cursor or a custom 0219 /// cursor. 0220 /// 0221 /// After loading the cursor the graphical appearance 0222 /// with either loadFromPixels() or loadFromSystem(), the 0223 /// cursor can be changed with sf::Window::setMouseCursor(). 0224 /// 0225 /// The behaviour is undefined if the cursor is destroyed while 0226 /// in use by the window. 0227 /// 0228 /// Usage example: 0229 /// \code 0230 /// sf::Window window; 0231 /// 0232 /// // ... create window as usual ... 0233 /// 0234 /// sf::Cursor cursor; 0235 /// if (cursor.loadFromSystem(sf::Cursor::Hand)) 0236 /// window.setMouseCursor(cursor); 0237 /// \endcode 0238 /// 0239 /// \see sf::Window::setMouseCursor 0240 /// 0241 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|