home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / pccurs14.zoo / pccurses.2 / boxes.c < prev    next >
C/C++ Source or Header  |  1990-01-20  |  4KB  |  120 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 (bl@infovox.se)    */
  10. /****************************************************************/
  11. /* 1.4:  References to win->borderchar[] removed due to        */
  12. /*     re-defined border() functions. Use of short        */
  13. /*     wherever possible. Portability improvements:    900114    */
  14. /* 1.3:  MSC '-W3', Turbo'C' '-w -w-pro' checks.        */
  15. /*     Support for border(), wborder() functions:    881005    */
  16. /* 1.2:     Max limits off by 1. Fixed thanks to S. Creps:    881002    */
  17. /* 1.0:     Release:                    870515    */
  18. /****************************************************************/
  19.  
  20. #include <curses.h>
  21. #include <curspriv.h>
  22.  
  23. char _curses_boxes_rcsid[] = "@(#)boxes.c      v.1.4  - 900114";
  24.  
  25. /****************************************************************/
  26. /* wbox(win,ymin,xmin,ymax,xmax,v,h) draws a box in window    */
  27. /* 'win', enclosing the area xmin-xmax and ymin-xmax. If    */
  28. /* xmax and/or ymax is 0, the window max value is used. 'v' and    */
  29. /* 'h' are the vertical and horizontal characters to use. If    */
  30. /* 'v' and 'h' are PC grapics lines, wbox will make the corners    */
  31. /* in a pretty way.                        */
  32. /****************************************************************/
  33.  
  34. int    wbox(win,ymin,xmin,ymax,xmax,v,h)
  35.   WINDOW    *win;
  36.   int         ymin;
  37.   int         xmin;
  38.   int         ymax;
  39.   int         xmax;
  40.   char         v;
  41.   char         h;
  42.   {
  43.   static short     l, r, t, b, tl, tr, bl,br;    /* border chars */
  44.   short         i;
  45.  
  46.   if (ymax == 0)
  47.     ymax = win->_maxy - 1;
  48.   if (xmax == 0)
  49.     xmax = win->_maxx - 1;
  50.  
  51.   if (ymin >= win->_maxy || ymax > win->_maxy ||
  52.       xmin >= win->_maxx || xmax > win->_maxx ||
  53.       ymin >= ymax || xmin >= xmax
  54.      )
  55.      return(ERR);
  56.  
  57.   l = r = v & 0xff;            /* get rid of sign-extended int */
  58.   t = b = h & 0xff;
  59.   tl = tr = bl = br = v;        /* default same as vertical */
  60.  
  61.   if (l == 0xba)            /* vertical double bars */
  62.     {
  63.     if (t == 0xcd)            /* horizontal too? */
  64.       {tl=0xc9;tr=0xbb;bl=0xc8;br=0xbc;}/* use double bar corners */
  65.     else
  66.       {tl=0xd6;tr=0xb7;bl=0xd3;br=0xbd;}/* use hor-s vert-d corners */
  67.     } /* if */
  68.  
  69.   if (l == 0xb3)            /* vertical single bars */
  70.     {
  71.     if (t == 0xcd)            
  72.       {tl=0xd5;tr=0xb8;bl=0xd4;br=0xbe;}/* horizontal double bars */
  73.     else                
  74.       {tl=0xda;tr=0xbf;bl=0xc0;br=0xd9;}/* use hor-s vert-s bars */
  75.     } /* if */
  76.  
  77.   for (i = xmin+1;i <= xmax-1;i++)
  78.     {
  79.     win->_line[ymin][i] = t | win->_attrs;
  80.     win->_line[ymax][i] = b | win->_attrs;
  81.     }
  82.   for (i = ymin+1;i <= ymax-1;i++)
  83.     {
  84.     win->_line[i][xmin] = l | win->_attrs;
  85.     win->_line[i][xmax] = r | win->_attrs;
  86.     }
  87.   win->_line[ymin][xmin] = tl | win->_attrs;
  88.   win->_line[ymin][xmax] = tr | win->_attrs;
  89.   win->_line[ymax][xmin] = bl | win->_attrs;
  90.   win->_line[ymax][xmax] = br | win->_attrs;
  91.  
  92.   for (i=ymin; i <= ymax ; i++)
  93.     {
  94.     if (win->_minchng[i] == _NO_CHANGE)
  95.       {
  96.       win->_minchng[i] = xmin;
  97.       win->_maxchng[i] = xmax;
  98.       } /* if */
  99.     else
  100.       {
  101.       win->_minchng[i] = min(win->_minchng[i], xmin);
  102.       win->_maxchng[i] = max(win->_maxchng[i], xmax);
  103.       } /* else */
  104.     } /* for */
  105.   return(OK);
  106.   } /* box */
  107.  
  108. /****************************************************************/
  109. /* box(win,v,h) draws a box around window window 'win'. 'v' and    */
  110. /* 'h' are the vertical and horizontal characters to use.    */
  111. /****************************************************************/
  112.  
  113. void    box(win,v,h)
  114.   WINDOW    *win;
  115.   char         v;
  116.   char         h;
  117.   {
  118.   wbox(win,0,0,0,0,v,h);
  119.   } /* box */
  120.