fractol/mlx/src/mlx_keys.c

50 lines
1.7 KiB
C
Raw Normal View History

2023-03-01 04:36:42 +01:00
/* ************************************************************************** */
/* */
/* :::::::: */
/* mlx_keys.c :+: :+: */
/* +:+ */
2023-10-25 13:29:53 +02:00
/* By: W2Wizard <main@w2wizard.dev> +#+ */
2023-03-01 04:36:42 +01:00
/* +#+ */
/* Created: 2022/01/01 21:06:45 by W2Wizard #+# #+# */
2023-10-25 13:29:53 +02:00
/* Updated: 2023/02/13 12:24:40 by W2Wizard ######## odam.nl */
2023-03-01 04:36:42 +01:00
/* */
/* ************************************************************************** */
#include "MLX42/MLX42_Int.h"
//= Private =//
static void mlx_key_callback(GLFWwindow* window, int32_t key, int32_t scancode, int32_t action, int32_t mods)
{
const mlx_t* mlx = glfwGetWindowUserPointer(window);
const mlx_key_t key_hook = ((mlx_ctx_t*)mlx->context)->key_hook;
const mlx_key_data_t callback_data = {
key,
action,
scancode,
mods,
};
key_hook.func(callback_data, key_hook.param);
}
//= Public =//
void mlx_key_hook(mlx_t* mlx, mlx_keyfunc func, void* param)
{
2023-10-25 13:29:53 +02:00
MLX_NONNULL(mlx);
MLX_NONNULL(func);
2023-03-01 04:36:42 +01:00
mlx_ctx_t* mlxctx = mlx->context;
mlxctx->key_hook.func = func;
mlxctx->key_hook.param = param;
glfwSetKeyCallback(mlx->window, mlx_key_callback);
}
bool mlx_is_key_down(mlx_t* mlx, keys_t key)
{
2023-10-25 13:29:53 +02:00
MLX_NONNULL(mlx);
2023-03-01 04:36:42 +01:00
return (glfwGetKey(mlx->window, key) == GLFW_PRESS);
}