Commit 14568d74 authored by Florian Oetke's avatar Florian Oetke
Browse files

fixed ignoring clicks on UI elements and partial fix for keys

parent d6ddd6cc
Pipeline #2802 passed with stage
in 9 minutes and 58 seconds
#include <sf2/sf2.hpp>
#include <mirrage/gui/gui.hpp> #include <mirrage/gui/gui.hpp>
#include <sf2/sf2.hpp>
#include <mirrage/asset/asset_manager.hpp> #include <mirrage/asset/asset_manager.hpp>
#include <mirrage/input/events.hpp> #include <mirrage/input/events.hpp>
...@@ -373,6 +373,7 @@ namespace mirrage::gui { ...@@ -373,6 +373,7 @@ namespace mirrage::gui {
handle_key(evt.type == SDL_KEYDOWN, evt.key.keysym.scancode); handle_key(evt.type == SDL_KEYDOWN, evt.key.keysym.scancode);
return evt.key.keysym.sym == SDLK_ESCAPE || !io.WantCaptureKeyboard; return evt.key.keysym.sym == SDLK_ESCAPE || !io.WantCaptureKeyboard;
case SDL_MOUSEBUTTONUP: return !io.WantCaptureMouse;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
if(evt.button.button > 0 && evt.button.button < 4) { if(evt.button.button > 0 && evt.button.button < 4) {
_mouse_pressed[evt.button.button - 1] = true; _mouse_pressed[evt.button.button - 1] = true;
......
...@@ -102,7 +102,7 @@ namespace mirrage::input { ...@@ -102,7 +102,7 @@ namespace mirrage::input {
void _on_mouse_motion(const SDL_MouseMotionEvent& motion); void _on_mouse_motion(const SDL_MouseMotionEvent& motion);
void _poll_events(); void _poll_events();
void _handle_event(SDL_Event& event); void _handle_event(SDL_Event& event, bool filtered);
private: private:
class Gamepad; class Gamepad;
......
...@@ -201,9 +201,7 @@ namespace mirrage::input { ...@@ -201,9 +201,7 @@ namespace mirrage::input {
[&](auto f) { return !f->propagate(event); }) [&](auto f) { return !f->propagate(event); })
!= _event_filter.end(); != _event_filter.end();
if(!filtered) { _handle_event(event, filtered);
_handle_event(event);
}
} }
for(auto& f : _event_filter) { for(auto& f : _event_filter) {
...@@ -212,8 +210,11 @@ namespace mirrage::input { ...@@ -212,8 +210,11 @@ namespace mirrage::input {
} }
void Input_manager::_handle_event(SDL_Event& event) void Input_manager::_handle_event(SDL_Event& event, bool filtered)
{ {
if(filtered)
return; // TODO: don't filter key/button-up events if the down event has already been send
switch(event.type) { switch(event.type) {
case SDL_TEXTINPUT: _mailbox.send<Char_input>(event.text.text); break; case SDL_TEXTINPUT: _mailbox.send<Char_input>(event.text.text); break;
...@@ -339,7 +340,8 @@ namespace mirrage::input { ...@@ -339,7 +340,8 @@ namespace mirrage::input {
if(SDL_IsGameController(joystick_id)) { if(SDL_IsGameController(joystick_id)) {
SDL_GameController* controller = SDL_GameControllerOpen(joystick_id); SDL_GameController* controller = SDL_GameControllerOpen(joystick_id);
if(controller) { if(controller) {
_gamepads.emplace_back(std::make_unique<Gamepad>(gsl::narrow<Input_source>(_gamepads.size() + 1), controller, *_mapper)); _gamepads.emplace_back(std::make_unique<Gamepad>(
gsl::narrow<Input_source>(_gamepads.size() + 1), controller, *_mapper));
_mailbox.send<Source_added>(Input_source(_gamepads.size())); _mailbox.send<Source_added>(Input_source(_gamepads.size()));
} else { } else {
std::cerr << "Could not open gamecontroller " << joystick_id << ": " << SDL_GetError() std::cerr << "Could not open gamecontroller " << joystick_id << ": " << SDL_GetError()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment