home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / OCBOX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  3.4 KB  |  165 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.1
  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. */
  17.  
  18. #include "oakhead.h"
  19. /* -------------------------------------------------------------------------- */
  20.  
  21. void ocbox_pixcoords(cboxp, font, boxp)
  22.     ocbox *cboxp;
  23.     ofont_type font;
  24.     opbox *boxp;
  25. /*
  26.     Set 'boxp' to contain in pixel coords the character box 'cboxp'
  27. */
  28. {
  29.     boxp->xmin = ofont_GetWidth(font) * cboxp->leftcol;
  30.     boxp->xmax = ofont_GetWidth(font) * (cboxp->rightcol + 1);
  31.     boxp->ymin = ofont_GetHeight(font) * cboxp->toprow;
  32.     boxp->ymax = ofont_GetHeight(font) * (cboxp->botrow + 1);
  33. }
  34. /* -------------------------------------------------------------------------- */
  35.  
  36. int opcoord_GetYRow(y, font)
  37.     opcoord y;
  38.     ofont_type font;
  39. {
  40.     opcoord fh;
  41.  
  42.     if (font != NULL) {
  43.         if ((fh = ofont_GetHeight(font)) != 1) {
  44.             /* Round in the negative direction */
  45.             if (y >= 0) {
  46.                 return(y / fh);
  47.             }
  48.             else return((y-fh+1) / fh);
  49.         }
  50.     }
  51.     return((int)y);
  52. }
  53. /* -------------------------------------------------------------------------- */
  54.  
  55. int opcoord_GetXCol(x, font)
  56.     opcoord x;
  57.     ofont_type font;
  58. {
  59.     opcoord fw;
  60.  
  61.     if (font != NULL) {
  62.         if ((fw = ofont_GetWidth(font)) != 1) {
  63.             /* Round in the negative direction */
  64.             if (x >= 0) {
  65.                 return(x / fw);
  66.             }
  67.             else return((x-fw+1) / fw);
  68.         }
  69.     }
  70.     return((int)x);
  71. }
  72. /* -------------------------------------------------------------------------- */
  73.  
  74. void opcoord_GridRound(xp, yp, font)
  75.     opcoord *xp;
  76.     opcoord *yp;
  77.     ofont_type font;
  78. /*
  79.     Round pixel coordinates so they fall on text grid boundaries, given
  80.     the font.
  81. */
  82. {
  83.     if (font == NULL) {
  84.         return;
  85.     }
  86.     *yp = ofont_GetHeight(font) * opcoord_GetYRow(*yp, font);
  87.     *xp = ofont_GetWidth(font)  * opcoord_GetXCol(*xp, font);
  88. }
  89. /* -------------------------------------------------------------------------- */
  90.  
  91. boolean ocbox_ScrollVtIn(cboxp, n)
  92.     ocbox *cboxp;
  93.     int n;
  94. /*
  95.     Squash box into just the part that needs to be repainted after a scroll.
  96. */
  97. {
  98.     opcoord newbound;
  99.  
  100.     if (n > 0) {
  101.         newbound = cboxp->botrow - n + 1;
  102.  
  103.         if (newbound < cboxp->toprow) {
  104.             return(FALSE);
  105.         }
  106.         else {
  107.             cboxp->toprow = newbound;
  108.             return(TRUE);
  109.         }
  110.     }
  111.     else if (n < 0) {
  112.         newbound = cboxp->toprow - n - 1;
  113.  
  114.         if (newbound > cboxp->botrow) {
  115.             return(FALSE);
  116.         }
  117.         else {
  118.             cboxp->botrow = newbound;
  119.             return(TRUE);
  120.         }
  121.     }
  122.     else {
  123.         return(FALSE);
  124.     }
  125. }
  126. /* -------------------------------------------------------------------------- */
  127.  
  128. boolean ocbox_ScrollHzIn(cboxp, n)
  129.     ocbox *cboxp;
  130.     int n;
  131. /*
  132.     Squash box into just the part that needs to be repainted after a scroll.
  133. */
  134. {
  135.     opcoord newbound;
  136.  
  137.     if (n > 0) {
  138.         newbound = cboxp->rightcol - n + 1;
  139.  
  140.         if (newbound < cboxp->leftcol) {
  141.             return(FALSE);
  142.         }
  143.         else {
  144.             cboxp->leftcol = newbound;
  145.             return(TRUE);
  146.         }
  147.     }
  148.     else if (n < 0) {
  149.         newbound = cboxp->leftcol - n - 1;
  150.  
  151.         if (newbound > cboxp->rightcol) {
  152.             return(FALSE);
  153.         }
  154.         else {
  155.             cboxp->rightcol = newbound;
  156.             return(TRUE);
  157.         }
  158.     }
  159.     else {
  160.         return(FALSE);
  161.     }
  162. }
  163. /* -------------------------------------------------------------------------- */
  164.  
  165.