CURSES: use of overlay()/overwrite()

Anthony Howe ant at mks.com
Sun Jun 23 02:46:56 AEST 1991


jfv at cbnewsk.att.com (j.f.van valkenburg) writes:
>In article <1991Jun20.170834.8080 at mks.com>, ant at mks.com (Anthony Howe) writes:
>> 
>> What is the correct way to use overlay() and overwrite().  Are they what
>> I need?  I want to display a dialogue box, then later remove it from the
>> screen restoring whatever was covered.  The catch is that I want the
>> dialogue box to do the refresh and maintain independence by not having
>> any knowledge of other windows other than curscr.
>
>Instead of flipping windows as in overlay, try openning a new window altogether.
>
>By making a new window you can do a wrefresh(newwin) to update just one
>window or wnoutrefresh(newwin) and do everything with a refresh().
>
>The two windows,stdscr and newwin, will be totally independent of each other and
>cursor addressing will be dependent on the window addressed.

I do this, but the problem is refreshing the screen in order to remove the
top most window.  If you have several routines each opening windows on top
of each other, how do you tell them to redraw their windows?

First I tried a window stacking structure.  Works but requires that the 
routines register the window on the stack.  I then sat back and read the
System V man pages on overlay(), overwrite(), copywin(), and dupwin().
This is the solution I came up with for the dialogue routine.

int
dailogue(msg)
char *msg;
{
	WINDOW *dial;
	WINDOW *covered;
	...
	dail = newwin(height, width, row, col);
	/* Make a exact size duplicate of the dialogue window. 
	 * Another newwin() could be done with the same dimensions,
	 * but I wanted to test our in-house CURSES that I maintain.
	 */
	covered = dupwin(dail);
	/* Save the region from curscr that will be covered. */
	overwrite(curscr, covered);
	/* Do what ever. */
	...
	delwin(dail);
	/* Restore the covered region. */
	overwrite(covered, curscr);
	delwin(covered);
	/* Restore the screen so that all other routines think that the 
	 * window is as they left it. */ 
	wrefresh(curscr);
	return (result);
}

-- 
ant at mks.com                                                   Anthony C Howe 
Mortice Kern Systems Inc. 35 King St. N., Waterloo, Ontario, Canada, N2J 6W9
"Fate favors fools, small children, and ships named Enterprise" - Riker



More information about the Comp.unix.programmer mailing list