ncurses.c
来自「VLC媒体播放程序」· C语言 代码 · 共 1,156 行 · 第 1/3 页
C
1,156 行
MainBoxWrite( p_intf, l++, 1, " o Order Playlist" ); MainBoxWrite( p_intf, l++, 1, " O Reverse order Playlist" ); MainBoxWrite( p_intf, l++, 1, " <del> Delete an entry" ); MainBoxWrite( p_intf, l++, 1, " <backspace> Delete an entry" ); MainBoxWrite( p_intf, l++, 1, "" ); MainBoxWrite( p_intf, l++, 1, "[Boxes]" ); MainBoxWrite( p_intf, l++, 1, " <up>,<down> Navigate through the box line by line" ); MainBoxWrite( p_intf, l++, 1, " <pgup>,<pgdown> Navigate through the box page by page" ); MainBoxWrite( p_intf, l++, 1, "" ); MainBoxWrite( p_intf, l++, 1, "[Player]" ); MainBoxWrite( p_intf, l++, 1, " <up>,<down> Seek +/-5%%" ); MainBoxWrite( p_intf, l++, 1, "" ); MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" ); MainBoxWrite( p_intf, l++, 1, " Ctrl-L Refresh the screen" ); p_sys->i_box_lines_total = l; if( p_sys->i_box_start >= p_sys->i_box_lines_total ) { p_sys->i_box_start = p_sys->i_box_lines_total - 1; } if( l - p_sys->i_box_start < p_sys->i_box_lines ) { y += l - p_sys->i_box_start; } else { y += p_sys->i_box_lines; } } else if( p_sys->i_box_type == BOX_INFO ) { /* Info box */ int l = 0; DrawBox( p_sys->w, y++, 0, h, COLS, " Information " ); if( p_input ) { input_info_category_t * p_category; input_info_t * p_info; vlc_mutex_lock( &p_input->stream.stream_lock ); p_category = p_input->stream.p_info; while ( p_category ) { if( y >= y_end ) break; MainBoxWrite( p_intf, l++, 1, " [%s]", p_category->psz_name ); p_info = p_category->p_info; while ( p_info ) { if( y >= y_end ) break; MainBoxWrite( p_intf, l++, 1, " %s: %s", p_info->psz_name, p_info->psz_value ); p_info = p_info->p_next; } p_category = p_category->p_next; } vlc_mutex_unlock( &p_input->stream.stream_lock ); } else { MainBoxWrite( p_intf, l++, 1, "No item currently playing" ); } p_sys->i_box_lines_total = l; if( p_sys->i_box_start >= p_sys->i_box_lines_total ) { p_sys->i_box_start = p_sys->i_box_lines_total - 1; } if( l - p_sys->i_box_start < p_sys->i_box_lines ) { y += l - p_sys->i_box_start; } else { y += p_sys->i_box_lines; } } else if( p_sys->i_box_type == BOX_LOG ) { int i_line = 0; int i_stop; int i_start; DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " ); i_start = p_intf->p_sys->p_sub->i_start; vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock ); i_stop = *p_intf->p_sys->p_sub->pi_stop; vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock ); for( ;; ) { static const char *ppsz_type[4] = { "", "error", "warning", "debug" }; if( i_line >= h - 2 ) { break; } i_stop--; i_line++; if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE; if( i_stop == i_start ) { break; } mvnprintw( y + h-2-i_line, 1, COLS - 2, " [%s] %s", ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type], p_sys->p_sub->p_msg[i_stop].psz_msg ); } vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock ); p_intf->p_sys->p_sub->i_start = i_stop; vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock ); y = y_end; } else if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist ) { /* Playlist box */ playlist_t *p_playlist = p_sys->p_playlist; int i_start, i_stop; int i_item; DrawBox( p_sys->w, y++, 0, h, COLS, " Playlist " ); if( p_sys->i_box_plidx >= p_playlist->i_size ) p_sys->i_box_plidx = p_playlist->i_size - 1; if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0; if( p_sys->i_box_plidx < (h - 2)/2 ) { i_start = 0; i_stop = h - 2; } else if( p_playlist->i_size - p_sys->i_box_plidx > (h - 2)/2 ) { i_start = p_sys->i_box_plidx - (h - 2)/2; i_stop = i_start + h - 2; } else { i_stop = p_playlist->i_size; i_start = p_playlist->i_size - (h - 2); } if( i_start < 0 ) { i_start = 0; } if( i_stop > p_playlist->i_size ) { i_stop = p_playlist->i_size; } for( i_item = i_start; i_item < i_stop; i_item++ ) { vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item ); int c = p_playlist->i_index == i_item ? '>' : ' '; if( y >= y_end ) break; if( b_selected ) { attrset( A_REVERSE ); } if( !strcmp( p_playlist->pp_items[i_item]->psz_name, p_playlist->pp_items[i_item]->psz_uri ) ) { mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'", c, i_item, p_playlist->pp_items[i_item]->psz_uri ); } else { mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)", c, i_item, p_playlist->pp_items[i_item]->psz_uri, p_playlist->pp_items[i_item]->psz_name ); } if( b_selected ) { attroff ( A_REVERSE ); } } } else { y++; } while( y < y_end ) { DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 ); } refresh(); *t_last_refresh = time( 0 );}static void Eject ( intf_thread_t *p_intf ){ char *psz_device = NULL, *psz_parser, *psz_name; /* * Get the active input * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA * If it's neither of these, then return */ playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } vlc_mutex_lock( &p_playlist->object_lock ); if( p_playlist->i_index < 0 ) { vlc_mutex_unlock( &p_playlist->object_lock ); vlc_object_release( p_playlist ); return; } psz_name = p_playlist->pp_items[ p_playlist->i_index ]->psz_name; if( psz_name ) { if( !strncmp(psz_name, "dvd://", 4) ) { switch( psz_name[strlen("dvd://")] ) { case '\0': case '@': psz_device = config_GetPsz( p_intf, "dvd" ); break; default: /* Omit the first MRL-selector characters */ psz_device = strdup( psz_name + strlen("dvd://" ) ); break; } } else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) ) { switch( psz_name[strlen(VCD_MRL)] ) { case '\0': case '@': psz_device = config_GetPsz( p_intf, VCD_MRL ); break; default: /* Omit the beginning MRL-selector characters */ psz_device = strdup( psz_name + strlen(VCD_MRL) ); break; } } else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) ) { switch( psz_name[strlen(CDDA_MRL)] ) { case '\0': case '@': psz_device = config_GetPsz( p_intf, "cd-audio" ); break; default: /* Omit the beginning MRL-selector characters */ psz_device = strdup( psz_name + strlen(CDDA_MRL) ); break; } } else { psz_device = strdup( psz_name ); } } vlc_mutex_unlock( &p_playlist->object_lock ); vlc_object_release( p_playlist ); if( psz_device == NULL ) { return; } /* Remove what we have after @ */ psz_parser = psz_device; for( psz_parser = psz_device ; *psz_parser ; psz_parser++ ) { if( *psz_parser == '@' ) { *psz_parser = '\0'; break; } } /* If there's a stream playing, we aren't allowed to eject ! */ if( p_intf->p_sys->p_input == NULL ) { msg_Dbg( p_intf, "ejecting %s", psz_device ); intf_Eject( p_intf, psz_device ); } free(psz_device); return;}static void PlayPause ( intf_thread_t *p_intf ){ input_thread_t *p_input = p_intf->p_sys->p_input; vlc_value_t val; if( p_input ) { var_Get( p_input, "state", &val ); if( val.i_int != PAUSE_S ) { val.i_int = PAUSE_S; } else { val.i_int = PLAYING_S; } var_Set( p_input, "state", val ); } else if( p_intf->p_sys->p_playlist ) { playlist_Play( p_intf->p_sys->p_playlist ); }}/**************************************************************************** * ****************************************************************************/static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title ){ int i; int i_len; if( w > 3 && h > 2 ) { if( title == NULL ) title = ""; i_len = strlen( title ); if( i_len > w - 2 ) i_len = w - 2; mvwaddch( win, y, x, ACS_ULCORNER ); mvwhline( win, y, x+1, ACS_HLINE, ( w-i_len-2)/2 ); mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title ); mvwhline( win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) ); mvwaddch( win, y, x+w-1,ACS_URCORNER ); for( i = 0; i < h-2; i++ ) { mvwaddch( win, y+i+1, x, ACS_VLINE ); mvwaddch( win, y+i+1, x+w-1, ACS_VLINE ); } mvwaddch( win, y+h-1, x, ACS_LLCORNER ); mvwhline( win, y+h-1, x+1, ACS_HLINE, w - 2 ); mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER ); }}static void DrawEmptyLine( WINDOW *win, int y, int x, int w ){ if( w > 0 ) { mvhline( y, x, ' ', w ); }}static void DrawLine( WINDOW *win, int y, int x, int w ){ if( w > 0 ) { attrset( A_REVERSE ); mvhline( y, x, ' ', w ); attroff ( A_REVERSE ); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?