/* fillarea.c 1.1 */ /* Copyright 1992, 1993 O'Reilly and Associates, Inc. Permission to use, copy, and modify this program is hereby granted, as long as this copyright notice appears in each copy of the program source code. */ #include "book_utils.h" #define WIN_GEOM "500x500+50+50" /* Structure ID */ static PEXStructure struct_id; /* Miscellaneous constants we use. */ #define NUM_CURVE_SEGMENTS 40 #define X_START 0.1 #define X_SIZE 0.2 #define Y_START 0.75 #define Y_SIZE 0.05 static PEXCoord2D chevron[] = {{.1,.3},{.2,.35},{.3,.3},{.2,.5}}; static PEXCoord2D octagon[] = {{.4,.45},{.45,.4},{.55,.4}, {.6,.45}, {.6,.55},{.55,.6}, {.45,.6},{.4,.55}}; static PEXCoord2D keyhole[] = {{.7,.3},{.9,.3},{.9,.5},{.7,.5}, {.8,.35},{.84,.4},{.8,.45}}; static PEXCoord bowtie[] = {{.7,.8,.5},{.7,.7,.5},{.9,.8,.5}, {.9,.7,.5}}; static void create_structure( dpy ) Display *dpy; { PEXColor color; PEXCoord2D curve[NUM_CURVE_SEGMENTS + 1]; double dx, angle; int i; /* Create the structure. */ struct_id = PEXCreateStructure( dpy ); /* Generate the points for the sine curve. */ dx = X_SIZE / NUM_CURVE_SEGMENTS; curve[0].x = X_START; curve[0].y = Y_START; for ( i = 1; i <= NUM_CURVE_SEGMENTS; i++ ) { curve[i].x = curve[i-1].x + dx; angle = ((curve[i].x - X_START) / X_SIZE) * 2 * M_PI; curve[i].y = Y_START + Y_SIZE * sin( angle ); } /* Set the interior style and color. */ PEXSetInteriorStyle( dpy, struct_id, PEXOCStore, PEXInteriorStyleSolid ); SET_COLOR( 1, 1, 1, color ); /* white */ PEXSetSurfaceColor( dpy, struct_id, PEXOCStore, PEXColorTypeRGB, &color ); /* Distinguish between front and back faces. */ PEXSetFacetDistinguishFlag( dpy, struct_id, PEXOCStore, True ); /* Set the back interior style and color. */ PEXSetBFInteriorStyle( dpy, struct_id, PEXOCStore, PEXInteriorStyleSolid ); SET_COLOR( 1, 1, 0, color ); /* yellow */ PEXSetBFSurfaceColor( dpy, struct_id, PEXOCStore, PEXColorTypeRGB, &color ); /* Create the fill area for the "curve." */ PEXFillArea2D( dpy, struct_id, PEXOCStore, PEXShapeComplex, True, NUM_CURVE_SEGMENTS + 1, curve ); /* Create the fill area for the chevron. */ PEXFillArea2D( dpy, struct_id, PEXOCStore, PEXShapeNonConvex, True, 4, chevron ); /* Create the fill area for the octagon. */ PEXFillArea2D( dpy, struct_id, PEXOCStore, PEXShapeConvex, True, 8, octagon ); /* Create the fill area for the key hole. */ PEXFillArea2D( dpy, struct_id, PEXOCStore, PEXShapeComplex, True, 7, keyhole ); /* Create a 3D fill area for the bow tie. */ PEXFillArea( dpy, struct_id, PEXOCStore, PEXShapeComplex, True, 4, bowtie ); } static void redraw( dpy, window, renderer ) Display *dpy; Window window; PEXRenderer renderer; { XClearWindow( dpy, window ); PEXRenderNetwork( dpy, window, renderer, struct_id ); XFlush( dpy ); } main( argc, argv ) int argc; char *argv[]; { Display *dpy; Window window; XEvent event; XVisualInfo vis_info; XColor bkgd_color; XStandardColormap cmap_info; PEXColorApproxEntry capx_info; PEXRenderer renderer; PEXRendererAttributes rattrs; PEXExtensionInfo *pexinfo; int done = 0; /* Open a display and initialize PEX. */ dpy = ora_init_pex( argv, &pexinfo ); if ( !dpy ) exit(1); /* Determine the best visual to use. */ ora_find_best_visual( dpy, &vis_info ); /* Get a standard colormap for the visual. */ if ( !ora_get_standard_colormap( dpy, &vis_info, &cmap_info ) ) { fprintf ( stderr, "Cannot find a standard colormap\n" ); exit(1); } ora_set_stdcmap_approx( &vis_info, &cmap_info, &capx_info ); /* Create the window, giving it a gray background. */ bkgd_color.red = bkgd_color.green = bkgd_color.blue = 0x5555; bkgd_color.flags = DoRed | DoGreen | DoBlue; window = ora_create_window( dpy, &vis_info, &cmap_info, WIN_GEOM, &bkgd_color ); /* Create the structure and Set up the PEX renderer. */ if ( STRUCTURE_SPT( pexinfo ) ) { create_structure( dpy ); renderer = ora_setup_renderer( dpy, window, &capx_info, &rattrs ); } else { fprintf( stderr, "Structures not supported.\n" ); exit(1); } /* Read and respond to X events. */ XSelectInput( dpy, window, ExposureMask | ButtonPressMask ); while ( !done ) { XNextEvent( dpy, &event ); switch ( event.type ) { case Expose: /* Flush remaining Expose events, then redraw. */ while ( XCheckTypedWindowEvent( dpy, window, Expose, &event ) ) ; /* empty statement */ redraw( dpy, window, renderer ); break; case ButtonPress: done = 1; break; } } XCloseDisplay( dpy ); return 0; }