Skip to content

Commit c21f155

Browse files
committed
[共通] Cursor::SetCapture() / Cursor::IsCaptured() #1045
1 parent 61c7c1c commit c21f155

File tree

13 files changed

+206
-105
lines changed

13 files changed

+206
-105
lines changed

Siv3D/include/Siv3D/Cursor.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ namespace s3d
139139
/// @return 適用されているカメラ座標変換
140140
[[nodiscard]]
141141
const Mat3x2& GetCameraTransform() noexcept;
142+
143+
/// @brief マウスカーソルのキャプチャ状態を設定します。
144+
/// @param captured キャプチャ状態にする場合 true, 解除する場合は false
145+
void SetCapture(bool captured) noexcept;
146+
147+
/// @brief マウスカーソルのキャプチャ状態を返します。
148+
/// @return マウスカーソルがキャプチャされている場合 true, それ以外の場合は false
149+
[[nodiscard]]
150+
bool IsCaptured() noexcept;
142151
}
143152
}
144153

Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,14 @@ namespace s3d
287287
m_requestedCursor = it->second.get();
288288
}
289289
}
290+
291+
void CCursor::setCapture(const bool captured) noexcept
292+
{
293+
m_captured = captured;
294+
}
295+
296+
bool CCursor::isCaptured() const noexcept
297+
{
298+
return m_captured;
299+
}
290300
}

Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.hpp

+31-25
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,6 @@ namespace s3d
2222
{
2323
class CCursor final : public ISiv3DCursor
2424
{
25-
private:
26-
27-
GLFWwindow* m_window = nullptr;
28-
29-
CursorState m_state;
30-
31-
Mat3x2 m_transformLocal = Mat3x2::Identity();
32-
Mat3x2 m_transformCamera = Mat3x2::Identity();
33-
Mat3x2 m_transformScreen = Mat3x2::Identity();
34-
Mat3x2 m_transformAll = Mat3x2::Identity();
35-
Mat3x2 m_transformAllInv = Mat3x2::Identity();
36-
37-
bool m_clipToWindow = false;
38-
39-
static void CursorDeleter(GLFWcursor* h)
40-
{
41-
::glfwDestroyCursor(h);
42-
}
43-
44-
std::array<GLFWcursor*, 11> m_systemCursors;
45-
GLFWcursor* m_currentCursor = nullptr;
46-
GLFWcursor* m_defaultCursor = nullptr;
47-
GLFWcursor* m_requestedCursor = nullptr;
48-
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;
49-
5025
public:
5126

5227
CCursor();
@@ -84,5 +59,36 @@ namespace s3d
8459
bool registerCursor(StringView name, const Image& image, Point hotSpot) override;
8560

8661
void requestStyle(StringView name) override;
62+
63+
void setCapture(bool captured) noexcept override;
64+
65+
bool isCaptured() const noexcept override;
66+
67+
private:
68+
69+
GLFWwindow* m_window = nullptr;
70+
71+
CursorState m_state;
72+
73+
Mat3x2 m_transformLocal = Mat3x2::Identity();
74+
Mat3x2 m_transformCamera = Mat3x2::Identity();
75+
Mat3x2 m_transformScreen = Mat3x2::Identity();
76+
Mat3x2 m_transformAll = Mat3x2::Identity();
77+
Mat3x2 m_transformAllInv = Mat3x2::Identity();
78+
79+
bool m_clipToWindow = false;
80+
81+
static void CursorDeleter(GLFWcursor* h)
82+
{
83+
::glfwDestroyCursor(h);
84+
}
85+
86+
std::array<GLFWcursor*, 11> m_systemCursors;
87+
GLFWcursor* m_currentCursor = nullptr;
88+
GLFWcursor* m_defaultCursor = nullptr;
89+
GLFWcursor* m_requestedCursor = nullptr;
90+
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;
91+
92+
bool m_captured = false;
8793
};
8894
}

Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,14 @@ namespace s3d
300300
// m_requestedCursor = it->second.get();
301301
}
302302
}
303+
304+
void CCursor::setCapture(const bool captured) noexcept
305+
{
306+
m_captured = captured;
307+
}
308+
309+
bool CCursor::isCaptured() const noexcept
310+
{
311+
return m_captured;
312+
}
303313
}

Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.hpp

