-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.c
69 lines (64 loc) · 2.05 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmack <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/30 07:52:41 by tmack #+# #+# */
/* Updated: 2016/10/05 07:08:49 by tmack ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int mouse_hook(int keycode, int x, int y, t_frac *m)
{
if (keycode == 4)
{
m->iterate_max++;
m->pan_x += (((double)x - m->s_y_max / 2) / m->s_x_max / 2) /
m->zoom * 10;
m->pan_y += (((double)y - m->s_x_max / 2) / m->s_y_max / 2) /
m->zoom * 10;
m->zoom *= 1.1;
}
if (keycode == 5)
{
m->pan_x += (((double)x - m->s_y_max / 2) /
m->s_x_max / 2) / m->zoom * 10;
m->pan_y += (((double)y - m->s_x_max / 2) /
m->s_y_max / 2) / m->zoom * 10;
m->zoom /= 1.1;
}
chose_fractal(m);
return (0);
}
int expose(t_frac *m)
{
chose_fractal(m);
return (0);
}
int key_hook(int keycode, t_frac *win)
{
if (keycode == 53)
exit(0);
if (keycode == 123)
win->pan_x += 10 / (win->zoom * 20);
if (keycode == 124)
win->pan_x -= 10 / (win->zoom * 20);
if (keycode == 126)
win->pan_y += 10 / (win->zoom * 20);
if (keycode == 125)
win->pan_y -= 10 / (win->zoom * 20);
chose_fractal(win);
return (0);
}
int mouse_move(int x, int y, t_frac *m)
{
if (x >= 0 && y >= 0 && x <= m->s_x_max && y <= m->s_y_max)
{
m->w_x_min = (double)x / (double)m->s_x_max * 4 - 2;
m->w_y_max = (double)y / (double)m->s_y_max * 4 - 2;
chose_fractal(m);
}
return (0);
}