Skip to content

Commit

Permalink
RMG-Core: add Mouse functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed May 28, 2024
1 parent 215532e commit f6b0717
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions Source/RMG-Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(RMG_CORE_SOURCES
Cheats.cpp
Volume.cpp
VidExt.cpp
Mouse.cpp
Video.cpp
Error.cpp
Unzip.cpp
Expand Down
1 change: 1 addition & 0 deletions Source/RMG-Core/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
60 changes: 60 additions & 0 deletions Source/RMG-Core/Mouse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
* Copyright (C) 2020 Rosalie Wanders <[email protected]>
*
* 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;
}
19 changes: 19 additions & 0 deletions Source/RMG-Core/Mouse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
* Copyright (C) 2020 Rosalie Wanders <[email protected]>
*
* 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
4 changes: 4 additions & 0 deletions Source/RMG-Core/m64p/api/m64p_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down
4 changes: 3 additions & 1 deletion Source/RMG-Core/m64p/api/m64p_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f6b0717

Please sign in to comment.