mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-05 01:38:07 +00:00
Add Scroll Binds (#835)
* Add Scroll Binds and fix a five year oob array index/write * number * fix that part I just saw this * That should be that I have tested it, scroll works on the Up input, and on a regular input, so does everything else
This commit is contained in:
parent
006fc1dcd2
commit
697f1c3f82
4 changed files with 22 additions and 9 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, 11, "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;
|
||||
|
|
@ -190,10 +190,11 @@ static void controller_sdl_read(OSContPad *pad) {
|
|||
controller_mouse_read_relative();
|
||||
u32 mouse = mouse_buttons;
|
||||
|
||||
u32 buttons_down = 0;
|
||||
if (!gInteractableOverridePad) {
|
||||
for (u32 i = 0; i < num_mouse_binds; ++i)
|
||||
if (mouse & SDL_BUTTON(mouse_binds[i][0]))
|
||||
pad->button |= mouse_binds[i][1];
|
||||
buttons_down |= mouse_binds[i][1];
|
||||
}
|
||||
// remember buttons that changed from 0 to 1
|
||||
last_mouse = (mouse_prev ^ mouse) & mouse;
|
||||
|
|
@ -282,7 +283,6 @@ static void controller_sdl_read(OSContPad *pad) {
|
|||
update_button(VK_LTRIGGER - VK_BASE_SDL_GAMEPAD, ltrig > AXIS_THRESHOLD);
|
||||
update_button(VK_RTRIGGER - VK_BASE_SDL_GAMEPAD, rtrig > AXIS_THRESHOLD);
|
||||
|
||||
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];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue