-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoom.c
57 lines (53 loc) · 1.94 KB
/
zoom.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zoom.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfortin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/15 17:54:10 by jfortin #+# #+# */
/* Updated: 2016/03/19 13:49:45 by jfortin ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
static void ft_zoom_out(int x, int y, t_env *e)
{
if (e->zoom > 250)
{
e->zoom /= 2;
e->tmpx = e->x1 + x * (e->x2 - e->x1) / IM_X;
e->tmpy = e->y1 + y * (e->y2 - e->y1) / WIN_Y;
e->tmpx2 = e->x1;
e->tmpy2 = e->y1;
e->x1 = e->tmpx - (e->x2 - e->x1);
e->x2 = e->tmpx + (e->x2 - e->tmpx2);
e->y1 = e->tmpy - (e->y2 - e->y1);
e->y2 = e->tmpy + (e->y2 - e->tmpy2);
}
}
static void ft_zoom_in(int x, int y, t_env *e)
{
e->zoom *= 2;
e->tmpx = e->x1 + x * (e->x2 - e->x1) / (IM_X - 50);
e->tmpy = e->y1 + y * (e->y2 - e->y1) / (WIN_Y - 20);
e->tmpx2 = e->x1;
e->tmpy2 = e->y1;
e->x1 = e->tmpx - (e->x2 - e->x1) / 4;
e->x2 = e->tmpx + (e->x2 - e->tmpx2) / 4;
e->y1 = e->tmpy - (e->y2 - e->y1) / 4;
e->y2 = e->tmpy + (e->y2 - e->tmpy2) / 4;
}
int ft_mouse_hook(int keycode, int x, int y, t_env *e)
{
if (!e->check)
ft_settings(e);
if (y > 0 && e->check)
{
if ((keycode == 1 || keycode == 5) && x <= IM_X)
ft_zoom_in(x, y, e);
if ((keycode == 2 || keycode == 4) && x <= IM_X)
ft_zoom_out(x, y, e);
}
e->check = 1;
return (0);
}