Last active
August 16, 2024 12:58
-
-
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 "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