mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
Merge pull request #4232 from thoys/cursor_is_visible_and_oculus_cursor_visibility
Ability to make cursor invisible again (both OS-cursor and oculus rectile) and js-interface to cursorVisible boolean
This commit is contained in:
commit
5ea785f4ad
5 changed files with 30 additions and 28 deletions
|
@ -230,6 +230,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
_touchAvgX(0.0f),
|
_touchAvgX(0.0f),
|
||||||
_touchAvgY(0.0f),
|
_touchAvgY(0.0f),
|
||||||
_isTouchPressed(false),
|
_isTouchPressed(false),
|
||||||
|
_cursorVisible(true),
|
||||||
_mousePressed(false),
|
_mousePressed(false),
|
||||||
_enableProcessOctreeThread(true),
|
_enableProcessOctreeThread(true),
|
||||||
_octreeProcessor(),
|
_octreeProcessor(),
|
||||||
|
@ -1480,6 +1481,8 @@ void Application::setEnableVRMode(bool enableVRMode) {
|
||||||
|
|
||||||
auto glCanvas = DependencyManager::get<GLCanvas>();
|
auto glCanvas = DependencyManager::get<GLCanvas>();
|
||||||
resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight());
|
resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight());
|
||||||
|
|
||||||
|
updateCursorVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setLowVelocityFilter(bool lowVelocityFilter) {
|
void Application::setLowVelocityFilter(bool lowVelocityFilter) {
|
||||||
|
@ -1947,35 +1950,22 @@ void Application::updateCursor(float deltaTime) {
|
||||||
|
|
||||||
static QPoint lastMousePos = QPoint();
|
static QPoint lastMousePos = QPoint();
|
||||||
_lastMouseMove = (lastMousePos == QCursor::pos()) ? _lastMouseMove : usecTimestampNow();
|
_lastMouseMove = (lastMousePos == QCursor::pos()) ? _lastMouseMove : usecTimestampNow();
|
||||||
bool hideMouse = false;
|
|
||||||
bool underMouse = QGuiApplication::topLevelAt(QCursor::pos()) ==
|
|
||||||
Application::getInstance()->getWindow()->windowHandle();
|
|
||||||
|
|
||||||
static const int HIDE_CURSOR_TIMEOUT = 3 * USECS_PER_SECOND; // 3 second
|
|
||||||
int elapsed = usecTimestampNow() - _lastMouseMove;
|
|
||||||
if ((elapsed > HIDE_CURSOR_TIMEOUT) ||
|
|
||||||
(OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) {
|
|
||||||
hideMouse = underMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCursorVisible(!hideMouse);
|
|
||||||
lastMousePos = QCursor::pos();
|
lastMousePos = QCursor::pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setCursorVisible(bool visible) {
|
void Application::updateCursorVisibility() {
|
||||||
if (visible) {
|
if (!_cursorVisible || Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) {
|
||||||
if (overrideCursor() != NULL) {
|
DependencyManager::get<GLCanvas>()->setCursor(Qt::BlankCursor);
|
||||||
restoreOverrideCursor();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (overrideCursor() != NULL) {
|
DependencyManager::get<GLCanvas>()->unsetCursor();
|
||||||
changeOverrideCursor(Qt::BlankCursor);
|
|
||||||
} else {
|
|
||||||
setOverrideCursor(Qt::BlankCursor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::setCursorVisible(bool visible) {
|
||||||
|
_cursorVisible = visible;
|
||||||
|
updateCursorVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
void Application::update(float deltaTime) {
|
void Application::update(float deltaTime) {
|
||||||
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
|
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
|
||||||
PerformanceWarning warn(showWarnings, "Application::update()");
|
PerformanceWarning warn(showWarnings, "Application::update()");
|
||||||
|
|
|
@ -186,8 +186,7 @@ public:
|
||||||
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
|
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
|
||||||
|
|
||||||
bool isMousePressed() const { return _mousePressed; }
|
bool isMousePressed() const { return _mousePressed; }
|
||||||
bool isMouseHidden() const { return DependencyManager::get<GLCanvas>()->cursor().shape() == Qt::BlankCursor; }
|
bool isMouseHidden() const { return !_cursorVisible; }
|
||||||
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;
|
||||||
|
@ -398,11 +397,15 @@ private slots:
|
||||||
|
|
||||||
void audioMuteToggled();
|
void audioMuteToggled();
|
||||||
|
|
||||||
|
void setCursorVisible(bool visible);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resetCamerasOnResizeGL(Camera& camera, int width, int height);
|
void resetCamerasOnResizeGL(Camera& camera, int width, int height);
|
||||||
void updateProjectionMatrix();
|
void updateProjectionMatrix();
|
||||||
void updateProjectionMatrix(Camera& camera, bool updateViewFrustum = true);
|
void updateProjectionMatrix(Camera& camera, bool updateViewFrustum = true);
|
||||||
|
|
||||||
|
void updateCursorVisibility();
|
||||||
|
|
||||||
void sendPingPackets();
|
void sendPingPackets();
|
||||||
|
|
||||||
void initDisplay();
|
void initDisplay();
|
||||||
|
@ -514,6 +517,7 @@ private:
|
||||||
|
|
||||||
Environment _environment;
|
Environment _environment;
|
||||||
|
|
||||||
|
bool _cursorVisible;
|
||||||
int _mouseDragStartedX;
|
int _mouseDragStartedX;
|
||||||
int _mouseDragStartedY;
|
int _mouseDragStartedY;
|
||||||
quint64 _lastMouseMove;
|
quint64 _lastMouseMove;
|
||||||
|
|
|
@ -50,7 +50,12 @@ void WindowScriptingInterface::setFocus() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowScriptingInterface::setCursorVisible(bool visible) {
|
void WindowScriptingInterface::setCursorVisible(bool visible) {
|
||||||
Application::getInstance()->setCursorVisible(visible);
|
QMetaObject::invokeMethod(Application::getInstance(), "setCursorVisible", Qt::BlockingQueuedConnection,
|
||||||
|
Q_ARG(bool, visible));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowScriptingInterface::isCursorVisible() const {
|
||||||
|
return !Application::getInstance()->isMouseHidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowScriptingInterface::setCursorPosition(int x, int y) {
|
void WindowScriptingInterface::setCursorPosition(int x, int y) {
|
||||||
|
|
|
@ -27,12 +27,14 @@ class WindowScriptingInterface : public QObject {
|
||||||
Q_PROPERTY(int innerHeight READ getInnerHeight)
|
Q_PROPERTY(int innerHeight READ getInnerHeight)
|
||||||
Q_PROPERTY(int x READ getX)
|
Q_PROPERTY(int x READ getX)
|
||||||
Q_PROPERTY(int y READ getY)
|
Q_PROPERTY(int y READ getY)
|
||||||
|
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible)
|
||||||
public:
|
public:
|
||||||
static WindowScriptingInterface* getInstance();
|
static WindowScriptingInterface* getInstance();
|
||||||
int getInnerWidth();
|
int getInnerWidth();
|
||||||
int getInnerHeight();
|
int getInnerHeight();
|
||||||
int getX();
|
int getX();
|
||||||
int getY();
|
int getY();
|
||||||
|
bool isCursorVisible() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QScriptValue getCursorPositionX();
|
QScriptValue getCursorPositionX();
|
||||||
|
|
|
@ -330,8 +330,9 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
|
||||||
_overlays.buildVBO(_textureFov, _textureAspectRatio, 80, 80);
|
_overlays.buildVBO(_textureFov, _textureAspectRatio, 80, 80);
|
||||||
}
|
}
|
||||||
_overlays.render();
|
_overlays.render();
|
||||||
renderPointersOculus(myAvatar->getDefaultEyePosition());
|
if (!Application::getInstance()->isMouseHidden()) {
|
||||||
|
renderPointersOculus(myAvatar->getDefaultEyePosition());
|
||||||
|
}
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
_overlays.releaseTexture();
|
_overlays.releaseTexture();
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
@ -542,7 +543,7 @@ void ApplicationOverlay::renderPointers() {
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, _crosshairTexture);
|
glBindTexture(GL_TEXTURE_2D, _crosshairTexture);
|
||||||
|
|
||||||
if (OculusManager::isConnected() && !application->getLastMouseMoveWasSimulated()) {
|
if (OculusManager::isConnected() && !application->getLastMouseMoveWasSimulated() && !application->isMouseHidden()) {
|
||||||
//If we are in oculus, render reticle later
|
//If we are in oculus, render reticle later
|
||||||
if (_lastMouseMove == 0) {
|
if (_lastMouseMove == 0) {
|
||||||
_lastMouseMove = usecTimestampNow();
|
_lastMouseMove = usecTimestampNow();
|
||||||
|
|
Loading…
Reference in a new issue