home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / OBOXCLIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  5.3 KB  |  163 lines

  1. /*
  2.     oboxclip.c    11/2/88
  3.  
  4.     % Box related clipping functions.
  5.     Extracted from obox.c
  6.     by Ted.
  7.  
  8.     OWL 1.1
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      8/30/89 ted    Changed the clipping code returned by _clipbox funcs.
  15. */
  16.  
  17. #include "oakhead.h"
  18.  
  19. OSTATIC unsigned OWLPRIV opbox_clipboxpoint(_arg3(opbox *, opcoord *, opcoord *));
  20. OSTATIC unsigned OWLPRIV opwh_clipboxpoint(_arg4(odim, odim, opcoord *, opcoord *));
  21. /* -------------------------------------------------------------------------- */
  22.  
  23. unsigned opbox_clipbox(clipboxp, boxp)
  24.     opbox *clipboxp, *boxp;
  25. /*
  26.     Return Sutherland clip code for box in display: 0 if box is completely
  27.     out of display; otherwise bits saying which side(s) it was clipped on:
  28.     1, 2, 4, 8 for right, top, left, bottom; 16 for coming through at all.
  29. */
  30. {
  31.     unsigned tlcode, brcode;
  32.  
  33.     tlcode = opbox_clipboxpoint(clipboxp, &boxp->xmin, &boxp->ymin); 
  34.     brcode = opbox_clipboxpoint(clipboxp, &boxp->xmax, &boxp->ymax); 
  35.  
  36.     if ((tlcode & brcode) != 0) {
  37.         return(0);
  38.     }
  39.     else return(tlcode | brcode | 16);
  40. }
  41. /* -------------------------------------------------------------------------- */
  42.  
  43. static unsigned OWLPRIV opbox_clipboxpoint(clipboxp, xp, yp)
  44.     opbox *clipboxp;
  45.     opcoord *xp, *yp;
  46. /*
  47.     Returns flag if point is out of or on edge of clipbox. This is good for
  48.     box clipping because a box with a point out and the other point on the edge
  49.     on that side should be flagged as out.
  50. */
  51. {
  52.     unsigned scode;
  53.  
  54.     scode = 0;
  55.     if (*xp <= clipboxp->xmin) { scode |= 4; *xp = clipboxp->xmin; }
  56.     if (*yp <= clipboxp->ymin) { scode |= 2; *yp = clipboxp->ymin; }
  57.     if (*xp >= clipboxp->xmax) { scode |= 1; *xp = clipboxp->xmax; }
  58.     if (*yp >= clipboxp->ymax) { scode |= 8; *yp = clipboxp->ymax; }
  59.     return scode;
  60. }
  61. /* -------------------------------------------------------------------------- */
  62.  
  63. unsigned opbox_clippoint(clipboxp, xp, yp)
  64.     opbox *clipboxp;
  65.     opcoord *xp, *yp;
  66. /*
  67.     Return Sutherland clip code for point in clipbox: 0 if point is
  68.     in; otherwise bits saying which side it's out on.
  69.     If the point is on the top or the left edge it is counted as in. This is
  70.     because drawing a pixel "at" a point means filling the grid box to the
  71.     lower right of the box in our convention.
  72. */
  73. {
  74.     unsigned scode;
  75.  
  76.     scode = 0;
  77.     if (*xp < clipboxp->xmin) { scode |= 4; *xp = clipboxp->xmin; }
  78.     if (*yp < clipboxp->ymin) { scode |= 2; *yp = clipboxp->ymin; }
  79.     if (*xp >= clipboxp->xmax) { scode |= 1; *xp = clipboxp->xmax - 1; }
  80.     if (*yp >= clipboxp->ymax) { scode |= 8; *yp = clipboxp->ymax - 1; }
  81.     return scode;
  82. }
  83. /* -------------------------------------------------------------------------- */
  84.  
  85. unsigned ocbox_clippos(clipcboxp, rowp, colp)
  86.     ocbox *clipcboxp;
  87.     int *rowp, *colp;
  88. /*
  89.     Return Sutherland clip code for point in char box: 0 if point is
  90.     in box; otherwise bits saying which side it's out on.
  91. */
  92. {
  93.     unsigned scode;
  94.  
  95.     scode = 0;
  96.     if (*colp < clipcboxp->leftcol)  { scode |= 4; *colp = clipcboxp->leftcol; }
  97.     if (*rowp < clipcboxp->toprow)   { scode |= 2; *rowp = clipcboxp->toprow;  }
  98.     if (*colp > clipcboxp->rightcol) { scode |= 1; *colp = clipcboxp->rightcol;}
  99.     if (*rowp > clipcboxp->botrow)   { scode |= 8; *rowp = clipcboxp->botrow;  }
  100.     return scode;
  101. }
  102. /* -------------------------------------------------------------------------- */
  103.  
  104. unsigned opwh_clipbox(width, height, boxp)
  105.     odim width, height;    /* width and height of 0-origin clipping box */
  106.     opbox *boxp;
  107. /*
  108.     Return Sutherland clip code for box in width/height: 0 if box is completely
  109.     out of width/height; otherwise bits saying which side(s) it was clipped on:
  110.     1, 2, 4, 8 for right, top, left, bottom; 16 for coming through at all.
  111. */
  112. {
  113.     unsigned tlcode, brcode;
  114.  
  115.     tlcode = opwh_clipboxpoint(width, height, &boxp->xmin, &boxp->ymin); 
  116.     brcode = opwh_clipboxpoint(width, height, &boxp->xmax, &boxp->ymax); 
  117.  
  118.     if ((tlcode & brcode) != 0) {
  119.         return(0);
  120.     }
  121.     else return(tlcode | brcode | 16);
  122. }
  123. /* -------------------------------------------------------------------------- */
  124.  
  125. static unsigned OWLPRIV opwh_clipboxpoint(width, height, xp, yp)
  126.     odim width, height;    /* width and height of 0-origin clipping box */
  127.     opcoord *xp, *yp;
  128. /*
  129.     Return Sutherland clip code for point in box: 0 if point is
  130.     in box; otherwise bits saying which side it's out on.
  131. */
  132. {
  133.     unsigned scode;
  134.  
  135.     scode = 0;
  136.     if               (*xp <= 0)        { scode |= 4; *xp = 0; }
  137.     else if ((odim) *xp >= width)    { scode |= 1; *xp = width; }
  138.     if               (*yp <= 0)        { scode |= 2; *yp = 0; }
  139.     else if ((odim) *yp >= height)    { scode |= 8; *yp = height; }
  140.     return scode;
  141. }
  142. /* -------------------------------------------------------------------------- */
  143.  
  144. unsigned opwh_clippoint(width, height, xp, yp)
  145.     odim width, height;    /* width and height of 0-origin clipping box */
  146.     opcoord *xp, *yp;
  147. /*
  148.     Return Sutherland clip code for point in box: 0 if point is
  149.     in box; otherwise bits saying which side it's out on.
  150. */
  151. {
  152.     unsigned scode;
  153.  
  154.     scode = 0;
  155.     if               (*xp < 0)        { scode |= 4; *xp = 0; }
  156.     else if ((odim) *xp >= width)    { scode |= 1; *xp = width - 1; }
  157.     if               (*yp < 0)        { scode |= 2; *yp = 0; }
  158.     else if ((odim) *yp >= height)    { scode |= 8; *yp = height - 1; }
  159.     return scode;
  160. }
  161. /* -------------------------------------------------------------------------- */
  162.  
  163.