home *** CD-ROM | disk | FTP | other *** search
- /*
- ocbox.c 11/2/88
-
- % Character coordinate graphics and geometry related utility functions.
- Extracted from obox.c
- by Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 12/09/88 Ted Added opcoord_GetRow, GetCol
- 7/06/89 ted Tweaked opcoord_GetYRow, GetXCol.
- */
-
- #include "oakhead.h"
- /* -------------------------------------------------------------------------- */
-
- void ocbox_pixcoords(cboxp, font, boxp)
- ocbox *cboxp;
- ofont_type font;
- opbox *boxp;
- /*
- Set 'boxp' to contain in pixel coords the character box 'cboxp'
- */
- {
- boxp->xmin = ofont_GetWidth(font) * cboxp->leftcol;
- boxp->xmax = ofont_GetWidth(font) * (cboxp->rightcol + 1);
- boxp->ymin = ofont_GetHeight(font) * cboxp->toprow;
- boxp->ymax = ofont_GetHeight(font) * (cboxp->botrow + 1);
- }
- /* -------------------------------------------------------------------------- */
-
- int opcoord_GetYRow(y, font)
- opcoord y;
- ofont_type font;
- {
- opcoord fh;
-
- if (font != NULL) {
- if ((fh = ofont_GetHeight(font)) != 1) {
- /* Round in the negative direction */
- if (y >= 0) {
- return(y / fh);
- }
- else return((y-fh+1) / fh);
- }
- }
- return((int)y);
- }
- /* -------------------------------------------------------------------------- */
-
- int opcoord_GetXCol(x, font)
- opcoord x;
- ofont_type font;
- {
- opcoord fw;
-
- if (font != NULL) {
- if ((fw = ofont_GetWidth(font)) != 1) {
- /* Round in the negative direction */
- if (x >= 0) {
- return(x / fw);
- }
- else return((x-fw+1) / fw);
- }
- }
- return((int)x);
- }
- /* -------------------------------------------------------------------------- */
-
- void opcoord_GridRound(xp, yp, font)
- opcoord *xp;
- opcoord *yp;
- ofont_type font;
- /*
- Round pixel coordinates so they fall on text grid boundaries, given
- the font.
- */
- {
- if (font == NULL) {
- return;
- }
- *yp = ofont_GetHeight(font) * opcoord_GetYRow(*yp, font);
- *xp = ofont_GetWidth(font) * opcoord_GetXCol(*xp, font);
- }
- /* -------------------------------------------------------------------------- */
-
- boolean ocbox_ScrollVtIn(cboxp, n)
- ocbox *cboxp;
- int n;
- /*
- Squash box into just the part that needs to be repainted after a scroll.
- */
- {
- opcoord newbound;
-
- if (n > 0) {
- newbound = cboxp->botrow - n + 1;
-
- if (newbound < cboxp->toprow) {
- return(FALSE);
- }
- else {
- cboxp->toprow = newbound;
- return(TRUE);
- }
- }
- else if (n < 0) {
- newbound = cboxp->toprow - n - 1;
-
- if (newbound > cboxp->botrow) {
- return(FALSE);
- }
- else {
- cboxp->botrow = newbound;
- return(TRUE);
- }
- }
- else {
- return(FALSE);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- boolean ocbox_ScrollHzIn(cboxp, n)
- ocbox *cboxp;
- int n;
- /*
- Squash box into just the part that needs to be repainted after a scroll.
- */
- {
- opcoord newbound;
-
- if (n > 0) {
- newbound = cboxp->rightcol - n + 1;
-
- if (newbound < cboxp->leftcol) {
- return(FALSE);
- }
- else {
- cboxp->leftcol = newbound;
- return(TRUE);
- }
- }
- else if (n < 0) {
- newbound = cboxp->leftcol - n - 1;
-
- if (newbound > cboxp->rightcol) {
- return(FALSE);
- }
- else {
- cboxp->rightcol = newbound;
- return(TRUE);
- }
- }
- else {
- return(FALSE);
- }
- }
- /* -------------------------------------------------------------------------- */
-
-