home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.4 KB | 2,082 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i004: sfs - Space Flight Simulator, Part04/21
- Message-ID: <1991Dec24.045237.29640@sparky.imd.sterling.com>
- X-Md4-Signature: 64fb49892016f3a4c9ddd1b8946762c1
- Date: Tue, 24 Dec 1991 04:52:37 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 4
- Archive-name: sfs/part04
- Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11,
-
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file io/gr/gr_tam.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 4; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping io/gr/gr_tam.c'
- else
- echo 'x - continuing file io/gr/gr_tam.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'io/gr/gr_tam.c' &&
- X (unsigned short) abs(x2 - x1) + ADD_SIZE,
- X (unsigned short) abs(y2 - y1) + ADD_SIZE,
- X SRCSRC, DSTSRC, (unsigned short *) 0 );
- X
- #ifdef DEBUG
- X if ( r == -1 )
- X {
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "gr_imsave(): wrastop() failed, error %d.\n", errno );
- X kb_rx();
- X }
- #endif
- X }
- X }
- X
- /****************************************************************
- X
- X gr_imfree()
- X
- ****************************************************************/
- X
- gr_imfree( image )
- X int image;
- X {
- X
- #ifdef DEBUG
- X if ( tam_images[ image ] == NULL )
- X {
- X bw_error( "gr_imfree(): NULL image requested" );
- X return FALSE;
- X }
- #endif
- X
- X free( tam_images[ image ] );
- X tam_images[ image ] = NULL;
- X
- X }
- X
- /****************************************************************
- X
- X gr_mouse()
- X
- ****************************************************************/
- X
- gr_mouse( mode, x, y, buttons )
- X int mode;
- X int *x, *y;
- X int *buttons;
- X {
- X static int b, r;
- X
- X if (( mode == STATUS ) || ( mode == SAMPLE ))
- X {
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "gr_mouse() STATUS: enter\n" );
- X fflush( outfile );
- #endif
- X
- X if ( tam_mready == FALSE )
- X {
- X att_rxstat();
- X }
- X return tam_mready;
- X }
- X else if ( mode == WAIT )
- X {
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "gr_mouse() WAIT: enter\n" );
- X fflush( outfile );
- #endif
- X
- X while( tam_mready == FALSE )
- X {
- X att_rxstat();
- X }
- X *x = tam_mx;
- X *y = grwind->ymax - tam_my;
- X tam_mready = FALSE;
- X return TRUE;
- X }
- X }
- X
- tam_setscreen( screen )
- X int screen;
- X {
- X if ( screen == GR_HIDDEN )
- X {
- X tam_selected = tam_hidden;
- X }
- X else
- X {
- X tam_selected = (unsigned short *) 0;
- X }
- X }
- X
- tam_readfont( fontfile, sptr )
- X char *fontfile;
- X struct fntdef **sptr;
- X {
- X FILE *ff_fp;
- X int size;
- X char *m;
- X
- X /* open the font file */
- X
- X if ( ( ff_fp = fopen( fontfile, "r" )) == NULL )
- X {
- X fprintf( stderr, "Failed to open font file\n" );
- X wgetc( w );
- X wexit( 1 );
- X }
- X
- X /* find the size of the file */
- X
- X size = 0;
- X while( !feof( ff_fp ) )
- X {
- X ++size;
- X fgetc( ff_fp );
- X }
- X
- X /* allocate memory for the file */
- X
- X if ( ( m = malloc( size )) == NULL )
- X {
- X fprintf( stderr, "No memory for font file <%s> \n",
- X fontfile );
- X *sptr = NULL;
- X wgetc( w );
- X return BW_ERROR;
- X }
- X *sptr = (struct fntdef *) m;
- X
- #ifdef OLD_DEBUG
- X clear();
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "Loading font <%s> \n", fontfile );
- X fprintf( stderr, "Size %d bytes sptr 0x%08lX top 0x%08lX \n",
- X size, (long) *sptr, (long) *sptr + size );
- X wgetc( w );
- X clear();
- X wgoto( 0, 0 );
- #endif
- X
- X /* now read the file into memory */
- X
- X rewind( ff_fp );
- X while( !feof( ff_fp ) )
- X {
- X *m = fgetc( ff_fp );
- X ++m;
- X }
- X
- X /* close the font file */
- X
- X fclose( ff_fp );
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Loaded font <%s>, %d by %d pixels\n",
- X fontfile, (*sptr)->ff_vs, (*sptr)->ff_hs );
- X wgetc( w );
- #endif
- X
- X }
- X
- tam_char( screen, x, y, icon, x_size, y_size,
- X foreground, background, c, cdef )
- X int screen, x, y, x_size, y_size, foreground, background, c;
- X unsigned short *icon;
- X struct fcdef *cdef;
- X {
- X int r;
- X
- X /* paint the background */
- X
- X gr_rectangle( screen, x, y,
- X x + tam_fdef->ff_hs, y + tam_fdef->ff_vs,
- X background, SOLID );
- X
- X /* call wrastop() to display the character as an icon */
- X
- X r = wrastop( w, icon, tam_words( y_size ),
- X tam_selected, tam_words( grwind->xmax + ADD_HIDDEN ),
- X (unsigned short) 0, (unsigned short) 0,
- X (unsigned short) x + cdef->fc_ha,
- X (unsigned short) (grwind->ymax - y) + ( cdef->fc_va - 1 ),
- X (unsigned short) x_size,
- X (unsigned short) y_size,
- X SRCSRC, DSTXOR, (unsigned short *) 0 );
- X
- #ifdef OLD_DEBUG
- X wgoto( w, 10, 0 );
- X if ( r == -1 )
- X {
- X fprintf( stderr, "tam_char(): wrastop() failed, error %d, screen %d.\n",
- X errno, screen );
- X wgetc( w );
- X }
- #ifdef OLD_STUFF
- X fprintf( stderr, "Character 0x%X <%c>: offset %d (0x%04X\n",
- X c, c, cdef->fc_mr, cdef->fc_mr );
- X fprintf( stderr, " x_size %d, y_size %d, words %d \n",
- X x_size, y_size, tam_words( y_size ) );
- X fprintf( stderr, " fc_ha %d, fc_va %d, fc_hi %d, fc_vi %d \n",
- X cdef->fc_ha, cdef->fc_va, cdef->fc_hi, cdef->fc_vi );
- X fprintf( stderr, " x pos %d, y pos %d\n",
- X x, y );
- X fprintf( stderr, " icon %08lX selected %08lX\n",
- X (long) icon, (long) tam_selected );
- X wgetc( w );
- X clear();
- #endif
- #endif
- X }
- X
- /* determine the number of 16-bit words necessary
- X for horizontal axis */
- X
- unsigned short
- tam_words( pixels )
- X int pixels;
- X {
- X return ((( pixels + 15) / 16 ) * 2);
- X }
- X
- #ifdef T_WRASTOP
- t_wrastop( tw, srcbase, srcwidth, dstbase, dstwidth,
- X srcx, srcy, dstx, dsty, width, height,
- X srcop, dstop, pattern )
- X int tw;
- X unsigned short *srcbase, *dstbase, *pattern;
- X unsigned short srcwidth, dstwidth;
- X unsigned short srcx, srcy, dstx, dsty;
- X char srcop, dstop;
- X {
- X
- X
- X if ( tam_wtest == TRUE )
- X {
- /* gr_rectangle( GR_PRIMARY, 0, grwind->ymax - 40,
- X grwind->xmax, grwind->ymax, BLACK, SOLID ); */
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "test wrastop(): srcwidth %d, dstwidth %d\n",
- X srcwidth, dstwidth );
- X kb_rx();
- /* gr_rectangle( GR_PRIMARY, 0, grwind->ymax - 40,
- X grwind->xmax, grwind->ymax, BLACK, SOLID ); */
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "test wrastop(): srcbase %08lx, dstbase %08lx\n",
- X (long) srcbase, (long) dstbase );
- X kb_rx();
- /* gr_rectangle( GR_PRIMARY, 0, grwind->ymax - 40,
- X grwind->xmax, grwind->ymax, BLACK, SOLID ); */
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "test wrastop(): srcx %d, srcy %d, dstx %d dsty %d\n",
- X srcx, srcy, dstx, dsty );
- X kb_rx();
- /* gr_rectangle( GR_PRIMARY, 0, grwind->ymax - 40,
- X grwind->xmax, grwind->ymax, BLACK, SOLID ); */
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "test wrastop(): width %d, height %d\n",
- X width, height );
- X kb_rx();
- X }
- X
- X return wrastop( tw, srcbase, srcwidth, dstbase, dstwidth,
- X srcx, srcy, dstx, dsty, width, height,
- X srcop, dstop, pattern );
- X
- X }
- #endif
- SHAR_EOF
- echo 'File io/gr/gr_tam.c is complete' &&
- chmod 0644 io/gr/gr_tam.c ||
- echo 'restore of io/gr/gr_tam.c failed'
- Wc_c="`wc -c < 'io/gr/gr_tam.c'`"
- test 27360 -eq "$Wc_c" ||
- echo 'io/gr/gr_tam.c: original size 27360, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/gr/gr_test.c ==============
- if test -f 'io/gr/gr_test.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/gr/gr_test.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/gr/gr_test.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_test.c' &&
- /****************************************************************
- X
- X gr_test.c Validation program for Bywater
- X Graphics Interface standard
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- #include "signal.h"
- X
- #ifdef __STDC__
- #include "malloc.h"
- #else
- extern char * malloc();
- #define size_t int
- #endif
- X
- #include "bw.h"
- #include "gr.h"
- #include "kb.h"
- X
- struct gr_window main_window;
- char tbuf[ 128 ];
- char bw_ebuf[ BW_EBUFSIZE ];
- int x_pos, y_pos, b_stat;
- int x, y;
- int bsize;
- static int image;
- int test_quit();
- X
- main()
- X {
- X register int c;
- X
- X gr_init( &main_window, NULL );
- X kb_init();
- X
- X signal( SIGTERM, test_quit );
- X
- X /* set a font equal to 1/25 of the screen height */
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 25 );
- X
- X c = 0;
- X while ( c != 0x1b )
- X {
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X " Bywater gr (Graphics and Mouse) Interface Validation: ",
- X BLACK, WHITE );
- X if ( gr_ismouse == TRUE )
- X {
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 3 ),
- X "Mouse detected.", WHITE, BLACK );
- X }
- X else
- X {
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 3 ),
- X "No mouse detected.", WHITE, BLACK );
- X }
- X sprintf( tbuf, "Screens supported: %d ", gr_screens );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 4 ), tbuf, WHITE, BLACK );
- X sprintf( tbuf, "Window size: X axis, %d pixels; Y axis, %d pixels",
- X main_window.xmax, main_window.ymax );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 5 ), tbuf, WHITE, BLACK );
- X
- X sprintf( tbuf, "Pixel size: X axis, %d pixels; Y axis, %d pixels",
- X gr_pxsize, gr_pysize );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 6 ), tbuf, WHITE, BLACK );
- X
- X sprintf( tbuf, "Font size: X axis, %d pixels; Y axis, %d pixels",
- X main_window.fxsize, main_window.fysize );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 7 ), tbuf, WHITE, BLACK );
- X
- X sprintf( tbuf, "Colors available: %d", gr_colors );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 8 ), tbuf, WHITE, BLACK );
- X
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 10 ),
- X " 1 Validate gr_font() and gr_text()", WHITE, BLACK );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 11 ),
- X " 2 Validate gr_pixel()", WHITE, BLACK );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 12 ),
- X " 3 Validate gr_line()", WHITE, BLACK );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 13 ),
- X " 4 Validate gr_rectangle()", WHITE, BLACK );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 14 ),
- X " 5 Validate gr_circle()", WHITE, BLACK );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 15 ),
- X " 6 Validate gr_imsave()", WHITE, BLACK );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 16 ),
- X " 7 Validate gr_blit()", WHITE, BLACK );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 17 ),
- X " 8 Validate gr_mouse()", WHITE, BLACK );
- X gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 19 ),
- X " 9 EXIT", WHITE, BLACK );
- X
- X c = kb_rx();
- X
- X switch( c )
- X {
- X case '1':
- X val_font();
- X break;
- X case '2':
- X val_pixel();
- X break;
- X case '3':
- X val_line();
- X break;
- X case '4':
- X val_rectangle();
- X break;
- X case '5':
- X val_circle();
- X break;
- X case '6':
- X val_save();
- X break;
- X case '7':
- X val_blit();
- X break;
- X case '8':
- X val_mouse();
- X break;
- X case '9':
- X case 0x1b:
- X c = 0x1b;
- X break;
- X }
- X
- X
- X }
- X
- X val_exit();
- X
- X }
- X
- X
- /* 1: validate gr_font(), and gr_text() */
- X
- val_font()
- X {
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X "GR test # 1: gr_font() validation.",
- X BLACK, WHITE );
- X
- X x = main_window.xmax / 10;
- X y = main_window.ymax / 18;
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 40 );
- X sprintf( tbuf, "Test size ymax / 40: %dx%d font",
- X main_window.fysize, main_window.fxsize );
- X gr_text( GR_PRIMARY, x, y, tbuf, WHITE, BLACK );
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 30 );
- X sprintf( tbuf, "Test size ymax / 30: %dx%d font",
- X main_window.fysize, main_window.fxsize );
- X gr_text( GR_PRIMARY, x, y * 2, tbuf, WHITE, BLACK );
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 25 );
- X sprintf( tbuf, "Test size ymax / 25: %dx%d font",
- X main_window.fysize, main_window.fxsize );
- X gr_text( GR_PRIMARY, x, y * 4, tbuf, WHITE, BLACK );
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 20 );
- X sprintf( tbuf, "Test size ymax / 20: %dx%d font",
- X main_window.fysize, main_window.fxsize );
- X gr_text( GR_PRIMARY, x, y * 8, tbuf, WHITE, BLACK );
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 15 );
- X sprintf( tbuf, "Test size ymax / 15: %dx%d font",
- X main_window.fysize, main_window.fxsize );
- X gr_text( GR_PRIMARY, x, y * 12, tbuf, WHITE, BLACK );
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 25 );
- X kb_rx();
- X
- X }
- X
- /* 2: validate gr_pixel() */
- X
- val_pixel()
- X {
- X register int c;
- X
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X "GR test # 2: gr_pixel() validation.",
- X BLACK, WHITE );
- X
- X x = main_window.xmax / 4;
- X y = ( main_window.ymax / 4 ) * 3;
- X c = 0;
- X while ( ( c < gr_colors ) && ( y > main_window.fysize ) )
- X {
- X gr_pixel( GR_PRIMARY, x, y, c );
- X sprintf( tbuf, " <- pixel color %d at x = %d, y = %d",
- X c, x, y );
- X gr_text( GR_PRIMARY, x + ( 3 * main_window.fxsize ),
- X y - ( main_window.fysize / 2 ), tbuf, WHITE, BLACK );
- X ++c;
- X y -= ( main_window.fysize / 2 ) * 3;
- X }
- X kb_rx();
- X
- X }
- X
- /* 3: validate gr_line() */
- X
- val_line()
- X {
- X register int c;
- X
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X "GR test # 3: gr_line() validation.",
- X BLACK, WHITE );
- X
- X x = main_window.xmax / 8;
- X y = ( main_window.ymax / 4 ) * 3;
- X c = 0;
- X while ( ( c < gr_colors ) && ( y > main_window.fysize ) )
- X {
- X gr_line( GR_PRIMARY, x, y, x + main_window.xmax / 20, y,
- X c, SOLID );
- X x += main_window.xmax / 10;
- X gr_line( GR_PRIMARY, x, y, x + main_window.xmax / 20, y,
- X c, HATCH );
- X sprintf( tbuf, " <- lines, color %d at x = %d, y = %d",
- X c, x, y );
- X gr_text( GR_PRIMARY, x + ( 3 * ( main_window.xmax / 20 )),
- X y - ( main_window.fysize / 2 ), tbuf, WHITE, BLACK );
- X ++c;
- X x -= main_window.xmax / 10;
- X y -= ( main_window.fysize / 2 ) * 3;
- X }
- X kb_rx();
- X
- X gr_cls( GR_PRIMARY );
- X for ( x = 0; x < main_window.xmax; x += 15 )
- X {
- X gr_line( GR_PRIMARY, x, 0, 0, main_window.ymax,
- X WHITE, SOLID );
- X }
- X
- X for ( y = main_window.ymax - 10; y > 0; y -= 15 )
- X {
- X gr_line( GR_PRIMARY, 0, y, main_window.xmax, 0,
- X WHITE, SOLID );
- X }
- X
- X kb_rx();
- X
- X }
- X
- /* 4: validate gr_rectangle() */
- X
- val_rectangle()
- X {
- X
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X "GR test # 4: gr_rectangle() validation.",
- X BLACK, WHITE );
- X
- X x = main_window.xmax / 40;
- X y = main_window.ymax / 20;
- X gr_rectangle( GR_PRIMARY, x * 4, y * 16, x * 6, y * 18, WHITE, HOLLOW );
- X gr_text( GR_PRIMARY, x * 10, y * 17, "Hollow rectangle", WHITE, BLACK );
- X gr_rectangle( GR_PRIMARY, x * 4, y * 12, x * 6, y * 14, WHITE, SOLID );
- X gr_text( GR_PRIMARY, x * 10, y * 13, "Solid rectangle", WHITE, BLACK );
- X gr_rectangle( GR_PRIMARY, x * 4, y * 8, x * 6, y * 10, WHITE, GRID );
- X gr_text( GR_PRIMARY, x * 10, y * 9, "Grid rectangle", WHITE, BLACK );
- X gr_rectangle( GR_PRIMARY, x * 4, y * 4, x * 6, y * 6, WHITE, HATCH );
- X gr_text( GR_PRIMARY, x * 10, y * 5, "Hatch rectangle", WHITE, BLACK );
- X kb_rx();
- X }
- X
- /* 5: validate gr_circle() */
- X
- val_circle()
- X {
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X "GR test # 5: gr_circle() validation.",
- X BLACK, WHITE );
- X
- X x = main_window.xmax / 40;
- X y = main_window.ymax / 20;
- X gr_circle( GR_PRIMARY, x * 5, y * 17, (y/2)*3, WHITE, HOLLOW );
- X gr_text( GR_PRIMARY, x * 10, y * 17, "Hollow circle", WHITE, BLACK );
- X gr_circle( GR_PRIMARY, x * 5, y * 13, (y/2)*3, WHITE, SOLID );
- X gr_text( GR_PRIMARY, x * 10, y * 13, "Solid circle", WHITE, BLACK );
- X gr_circle( GR_PRIMARY, x * 5, y * 9, (y/2)*3, WHITE, GRID );
- X gr_text( GR_PRIMARY, x * 10, y * 9, "Grid circle", WHITE, BLACK );
- X gr_circle( GR_PRIMARY, x * 5, y * 5, (y/2)*3, WHITE, HATCH );
- X gr_text( GR_PRIMARY, x * 10, y * 5, "Hatch circle", WHITE, BLACK );
- X kb_rx();
- X }
- X
- /* 6: test gr_imsave() */
- X
- val_save()
- X
- X {
- X
- X /* if saving is allowed, save a portion of the screen here */
- X
- X if ( gr_saving )
- X {
- X x = main_window.xmax / 10;
- X y = main_window.ymax / 18;
- X
- X gr_imsave( GR_PRIMARY, TRUE, x, y * 3, x * 6, y * 8, &image );
- X gr_rectangle( GR_PRIMARY, x, y * 3, x * 6, y * 8, WHITE, HOLLOW );
- X
- X
- X
- X /* now show the portion saved earlier */
- X
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X "GR test # 6: gr_imsave() validation.",
- X BLACK, WHITE );
- X
- X gr_imsave( GR_PRIMARY, FALSE, x, y * 3, x * 6, y * 8, &image );
- X gr_rectangle( GR_PRIMARY, x, y * 3, x * 6, y * 8, WHITE, HOLLOW );
- X kb_rx();
- X }
- X }
- X
- /* 7: validate gr_blit() */
- X
- val_blit()
- X {
- X
- X /* if there is more than one screen, validate screen writes and blits */
- X
- X if ( gr_blitting == TRUE )
- X {
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X "GR test # 7: gr_blit() validation.",
- X BLACK, WHITE );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 4 ),
- X " this has been written to screen GR_PRIMARY.",
- X BLACK, WHITE );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 5 ),
- X " but after you hit RETURN GR_HIDDEN ",
- X BLACK, WHITE );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 6 ),
- X " will be blitted to this screen ",
- X BLACK, WHITE );
- X gr_text( GR_HIDDEN, txt_x( 0 ), txt_y( 0 ),
- X " gr_blit() validation.",
- X BLACK, WHITE );
- X gr_text( GR_HIDDEN, txt_x( 0 ), txt_y( 4 ),
- X " this has been written to screen GR_HIDDEN.",
- X BLACK, WHITE );
- X gr_text( GR_HIDDEN, txt_x( 0 ), txt_y( 5 ),
- X " and has now been blitted over ",
- X BLACK, WHITE );
- X gr_text( GR_HIDDEN, txt_x( 0 ), txt_y( 6 ),
- X " to GR_PRIMARY ",
- X BLACK, WHITE );
- X
- X kb_rx();
- X gr_blit( GR_HIDDEN, GR_PRIMARY, 0, 0,
- X main_window.xmax,
- X main_window.ymax );
- X kb_rx();
- X }
- X }
- X
- /* 8: validate mouse */
- X
- val_mouse()
- X {
- X register int c;
- X
- X /* If mouse exists, validate it */
- X
- X if ( gr_ismouse == TRUE )
- X {
- X gr_cls( GR_PRIMARY );
- X gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
- X WHITE, SOLID );
- X gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
- X "GR test # 8: gr_mouse() validation.",
- X BLACK, WHITE );
- X
- X x = main_window.xmax / 40;
- X y = main_window.ymax / 20;
- X
- X while ( gr_mouse( STATUS, &x_pos, &y_pos, &b_stat ) != TRUE )
- X {
- X sprintf( tbuf, "Mouse position: x = %d, y = %d ",
- X x_pos, y_pos );
- X gr_text( GR_PRIMARY, x * 10, y * 17, tbuf, WHITE, BLACK );
- X }
- X gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
- X gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
- X
- X c = 0;
- X while( ( kb_rxstat() == FALSE ) && ( c < 12 ))
- X {
- X ++c;
- X gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
- X sprintf( tbuf, "Mouse position: x = %d, y = %d ",
- X x_pos, y_pos );
- X gr_text( GR_PRIMARY, x * 10, y * 17, tbuf, WHITE, BLACK );
- X }
- X }
- X }
- X
- val_exit()
- X
- X {
- X
- X /* Finished with validation: clear screen and restore original state */
- X
- X gr_cls( GR_PRIMARY );
- X kb_deinit();
- X gr_deinit();
- X }
- X
- txt_y( line )
- X int line;
- X {
- X return ( main_window.ymax ) - ( main_window.fysize * ( line + 1 ));
- X }
- X
- txt_x( column )
- X int column;
- X {
- X return column * main_window.fxsize;
- X }
- X
- test_quit()
- X {
- X gr_cls( GR_PRIMARY );
- X kb_deinit();
- X gr_deinit();
- X }
- X
- bw_error( m )
- X char *m;
- X {
- X fprintf( stderr, "ERROR: %s \n", m );
- X }
- X
- X
- SHAR_EOF
- chmod 0644 io/gr/gr_test.c ||
- echo 'restore of io/gr/gr_test.c failed'
- Wc_c="`wc -c < 'io/gr/gr_test.c'`"
- test 13731 -eq "$Wc_c" ||
- echo 'io/gr/gr_test.c: original size 13731, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/gr/gr_test.mak ==============
- if test -f 'io/gr/gr_test.mak' -a X"$1" != X"-c"; then
- echo 'x - skipping io/gr/gr_test.mak (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/gr/gr_test.mak (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_test.mak' &&
- PROJ =GR_TEST
- DEBUG =0
- CC =qcl
- CFLAGS_G = /AL /W1 /Ze /DDEBUG /I..\..\include
- CFLAGS_D = /Zi /Zr /Gi$(PROJ).mdt /Od
- CFLAGS_R = /O /Ot /DNDEBUG
- CFLAGS =$(CFLAGS_G) $(CFLAGS_R)
- LFLAGS_G =/NOI
- LFLAGS_D =/INCR /CO
- LFLAGS_R =
- LFLAGS =$(LFLAGS_G) $(LFLAGS_R)
- RUNFLAGS =
- OBJS_EXT =
- LIBS_EXT =
- X
- all: $(PROJ).exe
- X
- gr_test.obj: gr_test.c
- X
- gr_ibmpc.obj: gr_ibmpc.c
- X
- kb_ibmpc.obj: ..\kb\kb_ibmpc.c
- X
- $(PROJ).exe: gr_test.obj gr_ibmpc.obj kb_ibmpc.obj $(OBJS_EXT)
- X echo >NUL @<<$(PROJ).crf
- gr_test.obj +
- gr_ibmpc.obj +
- kb_ibmpc.obj +
- $(OBJS_EXT)
- $(PROJ).exe
- X
- $(LIBS_EXT);
- <<
- X link $(LFLAGS) @$(PROJ).crf
- X
- run: $(PROJ).exe
- X $(PROJ) $(RUNFLAGS)
- X
- SHAR_EOF
- chmod 0644 io/gr/gr_test.mak ||
- echo 'restore of io/gr/gr_test.mak failed'
- Wc_c="`wc -c < 'io/gr/gr_test.mak'`"
- test 643 -eq "$Wc_c" ||
- echo 'io/gr/gr_test.mak: original size 643, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/gr/gr_x.c ==============
- if test -f 'io/gr/gr_x.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/gr/gr_x.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/gr/gr_x.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_x.c' &&
- /****************************************************************
- X
- X gr_x.c X Windows Implementation
- X of Bywater Graphics Interface Standard
- X
- X Tested on DecStation 2100 and 3100
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- #ifdef __STDC__
- #include "stdlib.h"
- #endif
- X
- #include "X11/Xlib.h"
- #include "X11/Xutil.h"
- #include "X11/keysym.h"
- #include "X11/keysymdef.h"
- #include "X11/cursorfont.h"
- X
- #include "bw.h"
- #include "kb.h"
- #include "gr.h"
- X
- #define IMAGES 64
- #define KEY_NEEDED FALSE
- #define MAX_SCREEN_HEIGHT 500
- #define MAX_SCREEN_WIDTH 800
- #define X_OFFSET 30
- #define Y_OFFSET 30
- #define REQ_BORDER_WIDTH 3
- #define EVENT_MASK ( ButtonPressMask | \
- X ButtonReleaseMask | \
- X KeyPressMask )
- #define KEYBUF_LENGTH 64
- X
- /****************************************************************
- X
- X The following globals are defined in the gr specification
- X and are accessible to users of gr-based programs.
- X
- ****************************************************************/
- X
- int gr_screens = 2;
- int gr_colors = 2;
- int gr_pxsize = 30;
- int gr_pysize = 30;
- int gr_ismouse = TRUE;
- int gr_blitting = TRUE;
- int gr_clipping = FALSE; /* Not yet */
- int gr_saving = TRUE;
- X
- /****************************************************************
- X
- X The following globals are specific to the X Windows implementaion
- X of the gr standard and should not be accessible to users of
- X gr-based programs.
- X
- ****************************************************************/
- X
- struct gr_window *grwind; /* primary gr window */
- Display *x_display; /* primary X Windows display */
- Colormap x_colormap; /* system color map */
- XXColor rgbcolor, hardwarecolor;
- int x_screen; /* which screen is in use */
- XXSetWindowAttributes x_windattributes; /* send requested attributes */
- XXSizeHints x_sizehints; /* send size "hints" */
- unsigned long x_windmask; /* send window mask */
- Window x_primary; /* the principal X Window, used
- X when GR_PRIMARY is specified */
- Pixmap x_hidden; /* a second X Window, used
- X when GR_HIDDEN is specified */
- Drawable x_selected; /* X Drawable variable, which may be set
- X to either x_primary or x_hidden */
- int x_mousevent; /* is mouse event pending? */
- int x_keybevent; /* is keyboard event pending? */
- int x_moxpos; /* mouse x position pending */
- int x_moypos; /* mouse y position pending */
- int x_keypending; /* key pending */
- int x_depth; /* depth (color planes ) */
- XXFontStruct *x_font10; /* font structure: 10 y */
- XXFontStruct *x_font13; /* font structure: 13 y */
- XXFontStruct *x_font15; /* font structure: 15 y */
- XXFontStruct *x_font20; /* font structure: 20 y */
- XXFontStruct *x_font31; /* font structure: 31 y */
- XXFontStruct *x_curfont; /* font struct in use */
- XXGCValues x_gcvals; /* graphics content values */
- GC x_fontgc; /* graphics context for font */
- GC x_drawgc; /* graphics context for drawing */
- Cursor x_cursor; /* cursor to use for this X Window */
- Pixmap x_stippm; /* stipple pixmap */
- X
- char x_stipple[] = { 170, 85, 170, 85, 170, 85, 170, 85 };
- unsigned long x_colchart[ 16 ]; /* chart of sixteen colors */
- extern unsigned long x_color(); /* see function below */
- Pixmap x_images[ IMAGES ]; /* images */
- X
- /****************************************************************
- X
- X gr_init()
- X
- ****************************************************************/
- X
- gr_init( window, path )
- X struct gr_window *window;
- X char *path;
- X {
- X int x_xsize, x_ysize;
- X int req_xsize, req_ysize;
- X register int i;
- X
- X /* Part 1 of the Initialization:
- X **
- X ** Open and X Windows Display and Window and set system parameters
- X ** based on it.
- X */
- X
- X grwind = window;
- X
- X /* Open an X Windows display */
- X
- X x_display = XOpenDisplay( NULL );
- X
- X /* If the display is null, return */
- X
- X if ( x_display == NULL )
- X {
- X return FALSE;
- X }
- X
- X /* get the screen currently in use and some basic data */
- X
- X x_screen = DefaultScreen( x_display );
- X x_depth = DefaultDepth( x_display, x_screen );
- X x_colormap = DefaultColormap( x_display, x_screen );
- X x_xsize = DisplayWidth( x_display, x_screen );
- X x_ysize = DisplayHeight( x_display, x_screen );
- X
- X /* determine requested height and width of X Window */
- X
- X if ( x_xsize >= ( MAX_SCREEN_WIDTH + X_OFFSET ))
- X {
- X req_xsize = MAX_SCREEN_WIDTH;
- X }
- X else
- X {
- X req_xsize = x_xsize;
- X }
- X
- X if ( x_ysize >= ( MAX_SCREEN_HEIGHT + Y_OFFSET ))
- X {
- X req_ysize = MAX_SCREEN_HEIGHT;
- X }
- X else
- X {
- X req_ysize = x_ysize;
- X }
- X
- X /* Set a cursor for this application */
- X
- X x_cursor = XCreateFontCursor( x_display, XC_left_ptr );
- X
- X /* set requested window attributes in structure to be passed */
- X
- X x_windattributes.border_pixel =
- X WhitePixel( x_display, x_screen );
- X x_windattributes.background_pixel =
- X BlackPixel( x_display, x_screen );
- X x_windattributes.cursor = x_cursor;
- X x_windmask = ( CWCursor | CWBackPixel | CWBorderPixel
- X | CWOverrideRedirect );
- X
- X /* now create the window and hidden pixmap */
- X
- X x_primary = XCreateWindow( x_display, RootWindow( x_display, x_screen ),
- X X_OFFSET, Y_OFFSET, req_xsize, req_ysize, REQ_BORDER_WIDTH, x_depth,
- X InputOutput, CopyFromParent, x_windmask, &x_windattributes );
- X
- X x_hidden = XCreatePixmap( x_display, x_primary,
- X req_xsize, req_ysize, x_depth );
- X
- X x_selected = x_primary;
- X
- X /* Send size hints to the window manager */
- X
- X x_sizehints.flags = USPosition | USSize;
- X x_sizehints.x = X_OFFSET;
- X x_sizehints.y = Y_OFFSET;
- X x_sizehints.width = req_xsize;
- X x_sizehints.height = req_ysize;
- X XSetNormalHints( x_display, x_primary, &x_sizehints );
- X
- X /* Display the X Window */
- X
- X XMapRaised( x_display, x_primary );
- X
- X /* "Flush" the display to send all output to the screen */
- X
- X XFlush( x_display );
- X
- X /* Establish a graphics content for drawing */
- X
- X x_drawgc = XCreateGC( x_display, x_primary, (unsigned long) 0,
- X &x_gcvals );
- X
- X /* Set the stipple pattern for filling */
- X
- X x_stippm = XCreateBitmapFromData( x_display, x_primary, x_stipple, 8, 8 );
- X XSetStipple( x_display, x_drawgc, x_stippm );
- X
- X /* Set global gr variables based on this window */
- X
- X window->xmax = req_xsize;
- X window->ymax = req_ysize;
- X
- X /* Part 2 of the Initialization:
- X **
- X ** Set a default font.
- X */
- X
- X x_font10 = XLoadQueryFont( x_display, "6x10" );
- X x_font13 = XLoadQueryFont( x_display, "8x13" );
- X x_font15 = XLoadQueryFont( x_display, "9x15" );
- X x_font20 = XLoadQueryFont( x_display, "vr-20" );
- X x_font31 = XLoadQueryFont( x_display, "vr-31" );
- X x_fontgc = XCreateGC( x_display, x_primary, (unsigned long) 0,
- X &x_gcvals );
- X XSetForeground( x_display, x_fontgc, WhitePixel( x_display, x_screen ));
- X XSetBackground( x_display, x_fontgc, BlackPixel( x_display, x_screen ));
- X XSetFont( x_display, x_fontgc, x_font13->fid );
- X
- X x_curfont = x_font13;
- X grwind->fysize = x_font13->ascent + x_font13->descent;
- X grwind->fxsize = XTextWidth( x_font13, "m", 1 );
- X
- X x_initcolor(); /* initialize color */
- X
- X /* clear the screen */
- X
- X gr_cls( GR_PRIMARY );
- X gr_cls( GR_HIDDEN );
- X XFlush( x_display );
- X
- X /* Part 3 of the Initialization:
- X **
- X ** Initialize X events so the keyboard and mouse imput can
- X ** be processed.
- X */
- X
- X /* select input from key press, button press, and button release */
- X
- X XSelectInput( x_display, x_primary, EVENT_MASK );
- X
- X /* set image buffer pointers to NULL */
- X
- X for ( i = 0; i < IMAGES; ++i )
- X {
- X x_images[ i ] = NULL;
- X }
- X
- X /* start out at null state for keyboard and mouse entries */
- X
- X x_mousevent = FALSE;
- X x_keybevent = FALSE;
- X x_pollevent();
- X
- X window->initialized = grwind->initialized = TRUE;
- X
- #if KEY_NEEDED
- X kb_rx();
- #endif
- X return TRUE;
- X }
- X
- /****************************************************************
- X
- X gr_deinit()
- X
- ****************************************************************/
- X
- gr_deinit( screen )
- X int screen;
- X {
- X
- X /* remove the X Window */
- X
- X XDestroyWindow( x_display, x_primary );
- X XFreePixmap( x_display, x_hidden );
- X
- X /* close the X Display */
- X
- X XCloseDisplay( x_display );
- X
- X }
- X
- /****************************************************************
- X
- X gr_cls()
- X
- ****************************************************************/
- X
- gr_cls( screen )
- X int screen;
- X {
- X if ( screen == GR_PRIMARY )
- X {
- X XClearWindow( x_display, x_primary );
- X }
- X else
- X {
- X gr_rectangle( GR_HIDDEN, 0, 0, grwind->xmax - 1, grwind->ymax - 1,
- X BLACK, SOLID );
- X }
- X XFlush( x_display );
- X }
- X
- X
- /****************************************************************
- X
- X gr_pixel()
- X
- ****************************************************************/
- X
- gr_pixel( screen, x, y, color )
- X int screen;
- X int x, y;
- X int color;
- X {
- X
- #ifdef DEBUG
- X if ( ( x < 0 ) || ( x > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_pixel(): x value is %d", x );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y < 0 ) || ( y > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_pixel(): y value is %d", y );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X x_setscreen( screen );
- X XSetForeground( x_display, x_drawgc, x_color( color ) );
- X XDrawPoint( x_display, x_selected, x_drawgc, x, grwind->ymax - y );
- X XFlush( x_display );
- X }
- X
- /****************************************************************
- X
- X gr_line()
- X
- ****************************************************************/
- X
- gr_line( screen, x1, y1, x2, y2, color, style )
- X int screen;
- X int x1, y1, x2, y2;
- X int color, style;
- X {
- X
- #ifdef DEBUG
- X if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_line(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X x_setscreen( screen );
- X XSetLineAttributes( x_display, x_drawgc, (unsigned) 1,
- X x_linestyle( style ),
- X CapNotLast, JoinMiter );
- X XSetForeground( x_display, x_drawgc, x_color( color ) );
- X XDrawLine( x_display, x_selected, x_drawgc, x1, grwind->ymax - y1,
- X x2, grwind->ymax - y2 );
- X XFlush( x_display );
- X }
- X
- /****************************************************************
- X
- X gr_text()
- X
- ****************************************************************/
- X
- gr_text( screen, x, y, string, foreground, background )
- X int screen;
- X int x, y;
- X int foreground, background;
- X char *string;
- X {
- X
- #ifdef DEBUG
- X if ( ( x < 0 ) || ( x > grwind->xmax ))
- X {
- X fprintf( stderr, "ERROR: [pr:] gr_text(): x value is %d", x );
- X kb_rx();
- X return BW_ERROR;
- X }
- X if ( ( y < 0 ) || ( y > grwind->ymax ))
- X {
- X fprintf( stderr, "ERROR: [pr:] gr_text(): y value is %d", y );
- X kb_rx();
- X return BW_ERROR;
- X }
- #endif
- X
- X x_setscreen( screen );
- X
- X XSetForeground( x_display, x_fontgc, x_color( foreground ) );
- X XSetBackground( x_display, x_fontgc, x_color( background ) );
- X
- X XDrawImageString( x_display, x_selected, x_fontgc, x,
- X grwind->ymax - ( y + x_curfont->descent ), string,
- X strlen( string) );
- X XFlush( x_display );
- X }
- X
- /****************************************************************
- X
- X gr_strlen()
- X
- ****************************************************************/
- X
- unsigned int
- gr_strlen( string )
- X char *string;
- X {
- X return XTextWidth( x_curfont, string, strlen( string ) );
- X }
- X
- /****************************************************************
- X
- X gr_rectangle()
- X
- ****************************************************************/
- X
- gr_rectangle( screen, x1, y1, x2, y2, color, style )
- X int screen;
- X int x1, y1, x2, y2;
- X int color, style;
- X {
- X
- #ifdef DEBUG
- X if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_rectangle(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X x_setscreen( screen );
- X
- X if ( style == HOLLOW )
- X {
- X XSetLineAttributes( x_display, x_drawgc, (unsigned int) 1,
- X LineSolid, CapNotLast, JoinMiter );
- X XSetForeground( x_display, x_drawgc, x_color( color ) );
- X XDrawRectangle( x_display, x_selected, x_drawgc,
- X x1, grwind->ymax - y2, x2 - x1, y2 - y1 );
- X }
- X else
- X {
- X XSetFillRule( x_display, x_drawgc, EvenOddRule );
- X XSetFillStyle( x_display, x_drawgc, x_fillstyle( style ) );
- X XSetForeground( x_display, x_drawgc, x_color( color ) );
- X XSetBackground( x_display, x_drawgc, x_color( BLACK ) );
- X XFillRectangle( x_display, x_selected, x_drawgc,
- X x1, grwind->ymax - y2, x2 - x1, y2 - y1 );
- X }
- X XFlush( x_display );
- X }
- X
- /****************************************************************
- X
- X gr_circle()
- X
- ****************************************************************/
- X
- gr_circle( screen, x, y, radius, color, style )
- X int screen;
- X int x, y, radius;
- X int color, style;
- X {
- X
- #ifdef DEBUG
- X if ( ( x < 0 ) || ( x > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_circle(): x value is %d", x );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y < 0 ) || ( y > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_circle(): y value is %d", y );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X x_setscreen( screen );
- X
- X if ( style == HOLLOW )
- X {
- X XSetLineAttributes( x_display, x_drawgc, (unsigned int) 1,
- X LineSolid, CapNotLast, JoinMiter );
- X XSetForeground( x_display, x_drawgc, x_color( color ) );
- X XDrawArc( x_display, x_selected, x_drawgc,
- X x - radius, ( grwind->ymax - y ) - radius, radius * 2, radius * 2,
- X 0, 360 * 64 );
- X }
- X else
- X {
- X XSetFillRule( x_display, x_drawgc, EvenOddRule );
- X XSetFillStyle( x_display, x_drawgc, x_fillstyle( style ) );
- X XSetForeground( x_display, x_drawgc, x_color( color ) );
- X XSetBackground( x_display, x_drawgc, x_color( BLACK ) );
- X XFillArc( x_display, x_selected, x_drawgc,
- X x - radius, ( grwind->ymax - y ) - radius, radius * 2, radius * 2,
- X 0, 360 * 64 );
- X }
- X XFlush( x_display );
- X }
- X
- /****************************************************************
- X
- X gr_ellipse()
- X
- ****************************************************************/
- X
- gr_ellipse( screen, x, y, x_radius, y_radius, mode, color, style )
- X int screen;
- X int x, y, x_radius, y_radius;
- X int mode, color, style;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_clip()
- X
- ****************************************************************/
- X
- gr_clip( screen, mode, x1, y1, x2, y2 )
- X int screen;
- X int mode;
- X int x1, y1, x2, y2;
- X {
- X
- #ifdef DEBUG
- X if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_clip(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_clip(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_clip(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_clip(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X }
- X
- /****************************************************************
- X
- X gr_font()
- X
- ****************************************************************/
- X
- gr_font( screen, type, rq_height )
- X int screen;
- X int type, rq_height;
- X {
- X XFontStruct *oldfont;
- X
- X oldfont = x_curfont;
- X
- X if ( rq_height > 25 )
- X {
- X x_curfont = x_font31;
- X }
- X else if ( rq_height > 17 )
- X {
- X x_curfont = x_font20;
- X }
- X else if ( rq_height > 14 )
- X {
- X x_curfont = x_font15;
- X }
- X else if ( rq_height > 11 )
- X {
- X x_curfont = x_font13;
- X }
- X else
- X {
- X x_curfont = x_font10;
- X }
- X
- X if ( ( x_curfont == NULL ) || ( x_curfont->fid == 0 ))
- X {
- X x_curfont = oldfont;
- X }
- X
- X XSetFont( x_display, x_fontgc, x_curfont->fid );
- X grwind->fysize = x_curfont->ascent + x_curfont->descent;
- X grwind->fxsize = XTextWidth( x_curfont, "m", 1 );
- X
- X }
- X
- /****************************************************************
- X
- X gr_blit()
- X
- ****************************************************************/
- X
- gr_blit( src, dst, x1, y1, x2, y2 )
- X int src, dst;
- X int x1, y1, x2, y2;
- X {
- X
- #ifdef DEBUG
- X if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( src == dst )
- X {
- X sprintf( bw_ebuf, "[pr:] gr_blit(): src == dst" );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X if ( src == GR_HIDDEN )
- X {
- X XCopyArea( x_display, x_hidden, x_primary, x_drawgc,
- X x1, grwind->ymax - y2, x2 - x1, y2 - y1, x1, grwind->ymax - y2 );
- X }
- X
- X else
- X {
- X XCopyArea( x_display, x_primary, x_hidden, x_drawgc,
- X x1, grwind->ymax - y2, x2 - x1, y2 - y1, x1, grwind->ymax - y2 );
- X }
- X
- X }
- X
- /****************************************************************
- X
- X gr_imsave()
- X
- ****************************************************************/
- X
- gr_imsave( screen, mode, x1, y1, x2, y2, image )
- X int screen;
- X int mode, x1, y1, x2, y2;
- X int *image;
- X {
- X register int r;
- X int carry_on;
- X
- #ifdef DEBUG
- X if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_save(): x1 value is %d", x1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_save(): x2 value is %d", x2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_save(): y1 value is %d", y1 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_save(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X x_setscreen( screen );
- X
- X /* mode == TRUE, save the area */
- X
- X if ( mode == TRUE )
- X {
- X
- X /* find an available slot */
- X
- X carry_on = TRUE;
- X r = 0;
- X while( ( carry_on == TRUE ) && ( r < IMAGES ) )
- X {
- X if ( x_images[ r ] == NULL )
- X {
- X carry_on = FALSE;
- X }
- X else
- X {
- X ++r;
- X }
- X }
- X
- X if ( r >= IMAGES )
- X {
- X bw_error( "No more slots for image storage" );
- X return FALSE;
- X }
- X
- X *image = r;
- X
- X /* create a new pixmap */
- X
- X x_images[ *image ] = XCreatePixmap( x_display, x_selected,
- X ( x2 - x1 ) + 1, ( y2 - y1 ) + 1, x_depth );
- X
- X /* copy the area */
- X
- X XCopyArea( x_display, x_selected, x_images[ *image ], x_drawgc,
- X x1, grwind->ymax - y2, x2 - x1, y2 - y1, 0, 0 );
- X }
- X
- X /* mode == FALSE, restore the area */
- X
- X else
- X {
- X XCopyArea( x_display, x_images[ *image ], x_selected, x_drawgc,
- X 0, 0, x2 - x1, y2 - y1, x1, grwind->ymax - y2 );
- X }
- X }
- X
- /****************************************************************
- X
- X gr_imfree()
- X
- ****************************************************************/
- X
- gr_imfree( image )
- X int image;
- X {
- X XFreePixmap( x_display, x_images[ image ] );
- X x_images[ image ] = NULL;
- X }
- X
- /****************************************************************
- X
- X gr_mouse()
- X
- ****************************************************************/
- X
- gr_mouse( mode, x, y, buttons )
- X int mode;
- X int *x, *y;
- X int *buttons;
- X {
- X
- X switch ( mode )
- X {
- X case STATUS:
- X case SAMPLE:
- X if ( x_mousevent == TRUE )
- X {
- X *x = x_moxpos;
- X *y = grwind->ymax - x_moypos;
- X return TRUE;
- X }
- X x_pollevent();
- X if ( x_mousevent == TRUE )
- X {
- X *x = x_moxpos;
- X *y = grwind->ymax - x_moypos;
- X return TRUE;
- X }
- X return FALSE;
- X break;
- X
- X case WAIT:
- X while( x_mousevent == FALSE )
- X {
- X x_pollevent();
- X }
- X x_mousevent = FALSE;
- X *x = x_moxpos;
- X *y = grwind->ymax - x_moypos;
- X break;
- X
- X }
- X
- X }
- X
- /****************************************************************
- X
- X x_pollevent()
- X
- ****************************************************************/
- X
- x_pollevent()
- X {
- X static XEvent x_event;
- X static XComposeStatus x_cstatus;
- X static KeySym x_keysym;
- X static int x_keybufmaxlen = KEYBUF_LENGTH - 1;
- X static char x_keybuf[ KEYBUF_LENGTH ];
- X int length;
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Polling...\n" );
- #endif
- X
- X /* poll X Window to see if there is an event */
- X
- X if ( XCheckMaskEvent( x_display, (unsigned long) EVENT_MASK, &x_event )
- X == True )
- X {
- X switch ( x_event.type )
- X {
- X case ButtonPress:
- X case ButtonRelease:
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Mouse event...\n" );
- #endif
- X x_mousevent = TRUE;
- X x_moxpos = x_event.xbutton.x;
- X x_moypos = x_event.xbutton.y;
- X break;
- X case KeyPress:
- #ifdef OLD_DEBUG
- X fprintf( stderr, "Keyboard event...\n" );
- #endif
- X x_keybevent = TRUE;
- X length = XLookupString( &x_event, x_keybuf, x_keybufmaxlen,
- X &x_keysym,
- X &x_cstatus );
- X if ( ( x_keysym >= ' ' ) && ( x_keysym <= '~' )
- X && ( length > 0 ))
- X {
- X x_keypending = x_keysym;
- X }
- X else
- X {
- X switch( x_keysym )
- X {
- X case XK_Return:
- X x_keypending = '\r';
- X break;
- X case XK_BackSpace:
- X x_keypending = '\010';
- X break;
- X case XK_Escape:
- X x_keypending = '\033';
- X break;
- X case XK_Delete:
- X x_keypending = KB_DELETE;
- X break;
- X case XK_Up:
- X x_keypending = KB_UP;
- X break;
- X case XK_Down:
- X x_keypending = KB_DOWN;
- X break;
- X case XK_Right:
- X x_keypending = KB_RIGHT;
- X break;
- X case XK_Left:
- X x_keypending = KB_LEFT;
- X break;
- X case XK_F1:
- X x_keypending = KB_FK1;
- X break;
- X case XK_F2:
- X x_keypending = KB_FK2;
- X break;
- X case XK_F3:
- X x_keypending = KB_FK3;
- X break;
- X default:
- X x_keypending = 0;
- X break;
- X }
- X }
- X break;
- X }
- X return TRUE;
- X }
- X
- X return FALSE;
- X
- X }
- X
- /****************************************************************
- X
- X x_initcolor()
- X
- ****************************************************************/
- X
- x_initcolor()
- X {
- X
- X if ( x_depth <= 1 )
- X {
- X return FALSE;
- X }
- X
- X gr_colors = 16;
- X
- X XLookupColor( x_display, x_colormap, "Black", &rgbcolor, &hardwarecolor );
- X XAllocColor( x_display, x_colormap, &hardwarecolor );
- X x_colchart[ BLACK ] = hardwarecolor.pixel;
- X
- X XLookupColor( x_display, x_colormap, "White", &rgbcolor, &hardwarecolor );
- X XAllocColor( x_display, x_colormap, &hardwarecolor );
- X x_colchart[ WHITE ] = hardwarecolor.pixel;
- X
- X XLookupColor( x_display, x_colormap, "Red", &rgbcolor, &hardwarecolor );
- X XAllocColor( x_display, x_colormap, &hardwarecolor );
- X x_colchart[ LIGHT_RED ] = hardwarecolor.pixel;
- X x_colchart[ DARK_RED ] = hardwarecolor.pixel;
- X
- X XLookupColor( x_display, x_colormap, "Green", &rgbcolor, &hardwarecolor );
- X XAllocColor( x_display, x_colormap, &hardwarecolor );
- X x_colchart[ LIGHT_GREEN ] = hardwarecolor.pixel;
- X x_colchart[ DARK_GREEN ] = hardwarecolor.pixel;
- X
- X XLookupColor( x_display, x_colormap, "Blue", &rgbcolor, &hardwarecolor );
- X XAllocColor( x_display, x_colormap, &hardwarecolor );
- X x_colchart[ LIGHT_BLUE ] = hardwarecolor.pixel;
- X x_colchart[ DARK_BLUE ] = hardwarecolor.pixel;
- X
- X XLookupColor( x_display, x_colormap, "Yellow", &rgbcolor, &hardwarecolor );
- X XAllocColor( x_display, x_colormap, &hardwarecolor );
- X x_colchart[ LIGHT_YELLOW ] = hardwarecolor.pixel;
- X x_colchart[ DARK_YELLOW ] = hardwarecolor.pixel;
- X
- X XLookupColor( x_display, x_colormap, "Cyan", &rgbcolor, &hardwarecolor );
- X XAllocColor( x_display, x_colormap, &hardwarecolor );
- X x_colchart[ LIGHT_CYAN ] = hardwarecolor.pixel;
- X x_colchart[ DARK_CYAN ] = hardwarecolor.pixel;
- X
- X XLookupColor( x_display, x_colormap, "Magenta", &rgbcolor, &hardwarecolor );
- X XAllocColor( x_display, x_colormap, &hardwarecolor );
- X x_colchart[ LIGHT_MAGENTA ] = hardwarecolor.pixel;
- X x_colchart[ DARK_MAGENTA ] = hardwarecolor.pixel;
- X
- X return TRUE;
- X }
- X
- /****************************************************************
- X
- X x_color()
- X
- ****************************************************************/
- X
- unsigned long
- x_color( gr_color )
- X int gr_color;
- X {
- X
- X
- X if ( x_depth <= 1 )
- X {
- X switch ( gr_color )
- X {
- X case WHITE:
- X return WhitePixel( x_display, x_screen );
- X break;
- X case BLACK:
- X default:
- X return BlackPixel( x_display, x_screen );
- X break;
- X }
- X }
- X
- X else
- X {
- X return x_colchart[ gr_color ];
- X }
- X }
- X
- /****************************************************************
- X
- X x_fillstyle()
- X
- ****************************************************************/
- X
- x_fillstyle( gr_fillstyle )
- X int gr_fillstyle;
- X {
- X switch( gr_fillstyle )
- X {
- X case GRID:
- X return FillStippled;
- X break;
- X case HATCH:
- X return FillTiled;
- X break;
- X case HOLLOW:
- X case SOLID:
- X default:
- X return FillSolid;
- X break;
- X }
- X }
- X
- /****************************************************************
- X
- X x_linestyle()
- X
- ****************************************************************/
- X
- x_linestyle( gr_linestyle )
- X int gr_linestyle;
- X {
- X switch( gr_linestyle )
- X {
- X case GRID:
- X return LineOnOffDash;
- X break;
- X case SOLID:
- X case HOLLOW:
- X default:
- X return LineSolid;
- X break;
- X }
- X }
- X
- /****************************************************************
- X
- X x_setscreen()
- X
- ****************************************************************/
- X
- x_setscreen( screen )
- X int screen;
- X {
- X switch( screen )
- X {
- X case GR_PRIMARY:
- X x_selected = (Drawable) x_primary;
- X break;
- X case GR_HIDDEN:
- X x_selected = (Drawable) x_hidden;
- X break;
- X default:
- #ifdef DEBUG
- X sprintf( bw_ebuf, "[pr:] x_screen received %d", screen );
- X bw_error( bw_ebuf );
- #endif
- X return BW_ERROR;
- X break;
- X }
- X return TRUE;
- X }
- X
- X
- SHAR_EOF
- chmod 0644 io/gr/gr_x.c ||
- echo 'restore of io/gr/gr_x.c failed'
- Wc_c="`wc -c < 'io/gr/gr_x.c'`"
- test 30654 -eq "$Wc_c" ||
- echo 'io/gr/gr_x.c: original size 30654, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/gr/makefile.tam ==============
- if test -f 'io/gr/makefile.tam' -a X"$1" != X"-c"; then
- echo 'x - skipping io/gr/makefile.tam (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/gr/makefile.tam (Binary)'
- sed 's/^X//' << 'SHAR_EOF' > _shar_tmp_.tmp &&
- begin 600 io/gr/makefile.tam
- SHAR_EOF
- true || echo 'restore of io/gr/makefile.tam failed'
- fi
- echo 'End of part 4'
- echo 'File io/gr/makefile.tam is continued in part 5'
- echo 5 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-