[comp.sys.ibm.pc] pccurses v1.3 mvwin

pete@othello.dartmouth.edu (Pete Schmitt) (11/10/89)

The following code works correctly on BSD.  It rotates three small windows
that everlap each other.  But under pccurses (compiled with Turbo-C 1.5)
the three small windows don't move from the upper left corner of the screen.
Does anyone have this working?
==============================cut here==============================
#include <curses.h>

main()
{
	WINDOW *win;
	int i;

	initscr();
	box(stdscr,'*','-');
	refresh();
	sleep(2);
	win = newwin(10, 20, 3, 3);
	for(i=1;i<10;i++)
	{
		mvwin(win,3,3);
		box(win,'*','*');
		overlay(win,stdscr);
		refresh();
		sleep(1);
		box(win,'.','.');
		mvwin(win,5,5);
		overlay(win,stdscr);
		refresh();
		sleep(1);
		box(win,'+','+');
		mvwin(win,2,8);
		overlay(win,stdscr);
		move(15,1);
		refresh();
		sleep(1);
	}
	endwin();
}

bl@infovax.UUCP (Bj|rn Larsson) (11/12/89)

In article <16679@dartvax.Dartmouth.EDU> pete@othello.dartmouth.edu (Pete Schmitt) writes:
>The following code works correctly on BSD.  It rotates three small windows
>that everlap each other.  But under pccurses (compiled with Turbo-C 1.5)
>the three small windows don't move from the upper left corner of the screen.
>Does anyone have this working?
> (program example deleted)
It should be made clear that PCcurses is a port of Pavel Curtis' PD curses
package by the name of 'ncurses'. In the documentation about Ken Arnold's
original curses, it says about overlay(win1, win2):

'Overlay win1 on win2. The contents of win1, insofar as they fit, are
placed on win2 at their starting (x,y) coordinates...'

However, the ncurses documentation says on the same topic:

'These functions overlay win1 on top of win2, that is, all text in win1
is copied to win2, after lining up the two window's origins...'
		    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think this verifies the pccurses does the 'right' thing considering
its heritage. On the other hand, this way of working appears rather
useless to me... and should be easy to fix.

Interestingly, I test compiled the submitted programming example on our
Ultrix (~BSD) machine, and  the windows were placed as the author intended,
but they were not displayed in full - only the left and upper borders were
visible.

Below is a modified version of the example, which works with pccurses.
It produces the desired display without using overlay(), but requires
3 WIN structs, plus the storage to hold the lines of the new windows.
It's not a solution, but an alternative. And BTW, it works on Ultrix
curses...

================================================================
#include <curses.h>

main()
{
	WINDOW *win1;
	WINDOW *win2;
	WINDOW *win3;
	int i;

	initscr();
	box(stdscr,'*','-');
	refresh();
	sleep(2);
	win1 = newwin(10, 20, 3, 3);
	win2 = newwin(10, 20, 5, 7);
	win3 = newwin(10, 20, 7, 11);
	for(i=1;i<10;i++)
	box(win1,'*','*');
	box(win2,'.','.');
	box(win3,'+','+');
	while(1)
	  {
	  touchwin(win1);
	  wrefresh(win1);
	  sleep(1);
	  touchwin(win2);
	  wrefresh(win2);
	  sleep(1);
	  touchwin(win3);
	  wrefresh(win3);
	  sleep(1);
	  }
	endwin();
}
================================================================
-- 
 ====================== InfoVox = Speech Technology =======================
 Bjorn Larsson, INFOVOX AB      :      ...seismo!mcvax!kth!sunic!infovax!bl
 Box 2503                       :         bl@infovox.se
 S-171 02 Solna, Sweden         :         Phone (+46) 8 735 80 90

bl@infovax.UUCP (Bj|rn Larsson) (11/12/89)

In article <306@infovax.UUCP> bl@infovax.UUCP I write:
>In article <16679@dartvax.Dartmouth.EDU> pete@othello.dartmouth.edu (Pete Schmitt) writes:
>	<stuff deleted>
>Below is a modified version of the example, which works with pccurses.

Forget that! Just after posting I realized my example more or less emu-
lates overwrite(), not overlay(). Please no flames... instead I rewrote
the overlay/overwrite module to make it behave like Pete (and others)
wants. The revised version is for a (possibly) upcoming version 1.4.
I have not checked that it compiles, links and works correctly with the
1.3 package (I tested it with a 1.4a temporary version) but it should.
If there are any problems, they should not be worse than compiler
warnings. Just rebuild the pccurses libraries with the below overlay.c
module replacing the 1.3 version:

/****************************************************************/
/* Overlay() and overwrite() functions of the PCcurses package	*/
/*								*/
/****************************************************************/
/* This version of curses is based on ncurses, a curses version	*/
/* originally written by Pavel Curtis at Cornell University.	*/
/* I have made substantial changes to make it run on IBM PC's,	*/
/* and therefore consider myself free to make it public domain.	*/
/*		Bjorn Larsson (...mcvax!enea!infovax!bl)	*/
/****************************************************************/
/* 1.4b: Overlaying window will not line up with over-		*/
/*	 layed window's origin, but at it's 'own' origin	*/
/*	 relative to the overlayed's origin:		891111	*/
/* 1.4a: Portability improvements:			890408	*/
/* 1.3:	 MSC -W3, Turbo'C' -w -w-pro checks:		881005	*/
/* 1.2:	 Max limits off by 1. Fixed thanks to S. Creps:	881002	*/
/* 1.0:	 Release:					870515	*/
/****************************************************************/

