home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CURSES.LZH / BOXES.C < prev    next >
C/C++ Source or Header  |  1980-01-01  |  4KB  |  134 lines

  1. /****************************************************************/
  2. /* Box() routines of the PCcurses package            */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free to make it public domain.    */
  9. /*        Bjorn Larsson (...mcvax!enea!infovax!bl)    */
  10. /****************************************************************/
  11. /* 1.0:    Release:                    870515    */
  12. /* 1.2:    Max limits off by 1. Fixed thanks to S. Creps:    881002    */
  13. /* 1.3:    MSC '-W3', Turbo'C' '-w -w-pro' checks. Support        */
  14. /*    for border(), wborder() functions:        881005    */
  15. /****************************************************************/
  16.  
  17. #include <curses.h>
  18. #include <curspriv.h>
  19.  
  20. char _curses_boxes_rcsid[] = "@(#)boxes.c v1.3 - 881005";
  21.  
  22. /****************************************************************/
  23. /* wbox(win,ymin,xmin,ymax,xmax,v,h) draws a box in window    */
  24. /* 'win', enclosing the area xmin-xmax and ymin-xmax. If    */
  25. /* xmax and/or ymax is 0, the window max value is used. 'v' and    */
  26. /* 'h' are the vertical and horizontal characters to use. If    */
  27. /* 'v' and 'h' are PC grapics lines, wbox will make the corners    */
  28. /* in a pretty way.                        */
  29. /****************************************************************/
  30.  
  31. int    wbox(win,ymin,xmin,ymax,xmax,v,h)
  32.   WINDOW    *win;
  33.   int         ymin;
  34.   int         xmin;
  35.   int         ymax;
  36.   int         xmax;
  37.   char         v;
  38.   char         h;
  39.   {
  40.   static int     l, r, t, b, tl, tr, bl,br;    /* border chars */
  41.   int         i;
  42.  
  43.   if (ymax == 0)
  44.     ymax = win->_maxy - 1;
  45.   if (xmax == 0)
  46.     xmax = win->_maxx - 1;
  47.  
  48.   if (ymin >= win->_maxy || ymax > win->_maxy ||
  49.       xmin >= win->_maxx || xmax > win->_maxx ||
  50.       ymin >= ymax || xmin >= xmax
  51.      )
  52.      return(ERR);
  53.  
  54.   l = r = v & 0xff;            /* get rid of sign-extended int */
  55.   t = b = h & 0xff;
  56.   tl = tr = bl = br = v;        /* default same as vertical */
  57.  
  58.   if (l == 0xba)            /* vertical double bars */
  59.     {
  60.     if (t == 0xcd)            /* horizontal too? */
  61.       {tl=0xc9;tr=0xbb;bl=0xc8;br=0xbc;}/* use double bar corners */
  62.     else
  63.       {tl=0xd6;tr=0xb7;bl=0xd3;br=0xbd;}/* use hor-s vert-d corners */
  64.     } /* if */
  65.  
  66.   if (l == 0xb3)            /* vertical single bars */
  67.     {
  68.     if (t == 0xcd)            
  69.       {tl=0xd5;tr=0xb8;bl=0xd4;br=0xbe;}/* horizontal double bars */
  70.     else                
  71.       {tl=0xda;tr=0xbf;bl=0xc0;br=0xd9;}/* use hor-s vert-s bars */
  72.     } /* if */
  73.  
  74.   if (win->_borderchars[0])        /* border() settings override parms */
  75.     l = win->_borderchars[0];
  76.   if (win->_borderchars[3])
  77.     r = win->_borderchars[1];
  78.   if (win->_borderchars[3])
  79.     t = win->_borderchars[2];
  80.   if (win->_borderchars[3])
  81.     b = win->_borderchars[3];
  82.   if (win->_borderchars[4])
  83.     tl = win->_borderchars[4];
  84.   if (win->_borderchars[5])
  85.     tr = win->_borderchars[5];
  86.   if (win->_borderchars[6])
  87.     bl = win->_borderchars[6];
  88.   if (win->_borderchars[7])
  89.     br = win->_borderchars[7];
  90.  
  91.   for (i = xmin+1;i <= xmax-1;i++)
  92.     {
  93.     win->_line[ymin][i] = t | win->_attrs;
  94.     win->_line[ymax][i] = b | win->_attrs;
  95.     }
  96.   for (i = ymin+1;i <= ymax-1;i++)
  97.     {
  98.     win->_line[i][xmin] = l | win->_attrs;
  99.     win->_line[i][xmax] = r | win->_attrs;
  100.     }
  101.   win->_line[ymin][xmin] = tl | win->_attrs;
  102.   win->_line[ymin][xmax] = tr | win->_attrs;
  103.   win->_line[ymax][xmin] = bl | win->_attrs;
  104.   win->_line[ymax][xmax] = br | win->_attrs;
  105.  
  106.   for (i=ymin; i <= ymax ; i++)
  107.     {
  108.     if (win->_minchng[i] == _NO_CHANGE)
  109.       {
  110.       win->_minchng[i] = xmin;
  111.       win->_maxchng[i] = xmax;
  112.       } /* if */
  113.     else
  114.       {
  115.       win->_minchng[i] = min(win->_minchng[i], xmin);
  116.       win->_maxchng[i] = max(win->_maxchng[i], xmax);
  117.       } /* else */
  118.     } /* for */
  119.   return(OK);
  120.   } /* box */
  121.  
  122. /****************************************************************/
  123. /* box(win,v,h) draws a box around window window 'win'. 'v' and    */
  124. /* 'h' are the vertical and horizontal characters to use.    */
  125. /****************************************************************/
  126.  
  127. void    box(win,v,h)
  128.   WINDOW    *win;
  129.   char         v;
  130.   char         h;
  131.   {
  132.   wbox(win,0,0,0,0,v,h);
  133.   } /* box */
  134.