Skip to content

Commit

Permalink
[Windows, macOS, Linux, Web] CCursor::setCapture(), isCaptured()
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Aug 28, 2023
1 parent 7c76acd commit f2102c3
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 105 deletions.
9 changes: 9 additions & 0 deletions Siv3D/include/Siv3D/Cursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
10 changes: 10 additions & 0 deletions Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
56 changes: 31 additions & 25 deletions Siv3D/src/Siv3D-Platform/Linux/Siv3D/Cursor/CCursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GLFWcursor*, 11> m_systemCursors;
GLFWcursor* m_currentCursor = nullptr;
GLFWcursor* m_defaultCursor = nullptr;
GLFWcursor* m_requestedCursor = nullptr;
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;

public:

CCursor();
Expand Down Expand Up @@ -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<GLFWcursor*, 11> m_systemCursors;
GLFWcursor* m_currentCursor = nullptr;
GLFWcursor* m_defaultCursor = nullptr;
GLFWcursor* m_requestedCursor = nullptr;
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;

bool m_captured = false;
};
}
10 changes: 10 additions & 0 deletions Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
56 changes: 31 additions & 25 deletions Siv3D/src/Siv3D-Platform/Web/Siv3D/Cursor/CCursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, 11> m_systemCursors;
String m_currentCursor;
String m_defaultCursor;
String m_requestedCursor;
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;

public:

CCursor();
Expand Down Expand Up @@ -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<String, 11> m_systemCursors;
String m_currentCursor;
String m_defaultCursor;
String m_requestedCursor;
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;

bool m_captured = false;
};
}
10 changes: 10 additions & 0 deletions Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
66 changes: 36 additions & 30 deletions Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Cursor/CCursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,6 @@ namespace s3d
{
class CCursor final : public ISiv3DCursor
{
private:

HWND m_hWnd = nullptr;

std::mutex m_clientPosBufferMutex;
Array<std::pair<uint64, Point>> 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<HCURSOR, 11> m_systemCursors;
HICON m_currentCursor = nullptr;
HICON m_defaultCursor = nullptr;
HICON m_requestedCursor = nullptr;
HashTable<String, unique_resource<HICON, decltype(&CursorDeleter)>> m_customCursors;

void confineCursor();

public:

CCursor();
Expand Down Expand Up @@ -92,13 +62,49 @@ namespace s3d

void requestStyle(StringView name) override;

void setCapture(bool captured) noexcept override;

bool isCaptured() const noexcept override;

////////////////////////////////////////////////////////////////
//
// Windows
//
void handleMessage(UINT message, WPARAM wParam, LPARAM lParam);

void onSetCursor();

private:

HWND m_hWnd = nullptr;

std::mutex m_clientPosBufferMutex;
Array<std::pair<uint64, Point>> 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<HCURSOR, 11> m_systemCursors;
HICON m_currentCursor = nullptr;
HICON m_defaultCursor = nullptr;
HICON m_requestedCursor = nullptr;
HashTable<String, unique_resource<HICON, decltype(&CursorDeleter)>> m_customCursors;

bool m_captured = false;

void confineCursor();
};
}

56 changes: 31 additions & 25 deletions Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GLFWcursor*, 11> m_systemCursors;
GLFWcursor* m_currentCursor;
GLFWcursor* m_defaultCursor;
GLFWcursor* m_requestedCursor;
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;

public:

void* m_event = nullptr;
Expand Down Expand Up @@ -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<GLFWcursor*, 11> m_systemCursors;
GLFWcursor* m_currentCursor = nullptr;
GLFWcursor* m_defaultCursor = nullptr;
GLFWcursor* m_requestedCursor = nullptr;
HashTable<String, unique_resource<GLFWcursor*, decltype(&CursorDeleter)>> m_customCursors;

bool m_captured = false;
};
}
10 changes: 10 additions & 0 deletions Siv3D/src/Siv3D-Platform/macOS/Siv3D/Cursor/CCursor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions Siv3D/src/Siv3D/Cursor/CCursor_Null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ namespace s3d
{

}

void CCursor_Null::setCapture(const bool) noexcept
{

}

bool CCursor_Null::isCaptured() const noexcept
{
return false;
}
}
4 changes: 4 additions & 0 deletions Siv3D/src/Siv3D/Cursor/CCursor_Null.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Loading

0 comments on commit f2102c3

Please sign in to comment.