mirror of
https://github.com/Rosalie241/RMG.git
synced 2026-07-11 17:44:02 +02:00
Compare commits
11 Commits
windowsize
...
n64-mouse
| Author | SHA1 | Date | |
|---|---|---|---|
| cc701cc170 | |||
| ef28d45075 | |||
| 04f2ed62f3 | |||
| 78945b3742 | |||
| 28b4a1a307 | |||
| 84b7f6944b | |||
| 8826c6a05a | |||
| 5eca7d7d75 | |||
| 65fae11517 | |||
| c16fbef16e | |||
| 6746def849 |
@@ -169,6 +169,7 @@ EXPORT m64p_error CALL CoreDoCommand(m64p_command Command, int ParamInt, void *P
|
||||
{
|
||||
m64p_error rval;
|
||||
int keysym, keymod;
|
||||
int x, y;
|
||||
|
||||
if (!l_CoreInit)
|
||||
return M64ERR_NOT_INIT;
|
||||
@@ -315,6 +316,20 @@ EXPORT m64p_error CALL CoreDoCommand(m64p_command Command, int ParamInt, void *P
|
||||
keymod = (ParamInt >> 16) & 0xffff;
|
||||
event_sdl_keyup(keysym, keymod);
|
||||
return M64ERR_SUCCESS;
|
||||
case M64CMD_SET_MOUSE_MOVE:
|
||||
if (!g_EmulatorRunning)
|
||||
return M64ERR_INVALID_STATE;
|
||||
x = ParamInt & 0xffff;
|
||||
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;
|
||||
|
||||
@@ -139,6 +139,7 @@ typedef struct {
|
||||
/*** Controller types ****/
|
||||
#define CONT_TYPE_STANDARD 0
|
||||
#define CONT_TYPE_VRU 1
|
||||
#define CONT_TYPE_MOUSE 2
|
||||
|
||||
typedef struct {
|
||||
int Present;
|
||||
@@ -264,6 +265,8 @@ typedef void (*ptr_InitiateControllers)(CONTROL_INFO ControlInfo);
|
||||
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);
|
||||
@@ -277,6 +280,8 @@ EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo);
|
||||
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);
|
||||
|
||||
+3
-1
@@ -171,7 +171,9 @@ typedef enum {
|
||||
M64CMD_PIF_OPEN,
|
||||
M64CMD_ROM_SET_SETTINGS,
|
||||
M64CMD_DISK_OPEN,
|
||||
M64CMD_DISK_CLOSE
|
||||
M64CMD_DISK_CLOSE,
|
||||
M64CMD_SET_MOUSE_MOVE,
|
||||
M64CMD_SET_MOUSE_BUTTON
|
||||
} m64p_command;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -704,6 +704,23 @@ void event_sdl_keyup(int keysym, int keymod)
|
||||
}
|
||||
}
|
||||
|
||||
void event_mouse_move(int x, int y)
|
||||
{
|
||||
if (input.mouseMove != NULL)
|
||||
{
|
||||
input.mouseMove(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void event_mouse_button(int left, int right)
|
||||
{
|
||||
if (input.mouseButton != NULL)
|
||||
{
|
||||
input.mouseButton(left, right);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int event_gameshark_active(void)
|
||||
{
|
||||
return GamesharkActive;
|
||||
|
||||
@@ -26,6 +26,8 @@ extern int event_set_core_defaults(void);
|
||||
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);
|
||||
|
||||
|
||||
+7
-6
@@ -1778,12 +1778,13 @@ m64p_error main_run(void)
|
||||
}
|
||||
/* otherwise let the core do the processing */
|
||||
else {
|
||||
/* select appropriate controller
|
||||
* FIXME: assume for now that only standard controller is compatible
|
||||
* Use the rom db to know if other peripherals are compatibles (VRU, mouse, train, ...)
|
||||
*/
|
||||
const struct game_controller_flavor* cont_flavor =
|
||||
&g_standard_controller_flavor;
|
||||
const struct game_controller_flavor* cont_flavor;
|
||||
|
||||
if (Controls[i].Type == CONT_TYPE_MOUSE) {
|
||||
cont_flavor = &g_mouse_controller_flavor;
|
||||
} else {
|
||||
cont_flavor = &g_standard_controller_flavor;
|
||||
}
|
||||
|
||||
joybus_devices[i] = &g_dev.controllers[i];
|
||||
ijoybus_devices[i] = &g_ijoybus_device_controller;
|
||||
|
||||
@@ -101,6 +101,8 @@ static const input_plugin_functions dummy_input = {
|
||||
dummyinput_RomOpen,
|
||||
dummyinput_SDL_KeyDown,
|
||||
dummyinput_SDL_KeyUp,
|
||||
NULL,
|
||||
NULL,
|
||||
dummyinput_RenderCallback
|
||||
};
|
||||
|
||||
@@ -403,6 +405,12 @@ 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") ||
|
||||
!GET_FUNC(ptr_MouseMove, input.mouseButton, "MouseButton"))
|
||||
{
|
||||
DebugMessage(M64MSG_WARNING, "Input plugin does not contain mouse support.");
|
||||
}
|
||||
|
||||
/* check the version info */
|
||||
(*input.getVersion)(&PluginType, &PluginVersion, &APIVersion, NULL, NULL);
|
||||
if (PluginType != M64PLUGIN_INPUT || (APIVersion & 0xffff0000) != (INPUT_API_VERSION & 0xffff0000) || APIVersion < 0x020100)
|
||||
|
||||
@@ -100,6 +100,8 @@ typedef struct _input_plugin_functions
|
||||
ptr_RomOpen romOpen;
|
||||
ptr_SDL_KeyDown keyDown;
|
||||
ptr_SDL_KeyUp keyUp;
|
||||
ptr_MouseMove mouseMove;
|
||||
ptr_MouseButton mouseButton;
|
||||
ptr_RenderCallback renderCallback;
|
||||
ptr_SendVRUWord sendVRUWord;
|
||||
ptr_SetMicState setMicState;
|
||||
|
||||
@@ -50,6 +50,7 @@ set(RMG_CORE_SOURCES
|
||||
VidExt.cpp
|
||||
Video.cpp
|
||||
Error.cpp
|
||||
Mouse.cpp
|
||||
Unzip.cpp
|
||||
Core.cpp
|
||||
Key.cpp
|
||||
|
||||
@@ -33,7 +33,7 @@ static std::function<void(enum CoreDebugMessageType, std::string, std::string)>
|
||||
static std::function<void(enum CoreStateCallbackType, int)> l_StateCallbackFunc;
|
||||
static bool l_PrintCallbacks = false;
|
||||
static std::vector<l_DebugCallbackMessage> l_PendingCallbacks;
|
||||
|
||||
static std::function<void(void)> l_ResetMousePositionCallbackFunc;
|
||||
|
||||
//
|
||||
// Internal Functions
|
||||
@@ -78,6 +78,16 @@ void CoreStateCallback(void* context, m64p_core_param param, int value)
|
||||
l_StateCallbackFunc((CoreStateCallbackType)param, value);
|
||||
}
|
||||
|
||||
void ResetMousePositionCallback(void)
|
||||
{
|
||||
if (!l_SetupCallbacks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
l_ResetMousePositionCallbackFunc();
|
||||
}
|
||||
|
||||
//
|
||||
// Exported Functions
|
||||
//
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
void CoreDebugCallback(void* context, int level, const char* message);
|
||||
void CoreStateCallback(void* context, m64p_core_param param, int value);
|
||||
|
||||
void ResetMousePositionCallback(void);
|
||||
|
||||
#endif // CORE_INTERNAL
|
||||
|
||||
enum class CoreDebugMessageType
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "Volume.hpp"
|
||||
#include "Error.hpp"
|
||||
#include "Unzip.hpp"
|
||||
#include "Mouse.hpp"
|
||||
#include "Video.hpp"
|
||||
#include "Key.hpp"
|
||||
#include "Rom.hpp"
|
||||
|
||||
@@ -27,7 +27,7 @@ bool CoreSetKeyUp(int key, int mod)
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = m64p::Core.DoCommand(M64CMD_SEND_SDL_KEYUP, (mod << 16) + key, NULL);
|
||||
ret = m64p::Core.DoCommand(M64CMD_SEND_SDL_KEYUP, (mod << 16) + key, nullptr);
|
||||
if (ret != M64ERR_SUCCESS)
|
||||
{
|
||||
error = "CoreSetKeyUp M64P::Core.DoCommand(M64CMD_SEND_SDL_KEYUP) Failed: ";
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
|
||||
* Copyright (C) 2020 Rosalie Wanders <rosalie@mailbox.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 3.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "Key.hpp"
|
||||
#include "Error.hpp"
|
||||
#include "m64p/Api.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
//
|
||||
// Exported Functions
|
||||
//
|
||||
|
||||
bool CoreSetMouseMove(int x, int y)
|
||||
{
|
||||
std::string error;
|
||||
m64p_error ret;
|
||||
|
||||
if (!m64p::Core.IsHooked())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = m64p::Core.DoCommand(M64CMD_SET_MOUSE_MOVE, (y << 16) + x, nullptr);
|
||||
if (ret != M64ERR_SUCCESS)
|
||||
{
|
||||
error = "CoreSetMouseMove M64P::Core.DoCommand(M64CMD_SET_MOUSE_MOVE) Failed: ";
|
||||
error += m64p::Core.ErrorMessage(ret);
|
||||
CoreSetError(error);
|
||||
}
|
||||
|
||||
return ret == M64ERR_SUCCESS;
|
||||
}
|
||||
|
||||
bool CoreSetMouseButton(int left, int right)
|
||||
{
|
||||
std::string error;
|
||||
m64p_error ret;
|
||||
|
||||
if (!m64p::Core.IsHooked())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = m64p::Core.DoCommand(M64CMD_SET_MOUSE_BUTTON, (right << 16) + left, nullptr);
|
||||
if (ret != M64ERR_SUCCESS)
|
||||
{
|
||||
error = "CoreSetMouseMove M64P::Core.DoCommand(M64CMD_SET_MOUSE_MOVE) Failed: ";
|
||||
error += m64p::Core.ErrorMessage(ret);
|
||||
CoreSetError(error);
|
||||
}
|
||||
|
||||
return ret == M64ERR_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
|
||||
* Copyright (C) 2020 Rosalie Wanders <rosalie@mailbox.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 3.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CORE_MOUSE_HPP
|
||||
#define CORE_MOUSE_HPP
|
||||
|
||||
// sets mouse movement
|
||||
bool CoreSetMouseMove(int x, int y);
|
||||
|
||||
// sets mouse buttons
|
||||
bool CoreSetMouseButton(int left, int right);
|
||||
|
||||
#endif // CORE_MOUSE_HPP
|
||||
@@ -615,6 +615,9 @@ static l_Setting get_setting(SettingsID settingId)
|
||||
case SettingsID::Input_PluggedIn:
|
||||
setting = {"", "PluggedIn"};
|
||||
break;
|
||||
case SettingsID::Input_InputType:
|
||||
setting = {"", "InputType"};
|
||||
break;
|
||||
case SettingsID::Input_DeviceType:
|
||||
setting = {"", "DeviceType"};
|
||||
break;
|
||||
|
||||
@@ -201,6 +201,7 @@ enum class SettingsID
|
||||
Input_UseProfile,
|
||||
Input_UseGameProfile,
|
||||
Input_PluggedIn,
|
||||
Input_InputType,
|
||||
Input_DeviceType,
|
||||
Input_DeviceName,
|
||||
Input_DeviceNum,
|
||||
|
||||
@@ -30,6 +30,8 @@ bool PluginApi::Hook(m64p_dynlib_handle handle)
|
||||
HOOK_FUNC_OPT(handle, Plugin, Config);
|
||||
HOOK_FUNC_OPT(handle, Plugin, Config2);
|
||||
HOOK_FUNC_OPT(handle, Plugin, Config2HasRomConfig);
|
||||
|
||||
HOOK_FUNC_OPT(handle, , SetResetMousePositionCallback);
|
||||
HOOK_FUNC(handle, Plugin, GetVersion);
|
||||
|
||||
this->handle = handle;
|
||||
@@ -44,6 +46,7 @@ bool PluginApi::Unhook(void)
|
||||
UNHOOK_FUNC(Plugin, Config);
|
||||
UNHOOK_FUNC(Plugin, Config2);
|
||||
UNHOOK_FUNC(Plugin, Config2HasRomConfig);
|
||||
UNHOOK_FUNC( , SetResetMousePositionCallback);
|
||||
UNHOOK_FUNC(Plugin, GetVersion);
|
||||
|
||||
this->handle = nullptr;
|
||||
|
||||
@@ -36,6 +36,7 @@ class PluginApi
|
||||
ptr_PluginConfig Config;
|
||||
ptr_PluginConfig2 Config2;
|
||||
ptr_PluginConfig2HasRomConfig Config2HasRomConfig;
|
||||
ptr_SetResetMousePositionCallback SetResetMousePositionCallback;
|
||||
ptr_PluginGetVersion GetVersion;
|
||||
|
||||
private:
|
||||
|
||||
@@ -15,7 +15,7 @@ extern "C" {
|
||||
* This optional function opens a configuration GUI for the plugin
|
||||
* https://github.com/mupen64plus/mupen64plus-core/pull/774
|
||||
*
|
||||
*/
|
||||
*/
|
||||
typedef m64p_error (*ptr_PluginConfig)(void);
|
||||
#if defined(M64P_PLUGIN_PROTOTYPES) || defined(M64P_CORE_PROTOTYPES)
|
||||
EXPORT m64p_error CALL PluginConfig(void);
|
||||
@@ -44,8 +44,20 @@ typedef int (*ptr_PluginConfig2HasRomConfig)(void);
|
||||
EXPORT int CALL PluginConfig2HasRomConfig(void);
|
||||
#endif
|
||||
|
||||
/* SetResetMousePositionCallback()
|
||||
*
|
||||
* This optional input plugin function sets a callback for when
|
||||
* the cursor needs to be reset to the initial position (every time GetKeys() is called)
|
||||
*
|
||||
*/
|
||||
typedef void (*ptr_ResetMousePositionCallback)(void);
|
||||
typedef void (*ptr_SetResetMousePositionCallback)(ptr_ResetMousePositionCallback);
|
||||
#if defined(M64P_PLUGIN_PROTOTYPES) || defined(M64P_CORE_PROTOTYPES)
|
||||
EXPORT void CALL SetResetMousePositionCallback(ptr_ResetMousePositionCallback);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // M64P_CUSTOM_H
|
||||
#endif // M64P_CUSTOM_H
|
||||
@@ -139,6 +139,7 @@ typedef struct {
|
||||
/*** Controller types ****/
|
||||
#define CONT_TYPE_STANDARD 0
|
||||
#define CONT_TYPE_VRU 1
|
||||
#define CONT_TYPE_MOUSE 2
|
||||
|
||||
typedef struct {
|
||||
int Present;
|
||||
@@ -264,6 +265,8 @@ typedef void (*ptr_InitiateControllers)(CONTROL_INFO ControlInfo);
|
||||
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);
|
||||
@@ -277,6 +280,8 @@ EXPORT void CALL InitiateControllers(CONTROL_INFO ControlInfo);
|
||||
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);
|
||||
|
||||
@@ -171,7 +171,9 @@ typedef enum {
|
||||
M64CMD_PIF_OPEN,
|
||||
M64CMD_ROM_SET_SETTINGS,
|
||||
M64CMD_DISK_OPEN,
|
||||
M64CMD_DISK_CLOSE
|
||||
M64CMD_DISK_CLOSE,
|
||||
M64CMD_SET_MOUSE_MOVE,
|
||||
M64CMD_SET_MOUSE_BUTTON
|
||||
} m64p_command;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -29,6 +29,12 @@ bool EventFilter::eventFilter(QObject *object, QEvent *event)
|
||||
case QEvent::Type::KeyRelease:
|
||||
emit this->on_EventFilter_KeyReleased((QKeyEvent *)event);
|
||||
return true;
|
||||
case QEvent::Type::MouseButtonPress:
|
||||
emit this->on_EventFilter_MouseButtonPressed((QMouseEvent *)event);
|
||||
break;
|
||||
case QEvent::Type::MouseButtonRelease:
|
||||
emit this->on_EventFilter_MouseButtonReleased((QMouseEvent *)event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ class EventFilter : public QObject
|
||||
signals:
|
||||
void on_EventFilter_KeyPressed(QKeyEvent *);
|
||||
void on_EventFilter_KeyReleased(QKeyEvent *);
|
||||
|
||||
void on_EventFilter_MouseButtonPressed(QMouseEvent *);
|
||||
void on_EventFilter_MouseButtonReleased(QMouseEvent *);
|
||||
};
|
||||
} // namespace UserInterface
|
||||
|
||||
|
||||
@@ -36,6 +36,11 @@ MainDialog::MainDialog(QWidget* parent, Thread::SDLThread* sdlThread, bool romCo
|
||||
&MainDialog::on_EventFilter_KeyPressed);
|
||||
connect(this->eventFilter, &EventFilter::on_EventFilter_KeyReleased, this,
|
||||
&MainDialog::on_EventFilter_KeyReleased);
|
||||
connect(this->eventFilter, &EventFilter::on_EventFilter_MouseButtonPressed, this,
|
||||
&MainDialog::on_EventFilter_MouseButtonPressed);
|
||||
connect(this->eventFilter, &EventFilter::on_EventFilter_MouseButtonReleased, this,
|
||||
&MainDialog::on_EventFilter_MouseButtonReleased);
|
||||
|
||||
|
||||
// each tab needs its own ControllerWidget
|
||||
for (int i = 0; i < this->tabWidget->count(); i++)
|
||||
@@ -68,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);
|
||||
@@ -109,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)
|
||||
{
|
||||
@@ -235,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)
|
||||
{
|
||||
@@ -301,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)
|
||||
{
|
||||
@@ -385,6 +396,47 @@ void MainDialog::on_EventFilter_KeyReleased(QKeyEvent *event)
|
||||
SDL_PeepEvents(&sdlEvent, 1, SDL_ADDEVENT, 0, 0);
|
||||
}
|
||||
|
||||
void MainDialog::on_EventFilter_MouseButtonPressed(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::MouseButton::LeftButton &&
|
||||
event->button() != Qt::MouseButton::RightButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_MouseButtonEvent mouseButtonEvent;
|
||||
mouseButtonEvent.button = (event->button() == Qt::MouseButton::LeftButton) ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT;
|
||||
mouseButtonEvent.state = SDL_PRESSED;
|
||||
mouseButtonEvent.clicks = 1;
|
||||
|
||||
SDL_Event sdlEvent;
|
||||
sdlEvent.button = mouseButtonEvent;
|
||||
sdlEvent.type = SDL_MOUSEBUTTONDOWN;
|
||||
|
||||
SDL_PeepEvents(&sdlEvent, 1, SDL_ADDEVENT, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
void MainDialog::on_EventFilter_MouseButtonReleased(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() != Qt::MouseButton::LeftButton &&
|
||||
event->button() != Qt::MouseButton::RightButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_MouseButtonEvent mouseButtonEvent;
|
||||
mouseButtonEvent.button = (event->button() == Qt::MouseButton::LeftButton) ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT;
|
||||
mouseButtonEvent.state = SDL_RELEASED;
|
||||
mouseButtonEvent.clicks = 1;
|
||||
|
||||
SDL_Event sdlEvent;
|
||||
sdlEvent.button = mouseButtonEvent;
|
||||
sdlEvent.type = SDL_MOUSEBUTTONUP;
|
||||
|
||||
SDL_PeepEvents(&sdlEvent, 1, SDL_ADDEVENT, 0, 0);
|
||||
}
|
||||
|
||||
void MainDialog::accept(void)
|
||||
{
|
||||
Widget::ControllerWidget* controllerWidget;
|
||||
|
||||
@@ -80,6 +80,9 @@ private slots:
|
||||
void on_EventFilter_KeyPressed(QKeyEvent *);
|
||||
void on_EventFilter_KeyReleased(QKeyEvent *);
|
||||
|
||||
void on_EventFilter_MouseButtonPressed(QMouseEvent *);
|
||||
void on_EventFilter_MouseButtonReleased(QMouseEvent *);
|
||||
|
||||
void accept(void) Q_DECL_OVERRIDE;
|
||||
void reject(void) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 16 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 17 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 17 KiB |
@@ -16,6 +16,9 @@
|
||||
<file>Resource/Controller_Pressed_LeftTrigger.svg</file>
|
||||
<file>Resource/Controller_Pressed_RightTrigger.svg</file>
|
||||
<file>Resource/Controller_Pressed_ZTrigger.svg</file>
|
||||
<file>Resource/Mouse.svg</file>
|
||||
<file>Resource/Mouse_Pressed_Left.svg</file>
|
||||
<file>Resource/Mouse_Pressed_Right.svg</file>
|
||||
<file>Resource/RMG.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -26,11 +26,20 @@ ControllerImageWidget::~ControllerImageWidget()
|
||||
|
||||
}
|
||||
|
||||
void ControllerImageWidget::SetButtonState(enum N64ControllerButton button, bool state)
|
||||
void ControllerImageWidget::SetControllerButtonState(enum N64ControllerButton button, bool state)
|
||||
{
|
||||
if (this->buttonState[(int)button] != state)
|
||||
if (this->controllerButtonState[(int)button] != state)
|
||||
{
|
||||
this->buttonState[(int)button] = state;
|
||||
this->controllerButtonState[(int)button] = state;
|
||||
this->needImageUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerImageWidget::SetMouseButtonState(enum N64MouseButton button, bool state)
|
||||
{
|
||||
if (this->mouseButtonState[(int)button] != state)
|
||||
{
|
||||
this->mouseButtonState[(int)button] = state;
|
||||
this->needImageUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -71,14 +80,33 @@ void ControllerImageWidget::SetSensitivity(int value)
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerImageWidget::SetMouseMode(bool value)
|
||||
{
|
||||
if (this->isMouseMode != value)
|
||||
{
|
||||
this->isMouseMode = value;
|
||||
this->needImageUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerImageWidget::ClearControllerState()
|
||||
{
|
||||
// reset button state
|
||||
// reset controller button state
|
||||
for (int i = 0; i < (int)N64ControllerButton::Invalid; i++)
|
||||
{
|
||||
if (this->buttonState[i])
|
||||
if (this->controllerButtonState[i])
|
||||
{
|
||||
this->buttonState[i] = false;
|
||||
this->controllerButtonState[i] = false;
|
||||
this->needImageUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
// reset mouse button state
|
||||
for (int i = 0; i < (int)N64MouseButton::Invalid; i++)
|
||||
{
|
||||
if (this->mouseButtonState[i])
|
||||
{
|
||||
this->mouseButtonState[i] = false;
|
||||
this->needImageUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -119,7 +147,7 @@ void ControllerImageWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
enum N64ControllerButton button;
|
||||
QString imageUri;
|
||||
} buttons[] =
|
||||
} controllerButtons[] =
|
||||
{
|
||||
{ N64ControllerButton::A, ":Resource/Controller_Pressed_A.svg" },
|
||||
{ N64ControllerButton::B, ":Resource/Controller_Pressed_B.svg" },
|
||||
@@ -137,23 +165,57 @@ void ControllerImageWidget::paintEvent(QPaintEvent *event)
|
||||
{ N64ControllerButton::ZTrigger, ":Resource/Controller_Pressed_ZTrigger.svg" }
|
||||
};
|
||||
|
||||
static const QString baseImageUri = ":Resource/Controller_NoAnalogStick.svg";
|
||||
static const struct
|
||||
{
|
||||
enum N64MouseButton button;
|
||||
QString imageUri;
|
||||
} mouseButtons[] =
|
||||
{
|
||||
{ N64MouseButton::Left, ":Resource/Mouse_Pressed_Left.svg" },
|
||||
{ N64MouseButton::Right, ":Resource/Mouse_Pressed_Right.svg" },
|
||||
};
|
||||
|
||||
static const QString baseControllerImageUri = ":Resource/Controller_NoAnalogStick.svg";
|
||||
static const QString baseMouseImageUri = ":Resource/Mouse.svg";
|
||||
static const QString analogStickImageUri = ":Resource/Controller_AnalogStick.svg";
|
||||
|
||||
// render base image first
|
||||
renderer.load(baseImageUri);
|
||||
if (this->isMouseMode)
|
||||
{
|
||||
renderer.load(baseMouseImageUri);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer.load(baseControllerImageUri);
|
||||
}
|
||||
renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatio);
|
||||
renderer.render(&painter);
|
||||
|
||||
// render button images on top
|
||||
// when the button is pressed
|
||||
for (auto& button : buttons)
|
||||
if (this->isMouseMode)
|
||||
{
|
||||
if (this->buttonState[(int)button.button])
|
||||
for (auto& button : mouseButtons)
|
||||
{
|
||||
renderer.load(button.imageUri);
|
||||
renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatio);
|
||||
renderer.render(&painter);
|
||||
if (this->mouseButtonState[(int)button.button])
|
||||
{
|
||||
renderer.load(button.imageUri);
|
||||
renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatio);
|
||||
renderer.render(&painter);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& button : controllerButtons)
|
||||
{
|
||||
if (this->controllerButtonState[(int)button.button])
|
||||
{
|
||||
renderer.load(button.imageUri);
|
||||
renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatio);
|
||||
renderer.render(&painter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,10 @@ class ControllerImageWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
// button state
|
||||
bool buttonState[(int)N64ControllerButton::Invalid] = {0};
|
||||
// controller button state
|
||||
bool controllerButtonState[(int)N64ControllerButton::Invalid] = {0};
|
||||
// mouse button state
|
||||
bool mouseButtonState[(int)N64MouseButton::Invalid] = {0};
|
||||
// x axis state, -100-100
|
||||
int xAxisState = 0;
|
||||
// y axis state, -100-100
|
||||
@@ -35,15 +37,19 @@ private:
|
||||
int sensitivityValue = 100;
|
||||
|
||||
bool needImageUpdate = false;
|
||||
|
||||
bool isMouseMode = false;
|
||||
public:
|
||||
ControllerImageWidget(QWidget* parent);
|
||||
~ControllerImageWidget();
|
||||
|
||||
void SetButtonState(enum N64ControllerButton button, bool state);
|
||||
void SetControllerButtonState(enum N64ControllerButton button, bool state);
|
||||
void SetMouseButtonState(enum N64MouseButton button, bool state);
|
||||
void SetXAxisState(int xAxis);
|
||||
void SetYAxisState(int yAxis);
|
||||
void SetDeadzone(int value);
|
||||
void SetSensitivity(int value);
|
||||
void SetMouseMode(bool value);
|
||||
|
||||
void ClearControllerState();
|
||||
void UpdateImage();
|
||||
|
||||
@@ -683,6 +683,37 @@ void ControllerWidget::on_profileComboBox_currentIndexChanged(int value)
|
||||
this->CheckInputDeviceSettings();
|
||||
}
|
||||
|
||||
void ControllerWidget::on_inputTypeComboBox_currentIndexChanged(int value)
|
||||
{
|
||||
this->controllerImageWidget->SetMouseMode((value == 1));
|
||||
// force a re-load
|
||||
this->controllerImageWidget->UpdateImage();
|
||||
|
||||
// TODO
|
||||
return;
|
||||
|
||||
QWidget* widgets[] =
|
||||
{
|
||||
groupBox_4,
|
||||
deadZoneGroupBox,
|
||||
};
|
||||
|
||||
if (value == 1)
|
||||
{ // mouse mode
|
||||
for (const auto& widget : widgets)
|
||||
{
|
||||
widget->setEnabled(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // controller mode
|
||||
for (const auto& widget : widgets)
|
||||
{
|
||||
widget->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerWidget::on_inputDeviceComboBox_currentIndexChanged(int value)
|
||||
{
|
||||
// do nothing when value is invalid
|
||||
@@ -695,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())
|
||||
{
|
||||
@@ -1029,7 +1061,7 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event)
|
||||
{
|
||||
if (button.buttonWidget->HasInputData(inputType, sdlButton))
|
||||
{
|
||||
this->controllerImageWidget->SetButtonState(button.button, sdlButtonPressed);
|
||||
this->controllerImageWidget->SetControllerButtonState(button.button, sdlButtonPressed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1140,11 +1172,11 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event)
|
||||
{
|
||||
if (!sdlHatCentered && sdlHatDirection == direction)
|
||||
{
|
||||
this->controllerImageWidget->SetButtonState(button.button, true);
|
||||
this->controllerImageWidget->SetControllerButtonState(button.button, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->controllerImageWidget->SetButtonState(button.button, false);
|
||||
this->controllerImageWidget->SetControllerButtonState(button.button, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1290,7 +1322,7 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event)
|
||||
{
|
||||
if (button.buttonWidget->HasInputData(inputType, sdlAxis, sdlAxisDirection))
|
||||
{
|
||||
this->controllerImageWidget->SetButtonState(button.button, sdlAxisButtonPressed);
|
||||
this->controllerImageWidget->SetControllerButtonState(button.button, sdlAxisButtonPressed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1367,7 +1399,7 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event)
|
||||
{
|
||||
if (button.buttonWidget->HasInputData(InputType::Keyboard, sdlButton))
|
||||
{
|
||||
this->controllerImageWidget->SetButtonState(button.button, sdlButtonPressed);
|
||||
this->controllerImageWidget->SetControllerButtonState(button.button, sdlButtonPressed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1409,6 +1441,21 @@ void ControllerWidget::on_MainDialog_SdlEvent(SDL_Event* event)
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{ // mouse button press
|
||||
if (this->inputDeviceComboBox->currentIndex() != 0)
|
||||
{ // no mouse
|
||||
return;
|
||||
}
|
||||
|
||||
const bool sdlMouseButtonPressed = (event->type == SDL_MOUSEBUTTONDOWN);
|
||||
const N64MouseButton mouseButton = (event->button.button == SDL_BUTTON_LEFT ? N64MouseButton::Left : N64MouseButton::Right);
|
||||
|
||||
// update mouse button state
|
||||
this->controllerImageWidget->SetMouseButtonState(mouseButton, sdlMouseButtonPressed);
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1796,11 +1843,11 @@ void ControllerWidget::SaveSettings(QString section)
|
||||
CoreSettingsSetValue(SettingsID::Input_DeviceName, sectionStr, deviceName.toStdString());
|
||||
CoreSettingsSetValue(SettingsID::Input_DeviceNum, sectionStr, deviceNum);
|
||||
CoreSettingsSetValue(SettingsID::Input_Deadzone, sectionStr, this->deadZoneSlider->value());
|
||||
CoreSettingsSetValue(SettingsID::Input_Sensitivity, sectionStr, this->analogStickSensitivitySlider->value());
|
||||
CoreSettingsSetValue(SettingsID::Input_Pak, sectionStr, this->optionsDialogSettings.ControllerPak);
|
||||
CoreSettingsSetValue(SettingsID::Input_GameboyRom, sectionStr, this->optionsDialogSettings.GameboyRom);
|
||||
CoreSettingsSetValue(SettingsID::Input_GameboySave, sectionStr, this->optionsDialogSettings.GameboySave);
|
||||
CoreSettingsSetValue(SettingsID::Input_RemoveDuplicateMappings, sectionStr, this->optionsDialogSettings.RemoveDuplicateMappings);
|
||||
//CoreSettingsSetValue(SettingsID::Input_InvertAxis, sectionStr, this->optionsDialogSettings.InvertAxis);
|
||||
CoreSettingsSetValue(SettingsID::Input_FilterEventsForButtons, sectionStr, this->optionsDialogSettings.FilterEventsForButtons);
|
||||
CoreSettingsSetValue(SettingsID::Input_FilterEventsForAxis, sectionStr, this->optionsDialogSettings.FilterEventsForAxis);
|
||||
|
||||
|
||||
@@ -157,6 +157,8 @@ private slots:
|
||||
|
||||
void on_profileComboBox_currentIndexChanged(int value);
|
||||
|
||||
void on_inputTypeComboBox_currentIndexChanged(int value);
|
||||
|
||||
void on_inputDeviceComboBox_currentIndexChanged(int value);
|
||||
void on_inputDeviceRefreshButton_clicked();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
<enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -73,7 +73,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_8">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -84,7 +84,7 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="inputDeviceGroupBox">
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -104,7 +104,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
<enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -127,7 +127,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -158,10 +158,10 @@
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksBelow</enum>
|
||||
<enum>QSlider::TickPosition::TicksBelow</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>10</number>
|
||||
@@ -178,7 +178,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -193,7 +193,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -625,10 +625,10 @@
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksBelow</enum>
|
||||
<enum>QSlider::TickPosition::TicksBelow</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>15</number>
|
||||
@@ -641,7 +641,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -663,7 +663,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -706,7 +706,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_7">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -753,7 +753,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -786,7 +786,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_10">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -834,7 +834,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -882,7 +882,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_11">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -901,7 +901,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -1230,7 +1230,7 @@
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
@@ -1266,7 +1266,7 @@
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
|
||||
@@ -33,12 +33,20 @@ enum class N64ControllerButton
|
||||
|
||||
enum class InputDeviceType
|
||||
{
|
||||
Mouse = -5,
|
||||
EmulateVRU = -4,
|
||||
None = -3,
|
||||
Automatic = -2,
|
||||
Keyboard = -1,
|
||||
};
|
||||
|
||||
enum class N64MouseButton
|
||||
{
|
||||
Left = 0,
|
||||
Right,
|
||||
Invalid
|
||||
};
|
||||
|
||||
enum class InputType
|
||||
{
|
||||
Keyboard = -1,
|
||||
|
||||
+104
-1
@@ -30,6 +30,7 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
//
|
||||
// Local Defines
|
||||
@@ -68,6 +69,8 @@ struct InputProfile
|
||||
int DeadzoneValue = 0;
|
||||
int SensitivityValue = 100;
|
||||
|
||||
InputDeviceType DeviceType = InputDeviceType::Mouse;
|
||||
|
||||
N64ControllerPak ControllerPak = N64ControllerPak::None;
|
||||
|
||||
// input device information
|
||||
@@ -163,6 +166,12 @@ struct InputProfile
|
||||
InputMapping Hotkey_Fullscreen;
|
||||
};
|
||||
|
||||
struct MouseMovement
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
//
|
||||
// Local variables
|
||||
//
|
||||
@@ -189,6 +198,12 @@ static void *l_DebugCallContext = nullptr;
|
||||
// keyboard state
|
||||
static bool l_KeyboardState[SDL_NUM_SCANCODES];
|
||||
|
||||
// mouse movements
|
||||
static std::mutex l_MouseMutex;
|
||||
static std::vector<MouseMovement> l_MouseMovements;
|
||||
static bool l_MouseButtonState[2];
|
||||
static ptr_ResetMousePositionCallback l_ResetMousPositionCallback = nullptr;
|
||||
|
||||
//
|
||||
// Local Functions
|
||||
//
|
||||
@@ -289,6 +304,7 @@ static void load_settings(void)
|
||||
|
||||
profile->PluggedIn = CoreSettingsGetBoolValue(SettingsID::Input_PluggedIn, section);
|
||||
profile->DeadzoneValue = CoreSettingsGetIntValue(SettingsID::Input_Deadzone, section);
|
||||
profile->DeviceType = (InputDeviceType)CoreSettingsGetIntValue(SettingsID::Input_InputType, section);
|
||||
profile->ControllerPak = (N64ControllerPak)CoreSettingsGetIntValue(SettingsID::Input_Pak, section);
|
||||
profile->DeviceName = CoreSettingsGetStringValue(SettingsID::Input_DeviceName, section);
|
||||
profile->DeviceNum = CoreSettingsGetIntValue(SettingsID::Input_DeviceNum, section);
|
||||
@@ -423,6 +439,17 @@ static void apply_controller_profiles(void)
|
||||
l_ControlInfo.Controls[i].Plugin = emulateVRU ? PLUGIN_NONE : plugin;
|
||||
l_ControlInfo.Controls[i].RawData = 0;
|
||||
l_ControlInfo.Controls[i].Type = emulateVRU ? CONT_TYPE_VRU : CONT_TYPE_STANDARD;
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
l_ControlInfo.Controls[i].Type = CONT_TYPE_MOUSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_ControlInfo.Controls[i].Type = CONT_TYPE_STANDARD;
|
||||
}
|
||||
|
||||
l_ControlInfo.Controls[i].Type = (profile->DeviceType != InputDeviceType::Mouse ? CONT_TYPE_STANDARD : CONT_TYPE_MOUSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1182,6 +1209,7 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char* Command)
|
||||
}
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
EXPORT void CALL GetKeys(int Control, BUTTONS* Keys)
|
||||
{
|
||||
InputProfile* profile = &l_InputProfiles[Control];
|
||||
@@ -1217,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())
|
||||
{
|
||||
@@ -1254,6 +1283,53 @@ EXPORT void CALL GetKeys(int Control, BUTTONS* Keys)
|
||||
Keys->R_TRIG = get_button_state(profile, &profile->Button_RightTrigger);
|
||||
Keys->Z_TRIG = get_button_state(profile, &profile->Button_ZTrigger);
|
||||
|
||||
if (Control == 0)
|
||||
{
|
||||
// mouse
|
||||
if (profile->DeviceNum == (int)InputDeviceType::Mouse)
|
||||
{ // n64 mouse
|
||||
l_MouseMutex.lock();
|
||||
|
||||
// set left & right button state
|
||||
Keys->A_BUTTON = l_MouseButtonState[0];
|
||||
Keys->B_BUTTON = l_MouseButtonState[1];
|
||||
|
||||
if (!l_MouseMovements.empty())
|
||||
{
|
||||
// calculate how much the mouse has moved
|
||||
// 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
|
||||
|
||||
// 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();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Keys->A_BUTTON = get_button_state(profile, &profile->Button_A);
|
||||
Keys->B_BUTTON = get_button_state(profile, &profile->Button_B);
|
||||
Keys->START_BUTTON = get_button_state(profile, &profile->Button_Start);
|
||||
Keys->U_DPAD = get_button_state(profile, &profile->Button_DpadUp);
|
||||
Keys->D_DPAD = get_button_state(profile, &profile->Button_DpadDown);
|
||||
Keys->L_DPAD = get_button_state(profile, &profile->Button_DpadLeft);
|
||||
Keys->R_DPAD = get_button_state(profile, &profile->Button_DpadRight);
|
||||
Keys->U_CBUTTON = get_button_state(profile, &profile->Button_CButtonUp);
|
||||
Keys->D_CBUTTON = get_button_state(profile, &profile->Button_CButtonDown);
|
||||
Keys->L_CBUTTON = get_button_state(profile, &profile->Button_CButtonLeft);
|
||||
Keys->R_CBUTTON = get_button_state(profile, &profile->Button_CButtonRight);
|
||||
Keys->L_TRIG = get_button_state(profile, &profile->Button_LeftTrigger);
|
||||
Keys->R_TRIG = get_button_state(profile, &profile->Button_RightTrigger);
|
||||
Keys->Z_TRIG = get_button_state(profile, &profile->Button_ZTrigger);
|
||||
|
||||
double inputX = 0, inputY = 0;
|
||||
bool useButtonMapping = false;
|
||||
inputY = get_axis_state(profile, &profile->AnalogStick_Up, 1, inputY, useButtonMapping);
|
||||
@@ -1335,3 +1411,30 @@ EXPORT void CALL SDL_KeyUp(int keymod, int keysym)
|
||||
{
|
||||
l_KeyboardState[keysym] = false;
|
||||
}
|
||||
|
||||
EXPORT void CALL MouseMove(int x, int y)
|
||||
{
|
||||
if (!l_MouseMutex.try_lock())
|
||||
{
|
||||
return;
|
||||
}
|
||||
l_MouseMovements.push_back({x, y});
|
||||
l_MouseMutex.unlock();
|
||||
}
|
||||
|
||||
EXPORT void CALL MouseButton(int left, int right)
|
||||
{
|
||||
if (!l_MouseMutex.try_lock())
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::cout << "MouseButton" << std::endl;
|
||||
l_MouseButtonState[0] = left;
|
||||
l_MouseButtonState[1] = right;
|
||||
l_MouseMutex.unlock();
|
||||
}
|
||||
|
||||
EXPORT void CALL SetResetMousePositionCallback(ptr_ResetMousePositionCallback callback)
|
||||
{
|
||||
l_ResetMousPositionCallback = callback;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ bool CoreCallbacks::Init(void)
|
||||
this->LoadSettings();
|
||||
|
||||
l_CoreCallbacks = this;
|
||||
|
||||
|
||||
if (!CoreSetupCallbacks(this->coreDebugCallback, this->coreStateCallback))
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -32,6 +32,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;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,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
|
||||
|
||||
@@ -105,7 +105,6 @@ bool MainWindow::Init(QApplication* app, bool showUI, bool launchROM)
|
||||
{
|
||||
this->addActions();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -201,12 +200,20 @@ 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);
|
||||
}
|
||||
|
||||
void MainWindow::configureUI(QApplication* app, bool showUI)
|
||||
{
|
||||
this->qApplication = app;
|
||||
|
||||
this->setCentralWidget(this->ui_Widgets);
|
||||
|
||||
QString geometry;
|
||||
@@ -1301,6 +1308,52 @@ void MainWindow::on_EventFilter_FileDropped(QDropEvent *event)
|
||||
#endif // DRAG_DROP
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
void MainWindow::on_EventFilter_MouseButtonPressed(QMouseEvent *event)
|
||||
{
|
||||
if (!CoreIsEmulationRunning())
|
||||
{
|
||||
QMainWindow::mouseMoveEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void MainWindow::on_EventFilter_MouseButtonReleased(QMouseEvent *event)
|
||||
{
|
||||
if (!CoreIsEmulationRunning())
|
||||
{
|
||||
QMainWindow::mouseMoveEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void MainWindow::on_QGuiApplication_applicationStateChanged(Qt::ApplicationState state)
|
||||
{
|
||||
bool isRunning = CoreIsEmulationRunning();
|
||||
@@ -2593,3 +2646,16 @@ void MainWindow::on_VidExt_Quit(void)
|
||||
|
||||
this->ui_VidExtRenderMode = VidExtRenderMode::Invalid;
|
||||
}
|
||||
|
||||
void MainWindow::on_Core_ResetMousPositionCallback()
|
||||
{
|
||||
// reset cursor to center of opengl widget
|
||||
QPoint center = this->ui_Widget_OpenGL->GetWidget()->mapToGlobal(
|
||||
QPoint(
|
||||
this->ui_Widget_OpenGL->GetWidget()->width() / 2,
|
||||
this->ui_Widget_OpenGL->GetWidget()->height() / 2
|
||||
)
|
||||
);
|
||||
|
||||
QCursor::setPos(center);
|
||||
}
|
||||
|
||||
@@ -120,6 +120,11 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
|
||||
int ui_LoadSaveStateSlotCounter = 0;
|
||||
int ui_LoadSaveStateSlotTimerId = -1;
|
||||
|
||||
int ui_LeftMouseButtonState = 0;
|
||||
int ui_RightMouseButtonState = 0;
|
||||
|
||||
QApplication* qApplication = nullptr;
|
||||
|
||||
QString ui_WindowTitle;
|
||||
|
||||
Dialog::LogDialog logDialog;
|
||||
@@ -169,6 +174,10 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
|
||||
void on_EventFilter_KeyReleased(QKeyEvent *event);
|
||||
void on_EventFilter_FileDropped(QDropEvent *event);
|
||||
|
||||
void on_EventFilter_MouseMoved(QMouseEvent *event);
|
||||
void on_EventFilter_MouseButtonPressed(QMouseEvent *event);
|
||||
void on_EventFilter_MouseButtonReleased(QMouseEvent *event);
|
||||
|
||||
void on_QGuiApplication_applicationStateChanged(Qt::ApplicationState state);
|
||||
|
||||
#ifdef UPDATER
|
||||
@@ -241,6 +250,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
|
||||
|
||||
void on_Core_DebugCallback(QList<CoreCallbackMessage> messages);
|
||||
void on_Core_StateCallback(CoreStateCallbackType type, int value);
|
||||
void on_Core_ResetMousPositionCallback(void);
|
||||
};
|
||||
} // namespace UserInterface
|
||||
|
||||
|
||||
Reference in New Issue
Block a user