I am getting a very strange "bug" I guess you could call it. I am using Xcode to develop a simple game and wanted to add some simple graphics.
To do this I decided to use the ncurses
library.
In learning how to use ncurses
, I began mucking around creating windows, one of the functions I will definitely be using later (possibly for health bars or something) is the box()
function that surrounds a window in a box()
. The simple test I did was to create a new window in the centre of the strscr
window and then call box()
on it. The code for this is below:
WINDOW *AboutWindow;
int width=60,height=12;
int OffsetX=0,OffsetY=0;
OffsetX = (getmaxx(stdscr) - width) / 2;
OffsetY = ((getmaxy(stdscr) - height) / 2);
AboutWindow = newwin(height, width, OffsetY, OffsetX);
getch();
box(AboutWindow, 0, 0);
//getch();
wrefresh(AboutWindow);
The odd "bug" is that the box will only get drawn if getch()
is called before I call the box()
function. If I comment out the getch()
the box, does not get drawn.
I am completely flunked as to why this is happening.
Ok, I know the question is old, but for the future reference: There is a way to get it to work.
After reading a tutorial about ncurses here http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO I was wondering how is it that if you printw()
and then getch()
you don't have to run refresh()
. I figured that it is invoked in getch()
and it refreshes stdscr
which overrides output from any other windows.
So in order to keep the window on screen and get keyboard input you have to use wgetch(WINDOW*)
.
Your code would look like that:
WINDOW *AboutWindow;
int width=60,height=12;
int OffsetX=0,OffsetY=0;
OffsetX = (getmaxx(stdscr) - width) / 2;
OffsetY = ((getmaxy(stdscr) - height) / 2);
AboutWindow = newwin(height, width, OffsetY, OffsetX);
box(AboutWindow, 0, 0);
wgetch(AboutWindow); //also invokes wrefresh()