-
Notifications
You must be signed in to change notification settings - Fork 9
/
menu.c
61 lines (57 loc) · 1.84 KB
/
menu.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
#include <menu.h>
void server_or_client(SDL_Renderer *renderer, char *menu, TTF_Font *font){
SDL_Event e;
int pressed = false;
while (!pressed) {
if (SDL_PollEvent(&e)) {
if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.sym == SDLK_c) {
*menu = 'c';
pressed = true;
} else if (e.key.keysym.sym == SDLK_s) {
*menu = 's';
pressed = true;
}
}
}
usleep(200);
SDL_RenderClear(renderer);
disp_text(renderer, "[s]erver or [c]lient?", font, 240, 200);
SDL_RenderPresent(renderer);
}
}
void ask_for_ip(SDL_Renderer *renderer, TTF_Font *font, char *ip) {
memset(ip, ' ', 15);
SDL_Event e;
int position = 0;
int ok = false;
while (!ok) {
if (SDL_PollEvent(&e)) {
if (e.type == SDL_KEYDOWN) {
if ((e.key.keysym.sym >= SDLK_0 && e.key.keysym.sym <= SDLK_9) || e.key.keysym.sym == SDLK_PERIOD) {
if (position > 14) {
position = 14;
}
ip[position] = e.key.keysym.sym;
position++;
}
if (e.key.keysym.sym == SDLK_BACKSPACE) {
position--;
if (position < 0) {
position = 0;
}
ip[position] = ' ';
}
if (e.key.keysym.sym == SDLK_RETURN) {
ip[position] = 0;
ok = true;
}
}
}
usleep(200);
SDL_RenderClear(renderer);
disp_text(renderer, "ip addres", font, 240, 200);
disp_text(renderer, ip, font, 240, 230);
SDL_RenderPresent(renderer);
}
}