-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.c
86 lines (79 loc) · 2.47 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahmaymou <ahmaymou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/28 13:11:56 by ahmaymou #+# #+# */
/* Updated: 2023/01/29 17:24:37 by ahmaymou ### ########.fr */
/* */
/* ************************************************************************** */
#include "fract_ol.h"
int mouse_move(int x_pos, int y_pos, t_mlx_info *info)
{
if (!ft_strncmp(info->type, "julia", 6) && !info->stop)
{
info->fix = convert(x_pos, y_pos, info);
draw_shape(info);
}
return (0);
}
int mouse_scroll(int button, int x, int y, t_mlx_info *info)
{
double mouse_y;
double mouse_x;
mlx_clear_window(info->mlx_ptr, info->window_ptr);
mouse_x = info->xmin
+ (x * (info->xmax - info->xmin)) / 800;
mouse_y = info->ymin
+ (y * (info->ymax - info->ymin)) / HEIGHT;
if (button == 4)
{
info->xmin = mouse_x + (info->xmin - mouse_x) / info->zoom;
info->ymin = mouse_y + (info->ymin - mouse_y) / info->zoom;
info->xmax = mouse_x + (info->xmax - mouse_x) / info->zoom;
info->ymax = mouse_y + (info->ymax - mouse_y) / info->zoom;
}
if (button == 5)
{
info->xmin = mouse_x + (info->xmin - mouse_x) * info->zoom;
info->ymin = mouse_y + (info->ymin - mouse_y) * info->zoom;
info->xmax = mouse_x + (info->xmax - mouse_x) * info->zoom;
info->ymax = mouse_y + (info->ymax - mouse_y) * info->zoom;
}
draw_shape(info);
return (info->zoom);
}
int cross_destroy(void)
{
exit(0);
}
int destroy(t_mlx_info *info)
{
mlx_destroy_image(info->mlx_ptr, info->data.img);
mlx_destroy_window(info->mlx_ptr, info->window_ptr);
exit(0);
}
int change_pal(int key, t_mlx_info *info)
{
change_col(key, info);
change_shape(key, info);
if (key == 24)
{
if (info->iter_max <= 500)
info->iter_max += 5;
}
else if (key == 27)
{
if (info->iter_max > 5)
info->iter_max -= 5;
}
else if (key == 3)
{
info->stop++;
info->stop = info->stop % 2;
}
draw_shape(info);
return (0);
}