-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse_event.c
95 lines (86 loc) · 2.73 KB
/
mouse_event.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
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mouse_event.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dmelessa <dmelessa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/08/05 18:41:01 by dmelessa #+# #+# */
/* Updated: 2019/08/20 13:55:00 by dmelessa ### ########.fr */
/* */
/* ************************************************************************** */
#include "frctl.h"
void zoom_in(t_param_ptr p, int x, int y)
{
int i;
i = -1;
p->frctl.zoom *= 4;
if (p->cntrl.follow_zoom)
{
p->frctl.startx = p->frctl.startx + 2 * p->frctl.r1 * x
/ WIDTH - p->frctl.r / p->frctl.zoom;
p->frctl.starty = p->frctl.starty - 2 * p->frctl.r1 * y
/ HEIGHT + p->frctl.r / p->frctl.zoom;
}
else
{
p->frctl.startx = p->frctl.startx + p->frctl.r1 - p->frctl.r
/ p->frctl.zoom;
p->frctl.starty = p->frctl.starty - p->frctl.r1 + p->frctl.r
/ p->frctl.zoom;
}
p->frctl.r1 = p->frctl.r / p->frctl.zoom;
while (++i < NTHREADS)
(p->thread_args + i)->frctl = p->frctl;
draw_fractal(p);
}
void zoom_out(t_param_ptr p, int x, int y)
{
int i;
i = -1;
p->frctl.zoom *= 0.95;
p->frctl.startx = p->frctl.startx + p->frctl.r1 - p->frctl.r
/ p->frctl.zoom;
p->frctl.starty = p->frctl.starty - p->frctl.r1 + p->frctl.r
/ p->frctl.zoom;
p->frctl.r1 = p->frctl.r / p->frctl.zoom;
if (p->frctl.zoom < 1.)
{
p->frctl.startx = p->frctl_tb[p->frctl.type].startx;
p->frctl.starty = p->frctl_tb[p->frctl.type].starty;
p->frctl.r = p->frctl_tb[p->frctl.type].r;
p->frctl.r1 = p->frctl_tb[p->frctl.type].r1;
p->frctl.zoom = p->frctl_tb[p->frctl.type].zoom;
p->frctl.zoom_coord = p->frctl_tb[p->frctl.type].zoom_coord;
}
while (++i < NTHREADS)
(p->thread_args + i)->frctl = p->frctl;
draw_fractal(p);
}
int mouse_press(int button, int x, int y, void *param)
{
t_param_ptr p;
p = param;
if (button == 4)
zoom_in(p, x, y);
if (button == 5)
zoom_out(p, 400, 400);
return (0);
}
int mouse_move(int x, int y, void *param)
{
t_param_ptr p;
int i;
p = param;
if (p->frctl.type != julia)
return (1);
if (p->cntrl.follow_mouse == 0)
return (0);
i = -1;
p->frctl.c.r = 2. / WIDTH * x - 1;
p->frctl.c.i = 2. / HEIGHT * y - 1;
while (++i < NTHREADS)
(p->thread_args + i)->frctl = p->frctl;
draw_fractal(p);
return (0);
}