-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.c
77 lines (72 loc) · 2.41 KB
/
events.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* events.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jqueijo- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 12:20:27 by jqueijo- #+# #+# */
/* Updated: 2024/05/17 12:56:07 by jqueijo- ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int handle_mouse(int button, t_fractal *fractal)
{
if (button == Button4)
fractal->zoom *= 0.95;
else if (button == Button5)
fractal->zoom *= 1.05;
fractal_render(fractal);
return (0);
}
int handle_close(t_fractal *fractal)
{
mlx_destroy_image(fractal->mlx_ptr, fractal->img.img_ptr);
mlx_destroy_window(fractal->mlx_ptr, fractal->win_ptr);
mlx_destroy_display(fractal->mlx_ptr);
free(fractal->mlx_ptr);
exit(EXIT_SUCCESS);
}
int change_color_range(t_fractal *fractal)
{
if (fractal->color_range == 1)
{
fractal->cmin = BLACK;
fractal->cmax = WHITE;
fractal->color_range = 2;
}
else if (fractal->color_range == 2)
{
fractal->cmin = WHITE;
fractal->cmax = BLACK;
fractal->color_range = 3;
}
else if (fractal->color_range == 3)
{
fractal->cmin = BLACK;
fractal->cmax = ORANGE;
fractal->color_range = 1;
}
return (0);
}
int handle_keypress(int keysym, t_fractal *fractal)
{
if (keysym == XK_Escape)
handle_close(fractal);
else if (keysym == XK_Left)
fractal->shift_x += (0.05 * fractal->zoom);
else if (keysym == XK_Right)
fractal->shift_x -= (0.05 * fractal->zoom);
else if (keysym == XK_Up)
fractal->shift_y += (0.05 * fractal->zoom);
else if (keysym == XK_Down)
fractal->shift_y -= (0.05 * fractal->zoom);
else if (keysym == XK_p && fractal->iter_definition <= 502)
fractal->iter_definition += 10;
else if (keysym == XK_m && fractal->iter_definition >= 10)
fractal->iter_definition -= 10;
else if (keysym == XK_c)
change_color_range(fractal);
fractal_render(fractal);
return (0);
}