+31-25
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,6 @@ namespace s3d
2222
{
2323
class CCursor final : public ISiv3DCursor
2424
{
25-
private:
26-
27-
GLFWwindow* m_window = nullptr;
28-
29-
CursorState m_state;
30-
31-
Mat3x2 m_transformLocal = Mat3x2::Identity();
32-
Mat3x2 m_transformCamera = Mat3x2::Identity();
33-
Mat3x2 m_transformScreen = Mat3x2::Identity();
34-
Mat3x2 m_transformAll = Mat3x2::Identity();
35-
Mat3x2 m_transformAllInv = Mat3x2::Identity();
36-
37-
bool m_clipToWindow = false;
38-
39-
static void CursorDeleter(GLFWcursor* h)
40-
{
41-
::glfwDestroyCursor(h);
42-
}
43-
44-
std::array<String, 11> m_systemCursors;
45-
String m_currentCursor;
46-
String m_defaultCursor;
47-
String m_requestedCursor;
48-
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;
49-
5025
public:
5126

5227
CCursor();
@@ -84,5 +59,36 @@ namespace s3d
8459
bool registerCursor(StringView name, const Image& image, Point hotSpot) override;
8560

8661
void requestStyle(StringView name) override;
62+
63+
void setCapture(bool captured) noexcept override;
64+
65+
bool isCaptured() const noexcept override;
66+
67+
private:
68+
69+
GLFWwindow* m_window = nullptr;
70+
71+
CursorState m_state;
72+
73+
Mat3x2 m_transformLocal = Mat3x2::Identity();
74+
Mat3x2 m_transformCamera = Mat3x2::Identity();
75+
Mat3x2 m_transformScreen = Mat3x2::Identity();
76+
Mat3x2 m_transformAll = Mat3x2::Identity();
77+
Mat3x2 m_transformAllInv = Mat3x2::Identity();
78+
79+
bool m_clipToWindow = false;
80+
81+
static void CursorDeleter(GLFWcursor* h)
82+
{
83+
::glfwDestroyCursor(h);
84+
}
85+
86+
std::array<String, 11> m_systemCursors;
87+
String m_currentCursor;
88+
String m_defaultCursor;
89+
String m_requestedCursor;
90+
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;
91+
92+
bool m_captured = false;
8793
};
8894
}

Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,16 @@ namespace s3d
402402
}
403403
}
404404

