handle cross click
This commit is contained in:
parent
3cd1066b1b
commit
8ad8eb1fbc
3 changed files with 20 additions and 10 deletions
|
@ -6,7 +6,7 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 14:43:09 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/11/01 20:59:28 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 14:26:28 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -41,7 +41,9 @@ int hook_keypress(int keycode);
|
|||
/// @return Unused.
|
||||
int hook_keyrelease(int keycode);
|
||||
|
||||
/// @brief To call at the start of the program.
|
||||
void input_init(void);
|
||||
/// @brief To handle the input of a window.
|
||||
///
|
||||
/// @param win_ptr Reference to the window to use.
|
||||
void input_init(void *win_ptr);
|
||||
|
||||
#endif
|
||||
|
|
16
src/input.c
16
src/input.c
|
@ -6,7 +6,7 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 14:43:36 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/11/01 20:59:32 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 14:25:46 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -14,6 +14,13 @@
|
|||
|
||||
t_input_actions g_input_actions;
|
||||
|
||||
static int set_quit(void *_)
|
||||
{
|
||||
(void)_;
|
||||
g_input_actions.quit = true;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void set_action(int keycode, bool value)
|
||||
{
|
||||
if (keycode == XK_Up || keycode == XK_z || keycode == XK_w)
|
||||
|
@ -25,7 +32,7 @@ static void set_action(int keycode, bool value)
|
|||
if (keycode == XK_Left || keycode == XK_q || keycode == XK_a)
|
||||
g_input_actions.left = value;
|
||||
if (keycode == XK_Escape)
|
||||
g_input_actions.quit = value;
|
||||
set_quit(NULL);
|
||||
}
|
||||
|
||||
int hook_keypress(int keycode)
|
||||
|
@ -40,7 +47,10 @@ int hook_keyrelease(int keycode)
|
|||
return (0);
|
||||
}
|
||||
|
||||
void input_init(void)
|
||||
void input_init(void *win_ptr)
|
||||
{
|
||||
ft_memset(&g_input_actions, 0, sizeof(g_input_actions));
|
||||
mlx_hook(win_ptr, DestroyNotify, StructureNotifyMask, set_quit, NULL);
|
||||
mlx_hook(win_ptr, KeyPress, KeyPressMask, hook_keypress, NULL);
|
||||
mlx_hook(win_ptr, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 16:57:40 by mc #+# #+# */
|
||||
/* Updated: 2024/11/07 00:07:35 by mc ### ########.fr */
|
||||
/* Updated: 2024/11/07 14:25:29 by mc ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -53,7 +53,6 @@ static int loop_hook(void *param)
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
g_mlx = mlx_init();
|
||||
input_init();
|
||||
if (argc != 2)
|
||||
{
|
||||
printf("Syntax: %s <map.cub>\n", argv[0]);
|
||||
|
@ -62,8 +61,7 @@ int main(int argc, char *argv[])
|
|||
if (!map_from_file(&g_map, argv[1]))
|
||||
return (1);
|
||||
g_win = mlx_new_window(g_mlx, SCREEN_WIDTH, SCREEN_HEIGHT, "cub3d");
|
||||
mlx_hook(g_win, KeyPress, KeyPressMask, hook_keypress, NULL);
|
||||
mlx_hook(g_win, KeyRelease, KeyReleaseMask, hook_keyrelease, NULL);
|
||||
input_init(g_win);
|
||||
mlx_loop_hook(g_mlx, loop_hook, NULL);
|
||||
draw_screen();
|
||||
mlx_loop(g_mlx);
|
||||
|
|
Loading…
Add table
Reference in a new issue