diff --git a/Siv3D/include/Siv3D/Cursor.hpp b/Siv3D/include/Siv3D/Cursor.hpp index a10f447d2..6e372d106 100644 --- a/Siv3D/include/Siv3D/Cursor.hpp +++ b/Siv3D/include/Siv3D/Cursor.hpp @@ -139,6 +139,15 @@ namespace s3d /// @return 適用されているカメラ座標変換 [[nodiscard]] const Mat3x2& GetCameraTransform() noexcept; + + /// @brief マウスカーソルのキャプチャ状態を設定します。 + /// @param captured キャプチャ状態にする場合 true, 解除する場合は false + void SetCapture(bool captured) noexcept; + + /// @brief マウスカーソルのキャプチャ状態を返します。 + /// @return マウスカーソルがキャプチャされている場合 true, それ以外の場合は false + [[nodiscard]] + bool IsCaptured() noexcept; } } diff --git a/Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.cpp b/Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.cpp index 2d5b1f5b5..a4e484fd2 100644 --- a/Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.cpp +++ b/Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.cpp @@ -287,4 +287,14 @@ namespace s3d m_requestedCursor = it->second.get(); } } + + void CCursor::setCapture(const bool captured) noexcept + { + m_captured = captured; + } + + bool CCursor::isCaptured() const noexcept + { + return m_captured; + } } diff --git a/Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.hpp b/Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.hpp index 0ecc16d5b..96cc3c260 100644 --- a/Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.hpp +++ b/Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.hpp @@ -22,31 +22,6 @@ namespace s3d { class CCursor final : public ISiv3DCursor { - private: - - GLFWwindow* m_window = nullptr; - - CursorState m_state; - - Mat3x2 m_transformLocal = Mat3x2::Identity(); - Mat3x2 m_transformCamera = Mat3x2::Identity(); - Mat3x2 m_transformScreen = Mat3x2::Identity(); - Mat3x2 m_transformAll = Mat3x2::Identity(); - Mat3x2 m_transformAllInv = Mat3x2::Identity(); - - bool m_clipToWindow = false; - - static void CursorDeleter(GLFWcursor* h) - { - ::glfwDestroyCursor(h); - } - - std::array m_systemCursors; - GLFWcursor* m_currentCursor = nullptr; - GLFWcursor* m_defaultCursor = nullptr; - GLFWcursor* m_requestedCursor = nullptr; - HashTable> m_customCursors; - public: CCursor(); @@ -84,5 +59,36 @@ namespace s3d bool registerCursor(StringView name, const Image& image, Point hotSpot) override; void requestStyle(StringView name) override; + + void setCapture(bool captured) noexcept override; + + bool isCaptured() const noexcept override; + + private: + + GLFWwindow* m_window = nullptr; + + CursorState m_state; + + Mat3x2 m_transformLocal = Mat3x2::Identity(); + Mat3x2 m_transformCamera = Mat3x2::Identity(); + Mat3x2 m_transformScreen = Mat3x2::Identity(); + Mat3x2 m_transformAll = Mat3x2::Identity(); + Mat3x2 m_transformAllInv = Mat3x2::Identity(); + + bool m_clipToWindow = false; + + static void CursorDeleter(GLFWcursor* h) + { + ::glfwDestroyCursor(h); + } + + std::array m_systemCursors; + GLFWcursor* m_currentCursor = nullptr; + GLFWcursor* m_defaultCursor = nullptr; + GLFWcursor* m_requestedCursor = nullptr; + HashTable> m_customCursors; + + bool m_captured = false; }; } diff --git a/Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.cpp b/Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.cpp index cb53d8a00..90ae202b2 100644 --- a/Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.cpp +++ b/Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.cpp @@ -299,4 +299,14 @@ namespace s3d // m_requestedCursor = it->second.get(); } } + + void CCursor::setCapture(const bool captured) noexcept + { + m_captured = captured; + } + + bool CCursor::isCaptured() const noexcept + { + return m_captured; + } } diff --git a/Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.hpp b/Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.hpp index 34b34bb89..1960b15fc 100644 --- a/Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.hpp +++ b/Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.hpp @@ -22,31 +22,6 @@ namespace s3d { class CCursor final : public ISiv3DCursor { - private: - - GLFWwindow* m_window = nullptr; - - CursorState m_state; - - Mat3x2 m_transformLocal = Mat3x2::Identity(); - Mat3x2 m_transformCamera = Mat3x2::Identity(); - Mat3x2 m_transformScreen = Mat3x2::Identity(); - Mat3x2 m_transformAll = Mat3x2::Identity(); - Mat3x2 m_transformAllInv = Mat3x2::Identity(); - - bool m_clipToWindow = false; - - static void CursorDeleter(GLFWcursor* h) - { - ::glfwDestroyCursor(h); - } - - std::array m_systemCursors; - String m_currentCursor; - String m_defaultCursor; - String m_requestedCursor; - HashTable> m_customCursors; - public: CCursor(); @@ -84,5 +59,36 @@ namespace s3d bool registerCursor(StringView name, const Image& image, Point hotSpot) override; void requestStyle(StringView name) override; + + void setCapture(bool captured) noexcept override; + + bool isCaptured() const noexcept override; + + private: + + GLFWwindow* m_window = nullptr; + + CursorState m_state; + + Mat3x2 m_transformLocal = Mat3x2::Identity(); + Mat3x2 m_transformCamera = Mat3x2::Identity(); + Mat3x2 m_transformScreen = Mat3x2::Identity(); + Mat3x2 m_transformAll = Mat3x2::Identity(); + Mat3x2 m_transformAllInv = Mat3x2::Identity(); + + bool m_clipToWindow = false; + + static void CursorDeleter(GLFWcursor* h) + { + ::glfwDestroyCursor(h); + } + + std::array m_systemCursors; + String m_currentCursor; + String m_defaultCursor; + String m_requestedCursor; + HashTable> m_customCursors; + + bool m_captured = false; }; } diff --git a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.cpp b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.cpp index 6f9346c27..03a70fa89 100644 --- a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.cpp +++ b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.cpp @@ -401,6 +401,16 @@ namespace s3d } } + void CCursor::setCapture(const bool captured) noexcept + { + m_captured = captured; + } + + bool CCursor::isCaptured() const noexcept + { + return m_captured; + } + void CCursor::handleMessage(const UINT message, const WPARAM, const LPARAM lParam) { Point newPosRaw; diff --git a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.hpp b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.hpp index 10cffed74..8ace1d8bc 100644 --- a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.hpp +++ b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.hpp @@ -24,36 +24,6 @@ namespace s3d { class CCursor final : public ISiv3DCursor { - private: - - HWND m_hWnd = nullptr; - - std::mutex m_clientPosBufferMutex; - Array> m_clientPosBuffer; - - CursorState m_state; - - Mat3x2 m_transformLocal = Mat3x2::Identity(); - Mat3x2 m_transformCamera = Mat3x2::Identity(); - Mat3x2 m_transformScreen = Mat3x2::Identity(); - Mat3x2 m_transformAll = Mat3x2::Identity(); - Mat3x2 m_transformAllInv = Mat3x2::Identity(); - - bool m_clippedToWindow = false; - - static void CursorDeleter(HICON h) - { - ::DestroyIcon(h); - } - - std::array m_systemCursors; - HICON m_currentCursor = nullptr; - HICON m_defaultCursor = nullptr; - HICON m_requestedCursor = nullptr; - HashTable> m_customCursors; - - void confineCursor(); - public: CCursor(); @@ -92,6 +62,10 @@ namespace s3d void requestStyle(StringView name) override; + void setCapture(bool captured) noexcept override; + + bool isCaptured() const noexcept override; + //////////////////////////////////////////////////////////////// // // Windows @@ -99,6 +73,38 @@ namespace s3d void handleMessage(UINT message, WPARAM wParam, LPARAM lParam); void onSetCursor(); + + private: + + HWND m_hWnd = nullptr; + + std::mutex m_clientPosBufferMutex; + Array> m_clientPosBuffer; + + CursorState m_state; + + Mat3x2 m_transformLocal = Mat3x2::Identity(); + Mat3x2 m_transformCamera = Mat3x2::Identity(); + Mat3x2 m_transformScreen = Mat3x2::Identity(); + Mat3x2 m_transformAll = Mat3x2::Identity(); + Mat3x2 m_transformAllInv = Mat3x2::Identity(); + + bool m_clippedToWindow = false; + + static void CursorDeleter(HICON h) + { + ::DestroyIcon(h); + } + + std::array m_systemCursors; + HICON m_currentCursor = nullptr; + HICON m_defaultCursor = nullptr; + HICON m_requestedCursor = nullptr; + HashTable> m_customCursors; + + bool m_captured = false; + + void confineCursor(); }; } diff --git a/Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.hpp b/Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.hpp index 83b75fc58..be7e49d82 100644 --- a/Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.hpp +++ b/Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.hpp @@ -22,31 +22,6 @@ namespace s3d { class CCursor final : public ISiv3DCursor { - private: - - GLFWwindow* m_window = nullptr; - - CursorState m_state; - - Mat3x2 m_transformLocal = Mat3x2::Identity(); - Mat3x2 m_transformCamera = Mat3x2::Identity(); - Mat3x2 m_transformScreen = Mat3x2::Identity(); - Mat3x2 m_transformAll = Mat3x2::Identity(); - Mat3x2 m_transformAllInv = Mat3x2::Identity(); - - bool m_clipToWindow = false; - - static void CursorDeleter(GLFWcursor* h) - { - ::glfwDestroyCursor(h); - } - - std::array m_systemCursors; - GLFWcursor* m_currentCursor; - GLFWcursor* m_defaultCursor; - GLFWcursor* m_requestedCursor; - HashTable> m_customCursors; - public: void* m_event = nullptr; @@ -86,5 +61,36 @@ namespace s3d bool registerCursor(StringView name, const Image& image, Point hotSpot) override; void requestStyle(StringView name) override; + + void setCapture(bool captured) noexcept override; + + bool isCaptured() const noexcept override; + + private: + + GLFWwindow* m_window = nullptr; + + CursorState m_state; + + Mat3x2 m_transformLocal = Mat3x2::Identity(); + Mat3x2 m_transformCamera = Mat3x2::Identity(); + Mat3x2 m_transformScreen = Mat3x2::Identity(); + Mat3x2 m_transformAll = Mat3x2::Identity(); + Mat3x2 m_transformAllInv = Mat3x2::Identity(); + + bool m_clipToWindow = false; + + static void CursorDeleter(GLFWcursor* h) + { + ::glfwDestroyCursor(h); + } + + std::array m_systemCursors; + GLFWcursor* m_currentCursor = nullptr; + GLFWcursor* m_defaultCursor = nullptr; + GLFWcursor* m_requestedCursor = nullptr; + HashTable> m_customCursors; + + bool m_captured = false; }; } diff --git a/Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.mm b/Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.mm index 775b27e38..ac3a98c95 100644 --- a/Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.mm +++ b/Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.mm @@ -293,4 +293,14 @@ static Vec2 GetClientCursorPos(GLFWwindow* window) m_requestedCursor = it->second.get(); } } + + void CCursor::setCapture(const bool captured) noexcept + { + m_captured = captured; + } + + bool CCursor::isCaptured() const noexcept + { + return m_captured; + } } diff --git a/Siv3D/src/Siv3D/Cursor/CCursor_Null.cpp b/Siv3D/src/Siv3D/Cursor/CCursor_Null.cpp index 19588eb53..84bea6511 100644 --- a/Siv3D/src/Siv3D/Cursor/CCursor_Null.cpp +++ b/Siv3D/src/Siv3D/Cursor/CCursor_Null.cpp @@ -104,4 +104,14 @@ namespace s3d { } + + void CCursor_Null::setCapture(const bool) noexcept + { + + } + + bool CCursor_Null::isCaptured() const noexcept + { + return false; + } } diff --git a/Siv3D/src/Siv3D/Cursor/CCursor_Null.hpp b/Siv3D/src/Siv3D/Cursor/CCursor_Null.hpp index f590ba33a..e9da7feef 100644 --- a/Siv3D/src/Siv3D/Cursor/CCursor_Null.hpp +++ b/Siv3D/src/Siv3D/Cursor/CCursor_Null.hpp @@ -63,5 +63,9 @@ namespace s3d bool registerCursor(StringView name, const Image& image, Point hotSpot) override; void requestStyle(StringView name) override; + + void setCapture(bool captured) noexcept override; + + bool isCaptured() const noexcept override; }; } diff --git a/Siv3D/src/Siv3D/Cursor/ICursor.hpp b/Siv3D/src/Siv3D/Cursor/ICursor.hpp index d023349c9..ffd42762c 100644 --- a/Siv3D/src/Siv3D/Cursor/ICursor.hpp +++ b/Siv3D/src/Siv3D/Cursor/ICursor.hpp @@ -59,5 +59,9 @@ namespace s3d virtual bool registerCursor(StringView name, const Image& image, Point hotSpot) = 0; virtual void requestStyle(StringView name) = 0; + + virtual void setCapture(bool captured) noexcept = 0; + + virtual bool isCaptured() const noexcept = 0; }; } diff --git a/Siv3D/src/Siv3D/Cursor/SivCursor.cpp b/Siv3D/src/Siv3D/Cursor/SivCursor.cpp index 81e9e34f2..76eaf85df 100644 --- a/Siv3D/src/Siv3D/Cursor/SivCursor.cpp +++ b/Siv3D/src/Siv3D/Cursor/SivCursor.cpp @@ -135,6 +135,16 @@ namespace s3d return SIV3D_ENGINE(Cursor)->getCameraTransform(); } + void SetCapture(const bool captured) noexcept + { + SIV3D_ENGINE(Cursor)->setCapture(captured); + } + + bool IsCaptured() noexcept + { + return SIV3D_ENGINE(Cursor)->isCaptured(); + } + namespace Internal { void SetLocalTransform(const Mat3x2& matrix)