-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.c
More file actions
72 lines (66 loc) · 2.24 KB
/
handlers.c
File metadata and controls
72 lines (66 loc) · 2.24 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handlers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: moabed <moabed@student.42amman.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/09 23:50:57 by moabed #+# #+# */
/* Updated: 2026/01/17 16:56:39 by moabed ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int mouse_handler(int button, int x, int y, t_fractal *fractal)
{
(void)x;
(void)y;
if (button == Button4)
fractal->zoom *= 0.95;
else if (button == Button5)
fractal->zoom *= 1.05;
fractal_render(fractal);
return (0);
}
int image_handler(t_fractal *fractal)
{
mlx_put_image_to_window(fractal->mlx_connection, fractal->mlx_window,
fractal->img.img, 0, 0);
return (0);
}
int key_handler(int key, t_fractal *fractal)
{
if (key == XK_Escape)
close_handler(fractal);
if (key == Button5)
{
fractal->zoom *= 0.95;
fractal_render(fractal);
}
else if (key == Button4)
{
fractal->zoom *= 1.05;
fractal_render(fractal);
}
return (0);
}
int close_handler(t_fractal *fractal)
{
mlx_destroy_image(fractal->mlx_connection, fractal->img.img);
mlx_destroy_window(fractal->mlx_connection, fractal->mlx_window);
mlx_destroy_display(fractal->mlx_connection);
free(fractal->mlx_connection);
exit(0);
return (0);
}
void mlx(t_fractal *fractal)
{
fractal_init(fractal);
fractal_render(fractal);
mlx_hook(fractal->mlx_window, ButtonPress, ButtonPressMask, mouse_handler,
fractal);
mlx_hook(fractal->mlx_window, DestroyNotify, StructureNotifyMask,
close_handler, fractal);
mlx_hook(fractal->mlx_window, KeyPress, KeyPressMask, key_handler, fractal);
mlx_loop_hook(fractal->mlx_connection, image_handler, fractal);
mlx_loop(fractal->mlx_connection);
}