2019-12-16 03:28:01 +00:00
|
|
|
#include "d3d9_cursor.h"
|
2020-02-20 01:44:45 +00:00
|
|
|
#include "d3d9_util.h"
|
2019-12-16 03:28:01 +00:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2022-08-21 18:41:51 +00:00
|
|
|
#ifdef _WIN32
|
2024-09-28 15:53:02 +03:00
|
|
|
void D3D9Cursor::ResetCursor() {
|
|
|
|
ShowCursor(FALSE);
|
|
|
|
|
2024-10-08 20:55:52 +03:00
|
|
|
if (m_hCursor != nullptr)
|
|
|
|
ResetHardwareCursor();
|
2024-10-09 21:51:13 +03:00
|
|
|
else if (IsSoftwareCursor())
|
2024-10-08 20:55:52 +03:00
|
|
|
ResetSoftwareCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D9Cursor::ResetHardwareCursor() {
|
|
|
|
::DestroyCursor(m_hCursor);
|
|
|
|
m_hCursor = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D9Cursor::ResetSoftwareCursor() {
|
|
|
|
m_sCursor.DrawCursor = false;
|
|
|
|
m_sCursor.ResetCursor = true;
|
2024-09-28 15:53:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-16 03:28:01 +00:00
|
|
|
void D3D9Cursor::UpdateCursor(int X, int Y) {
|
2020-02-20 01:44:45 +00:00
|
|
|
POINT currentPos = { };
|
|
|
|
if (::GetCursorPos(¤tPos) && currentPos == POINT{ X, Y })
|
|
|
|
return;
|
|
|
|
|
2019-12-16 03:28:01 +00:00
|
|
|
::SetCursorPos(X, Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-28 15:53:02 +03:00
|
|
|
void D3D9Cursor::RefreshSoftwareCursorPosition() {
|
|
|
|
POINT currentPos = { };
|
|
|
|
::GetCursorPos(¤tPos);
|
|
|
|
|
2024-10-11 11:51:27 +03:00
|
|
|
m_sCursor.X = static_cast<int32_t>(currentPos.x) - m_sCursor.XHotSpot;
|
|
|
|
m_sCursor.Y = static_cast<int32_t>(currentPos.y) - m_sCursor.YHotSpot;
|
2024-09-28 15:53:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-16 03:28:01 +00:00
|
|
|
BOOL D3D9Cursor::ShowCursor(BOOL bShow) {
|
2024-10-05 17:44:46 +03:00
|
|
|
// Cursor visibility remains unchanged (typically FALSE) if the cursor isn't set.
|
2024-10-09 21:51:13 +03:00
|
|
|
if (unlikely(m_hCursor == nullptr && !IsSoftwareCursor()))
|
2024-10-05 17:44:46 +03:00
|
|
|
return m_visible;
|
|
|
|
|
2024-10-08 20:55:52 +03:00
|
|
|
if (m_hCursor != nullptr)
|
2023-07-16 18:46:19 +03:00
|
|
|
::SetCursor(bShow ? m_hCursor : nullptr);
|
2024-10-09 21:51:13 +03:00
|
|
|
else if (likely(!m_sCursor.ResetCursor))
|
2024-10-08 20:55:52 +03:00
|
|
|
m_sCursor.DrawCursor = bShow;
|
2023-07-16 18:46:19 +03:00
|
|
|
|
2019-12-16 03:28:01 +00:00
|
|
|
return std::exchange(m_visible, bShow);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT D3D9Cursor::SetHardwareCursor(UINT XHotSpot, UINT YHotSpot, const CursorBitmap& bitmap) {
|
2024-10-08 20:55:52 +03:00
|
|
|
if (IsSoftwareCursor())
|
|
|
|
ResetSoftwareCursor();
|
2024-09-28 15:53:02 +03:00
|
|
|
|
2024-07-06 23:43:38 +03:00
|
|
|
CursorMask mask;
|
2019-12-16 03:28:01 +00:00
|
|
|
std::memset(mask, ~0, sizeof(mask));
|
|
|
|
|
|
|
|
ICONINFO info;
|
|
|
|
info.fIcon = FALSE;
|
|
|
|
info.xHotspot = XHotSpot;
|
|
|
|
info.yHotspot = YHotSpot;
|
2024-07-06 23:43:38 +03:00
|
|
|
info.hbmMask = ::CreateBitmap(HardwareCursorWidth, HardwareCursorHeight, 1, 1, &mask[0]);
|
2019-12-16 03:28:01 +00:00
|
|
|
info.hbmColor = ::CreateBitmap(HardwareCursorWidth, HardwareCursorHeight, 1, 32, &bitmap[0]);
|
|
|
|
|
|
|
|
if (m_hCursor != nullptr)
|
|
|
|
::DestroyCursor(m_hCursor);
|
|
|
|
|
|
|
|
m_hCursor = ::CreateIconIndirect(&info);
|
|
|
|
|
|
|
|
::DeleteObject(info.hbmMask);
|
|
|
|
::DeleteObject(info.hbmColor);
|
|
|
|
|
|
|
|
ShowCursor(m_visible);
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
2024-09-28 15:53:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
HRESULT D3D9Cursor::SetSoftwareCursor(UINT Width, UINT Height, UINT XHotSpot, UINT YHotSpot) {
|
|
|
|
// Make sure to hide the win32 cursor
|
|
|
|
::SetCursor(nullptr);
|
|
|
|
|
2024-10-08 20:55:52 +03:00
|
|
|
if (m_hCursor != nullptr)
|
|
|
|
ResetHardwareCursor();
|
2024-09-28 15:53:02 +03:00
|
|
|
|
2024-10-09 21:51:13 +03:00
|
|
|
m_sCursor.Width = Width;
|
|
|
|
m_sCursor.Height = Height;
|
2024-10-11 11:51:27 +03:00
|
|
|
m_sCursor.XHotSpot = XHotSpot;
|
|
|
|
m_sCursor.YHotSpot = YHotSpot;
|
2024-10-09 21:51:13 +03:00
|
|
|
m_sCursor.ResetCursor = false;
|
2024-09-28 15:53:02 +03:00
|
|
|
|
|
|
|
ShowCursor(m_visible);
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2022-08-21 18:41:51 +00:00
|
|
|
#else
|
2024-09-28 15:53:02 +03:00
|
|
|
void D3D9Cursor::ResetCursor() {
|
|
|
|
Logger::warn("D3D9Cursor::ResetCursor: Not supported on current platform.");
|
|
|
|
}
|
|
|
|
|
2024-10-09 21:51:13 +03:00
|
|
|
|
2024-10-08 20:55:52 +03:00
|
|
|
void D3D9Cursor::ResetHardwareCursor() {
|
|
|
|
Logger::warn("D3D9Cursor::ResetHardwareCursor: Not supported on current platform.");
|
|
|
|
}
|
|
|
|
|
2024-10-09 21:51:13 +03:00
|
|
|
|
2024-10-08 20:55:52 +03:00
|
|
|
void D3D9Cursor::ResetSoftwareCursor() {
|
|
|
|
Logger::warn("D3D9Cursor::ResetSoftwareCursor: Not supported on current platform.");
|
|
|
|
}
|
2024-09-28 15:53:02 +03:00
|
|
|
|
2024-10-09 21:51:13 +03:00
|
|
|
|
2022-08-21 18:41:51 +00:00
|
|
|
void D3D9Cursor::UpdateCursor(int X, int Y) {
|
|
|
|
Logger::warn("D3D9Cursor::UpdateCursor: Not supported on current platform.");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-28 15:53:02 +03:00
|
|
|
void D3D9Cursor::RefreshSoftwareCursorPosition() {
|
|
|
|
Logger::warn("D3D9Cursor::RefreshSoftwareCursorPosition: Not supported on current platform.");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-21 18:41:51 +00:00
|
|
|
BOOL D3D9Cursor::ShowCursor(BOOL bShow) {
|
|
|
|
Logger::warn("D3D9Cursor::ShowCursor: Not supported on current platform.");
|
|
|
|
return std::exchange(m_visible, bShow);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT D3D9Cursor::SetHardwareCursor(UINT XHotSpot, UINT YHotSpot, const CursorBitmap& bitmap) {
|
|
|
|
Logger::warn("D3D9Cursor::SetHardwareCursor: Not supported on current platform.");
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
2024-09-28 15:53:02 +03:00
|
|
|
|
|
|
|
HRESULT D3D9Cursor::SetSoftwareCursor(UINT Width, UINT Height, UINT XHotSpot, UINT YHotSpot) {
|
|
|
|
Logger::warn("D3D9Cursor::SetSoftwareCursor: Not supported on current platform.");
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
2022-08-21 18:41:51 +00:00
|
|
|
#endif
|
2019-12-16 03:28:01 +00:00
|
|
|
|
2023-07-16 18:46:19 +03:00
|
|
|
}
|