⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncursesui.cpp

📁 FreeAMP(MP3播放)程序源代码-用来研究MP3解码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                    if (md.Track() != 0)
                    {
                        sprintf(buf, "%d", md.Track());
                        addstr(buf);
                    }
                    addstr("\nComment: ");
                    addstr((char *)md.Comment().c_str());
                    addstr("\n");
                    refresh();

                    counter = 0;
                    title = (char *)malloc((2*sizeof(char)) * (12 + strlen(pmvi->m_filename)));
                    sprintf( title, BRANDING " " FREEAMP_VERSION " - [%s]", pmvi->m_filename);
                    if ( strlen(title) > (unsigned)COLS - 13 )
                    {
                        titleStart = 0;
                        titleDir = -1;
                        move( 0, 6 );
                        //color_set(7, NULL);
                        attron(A_REVERSE);
                        for (int i = 6; i < COLS - 7; i++)
                            addch(title[i-6]);
                        attroff(A_REVERSE);
                    }
                    else
                    {
                        move(0, (COLS / 2) - ( strlen(title) ) / 2 );
                        //color_set(7, NULL);
                        attron(A_REVERSE);
                        addstr(title);
                        attroff(A_REVERSE);
                    }
                }
                refresh();
                break; }
            case INFO_StreamInfo:
            {
                char szTitle[100];
                int  i;
            
                StreamInfoEvent *pInfo = (StreamInfoEvent *)e;
           
                pInfo->GetTitle(szTitle, 100);
                move(2, 0);
                addstr("Title  : ");
                addstr(szTitle);
                for(i = 9 + strlen(szTitle); i < COLS; i++)
                    addch(' ');
                      
                break;
            } 
            case INFO_MediaTimeInfo: {
                MediaTimeInfoEvent *pmtp = ( MediaTimeInfoEvent *)e;
                float percentAmount;
                int i=0, hours, minutes, seconds;
                char buf[1024];

                if (title && ( strlen(title) > (unsigned)COLS - 13 ) )
                   counter++;
                
                if ( counter > 50
                   || (counter > 4 && (titleDir == 0 || titleDir == 1)))
                {
                    int i;
                    counter = 0;
                    if (titleDir == -1)
                       titleDir = 0;
                    else if (titleDir == 2)
                       titleDir = 1;
                    if (titleDir == 0)
                        titleStart++;
                    else
                        titleStart--;
                    move( 0, 6 );
                    //color_set(7, NULL);
                    attron(A_REVERSE);
                    for (i = 6; i < COLS - 7; i++)
                        addch(title[i-6+titleStart]);
                    attroff(A_REVERSE);
                    if ( titleStart <= 0 )
                       titleDir = -1;
                    else if ( i - 6 + (unsigned)titleStart >= strlen(title))
                       titleDir = 2;
                }

                
                percentAmount = ( totalTime / ( COLS + 1));
                move(LINES-2, 0);
                sprintf(buf, "%02d:%02d:%02d", pmtp->m_hours, pmtp->m_minutes,
                                               pmtp->m_seconds);
                addstr(buf);
                move(LINES-2, COLS-8);
                hours = (int)totalTime / 60 / 60;
                minutes = (int)totalTime / 60;
                seconds = (int)totalTime;
                seconds -= minutes * 60;
                minutes -= hours * 60;                

                sprintf(buf, "%02d:%02d:%02d", hours, minutes,
                                               seconds);
                addstr(buf);                
                move(LINES-1, 0);
                for (i=0; i < pmtp->m_totalSeconds / percentAmount; i++)
                    addch(ACS_BLOCK);
                for (; i < COLS; i++)
                    addch(ACS_BOARD);
                refresh();
                lastSeconds = pmtp->m_totalSeconds;
                break;}
              default:
                break;
        }
    }
    return kError_NoErr;
}

void ncursesUI::ProcessArgs() {
    //char *pc = NULL;
    //for(int i=1;i<m_argc;i++) {
        //cout << "Adding arg " << i << ": " << argv[i] << endl;
        //pc = m_argv[i];
        //if (pc[0] == '-') 
        //    processSwitch(pc);
    //}
    m_plm->SetCurrentIndex(0);
}

void ncursesUI::processSwitch(char *pc) {

    cursesStarted = false;
    curs_set(1);
    move(0,0);
    clear();
    refresh();
    endwin();
    if (pc[1] == 'h' || pc[1] == 'H')
    {
        cout << BRANDING << " ncurses user interface" << endl;
        cout << "Syntax: freeamp [-h] <filenames>" << endl;
        cout << "-h shows this help" << endl;
        cout << "If you are running freeamp with the -ui argument to select" << endl;
        cout << "the ncurses ui, you can edit ~/.freeamp_prefs and change the" << endl;
        cout << "value of TextUI." << endl << endl;
        cout << "ncurses user interface Copyright (C) 1999 Stephan Auerhahn" << endl;
    }
    else
    {
        cout << "Invalid command line argument, try -h for help." << endl;
    }
    Event *e = new Event(CMD_QuitPlayer);
    m_playerEQ->AcceptEvent(e);
    return;
}

