Add Input::scrollV() to query vertical mouse wheel scroll events
This commit is contained in:
		
							parent
							
								
									e2bbcde85d
								
							
						
					
					
						commit
						e32aa71f4b
					
				
					 5 changed files with 31 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -115,6 +115,13 @@ RB_METHOD(inputMouseY)
 | 
			
		|||
	return rb_fix_new(shState->input().mouseY());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RB_METHOD(inputScrollV)
 | 
			
		||||
{
 | 
			
		||||
	RB_UNUSED_PARAM;
 | 
			
		||||
 | 
			
		||||
	return rb_fix_new(shState->input().scrollV());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -168,6 +175,7 @@ inputBindingInit()
 | 
			
		|||
 | 
			
		||||
	_rb_define_module_function(module, "mouse_x", inputMouseX);
 | 
			
		||||
	_rb_define_module_function(module, "mouse_y", inputMouseY);
 | 
			
		||||
	_rb_define_module_function(module, "scroll_v", inputScrollV);
 | 
			
		||||
 | 
			
		||||
	if (rgssVer >= 3)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,6 +73,7 @@ uint8_t EventThread::keyStates[];
 | 
			
		|||
EventThread::JoyState EventThread::joyState;
 | 
			
		||||
EventThread::MouseState EventThread::mouseState;
 | 
			
		||||
EventThread::TouchState EventThread::touchState;
 | 
			
		||||
SDL_atomic_t EventThread::verticalScrollDistance;
 | 
			
		||||
 | 
			
		||||
/* User event codes */
 | 
			
		||||
enum
 | 
			
		||||
| 
						 | 
				
			
			@ -380,6 +381,11 @@ void EventThread::process(RGSSThreadData &rtData)
 | 
			
		|||
			updateCursorState(cursorInWindow, gameScreen);
 | 
			
		||||
			break;
 | 
			
		||||
 | 
			
		||||
		case SDL_MOUSEWHEEL :
 | 
			
		||||
			/* Only consider vertical scrolling for now */
 | 
			
		||||
			SDL_AtomicAdd(&verticalScrollDistance, event.wheel.y);
 | 
			
		||||
			break;
 | 
			
		||||
 | 
			
		||||
		case SDL_FINGERDOWN :
 | 
			
		||||
			i = event.tfinger.fingerId;
 | 
			
		||||
			touchState.fingers[i].down = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,6 +31,7 @@
 | 
			
		|||
#include <SDL_joystick.h>
 | 
			
		||||
#include <SDL_mouse.h>
 | 
			
		||||
#include <SDL_mutex.h>
 | 
			
		||||
#include <SDL_atomic.h>
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -76,6 +77,7 @@ public:
 | 
			
		|||
	static JoyState joyState;
 | 
			
		||||
	static MouseState mouseState;
 | 
			
		||||
	static TouchState touchState;
 | 
			
		||||
	static SDL_atomic_t verticalScrollDistance;
 | 
			
		||||
 | 
			
		||||
	static bool allocUserEvents();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@
 | 
			
		|||
 | 
			
		||||
#include <SDL_scancode.h>
 | 
			
		||||
#include <SDL_mouse.h>
 | 
			
		||||
#include <SDL_atomic.h>
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -287,6 +288,9 @@ struct InputPrivate
 | 
			
		|||
	Input::ButtonCode repeating;
 | 
			
		||||
	unsigned int repeatCount;
 | 
			
		||||
 | 
			
		||||
	/* Cumulative vertical scroll distance since last update call */
 | 
			
		||||
	int vScrollDistance;
 | 
			
		||||
 | 
			
		||||
	struct
 | 
			
		||||
	{
 | 
			
		||||
		int active;
 | 
			
		||||
| 
						 | 
				
			
			@ -322,6 +326,8 @@ struct InputPrivate
 | 
			
		|||
		dir4Data.previous = Input::None;
 | 
			
		||||
 | 
			
		||||
		dir8Data.active = 0;
 | 
			
		||||
 | 
			
		||||
		vScrollDistance = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	inline ButtonState &getStateCheck(int code)
 | 
			
		||||
| 
						 | 
				
			
			@ -640,6 +646,9 @@ void Input::update()
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	p->repeating = None;
 | 
			
		||||
 | 
			
		||||
	/* Fetch new cumulative scroll distance and reset counter */
 | 
			
		||||
	p->vScrollDistance = SDL_AtomicSet(&EventThread::verticalScrollDistance, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Input::isPressed(int button)
 | 
			
		||||
| 
						 | 
				
			
			@ -681,6 +690,11 @@ int Input::mouseY()
 | 
			
		|||
	return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Input::scrollV()
 | 
			
		||||
{
 | 
			
		||||
	return p->vScrollDistance;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Input::~Input()
 | 
			
		||||
{
 | 
			
		||||
	delete p;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,6 +58,7 @@ public:
 | 
			
		|||
	/* Non-standard extensions */
 | 
			
		||||
	int mouseX();
 | 
			
		||||
	int mouseY();
 | 
			
		||||
	int scrollV();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	Input(const RGSSThreadData &rtData);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue