-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.c
57 lines (49 loc) · 1.88 KB
/
hooks.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: stigkas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/29 16:36:40 by stigkas #+# #+# */
/* Updated: 2024/03/07 10:31:14 by stigkas ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/fractol.h"
void zoom_in(t_fractal *f)
{
f->zoom *= 3;
fractal_render(f);
}
void zoom_out(t_fractal *f)
{
f->zoom /= 3;
fractal_render(f);
}
void ft_keyhook(mlx_key_data_t keydata, void *param)
{
t_fractal *fractal;
fractal = param;
(void)keydata;
if (mlx_is_key_down(fractal->mlx_connection, MLX_KEY_ESCAPE))
mlx_close_window(fractal->mlx_connection);
else if (mlx_is_key_down(fractal->mlx_connection, MLX_KEY_UP))
fractal->shift_y -= 0.05;
else if (mlx_is_key_down(fractal->mlx_connection, MLX_KEY_DOWN))
fractal->shift_y += 0.05;
else if (mlx_is_key_down(fractal->mlx_connection, MLX_KEY_LEFT))
fractal->shift_x += 0.05;
else if (mlx_is_key_down(fractal->mlx_connection, MLX_KEY_RIGHT))
fractal->shift_x -= 0.05;
fractal_render(fractal);
}
void ft_scrollhook(double xdelta, double ydelta, void *param)
{
t_fractal *fractal;
fractal = param;
if (ydelta > 0 || xdelta > 0)
zoom_in(fractal);
else if (ydelta < 0 || xdelta < 0)
zoom_out(fractal);
fractal_render(fractal);
}