Skip to content

Commit

Permalink
RMG: hook up RMG-Core mouse functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed May 28, 2024
1 parent f6b0717 commit 7092859
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Source/RMG/UserInterface/EventFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ bool EventFilter::eventFilter(QObject *object, QEvent *event)
case QEvent::Type::KeyRelease:
emit this->on_EventFilter_KeyReleased((QKeyEvent *)event);
return true;
case QEvent::Type::MouseMove:
emit this->on_EventFilter_MouseMoved((QMouseEvent *)event);
return true;
case QEvent::Type::MouseButtonPress:
emit this->on_EventFilter_MouseButtonPressed((QMouseEvent *)event);
return true;
case QEvent::Type::MouseButtonRelease:
emit this->on_EventFilter_MouseButtonReleased((QMouseEvent *)event);
return true;
default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions Source/RMG/UserInterface/EventFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class EventFilter : public QObject
void on_EventFilter_KeyPressed(QKeyEvent *);
void on_EventFilter_KeyReleased(QKeyEvent *);

void on_EventFilter_MouseMoved(QMouseEvent *);
void on_EventFilter_MouseButtonPressed(QMouseEvent *);
void on_EventFilter_MouseButtonReleased(QMouseEvent *);

void on_EventFilter_FileDropped(QDropEvent *);
};
} // namespace UserInterface
Expand Down
44 changes: 44 additions & 0 deletions Source/RMG/UserInterface/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ void MainWindow::initializeUI(bool launchROM)
&MainWindow::on_EventFilter_KeyPressed);
connect(this->ui_EventFilter, &EventFilter::on_EventFilter_KeyReleased, this,
&MainWindow::on_EventFilter_KeyReleased);
connect(this->ui_EventFilter, &EventFilter::on_EventFilter_MouseMoved, this,
&MainWindow::on_EventFilter_MouseMoved);
connect(this->ui_EventFilter, &EventFilter::on_EventFilter_MouseButtonPressed, this,
&MainWindow::on_EventFilter_MouseButtonPressed);
connect(this->ui_EventFilter, &EventFilter::on_EventFilter_MouseButtonReleased, this,
&MainWindow::on_EventFilter_MouseButtonReleased);
connect(this->ui_EventFilter, &EventFilter::on_EventFilter_FileDropped, this,
&MainWindow::on_EventFilter_FileDropped);
}
Expand Down Expand Up @@ -1251,6 +1257,44 @@ void MainWindow::on_EventFilter_KeyReleased(QKeyEvent *event)
CoreSetKeyUp(key, mod);
}

#include <iostream>
void MainWindow::on_EventFilter_MouseMoved(QMouseEvent *event)
{
if (!CoreIsEmulationRunning())
{
QMainWindow::mouseMoveEvent(event);
return;
}

int x = event->position().x();
int y = event->position().y();

CoreSetMouseMove(x, y);

}

void MainWindow::on_EventFilter_MouseButtonPressed(QMouseEvent *event)
{
if (!CoreIsEmulationRunning())
{
QMainWindow::mouseMoveEvent(event);
return;
}

CoreSetMouseButton((event->button() == Qt::MouseButton::LeftButton ? 1 : 0), (event->button() == Qt::MouseButton::RightButton ? 1 : 0));
}

void MainWindow::on_EventFilter_MouseButtonReleased(QMouseEvent *event)
{
if (!CoreIsEmulationRunning())
{
QMainWindow::mouseMoveEvent(event);
return;
}

CoreSetMouseButton((event->button() == Qt::MouseButton::LeftButton ? 0 : 1), (event->button() == Qt::MouseButton::RightButton ? 0 : 1));
}

void MainWindow::on_EventFilter_FileDropped(QDropEvent *event)
{
#ifdef DRAG_DROP
Expand Down
3 changes: 3 additions & 0 deletions Source/RMG/UserInterface/MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
private slots:
void on_EventFilter_KeyPressed(QKeyEvent *event);
void on_EventFilter_KeyReleased(QKeyEvent *event);
void on_EventFilter_MouseMoved(QMouseEvent *event);
void on_EventFilter_MouseButtonPressed(QMouseEvent *event);
void on_EventFilter_MouseButtonReleased(QMouseEvent *event);
void on_EventFilter_FileDropped(QDropEvent *event);

void on_QGuiApplication_applicationStateChanged(Qt::ApplicationState state);
Expand Down

0 comments on commit 7092859

Please sign in to comment.