-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.c
89 lines (84 loc) · 2.7 KB
/
hook.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
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vvinogra <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/30 21:21:22 by vvinogra #+# #+# */
/* Updated: 2018/03/20 20:50:56 by vvinogra ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int mouse_func(int button, int x, int y, t_frac *frac)
{
image_clear(frac->im);
if (button == 4)
{
frac->zoom *= 1.1;
frac->y_move += (y - WIN_HEIGHT / 2) * 0.0005 / frac->zoom;
frac->x_move += (x - WIN_WIDTH / 2) * 0.0005 / frac->zoom;
}
if (button == 5)
{
frac->y_move += (y - WIN_HEIGHT / 2) * 0.0005 / frac->zoom;
frac->x_move += (x - WIN_WIDTH / 2) * 0.0005 / frac->zoom;
frac->zoom /= 1.1;
}
choose_frac(frac);
mlx_put_image_to_window(frac->mlx, frac->win, frac->im->image, 0, 0);
return (0);
}
int mouse_julia(int x, int y, t_frac *frac)
{
image_clear(frac->im);
if (frac->stop == 0)
frac->c_re = (x - WIN_WIDTH / 2)
/ (0.25 * frac->zoom * WIN_WIDTH) + frac->x_move;
if (frac->stop == 0)
frac->c_im = (y - WIN_HEIGHT / 2)
/ (0.25 * frac->zoom * WIN_HEIGHT) + frac->y_move;
frac->x_cur = x;
frac->y_cur = y;
if (frac->nb == 2)
ft_draw_jul(frac);
if (frac->nb == 6)
ft_draw_jul_s(frac);
mlx_put_image_to_window(frac->mlx, frac->win, frac->im->image, 0, 0);
return (0);
}
void helper(int keycode, t_frac *frac)
{
if (keycode == 53)
{
mlx_destroy_window(frac->mlx, frac->win);
exit(0);
}
if (keycode == 48 && frac->stop == 1)
{
frac->stop = 0;
frac->c_im = (frac->y_cur - WIN_HEIGHT / 2)
/ (0.25 * frac->zoom * WIN_HEIGHT) + frac->y_move;
frac->c_re = (frac->x_cur - WIN_WIDTH / 2)
/ (0.25 * frac->zoom * WIN_WIDTH) + frac->x_move;
}
else if (keycode == 48 && frac->stop == 0)
frac->stop = 1;
}
int key_func(int keycode, t_frac *frac)
{
if (keycode == 82 || keycode == 29)
{
frac->max_iter = 30;
frac->x_move = 0;
frac->y_move = 0;
frac->zoom = 1;
}
helper(keycode, frac);
image_clear(frac->im);
zoom_and_iter_move(keycode, frac);
color(keycode, frac);
choose_frac(frac);
mlx_put_image_to_window(frac->mlx, frac->win, frac->im->image, 0, 0);
return (0);
}