Merge pull request #1058 from ZappoMan/hide_cursor

make mouse cursor hiding more aware of focused window and bounds
This commit is contained in:
ZappoMan 2013-10-14 11:50:21 -07:00
commit 8c5c1aeae7
2 changed files with 19 additions and 6 deletions

View file

@ -107,6 +107,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_mouseY(0),
_lastMouseMove(usecTimestampNow()),
_mouseHidden(false),
_seenMouseMove(false),
_touchAvgX(0.0f),
_touchAvgY(0.0f),
_isTouchPressed(false),
@ -988,6 +989,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) {
if (_mouseHidden) {
getGLWidget()->setCursor(Qt::ArrowCursor);
_mouseHidden = false;
_seenMouseMove = true;
}
if (activeWindow() == _window) {
@ -2133,12 +2135,22 @@ void Application::update(float deltaTime) {
#endif
// watch mouse position, if it hasn't moved, hide the cursor
uint64_t now = usecTimestampNow();
int elapsed = now - _lastMouseMove;
const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second
if (elapsed > HIDE_CURSOR_TIMEOUT) {
getGLWidget()->setCursor(Qt::BlankCursor);
_mouseHidden = true;
bool underMouse = _glWidget->underMouse();
if (!_mouseHidden) {
uint64_t now = usecTimestampNow();
int elapsed = now - _lastMouseMove;
const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second
if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) {
getGLWidget()->setCursor(Qt::BlankCursor);
_mouseHidden = true;
}
} else {
// if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving
if (!underMouse && _seenMouseMove) {
_lastMouseMove = usecTimestampNow();
getGLWidget()->setCursor(Qt::ArrowCursor);
_mouseHidden = false;
}
}
}

View file

@ -307,6 +307,7 @@ private:
int _mouseDragStartedY;
uint64_t _lastMouseMove;
bool _mouseHidden;
bool _seenMouseMove;
float _touchAvgX;
float _touchAvgY;