-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.c
121 lines (112 loc) · 2.6 KB
/
controls.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* controls.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pnoutere <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/04 17:23:50 by pnoutere #+# #+# */
/* Updated: 2022/04/06 13:21:25 by pnoutere ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void rotate_key(t_data *coords)
{
if (coords->status == 0)
{
coords->parallel = 0;
coords->status = 1;
coords->rotation = 0.8;
}
else if (coords->status == 1)
{
coords->status = 2;
coords->rotation = 0.01;
}
else if (coords->status == 2)
{
coords->status = 3;
coords->rotation = 0.4;
}
else if (coords->status == 3)
{
coords->status = 0;
coords->parallel = 1;
}
}
int deal_key(int key, void *param)
{
t_data *coords;
coords = param;
if (key == ARROW_UP)
{
coords->z++;
initiate_fdf(coords);
}
if (key == ARROW_DOWN)
{
coords->z--;
initiate_fdf(coords);
}
if (key == MAIN_PAD_ESC)
{
mlx_destroy_window(coords->mlx, coords->win);
exit (0);
}
if (key == MAIN_PAD_P)
{
rotate_key(coords);
initiate_fdf(coords);
}
return (0);
}
int deal_mouse(int key, int x, int y, void *param)
{
t_data *coords;
coords = param;
(void)x;
(void)y;
if (key == MOUSE_LEFT_BUTTON)
coords->state *= -1;
if (key == MOUSE_SCROLL_UP)
{
coords->scale += 2;
mlx_clear_window(coords->mlx, coords->win);
initiate_fdf(coords);
}
if (key == MOUSE_SCROLL_DOWN)
{
coords->scale -= 2;
initiate_fdf(coords);
}
return (0);
}
void ctrl_hooks(t_data *img)
{
mlx_hook(img->win, 2, 0, &deal_key, img);
mlx_hook(img->win, 4, 0, &deal_mouse, img);
mlx_hook(img->win, 5, 0, &deal_mouse, img);
mlx_hook(img->win, 6, 0, &deal_mouse_movement, img);
}
int deal_mouse_movement(int x, int y, void *param)
{
t_data *coords;
coords = param;
(void)x;
if (coords->state == 1)
{
if (y > coords->rotation_y)
{
coords->rotation += 0.02;
initiate_fdf(coords);
}
else
{
initiate_fdf(coords);
coords->rotation -= 0.02;
}
}
coords->rotation_x = x;
coords->rotation_y = y;
return (0);
}