fixing color issues with texts

This commit is contained in:
Kbz-8
2023-04-11 23:42:27 +02:00
parent 3863bd3378
commit 34cc9d63da
8 changed files with 113 additions and 19 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/04/03 12:40:10 by maldavid ### ########.fr */
/* Updated: 2023/04/11 21:32:43 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -36,10 +36,33 @@ namespace mlx
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;
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);
if(_key_hook.hook)
_key_hook.hook(SDL_GetScancodeName(_event.key.keysym.scancode), _key_hook.param);
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);
if(_mouse_hook.hook)
_mouse_hook.hook(std::string("mouse").c_str(), _mouse_hook.param);
break;
}
default: 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/04/03 14:19:11 by maldavid ### ########.fr */
/* Updated: 2023/04/11 21:41:33 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,6 +14,7 @@
#include <memory>
#include <vector>
#include <cstdint>
#include <functional>
#include <SDL2/SDL.h>
#include "window.h"
@@ -22,6 +23,12 @@ namespace mlx
{
enum class action : uint8_t { up = (1 << 1), down = (1 << 2) };
struct Hook
{
std::function<int(const char*, void*)> hook;
void* param = nullptr;
};
class Input
{
public:
@@ -46,13 +53,21 @@ namespace mlx
inline constexpr void enableAutoRepeat() noexcept { _auto_repeat = true; }
inline constexpr void disableAutoRepeat() noexcept { _auto_repeat = false; }
inline void mouseHook(int (*funct_ptr)(const char*, void*), void* param) noexcept { _mouse_hook.hook = funct_ptr; _mouse_hook.param = param; }
inline void keyHook(int (*funct_ptr)(const char*, void*), void* param) noexcept { _key_hook.hook = funct_ptr; _key_hook.param = param; }
inline void exposeHook(int (*funct_ptr)(const char*, void*), void* param) noexcept { _expose_hook.hook = funct_ptr; _expose_hook.param = param; }
~Input() = default;
private:
SDL_Event _event;
std::array<uint8_t, SDL_NUM_SCANCODES> _keys;
SDL_Event _event;
std::array<uint8_t, 8> _mouse;
Hook _mouse_hook;
Hook _key_hook;
Hook _expose_hook;
int _x = 0;
int _y = 0;
int _xRel = 0;