Created
July 5, 2023 09:01
-
-
Save shiyuugohirao/7193b074a6b23036f8d76e79db72898b to your computer and use it in GitHub Desktop.
handling mouse visibility in openFrameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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