-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandle_input.c
82 lines (74 loc) · 2.22 KB
/
handle_input.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alcohen <alcohen@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 16:03:34 by alcohen #+# #+# */
/* Updated: 2020/08/10 19:36:35 by alcohen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void handle_zoom(t_mlx *mlx, int button, int x, int y)
{
if (button == 4 && mlx->zoom > MAX_ZOOM)
{
mlx->zoom /= 1.1;
mlx->offset[0] = (mlx->offset[0] +
(x - WINDOW_WIDTH / 2) * 0.25) * 1.1 + 60;
mlx->offset[1] = (mlx->offset[1] +
(y - WINDOW_HEIGHT / 2) * 0.25) * 1.1 + 40;
}
if (button == 5 && mlx->zoom < MIN_ZOOM)
{
mlx->zoom *= 1.1;
mlx->offset[0] = (mlx->offset[0] +
(x - WINDOW_WIDTH / 2) * 0.25) / 1.1 - 60;
mlx->offset[1] = (mlx->offset[1] +
(y - WINDOW_HEIGHT / 2) * 0.25) / 1.1 - 40;
}
}
int mouse_event(int button, int x, int y, void *param)
{
t_mlx *mlx;
mlx = param;
if (button == 4 || button == 5)
handle_zoom(mlx, button, x, y);
if (button == 1)
{
mlx->mouse_x = x;
mlx->mouse_y = y;
mlx->mouse_pressed = 1;
}
handle_drawing(mlx);
return (0);
}
int mouse_release(int button, int x, int y, void *param)
{
t_mlx *mlx;
(void)button;
(void)x;
(void)y;
mlx = param;
mlx->mouse_pressed = 0;
return (0);
}
int mouse_move(int x, int y, void *param)
{
t_mlx *mlx;
mlx = param;
if (mlx->mouse_pressed)
{
if (x != mlx->mouse_x)
mlx->offset[0] -= x - mlx->mouse_x;
if (y != mlx->mouse_y)
mlx->offset[1] -= y - mlx->mouse_y;
handle_drawing(mlx);
}
mlx->mouse_x = x;
mlx->mouse_y = y;
if (mlx->fractal == JULIA && !mlx->lock_mouse)
handle_drawing(mlx);
return (0);
}