Skip to content

Commit a0b4ae1

Browse files
authored
Mouse Wheel Cleanup Option (#7079)
* Adds an optional bool to `mouse_down()` for `must_be_mousewheel` to only process mousewheel events. * Used within `controlsconfig.cpp::check_control_used()` to handle a special case with the mousewheel to allow using it for `CC_TYPE_TRIGGER` controls.
1 parent 6a9b6a3 commit a0b4ae1

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

code/controlconfig/controlsconfig.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,17 +2888,10 @@ int check_control_used(int id, int key)
28882888

28892889
// special case to allow actual mouse wheel to work with trigger controls --wookieejedi
28902890
if (item.type == CC_TYPE_TRIGGER) {
2891-
2892-
int first_btn = 1 << item.first.get_btn();
2893-
int second_btn = 1 << item.second.get_btn();
2894-
2895-
if ( (first_btn >= LOWEST_MOUSE_WHEEL && first_btn <= HIGHEST_MOUSE_WHEEL) ||
2896-
(second_btn >= LOWEST_MOUSE_WHEEL && second_btn <= HIGHEST_MOUSE_WHEEL) ) {
2897-
if ( mouse_down(item.first) || mouse_down(item.second) ) {
2898-
// Mouse wheel bound to this trigger control was pressed, control activated
2899-
control_used(id);
2900-
return 1;
2901-
}
2891+
if ( mouse_down(item.first, true) || mouse_down(item.second, true) ) {
2892+
// Mouse wheel bound to this trigger control was pressed, control activated
2893+
control_used(id);
2894+
return 1;
29022895
}
29032896
}
29042897

code/io/mouse.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ int mouse_up_count(int n) {
459459

460460
// returns 1 if mouse button btn is down, 0 otherwise
461461

462-
int mouse_down(const CC_bind &bind)
462+
int mouse_down(const CC_bind &bind, bool must_be_wheel)
463463
{
464464
// Bail if the incoming bind is not the right CID according to mouse-fly mode
465465
auto CID = bind.get_cid();
@@ -483,20 +483,22 @@ int mouse_down(const CC_bind &bind)
483483

484484
btn = 1 << btn;
485485

486-
return mouse_down(btn);
486+
return mouse_down(btn, must_be_wheel);
487487
}
488488

489-
int mouse_down(int btn) {
490-
int tmp;
489+
int mouse_down(int btn, bool must_be_wheel) {
491490
if ( !mouse_inited ) return 0;
492491

493492
// Bail if not a button or wheel direction
494493
if ((btn < LOWEST_MOUSE_BUTTON) || (btn > HIGHEST_MOUSE_WHEEL)) return 0;
495494

495+
// Bail if needs to be a mouse wheel and is not --wookieejedi
496+
if (must_be_wheel && (btn < LOWEST_MOUSE_WHEEL || btn > HIGHEST_MOUSE_WHEEL)) return 0;
496497

497-
SDL_LockMutex( mouse_lock );
498498

499+
SDL_LockMutex( mouse_lock );
499500

501+
int tmp;
500502
if (mouse_flags & btn) {
501503
tmp = 1;
502504
if ((btn >= LOWEST_MOUSE_WHEEL) && (btn <= HIGHEST_MOUSE_WHEEL)) {

code/io/mouse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ void mouse_flush();
9898
* @note Calls mousewheel_decay() if the mousewheel direction is "down".
9999
* Please ensure mouse_down() is called only once per frame.
100100
*/
101-
int mouse_down(const CC_bind &bind);
101+
int mouse_down(const CC_bind& bind, bool must_be_wheel = false);
102102

103103
/**
104104
* Returns 1 if any of the given mouse buttons are down. 0 otherwise
105105
*/
106-
int mouse_down(int btn);
106+
int mouse_down(int btn, bool must_be_wheel = false);
107107

108108
void mouse_reset_deltas();
109109
void mouse_get_delta(int *dx = NULL, int *dy = NULL, int *dz = NULL);

0 commit comments

Comments
 (0)