mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-27 12:31:47 +00:00
Add Scroll Binds
and fix a five year oob array index/write
This commit is contained in:
parent
b99f18dacc
commit
e7e04d9925
4 changed files with 21 additions and 10 deletions
|
|
@ -106,11 +106,17 @@ const char* translate_bind_to_name(int bind) {
|
|||
// mouse
|
||||
if (bind >= VK_BASE_SDL_MOUSE) {
|
||||
int mouse_button = (bind - VK_BASE_SDL_MOUSE);
|
||||
if (mouse_button == 1) { return "L Mouse"; }
|
||||
if (mouse_button == 2) { return "M Mouse"; }
|
||||
if (mouse_button == 3) { return "R Mouse"; }
|
||||
snprintf(name, 8, "Mouse %d", bind - VK_BASE_SDL_MOUSE);
|
||||
return name;
|
||||
switch (mouse_button) {
|
||||
case 1: return "L Mouse";
|
||||
case 2: return "M Mouse";
|
||||
case 3: return "R Mouse";
|
||||
case 6: return "Scroll Up";
|
||||
case 7: return "Scroll Down";
|
||||
default: {
|
||||
snprintf(name, 8, "Mouse %d", mouse_button);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// gamepad
|
||||
|
|
|
|||
|
|
@ -116,6 +116,11 @@ void controller_mouse_read_relative(void) {
|
|||
#elif defined(CAPI_SDL1) || defined(CAPI_SDL2)
|
||||
mouse_buttons = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
|
||||
#endif
|
||||
if (mouse_scroll_y > 0) {
|
||||
mouse_buttons |= MWHEELUP;
|
||||
} else if (mouse_scroll_y < 0) {
|
||||
mouse_buttons |= MWHEELDOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void controller_mouse_enter_relative(void) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
// mouse buttons are also in the controller namespace, just offset 0x100
|
||||
#define VK_OFS_SDL_MOUSE 0x0100
|
||||
#define VK_BASE_SDL_MOUSE (VK_BASE_SDL_GAMEPAD + VK_OFS_SDL_MOUSE)
|
||||
#define MWHEELUP 0x20
|
||||
#define MWHEELDOWN 0x40
|
||||
|
||||
extern struct ControllerAPI controller_sdl;
|
||||
|
||||
|
|
|
|||
|
|
@ -60,11 +60,11 @@ static s16 invert_s16(s16 val) {
|
|||
static inline void controller_add_binds(const u32 mask, const u32 *btns) {
|
||||
for (u32 i = 0; i < MAX_BINDS; ++i) {
|
||||
if (btns[i] >= VK_BASE_SDL_GAMEPAD && btns[i] <= VK_BASE_SDL_GAMEPAD + VK_SIZE) {
|
||||
if (btns[i] >= VK_BASE_SDL_MOUSE && num_joy_binds < MAX_JOYBINDS) {
|
||||
if (btns[i] >= VK_BASE_SDL_MOUSE && num_mouse_binds < MAX_JOYBINDS) {
|
||||
mouse_binds[num_mouse_binds][0] = btns[i] - VK_BASE_SDL_MOUSE;
|
||||
mouse_binds[num_mouse_binds][1] = mask;
|
||||
++num_mouse_binds;
|
||||
} else if (num_mouse_binds < MAX_JOYBINDS) {
|
||||
} else if (num_joy_binds < MAX_JOYBINDS) {
|
||||
joy_binds[num_joy_binds][0] = btns[i] - VK_BASE_SDL_GAMEPAD;
|
||||
joy_binds[num_joy_binds][1] = mask;
|
||||
++num_joy_binds;
|
||||
|
|
@ -285,9 +285,7 @@ static void controller_sdl_read(OSContPad *pad) {
|
|||
u32 buttons_down = 0;
|
||||
for (u32 i = 0; i < num_joy_binds; ++i)
|
||||
if (joy_buttons[joy_binds[i][0]])
|
||||
buttons_down |= joy_binds[i][1];
|
||||
|
||||
pad->button |= buttons_down;
|
||||
pad->button |= joy_binds[i][1];
|
||||
|
||||
const u32 xstick = buttons_down & STICK_XMASK;
|
||||
const u32 ystick = buttons_down & STICK_YMASK;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue