mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
adding imputs system
This commit is contained in:
56
src/platform/inputs.h
git.filemode.normal_file
56
src/platform/inputs.h
git.filemode.normal_file
@@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* inputs.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */
|
||||
/* Updated: 2022/10/05 16:45:55 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
enum class action : uint8_t { up = (1 << 1), down = (1 << 2) };
|
||||
|
||||
class Input
|
||||
{
|
||||
public:
|
||||
Input();
|
||||
|
||||
void update();
|
||||
|
||||
inline bool getInKey(const SDL_Scancode key, action type = action::down) const noexcept { return _keys[key] & static_cast<uint8_t>(type); }
|
||||
|
||||
inline bool getInMouse(const uint8_t button, action type = action::down) const noexcept { return _mouse[button] & static_cast<uint8_t>(type); }
|
||||
inline bool isMouseMoving() const noexcept { return _xRel || _yRel; }
|
||||
|
||||
inline int getX() const noexcept { return _x; }
|
||||
inline int getY() const noexcept { return _y; }
|
||||
|
||||
inline int getXRel() const noexcept { return _xRel; }
|
||||
inline int getYRel() const noexcept { return _yRel; }
|
||||
|
||||
inline bool is_running() const noexcept { return !_end; }
|
||||
inline void finish() noexcept { _end = true; }
|
||||
|
||||
~Input() = default;
|
||||
|
||||
private:
|
||||
std::array<uint8_t, SDL_NUM_SCANCODES> _keys;
|
||||
std::array<uint8_t, 8> _mouse;
|
||||
SDL_Event _event;
|
||||
|
||||
int _x = 0;
|
||||
int _y = 0;
|
||||
int _xRel = 0;
|
||||
int _yRel = 0;
|
||||
|
||||
bool _end = false;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user