diff --git a/Source/3rdParty/mupen64plus-core/src/api/frontend.c b/Source/3rdParty/mupen64plus-core/src/api/frontend.c
index 38e88127..dbcd3c9c 100644
--- a/Source/3rdParty/mupen64plus-core/src/api/frontend.c
+++ b/Source/3rdParty/mupen64plus-core/src/api/frontend.c
@@ -323,6 +323,13 @@ EXPORT m64p_error CALL CoreDoCommand(m64p_command Command, int ParamInt, void *P
y = (ParamInt >> 16) & 0xffff;
event_mouse_move(x, y);
return M64ERR_SUCCESS;
+ case M64CMD_SET_MOUSE_BUTTON:
+ if (!g_EmulatorRunning)
+ return M64ERR_INVALID_STATE;
+ x = ParamInt & 0xffff;
+ y = (ParamInt >> 16) & 0xffff;
+ event_mouse_button(x, y);
+ return M64ERR_SUCCESS;
case M64CMD_SET_FRAME_CALLBACK:
*(void**)&g_FrameCallback = ParamPtr;
return M64ERR_SUCCESS;
diff --git a/Source/3rdParty/mupen64plus-core/src/api/m64p_plugin.h b/Source/3rdParty/mupen64plus-core/src/api/m64p_plugin.h
index 8940b599..8c945675 100644
--- a/Source/3rdParty/mupen64plus-core/src/api/m64p_plugin.h
+++ b/Source/3rdParty/mupen64plus-core/src/api/m64p_plugin.h
@@ -266,6 +266,7 @@ typedef void (*ptr_ReadController)(int Control, unsigned char *Command);
typedef void (*ptr_SDL_KeyDown)(int keymod, int keysym);
typedef void (*ptr_SDL_KeyUp)(int keymod, int keysym);
typedef void (*ptr_MouseMove)(int x, int y);
+typedef void (*ptr_MouseButton)(int left, int right);
typedef void (*ptr_RenderCallback)(void);
typedef void (*ptr_SendVRUWord)(uint16_t length, uint16_t *word, uint8_t lang);
typedef void (*ptr_SetMicState)(int state);
@@ -280,6 +281,7 @@ EXPORT void CALL ReadController(int Control, unsigned char *Command);
EXPORT void CALL SDL_KeyDown(int keymod, int keysym);
EXPORT void CALL SDL_KeyUp(int keymod, int keysym);
EXPORT void CALL MouseMove(int x, int y);
+EXPORT void CALL MouseButton(int left, int right);
EXPORT void CALL RenderCallback(void);
EXPORT void CALL SendVRUWord(uint16_t length, uint16_t *word, uint8_t lang);
EXPORT void CALL SetMicState(int state);
diff --git a/Source/3rdParty/mupen64plus-core/src/api/m64p_types.h b/Source/3rdParty/mupen64plus-core/src/api/m64p_types.h
index adbf41b8..8a59a9ea 100644
--- a/Source/3rdParty/mupen64plus-core/src/api/m64p_types.h
+++ b/Source/3rdParty/mupen64plus-core/src/api/m64p_types.h
@@ -172,7 +172,8 @@ typedef enum {
M64CMD_ROM_SET_SETTINGS,
M64CMD_DISK_OPEN,
M64CMD_DISK_CLOSE,
- M64CMD_SET_MOUSE_MOVE
+ M64CMD_SET_MOUSE_MOVE,
+ M64CMD_SET_MOUSE_BUTTON
} m64p_command;
typedef struct {
diff --git a/Source/3rdParty/mupen64plus-core/src/main/eventloop.c b/Source/3rdParty/mupen64plus-core/src/main/eventloop.c
index 032148b3..801ef20e 100644
--- a/Source/3rdParty/mupen64plus-core/src/main/eventloop.c
+++ b/Source/3rdParty/mupen64plus-core/src/main/eventloop.c
@@ -712,6 +712,15 @@ void event_mouse_move(int x, int y)
}
}
+void event_mouse_button(int left, int right)
+{
+ if (input.mouseButton != NULL)
+ {
+ input.mouseButton(left, right);
+ }
+}
+
+
int event_gameshark_active(void)
{
return GamesharkActive;
diff --git a/Source/3rdParty/mupen64plus-core/src/main/eventloop.h b/Source/3rdParty/mupen64plus-core/src/main/eventloop.h
index ef99f8c3..c8f5fe06 100644
--- a/Source/3rdParty/mupen64plus-core/src/main/eventloop.h
+++ b/Source/3rdParty/mupen64plus-core/src/main/eventloop.h
@@ -27,6 +27,7 @@ extern void event_initialize(void);
extern void event_sdl_keydown(int keysym, int keymod);
extern void event_sdl_keyup(int keysym, int keymod);
extern void event_mouse_move(int x, int y);
+extern void event_mouse_button(int left, int right);
extern int event_gameshark_active(void);
extern void event_set_gameshark(int active);
diff --git a/Source/3rdParty/mupen64plus-core/src/plugin/plugin.c b/Source/3rdParty/mupen64plus-core/src/plugin/plugin.c
index 4052ca85..e3122441 100644
--- a/Source/3rdParty/mupen64plus-core/src/plugin/plugin.c
+++ b/Source/3rdParty/mupen64plus-core/src/plugin/plugin.c
@@ -102,6 +102,7 @@ static const input_plugin_functions dummy_input = {
dummyinput_SDL_KeyDown,
dummyinput_SDL_KeyUp,
NULL,
+ NULL,
dummyinput_RenderCallback
};
@@ -404,7 +405,8 @@ static m64p_error plugin_connect_input(m64p_dynlib_handle plugin_handle)
DebugMessage(M64MSG_WARNING, "Input plugin does not contain VRU support.");
}
- if (!GET_FUNC(ptr_MouseMove, input.mouseMove, "MouseMove"))
+ if (!GET_FUNC(ptr_MouseMove, input.mouseMove, "MouseMove") ||
+ !GET_FUNC(ptr_MouseMove, input.mouseButton, "MouseButton"))
{
DebugMessage(M64MSG_WARNING, "Input plugin does not contain mouse support.");
}
diff --git a/Source/3rdParty/mupen64plus-core/src/plugin/plugin.h b/Source/3rdParty/mupen64plus-core/src/plugin/plugin.h
index 666ae25f..81ee7cca 100644
--- a/Source/3rdParty/mupen64plus-core/src/plugin/plugin.h
+++ b/Source/3rdParty/mupen64plus-core/src/plugin/plugin.h
@@ -101,6 +101,7 @@ typedef struct _input_plugin_functions
ptr_SDL_KeyDown keyDown;
ptr_SDL_KeyUp keyUp;
ptr_MouseMove mouseMove;
+ ptr_MouseButton mouseButton;
ptr_RenderCallback renderCallback;
ptr_SendVRUWord sendVRUWord;
ptr_SetMicState setMicState;
diff --git a/Source/RMG-Core/m64p/api/m64p_types.h b/Source/RMG-Core/m64p/api/m64p_types.h
index cb00b262..8a59a9ea 100644
--- a/Source/RMG-Core/m64p/api/m64p_types.h
+++ b/Source/RMG-Core/m64p/api/m64p_types.h
@@ -170,10 +170,10 @@ typedef enum {
M64CMD_NETPLAY_CLOSE,
M64CMD_PIF_OPEN,
M64CMD_ROM_SET_SETTINGS,
- M64CMD_SET_MOUSE_MOVE,
- M64CMD_SET_MOUSE_BUTTON,
M64CMD_DISK_OPEN,
- M64CMD_DISK_CLOSE
+ M64CMD_DISK_CLOSE,
+ M64CMD_SET_MOUSE_MOVE,
+ M64CMD_SET_MOUSE_BUTTON
} m64p_command;
typedef struct {
diff --git a/Source/RMG-Input/UserInterface/MainDialog.cpp b/Source/RMG-Input/UserInterface/MainDialog.cpp
index 37dd2cbb..68719ecd 100644
--- a/Source/RMG-Input/UserInterface/MainDialog.cpp
+++ b/Source/RMG-Input/UserInterface/MainDialog.cpp
@@ -73,6 +73,9 @@ MainDialog::MainDialog(QWidget* parent, Thread::SDLThread* sdlThread, bool romCo
controllerWidget->AddInputDevice("Voice Recognition Unit", (int)InputDeviceType::EmulateVRU);
}
#endif // VRU
+ // TODO: shouldn't this be specific to 1 port??
+ controllerWidget->AddInputDevice("Mouse", (int)InputDeviceType::Mouse);
+
controllerWidget->AddInputDevice("None", (int)InputDeviceType::None);
controllerWidget->AddInputDevice("Automatic", (int)InputDeviceType::Automatic);
controllerWidget->AddInputDevice("Keyboard", (int)InputDeviceType::Keyboard);
@@ -114,8 +117,9 @@ void MainDialog::openInputDevice(QString deviceName, int deviceNum)
Widget::ControllerWidget* controllerWidget;
controllerWidget = this->controllerWidgets.at(this->tabWidget->currentIndex());
- // we don't need to open a keyboard or VRU
+ // we don't need to open a mouse, keyboard or VRU
if (deviceNum == (int)InputDeviceType::None ||
+ deviceNum == (int)InputDeviceType::Mouse ||
deviceNum == (int)InputDeviceType::Keyboard ||
deviceNum == (int)InputDeviceType::EmulateVRU)
{
@@ -240,6 +244,7 @@ void MainDialog::on_ControllerWidget_CurrentInputDeviceChanged(ControllerWidget*
// only open device when needed
if (deviceNum != (int)InputDeviceType::None &&
+ deviceNum != (int)InputDeviceType::Mouse &&
deviceNum != (int)InputDeviceType::Keyboard &&
deviceNum != (int)InputDeviceType::EmulateVRU)
{
@@ -306,6 +311,7 @@ void MainDialog::on_tabWidget_currentChanged(int index)
// only open device when needed
if (deviceNum != (int)InputDeviceType::None &&
+ deviceNum != (int)InputDeviceType::Mouse &&
deviceNum != (int)InputDeviceType::Keyboard &&
deviceNum != (int)InputDeviceType::EmulateVRU)
{
diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.cpp
index 751409ae..4f330598 100644
--- a/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.cpp
+++ b/Source/RMG-Input/UserInterface/Widget/ControllerImageWidget.cpp
@@ -85,6 +85,7 @@ void ControllerImageWidget::SetMouseMode(bool value)
if (this->isMouseMode != value)
{
this->isMouseMode = value;
+ this->needImageUpdate = true;
}
}
diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp
index d768c1f5..2ef853e2 100644
--- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp
+++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.cpp
@@ -726,6 +726,7 @@ void ControllerWidget::on_inputDeviceComboBox_currentIndexChanged(int value)
int deviceNum = this->inputDeviceComboBox->itemData(value).toInt();
this->ClearControllerImage();
+ this->controllerImageWidget->SetMouseMode((deviceNum == (int)InputDeviceType::Mouse));
if (this->isCurrentDeviceNotFound())
{
@@ -1443,7 +1444,7 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event)
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{ // mouse button press
- if (this->inputTypeComboBox->currentIndex() != 1)
+ if (this->inputDeviceComboBox->currentIndex() != 0)
{ // no mouse
return;
}
@@ -1643,7 +1644,6 @@ void ControllerWidget::LoadSettings(QString sectionQString, bool loadUserProfile
}
this->deadZoneSlider->setValue(CoreSettingsGetIntValue(SettingsID::Input_Deadzone, section));
- this->inputTypeComboBox->setCurrentIndex(CoreSettingsGetIntValue(SettingsID::Input_InputType, section));
this->optionsDialogSettings.RemoveDuplicateMappings = CoreSettingsGetBoolValue(SettingsID::Input_RemoveDuplicateMappings, section);
this->optionsDialogSettings.ControllerPak = CoreSettingsGetIntValue(SettingsID::Input_Pak, section);
this->optionsDialogSettings.GameboyRom = CoreSettingsGetStringValue(SettingsID::Input_GameboyRom, section);
@@ -1699,9 +1699,6 @@ void ControllerWidget::LoadSettings(QString sectionQString, bool loadUserProfile
// force refresh some UI elements
this->CheckInputDeviceSettings(sectionQString);
-
- // TODO: is this correct?
- this->on_inputTypeComboBox_currentIndexChanged(this->inputTypeComboBox->currentIndex());
this->on_deadZoneSlider_valueChanged(this->deadZoneSlider->value());
this->setPluggedIn(this->IsPluggedIn());
}
@@ -1843,7 +1840,6 @@ void ControllerWidget::SaveSettings(QString section)
this->GetCurrentInputDevice(deviceName, deviceNum, true);
CoreSettingsSetValue(SettingsID::Input_PluggedIn, sectionStr, this->IsPluggedIn());
- CoreSettingsSetValue(SettingsID::Input_InputType, sectionStr, this->inputTypeComboBox->currentIndex());
CoreSettingsSetValue(SettingsID::Input_DeviceName, sectionStr, deviceName.toStdString());
CoreSettingsSetValue(SettingsID::Input_DeviceNum, sectionStr, deviceNum);
CoreSettingsSetValue(SettingsID::Input_Deadzone, sectionStr, this->deadZoneSlider->value());
diff --git a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.ui b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.ui
index fd0b1cc0..f01aa3d4 100644
--- a/Source/RMG-Input/UserInterface/Widget/ControllerWidget.ui
+++ b/Source/RMG-Input/UserInterface/Widget/ControllerWidget.ui
@@ -37,7 +37,7 @@
- QComboBox::AdjustToContents
+ QComboBox::SizeAdjustPolicy::AdjustToContents
@@ -73,7 +73,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -83,29 +83,6 @@
- -
-
-
- Device Type
-
-
-
-
-
-
-
-
- Controller
-
-
- -
-
- Mouse
-
-
-
-
-
-
-
-
@@ -127,7 +104,7 @@
- QComboBox::AdjustToContents
+ QComboBox::SizeAdjustPolicy::AdjustToContents
@@ -150,7 +127,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -181,10 +158,10 @@
100
- Qt::Horizontal
+ Qt::Orientation::Horizontal
- QSlider::TicksBelow
+ QSlider::TickPosition::TicksBelow
10
@@ -201,7 +178,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -216,7 +193,7 @@
-
- Qt::Vertical
+ Qt::Orientation::Vertical
@@ -648,10 +625,10 @@
100
- Qt::Horizontal
+ Qt::Orientation::Horizontal
- QSlider::TicksBelow
+ QSlider::TickPosition::TicksBelow
15
@@ -664,7 +641,7 @@
-
- Qt::Vertical
+ Qt::Orientation::Vertical
@@ -686,7 +663,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -729,7 +706,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -776,7 +753,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -809,7 +786,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -857,7 +834,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -905,7 +882,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
@@ -924,7 +901,7 @@
-
- Qt::Vertical
+ Qt::Orientation::Vertical
@@ -1253,7 +1230,7 @@
-
- Qt::Vertical
+ Qt::Orientation::Vertical
@@ -1289,7 +1266,7 @@
-
- Qt::Horizontal
+ Qt::Orientation::Horizontal
diff --git a/Source/RMG-Input/main.cpp b/Source/RMG-Input/main.cpp
index a5fae1bd..ed25d61d 100644
--- a/Source/RMG-Input/main.cpp
+++ b/Source/RMG-Input/main.cpp
@@ -1245,7 +1245,8 @@ EXPORT void CALL GetKeys(int Control, BUTTONS* Keys)
{
profile->LastDeviceCheckTime = currentTime;
- if (profile->DeviceNum != (int)InputDeviceType::Keyboard)
+ if (profile->DeviceNum != (int)InputDeviceType::Mouse &&
+ profile->DeviceNum != (int)InputDeviceType::Keyboard)
{
if (profile->InputDevice.IsOpeningDevice())
{
@@ -1285,7 +1286,7 @@ EXPORT void CALL GetKeys(int Control, BUTTONS* Keys)
if (Control == 0)
{
// mouse
- if (profile->DeviceType == InputDeviceType::Mouse)
+ if (profile->DeviceNum == (int)InputDeviceType::Mouse)
{ // n64 mouse
l_MouseMutex.lock();
@@ -1296,24 +1297,20 @@ EXPORT void CALL GetKeys(int Control, BUTTONS* Keys)
if (!l_MouseMovements.empty())
{
// calculate how much the mouse has moved
- const int x = l_MouseMovements.front().x - l_MouseMovements.back().x;
- const int y = l_MouseMovements.front().y - l_MouseMovements.back().y;
+ // TODO: sensitivity
+ const int x = (l_MouseMovements.back().x - l_MouseMovements.front().x) * 5;
+ const int y = (l_MouseMovements.front().y - l_MouseMovements.back().y) * 5;
// set axis state
- Keys->X_AXIS = -x;
- Keys->Y_AXIS = y;
+
+ // TODO: is this clamping correct?
+ Keys->X_AXIS = x < 0 ? std::max(x, -N64_AXIS_PEAK) : std::min(x, N64_AXIS_PEAK);;
+ Keys->Y_AXIS = y < 0 ? std::max(y, -N64_AXIS_PEAK) : std::min(y, N64_AXIS_PEAK);
l_MouseMovements.clear();
}
l_MouseMutex.unlock();
-
- // request front-end to reset mouse position
- if (l_ResetMousPositionCallback != nullptr)
- {
- l_ResetMousPositionCallback();
- }
-
return;
}
}
@@ -1417,14 +1414,21 @@ EXPORT void CALL SDL_KeyUp(int keymod, int keysym)
EXPORT void CALL MouseMove(int x, int y)
{
- l_MouseMutex.lock();
+ if (!l_MouseMutex.try_lock())
+ {
+ return;
+ }
l_MouseMovements.push_back({x, y});
l_MouseMutex.unlock();
}
EXPORT void CALL MouseButton(int left, int right)
{
- l_MouseMutex.lock();
+ if (!l_MouseMutex.try_lock())
+ {
+ return;
+ }
+ std::cout << "MouseButton" << std::endl;
l_MouseButtonState[0] = left;
l_MouseButtonState[1] = right;
l_MouseMutex.unlock();
diff --git a/Source/RMG/Callbacks.hpp b/Source/RMG/Callbacks.hpp
index 67ade9c5..c852162c 100644
--- a/Source/RMG/Callbacks.hpp
+++ b/Source/RMG/Callbacks.hpp
@@ -50,10 +50,6 @@ class CoreCallbacks : public QObject
signals:
void OnCoreDebugCallback(QList callbackMessages);
void OnCoreStateCallback(CoreStateCallbackType type, int value);
-
-signals:
- void OnCoreDebugCallback(CoreDebugMessageType type, QString context, QString message);
- void OnResetMousePositionCallback(void);
};
#endif // RMG_CALLBACKS_HPP
diff --git a/Source/RMG/UserInterface/MainWindow.cpp b/Source/RMG/UserInterface/MainWindow.cpp
index 8617e98e..11f96055 100644
--- a/Source/RMG/UserInterface/MainWindow.cpp
+++ b/Source/RMG/UserInterface/MainWindow.cpp
@@ -90,7 +90,7 @@ bool MainWindow::Init(QApplication* app, bool showUI, bool launchROM)
this->coreCallBacks = new CoreCallbacks(this);
// connect signals early due to pending debug callbacks
- //connect(coreCallBacks, &CoreCallbacks::OnCoreDebugCallback, this, &MainWindow::on_Core_DebugCallback);
+ connect(coreCallBacks, &CoreCallbacks::OnCoreDebugCallback, this, &MainWindow::on_Core_DebugCallback);
connect(coreCallBacks, &CoreCallbacks::OnCoreStateCallback, this, &MainWindow::on_Core_StateCallback);
connect(app, &QGuiApplication::applicationStateChanged, this, &MainWindow::on_QGuiApplication_applicationStateChanged);
@@ -1316,13 +1316,13 @@ void MainWindow::on_EventFilter_MouseMoved(QMouseEvent *event)
return;
}
- int x = event->globalPosition().x();
- int y = event->globalPosition().y();
+ int x = event->position().x();
+ int y = event->position().y();
CoreSetMouseMove(x, y);
-
}
+#include
void MainWindow::on_EventFilter_MouseButtonPressed(QMouseEvent *event)
{
if (!CoreIsEmulationRunning())
@@ -1334,6 +1334,8 @@ void MainWindow::on_EventFilter_MouseButtonPressed(QMouseEvent *event)
this->ui_LeftMouseButtonState = (event->button() == Qt::MouseButton::LeftButton ? 1 : this->ui_LeftMouseButtonState);
this->ui_RightMouseButtonState = (event->button() == Qt::MouseButton::RightButton ? 1 : this->ui_RightMouseButtonState);
+ std::cout << "on_EventFilter_MouseButtonPressed" << std::endl;
+
CoreSetMouseButton(this->ui_LeftMouseButtonState, this->ui_RightMouseButtonState);
}
@@ -1347,6 +1349,7 @@ void MainWindow::on_EventFilter_MouseButtonReleased(QMouseEvent *event)
this->ui_LeftMouseButtonState = (event->button() == Qt::MouseButton::LeftButton ? 0 : this->ui_LeftMouseButtonState);
this->ui_RightMouseButtonState = (event->button() == Qt::MouseButton::RightButton ? 0 : this->ui_RightMouseButtonState);
+ std::cout << "on_EventFilter_MouseButtonReleased" << std::endl;
CoreSetMouseButton(this->ui_LeftMouseButtonState, this->ui_RightMouseButtonState);
}