-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.c
64 lines (57 loc) · 1.77 KB
/
window.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* window.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmummadi <kmummadi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/22 17:26:34 by kmummadi #+# #+# */
/* Updated: 2024/12/20 18:20:32 by kmummadi ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void handle_keypress(struct mlx_key_data keydata, void *data);
void paint_black(mlx_image_t *image);
void initialize_window(t_dim *dim)
{
void *mlx;
mlx_image_t *image;
mlx = mlx_init(WIDTH, HEIGHT, "FDF", true);
if (!mlx)
exit(-1);
image = mlx_new_image(mlx, WIDTH, HEIGHT);
if (!image)
{
mlx_terminate(mlx);
exit(-1);
}
mlx_image_to_window(mlx, image, 0, 0);
paint_black(image);
draw_fdf(image, dim);
mlx_key_hook(mlx, handle_keypress, mlx);
mlx_loop(mlx);
mlx_terminate(mlx);
return ;
}
void handle_keypress(struct mlx_key_data keydata, void *data)
{
if (keydata.key == MLX_KEY_ESCAPE && keydata.action == MLX_RELEASE)
mlx_close_window((mlx_t *)data);
}
void paint_black(mlx_image_t *image)
{
u_int32_t i;
u_int32_t j;
i = 0;
j = 0;
while (j < image->height)
{
i = 0;
while (i < image->width)
{
draw_pixel(image, i, j, 0x000000FF);
i++;
}
j++;
}
}