405+
void CCursor::setCapture(const bool captured) noexcept
406+
{
407+
m_captured = captured;
408+
}
409+
410+
bool CCursor::isCaptured() const noexcept
411+
{
412+
return m_captured;
413+
}
414+
405415
void CCursor::handleMessage(const UINT message, const WPARAM, const LPARAM lParam)
406416
{
407417
Point newPosRaw;

Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.hpp

+36-30
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,6 @@ namespace s3d
2424
{
2525
class CCursor final : public ISiv3DCursor
2626
{
27-
private:
28-
29-
HWND m_hWnd = nullptr;
30-
31-
std::mutex m_clientPosBufferMutex;
32-
Array<std::pair<uint64, Point>> m_clientPosBuffer;
33-
34-
CursorState m_state;
35-
36-
Mat3x2 m_transformLocal = Mat3x2::Identity();
37-
Mat3x2 m_transformCamera = Mat3x2::Identity();
38-
Mat3x2 m_transformScreen = Mat3x2::Identity();
39-
Mat3x2 m_transformAll = Mat3x2::Identity();
40-
Mat3x2 m_transformAllInv = Mat3x2::Identity();
41-
42-
bool m_clippedToWindow = false;
43-
44-
static void CursorDeleter(HICON h)
45-
{
46-
::DestroyIcon(h);
47-
}
48-
49-
std::array<HCURSOR, 11> m_systemCursors;
50-
HICON m_currentCursor = nullptr;
51-
HICON m_defaultCursor = nullptr;
52-
HICON m_requestedCursor = nullptr;
53-
HashTable<String, unique_resource<HICON, decltype(&CursorDeleter)>> m_customCursors;
54-
55-
void confineCursor();
56-
5727
public:
5828

5929
CCursor();
@@ -92,13 +62,49 @@ namespace s3d
9262

9363
void requestStyle(StringView name) override;
9464

65+
void setCapture(bool captured) noexcept override;
66+
67+
bool isCaptured() const noexcept override;
68+
9569
////////////////////////////////////////////////////////////////
9670
//
9771
// Windows
9872
//
9973
void handleMessage(UINT message, WPARAM wParam, LPARAM lParam);
10074

10175
void onSetCursor();
76+
77+
private:
78+
79+
HWND m_hWnd = nullptr;
80+
81+
std::mutex m_clientPosBufferMutex;
82+
Array<std::pair<uint64, Point>> m_clientPosBuffer;
83+
84+
CursorState m_state;
85+
86+
Mat3x2 m_transformLocal = Mat3x2::Identity();
87+
Mat3x2 m_transformCamera = Mat3x2::Identity();
88+
Mat3x2 m_transformScreen = Mat3x2::Identity();
89+
Mat3x2 m_transformAll = Mat3x2::Identity();
90+
Mat3x2 m_transformAllInv = Mat3x2::Identity();
91+
92+
bool m_clippedToWindow = false;
93+
94+
static void CursorDeleter(HICON h)
95+
{
96+
::DestroyIcon(h);
97+
}
98+
99+
std::array<HCURSOR, 11> m_systemCursors;
100+
HICON m_currentCursor = nullptr;
101+
HICON m_defaultCursor = nullptr;
102+
HICON m_requestedCursor = nullptr;
103+
HashTable<String, unique_resource<HICON, decltype(&CursorDeleter)>> m_customCursors;
104+
105+
bool m_captured = false;
106+
107+
void confineCursor();
102108
};
103109
}
104110

Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.hpp

+31-25
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,6 @@ namespace s3d
2222
{
2323
class CCursor final : public ISiv3DCursor
2424
{
25-
private:
26-
27-
GLFWwindow* m_window = nullptr;
28-
29-
CursorState m_state;
30-
31-
Mat3x2 m_transformLocal = Mat3x2::Identity();
32-
Mat3x2 m_transformCamera = Mat3x2::Identity();
33-
Mat3x2 m_transformScreen = Mat3x2::Identity();
34-
Mat3x2 m_transformAll = Mat3x2::Identity();
35-
Mat3x2 m_transformAllInv = Mat3x2::Identity();
36-
37-
bool m_clipToWindow = false;
38-
39-
static void CursorDeleter(GLFWcursor* h)
40-
{
41-
::glfwDestroyCursor(h);
42-
}
43-
44-
std::array<GLFWcursor*, 11> m_systemCursors;
45-
GLFWcursor* m_currentCursor;
46-
GLFWcursor* m_defaultCursor;
47-
GLFWcursor* m_requestedCursor;
48-
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;
49-
5025
public:
5126

5227
void* m_event = nullptr;
@@ -86,5 +61,36 @@ namespace s3d
8661
bool registerCursor(StringView name, const Image& image, Point hotSpot) override;
8762

8863
void requestStyle(StringView name) override;
64+
65+
void setCapture(bool captured) noexcept override;
66+
67+
bool isCaptured() const noexcept override;
68+
69+
private:
70+
71+
GLFWwindow* m_window = nullptr;
72+
73+
CursorState m_state;
74+
75+
Mat3x2 m_transformLocal = Mat3x2::Identity();
76+
Mat3x2 m_transformCamera = Mat3x2::Identity();
77+
Mat3x2 m_transformScreen = Mat3x2::Identity();
78+
Mat3x2 m_transformAll = Mat3x2::Identity();
79+
Mat3x2 m_transformAllInv = Mat3x2::Identity();
80+
81+
bool m_clipToWindow = false;
82+
83+
static void CursorDeleter(GLFWcursor* h)
84+
{
85+
::glfwDestroyCursor(h);
86+
}
87+
88+
std::array<GLFWcursor*, 11> m_systemCursors;
89+
GLFWcursor* m_currentCursor;
90+
GLFWcursor* m_defaultCursor;
91+
GLFWcursor* m_requestedCursor;
92+
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;
93+
94+
bool m_captured = false;
8995
};
9096
}

Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.mm

+10
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,14 @@ static Vec2 GetClientCursorPos(GLFWwindow* window)
293293
m_requestedCursor = it->second.get();
294294
}
295295
}
296+
297+
void CCursor::setCapture(const bool captured) noexcept
298+
{
299+
m_captured = captured;
300+
}
301+
302+
bool CCursor::isCaptured() const noexcept
303+
{
304+
return m_captured;
305+
}
296306
}

Siv3D/src/Siv3D/Cursor/CCursor_Null.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,14 @@ namespace s3d
104104
{
105105

106106
}
107+
108+
void CCursor_Null::setCapture(const bool) noexcept
109+
{
110+
111+
}
112+
113+
bool CCursor_Null::isCaptured() const noexcept
114+
{
115+
return false;
116+
}
107117
}

Siv3D/src/Siv3D/Cursor/CCursor_Null.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,9 @@ namespace s3d
6363
bool registerCursor(StringView name, const Image& image, Point hotSpot) override;
6464

6565
void requestStyle(StringView name) override;
66+
67+
void setCapture(bool captured) noexcept override;
68+
69+
bool isCaptured() const noexcept override;
6670
};
6771
}

0 commit comments

Comments
 (0)