0

I want to print text in the middle of the screen (my window) line with line and when I choose an option I want to make that window dissapear using ncurses.h..

int height = 6;
int width = 24;

WINDOW* menuwin = newwin(height, width, (LINES - height)/2, (COLS - width)/2);
box(menuwin, 0, 0);
refresh();
wrefresh(menuwin);

keypad(menuwin, TRUE);

char* choices[3] = {"something", "something", "something"};
int choice;
int highlight = 0;

while(TRUE)
{
    for(int i = 0; i < 3; ++i)
    {
        if(i == highlight)
        {
            wattron(menuwin, A_REVERSE);
        }
        mvwprintw(menuwin, i + 1, 1, choices[i]);
        wattroff(menuwin, A_REVERSE);
    }
    choice = wgetch(menuwin);
    switch(choice)
    {
        case KEY_UP:
            highlight--;
            if(highlight == -1) highlight = 2;
            break;
        case KEY_DOWN:
            highlight++;
            if(highlight == 3) highlight = 0;
            break;
        default:
            break;
    }

    if(choice == 10) 
    {
        wrefresh(menuwin);
        delwin(menuwin);
        refresh();
        getch();
    }
}

Okay, so what this does, I create a menu in the middle of the screen but my text inside the box is in the top left and I want it to be in the middle of that window, also, when I choose say option 1 I want that window to be "hidden" or something, so that I can make it visible whenever I want, only Ncurses and C.

UPDATE: I made my options in the middle of the box by changing: mvwprintw(menuwin, i + 1, 1, choices[i]); to mvwprintw(menuwin, i + 1, 6, choices[i]); and it worked, but is there a more generalized way of doing this?

C. Cristi
  • 569
  • 1
  • 7
  • 21

1 Answers1

0

If you make a change to stdscr and refresh that, it will obscure other windows (until you modify/refresh those).

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105