home *** CD-ROM | disk | FTP | other *** search
- /*
- * Virtual Window for Windows Metafile (WMF).
- *
- * Need to put more thought into clipping...
- *
- * $Log: window.c,v $
- * Revision 1.7 1995/12/04 19:24:33 JFusco
- * #ifdef'd out some debug messages.
- *
- * Revision 1.6 1994/11/08 22:10:52 JFusco
- * Added iff save.
- *
- * Revision 1.5 1994/11/04 20:51:43 JFusco
- * Added some speedup code.
- *
- * Revision 1.4 1994/06/20 23:23:06 JFusco
- * Added polygon fill routines
- *
- * Revision 1.3 1994/06/19 21:59:45 JFusco
- * Fixed scaling problem when scaling images down.
- * Scaling up has not been tested.
- *
- * Revision 1.2 1994/06/19 10:48:43 JFusco
- * Fixed scaling problems. Need to watch out for possible
- * problems with coodinate systems. Do all WMF files use the
- * same convention?
- *
- * Revision 1.1 94/06/18 02:45:07 JFusco
- * Initial revision
- *
- *
- */
-
- #include <stdio.h>
- #include "wmf.h" /* WMF Structures and types. */
- #include "amiga.h" /* Amiga<->WMF Specific stuff. */
-
- static char RCS_ID[] = "$Id: window.c,v 1.7 1995/12/04 19:24:33 JFusco Exp $";
-
- /* Virtual window origin and extent. */
- yx_pair_t WindowOrg={0,0}, WindowExt={0,0};
- short Top, Left, Bottom, Right;
-
- /* Integer scaling. */
- struct ratio { long num, den; };
- struct scale { struct ratio X, Y; } Scale;
-
- void InitVirtualWindow( wmf_place_hdr_t *PlaceHdr )
- {
- ULONG xfactor, yfactor;
- int aspectx, aspecty;
- struct xy_pair display_dim, extent;
-
- Top = PlaceHdr->Top;
- Left = PlaceHdr->Left;
- Bottom = PlaceHdr->Bottom;
- Right = PlaceHdr->Right;
-
- /* This corrects for non-square pixels. */
- GetPixelAspect( &aspectx, &aspecty );
-
- display_dim.X = WINDOWX-1;
- display_dim.Y = WINDOWY-1;
- extent.X = abs(WindowExt.X);
- extent.Y = abs(WindowExt.Y);
-
- /* Determine scale factor - up or down. */
- if (extent.X > display_dim.X * aspectx || extent.Y > display_dim.Y * aspecty)
- /* Scaling down. */
- {
- /* Is it tall or wide? */
- xfactor = extent.X / (display_dim.X * aspectx);
- yfactor = extent.Y / (display_dim.Y * aspecty);
- if ( abs(yfactor>xfactor) )
- { /* Tall - scale to the Y dimension */
- Scale.X.num = display_dim.X;
- Scale.Y.num = display_dim.Y;
- Scale.X.den = extent.Y;
- Scale.Y.den = extent.Y;
- }
- else
- { /* Wide - scale to the X dimension */
- Scale.X.num = display_dim.X;
- Scale.Y.num = display_dim.Y;
- Scale.X.den = extent.X;
- Scale.Y.den = extent.X;
- }
- }
- else
- /* Scaling up. */
- {
- /* Is it tall or wide? */
- xfactor = (display_dim.X * aspecty) / extent.Y;
- yfactor = (display_dim.Y * aspectx) / extent.X;
- if ( abs(yfactor>xfactor) )
- { /* Tall - scale to the Y dimension */
- Scale.X.num = extent.Y;
- Scale.Y.num = extent.Y;
- Scale.X.den = display_dim.X;
- Scale.Y.den = display_dim.Y;
- }
- else
- { /* Wide - scale to the X dimension */
- Scale.X.num = extent.X;
- Scale.Y.num = extent.X;
- Scale.X.den = display_dim.X;
- Scale.Y.den = display_dim.Y;
- }
- };
-
- #ifdef DEBUG
- printf("Output window will be %d x %d\n", display_dim.X, display_dim.Y);
- printf("X Scale factor is %d/%d\n",Scale.X.num, Scale.X.den);
- printf("Y Scale factor is %d/%d\n",Scale.X.num, Scale.X.den);
- #endif
- }
-
- /* WC stands for Window Coordinates. */
-
- MoveWC( short x, short y )
- {
- register long rx, ry;
-
- /* Need to do real clipping! */
- x = (x>Right) ? Right : x;
- x = (x<Left) ? Left : x;
- y = (y<Top) ? Top : y;
- y = (y>Bottom) ? Bottom : y;
-
- y -= WindowOrg.Y;
- y = -y;
- x -= WindowOrg.X;
-
- rx = x;
- ry = y;
-
- rx *= Scale.X.num;
- rx /= Scale.X.den;
- x = (short) rx;
- ry *= Scale.Y.num;
- ry /= Scale.Y.den;
- y = (short) ry;
- MoveAmiga( x, y );
- }
-
- DrawWC( short x, short y )
- {
- register long rx, ry;
- static short lastx, lasty;
-
- /* Need to do real clipping! */
- x = (x>Right) ? Right : x;
- x = (x<Left) ? Left : x;
- y = (y<Top) ? Top : y;
- y = (y>Bottom) ? Bottom : y;
-
- y -= WindowOrg.Y;
- y = -y;
- x -= WindowOrg.X;
-
- if (x==lastx && y==lasty) {
- return;
- }
- else {
- lastx = x;
- lasty = y;
- }
-
- rx = x;
- ry = y;
-
- rx *= Scale.X.num;
- rx /= Scale.X.den;
- x = (short) rx;
- ry *= Scale.Y.num;
- ry /= Scale.Y.den;
- y = (short) ry;
- DrawAmiga( x, y );
- }
-
- PolygonMoveWC( short x, short y )
- {
- register long rx, ry;
-
- /* Need to do real clipping! */
- x = (x>Right) ? Right : x;
- x = (x<Left) ? Left : x;
- y = (y<Top) ? Top : y;
- y = (y>Bottom) ? Bottom : y;
-
- y -= WindowOrg.Y;
- y = -y;
- x -= WindowOrg.X;
-
- rx = x;
- ry = y;
-
- rx *= Scale.X.num;
- rx /= Scale.X.den;
- x = (short) rx;
- ry *= Scale.Y.num;
- ry /= Scale.Y.den;
- y = (short) ry;
- PolygonMoveAmiga( x, y );
- }
-
- PolygonDrawWC( short x, short y )
- {
- register long rx, ry;
- static short lastx, lasty;
-
- /* Need to do real clipping! */
- x = (x>Right) ? Right : x;
- x = (x<Left) ? Left : x;
- y = (y<Top) ? Top : y;
- y = (y>Bottom) ? Bottom : y;
-
- y -= WindowOrg.Y;
- y = -y;
- x -= WindowOrg.X;
-
- if (x==lastx && y==lasty) {
- return;
- }
- else {
- lastx = x;
- lasty = y;
- }
-
- rx = x;
- ry = y;
-
- rx *= Scale.X.num;
- rx /= Scale.X.den;
- x = (short) rx;
- ry *= Scale.Y.num;
- ry /= Scale.Y.den;
- y = (short) ry;
- PolygonDrawAmiga( x, y );
- }
-
- PolygonEndWC( )
- {
- PolygonEndAmiga( );
- }
-
-
-