mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:24:03 +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),
|
||||
_lastMouseMove(usecTimestampNow()),
|
||||
_lastMouseMoveWasSimulated(false),
|
||||
_mouseHidden(false),
|
||||
_seenMouseMove(false),
|
||||
_touchAvgX(0.0f),
|
||||
_touchAvgY(0.0f),
|
||||
_isTouchPressed(false),
|
||||
|
@ -1252,34 +1250,23 @@ void Application::focusOutEvent(QFocusEvent* event) {
|
|||
}
|
||||
|
||||
void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||
bool showMouse = true;
|
||||
|
||||
// Used by application overlay to determine how to draw cursor(s)
|
||||
_lastMouseMoveWasSimulated = deviceID > 0;
|
||||
|
||||
// If this mouse move event is emitted by a controller, dont show the mouse cursor
|
||||
if (_lastMouseMoveWasSimulated) {
|
||||
showMouse = false;
|
||||
if (!_lastMouseMoveWasSimulated) {
|
||||
_lastMouseMove = usecTimestampNow();
|
||||
}
|
||||
|
||||
if (!_aboutToQuit) {
|
||||
_entities.mouseMoveEvent(event, deviceID);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_entities.mouseMoveEvent(event, deviceID);
|
||||
|
||||
_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 (_controllerScriptingInterface.isMouseCaptured()) {
|
||||
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) {
|
||||
|
@ -2111,13 +2098,7 @@ void Application::updateMouseRay() {
|
|||
// make sure the frustum is up-to-date
|
||||
loadViewFrustum(_myCamera, _viewFrustum);
|
||||
|
||||
// if the mouse pointer isn't visible, act like it's at the center of the screen
|
||||
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);
|
||||
PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY());
|
||||
_mouseRayOrigin = pickRay.origin;
|
||||
_mouseRayDirection = pickRay.direction;
|
||||
|
||||
|
@ -2313,23 +2294,26 @@ void Application::updateCursor(float deltaTime) {
|
|||
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
|
||||
PerformanceWarning warn(showWarnings, "Application::updateCursor()");
|
||||
|
||||
// watch mouse position, if it hasn't moved, hide the cursor
|
||||
bool hideMouse = false;
|
||||
bool underMouse = _glWidget->underMouse();
|
||||
if (!_mouseHidden) {
|
||||
quint64 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;
|
||||
}
|
||||
|
||||
static const int HIDE_CURSOR_TIMEOUT = 1 * USECS_PER_SECOND; // 1 second
|
||||
int elapsed = usecTimestampNow() - _lastMouseMove;
|
||||
if ((elapsed > HIDE_CURSOR_TIMEOUT && underMouse) ||
|
||||
(OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) {
|
||||
hideMouse = true;
|
||||
}
|
||||
|
||||
if (hideMouse != isMouseHidden()) {
|
||||
setCursorVisible(!hideMouse);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::setCursorVisible(bool visible) {
|
||||
if (visible) {
|
||||
_glWidget->setCursor(Qt::ArrowCursor);
|
||||
} 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;
|
||||
}
|
||||
_glWidget->setCursor(Qt::BlankCursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
_controllerScriptingInterface.updateInputControllers();
|
||||
|
||||
|
@ -4372,14 +4345,6 @@ void Application::skipVersion(QString latestVersion) {
|
|||
skipFile.write(latestVersion.toStdString().c_str());
|
||||
}
|
||||
|
||||
void Application::setCursorVisible(bool visible) {
|
||||
if (visible) {
|
||||
restoreOverrideCursor();
|
||||
} else {
|
||||
setOverrideCursor(Qt::BlankCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::takeSnapshot() {
|
||||
QMediaPlayer* player = new QMediaPlayer();
|
||||
QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav");
|
||||
|
|
|
@ -211,7 +211,8 @@ public:
|
|||
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
|
||||
Environment* getEnvironment() { return &_environment; }
|
||||
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& getMouseRayDirection() const { return _mouseRayDirection; }
|
||||
bool mouseOnScreen() const;
|
||||
|
@ -309,8 +310,6 @@ public:
|
|||
|
||||
QStringList getRunningScripts() { return _scriptEnginesHash.keys(); }
|
||||
ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; }
|
||||
|
||||
void setCursorVisible(bool visible);
|
||||
|
||||
bool isLookingAtMyAvatar(Avatar* avatar);
|
||||
|
||||
|
@ -567,8 +566,6 @@ private:
|
|||
int _mouseDragStartedY;
|
||||
quint64 _lastMouseMove;
|
||||
bool _lastMouseMoveWasSimulated;
|
||||
bool _mouseHidden;
|
||||
bool _seenMouseMove;
|
||||
|
||||
glm::vec3 _mouseRayOrigin;
|
||||
glm::vec3 _mouseRayDirection;
|
||||
|
|
|
@ -122,21 +122,21 @@ void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) {
|
|||
if (hitLeft || hitRight) {
|
||||
_isResizing = true;
|
||||
_resizeInitialWidth = size().width();
|
||||
QApplication::setOverrideCursor(Qt::SizeHorCursor);
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
}
|
||||
} else {
|
||||
bool hitTop = (_position == POSITION_TOP) && (abs(mouseEvent->pos().y() - size().height()) < RESIZE_HANDLE_WIDTH);
|
||||
if (hitTop) {
|
||||
_isResizing = true;
|
||||
_resizeInitialWidth = size().height();
|
||||
QApplication::setOverrideCursor(Qt::SizeHorCursor);
|
||||
setCursor(Qt::SizeHorCursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessDialog::mouseReleaseEvent(QMouseEvent* mouseEvent) {
|
||||
QApplication::restoreOverrideCursor();
|
||||
unsetCursor();
|
||||
_isResizing = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue