adding imputs system

This commit is contained in:
Kbz-8
2022-10-05 17:08:36 +02:00
commit 5df9b4d39f
15 changed files with 825 additions and 0 deletions

54
src/platform/inputs.cpp git.filemode.normal_file
View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* inputs.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */
/* Updated: 2022/10/05 16:39:42 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include "inputs.h"
#include <cstring>
namespace mlx
{
Input::Input()
{
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<uint8_t>(action::down); break;
case SDL_KEYUP: _keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::up); break;
case SDL_MOUSEBUTTONDOWN: _mouse[_event.button.button] = static_cast<uint8_t>(action::down); break;
case SDL_MOUSEBUTTONUP: _mouse[_event.button.button] = static_cast<uint8_t>(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;
}
}
}
}