2017-02-24 65 views
0

我有兩個窗口,一個在頂部,一個在底部(我將在後面添加第三個窗口,它們將在這兩個窗口之間)。我爲底部窗口繪製一條水平線,然後開始繪製頂部窗口,並且底部窗口被擦除!當我不想要它時,Ncurses擦除窗口

構造函數display()被自動調用,而函數displayMessage()被我的代碼調用。

這裏是display()代碼:

display::display() 
{ 
    //initialize window 
    initscr(); //start curses mode 
    cbreak(); //Disable line buffering 
    curs_set(0); //Don't show curser 
    refresh(); //Now refresh screen 

    //setup bottom bar 
    bottomBar = newwin(2, 80, 22, 0); //create new window 
    whline(bottomBar, '_', 80); //draw line 
    wrefresh(bottomBar); //refresh 

    //setup top bar 
    topBar = newwin(0, 80, 0, 0); //create new window 
    wattron(topBar, A_UNDERLINE); //text is to be underlined 

} 

這裏是displayMessage()代碼:

void display::displayMessage(string message) 
{ 
    //do some other necessary stuff 
    int length = message.length(); //get length of message 
    wmove(topBar, 0, 0); //move curser back to beginning 
    //getch(); 
    wrefresh(topBar); //refresh 
    //getch(); 
    whline(topBar, '_',80); //draw line for bottom 
    //getch(); 
    wmove(topBar, 0, 40 - length/2 - 1); //move cursor to center text 
    wprintw(topBar,message.c_str()); //print message 
    wrefresh(topBar); //refresh 
} 

另外這裏是代碼段,調用這兩個:

//initialize stuff 
    pomodoro instance; 

    while(true) //loop forever, or until user 
    { 
     for (int i = 0; i < 3; i++) //loop thru 4 pomodoros 
    { 
     //work 
     instance.Display.displayMessage("**Time to work!**"); 
     instance.playAlarm(); 
     //waitForUser(); 
     //timer(config.workTime); 
     //break 
     return 0; //doing development right now 

回答

1

這條線是一個問題:

topBar = newwin(0, 80, 0, 0); //create new window 

因爲第一個參數是零。該manual page解釋:

如果任nlines或NCOLS是零,它們默認 LINES - begin_yCOLS - begin_x

所以零參數會讓你的窗口重疊(很多)。

+0

我忽略了這樣一個小細節! – user3273814

相關問題