-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
92 lines (85 loc) · 2.34 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: snicolet <snicolet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/20 16:19:41 by snicolet #+# #+# */
/* Updated: 2016/09/14 20:52:11 by snicolet ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt.h"
#include "draw.h"
#include "libft.h"
#include "keyboard.h"
#include "parser.h"
#include "menu.h"
#include "sda.h"
#include "arguments.h"
#include "interface.h"
static int sdl_loop(SDL_Event *event, t_rt *rt)
{
while (SDL_PollEvent(event))
{
if (sdl_event(event, rt))
{
ft_putendl("#exit requested...");
return (1);
}
}
return (0);
}
int rt_create_window(t_rt *rt)
{
if (draw_init(&rt->sys, rt->sys.geometry, "RT") < 0)
return (1);
if (!(rt->sys.screen = SDL_GetWindowSurface(rt->sys.win)))
{
ft_putendl("error: failed to get sdl surface from screen");
return (1);
}
draw_reset_surface(rt->sys.screen, COLOR_BLACK);
if (rt->settings.cfgbits & RT_CFGB_FULLSCREEN)
togglefs(rt);
return (0);
}
int rt_start(t_rt *rt)
{
SDL_UpdateWindowSurface(rt->sys.win);
while ((!sdl_loop(&rt->sys.events, rt)) && (!display(rt)))
SDL_Delay(1);
if (rt->keyboard & MENU)
menu_clean(rt, -1);
return (0);
}
int rt_normal(t_rt *rt, const char *path)
{
if (!path || ls_isdir(path) == 1)
menu_init(rt, path);
else
{
if (!(rt->root = rt_parser(path, rt)))
{
ft_putendl_fd("error.", 2);
return (1);
}
if (rt_checkcamera(rt))
{
if (!rt_create_window(rt))
rt_start(rt);
}
else
ft_putstr("#no camera\n");
}
ft_putendl("#normal end");
return (0);
}
int main(int ac, char **av)
{
t_rt rt;
rt_configure(&rt);
if (ac > 1)
return (rt_quit(&rt, arg_parse(&rt, ac - 1, av + 1)));
return (rt_quit(&rt, rt_normal(&rt, NULL)));
}