Skip to content

Commit

Permalink
Wrapping updateMouseCursor() behind a dirty flag, like other example …
Browse files Browse the repository at this point in the history
…backends. Fixes the window resize cursor not being shown.
  • Loading branch information
lucasz93 authored and eliasdaler committed Mar 28, 2022
1 parent 03c3e30 commit 8faa79d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions imgui-SFML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct WindowContext {
bool windowHasFocus;
bool mouseMoved;
bool mousePressed[3];
ImGuiMouseCursor lastCursor;

bool touchDown[3];
sf::Vector2i touchPos;
Expand Down Expand Up @@ -202,6 +203,7 @@ struct WindowContext {
mousePressed[i] = false;
touchDown[i] = false;
}
lastCursor = ImGuiMouseCursor_COUNT;

joystickId = getConnectedJoystickId();
for (int i = 0; i < ImGuiNavInput_COUNT; ++i) {
Expand Down Expand Up @@ -432,22 +434,23 @@ void Update(sf::RenderWindow& window, sf::Time dt) {

void Update(sf::Window& window, sf::RenderTarget& target, sf::Time dt) {
SetCurrentWindow(window);
assert(s_currWindowCtx);

// Update OS/hardware mouse cursor if imgui isn't drawing a software cursor
updateMouseCursor(window);
ImGuiMouseCursor mouse_cursor =
ImGui::GetIO().MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor();
if (s_currWindowCtx->lastCursor != mouse_cursor) {
s_currWindowCtx->lastCursor = mouse_cursor;
updateMouseCursor(window);
}

assert(s_currWindowCtx);
if (!s_currWindowCtx->mouseMoved) {
if (sf::Touch::isDown(0)) s_currWindowCtx->touchPos = sf::Touch::getPosition(0, window);

Update(s_currWindowCtx->touchPos, static_cast<sf::Vector2f>(target.getSize()), dt);
} else {
Update(sf::Mouse::getPosition(window), static_cast<sf::Vector2f>(target.getSize()), dt);
}

if (ImGui::GetIO().MouseDrawCursor) {
// Hide OS mouse cursor if imgui is drawing it
window.setMouseCursorVisible(false);
}
}

void Update(const sf::Vector2i& mousePos, const sf::Vector2f& displaySize, sf::Time dt) {
Expand Down

0 comments on commit 8faa79d

Please sign in to comment.