Add Mouse4, Mouse5 and scroll wheel bindings

This commit is contained in:
Struma 2022-07-03 11:53:40 -04:00
parent 2a7ff4b7f3
commit 342f30069f
5 changed files with 39 additions and 5 deletions

View file

@ -269,6 +269,12 @@ RB_METHOD(inputMouseY) {
return rb_fix_new(shState->input().mouseY()); return rb_fix_new(shState->input().mouseY());
} }
RB_METHOD(inputScrollV) {
RB_UNUSED_PARAM;
return rb_fix_new(shState->input().scrollV());
}
#define M_SYMBOL(x) ID2SYM(rb_intern(x)) #define M_SYMBOL(x) ID2SYM(rb_intern(x))
#define POWERCASE(v, c) \ #define POWERCASE(v, c) \
case SDL_JOYSTICK_POWER_##c: \ case SDL_JOYSTICK_POWER_##c: \
@ -386,7 +392,10 @@ struct {
{"MOUSELEFT", Input::MouseLeft}, {"MOUSELEFT", Input::MouseLeft},
{"MOUSEMIDDLE", Input::MouseMiddle}, {"MOUSEMIDDLE", Input::MouseMiddle},
{"MOUSERIGHT", Input::MouseRight}}; {"MOUSERIGHT", Input::MouseRight},
{"MOUSEX1", Input::MouseX1},
{"MOUSEX2", Input::MouseX2}
};
static elementsN(buttonCodes); static elementsN(buttonCodes);
@ -412,6 +421,7 @@ void inputBindingInit() {
_rb_define_module_function(module, "mouse_x", inputMouseX); _rb_define_module_function(module, "mouse_x", inputMouseX);
_rb_define_module_function(module, "mouse_y", inputMouseY); _rb_define_module_function(module, "mouse_y", inputMouseY);
_rb_define_module_function(module, "scroll_v", inputScrollV);
_rb_define_module_function(module, "joystick", inputJoystickInfo); _rb_define_module_function(module, "joystick", inputJoystickInfo);

View file

@ -86,6 +86,7 @@ uint8_t EventThread::keyStates[];
EventThread::JoyState EventThread::joyState; EventThread::JoyState EventThread::joyState;
EventThread::MouseState EventThread::mouseState; EventThread::MouseState EventThread::mouseState;
EventThread::TouchState EventThread::touchState; EventThread::TouchState EventThread::touchState;
SDL_atomic_t EventThread::verticalScrollDistance;
/* User event codes */ /* User event codes */
enum enum
@ -428,6 +429,10 @@ void EventThread::process(RGSSThreadData &rtData)
updateCursorState(cursorInWindow, gameScreen); updateCursorState(cursorInWindow, gameScreen);
break; break;
case SDL_MOUSEWHEEL :
/* Only consider vertical scrolling for now */
SDL_AtomicAdd(&verticalScrollDistance, event.wheel.y);
case SDL_FINGERDOWN : case SDL_FINGERDOWN :
i = event.tfinger.fingerId; i = event.tfinger.fingerId;
touchState.fingers[i].down = true; touchState.fingers[i].down = true;

View file

@ -26,6 +26,7 @@
#include <SDL_joystick.h> #include <SDL_joystick.h>
#include <SDL_mouse.h> #include <SDL_mouse.h>
#include <SDL_mutex.h> #include <SDL_mutex.h>
#include <SDL_atomic.h>
#include <string> #include <string>
@ -75,6 +76,7 @@ public:
static JoyState joyState; static JoyState joyState;
static MouseState mouseState; static MouseState mouseState;
static TouchState touchState; static TouchState touchState;
static SDL_atomic_t verticalScrollDistance;
std::string textInputBuffer; std::string textInputBuffer;
void lockText(bool lock); void lockText(bool lock);

View file

@ -38,7 +38,7 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#define BUTTON_CODE_COUNT 24 #define BUTTON_CODE_COUNT 26
#define m(vk,sc) { vk, SDL_SCANCODE_##sc } #define m(vk,sc) { vk, SDL_SCANCODE_##sc }
std::unordered_map<int, int> vKeyToScancode{ std::unordered_map<int, int> vKeyToScancode{
@ -626,7 +626,7 @@ static const int mapToIndex[] =
0, 0,
16, 17, 18, 19, 20, 16, 17, 18, 19, 20,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
21, 22, 23 21, 22, 23, 24, 25
}; };
static elementsN(mapToIndex); static elementsN(mapToIndex);
@ -692,6 +692,8 @@ struct InputPrivate
unsigned long long last_update; unsigned long long last_update;
int vScrollDistance;
struct struct
{ {
int active; int active;
@ -746,6 +748,8 @@ struct InputPrivate
dir4Data.previous = Input::None; dir4Data.previous = Input::None;
dir8Data.active = 0; dir8Data.active = 0;
vScrollDistance = 0;
} }
inline ButtonState &getStateCheck(int code) inline ButtonState &getStateCheck(int code)
@ -942,12 +946,14 @@ struct InputPrivate
void initMsBindings() void initMsBindings()
{ {
msBindings.resize(3); msBindings.resize(5);
size_t i = 0; size_t i = 0;
msBindings[i++] = MsBinding(SDL_BUTTON_LEFT, Input::MouseLeft); msBindings[i++] = MsBinding(SDL_BUTTON_LEFT, Input::MouseLeft);
msBindings[i++] = MsBinding(SDL_BUTTON_MIDDLE, Input::MouseMiddle); msBindings[i++] = MsBinding(SDL_BUTTON_MIDDLE, Input::MouseMiddle);
msBindings[i++] = MsBinding(SDL_BUTTON_RIGHT, Input::MouseRight); msBindings[i++] = MsBinding(SDL_BUTTON_RIGHT, Input::MouseRight);
msBindings[i++] = MsBinding(SDL_BUTTON_X1, Input::MouseX1);
msBindings[i++] = MsBinding(SDL_BUTTON_X2, Input::MouseX2);
} }
void pollBindings(Input::ButtonCode &repeatCand) void pollBindings(Input::ButtonCode &repeatCand)
@ -1173,6 +1179,10 @@ void Input::update()
} }
p->repeating = None; p->repeating = None;
/* Fetch new cumulative scroll distance and reset counter */
p->vScrollDistance = SDL_AtomicSet(&EventThread::verticalScrollDistance, 0);
p->last_update = shState->runTime(); p->last_update = shState->runTime();
} }
@ -1307,6 +1317,11 @@ int Input::mouseY()
return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y; return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
} }
int Input::scrollV()
{
return p->vScrollDistance;
}
bool Input::getJoystickConnected() bool Input::getJoystickConnected()
{ {
return shState->eThread().getJoystickConnected(); return shState->eThread().getJoystickConnected();

View file

@ -50,7 +50,8 @@ public:
F5 = 25, F6 = 26, F7 = 27, F8 = 28, F9 = 29, F5 = 25, F6 = 26, F7 = 27, F8 = 28, F9 = 29,
/* Non-standard extensions */ /* Non-standard extensions */
MouseLeft = 38, MouseMiddle = 39, MouseRight = 40 MouseLeft = 38, MouseMiddle = 39, MouseRight = 40,
MouseX1 = 41, MouseX2 = 42
}; };
void recalcRepeat(unsigned int fps); void recalcRepeat(unsigned int fps);
@ -79,6 +80,7 @@ public:
/* Non-standard extensions */ /* Non-standard extensions */
int mouseX(); int mouseX();
int mouseY(); int mouseY();
int scrollV();
bool getJoystickConnected(); bool getJoystickConnected();
const char *getJoystickName(); const char *getJoystickName();