all repos — mgba @ 928896f978c35578de13bed991ecfb028bbaf5b2

mGBA Game Boy Advance Emulator

Qt: Add mouse events
Vicki Pfau vi@endrift.com
Sat, 04 Mar 2017 12:35:52 -0800
commit

928896f978c35578de13bed991ecfb028bbaf5b2

parent

97f915e6173688e07ff6d8107bffda760e09dcdd

M src/platform/qt/Display.cppsrc/platform/qt/Display.cpp

@@ -88,8 +88,9 @@ forceDraw();

} } -void Display::mouseMoveEvent(QMouseEvent*) { +void Display::mouseMoveEvent(QMouseEvent* event) { emit showCursor(); m_mouseTimer.stop(); m_mouseTimer.start(); + event->ignore(); }
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -819,6 +819,20 @@ }

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;
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -133,6 +133,8 @@ void startRewinding();

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);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -684,11 +684,37 @@ event->accept();

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 @@ if (m_savedScale > 0) {

resizeFrame(QSize(width, height) * m_savedScale); } attachWidget(m_display); + setMouseTracking(true); #ifndef Q_OS_MAC if (isFullScreen()) {

@@ -789,6 +816,7 @@ m_display->setMinimumSize(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);

#endif m_screenWidget->setMinimumSize(m_display->minimumSize()); + setMouseTracking(false); m_fpsTimer.stop(); m_focusCheck.stop(); }
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -107,7 +107,9 @@ virtual void focusInEvent(QFocusEvent*) override;

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