Skip to content
Snippets Groups Projects
Commit 0572b7d2 authored by jwendt's avatar jwendt
Browse files

Add mouse weel scroll signal

#463
parent b33dff4c
No related branches found
No related tags found
1 merge request!156Feature/#463 mouse keyboard device
...@@ -36,6 +36,8 @@ void Mouse::OnSDLEvent(const SDL_Event& event) { ...@@ -36,6 +36,8 @@ void Mouse::OnSDLEvent(const SDL_Event& event) {
if (event.type == SDL_MOUSEMOTION) { if (event.type == SDL_MOUSEMOTION) {
move_signal_(static_cast<int>(event.motion.xrel), move_signal_(static_cast<int>(event.motion.xrel),
static_cast<int>(event.motion.yrel)); static_cast<int>(event.motion.yrel));
} else if (event.type == SDL_MOUSEWHEEL) {
wheel_signal_(static_cast<int>(event.wheel.y));
} else if (event.type == SDL_MOUSEBUTTONDOWN) { } else if (event.type == SDL_MOUSEBUTTONDOWN) {
event_type = BUTTON_PRESSED; event_type = BUTTON_PRESSED;
} else if (event.type == SDL_MOUSEBUTTONUP) { } else if (event.type == SDL_MOUSEBUTTONUP) {
...@@ -75,4 +77,9 @@ boost::signals2::connection Mouse::RegisterMoveSignal( ...@@ -75,4 +77,9 @@ boost::signals2::connection Mouse::RegisterMoveSignal(
return move_signal_.connect(callback); return move_signal_.connect(callback);
} }
boost::signals2::connection Mouse::RegisterWheelSignal(
const std::function<void(int)>& callback) {
return wheel_signal_.connect(callback);
}
} // namespace phx } // namespace phx
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "boost/signals2/signal.hpp" #include "boost/signals2/signal.hpp"
#include "phx/input/sdl_device.hpp" #include "phx/input/sdl_device.hpp"
#include "phx/suppress_warnings.hpp"
#include "phx/export.hpp" #include "phx/export.hpp"
...@@ -57,10 +56,13 @@ class PHOENIX_EXPORT Mouse : public SDLDevice { ...@@ -57,10 +56,13 @@ class PHOENIX_EXPORT Mouse : public SDLDevice {
const std::function<void(ButtonId, ButtonEvent)>& callback); const std::function<void(ButtonId, ButtonEvent)>& callback);
boost::signals2::connection RegisterMoveSignal( boost::signals2::connection RegisterMoveSignal(
const std::function<void(int, int)>& callback); const std::function<void(int, int)>& callback);
boost::signals2::connection RegisterWheelSignal(
const std::function<void(int)>& callback);
private: private:
boost::signals2::signal<void(ButtonId, ButtonEvent)> button_signal_; boost::signals2::signal<void(ButtonId, ButtonEvent)> button_signal_;
boost::signals2::signal<void(int, int)> move_signal_; boost::signals2::signal<void(int, int)> move_signal_;
boost::signals2::signal<void(int)> wheel_signal_;
}; };
} // namespace phx } // namespace phx
......
...@@ -97,5 +97,29 @@ SCENARIO("Mouse signals received events.", "[phx][phx::Mouse]") { ...@@ -97,5 +97,29 @@ SCENARIO("Mouse signals received events.", "[phx][phx::Mouse]") {
} }
} }
} }
WHEN("a mouse scroll signal is registered") {
int y_delta_received = 0;
mouse.RegisterWheelSignal(
[&y_delta_received](int y_delta) { y_delta_received = y_delta; });
WHEN("A mouse scroll event is fired by SDL.") {
SDL_Event mouse_event;
mouse_event.type = SDL_MOUSEWHEEL;
mouse_event.wheel.y = 3;
auto first_call = std::make_shared<bool>(true);
ALLOW_CALL(sdl_mock.Get(), SDL_PollEvent(_))
.SIDE_EFFECT(*_1 = mouse_event)
.SIDE_EFFECT(*first_call = false)
.WITH(*first_call == true)
.RETURN(true);
ALLOW_CALL(sdl_mock.Get(), SDL_PollEvent(_))
.WITH(*first_call == false)
.RETURN(false);
THEN("I should receive a signal.") {
mouse.Update();
REQUIRE(y_delta_received == 3);
}
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment