Skip to content

Instantly share code, notes, and snippets.

@shiyuugohirao
Last active August 16, 2024 12:58
Show Gist options
  • Save shiyuugohirao/7193b074a6b23036f8d76e79db72898b to your computer and use it in GitHub Desktop.
Save shiyuugohirao/7193b074a6b23036f8d76e79db72898b to your computer and use it in GitHub Desktop.
handling mouse visibility in openFrameworks
#pragma once
#include "ofAppRunner.h"
/* [Note]
if you use ImGui, add bellow after .begin() not to control mouse by ImGui.
`ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;`
*/
inline void updateMouse(int mouseX, int mouseY, float hideTimef = 1.0) {
glm::vec2 cursorPos(mouseX, mouseY);
static glm::vec2 lastCursorPos = cursorPos;
static bool cursorFlag = true;
static float stopCursorTimef = 0;
if (cursorPos == lastCursorPos) {
stopCursorTimef += 1.0 / ofGetFrameRate();
if (cursorFlag && stopCursorTimef > hideTimef) {
ofHideCursor();
cursorFlag = false;
}
} else {
if (!cursorFlag) {
stopCursorTimef = 0;
ofShowCursor();
cursorFlag = true;
}
}
lastCursorPos = cursorPos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment