/* Initialize the search screen */ void search_screen_init(Screen *this_screen) { int cur_start_row = 0; this_screen->wl_size = WL_SIZE; this_screen->win_list = win; this_screen->screen_enter = screen_enter; this_screen->screen_exit = screen_exit; this_screen->keypress = keypress; win_init(&title_win, cur_start_row, 0, WL_SMALL_HEIGHT, 128, 1, win_txt[0]); title_win.font = SMALLFONT; title_win.flags |= WINFLG_CENTER; title_win.fg_color = WHITE; title_win.bg_color = BLACK; win_new_text(&title_win, "Search Artist"); cur_start_row += WL_SMALL_HEIGHT; win_init(&input_win, cur_start_row, 0, 20, 128, 1, win_txt[1]); input_win.font = BIGFONT; input_win.txt_offs_row = 3; win_new_text(&input_win, " "); cur_start_row += 20; win_init(&num_results_win, cur_start_row, 0, WL_SMALL_HEIGHT, 128, 0, win_txt[2]); num_results_win.font = SMALLFONT; num_results_win.fg_color = BLACK; num_results_win.bg_color = DARK_GREY; win_new_text(&num_results_win, ""); cur_start_row += WL_SMALL_HEIGHT; init_scroll_list(&result_list, &(win[3]), win_txt[3], WIN_TXT_SIZE, RL_SIZE, &get_result, cur_start_row); }
/* The volume has changed. Show new value. */ void view_volume_changed(int vol){ char newstr[VOLSTR_SIZE]; char number[20]; char *numstr; if (vol > 0) win_new_text(&speaker_win, "\xB8"); // speaker icon on else win_new_text(&speaker_win, "\xB9"); //speaker off strlcpy (newstr, "", sizeof(newstr)); if (vol < 0) strlcat(newstr, "?? \n", sizeof(newstr)); else { numstr = get_digits(vol, number, 0); strlcat(newstr, numstr, sizeof(newstr)); strlcat(newstr, " %\n", sizeof(newstr)); }; win_new_text(&volume_win, newstr); if (vol >= 0){ if ((win->flags & WINFLG_VISIBLE)) draw_trianglebar( vol_ramp_win.start_row+1, vol_ramp_win.start_col+1, vol_ramp_win.width-2, vol_ramp_win.height-2, vol_ramp_win.fg_color, vol_ramp_win.bg_color, vol_ramp_win.cur_char, vol/2 ); vol_ramp_win.cur_char = vol/2; }; };
/* The current song or the playlistlength (or both) has changed. Redraw the caption window */ void view_pos_changed(){ char newstr[30]; char number[20]; char *numstr; int cur_song, pl_length; cur_song = mpd_get_pos(); if (cur_song == SONG_UNKNOWN) { win_new_text(&caption_win,""); return; }; if (cur_song == NO_SONG){ win_new_text(&caption_win,"No current song"); return; }; if (is_stream() == 1) strlcpy(newstr, "Station ", sizeof(newstr)); else strlcpy(newstr, "Song ", sizeof(newstr)); numstr = get_digits(cur_song + 1, number, 0); // user readable song pos starts with 1, not 0 strlcat(newstr, numstr, sizeof(newstr)); pl_length = mpd_get_pl_length(); if (pl_length >= 0){ strlcat(newstr, " of ", sizeof(newstr)); numstr = get_digits(pl_length, number, 0); strlcat(newstr, numstr, sizeof(newstr)); }; win_new_text(&caption_win, newstr); };
/* Initialize the playing screen We clear the whole screen. */ void info_screen_init(Screen *this_screen) { this_screen->wl_size = WL_SIZE; this_screen->win_list = win; this_screen->screen_enter = screen_enter; this_screen->screen_exit = screen_exit; this_screen->keypress = keypress; win_init(&title_win, 0, 0, 40, 128, 1, win_txt[0]); title_win.font = BIGFONT; title_win.flags |= WINFLG_CENTER; title_win.fg_color = WHITE; title_win.bg_color = BLACK; win_new_text(&title_win, "Error "); win_init(&info_win, 40, 0, 50, 128, 1, win_txt[1]); info_win.font = MEDIUMFONT; info_win.flags |= WINFLG_CENTER; win_init(&help_win, 90, 0, 160-40-50, 128, 1, win_txt[2]); help_win.font = MEDIUMFONT; help_win.flags |= WINFLG_CENTER; win_new_text(&help_win, "Test Message"); }
static void info_mpd_dead(){ win_new_text(&title_win, "Error"); win_new_text(&info_win, "Communication with MPD broken."); win_new_text(&help_win, "Check if MPD is still running and reachable via LAN."); show_new_screen(INFO_SCREEN); }
static void info_playlist_empty(){ win_new_text(&title_win, "Info"); win_new_text(&info_win, "Playlist is empty."); win_new_text(&help_win, "Select a new playlist or check mpd configuration."); show_new_screen(INFO_SCREEN); }
static void info_end_of_playlist(){ win_new_text(&title_win, "Info"); win_new_text(&info_win, "End of playlist reached."); win_new_text(&help_win, "Select a new track or a new playlist."); show_new_screen(INFO_SCREEN); }
void view_state_changed(enum PLAYSTATE state){ if (state == PLAY) win_new_text(&state_win, "\xB3"); // play icon == b3 else if (state == PAUSE) win_new_text(&state_win, "\xBA"); // pause icon == ba else if (state == STOP) win_new_text(&state_win, "\xA0"); // pause icon == a0 };
void popup(char *text, int time_out, int (*keypress_handler) (struct Screen *, int)){ if ( ! popup_active ){ popup_active = 1; screen_visible(cur_screen, 0); popup_save(); popup_win.flags |= WINFLG_VISIBLE; if (keypress_handler != NULL) popup_keypress_handler = keypress_handler; set_keypress_handler(popup_keypress_dispatch); if (time_out > 0){ timer_add(&popup_tmr, time_out, 0); close_popup_task = task_add(&close_popup); } } else { // already a popup active if (time_out > 0){ if (timed_popup) timer_set(&popup_tmr, time_out, 0); else { timer_add(&popup_tmr, time_out, 0); close_popup_task = task_add(close_popup); }; } else { if (timed_popup) { task_del(close_popup_task); timer_del(&popup_tmr); }; }; }; timed_popup = (time_out > 0); win_new_text(&popup_win, text); win_redraw(&popup_win); };
void view_time_changed(int te, int tt){ char newstr[TIMESTR_LEN]; int newval; sec2hms(newstr, te); strlcat(newstr, " / ", sizeof(newstr)); if (0 == tt) // shoutcast ! strlcat(newstr+8, "--:--", sizeof(newstr)-8); else sec2hms(newstr+8, tt); win_new_text(&time_win, newstr); if ( (te < 0) || (tt < 0) || (0 == tt ) ) // elapsed == UNKNOWN or total == UNKNOWN or Shoutcast newval = 0; else newval = (te * 100) / tt; if ( (win->flags & WINFLG_VISIBLE)) draw_progressbar(time_prog_win.start_row+1, time_prog_win.start_col, time_prog_win.height-2, time_prog_win.fg_color, time_prog_win.bg_color, time_prog_win.cur_char, newval); time_prog_win.cur_char = newval; };
/* We are called when the scroll list has potentially changed Updates the info in all windows of the scroll list (sets new text in window). */ void scroll_list_changed(scroll_list *sl){ int i; char *info; struct Window *pwin; for (i=0, pwin = sl->wl; i < sl->num_windows; pwin++, i++){ info = sl->info_text( info_pos(sl, i) ); win_new_text( pwin, info); } };
void view_time_changed(int te, int tt){ char newstr[TIMESTR_LEN]; int newval; sec2hms(newstr, te); strlcat(newstr, " / ", sizeof(newstr)); sec2hms(newstr+8, tt); win_new_text(&time_win, newstr); newval = (te * 100) / tt; if ( (win->flags & WINFLG_VISIBLE)) draw_progressbar(time_prog_win.start_row+1, time_prog_win.start_col, time_prog_win.height-2, time_prog_win.fg_color, time_prog_win.bg_color, time_prog_win.cur_char, newval); time_prog_win.cur_char = newval; };
void view_results_changed(int num){ char newstr[50]; char number[20]; char *numstr; strlcpy (newstr, "Results: ", sizeof(newstr)); if (num > 30) strlcat(newstr, "> 50\n", sizeof(newstr)); else { numstr = get_digits(num, number, 0); strlcat(newstr, numstr, sizeof(newstr)); strlcat(newstr, "\n", sizeof(newstr)); }; if (num_results_win.bg_color == DARK_GREY) num_results_win.bg_color = LIGHT_GREY; else num_results_win.bg_color = DARK_GREY; win_new_text(&num_results_win, newstr); };
void view_artist_changed(char *s){ win_new_text(&artist_win, s); };
void view_title_changed(char *s){ win_new_text(&title_win, s); };
/* Initialize the playing screen We clear the whole screen. */ void playing_screen_init(Screen *this_screen) { this_screen->wl_size = WL_SIZE; this_screen->win_list = win; this_screen->screen_enter = screen_enter; this_screen->screen_exit = screen_exit; this_screen->keypress = keypress; win_init(&title_win, 0, 0, 50, 128, 1, win_txt[0]); title_win.font = MEDIUMFONT; title_win.flags |= WINFLG_CENTER; win_init(&artist_win, 49, 0, 30, 128, 1, win_txt[1]); artist_win.font = MEDIUMFONT; artist_win.flags |= WINFLG_CENTER; win_init(&time_win, 84, 22, 10, 128-22, 0, win_txt[2]); time_win.font = SMALLFONT; /* The state window, on the same line as the time progress */ win_init(&state_win, 89, 1, 16, 18, 0, win_txt[3]); state_win.font = BIGFONT; win_new_text(&state_win, "\xB3"); // play icon == b3 /* This is our progressbar */ win_init(&time_prog_win, 95, 22, 8, 102, 1, win_txt[4]); time_prog_win.font = SMALLFONT; time_prog_win.flags = WINFLG_BAR; time_prog_win.fg_color = DARK_GREY; time_prog_win.cur_char = 0; /* current value */ #define VOL_ROW 114 /* The speaker indicator is on the same line as volume text */ win_init(&speaker_win, VOL_ROW, 15, 18, 15, 0, win_txt[5]); speaker_win.font = BIGFONT; win_new_text(&speaker_win, "\xB8"); // speaker icon on /* Our indicator for the volume (triangle progress bar) */ win_init(&vol_ramp_win, VOL_ROW, 31, 16, 50, 0, win_txt[6]); vol_ramp_win.flags = WINFLG_RAMP; vol_ramp_win.fg_color = BLACK; vol_ramp_win.cur_char = 100/2; /* We initialize the volume with 100 % */ /* The text portion of the volume follows on the same line as the ramp */ win_init(&volume_win, VOL_ROW, 88, 16, 128-88, 0, win_txt[7]); win_new_text(&volume_win, "100 %"); win_init(&rnd_win, 134, 0, 14, 33, 1, win_txt[8]); rnd_win.font = SMALLFONT; rnd_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE; rnd_win.fg_color = WHITE; rnd_win.bg_color = BLACK; win_new_text(&rnd_win, "RND" ); win_init(&rpt_win, 134, 43, 14, 33, 1, win_txt[9]); rpt_win.font = SMALLFONT; rpt_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE; rpt_win.fg_color = WHITE; rpt_win.bg_color = BLACK; win_new_text(&rpt_win, "RPT" ); win_init(&single_win, 134, 86, 14, 33, 1, win_txt[10]); single_win.font = SMALLFONT; single_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE; single_win.fg_color = WHITE; single_win.bg_color = BLACK; win_new_text(&single_win, "1" ); win_init(&version_win, 150, 0, 10, 128, 0, win_txt[11]); version_win.font = SMALLFONT; version_win.flags |= WINFLG_CENTER; version_win.fg_color = WHITE; version_win.bg_color = BLACK; win_new_text(&version_win, "Version " VERSION); }
/* Initialize the playing screen We clear the whole screen. */ void playing_screen_init(Screen *this_screen) { int cur_start_row; this_screen->wl_size = WL_SIZE; this_screen->win_list = win; this_screen->screen_enter = screen_enter; this_screen->screen_exit = screen_exit; this_screen->keypress = keypress; cur_start_row = WL_START_ROW; win_init(&title_win, cur_start_row, 0, 50, 128, 1, win_txt[1]); title_win.font = MEDIUMFONT; title_win.flags |= WINFLG_CENTER; // The first line overlaps with the last line of the previous window cur_start_row += 49; win_init(&artist_win, cur_start_row, 0, 30, 128, 1, win_txt[2]); artist_win.font = MEDIUMFONT; artist_win.flags |= WINFLG_CENTER; // leave some room between artist and time window cur_start_row += 30 + 5; // 84 win_init(&time_win, cur_start_row, 22, 10, 128-22, 0, win_txt[3]); time_win.font = SMALLFONT; // state windows lies between time window and progress bar cur_start_row += 5; // 89 /* The state window, a bit higher than the time progress */ win_init(&state_win, cur_start_row - 2, 1, 16, 18, 0, win_txt[4]); state_win.font = BIGFONT; win_new_text(&state_win, "\xB3"); // play icon == b3 cur_start_row += 5; // 94 /* This is our progressbar */ win_init(&time_prog_win, cur_start_row, 22, 8, 102, 1, win_txt[5]); time_prog_win.font = SMALLFONT; time_prog_win.flags = WINFLG_BAR; time_prog_win.fg_color = DARK_GREY; time_prog_win.cur_char = 0; /* current value */ cur_start_row += 16; // 110 /* The speaker indicator is on the same line as volume text */ win_init(&speaker_win, cur_start_row, 15, 18, 15, 0, win_txt[6]); speaker_win.font = BIGFONT; win_new_text(&speaker_win, "\xB8"); // speaker icon on /* Our indicator for the volume (triangle progress bar) */ win_init(&vol_ramp_win, cur_start_row, 31, 16, 50, 0, win_txt[7]); vol_ramp_win.flags = WINFLG_RAMP; vol_ramp_win.fg_color = BLACK; vol_ramp_win.cur_char = 100/2; /* We initialize the volume with 100 % */ /* The text portion of the volume follows on the same line as the ramp */ win_init(&volume_win, cur_start_row, 88, 16, 128-88, 0, win_txt[8]); win_new_text(&volume_win, "100 %"); cur_start_row += 20; // 130 win_init(&rnd_win, cur_start_row, 0, 14, 32, 1, win_txt[9]); rnd_win.font = SMALLFONT; rnd_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE; rnd_win.fg_color = WHITE; rnd_win.bg_color = BLACK; win_new_text(&rnd_win, "RND" ); win_init(&rpt_win, cur_start_row, 48, 14, 32, 1, win_txt[10]); rpt_win.font = SMALLFONT; rpt_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE; rpt_win.fg_color = WHITE; rpt_win.bg_color = BLACK; win_new_text(&rpt_win, "RPT" ); win_init(&single_win, cur_start_row, 96, 14, 32, 1, win_txt[11]); single_win.font = SMALLFONT; single_win.flags |= WINFLG_CENTER | WINFLG_FRAME | WINFLG_HIDE; single_win.fg_color = WHITE; single_win.bg_color = BLACK; win_new_text(&single_win, "1" ); cur_start_row += 20; // 150 /* The caption window is the last window */ win_init(&caption_win, cur_start_row, 0, WL_SMALL_HEIGHT, 128,0, win_txt[0]); caption_win.font = SMALLFONT; caption_win.fg_color = BLACK; caption_win.bg_color = LIGHT_GREY; caption_win.flags |= WINFLG_CENTER; }