-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_output_service.c
99 lines (91 loc) · 2.82 KB
/
menu_output_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* menu_output_service.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jjacobso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/22 19:05:09 by jjacobso #+# #+# */
/* Updated: 2019/04/22 19:23:48 by jjacobso ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
char *nspaces(int n)
{
char *s;
if (n < 0)
error("Window too small to open menu");
if (!(s = ft_strnew(n)))
error("Malloc error");
while (--n >= 0)
s[n] = ' ';
return (s);
}
char *clr_to_line(int clr)
{
char *s;
char *w;
int r;
int g;
int b;
r = (clr & 0xFF0000) >> 16;
g = (clr & 0xFF00) >> 8;
b = (clr & 0xFF);
if (!(s = ft_strnew(ft_nlen(r, 10) + ft_nlen(g, 10) + ft_nlen(b, 10)
+ ft_strlen("( , , )"))))
error("Malloc error");
s = ft_strcat(s, "(");
s = ft_strcat(s,
(w = ft_itoa(r)));
ft_memdel((void **)&w);
s = ft_strcat(s, ", ");
s = ft_strcat(s,
(w = ft_itoa(g)));
ft_memdel((void **)&w);
s = ft_strcat(s, ", ");
s = ft_strcat(s,
(w = ft_itoa(b)));
ft_memdel((void **)&w);
return ((s = ft_strcat(s, ")")));
}
char *coord_to_line(t_coord c)
{
char *s;
char *w;
if (!(s = ft_strnew(ft_nlen(c.x, 10) + ft_nlen(c.y, 10) + ft_nlen(c.z, 10)
+ ft_strlen("( , , )"))))
error("Malloc error");
s = ft_strcat(s, "(");
s = ft_strcat(s,
(w = ft_itoa(c.x)));
ft_memdel((void **)&w);
s = ft_strcat(s, ", ");
s = ft_strcat(s,
(w = ft_itoa(c.y)));
ft_memdel((void **)&w);
s = ft_strcat(s, ", ");
s = ft_strcat(s,
(w = ft_itoa(c.z)));
ft_memdel((void **)&w);
s = ft_strcat(s, ")");
return (s);
}
void rgb_print(t_view *view, int line, int clr, char *s)
{
if (OPTIONS.print_menu_bg)
{
mlx_string_put(view->id, view->win, view->ww - MENU.w + 15
+ 10 * (ft_strlen(s)),
17 * (line * 2) + 5, clr & 0xFF0000, "r");
mlx_string_put(view->id, view->win, view->ww - MENU.w + 15
+ 10 * (ft_strlen(s)) + 10,
17 * (line * 2) + 5, clr & 0xFF00, "g");
mlx_string_put(view->id, view->win, view->ww - MENU.w + 15
+ 10 * (ft_strlen(s)) + 20,
17 * (line * 2) + 5, clr & 0xFF, "b");
}
else
mlx_string_put(view->id, view->win, view->ww - MENU.w + 15
+ 10 * (ft_strlen(s)),
17 * (line * 2) + 5, rgb(255, 145, 0), "rgb");
}