Qt: Add mouse events

This commit is contained in:
Vicki Pfau 2017-03-04 12:35:52 -08:00
parent 97f915e617
commit 928896f978
5 changed files with 51 additions and 4 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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);

View File

@ -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();
}

View File

@ -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&);