Skip to content

Commit 8faa79d

Browse files
lucasz93eliasdaler
authored andcommitted
Wrapping updateMouseCursor() behind a dirty flag, like other example backends. Fixes the window resize cursor not being shown.
1 parent 03c3e30 commit 8faa79d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

imgui-SFML.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct WindowContext {
173173
bool windowHasFocus;
174174
bool mouseMoved;
175175
bool mousePressed[3];
176+
ImGuiMouseCursor lastCursor;
176177

177178
bool touchDown[3];
178179
sf::Vector2i touchPos;
@@ -202,6 +203,7 @@ struct WindowContext {
202203
mousePressed[i] = false;
203204
touchDown[i] = false;
204205
}
206+
lastCursor = ImGuiMouseCursor_COUNT;
205207

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

433435
void Update(sf::Window& window, sf::RenderTarget& target, sf::Time dt) {
434436
SetCurrentWindow(window);
437+
assert(s_currWindowCtx);
438+
435439
// Update OS/hardware mouse cursor if imgui isn't drawing a software cursor
436-
updateMouseCursor(window);
440+
ImGuiMouseCursor mouse_cursor =
441+
ImGui::GetIO().MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor();
442+
if (s_currWindowCtx->lastCursor != mouse_cursor) {
443+
s_currWindowCtx->lastCursor = mouse_cursor;
444+
updateMouseCursor(window);
445+
}
437446

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

442450
Update(s_currWindowCtx->touchPos, static_cast<sf::Vector2f>(target.getSize()), dt);
443451
} else {
444452
Update(sf::Mouse::getPosition(window), static_cast<sf::Vector2f>(target.getSize()), dt);
445453
}
446-
447-
if (ImGui::GetIO().MouseDrawCursor) {
448-
// Hide OS mouse cursor if imgui is drawing it
449-
window.setMouseCursorVisible(false);
450-
}
451454
}
452455

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

0 commit comments

Comments
 (0)