void ncursesUI::showInfo() {
    move(0,0);
    //color_set(7, NULL);
    attron(A_REVERSE);
    for (int i=0; i < COLS; i++)
        addstr(" ");
    move(0, (COLS/2) - 4);
    addstr(BRANDING " " FREEAMP_VERSION);
    attroff(A_REVERSE);
//    refresh();
    //color_set(7, NULL);
    move(LINES - 4 ,0);
    addstr(" press h for keystroke help ");
/*
    addstr("       Keystroke Help     \n");
    addstr("  ( q )    Quit           \n");
    addstr("  ( + )    Next Song      \n");
    addstr("  ( - )    Prev Song      \n");
    addstr("  ( p )    Pause / UnPause\n");
    addstr("  ( s )    Shuffle        \n");
*/
    move(LINES - 2, 0);
    addstr("00:00:00");
    move(LINES - 2, COLS - 8);
    addstr("00:00:00");
    move(LINES - 1, 0);
    for (int i = 0; i < COLS; i++)
    {
         addch(ACS_BOARD);
    }
    
//    refresh();
    return;
}

void ncursesUI::help() {
     if (helpwin_open)
     {
        delwin(helpwin);
        helpwin_open = false;
        touchwin(stdscr);
        refresh();
        if (playlistwin_open)
        {
            touchwin(playlistwin);
            wrefresh(playlistwin);
        }
     }
     else
     {
        helpwin = newwin( 10, 30, (LINES / 2) - 5, (COLS / 2) - 15 );
        wmove(helpwin, 0, 0);
        waddch(helpwin, ACS_ULCORNER);
        for (int i = 0; i < 2; i++)
            waddch(helpwin, ACS_HLINE);
        waddch(helpwin, ACS_RTEE);
        waddstr(helpwin, "Help( h to close )");
        waddch(helpwin, ACS_LTEE);
        for (int i = 0; i < 2; i++)
            waddch(helpwin, ACS_HLINE);
        waddch(helpwin, ACS_URCORNER);
        waddch(helpwin, 10);
        waddch(helpwin, ACS_VLINE);
        waddstr(helpwin, " ( q )    Quit          ");
        waddch(helpwin, ACS_VLINE);
        waddch(helpwin, 10);
        waddch(helpwin, ACS_VLINE);
        waddstr(helpwin, " ( + )    Next Song     ");
        waddch(helpwin, ACS_VLINE);
        waddch(helpwin, 10);
        waddch(helpwin, ACS_VLINE);
        waddstr(helpwin, " ( - )    Prev Song     ");
        waddch(helpwin, ACS_VLINE);
        waddch(helpwin, 10);
        waddch(helpwin, ACS_VLINE);
        waddstr(helpwin, " ( p )    Pause/UnPause ");
        waddch(helpwin, ACS_VLINE);
        waddch(helpwin, 10);
        waddch(helpwin, ACS_VLINE);
        waddstr(helpwin, " ( s )    Shuffle       ");
        waddch(helpwin, ACS_VLINE);
        waddch(helpwin, 10);
        waddch(helpwin, ACS_LLCORNER);
        for (int i = 0; i < 24; i++)
            waddch(helpwin, ACS_HLINE);
        waddch(helpwin, ACS_LRCORNER);
        wrefresh(helpwin);
        helpwin_open = true;
     }
}

void ncursesUI::playlist() {
/*
     if (playlistwin_open)
     {
        delwin(playlistwin);
        playlistwin_open = false;
        touchwin(stdscr);
        refresh();
        if (helpwin_open)
        {
            touchwin(helpwin);
            wrefresh(helpwin);
        }
     }
     else
     {
        playlistwin = newwin( LINES - 10, 70, 4, (COLS / 2) - 35);
        wmove(playlistwin, 0, 0);
        waddch(playlistwin, ACS_ULCORNER);
        for (int i = 0; i < 68; i++)
            waddch(playlistwin, ACS_HLINE);
        waddch(playlistwin, ACS_URCORNER);
        for (int i = 1; i < LINES - 10; i++)
        {
            mvwaddch(playlistwin, i, 0, ACS_VLINE);
            mvwaddch(playlistwin, i, 69, ACS_VLINE);
        }
        wmove(playlistwin, LINES - 11, 0);
        waddch(playlistwin, ACS_LLCORNER);
        for (int i = 0; i < 68; i++)
            waddch(playlistwin, ACS_HLINE);
        waddch(playlistwin, ACS_LRCORNER);
        for (int i = 0; i < m_plm->CountItems() && i < LINES - 12; i++)
        {
             wmove(playlistwin, i + 1, 3);
             waddstr(playlistwin, m_plm->ItemAt(i)->StringForPlayerToDisplay());
        }
        wrefresh(playlistwin);
        playlistwin_open = true;
     }
*/
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -