-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbs_hook_bonus.c
70 lines (62 loc) · 2.29 KB
/
bs_hook_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bs_hook_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nkawaguc <nkawaguc@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 18:51:26 by nkawaguc #+# #+# */
/* Updated: 2024/11/03 20:36:00 by nkawaguc ### ########.fr */
/* */
/* ************************************************************************** */
#include "bs_stl_bonus.h"
static int stl_key_hook(int keycode, t_stldata *stldata);
static int stl_hook_esc(t_stldata *stldata);
static int stl_cross_hook(t_stldata *stldata);
static int loop_hook(t_stldata *stldata);
void stl_hook(t_stldata *stldata)
{
mlx_key_hook(stldata->win, stl_key_hook, stldata);
mlx_hook(stldata->win, DestroyNotify, 0, stl_cross_hook, stldata);
mlx_hook(stldata->win, KeyPress, KeyPressMask, stl_key_hook_loop, stldata);
mlx_loop_hook(stldata->mlx, loop_hook, stldata);
ft_putstr_fd(STL_USAGE, STDOUT_FILENO);
}
static int stl_key_hook(int keycode, t_stldata *stldata)
{
if (keycode == KEY_ESC)
return (stl_hook_esc(stldata));
return (0);
}
static int stl_hook_esc(t_stldata *stldata)
{
mlx_destroy_image(stldata->mlx, stldata->img);
mlx_destroy_window(stldata->mlx, stldata->win);
mlx_loop_end(stldata->mlx);
stldata->win = NULL;
return (0);
}
static int stl_cross_hook(t_stldata *stldata)
{
mlx_destroy_image(stldata->mlx, stldata->img);
mlx_destroy_window(stldata->mlx, stldata->win);
mlx_loop_end(stldata->mlx);
stldata->win = NULL;
exit(0);
return (0);
}
static int loop_hook(t_stldata *stldata)
{
int i;
if (stldata->win != NULL)
{
ft_bzero(stldata->addr, WIN_WIDTH * WIN_HEIGHT * sizeof(int));
i = -1;
while (++i < WIN_WIDTH * WIN_HEIGHT)
stldata->z_buffer[i] = INF;
draw_stl(stldata);
mlx_put_image_to_window(stldata->mlx, stldata->win,
stldata->img, 0, 0);
}
return (0);
}