/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* inputs.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */ /* Updated: 2022/10/05 19:24:30 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ #include "inputs.h" #include namespace mlx { Input::Input(const std::vector>& wins) : _wins(wins) { std::memset(_keys.data(), 0, SDL_NUM_SCANCODES); std::memset(_mouse.data(), 0, 8); } void Input::update() { _xRel = 0; _yRel = 0; while(SDL_PollEvent(&_event)) { if(_event.window.event == SDL_WINDOWEVENT_CLOSE) _end = true; switch(_event.type) { case SDL_KEYDOWN: _keys[_event.key.keysym.scancode] = static_cast(action::down); break; case SDL_KEYUP: _keys[_event.key.keysym.scancode] = static_cast(action::up); break; case SDL_MOUSEBUTTONDOWN: _mouse[_event.button.button] = static_cast(action::down); break; case SDL_MOUSEBUTTONUP: _mouse[_event.button.button] = static_cast(action::up); break; default: break; } if(_event.type == SDL_MOUSEMOTION) { _x = _event.motion.x; _y = _event.motion.y; _xRel = _event.motion.xrel; _yRel = _event.motion.yrel; } } } }