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

  1. /*
  2.     ocbox.c    11/2/88
  3.  
  4.     % Character coordinate graphics and geometry related utility functions.
  5.     Extracted from obox.c
  6.     by Ted.
  7.  
  8.     OWL 1.2
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.     12/09/88 Ted    Added opcoord_GetRow, GetCol
  15.      7/06/89 ted    Tweaked opcoord_GetYRow, GetXCol.
  16.      3/28/90 jmd    ansi-fied
  17. */
  18.  
  19. #include "oakhead.h"
  20. /* -------------------------------------------------------------------------- */
  21.  
  22. void ocbox_pixcoords(ocbox *cboxp, ofont_type font, opbox *boxp)
  23. /*
  24.     Set 'boxp' to contain in pixel coords the character box 'cboxp'
  25. */
  26. {
  27.     boxp->xmin = ofont_GetWidth(font) * cboxp->leftcol;
  28.     boxp->xmax = ofont_GetWidth(font) * (cboxp->rightcol + 1);
  29.     boxp->ymin = ofont_GetHeight(font) * cboxp->toprow;
  30.     boxp->ymax = ofont_GetHeight(font) * (cboxp->botrow + 1);
  31. }
  32. /* -------------------------------------------------------------------------- */
  33.  
  34. int opcoord_GetYRow(opcoord y, ofont_type font)
  35. {
  36.     opcoord fh;
  37.  
  38.     if (font != NULL) {
  39.         if ((fh = ofont_GetHeight(font)) != 1) {
  40.             /* Round in the negative direction */
  41.             if (y >= 0) {
  42.                 return(y / fh);
  43.             }
  44.             else return((y-fh+1) / fh);
  45.         }
  46.     }
  47.     return((int)y);
  48. }
  49. /* -------------------------------------------------------------------------- */
  50.  
  51. int opcoord_GetXCol(opcoord x, ofont_type font)
  52. {
  53.     opcoord fw;
  54.  
  55.     if (font != NULL) {
  56.         if ((fw = ofont_GetWidth(font)) != 1) {
  57.             /* Round in the negative direction */
  58.             if (x >= 0) {
  59.                 return(x / fw);
  60.             }
  61.             else return((x-fw+1) / fw);
  62.         }
  63.     }
  64.     return((int)x);
  65. }
  66. /* -------------------------------------------------------------------------- */
  67.  
  68. void opcoord_GridRound(opcoord *xp, opcoord *yp, ofont_type font)
  69. /*
  70.     Round pixel coordinates so they fall on text grid boundaries, given
  71.     the font.
  72. */
  73. {
  74.     if (font == NULL) {
  75.         return;
  76.     }
  77.     *yp = ofont_GetHeight(font) * opcoord_GetYRow(*yp, font);
  78.     *xp = ofont_GetWidth(font)  * opcoord_GetXCol(*xp, font);
  79. }
  80. /* -------------------------------------------------------------------------- */
  81.  
  82. boolean ocbox_ScrollVtIn(ocbox *cboxp, int n)
  83. /*
  84.     Squash box into just the part that needs to be repainted after a scroll.
  85. */
  86. {
  87.     opcoord newbound;
  88.  
  89.     if (n > 0) {
  90.         newbound = cboxp->botrow - n + 1;
  91.  
  92.         if (newbound < cboxp->toprow) {
  93.             return(FALSE);
  94.         }
  95.         else {
  96.             cboxp->toprow = newbound;
  97.             return(TRUE);
  98.         }
  99.     }
  100.     else if (n < 0) {
  101.         newbound = cboxp->toprow - n - 1;
  102.  
  103.         if (newbound > cboxp->botrow) {
  104.             return(FALSE);
  105.         }
  106.         else {
  107.             cboxp->botrow = newbound;
  108.             return(TRUE);
  109.         }
  110.     }
  111.     else {
  112.         return(FALSE);
  113.     }
  114. }
  115. /* -------------------------------------------------------------------------- */
  116.  
  117. boolean ocbox_ScrollHzIn(ocbox *cboxp, int n)
  118. /*
  119.     Squash box into just the part that needs to be repainted after a scroll.
  120. */
  121. {
  122.     opcoord newbound;
  123.  
  124.     if (n > 0) {
  125.         newbound = cboxp->rightcol - n + 1;
  126.  
  127.         if (newbound < cboxp->leftcol) {
  128.             return(FALSE);
  129.         }
  130.         else {
  131.             cboxp->leftcol = newbound;
  132.             return(TRUE);
  133.         }
  134.     }
  135.     else if (n < 0) {
  136.         newbound = cboxp->leftcol - n - 1;
  137.  
  138.         if (newbound > cboxp->rightcol) {
  139.             return(FALSE);
  140.         }
  141.         else {
  142.             cboxp->rightcol = newbound;
  143.             return(TRUE);
  144.         }
  145.     }
  146.     else {
  147.         return(FALSE);
  148.     }
  149. }
  150. /* -------------------------------------------------------------------------- */
  151.  
  152.