Skip to content

Commit

Permalink
[d3d9] Update software cursor position using SetCursorPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall authored and doitsujin committed Feb 8, 2025
1 parent 54a26dd commit 13554f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
23 changes: 9 additions & 14 deletions src/d3d9/d3d9_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ namespace dxvk {


void D3D9Cursor::UpdateCursor(int X, int Y) {
// SetCursorPosition is used to directly update the position of software cursors,
// but keep track of the cursor position even when using hardware cursors, in order
// to ensure a smooth transition/overlap from one type to the other.
m_sCursor.X = X;
m_sCursor.Y = Y;

if (unlikely(m_sCursor.Width > 0 && m_sCursor.Height > 0))
return;

POINT currentPos = { };
if (::GetCursorPos(&currentPos) && currentPos == POINT{ X, Y })
return;
Expand All @@ -37,15 +46,6 @@ namespace dxvk {
}


void D3D9Cursor::RefreshSoftwareCursorPosition() {
POINT currentPos = { };
::GetCursorPos(&currentPos);

m_sCursor.X = static_cast<int32_t>(currentPos.x) - m_sCursor.XHotSpot;
m_sCursor.Y = static_cast<int32_t>(currentPos.y) - m_sCursor.YHotSpot;
}


BOOL D3D9Cursor::ShowCursor(BOOL bShow) {
// Cursor visibility remains unchanged (typically FALSE) if the cursor isn't set.
if (unlikely(m_hCursor == nullptr && !IsSoftwareCursor()))
Expand Down Expand Up @@ -127,11 +127,6 @@ namespace dxvk {
}


void D3D9Cursor::RefreshSoftwareCursorPosition() {
Logger::warn("D3D9Cursor::RefreshSoftwareCursorPosition: Not supported on current platform.");
}


BOOL D3D9Cursor::ShowCursor(BOOL bShow) {
Logger::warn("D3D9Cursor::ShowCursor: Not supported on current platform.");
return std::exchange(m_visible, bShow);
Expand Down
2 changes: 0 additions & 2 deletions src/d3d9/d3d9_cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ namespace dxvk {

void UpdateCursor(int X, int Y);

void RefreshSoftwareCursorPosition();

BOOL ShowCursor(BOOL bShow);

HRESULT SetHardwareCursor(UINT XHotSpot, UINT YHotSpot, const CursorBitmap& bitmap);
Expand Down
7 changes: 2 additions & 5 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4052,14 +4052,13 @@ namespace dxvk {
DWORD dwFlags) {

if (m_cursor.IsSoftwareCursor()) {
m_cursor.RefreshSoftwareCursorPosition();

D3D9_SOFTWARE_CURSOR* pSoftwareCursor = m_cursor.GetSoftwareCursor();

UINT cursorWidth = pSoftwareCursor->DrawCursor ? pSoftwareCursor->Width : 0;
UINT cursorHeight = pSoftwareCursor->DrawCursor ? pSoftwareCursor->Height : 0;

m_implicitSwapchain->SetCursorPosition(pSoftwareCursor->X, pSoftwareCursor->Y,
m_implicitSwapchain->SetCursorPosition(pSoftwareCursor->X - pSoftwareCursor->XHotSpot,
pSoftwareCursor->Y - pSoftwareCursor->YHotSpot,
cursorWidth, cursorHeight);

// Once a hardware cursor has been set or the device has been reset,
Expand All @@ -4070,8 +4069,6 @@ namespace dxvk {
pSoftwareCursor->Height = 0;
pSoftwareCursor->XHotSpot = 0;
pSoftwareCursor->YHotSpot = 0;
pSoftwareCursor->X = 0;
pSoftwareCursor->Y = 0;
pSoftwareCursor->ResetCursor = false;
}
}
Expand Down

0 comments on commit 13554f1

Please sign in to comment.