home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / OPBOX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-28  |  4.9 KB  |  192 lines

  1. /*
  2.     opbox.c    5/15/88
  3.  
  4.     % Pixel-coordinate graphics and geometry related utility functions.
  5.     by Ted.
  6.  
  7.     OWL 1.2
  8.     Copyright (c) 1988, by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13.       8/17/88 jmd      removed  eNOMEM
  14.      10/19/88 ted    split out ocolmap stuff to ocolmap.c
  15.      11/02/88 ted:    split out ocbox functions to ocbox.c and clipping functions
  16.                     to oboxclip.c, renamed to opbox.c
  17.      5/09/89 ted    renamed old set's to copy's, added new set's.
  18.      5/09/89 ted    removed _point_copy because nobody uses it.
  19.      7/06/89 ted    Subtracted 1 from botrow and rightcol in opbox_charcoords.
  20.      3/28/90 jmd    ansi-fied
  21. */
  22.  
  23. #include "oakhead.h"
  24. /* -------------------------------------------------------------------------- */
  25.  
  26. void opbox_charcoords(opbox *boxp, ofont_type font, ocbox *cboxp)
  27. /*
  28.     Set 'cboxp' to contain in char coords the pixel box 'boxp'.
  29.     If 'boxp' clips the chars in half, 'cboxp' gets rounded outward.
  30. */
  31. {
  32.     cboxp->toprow  = opcoord_GetYRow(boxp->ymin, font);
  33.     /* Round botrow up and then subtract one row */
  34.     cboxp->botrow  = opcoord_GetYRow(boxp->ymax - 1, font);
  35.  
  36.     cboxp->leftcol = opcoord_GetXCol(boxp->xmin, font); 
  37.     /* Round rightcol right and then subtract one col */
  38.     cboxp->rightcol= opcoord_GetXCol(boxp->xmax - 1, font);
  39. }
  40. /* -------------------------------------------------------------------------- */
  41.  
  42. void opbox_uncover(opbox *winboxp, opbox *boxp)
  43. /*
  44.     Set 'boxp' to that part of boxp not intersecting with winboxp.
  45.     NOTE: only useful for boxes with identical top&bottom or left&right sides!
  46. */
  47. {
  48.     if (winboxp->ymin == boxp->ymin && winboxp->ymax == boxp->ymax) {
  49.         if (winboxp->xmin > boxp->xmin && winboxp->xmin < boxp->xmax) {
  50.             boxp->xmax = winboxp->xmin;
  51.         }
  52.         else if (winboxp->xmax < boxp->xmax && winboxp->xmax > boxp->xmin) {
  53.             boxp->xmin = winboxp->xmax;
  54.         }
  55.     }
  56.     else if (winboxp->xmin == boxp->xmin && winboxp->xmax == boxp->xmax) {
  57.         if (winboxp->ymin > boxp->ymin && winboxp->ymin < boxp->ymax) {
  58.             boxp->ymax = winboxp->ymin;
  59.         }
  60.         else if (winboxp->ymax < boxp->ymax && winboxp->ymax > boxp->ymin) {
  61.             boxp->ymin = winboxp->ymax;
  62.         }
  63.     }
  64. }
  65. /* -------------------------------------------------------------------------- */
  66.  
  67. boolean opbox_empty(opbox *boxp)
  68. /*
  69.     Return TRUE if 'boxp' is an empty or inverted box.
  70. */
  71. {
  72.     return (boxp->xmin >= boxp->xmax || boxp->ymin >= boxp->ymax);
  73. }
  74. /* -------------------------------------------------------------------------- */
  75.  
  76. boolean opbox_ScrollVtIn(opbox *boxp, int n)
  77. /*
  78.     Squash box into just the part that needs to be repainted after a scroll.
  79. */
  80. {
  81.     opcoord newbound;
  82.  
  83.     if (n > 0) {
  84.         newbound = boxp->ymax - n;
  85.  
  86.         if (newbound <= boxp->ymin) {
  87.             return(FALSE);
  88.         }
  89.         else {
  90.             boxp->ymin = newbound;
  91.             return(TRUE);
  92.         }
  93.     }
  94.     else if (n < 0) {
  95.         newbound = boxp->ymin - n;
  96.  
  97.         if (newbound >= boxp->ymax) {
  98.             return(FALSE);
  99.         }
  100.         else {
  101.             boxp->ymax = newbound;
  102.             return(TRUE);
  103.         }
  104.     }
  105.     else {
  106.         return(FALSE);
  107.     }
  108. }
  109. /* -------------------------------------------------------------------------- */
  110.  
  111. boolean opbox_ScrollHzIn(opbox *boxp, int n)
  112. /*
  113.     Squash box into just the part that needs to be repainted after a scroll.
  114. */
  115. {
  116.     opcoord newbound;
  117.  
  118.     if (n > 0) {
  119.         newbound = boxp->xmax - n;
  120.  
  121.         if (newbound <= boxp->xmin) {
  122.             return(FALSE);
  123.         }
  124.         else {
  125.             boxp->xmin = newbound;
  126.             return(TRUE);
  127.         }
  128.     }
  129.     else if (n < 0) {
  130.         newbound = boxp->xmin - n;
  131.  
  132.         if (newbound >= boxp->xmax) {
  133.             return(FALSE);
  134.         }
  135.         else {
  136.             boxp->xmax = newbound;
  137.             return(TRUE);
  138.         }
  139.     }
  140.     else {
  141.         return(FALSE);
  142.     }
  143. }
  144. /* -------------------------------------------------------------------------- */
  145. /* Functions doubling for opboxes and ocboxes */
  146. /* -------------------------------------------------------------------------- */
  147.  
  148. odim _box_GetWidth(opbox *boxp)
  149. {
  150.     return(boxp->xmax - boxp->xmin);
  151. }
  152. /* -------------------------------------------------------------------------- */
  153.  
  154. odim _box_GetHeight(opbox *boxp)
  155. {
  156.     return(boxp->ymax - boxp->ymin);
  157. }
  158. /* -------------------------------------------------------------------------- */
  159.  
  160. opbox *_box_copy(opbox *dboxp, opbox *sboxp)
  161. {
  162.     dboxp->xmin = sboxp->xmin;
  163.     dboxp->ymin = sboxp->ymin;
  164.     dboxp->xmax = sboxp->xmax;
  165.     dboxp->ymax = sboxp->ymax;
  166.     return(dboxp);
  167. }
  168. /* -------------------------------------------------------------------------- */
  169.  
  170. opbox *_box_trans(opbox *boxp, opcoord xdisp, opcoord ydisp)
  171. {
  172.     boxp->xmin += xdisp;
  173.     boxp->xmax += xdisp;
  174.     boxp->ymin += ydisp;
  175.     boxp->ymax += ydisp;
  176.     return(boxp);
  177. }
  178. /* -------------------------------------------------------------------------- */
  179.  
  180. boolean _box_equal(opbox *boxp1, opbox *boxp2)
  181. /*
  182.     Return TRUE if 'boxp' is an empty or inverted box.
  183. */
  184. {
  185.     return (boxp1->xmin == boxp2->xmin &&
  186.             boxp1->xmax == boxp2->xmax &&
  187.             boxp1->ymin == boxp2->ymin &&
  188.             boxp1->ymax == boxp2->ymax);
  189. }
  190. /* -------------------------------------------------------------------------- */
  191.  
  192.