-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdf_main.c
95 lines (87 loc) · 2.51 KB
/
fdf_main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf_main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jimchoi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:37:22 by jimchoi #+# #+# */
/* Updated: 2024/04/12 18:57:02 by jimchoi ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int remove_window(t_data *image)
{
int x;
int y;
x = 0;
while (x < WIDTH)
{
y = 0;
while (y < HEIGHT)
{
my_mlx_pixel_put(image, x, y, BLACK);
y++;
}
x++;
}
mlx_put_image_to_window(image->mlx_ptr, image->win_ptr, image->img, 0, 0);
return (0);
}
int handle_key_hook(int keycode, t_data *image)
{
remove_window(image);
if (keycode == 53)
handle_exit(0);
if (keycode == 126)
image->z_level += 1;
if (keycode == 125)
image->z_level -= 1;
convert_isometric(image);
draw_image(image);
mlx_put_image_to_window(image->mlx_ptr, image->win_ptr, image->img, 0, 0);
return (0);
}
int handle_exit(int num)
{
if (num == 1)
{
ft_putendl_fd("Invalid file", 2);
exit(1);
}
else if (num == 2)
{
ft_putendl_fd("Invalid map", 2);
exit(1);
}
else
exit(0);
return (0);
}
int main(int argc, char *argv[])
{
char *str;
t_data image;
if (argc != 2)
handle_exit(1);
str = ft_strrchr(argv[1], '.');
if (ft_strncmp(str, ".fdf", 5) != 0)
handle_exit(1);
parsing(argv, &image, -1, -1);
image.mlx_ptr = mlx_init();
image.win_ptr = mlx_new_window(image.mlx_ptr, WIDTH, HEIGHT, "fdf");
image.img = mlx_new_image(image.mlx_ptr, WIDTH, HEIGHT);
image.addr = mlx_get_data_addr(image.img, &image.bits_per_pixel, \
&image.line_length, &image.endian);
image.z_level = 4;
convert_isometric(&image);
draw_image(&image);
mlx_put_image_to_window(image.mlx_ptr, image.win_ptr, image.img, 0, 0);
mlx_hook(image.win_ptr, 17, 0, &handle_exit, 0);
mlx_key_hook(image.win_ptr, handle_key_hook, &image);
mlx_loop(image.mlx_ptr);
handle_exit(0);
}
// void check_leaks(void)
// { system("leaks fdf"); }
// atexit(check_leaks);