-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
76 lines (71 loc) · 2.3 KB
/
init.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: slouham <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/17 15:44:53 by slouham #+# #+# */
/* Updated: 2024/07/18 14:37:05 by slouham ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
static void malloc_error(void)
{
write(2, "Problems with malloc", 20);
exit(EXIT_FAILURE);
}
static void data_init(t_fractal *fractal)
{
fractal->escape_value = 4;
fractal->iterations = 50;
fractal->shift_x = 0.0;
fractal->shift_y = 0.0;
fractal->zoom = 1.0;
}
static void events_init(t_fractal *fractal)
{
mlx_hook(fractal->mlx_window,
KeyPress,
KeyPressMask,
key_handler,
fractal);
mlx_hook(fractal->mlx_window,
ButtonPress,
ButtonPressMask,
mouse_handler,
fractal);
mlx_hook(fractal->mlx_window,
DestroyNotify,
StructureNotifyMask,
close_handler,
fractal);
}
void fractal_init(t_fractal *fractal)
{
fractal->mlx_connection = mlx_init();
if (fractal->mlx_connection == NULL)
malloc_error();
fractal->mlx_window = mlx_new_window(fractal->mlx_connection,
WIDTH, HEIGHT, fractal->name);
if (fractal->mlx_window == NULL)
{
mlx_destroy_display(fractal->mlx_connection);
free(fractal->mlx_connection);
malloc_error();
}
fractal->img.img_ptr = mlx_new_image(fractal->mlx_connection,
WIDTH, HEIGHT);
if (fractal->img.img_ptr == NULL)
{
mlx_destroy_window(fractal->mlx_connection, fractal->mlx_window);
mlx_destroy_display(fractal->mlx_connection);
free(fractal->mlx_connection);
malloc_error();
}
fractal->img.pixels_ptr = mlx_get_data_addr(fractal->img.img_ptr,
&fractal->img.bpp, &fractal->img.line_len,
&fractal->img.endian);
events_init(fractal);
data_init(fractal);
}