Skip to content

Instantly share code, notes, and snippets.

@shiyuugohirao
Created July 5, 2023 09:01
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 "ofMain.h"
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) {
// ofLogVerbose(_YP_, "hide cursor");
ShowCursor(false);
cursorFlag = false;
}
} else {
if (!cursorFlag) {
// ofLogVerbose(_YP_, "show cursor");
stopCursorTimef = 0;
ShowCursor(true);
cursorFlag = true;
}
}
lastCursorPos = cursorPos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment