-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse.c
More file actions
63 lines (56 loc) · 1.68 KB
/
mouse.c
File metadata and controls
63 lines (56 loc) · 1.68 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mouse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ishakuro <ishakuro@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/18 16:31:42 by ishakuro #+# #+# */
/* Updated: 2022/06/07 11:28:50 by ishakuro ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int mouse(int button, int x, int y, void *param)
{
t_mlx *mlx;
(void)x;
(void)y;
mlx = (t_mlx *)param;
if (button == 4)
mlx->map->zoom -= 1;
if (button == 5)
mlx->map->zoom += 1;
else if (button == 1)
{
mlx->mouse->x = x;
mlx->mouse->y = y;
mlx->onclick = 1;
}
draw(mlx);
return (0);
}
int mouse_release(int button, int x, int y, void *param)
{
t_mlx *mlx;
mlx = (t_mlx *)param;
(void)x;
(void)y;
(void)button;
mlx->onclick = 0;
return (0);
}
int mouse_move(int x, int y, void *param)
{
t_mlx *mlx;
mlx = (t_mlx *)param;
if (!mlx->onclick)
return (0);
mlx->mouse->prev_x = mlx->mouse->x;
mlx->mouse->prev_y = mlx->mouse->y;
mlx->mouse->x = x;
mlx->mouse->y = y;
mlx->offset_x += x - mlx->mouse->prev_x;
mlx->offset_y += y - mlx->mouse->prev_y;
draw(mlx);
return (0);
}