-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.c
63 lines (56 loc) · 2.27 KB
/
mouse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mouse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alamy <alamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/06 14:59:39 by alamy #+# #+# */
/* Updated: 2018/03/16 16:09:40 by alamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
double interpolate(double start, double end, double interpolation)
{
return (start + ((end - start) * interpolation));
}
void t_zoom(t_env *tmp, double mouse_re, double mouse_im, double zoom_factor)
{
double interpolation;
interpolation = 1.0 / zoom_factor;
tmp->f.xmin = interpolate(mouse_re, tmp->f.xmin, interpolation);
tmp->f.ymin = interpolate(mouse_im, tmp->f.ymin, interpolation);
tmp->f.xmax = interpolate(mouse_re, tmp->f.xmax, interpolation);
tmp->f.ymax = interpolate(mouse_im, tmp->f.ymax, interpolation);
}
int my_mouse_funct(int button, int x, int y, t_env *tmp)
{
double mouse_re;
double mouse_im;
mouse_re = (double)x / (WINDOW_L / (tmp->f.xmax - tmp->f.xmin))
+ tmp->f.xmin;
mouse_im = (double)y / (WINDOW_H / (tmp->f.ymax - tmp->f.ymin))
+ tmp->f.ymin;
if (button == CLIC_LEFT)
t_zoom(tmp, mouse_re, mouse_im, 2);
if (button == CLIC_RIGHT)
t_zoom(tmp, mouse_re, mouse_im, 0.5);
if (button == SCROLL_UP)
t_zoom(tmp, mouse_re, mouse_im, 2);
if (button == SCROLL_DOWN)
t_zoom(tmp, mouse_re, mouse_im, 0.5);
if (button == 8)
t_zoom(tmp, mouse_re, mouse_im, 0.5);
ft_redraw_image(tmp);
return (0);
}
int my_motion_hook(int x, int y, t_env *tmp)
{
if (x >= 0 && y >= 0 && x <= WINDOW_L && y <= WINDOW_H && tmp->f.stop != 1)
{
tmp->f.c_re = (double)x / WINDOW_L * 4 - 2;
tmp->f.c_im = (double)y / WINDOW_H * 4 - 2;
}
ft_redraw_image(tmp);
return (0);
}