diff --git a/src/platform/qt/Display.cpp b/src/platform/qt/Display.cpp index 506afe76b..211585f79 100644 --- a/src/platform/qt/Display.cpp +++ b/src/platform/qt/Display.cpp @@ -88,8 +88,9 @@ void Display::showMessage(const QString& message) { } } -void Display::mouseMoveEvent(QMouseEvent*) { +void Display::mouseMoveEvent(QMouseEvent* event) { emit showCursor(); m_mouseTimer.stop(); m_mouseTimer.start(); + event->ignore(); } diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 84f089cfd..754253c99 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -819,6 +819,20 @@ void GameController::keyReleased(int key) { updateKeys(); } +void GameController::cursorLocation(int x, int y) { + if (!isLoaded()) { + return; + } + m_threadContext.core->setCursorLocation(m_threadContext.core, x, y); +} + +void GameController::cursorDown(bool down) { + if (!isLoaded()) { + return; + } + m_threadContext.core->setCursorDown(m_threadContext.core, down); +} + void GameController::clearKeys() { m_activeKeys = 0; m_inactiveKeys = 0; diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index 7a3bfbecc..e1182063c 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -133,6 +133,8 @@ public slots: void stopRewinding(); void keyPressed(int key); void keyReleased(int key); + void cursorLocation(int x, int y); + void cursorDown(bool); void clearKeys(); void setAutofire(int key, bool enable); void setAudioBufferSamples(int samples); diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index b6867a346..9d0d39fff 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -684,11 +684,37 @@ void Window::dropEvent(QDropEvent* event) { m_controller->loadGame(url.toLocalFile()); } -void Window::mouseDoubleClickEvent(QMouseEvent* event) { +void Window::mouseMoveEvent(QMouseEvent* event) { + QSize dimensions = m_controller->screenDimensions(); + QSize screenDimensions = m_screenWidget->size(); + int x = dimensions.width() * event->x() / screenDimensions.width(); + int y = dimensions.height() * event->y() / screenDimensions.height(); + m_controller->cursorLocation(x, y); + event->accept(); +} + +void Window::mousePressEvent(QMouseEvent* event) { if (event->button() != Qt::LeftButton) { return; } - toggleFullScreen(); + QSize dimensions = m_controller->screenDimensions(); + QSize screenDimensions = m_screenWidget->size(); + int x = dimensions.width() * event->x() / screenDimensions.width(); + int y = dimensions.height() * event->y() / screenDimensions.height(); + m_controller->cursorLocation(x, y); + m_controller->cursorDown(true); +} + +void Window::mouseReleaseEvent(QMouseEvent* event) { + if (event->button() != Qt::LeftButton) { + return; + } + QSize dimensions = m_controller->screenDimensions(); + QSize screenDimensions = m_screenWidget->size(); + int x = dimensions.width() * event->x() / screenDimensions.width(); + int y = dimensions.height() * event->y() / screenDimensions.height(); + m_controller->cursorLocation(x, y); + m_controller->cursorDown(false); } void Window::enterFullScreen() { @@ -755,6 +781,7 @@ void Window::gameStarted(mCoreThread* context, const QString& fname) { resizeFrame(QSize(width, height) * m_savedScale); } attachWidget(m_display); + setMouseTracking(true); #ifndef Q_OS_MAC if (isFullScreen()) { @@ -789,6 +816,7 @@ void Window::gameStopped() { #endif m_screenWidget->setMinimumSize(m_display->minimumSize()); + setMouseTracking(false); m_fpsTimer.stop(); m_focusCheck.stop(); } diff --git a/src/platform/qt/Window.h b/src/platform/qt/Window.h index 37ef814df..a4f05f58c 100644 --- a/src/platform/qt/Window.h +++ b/src/platform/qt/Window.h @@ -107,7 +107,9 @@ protected: virtual void focusOutEvent(QFocusEvent*) override; virtual void dragEnterEvent(QDragEnterEvent*) override; virtual void dropEvent(QDropEvent*) override; - virtual void mouseDoubleClickEvent(QMouseEvent*) override; + virtual void mouseMoveEvent(QMouseEvent*) override; + virtual void mousePressEvent(QMouseEvent*) override; + virtual void mouseReleaseEvent(QMouseEvent*) override; private slots: void gameStarted(mCoreThread*, const QString&);