[comp.unix.xenix] Curses! Graphics again!

frankb@usource.SARASOTA.FL.US (Frank Bicknell) (11/18/89)

In my original article <323@usource.SARASOTA.FL.US> I mumbled:

+ ...I've done some work at getting borders around windows that
+ look more reasonable than: 

[ pretty box pictures deleted ]

+ Almost every terminal we've seen these days supports
+ character-mode graphics. ...
+ Can anyone tell me if the newer versions of curses supplied with
+ the new development system supports these characters?  ...

To date I've had no response: does anyone out there do anything
with curses?  If so, please drop me a line... I'd like to know
more about the newer curses functionality.
-- 
Frank Bicknell
UniSource; 1405 Main St, Ste 709; Sarasota, FL 34236
attctc!usource!frankb || frankb@usource.SARASOTA.FL.US

rosso (Ross Oliver, x537, ionesco) (11/22/89)

In article <329@usource.SARASOTA.FL.US> frankb@usource.SARASOTA.FL.US (Frank Bicknell) writes:
>In my original article <323@usource.SARASOTA.FL.US> I mumbled:
>
>+ ...I've done some work at getting borders around windows that
>+ look more reasonable than: 
>
>[ pretty box pictures deleted ]
>
>+ Almost every terminal we've seen these days supports
>+ character-mode graphics. ...
>+ Can anyone tell me if the newer versions of curses supplied with
>+ the new development system supports these characters?  ...
>
>To date I've had no response: does anyone out there do anything
>with curses?  If so, please drop me a line... I'd like to know
>more about the newer curses functionality.

In the SCO XENIX 2.3 and SCO UNIX 3.2 development systems, you can use
8-bit characters in curses.  On the PC, and most terminals that use the
PC character set, the graphics characters are in the 128-to-255 range,
so you can use them directly to draw character graphics in curses.  For
example, to draw a box around the window "w" using graphics characters
on the XENIX console, you could use the standard curses box() function:

  box( w, '\263', '\304' );

There are two caveats that go with the box() function: the horizontal
and vertical elements must be single characters (not escape sequences),
and box() won't draw corners.  You could draw the corner characters
after the box call, or write your own box function that includes putting
corner characters on boxes.

If you must support graphics elements that consist of more than one
character per screen position, you can use the new character mapping
functions of curses.  These functions are described in the last section
of the Screen Processing chapter of the C Library Guide.  They are
_not_ described in the curses manual entry.

These functions allow you to define your own mapping from the characters
curses outputs to what actually appears on the screen.  If you have
the function mputch() defined in your program, then curses will call
your function instead of its normal output functions for each character
it sends to the screen.  Using this method, you would assign arbitrary
single characters to your graphics elements, and your mputch() function
would map these to the multiple-character sequences needed by your
terminal.  For example:


#define  HORIZONTAL_CHAR  '\200'
char *horizontal_sequence = '\033[x'  /* characters needed by terminal to */
				      /*   display an horizontal bar.     */

#define  VERTICAL_CHAR    '\201'
char *vertical_sequence = '\033[y'     /* characters needed by terminal to */
				       /*   display a vertical bar.     */

main()
{
   initscr();
   box( stdwin, HORIZONTAL_CHAR, VERTICAL_CHAR );
   refresh();
   ...
}

mputch( ch );
{
  switch( ch ) {

    case HORIZONTAL_CHAR:
      fputs( horizontal_sequence, stdout );
      break;

    case VERTICAL_CHAR:
      fputs( vertical_sequence, stdout );
      break;
    
    default:
      putc( ch, stdout );
  }
}

----------------
In addition to the output mapping function, you can also define your
own function to handle special sequences (cursor motion, insert and
delete chars, etc), buffer flush, and initialization functions.

All of these functions are available for both the termcap and terminfo
versions of curses.

Ross Oliver
Technical Support
The Santa Cruz Operation, Inc.