How to get Mousewheel event in SDL?

Started by
6 comments, last by MARS_999 17 years, 1 month ago
I can't find anywhere on the net that shows how to get values from the mousewheel when the user moves it? I don't see mousewheel in the sdl docs either? thanks
Advertisement
IIRC it counts as a mouse button event. From the docs:
Quote:
Structure Data
type SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP

button The mouse button index (SDL_BUTTON_LEFT, SDL_BUTTON_MIDDLE, SDL_BUTTON_RIGHT, SDL_BUTTON_WHEELUP, SDL_BUTTON_WHEELDOWN)

state SDL_PRESSED or SDL_RELEASED

x, y The X/Y coordinates of the mouse at press/release time


Would elaborate, but I have to go [smile]

HTH
Thanks for the tip. Am I correct in assuming that with SDL_BUTTON_WHEELUP or down you can make the wheel movement amount whatever you want? As of now I just increment by a value and thats what I get... Windows mouse wheel movement is a bit different, where it goes something like so

if(directInput.getMouseMovementWheel())gCameraHeight += (directInput.getMouseMovementWheel() / 120.0f * gameSetupData.mouseWheelSensitivity);//So in SDL I am doingcase SDL_BUTTON_WHEELUP:gCameraHeight += .005f;
The code above (assuming you do the same for wheel down) would give incorrect results, as one button is followed by another. So you would get a mouse up then a mouse down or vice versa and you camera would never alter.
Well if thats the case than how do you just get the input for a mouse wheel when its only moved up or down and only want to add or sub a value? Not sure why both should be called if the user only moves the wheel up than up should be called not down...
Here is some old source I have from when I was just interested in whether the wheel was up or down and it is hackish due to the buffer size which could cause an overrun.
void SDL_input::capture_mousewheel(){		int const num = 32;		SDL_Event events[num];		int count = SDL_PeepEvents(events, num, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN));		//Mousewheel events are just that and are not states.		//When the mousewheel is moved a SDL_MOUSEBUTTONDOWN followed by a SDL_MOUSEBUTTONUP		//is generated so we need to remove these off the queue.//at the current frame rate i get one (if any) per update.		//if(count >0)		//	SYSTEM_LOG(FILENLINE,"number of mouse wheel down events is: %d",count);		for( int i = 0; i<count;++i)		{			if(events.button.button == SDL_BUTTON_WHEELUP)				{ m_mouse_current.wheel_up=true; }			else if(events.button.button == SDL_BUTTON_WHEELDOWN)				{ m_mouse_current.wheel_down=true; }		}		//get the release events of the queue		SDL_PeepEvents(events, num, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEBUTTONUP) );}
Would you like a copy of my mouse class? I was planning to implement mouse wheel sooner or later, so if you like ill do it now. Its nothing particularly fancy, but it works in the game engine im making right now.

Basicaly, you need a value for the amount of scrolling which has been done, preferably a float.
for each mouse wheel event, add or subtract the "speed per click" to this value.
do this once per frame and take the result once all events on the message buffer have been handled. I use a similar method for cursor movement, which gives better results than simply reading the last instance of SDL_MOUSEMOTION, which is what I did when I first started out with SDL.


Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
Quote:Original post by speciesUnknown
Would you like a copy of my mouse class? I was planning to implement mouse wheel sooner or later, so if you like ill do it now. Its nothing particularly fancy, but it works in the game engine im making right now.

Basicaly, you need a value for the amount of scrolling which has been done, preferably a float.
for each mouse wheel event, add or subtract the "speed per click" to this value.
do this once per frame and take the result once all events on the message buffer have been handled. I use a similar method for cursor movement, which gives better results than simply reading the last instance of SDL_MOUSEMOTION, which is what I did when I first started out with SDL.


If you want to great, but this is what I am using now and seems to work fine....

case SDL_MOUSEBUTTONUP:				switch(event->button.button)				{					case SDL_BUTTON_WHEELUP:						gCameraHeight += .5f;                        break;					case SDL_BUTTON_WHEELDOWN:						gCameraHeight -= .5f;						break;				}				break;


Thanks

This topic is closed to new replies.

Advertisement