diff --git a/Source/RMG-Core/CMakeLists.txt b/Source/RMG-Core/CMakeLists.txt index 8ed4f6e8a..7c5440631 100644 --- a/Source/RMG-Core/CMakeLists.txt +++ b/Source/RMG-Core/CMakeLists.txt @@ -47,6 +47,7 @@ set(RMG_CORE_SOURCES Cheats.cpp Volume.cpp VidExt.cpp + Mouse.cpp Video.cpp Error.cpp Unzip.cpp diff --git a/Source/RMG-Core/Core.hpp b/Source/RMG-Core/Core.hpp index 4ed565527..fadd52f3e 100644 --- a/Source/RMG-Core/Core.hpp +++ b/Source/RMG-Core/Core.hpp @@ -27,6 +27,7 @@ #include "Cheats.hpp" #include "Volume.hpp" #include "Error.hpp" +#include "Mouse.hpp" #include "Unzip.hpp" #include "Video.hpp" #include "Key.hpp" diff --git a/Source/RMG-Core/Mouse.cpp b/Source/RMG-Core/Mouse.cpp new file mode 100644 index 000000000..6c5034d44 --- /dev/null +++ b/Source/RMG-Core/Mouse.cpp @@ -0,0 +1,60 @@ +/* + * Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG + * Copyright (C) 2020 Rosalie Wanders + * + * 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 . + */ +#include "Key.hpp" +#include "Error.hpp" +#include "m64p/Api.hpp" + +#include + +// +// 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; +} diff --git a/Source/RMG-Core/Mouse.hpp b/Source/RMG-Core/Mouse.hpp new file mode 100644 index 000000000..b916bd963 --- /dev/null +++ b/Source/RMG-Core/Mouse.hpp @@ -0,0 +1,19 @@ +/* + * Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG + * Copyright (C) 2020 Rosalie Wanders + * + * 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 . + */ +#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 diff --git a/Source/RMG-Core/m64p/api/m64p_plugin.h b/Source/RMG-Core/m64p/api/m64p_plugin.h index 76671fd32..45384cf48 100644 --- a/Source/RMG-Core/m64p/api/m64p_plugin.h +++ b/Source/RMG-Core/m64p/api/m64p_plugin.h @@ -199,6 +199,8 @@ typedef void (*ptr_ViWidthChanged)(void); typedef void (*ptr_ReadScreen2)(void *dest, int *width, int *height, int front); typedef void (*ptr_SetRenderingCallback)(void (*callback)(int)); typedef void (*ptr_ResizeVideoOutput)(int width, int height); +typedef void (*ptr_MouseMove)(int x, int y); +typedef void (*ptr_MouseButton)(int left, int right); #if defined(M64P_PLUGIN_PROTOTYPES) EXPORT void CALL ChangeWindow(void); EXPORT int CALL InitiateGFX(GFX_INFO Gfx_Info); @@ -212,6 +214,8 @@ EXPORT void CALL ViWidthChanged(void); EXPORT void CALL ReadScreen2(void *dest, int *width, int *height, int front); EXPORT void CALL SetRenderingCallback(void (*callback)(int)); EXPORT void CALL ResizeVideoOutput(int width, int height); +EXPORT void CALL MouseMove(int x, int y); +EXPORT void CALL MouseButton(int left, int right); #endif /* frame buffer plugin spec extension */ diff --git a/Source/RMG-Core/m64p/api/m64p_types.h b/Source/RMG-Core/m64p/api/m64p_types.h index 088f0117f..bfebed905 100644 --- a/Source/RMG-Core/m64p/api/m64p_types.h +++ b/Source/RMG-Core/m64p/api/m64p_types.h @@ -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 {