-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio_service.c
84 lines (79 loc) · 2.09 KB
/
io_service.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* io_service.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jjacobso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 17:54:39 by jjacobso #+# #+# */
/* Updated: 2019/05/16 20:14:14 by jjacobso ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int io_is_reading(t_view *view)
{
return (IO.read_mode > 0);
}
void io_set_coord(t_view *view)
{
if (IO.to_read == 'x')
LAMP.dot.x = IO.input;
else if (IO.to_read == 'y')
LAMP.dot.y = IO.input;
else if (IO.to_read == 'z')
LAMP.dot.z = IO.input;
set_line_color(view);
apply_light(view);
}
int io_read_clr(t_view *view, int key)
{
if (!ft_inrange(IO.input, 0, 255))
{
IO.read_err = WRONG_NUM;
set_clr(view);
print_map(view);
IO.read_err = 0;
IO.input = 0;
IO.read_mode = 0;
return (-1);
}
if (ft_nlen(IO.input, 10) == 3 || key == KEY_ENTER)
{
IO.read_err = 0;
set_clr(view);
print_map(view);
IO.read_mode = 0;
IO.input = 0;
return (1);
}
set_clr(view);
print_map(view);
return (0);
}
int io_read_coord(t_view *view, int key)
{
if (!ft_inrange(IO.input, 0, 10000))
{
IO.read_err = WRONG_NUM;
LAMP.dot = IO.saved_coord;
print_map(view);
IO.read_err = 0;
IO.input = 0;
IO.read_mode = 0;
return (-1);
}
if (ft_nlen(IO.input, 10) == 5 || key == KEY_ENTER)
{
IO.read_err = 0;
io_set_coord(view);
project(view);
print_map(view);
IO.read_mode = 0;
IO.input = 0;
return (1);
}
io_set_coord(view);
project(view);
print_map(view);
return (0);
}