Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Events using SDL 2.0

Tags:

opengl

sdl

sdl-2

I wrote a simple SDL program using SDL 2.0. I have a little problem when I want to check the mouse wheel events. Actually, in the version 2.0 the flags SDL_BUTTON_WHEELDOWN and SDL_BUTTON_WHEELUP no longer exist. There is just the flags SDL_MOUSEWHEEL. The code below check correctly the' WHEELUP' and 'WHEELDOWN' events but with the same flag.

while(!terminer)
    {
        while (SDL_PollEvent(&evenements))
        {
            switch (evenements.type)
            {
            case SDL_QUIT:
                terminer = true;
                break;
            case SDL_KEYDOWN:
                switch (evenements.key.keysym.sym)
                {
                case SDLK_ESCAPE:
                    terminer = true;
                    break;
                }
                break;
                case SDL_MOUSEMOTION:
                    std::cout << "MOUSE : MOVE" << std::endl;
                    break;
                case SDL_MOUSEBUTTONUP:
                case SDL_MOUSEBUTTONDOWN:
                    std::cout << "MOUSE : BUTTON DOWN" << std::endl;
                    break;
                case SDL_MOUSEWHEEL:
                    std::cout << "MOUSE : WHEEL" << std::endl;
                    break;
            }
        }

But I would like to handle separately the 'WHEELUP' and 'WHEELDOWN' events. I tried several others flags in my condition but without success. Does anyone can help me?

like image 640
user1364743 Avatar asked Feb 14 '23 14:02

user1364743


1 Answers

You can catch the up and down event this way:

case SDL_MOUSEWHEEL:

    if (evenements.wheel.y < 0)
        std::cout << "MOUSE : WHEEL DOWN" << std::endl;
    else
        std::cout << "MOUSE : WHEEL UP" << std::endl;
break;
like image 136
jpw Avatar answered Feb 24 '23 09:02

jpw