From aba438680756b0b1448f4364bb4bd3dcbc90e72b Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 27 Sep 2016 22:53:48 -0300 Subject: [PATCH] SDL click count functionality was added in 2.0.2, not 2.0.4. So we can get rid of some useless code since we require 2.0.2+ in love 0.11... --HG-- branch : minor --- src/modules/event/sdl/Event.cpp | 94 ++++++++++----------------------- src/modules/event/sdl/Event.h | 17 ++---- 2 files changed, 31 insertions(+), 80 deletions(-) diff --git a/src/modules/event/sdl/Event.cpp b/src/modules/event/sdl/Event.cpp index 7296c9359..50de0a7a4 100644 --- a/src/modules/event/sdl/Event.cpp +++ b/src/modules/event/sdl/Event.cpp @@ -147,7 +147,7 @@ void Event::clear() love::event::Event::clear(); } -Message *Event::convert(const SDL_Event &e) +Message *Event::convert(const SDL_Event &e) const { Message *msg = nullptr; @@ -244,7 +244,31 @@ Message *Event::convert(const SDL_Event &e) break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: - msg = convertMouseButtonEvent(e); + { + // SDL uses button 3 for the right mouse button, but we use button 2 + int button = e.button.button; + switch (button) + { + case SDL_BUTTON_RIGHT: + button = 2; + break; + case SDL_BUTTON_MIDDLE: + button = 3; + break; + } + + double px = (double) e.button.x; + double py = (double) e.button.y; + windowToPixelCoords(&px, &py); + vargs.emplace_back(px); + vargs.emplace_back(py); + vargs.emplace_back((double) button); + vargs.emplace_back(e.button.which == SDL_TOUCH_MOUSEID); + vargs.emplace_back((double) e.button.clicks); + + bool down = e.type == SDL_MOUSEBUTTONDOWN; + msg = new Message(down ? "mousepressed" : "mousereleased", vargs); + } break; case SDL_MOUSEWHEEL: vargs.emplace_back((double) e.wheel.x); @@ -362,69 +386,7 @@ Message *Event::convert(const SDL_Event &e) return msg; } -Message *Event::convertMouseButtonEvent(const SDL_Event &e) -{ - bool down = e.type == SDL_MOUSEBUTTONDOWN; - - std::vector vargs; - vargs.reserve(5); - - // SDL uses button index 3 for the right mouse button, but we use index 2. - int button = e.button.button; - switch (button) - { - case SDL_BUTTON_RIGHT: - button = 2; - break; - case SDL_BUTTON_MIDDLE: - button = 3; - break; - } - - double px = (double) e.button.x; - double py = (double) e.button.y; - windowToPixelCoords(&px, &py); - vargs.emplace_back(px); - vargs.emplace_back(py); - vargs.emplace_back((double) button); - vargs.emplace_back(e.button.which == SDL_TOUCH_MOUSEID); - -#if SDL_VERSION_ATLEAST(2,0,4) - SDL_version version; - SDL_GetVersion(&version); - if (version.major >= 2 && (version.minor > 0 || version.patch >= 4)) - vargs.emplace_back((double) e.button.clicks); - else -#endif - { - ClickState state = clickCounts[e.button.which]; - - // Matches the behaviour of SDL 2.0.4's click count tracking code when - // it doesn't know any OS-specific information. - if (down) - { - double now = timer::Timer::getTime(); - int diffX = abs(e.button.x - state.lastX); - int diffY = abs(e.button.y - state.lastY); - - if ((now - state.time) >= 0.5 || diffX > 1 || diffY > 1) - state.count = 0; - - state.count++; - state.lastX = e.button.x; - state.lastY = e.button.y; - state.time = now; - - clickCounts[e.button.which] = state; - } - - vargs.emplace_back((double) state.count); - } - - return new Message(down ? "mousepressed" : "mousereleased", vargs); -} - -Message *Event::convertJoystickEvent(const SDL_Event &e) +Message *Event::convertJoystickEvent(const SDL_Event &e) const { auto joymodule = Module::getInstance(Module::M_JOYSTICK); if (!joymodule) @@ -549,7 +511,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) return msg; } -Message *Event::convertWindowEvent(const SDL_Event &e) +Message *Event::convertWindowEvent(const SDL_Event &e) const { Message *msg = nullptr; diff --git a/src/modules/event/sdl/Event.h b/src/modules/event/sdl/Event.h index 40f53a444..9ab44174e 100644 --- a/src/modules/event/sdl/Event.h +++ b/src/modules/event/sdl/Event.h @@ -68,20 +68,9 @@ public: private: - struct ClickState - { - int count; - int lastX; - int lastY; - double time; - }; - - Message *convert(const SDL_Event &e); - Message *convertMouseButtonEvent(const SDL_Event &e); - Message *convertJoystickEvent(const SDL_Event &e); - Message *convertWindowEvent(const SDL_Event &e); - - std::map clickCounts; + Message *convert(const SDL_Event &e) const; + Message *convertJoystickEvent(const SDL_Event &e) const; + Message *convertWindowEvent(const SDL_Event &e) const; static std::map createKeyMap(); static std::map keys;