File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ Game::Game()
3030
3131bool Game::Initialize ()
3232{
33- if (SDL_Init (SDL_INIT_VIDEO |SDL_INIT_AUDIO ) != 0 )
33+ if (SDL_Init (SDL_INIT_VIDEO |SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER ) != 0 )
3434 {
3535 SDL_Log (" Unable to initialize SDL: %s" , SDL_GetError ());
3636 return false ;
@@ -122,6 +122,11 @@ void Game::ProcessInput()
122122 case SDL_QUIT :
123123 mIsRunning = false ;
124124 break ;
125+ case SDL_MOUSEWHEEL :
126+ mInputSystem ->ProcessEvent (event);
127+ break ;
128+ default :
129+ break ;
125130 }
126131 }
127132
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ void InputSystem::PrepareForUpdate()
103103 // Mouse
104104 mState .Mouse .mPrevButtons = mState .Mouse .mCurrButtons ;
105105 mState .Mouse .mIsRelative = false ;
106+ mState .Mouse .mScrollWheel = Vector2::Zero;
106107}
107108
108109void InputSystem::Update ()
@@ -124,6 +125,20 @@ void InputSystem::Update()
124125 mState .Mouse .mMousePos .y = static_cast <float >(y);
125126}
126127
128+ void InputSystem::ProcessEvent (SDL_Event& event)
129+ {
130+ switch (event.type )
131+ {
132+ case SDL_MOUSEWHEEL :
133+ mState .Mouse .mScrollWheel = Vector2 (
134+ static_cast <float >(event.wheel .x ),
135+ static_cast <float >(event.wheel .y ));
136+ break ;
137+ default :
138+ break ;
139+ }
140+ }
141+
127142void InputSystem::SetRelativeMouseMode (bool value)
128143{
129144 SDL_bool set = value ? SDL_TRUE : SDL_FALSE ;
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ class MouseState
4242
4343 // For mouse position
4444 const Vector2& GetPosition () const { return mMousePos ; }
45+ const Vector2& GetScrollWheel () const { return mScrollWheel ; }
4546 bool IsRelative () const { return mIsRelative ; }
4647
4748 // For buttons
@@ -50,6 +51,8 @@ class MouseState
5051private:
5152 // Store current mouse position
5253 Vector2 mMousePos ;
54+ // Motion of scroll wheel
55+ Vector2 mScrollWheel ;
5356 // Store button data
5457 Uint32 mCurrButtons ;
5558 Uint32 mPrevButtons ;
@@ -74,6 +77,8 @@ class InputSystem
7477 void PrepareForUpdate ();
7578 // Called after SDL_PollEvents loop
7679 void Update ();
80+ // Called to process an SDL event in input system
81+ void ProcessEvent (union SDL_Event& event);
7782
7883 const InputState& GetState () const { return mState ; }
7984
You can’t perform that action at this time.
0 commit comments