#include <curses.h>
#include <curspriv.h>

char _curses_overlay_rcsid[] = "@(#)overlay.c    v.1.4b - 891111";

/****************************************************************/
/* Overlay() overwrites 'win1' upon 'win2', with 'win1' appea-	*/
/* ring in 'win2' at it own origin relative to 'win2's origin.	*/
/* This is a departure, but a desirable one, from the initial	*/
/* definition of this function. Overlay is transparent; blanks	*/
/* from 'win1' are not copied to 'win2'.			*/
/****************************************************************/

void overlay(win1, win2)
  WINDOW	*win1, *win2;
  {
  int		*minchng;
  int		*maxchng;
  int		*w1ptr;
  int		*w2ptr;
  int		 attrs;
  int		 col;
  int		 line;
  int		 last_line;
  int		 last_col;

  last_col = min(win1->_maxx + win1->_begx, win2->_maxx) - 1;
  last_line = min(win1->_maxy + win1->_begy, win2->_maxy) - 1;
  attrs = win2->_attrs & ATR_MSK;
  minchng = win2->_minchng + win1->_begy;
  maxchng = win2->_maxchng + win1->_begy;

  for(line = win1->_begy;  line <= last_line;  line++)
    {
    register short   fc, lc;

    w1ptr = win1->_line[line - win1->_begy];
    w2ptr = win2->_line[line] + win1->_begx;
    fc = _NO_CHANGE;

    for(col = win1->_begx;  col <= last_col;  col++)
      {
      if ((*w1ptr & CHR_MSK) != ' ')
	{
	*w2ptr = (*w1ptr & CHR_MSK) | attrs;
	if (fc == _NO_CHANGE)
	  fc = col;
	lc = col;
	} /* if */
      w1ptr++;
      w2ptr++;
      } /* for */

    if (*minchng == _NO_CHANGE)
      {
      *minchng = fc;
      *maxchng = lc;
      } /* if */
    else
      if (fc != _NO_CHANGE)
	{
	if (fc < *minchng)
	  *minchng = fc;
	if (lc > *maxchng)
	  *maxchng = lc;
	} /* else if */
    minchng++;
    maxchng++;
    } /* for */
  } /* overlay */

/****************************************************************/
/* Overwrite() overwrites 'win1' upon 'win2', with 'win1' ap-	*/
/* pearing in 'win2' at it own origin relative to 'win2's ori-	*/
/* gin. This is a departure, but a desirable one, from the	*/
/* initial definition of this function. Overwrite is non-trans-	*/
/* parent; blanks from 'win1' are copied to 'win2'.		*/
/****************************************************************/

void	overwrite(win1, win2)
  WINDOW	*win1, *win2;
  {
  int		*minchng;
  int		*maxchng;
  int		*w1ptr;
  int		*w2ptr;
  int		 attrs;
  int		 col;
  int		 line;
  int		 last_line;
  int		 last_col;

  last_col = min(win1->_maxx + win1->_begx, win2->_maxx) - 1;
  last_line = min(win1->_maxy + win1->_begy, win2->_maxy) - 1;
  attrs = win2->_attrs & ATR_MSK;
  minchng = win2->_minchng + win1->_begy;
  maxchng = win2->_maxchng + win1->_begy;

  for(line = win1->_begy;  line <= last_line;  line++)
    {
    register short   fc, lc;

    w1ptr = win1->_line[line - win1->_begy];
    w2ptr = win2->_line[line] + win1->_begx;
    fc = _NO_CHANGE;

    for(col = win1->_begx;  col <= last_col;  col++)
      {
      if ((*w1ptr & CHR_MSK) != (*w2ptr & CHR_MSK))
	{
	*w2ptr = (*w1ptr & CHR_MSK) | attrs;
	if (fc == _NO_CHANGE)
	  fc = col;
	lc = col;
	} /* if */
      w1ptr++;
      w2ptr++;
      } /* for */

    if (*minchng == _NO_CHANGE)
      {
      *minchng = fc;
      *maxchng = lc;
      } /* if */
    else
      if (fc != _NO_CHANGE)
	{
	if (fc < *minchng)
	  *minchng = fc;
	if (lc > *maxchng)
	  *maxchng = lc;
	} /* else if */
    minchng++;
    maxchng++;
    } /* for */
  } /* overwrite */
-- 
 ====================== InfoVox = Speech Technology =======================
 Bjorn Larsson, INFOVOX AB      :      ...seismo!mcvax!kth!sunic!infovax!bl
 Box 2503                       :         bl@infovox.se
 S-171 02 Solna, Sweden         :         Phone (+46) 8 735 80 90