Jump to content
  • Advertisement
Sign in to follow this  
ManaStone

SDL: Does SDL_BUTTON(SDL_BUTTON_WHEELUP) work for anyone else?

This topic is 4929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can get my program to do scrolling if I poll for the event, but if I try to do the following: ------------ SDL_PumpEvents(); if(SDL_GetMouseState(&x,&y) == SDL_BUTTON(SDL_BUTTON_WHEELUP)) cout<<"asd"<<endl; ----------- it doesn't work. I am using Windows XP and the other mouse buttons work fine. Is this a problem with SDL or is it just me.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ManaStone
I can get my program to do scrolling if I poll for the event, but if I try to do the following:

------------
SDL_PumpEvents();

if(SDL_GetMouseState(&x,&y) == SDL_BUTTON(SDL_BUTTON_WHEELUP))
cout<<"asd"<<endl;



-----------

it doesn't work. I am using Windows XP and the other mouse buttons work fine. Is this a problem with SDL or is it just me.


I think you should be doing:


// 1 & is intentional
if(SDL_GetMouseState(&x,&y) & SDL_BUTTON(SDL_BUTTON_WHEELUP))
cout<<"asd"<<endl;


- Drew

[Edited by - Drew_Benton on June 29, 2005 12:58:16 AM]

Share this post


Link to post
Share on other sites
Ok this is what you will have to do. I found this after searching google:

Someone had this code and it was not working.


SDL_PumpEvents();
if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_WHEELUP))
printf("Wheel up event\n");


In response they got
Quote:
"Wheel up" is a momentary event, not a state. So you should use
SDL_PollEvent() instead of SDL_GetMouseState().


This means that you will have to process it in your event loop. This is why it was not working at all.

- Drew

[Edited by - Drew_Benton on June 29, 2005 12:36:22 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by LizardCPP
Is there any way I can see if the mouse wheel has MOVED? Can't find anything in the SDL docs.

thx

Lizard


Straight from the docs.
Example:

{
SDL_Event event;

while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_MOUSEMOTION:
printf("Mouse moved by %d,%d to (%d,%d)\n",
event.motion.xrel, event.motion.yrel,
event.motion.x, event.motion.y);
break;
case SDL_MOUSEBUTTONDOWN:
printf("Mouse button %d pressed at (%d,%d)\n",
event.button.button, event.button.x, event.button.y);
break;
case SDL_QUIT:
exit(0);
}
}
}


Hope this helps! [smile]

- Drew

[Edited by - Drew_Benton on June 29, 2005 12:21:33 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
Quote:
Original post by LizardCPP
Is there any way I can see if the mouse wheel has MOVED? Can't find anything in the SDL docs.

thx

Lizard


Straight from the docs.
Example:

{
SDL_Event event;

while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_MOUSEMOTION:
printf("Mouse moved by %d,%d to (%d,%d)\n",
event.motion.xrel, event.motion.yrel,
event.motion.x, event.motion.y);
break;
case SDL_MOUSEBUTTONDOWN:
printf("Mouse button %d pressed at (%d,%d)\n",
event.button.button, event.button.x, event.button.y);
break;
case SDL_QUIT:
exit(0);
}
}
}


Hope this helps! [smile]

- Drew


As I see it SDL_MOUSEMOTION checks how much the mouse has moved and it's current position. And SDL_MOUSEBUTTONDOWN is recieved when a button is pressen on the mouse. But I was looking for Mouse Wheel events. That is the middle button on the mouse formed as a wheel that you can just scroll or press down and scroll. And I dont see how I can get that from your example?

hope this makes any sense.

Lizard

Share this post


Link to post
Share on other sites
I appologize! [embarrass]. I read your post as "Is there any way I can see if the mouse has MOVED? Can't find anything in the SDL docs." not as you had it "Is there any way I can see if the mouse wheel has MOVED? Can't find anything in the SDL docs."

I am currently not sure if you can get that with SDL, but you should. I'll give it a try when I get back from class this evening.

- Drew

[edit] I got it figured out[/edit]


if( event.type == SDL_MOUSEBUTTONDOWN )
{
if(event.button.button == SDL_BUTTON_WHEELUP)
printf("Wheel Up");
else if(event.button.button == SDL_BUTTON_WHEELDOWN)
printf("Wheel Down");
}


Works for me in a test program I made!


#include "stdafx.h"

#include <sdl/sdl.h>
#include <stdlib.h>

#pragma comment(lib,"sdl.lib")
#pragma comment(lib,"sdlmain.lib")

int main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
printf("Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}

atexit(SDL_Quit);

SDL_Surface *screen;
screen=SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);

if ( screen == NULL )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}

int done=0;


while(done == 0)
{
SDL_Event event;

while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }

if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
done = 1;
}
}

if( event.type == SDL_MOUSEBUTTONDOWN )
{
if(event.button.button == SDL_BUTTON_WHEELUP)
printf("Wheel Up\n");
else if(event.button.button == SDL_BUTTON_WHEELDOWN)
printf("Wheel Down\n");
}

SDL_Flip(screen);
}
}

return 0;
}




Hope this helps!

- Drew

[Edited by - Drew_Benton on June 29, 2005 12:09:09 AM]

Share this post


Link to post
Share on other sites
Thx for your effort, but it's not really what I meant. Sorry =).
With your code, one can see if the wheel is pressed down or if it's up. But I was looking for if the wheel has been moved (use often to scroll down a webrowser window for example).

But really thx for your effort

Lizard

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!