home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wtitle.c < prev    next >
C/C++ Source or Header  |  1991-03-17  |  3KB  |  144 lines

  1. /* WTITLE.C contatins wborderwrite()  ( called by macros wtitle and also wps )
  2.  *
  3.  * write a string on the border of the window
  4.  *
  5.  *    if place = 't' write on the top of the window
  6.  *    if place = 'b' write on the bottom
  7.  *
  8.  *    if justify = r/c/l justify the string right/center/left
  9.  *
  10.  *    using the #defines wtitle and wfootnote or wps simplifies this
  11.  *
  12.  *     If the string is NULL the previous border is restored.
  13.  */
  14. #include  "wscreen.h"
  15. #include  "wsys.h"
  16.  
  17.  
  18.  
  19.  
  20. void      wborderwrite (char place, char justify, char *t)
  21.     {
  22.     #ifdef TEXTONLY
  23.         unsigned char far *ptr;
  24.     #endif    /* end TEXTONLY - variable definitions */
  25.  
  26.     int     row, col, lastcol, offset;
  27.     char      boxchar;
  28.     char    boxattr;
  29.  
  30.     int     x;    /* x-position */
  31.  
  32.  
  33.     _NORMALIZE (t);        /* model-dependent ptr normalization */
  34.  
  35.     if ( ! w0->winbox )
  36.         {
  37.         /* cant do it if no border
  38.         */
  39.         return;
  40.         }
  41.  
  42.  
  43.  
  44.     /* select which row to write the title in.
  45.      * move up/down one line to the border area
  46.      *  if a border is present
  47.      */
  48.     row = w0->wintop-1;
  49.     if (place == 'b')
  50.         {
  51.         row += w0->winymax+2;
  52.         }
  53.     col     =        w0-> winleft +1;
  54.     lastcol = col + (w0-> winxmax);
  55.  
  56.  
  57.     /* attribute for text
  58.      */
  59.     boxattr =       w0-> winboxcolor;
  60.  
  61.  
  62.     /* calling with NULL argument means erase the current title
  63.      */
  64.     if ( t == NULL )
  65.         {
  66.         /* what to restore
  67.          */
  68.         boxchar = wbox[ w0-> winbox ].horiz;
  69.  
  70.  
  71.         #ifdef TEXTONLY
  72.  
  73.             ptr = wpage_ram + 2*80*(row) + 2*(col);
  74.             do
  75.                 {
  76.                 *(ptr++) = boxchar;
  77.                 *(ptr++) = boxattr;
  78.                 }
  79.             while ( ++col <= lastcol );
  80.             /* end text mode restore old border */
  81.         #else
  82.             /* graphics mode restore old border */
  83.             do
  84.                 {
  85.                 wputcabs (col, row, boxchar, boxattr,
  86.                     WGOVERWRITE );
  87.                 }
  88.             while ( ++col <= lastcol );
  89.         #endif    /* ifndef TEXTONLY - end graphics restore border */
  90.  
  91.         return;
  92.         } /*end if for restoring old border */
  93.  
  94.  
  95.  
  96.     /* calculate the x- position of the string
  97.      *    for left/center/right positions.
  98.      */
  99.     x = strlen(t);
  100.  
  101.     if ( justify == 'c' )
  102.         {
  103.         offset =  (w0->winxmax -x)/2;
  104.         }
  105.     else
  106.     if ( justify == 'r' )
  107.         {
  108.         offset =  (w0->winxmax -x);
  109.         }
  110.     else     /* left justify the string */
  111.         {
  112.         offset = 0;
  113.         }
  114.  
  115.     /* x position for text output
  116.      */
  117.     col += offset;
  118.  
  119.  
  120.  
  121.  
  122.     #ifdef TEXTONLY
  123.         ptr = wpage_ram + 2*80*row + 2*( col ) ;
  124.     #endif
  125.  
  126.  
  127.     do    {
  128.         #ifdef TEXTONLY
  129.             *(ptr++) = *t;
  130.             *(ptr++) = boxattr;
  131.         #else
  132.             /* graphics mode
  133.              */
  134.             wputcabs ( col, row, *t, boxattr,
  135.                 WGOVERWRITE );
  136.         #endif
  137.  
  138.         }
  139.     while  ( *(++t)  &&  (++col <=lastcol) );
  140.  
  141.     return;
  142.     } /*end wborderwrite */
  143.  
  144.