Archived
1
0

macrolibx update to 1.2.1

This commit is contained in:
Adam Joly
2024-01-12 11:25:48 +01:00
parent 904013801a
commit a4aed04873
186 changed files with 4494 additions and 290004 deletions

View File

@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */
/* Updated: 2023/12/11 19:01:14 by kbz_8 ### ########.fr */
/* Updated: 2023/12/08 12:17:40 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,12 @@
namespace mlx
{
Input::Input()
{
std::memset(_keys.data(), 0, SDL_NUM_SCANCODES);
std::memset(_mouse.data(), 0, 8);
}
void Input::update()
{
_xRel = 0;
@ -41,6 +47,7 @@ namespace mlx
{
case SDL_KEYDOWN:
{
_keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::down);
if(hooks[MLX_KEYDOWN].hook)
hooks[MLX_KEYDOWN].hook(_event.key.keysym.scancode, hooks[MLX_KEYDOWN].param);
break;
@ -48,6 +55,7 @@ namespace mlx
case SDL_KEYUP:
{
_keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::up);
if(hooks[MLX_KEYUP].hook)
hooks[MLX_KEYUP].hook(_event.key.keysym.scancode, hooks[MLX_KEYUP].param);
break;
@ -55,6 +63,7 @@ namespace mlx
case SDL_MOUSEBUTTONDOWN:
{
_mouse[_event.button.button] = static_cast<uint8_t>(action::down);
if(hooks[MLX_MOUSEDOWN].hook)
hooks[MLX_MOUSEDOWN].hook(_event.button.button, hooks[MLX_MOUSEDOWN].param);
break;
@ -62,6 +71,7 @@ namespace mlx
case SDL_MOUSEBUTTONUP:
{
_mouse[_event.button.button] = static_cast<uint8_t>(action::up);
if(hooks[MLX_MOUSEUP].hook)
hooks[MLX_MOUSEUP].hook(_event.button.button, hooks[MLX_MOUSEUP].param);
break;

View File

@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */
/* Updated: 2023/12/11 19:47:20 by kbz_8 ### ########.fr */
/* Updated: 2023/12/08 18:54:03 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,12 +18,14 @@
#include <SDL2/SDL.h>
#include <unordered_map>
#include <mlx_profile.h>
#include <core/profile.h>
#include "window.h"
namespace mlx
{
enum class action : uint8_t { up = (1 << 1), down = (1 << 2) };
struct Hook
{
std::function<int(int, void*)> hook;
@ -33,10 +35,13 @@ namespace mlx
class Input
{
public:
Input() = default;
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; }
@ -63,9 +68,11 @@ namespace mlx
~Input() = default;
private:
std::array<uint8_t, SDL_NUM_SCANCODES> _keys;
std::unordered_map<uint32_t, std::shared_ptr<MLX_Window>> _windows;
std::unordered_map<uint32_t, std::array<Hook, 6>> _events_hooks;
SDL_Event _event;
std::array<uint8_t, 8> _mouse;
int _x = 0;
int _y = 0;

View File

@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
/* Updated: 2023/12/27 16:57:28 by maldavid ### ########.fr */
/* Updated: 2023/12/09 16:52:29 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,8 +31,6 @@ namespace mlx
MLX_Window::MLX_Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h)
{
if(title.find("vvaas") != std::string::npos)
core::error::report(e_kind::message, "vvaas est mauvais");
_win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN);
if(!_win)
core::error::report(e_kind::fatal_error, std::string("unable to open a new window, ") + SDL_GetError());
@ -43,6 +41,7 @@ namespace mlx
void MLX_Window::destroy() noexcept
{
std::cout << "prout" << std::endl;
if(_win != nullptr)
{
SDL_DestroyWindow(_win);

View File

@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
/* Updated: 2023/12/21 00:24:26 by maldavid ### ########.fr */
/* Updated: 2023/12/09 16:35:57 by kbz_8 ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,7 @@
#include <SDL2/SDL.h>
#include <string>
#include <mlx_profile.h>
#include <core/profile.h>
namespace mlx
{