3 #include <glib.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <ncurses.h>
7 #include <string.h>
9 #include "ncmpc.h"
10 #include "colors.h"
13 gpointer get_input(void *null)
14 {
15 int key;
16 while(key = getch())
17 {
18 if(key == 'q')
19 {
20 exit(0);
21 }
22 }
23 return;
24 }
26 void draw_message(char *msg)
27 {
28 int rows, cols;
29 getmaxyx(stdscr, rows, cols);
30 mvaddstr(rows-1, (cols/2)-(strlen(msg)/2), msg);
31 refresh();
32 }
35 /*void draw_title()
36 {
37 colors_use(stdscr, COLOR_TITLE_BOLD);
38 mvaddstr(rows/2+1, COLS/2, VERSION);
39 colors_use(stdscr, COLOR_TITLE_BOLD);
40 mvaddstr(rows/2-1, x, PACKAGE);
41 refresh();
42 }
43 */
44 gboolean advance_version()
45 {
46 int rows, cols;
47 getmaxyx(stdscr, rows, cols);
48 static int x = 0;
49 if(x == 0)
50 {
51 x = cols - strlen(VERSION);
52 }
53 colors_use(stdscr, COLOR_TITLE_BOLD);
54 mvaddstr(rows/2+1, x--, VERSION);
55 mvhline(rows/2+1, x+strlen(VERSION)+1, ' ', cols);
56 refresh();
57 if(x == cols/2) return FALSE;
58 return TRUE;
59 }
62 gboolean advance_name()
63 {
64 int rows, cols;
65 getmaxyx(stdscr, rows, cols);
66 static int x = 0;
67 colors_use(stdscr, COLOR_TITLE_BOLD);
68 mvaddstr(rows/2-1, x, PACKAGE);
69 mvhline(rows/2-1, 0, ' ', x);
70 refresh();
71 if(x + strlen(PACKAGE) == cols/2) return FALSE;
72 x++;
73 return TRUE;
74 }
76 gboolean draw_animation(gpointer *data)
77 { //need this to execute both functions, even if one of them return TRUE
78 if(advance_name() == FALSE && advance_version() == FALSE || advance_name() == TRUE && advance_version() == FALSE)
79 {
80 // system("sleep 8");
81 g_main_loop_quit((GMainLoop*) data);
82 // g_source_attach(((int*)data)[1], data);
83 return FALSE;
84 }
86 return TRUE;
87 }
89 void drawx()
90 {
91 // g_thread_create(get_input, NULL, FALSE, NULL);
92 int rows, cols;
93 getmaxyx(stdscr, rows, cols);
95 fprintf(stderr, "%d", rows/2);
97 mvhline(rows/2, 0, ACS_HLINE , cols);
98 draw_message("Connecting...");
99 //advance_version();
100 refresh();
102 GMainContext *cont = g_main_context_new();
103 GMainLoop *loop = g_main_loop_new(cont, FALSE);
105 GSource *frame = g_timeout_source_new(3);
106 GSource *state = g_timeout_source_new(100);
107 GSource *stopper = g_timeout_source_new(200);
109 void *blubb = malloc(sizeof(GMainLoop*)+sizeof(GSource*));
110 blubb = loop;
111 ((int*)blubb)[1] = stopper;
113 g_source_set_callback(frame, draw_animation ,blubb, NULL);
114 g_source_attach(frame, g_main_loop_get_context(loop));
116 g_main_loop_run(loop);
117 }
120 void draw_splash()
121 {
122 drawx();
123 }
125 //int draw_frame