SetCursorPosition Windows
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m36s

This commit is contained in:
2025-07-12 17:08:37 -04:00
parent ac9512ef1d
commit bc59e49402
5 changed files with 28 additions and 7 deletions

View File

@@ -300,7 +300,8 @@ public:
/// Set the position of the cursor relative to the top-left corner of the renderable area.
/// @returns False if the cursor could not be guaranteed to be teleported.
/// @note our window *must* be visible and in focus.
/// @note Moving the cursor outside of our window is unsupported.
/// @note Moving the cursor outside our window is unsupported.
/// @note Doesn't update where the mouse is observed for this refresh.
[[nodiscard]] bool SetCursorPosition(const std::pair<int, int>& position);
[[nodiscard]] bool SetCursorPosition(int x, int y);

View File

@@ -57,8 +57,6 @@ int main() {
window->SetResizable(true);
window->SetKeyRepeatEnabled(false);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
Logger::Debug(std::format
(
"Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} KEY_REPEAT={} QUIT={}",

View File

@@ -46,10 +46,6 @@ bool RWindow::SetCursorPosition(const std::pair<int, int>& position) {
return true;
}
bool RWindow::SetCursorPosition(const int x, const int y) {
return SetCursorPosition({x, y});
}
void RWindow::SetKeyRepeatEnabled(bool state) {
key_repeat = state;

View File

@@ -124,6 +124,8 @@ int RWindow::GetHeight() const { return this->height; }
float RWindow::GetRefreshRate() const { return refresh_rate; }
bool RWindow::SetCursorPosition(const int x, const int y) { return SetCursorPosition({x, y}); }
unsigned long long RWindow::GetRefreshCount() const { return refresh_count; }
void RWindow::SetSizeWithoutEvent(const std::pair<int, int>& size) {

View File

@@ -30,6 +30,29 @@ void RWindow::SetCursorFocused(bool state) {
}
}
bool RWindow::SetCursorPosition(const std::pair<int, int>& position) {
if (!IsFocused())
return false;
if (!IsVisible())
return false;
if (position.first < 0 || position.first > GetWidth())
return false;
if (position.second < 0 || position.second > GetHeight())
return false;
POINT screen_pos = { position.first, position.second };
if (!ClientToScreen(platform->hwnd, &screen_pos))
return false;
if (!SetCursorPos(screen_pos.x, screen_pos.y))
return false;
return true;
}
std::pair<int, int> RWindow::SetCursorCenter() {
auto current_cursor_pos = GetAccurateCursorCoordinates();
RECT client_rect;
@@ -40,6 +63,7 @@ std::pair<int, int> RWindow::SetCursorCenter() {
return current_cursor_pos;
}
void RWindow::PollEvents() {
MSG msg;
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))