-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
54 lines (48 loc) · 1.72 KB
/
main.c
File metadata and controls
54 lines (48 loc) · 1.72 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mvalient <mvalient@student.42urduliz.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 13:17:56 by mvalient #+# #+# */
/* Updated: 2022/12/21 13:23:56 by mvalient ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static int clear_mem(t_mlx *mlx)
{
ft_clear_point_list(&mlx->points, free);
free(mlx->mlx);
free(mlx);
return (EXIT_SUCCESS);
}
static int key_hook(int keycode, void *param)
{
t_mlx *mlx;
mlx = param;
ft_printf("KEY PRESSED: %d\n", keycode);
if (keycode == 65307)
{
mlx_destroy_window(mlx->mlx, mlx->win);
exit(clear_mem(mlx));
}
return (0);
}
int main(int argc, char **argv)
{
t_mlx *mlx;
t_img img;
(void)argc;
mlx = malloc(sizeof(t_mlx));
mlx->mlx = mlx_init();
mlx->win = mlx_new_window(mlx->mlx, WIDTH, HEIGHT, "fdf");
img.img = mlx_new_image(mlx->mlx, WIDTH, HEIGHT);
img.addr = mlx_get_data_addr(img.img, &img.bits_per_pixel, &img.line_length,
&img.endian);
mlx->points = ft_read_file(argv[1]);
ft_put_lines(&img, mlx);
mlx_key_hook(mlx->win, key_hook, mlx);
mlx_loop(mlx->mlx);
return (EXIT_SUCCESS);
}