-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse_events.c
81 lines (73 loc) · 2.73 KB
/
mouse_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
78
79
80
81
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mouse_events.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kprytkov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/06/06 16:19:34 by kprytkov #+# #+# */
/* Updated: 2018/06/06 16:19:35 by kprytkov ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/fractol.h"
static int mouse_zoom_in(int x, int y, t_env *e)
{
long double zoom_factor;
long double move_x;
long double move_y;
move_x = (long double)x * (long double)((e->max_x - e->min_x)
/ (long double)WIDTH) + (long double)e->min_x;
move_y = (long double)y * (long double)((e->max_y - e->min_y)
/ (long double)HEIGHT) + (long double)e->min_y;
zoom_factor = 0.9f;
e->zoom *= zoom_factor;
e->max_x = e->max_x * zoom_factor + move_x * (1 - zoom_factor);
e->min_x = e->min_x * zoom_factor + move_x * (1 - zoom_factor);
e->max_y = e->max_y * zoom_factor + move_y * (1 - zoom_factor);
e->min_y = e->min_y * zoom_factor + move_y * (1 - zoom_factor);
next_draw(e);
return (0);
}
static int mouse_zoom_out(int x, int y, t_env *e)
{
long double zoom_factor;
long double move_x;
long double move_y;
if (e->zoom <= 2)
{
move_x = (long double)x * (long double)((e->max_x - e->min_x)
/ (long double)WIDTH) + e->min_x;
move_y = (long double)y * ((long double)(e->max_y - e->min_y)
/ (long double)HEIGHT) + e->min_y;
zoom_factor = 1.1f;
e->zoom *= zoom_factor;
e->max_x = e->max_x * zoom_factor + move_x * (1 - zoom_factor);
e->min_x = e->min_x * zoom_factor + move_x * (1 - zoom_factor);
e->max_y = e->max_y * zoom_factor + move_y * (1 - zoom_factor);
e->min_y = e->min_y * zoom_factor + move_y * (1 - zoom_factor);
next_draw(e);
}
return (0);
}
int mouse_zoom(int keycode, int x, int y, t_env *e)
{
if (keycode == 5 || keycode == 1)
mouse_zoom_in(x, y, e);
else if (keycode == 4 || keycode == 2)
mouse_zoom_out(x, y, e);
return (0);
}
int mouse_for_julia(int x, int y, t_env *e)
{
long double new_x;
long double new_y;
if (e->julia_mode_on == 1)
{
new_x = ft_map(x, add_params(0, WIDTH, -1, 1));
new_y = ft_map(y, add_params(0, HEIGHT, -1, 1));
e->c_re = new_x;
e->c_im = new_y;
next_draw(e);
}
return (0);
}