mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 08:30:35 +02:00
Mouse cursor modifications
This commit is contained in:
parent
0a4f74cf9c
commit
8765d9a9b3
3 changed files with 30 additions and 68 deletions
|
@ -167,8 +167,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
_raiseMirror(0.0f),
|
_raiseMirror(0.0f),
|
||||||
_lastMouseMove(usecTimestampNow()),
|
_lastMouseMove(usecTimestampNow()),
|
||||||
_lastMouseMoveWasSimulated(false),
|
_lastMouseMoveWasSimulated(false),
|
||||||
_mouseHidden(false),
|
|
||||||
_seenMouseMove(false),
|
|
||||||
_touchAvgX(0.0f),
|
_touchAvgX(0.0f),
|
||||||
_touchAvgY(0.0f),
|
_touchAvgY(0.0f),
|
||||||
_isTouchPressed(false),
|
_isTouchPressed(false),
|
||||||
|
@ -1252,34 +1250,23 @@ void Application::focusOutEvent(QFocusEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
|
void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||||
bool showMouse = true;
|
|
||||||
|
|
||||||
// Used by application overlay to determine how to draw cursor(s)
|
// Used by application overlay to determine how to draw cursor(s)
|
||||||
_lastMouseMoveWasSimulated = deviceID > 0;
|
_lastMouseMoveWasSimulated = deviceID > 0;
|
||||||
|
if (!_lastMouseMoveWasSimulated) {
|
||||||
// If this mouse move event is emitted by a controller, dont show the mouse cursor
|
_lastMouseMove = usecTimestampNow();
|
||||||
if (_lastMouseMoveWasSimulated) {
|
|
||||||
showMouse = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_aboutToQuit) {
|
if (!_aboutToQuit) {
|
||||||
_entities.mouseMoveEvent(event, deviceID);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_entities.mouseMoveEvent(event, deviceID);
|
||||||
|
|
||||||
_controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts
|
_controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts
|
||||||
|
|
||||||
// if one of our scripts have asked to capture this event, then stop processing it
|
// if one of our scripts have asked to capture this event, then stop processing it
|
||||||
if (_controllerScriptingInterface.isMouseCaptured()) {
|
if (_controllerScriptingInterface.isMouseCaptured()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastMouseMove = usecTimestampNow();
|
|
||||||
|
|
||||||
if (_mouseHidden && showMouse && !OculusManager::isConnected() && !TV3DManager::isConnected()) {
|
|
||||||
getGLWidget()->setCursor(Qt::ArrowCursor);
|
|
||||||
_mouseHidden = false;
|
|
||||||
_seenMouseMove = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||||
|
@ -2111,13 +2098,7 @@ void Application::updateMouseRay() {
|
||||||
// make sure the frustum is up-to-date
|
// make sure the frustum is up-to-date
|
||||||
loadViewFrustum(_myCamera, _viewFrustum);
|
loadViewFrustum(_myCamera, _viewFrustum);
|
||||||
|
|
||||||
// if the mouse pointer isn't visible, act like it's at the center of the screen
|
PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY());
|
||||||
float x = 0.5f, y = 0.5f;
|
|
||||||
if (!_mouseHidden) {
|
|
||||||
x = getTrueMouseX() / (float)_glWidget->width();
|
|
||||||
y = getTrueMouseY() / (float)_glWidget->height();
|
|
||||||
}
|
|
||||||
PickRay pickRay = _myCamera.computeViewPickRay(x, y);
|
|
||||||
_mouseRayOrigin = pickRay.origin;
|
_mouseRayOrigin = pickRay.origin;
|
||||||
_mouseRayDirection = pickRay.direction;
|
_mouseRayDirection = pickRay.direction;
|
||||||
|
|
||||||
|
@ -2313,23 +2294,26 @@ void Application::updateCursor(float deltaTime) {
|
||||||
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
|
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
|
||||||
PerformanceWarning warn(showWarnings, "Application::updateCursor()");
|
PerformanceWarning warn(showWarnings, "Application::updateCursor()");
|
||||||
|
|
||||||
// watch mouse position, if it hasn't moved, hide the cursor
|
bool hideMouse = false;
|
||||||
bool underMouse = _glWidget->underMouse();
|
bool underMouse = _glWidget->underMouse();
|
||||||
if (!_mouseHidden) {
|
|
||||||
quint64 now = usecTimestampNow();
|
static const int HIDE_CURSOR_TIMEOUT = 1 * USECS_PER_SECOND; // 1 second
|
||||||
int elapsed = now - _lastMouseMove;
|
int elapsed = usecTimestampNow() - _lastMouseMove;
|
||||||
const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second
|
if ((elapsed > HIDE_CURSOR_TIMEOUT && underMouse) ||
|
||||||
if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) {
|
(OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) {
|
||||||
getGLWidget()->setCursor(Qt::BlankCursor);
|
hideMouse = true;
|
||||||
_mouseHidden = true;
|
}
|
||||||
}
|
|
||||||
|
if (hideMouse != isMouseHidden()) {
|
||||||
|
setCursorVisible(!hideMouse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setCursorVisible(bool visible) {
|
||||||
|
if (visible) {
|
||||||
|
_glWidget->setCursor(Qt::ArrowCursor);
|
||||||
} else {
|
} else {
|
||||||
// if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving
|
_glWidget->setCursor(Qt::BlankCursor);
|
||||||
if (!underMouse && _seenMouseMove) {
|
|
||||||
_lastMouseMove = usecTimestampNow();
|
|
||||||
getGLWidget()->setCursor(Qt::ArrowCursor);
|
|
||||||
_mouseHidden = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2350,17 +2334,6 @@ void Application::update(float deltaTime) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QCursor cursor;
|
|
||||||
if (OculusManager::isConnected() &&
|
|
||||||
Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)){
|
|
||||||
if (_window->cursor().shape() != Qt::BlankCursor) {
|
|
||||||
cursor = _window->cursor();
|
|
||||||
_window->setCursor(QCursor(Qt::BlankCursor));
|
|
||||||
}
|
|
||||||
} else if(_window->cursor().shape() == Qt::BlankCursor) {
|
|
||||||
_window->setCursor(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dispatch input events
|
// Dispatch input events
|
||||||
_controllerScriptingInterface.updateInputControllers();
|
_controllerScriptingInterface.updateInputControllers();
|
||||||
|
|
||||||
|
@ -4372,14 +4345,6 @@ void Application::skipVersion(QString latestVersion) {
|
||||||
skipFile.write(latestVersion.toStdString().c_str());
|
skipFile.write(latestVersion.toStdString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setCursorVisible(bool visible) {
|
|
||||||
if (visible) {
|
|
||||||
restoreOverrideCursor();
|
|
||||||
} else {
|
|
||||||
setOverrideCursor(Qt::BlankCursor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::takeSnapshot() {
|
void Application::takeSnapshot() {
|
||||||
QMediaPlayer* player = new QMediaPlayer();
|
QMediaPlayer* player = new QMediaPlayer();
|
||||||
QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav");
|
QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav");
|
||||||
|
|
|
@ -211,7 +211,8 @@ public:
|
||||||
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
|
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
|
||||||
Environment* getEnvironment() { return &_environment; }
|
Environment* getEnvironment() { return &_environment; }
|
||||||
bool isMousePressed() const { return _mousePressed; }
|
bool isMousePressed() const { return _mousePressed; }
|
||||||
bool isMouseHidden() const { return _mouseHidden; }
|
bool isMouseHidden() const { return _glWidget->cursor().shape() == Qt::BlankCursor; }
|
||||||
|
void setCursorVisible(bool visible);
|
||||||
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
||||||
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||||
bool mouseOnScreen() const;
|
bool mouseOnScreen() const;
|
||||||
|
@ -309,8 +310,6 @@ public:
|
||||||
|
|
||||||
QStringList getRunningScripts() { return _scriptEnginesHash.keys(); }
|
QStringList getRunningScripts() { return _scriptEnginesHash.keys(); }
|
||||||
ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; }
|
ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; }
|
||||||
|
|
||||||
void setCursorVisible(bool visible);
|
|
||||||
|
|
||||||
bool isLookingAtMyAvatar(Avatar* avatar);
|
bool isLookingAtMyAvatar(Avatar* avatar);
|
||||||
|
|
||||||
|
@ -567,8 +566,6 @@ private:
|
||||||
int _mouseDragStartedY;
|
int _mouseDragStartedY;
|
||||||
quint64 _lastMouseMove;
|
quint64 _lastMouseMove;
|
||||||
bool _lastMouseMoveWasSimulated;
|
bool _lastMouseMoveWasSimulated;
|
||||||
bool _mouseHidden;
|
|
||||||
bool _seenMouseMove;
|
|
||||||
|
|
||||||
glm::vec3 _mouseRayOrigin;
|
glm::vec3 _mouseRayOrigin;
|
||||||
glm::vec3 _mouseRayDirection;
|
glm::vec3 _mouseRayDirection;
|
||||||
|
|
|
@ -122,21 +122,21 @@ void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) {
|
||||||
if (hitLeft || hitRight) {
|
if (hitLeft || hitRight) {
|
||||||
_isResizing = true;
|
_isResizing = true;
|
||||||
_resizeInitialWidth = size().width();
|
_resizeInitialWidth = size().width();
|
||||||
QApplication::setOverrideCursor(Qt::SizeHorCursor);
|
setCursor(Qt::SizeHorCursor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool hitTop = (_position == POSITION_TOP) && (abs(mouseEvent->pos().y() - size().height()) < RESIZE_HANDLE_WIDTH);
|
bool hitTop = (_position == POSITION_TOP) && (abs(mouseEvent->pos().y() - size().height()) < RESIZE_HANDLE_WIDTH);
|
||||||
if (hitTop) {
|
if (hitTop) {
|
||||||
_isResizing = true;
|
_isResizing = true;
|
||||||
_resizeInitialWidth = size().height();
|
_resizeInitialWidth = size().height();
|
||||||
QApplication::setOverrideCursor(Qt::SizeHorCursor);
|
setCursor(Qt::SizeHorCursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessDialog::mouseReleaseEvent(QMouseEvent* mouseEvent) {
|
void FramelessDialog::mouseReleaseEvent(QMouseEvent* mouseEvent) {
|
||||||
QApplication::restoreOverrideCursor();
|
unsetCursor();
|
||||||
_isResizing = false;
|
_isResizing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue