Permalink
Browse files

[SDL2] Use new wheel events in mouse handling.

The mouse wheel is not a button anymore. The old button codes and events are now
removed and we use SDL_MouseWheelEvent to get the updates.

SDL_EventState( SDL_MOUSEWHEEL, SDL_ENABLE ) is called at initialization but I
do not know it is required.
  • Loading branch information...
Julien Jorge
Julien Jorge committed Aug 25, 2013
1 parent 43ab1af commit 3c8d30adc5abaddfdc13a93506377b49fa806311
Showing with 23 additions and 10 deletions.
  1. +22 −8 bear-engine/core/src/input/code/mouse.cpp
  2. +1 −2 bear-engine/core/src/input/code/system.cpp
@@ -125,13 +125,29 @@ void bear::input::mouse::refresh()
SDL_Event e;
- while ( SDL_PeepEvents(&e, 1, SDL_GETEVENT, SDL_MOUSEEVENTMASK) == 1 )
- {
- SDL_MouseButtonEvent* evt = reinterpret_cast<SDL_MouseButtonEvent*>(&e);
+ // The range of events to process. It includes button up and button down.
+ const SDL_EventType event_min( SDL_MOUSEMOTION );
+ const SDL_EventType event_max( SDL_MOUSEWHEEL );
+
+ while ( SDL_PeepEvents(&e, 1, SDL_GETEVENT, event_min, event_max ) == 1 )
+ if ( e.type == SDL_MOUSEBUTTONDOWN )
+ {
+ const SDL_MouseButtonEvent* const evt =
+ reinterpret_cast<SDL_MouseButtonEvent*>(&e);
- if ( (evt->type == SDL_MOUSEBUTTONDOWN) && (evt->state == SDL_PRESSED) )
- m_pressed_buttons.push_back( sdl_button_to_local( evt->button ) );
- }
+ if ( evt->state == SDL_PRESSED )
+ m_pressed_buttons.push_back( sdl_button_to_local( evt->button ) );
+ }
+ else if ( e.type == SDL_MOUSEWHEEL )
+ {
+ const SDL_MouseWheelEvent* const evt =
+ reinterpret_cast<SDL_MouseWheelEvent*>(&e);
+
+ if ( evt->y > 0 )
+ m_pressed_buttons.push_back( mc_wheel_up );
+ else
+ m_pressed_buttons.push_back( mc_wheel_down );
+ }
} // mouse::refresh()
/*----------------------------------------------------------------------------*/
@@ -166,8 +182,6 @@ bear::input::mouse::mouse_code bear::input::mouse::sdl_button_to_local
case SDL_BUTTON_LEFT : return mc_left_button; break;
case SDL_BUTTON_MIDDLE : return mc_middle_button; break;
case SDL_BUTTON_RIGHT : return mc_right_button; break;
- case SDL_BUTTON_WHEELUP : return mc_wheel_up; break;
- case SDL_BUTTON_WHEELDOWN : return mc_wheel_down; break;
default: return mc_invalid;
}
@@ -39,8 +39,7 @@ void bear::input::system::initialize()
SDL_EnableUNICODE(1);
SDL_EventState( SDL_KEYDOWN, SDL_ENABLE );
- SDL_EventState( SDL_BUTTON_WHEELUP, SDL_ENABLE );
- SDL_EventState( SDL_BUTTON_WHEELDOWN, SDL_ENABLE );
+ SDL_EventState( SDL_MOUSEWHEEL, SDL_ENABLE );
// force the creation of the instance
get_instance().refresh();

0 comments on commit 3c8d30a

Please sign in to comment.