home *** CD-ROM | disk | FTP | other *** search
- /*
- oboxclip.c 11/2/88
-
- % Box related clipping functions.
- Extracted from obox.c
- by Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 8/30/89 ted Changed the clipping code returned by _clipbox funcs.
- */
-
- #include "oakhead.h"
-
- OSTATIC unsigned OWLPRIV opbox_clipboxpoint(_arg3(opbox *, opcoord *, opcoord *));
- OSTATIC unsigned OWLPRIV opwh_clipboxpoint(_arg4(odim, odim, opcoord *, opcoord *));
- /* -------------------------------------------------------------------------- */
-
- unsigned opbox_clipbox(clipboxp, boxp)
- opbox *clipboxp, *boxp;
- /*
- Return Sutherland clip code for box in display: 0 if box is completely
- out of display; otherwise bits saying which side(s) it was clipped on:
- 1, 2, 4, 8 for right, top, left, bottom; 16 for coming through at all.
- */
- {
- unsigned tlcode, brcode;
-
- tlcode = opbox_clipboxpoint(clipboxp, &boxp->xmin, &boxp->ymin);
- brcode = opbox_clipboxpoint(clipboxp, &boxp->xmax, &boxp->ymax);
-
- if ((tlcode & brcode) != 0) {
- return(0);
- }
- else return(tlcode | brcode | 16);
- }
- /* -------------------------------------------------------------------------- */
-
- static unsigned OWLPRIV opbox_clipboxpoint(clipboxp, xp, yp)
- opbox *clipboxp;
- opcoord *xp, *yp;
- /*
- Returns flag if point is out of or on edge of clipbox. This is good for
- box clipping because a box with a point out and the other point on the edge
- on that side should be flagged as out.
- */
- {
- unsigned scode;
-
- scode = 0;
- if (*xp <= clipboxp->xmin) { scode |= 4; *xp = clipboxp->xmin; }
- if (*yp <= clipboxp->ymin) { scode |= 2; *yp = clipboxp->ymin; }
- if (*xp >= clipboxp->xmax) { scode |= 1; *xp = clipboxp->xmax; }
- if (*yp >= clipboxp->ymax) { scode |= 8; *yp = clipboxp->ymax; }
- return scode;
- }
- /* -------------------------------------------------------------------------- */
-
- unsigned opbox_clippoint(clipboxp, xp, yp)
- opbox *clipboxp;
- opcoord *xp, *yp;
- /*
- Return Sutherland clip code for point in clipbox: 0 if point is
- in; otherwise bits saying which side it's out on.
- If the point is on the top or the left edge it is counted as in. This is
- because drawing a pixel "at" a point means filling the grid box to the
- lower right of the box in our convention.
- */
- {
- unsigned scode;
-
- scode = 0;
- if (*xp < clipboxp->xmin) { scode |= 4; *xp = clipboxp->xmin; }
- if (*yp < clipboxp->ymin) { scode |= 2; *yp = clipboxp->ymin; }
- if (*xp >= clipboxp->xmax) { scode |= 1; *xp = clipboxp->xmax - 1; }
- if (*yp >= clipboxp->ymax) { scode |= 8; *yp = clipboxp->ymax - 1; }
- return scode;
- }
- /* -------------------------------------------------------------------------- */
-
- unsigned ocbox_clippos(clipcboxp, rowp, colp)
- ocbox *clipcboxp;
- int *rowp, *colp;
- /*
- Return Sutherland clip code for point in char box: 0 if point is
- in box; otherwise bits saying which side it's out on.
- */
- {
- unsigned scode;
-
- scode = 0;
- if (*colp < clipcboxp->leftcol) { scode |= 4; *colp = clipcboxp->leftcol; }
- if (*rowp < clipcboxp->toprow) { scode |= 2; *rowp = clipcboxp->toprow; }
- if (*colp > clipcboxp->rightcol) { scode |= 1; *colp = clipcboxp->rightcol;}
- if (*rowp > clipcboxp->botrow) { scode |= 8; *rowp = clipcboxp->botrow; }
- return scode;
- }
- /* -------------------------------------------------------------------------- */
-
- unsigned opwh_clipbox(width, height, boxp)
- odim width, height; /* width and height of 0-origin clipping box */
- opbox *boxp;
- /*
- Return Sutherland clip code for box in width/height: 0 if box is completely
- out of width/height; otherwise bits saying which side(s) it was clipped on:
- 1, 2, 4, 8 for right, top, left, bottom; 16 for coming through at all.
- */
- {
- unsigned tlcode, brcode;
-
- tlcode = opwh_clipboxpoint(width, height, &boxp->xmin, &boxp->ymin);
- brcode = opwh_clipboxpoint(width, height, &boxp->xmax, &boxp->ymax);
-
- if ((tlcode & brcode) != 0) {
- return(0);
- }
- else return(tlcode | brcode | 16);
- }
- /* -------------------------------------------------------------------------- */
-
- static unsigned OWLPRIV opwh_clipboxpoint(width, height, xp, yp)
- odim width, height; /* width and height of 0-origin clipping box */
- opcoord *xp, *yp;
- /*
- Return Sutherland clip code for point in box: 0 if point is
- in box; otherwise bits saying which side it's out on.
- */
- {
- unsigned scode;
-
- scode = 0;
- if (*xp <= 0) { scode |= 4; *xp = 0; }
- else if ((odim) *xp >= width) { scode |= 1; *xp = width; }
- if (*yp <= 0) { scode |= 2; *yp = 0; }
- else if ((odim) *yp >= height) { scode |= 8; *yp = height; }
- return scode;
- }
- /* -------------------------------------------------------------------------- */
-
- unsigned opwh_clippoint(width, height, xp, yp)
- odim width, height; /* width and height of 0-origin clipping box */
- opcoord *xp, *yp;
- /*
- Return Sutherland clip code for point in box: 0 if point is
- in box; otherwise bits saying which side it's out on.
- */
- {
- unsigned scode;
-
- scode = 0;
- if (*xp < 0) { scode |= 4; *xp = 0; }
- else if ((odim) *xp >= width) { scode |= 1; *xp = width - 1; }
- if (*yp < 0) { scode |= 2; *yp = 0; }
- else if ((odim) *yp >= height) { scode |= 8; *yp = height - 1; }
- return scode;
- }
- /* -------------------------------------------------------------------------- */
-
-