home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1991-12-27 | 55.2 KB | 2,168 lines
Newsgroups: comp.sources.misc From: tcamp@hercules.acpub.duke.edu (Ted Campbell) Subject: v27i010: sfs - Space Flight Simulator, Part10/21 Message-ID: <1991Dec24.191522.20578@sparky.imd.sterling.com> X-Md4-Signature: dab3c2e71feb4339a67498ea5b8efa23 Date: Tue, 24 Dec 1991 19:15:22 GMT Approved: kent@sparky.imd.sterling.com Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell) Posting-number: Volume 27, Issue 10 Archive-name: sfs/part10 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/ui/ui_pbm.c continued # if test ! -r _shar_seq_.tmp; then echo 'Please unpack part 1 first!' exit 1 fi (read Scheck if test "$Scheck" != 10; 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/ui/ui_pbm.c' else echo 'x - continuing file io/ui/ui_pbm.c' sed 's/^X//' << 'SHAR_EOF' >> 'io/ui/ui_pbm.c' && 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 X #include "stdio.h" #include "ctype.h" X #ifdef __STDC__ #include "malloc.h" #include "stdlib.h" #else extern char * malloc(); #include "math.h" #endif X #include "bw.h" #include "gr.h" #include "ui.h" X #define BUFSIZE 128 #define TESTINT 0 #define ACC 50 X extern char *pbm_fgets(); X ui_pbmread( file, pmstruct, foreground, background ) X char *file; X struct pbm_struct *pmstruct; X int foreground, background; X { X FILE *fp; X char *p; X static int w, h, i, ctr; X register int x, y; X static char tbuf[ BW_EBUFSIZE ]; X X if ( ( fp = fopen( file, "r" ) ) == NULL ) X { X strcpy( tbuf, ui_fontpath ); X strcat( tbuf, file ); X if ( ( fp = fopen( tbuf, "r" ) ) == NULL ) X { X strcpy( tbuf, "../../fonts/" ); X strcat( tbuf, file ); X if ( ( fp = fopen( tbuf, "r" ) ) == NULL ) X { #ifdef OLD_DEBUG X fprintf( stderr, "Failed to open file %s \n", file ); #endif X return FALSE; X } X } X } X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "Opened: %s ", file ); X bw_debug( bw_ebuf ); #endif X X /* Read first line to check for PBM magic number */ X X p = pbm_fgets( tbuf, BUFSIZE, fp ); X if ( tbuf[ 0 ] != 'P' ) X { #ifdef DEBUG X sprintf( bw_ebuf, "File %s is not in PBM format", file ); X bw_error( bw_ebuf ); #endif X return BW_ERROR; X } X if ( tbuf[ 1 ] != '1' ) X { #ifdef DEBUG X sprintf( bw_ebuf, "File %s is not in PBM format", file ); X bw_error( bw_ebuf ); #endif X return BW_ERROR; X } X X /* Read next line to get width and height */ X X p = pbm_fgets( tbuf, BUFSIZE, fp ); X sscanf( tbuf, "%d %d", &w, &h ); X pmstruct->xsize = w; X pmstruct->ysize = h; X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "Sizes read: x: %03d y: %03d ", pmstruct->xsize, pmstruct->ysize ); X bw_debug( bw_ebuf ); #endif X X /* display the bitmap in hidden memory before getting image */ X X y = 0; X while ( ( y < pmstruct->ysize ) && ( feof( fp ) == 0 )) X { X x = 0; X p = pbm_fgets( tbuf, BUFSIZE, fp ); X ctr = 0; X if ( p == NULL ) X { #ifdef DEBUG X bw_error( "PBM file terminated prematurely" ); #endif X return FALSE; X } X while( ( x < pmstruct->xsize ) && ( tbuf[ ctr ] != '\n' )) X { X i = pbm_nextc( tbuf, &ctr ); X if ( i == 0 ) X { X gr_pixel( GR_HIDDEN, x, ( pmstruct->ysize - y), background ); X } X else if ( i == 1 ) X { X gr_pixel( GR_HIDDEN, x, ( pmstruct->ysize - y), foreground ); X } X ++x; X } X ++y; X } X X /* close the bitmap file */ X X fclose( fp ); X X /* save the image */ X X gr_imsave( GR_HIDDEN, TRUE, 0, 1, x - 1, y, &( pmstruct->image ) ); X X return TRUE; X X } X ui_pbmshow( screen, x, y, pmstruct ) X int screen; X int x, y; X struct pbm_struct *pmstruct; X { X X if ( pmstruct == NULL ) X { #ifdef DEBUG X bw_error( "ui_pmshow() received NULL pbm structure" ); #endif X return BW_ERROR; X } X #ifdef OLD_DEBUG X bw_debug( "Ready to show image" ); #endif X gr_imsave( screen, FALSE, x, y + 1, x + pmstruct->xsize - 1, X y + pmstruct->ysize - 1, &( pmstruct->image ) ); X X } X char * pbm_fgets( string, n, stream ) X char *string; X int n; X FILE *stream; X { X register int c; X char *p; X X c = TRUE; X while( c == TRUE ) X { X p = fgets( string, n, stream ); X if ( p == NULL ) X { X return NULL; X } X if ( string[ 0 ] != '#' ) X { #ifdef OLD_DEBUG X sprintf( bw_ebuf, "read line <%s>", string ); X bw_debug( bw_ebuf ); #endif X return p; X } X } X } X pbm_nextc( s, ctr ) X char *s; X int *ctr; X { X static char tbuf[ 12 ]; X register int c; X #ifdef OLD_DEBUG X bw_message( "entered pbm_nextc()" ); #endif X X while( isspace( s[ *ctr ] ) != FALSE ) X { X ++*ctr; X } X X c = 0; X while( isspace( s[*ctr ] ) == FALSE ) X { X tbuf[ c ] = s[ *ctr ]; X ++*ctr; X ++c; X tbuf[ c ] = 0; X } X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "read char %d", atoi( tbuf ) ); X bw_debug( bw_ebuf ); #endif X X return atoi( tbuf ); X } X ui_pbmcenter( screen, x1, y1, x2, y2, pmstruct ) X int screen; X int x1, y1, x2, y2; X struct pbm_struct *pmstruct; X { X register int x, y; X X /* calculate coordinates */ X X x = x1 + ((( x2 - x1 ) - ( pmstruct->xsize )) / 2 ); X y = y1 + ((( y2 - y1 ) - ( pmstruct->ysize )) / 2 ); X X /* show the icon */ X X ui_pbmshow( screen, x, y, pmstruct ); X X } X ui_pbmtile( screen, x1, y1, x2, y2, pmstruct ) X int screen; X int x1, y1, x2, y2; X struct pbm_struct *pmstruct; X { X register int x, y; X static int image; X X /* check size */ X X if ( ( x2 - x1 ) < pmstruct->xsize ) X { #ifdef DEBUG X sprintf( bw_ebuf, "Area too small: x1 %d x2 %d: xsize %d", X x1, x2, pmstruct->xsize ); X bw_error( bw_ebuf ); #endif X return BW_ERROR; X } X X if ( ( y2 - y1 ) < pmstruct->ysize ) X { #ifdef DEBUG X sprintf( bw_ebuf, "Area too small: y1 %d y2 %d: ysize %d", X y1, y2, pmstruct->ysize ); X bw_error( bw_ebuf ); #endif X return BW_ERROR; X } X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "x1 %d, y1 %d, x2, %d, y2 %d, xsize, %d, ysize %d", X x1, y1, x2, y2, pmstruct->xsize, pmstruct->ysize ); X bw_debug( bw_ebuf ); X bw_message( " " ); #endif X X /* fill area with tile except right and top areas */ X X for ( x = x1; x < ( x2 - pmstruct->xsize ); x += pmstruct->xsize ) X { X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "x = %d", x ); X bw_debug( bw_ebuf ); X bw_message( " " ); #endif X for ( y = y1; y < ( y2 - pmstruct->ysize ); y += pmstruct->ysize ) X { #ifdef OLD_DEBUG X sprintf( bw_ebuf, "y = %d", y ); X bw_debug( bw_ebuf ); X bw_message( " " ); #endif X ui_pbmshow( screen, x, y, pmstruct ); #ifdef OLD_DEBUG X bw_debug( "icon displayed" ); X bw_message( " " ); #endif X } X X } X X /* first the right remaining area */ X X if ( x != x2 ) X { X gr_imsave( screen, TRUE, x1, y1, x1 + ( x2 - x ), y, &image ); X gr_imsave( screen, FALSE, x, y1, x2, y, &image ); X } X gr_imfree( image ); X X /* then the top remaining area */ X X if ( y != y2 ) X { X gr_imsave( screen, TRUE, x1, y1, x2, y1 + ( y2 - y ), &image ); X gr_imsave( screen, FALSE, x1, y, x2, y2, &image ); X } X gr_imfree( image ); X } SHAR_EOF echo 'File io/ui/ui_pbm.c is complete' && chmod 0644 io/ui/ui_pbm.c || echo 'restore of io/ui/ui_pbm.c failed' Wc_c="`wc -c < 'io/ui/ui_pbm.c'`" test 7475 -eq "$Wc_c" || echo 'io/ui/ui_pbm.c: original size 7475, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= io/ui/ui_rband.c ============== if test -f 'io/ui/ui_rband.c' -a X"$1" != X"-c"; then echo 'x - skipping io/ui/ui_rband.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting io/ui/ui_rband.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_rband.c' && X /*************************************************************** X X ui_rband.c rubber-band routine for ui 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 "ctype.h" X #include "bw.h" #include "kb.h" #include "gr.h" #include "ui.h" X #ifdef __STDC__ #include "malloc.h" #else extern char * malloc(); #endif X #ifndef __STDC__ #define time_t long #define size_t int #endif X #define ERR_RBAND "Memory error in ui_rband() routine" X ui_rband( mode, x1, y1, x2, y2 ) X int mode; X int *x1, *y1, *x2, *y2; X { X static int left, right, top, bottom; X static int b, k; X static int y, x; /* current position */ X static int yy, xx; /* dummy arguments */ X int start_x, start_y; /* start x, y, position */ X int prev_x, prev_y; /* previous x, y position */ X int rxstat; /* receive status (keyboard or mouse) */ X X /* Check mode */ X X if ( mode != TRUE ) X { X goto movebox; X } X X /*** RBAND FUNCTION TRUE: RUBBERBAND FOR VARIABLE_SIZED BOX ****/ X X /* save initial screen areas */ X X x = *x2; X y = *y1; X gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x1, *y2, &left ); X gr_imsave( GR_PRIMARY, TRUE, *x2, *y1, *x2, *y2, &right ); X gr_imsave( GR_PRIMARY, TRUE, *x1, *y2, *x2, *y2, &top ); X gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x2, *y1, &bottom ); X X /* reposition mouse to begin sizing */ X X if ( gr_ismouse == TRUE ) X { X gr_mouse( POSITION, &x, &y, &b ); X } X X /* draw the initial box */ X X gr_line( GR_PRIMARY, *x1, *y1, *x1, *y2, BLACK, SOLID ); /* left */ X gr_line( GR_PRIMARY, *x2, *y1, *x2, *y2, BLACK, SOLID ); /* right */ X gr_line( GR_PRIMARY, *x1, *y2, *x2, *y2, BLACK, SOLID ); /* top */ X gr_line( GR_PRIMARY, *x1, *y1, *x2, *y1, BLACK, SOLID ); /* bottom */ X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "gr_mouse( SAMPLE ) == %d ", X gr_mouse( SAMPLE, x2, y1, &b ) ); X bw_message( bw_ebuf ); #endif X X /* main rband loop: wait until first mouse click or RETURN */ X X if ( gr_ismouse == TRUE ) X { X bw_message( " Use Mouse to Size Window, Click to Fix Size " ); X } X else X { X bw_message( " Use Arrow Keys to Size Window, RETURN to Fix Size " ); X } X X rxstat = FALSE; X while ( rxstat != TRUE ) X { X X if (( x != *x2 ) || ( y != *y1 )) X { X X /* restore old screen areas */ X X gr_imsave( GR_PRIMARY, FALSE, *x1, y, *x1, *y2, &left ); X gr_imsave( GR_PRIMARY, FALSE, x, y, x, *y2, &right ); X gr_imsave( GR_PRIMARY, FALSE, *x1, *y2, x, *y2, &top ); X gr_imsave( GR_PRIMARY, FALSE, *x1, y, x, y, &bottom ); X X /* release memory */ X X gr_imfree( top ); X gr_imfree( left ); X gr_imfree( bottom ); X gr_imfree( right ); X X /* check for position above or left of point */ X X if ( *x2 < *x1 ) X { X *x2 = *x1; X } X X if ( *y1 > *y2 ) X { X *y1 = *y2; X } X X /* save new screen areas */ X X gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x1, *y2, &left ); X gr_imsave( GR_PRIMARY, TRUE, *x2, *y1, *x2, *y2, &right ); X gr_imsave( GR_PRIMARY, TRUE, *x1, *y2, *x2, *y2, &top ); X gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x2, *y1, &bottom ); X X /* draw lines */ X #ifdef OLD_DEBUG X bw_message( "Drawing... " ); #endif X X gr_line( GR_PRIMARY, *x1, *y1, *x1, *y2, BLACK, SOLID ); /* left */ X gr_line( GR_PRIMARY, *x2, *y1, *x2, *y2, BLACK, SOLID ); /* right */ X gr_line( GR_PRIMARY, *x1, *y2, *x2, *y2, BLACK, SOLID ); /* top */ X gr_line( GR_PRIMARY, *x1, *y1, *x2, *y1, BLACK, SOLID ); /* bottom */ X X x = *x2; X y = *y1; X } #ifdef OLD_DEBUG X else X { X bw_message( "No change... " ); X } #endif X X /* check keyboard or mouse status */ X X if ( gr_ismouse == TRUE ) X { X rxstat = gr_mouse( SAMPLE, x2, y1, &b ); X } X else X { X if ( kb_rxstat() == TRUE ) X { X k = kb_rx(); X switch (k) X { X case '\n': X case '\r': X rxstat = TRUE; X break; X case KB_UP: X ++(*y1); X break; X case KB_DOWN: X --(*y1); X break; X case KB_LEFT: X --(*x2); X break; X case KB_RIGHT: X ++(*x2); X break; X } X } X } X X } /* end main rband loop */ X X /* wait until the mouse is released */ X X if ( gr_ismouse == TRUE ) X { X gr_mouse( WAIT, &xx, &yy, &b ); /* down */ X gr_mouse( WAIT, &xx, &yy, &b ); /* up */ X } X #ifdef OLD_DEBUG X bw_message( "Loop Finished " ); #endif X X /* restore old screen areas */ X X gr_imsave( GR_PRIMARY, FALSE, *x1, y, *x1, *y2, &left ); X gr_imsave( GR_PRIMARY, FALSE, x, y, x, *y2, &right ); X gr_imsave( GR_PRIMARY, FALSE, *x1, *y2, x, *y2, &top ); X gr_imsave( GR_PRIMARY, FALSE, *x1, y, x, y, &bottom ); X X /* release memory */ X X gr_imfree( top ); X gr_imfree( left ); X gr_imfree( bottom ); X gr_imfree( right ); X X goto end; X X /*** RBAND FUNCTION NOT TRUE: MOVE FIXED_SIZE BOX ***/ X X movebox: X X /* reposition the mouse */ X X start_x = x = *x2; X start_y = y = *y1; X X if ( gr_ismouse == TRUE ) X { X gr_mouse( POSITION, &x, &y, &b ); X } X X /* save the initial area */ X X gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x1, *y2, &left ); X gr_imsave( GR_PRIMARY, TRUE, *x2, *y1, *x2, *y2, &right ); X gr_imsave( GR_PRIMARY, TRUE, *x1, *y2, *x2, *y2, &top ); X gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x2, *y1, &bottom ); X X /* show the initial rectangle */ X X gr_line( GR_PRIMARY, *x1, *y1, *x1, *y2, BLACK, SOLID ); X gr_line( GR_PRIMARY, *x2, *y1, *x2, *y2, BLACK, SOLID ); X gr_line( GR_PRIMARY, *x1, *y2, *x2, *y2, BLACK, SOLID ); X gr_line( GR_PRIMARY, *x1, *y1, *x2, *y1, BLACK, SOLID ); X X /* main rband loop */ X X prev_x = x = start_x; X prev_y = y = start_y; X X if ( gr_ismouse == TRUE ) X { X bw_message( " Use Mouse to Move Window, Click to Fix Position " ); X } X else X { X bw_message( " Use Arrow Keys to Move Window, RETURN to Fix Position " ); X } X X rxstat = FALSE; X while( rxstat != TRUE ) X { X X if ( ( x != prev_x ) || ( y != prev_y )) X { X X /* restore the old area */ X X gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x1 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &left ); X gr_imsave( GR_PRIMARY, FALSE, *x2 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &right ); X gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &top ); X gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), &bottom ); X X /* release memory */ X X gr_imfree( top ); X gr_imfree( left ); X gr_imfree( bottom ); X gr_imfree( right ); X X /* check for position out of bounds */ X X if ( ( *x1 + ( x - start_x )) < 0 ) X { X x = prev_x; X } X else if ( ( *x2 + ( x - start_x )) > ui_grwind->xmax ) X { X x = prev_x; X } X X if ( ( *y1 + ( y - start_y )) < 0 ) X { X y = prev_y; X } X else if ( ( *y2 + ( y - start_y )) > ui_grwind->ymax ) X { X y = prev_y; X } X X /* save the new area */ X X gr_imsave( GR_PRIMARY, TRUE, *x1 + ( x - start_x ), *y1 + ( y - start_y ), *x1 + ( x - start_x ), *y2 + ( y - start_y ), &left ); X gr_imsave( GR_PRIMARY, TRUE, *x2 + ( x - start_x ), *y1 + ( y - start_y ), *x2 + ( x - start_x ), *y2 + ( y - start_y ), &right ); X gr_imsave( GR_PRIMARY, TRUE, *x1 + ( x - start_x ), *y2 + ( y - start_y ), *x2 + ( x - start_x ), *y2 + ( y - start_y ), &top ); X gr_imsave( GR_PRIMARY, TRUE, *x1 + ( x - start_x ), *y1 + ( y - start_y ), *x2 + ( x - start_x ), *y1 + ( y - start_y ), &bottom ); X X /* draw the new area */ X X gr_line( GR_PRIMARY, *x1 + ( x - start_x ), *y1 + ( y - start_y ), *x1 + ( x - start_x ), *y2 + ( y - start_y ), BLACK, SOLID ); X gr_line( GR_PRIMARY, *x2 + ( x - start_x ), *y1 + ( y - start_y ), *x2 + ( x - start_x ), *y2 + ( y - start_y ), BLACK, SOLID ); X gr_line( GR_PRIMARY, *x1 + ( x - start_x ), *y2 + ( y - start_y ), *x2 + ( x - start_x ), *y2 + ( y - start_y ), BLACK, SOLID ); X gr_line( GR_PRIMARY, *x1 + ( x - start_x ), *y1 + ( y - start_y ), *x2 + ( x - start_x ), *y1 + ( y - start_y ), BLACK, SOLID ); X X prev_x = x; X prev_y = y; X } X X /* check keyboard or mouse status */ X X if ( gr_ismouse == TRUE ) X { X rxstat = gr_mouse( SAMPLE, &x, &y, &b ); X } X else X { X if ( kb_rxstat() == TRUE ) X { X k = kb_rx(); X switch (k) X { X case '\n': X case '\r': X rxstat = TRUE; X break; X case KB_UP: X ++y; X break; X case KB_DOWN: X --y; X break; X case KB_LEFT: X --x; X break; X case KB_RIGHT: X ++x; X break; X } X } X } X X } /* end of main rband loop */ X X /* restore the old area */ X X gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x1 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &left ); X gr_imsave( GR_PRIMARY, FALSE, *x2 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &right ); X gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &top ); X gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), &bottom ); X X /* release memory */ X X gr_imfree( top ); X gr_imfree( left ); X gr_imfree( bottom ); X gr_imfree( right ); X X /* get final mouse position */ X X if ( gr_ismouse == TRUE ) X { X gr_mouse( WAIT, &x, &y, &b ); /* click down */ X gr_mouse( WAIT, &xx, &yy, &b ); /* click up */ X } X X *x1 = *x1 + ( x - start_x ); X *x2 = *x2 + ( x - start_x ); X *y1 = *y1 + ( y - start_y ); X *y2 = *y2 + ( y - start_y ); X X end: X X bw_message( " " ); X X return TRUE; X X } X SHAR_EOF chmod 0644 io/ui/ui_rband.c || echo 'restore of io/ui/ui_rband.c failed' Wc_c="`wc -c < 'io/ui/ui_rband.c'`" test 11199 -eq "$Wc_c" || echo 'io/ui/ui_rband.c: original size 11199, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= io/ui/ui_test.c ============== if test -f 'io/ui/ui_test.c' -a X"$1" != X"-c"; then echo 'x - skipping io/ui/ui_test.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting io/ui/ui_test.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_test.c' && /*************************************************************** X X ui_test.c Test GR and UI 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 /* #define TEST_TW */ X #include "stdio.h" #ifdef __STDC__ #include "malloc.h" #else extern char *malloc(); #define size_t int #endif #include "bw.h" #include "gr.h" #include "kb.h" #include "dr.h" #ifdef TEST_TW #include "tw.h" #endif #include "ui.h" X #define TITLESIZE 64 #define MAXENTRIES 64 X #define MM_ITEMS 12 /* items in main menu */ X char bw_ebuf[ BW_EBUFSIZE ]; X struct uiwindow *big_box, *little_box, *d_box; struct menu_box m_box; struct dir_ent *d_entries[ MAXENTRIES ]; X char *d_titles[ MAXENTRIES ]; X char *t_titles[] = { X " Test Windows", X " Test Colors", X " Test Styles", X " Dialog Box", X " Yes/No Box", X " Alarm Box ", X " Text File Selector", X " Icon File Selector ", X " Test Pixel Map ", X " Test Rubberbanding ", #ifdef TEST_TW X " Test GR Text Window ", #else X " [UNAVAILABLE] ", #endif X " Exit from Test" }; X char tbuf[ 128 ]; static char *buf; X main() X { X register int c, y; X int x1, y1, item; X X /* Initialize the screen and keyboard */ X X /* Initialize the toolkit */ X X ui_init(); X if ( ui_grwind->initialized == FALSE ) X { X printf( "The graphics system has not been initialized.\n" ); X return -1; X } X X /* get memory for directory/menu arrays */ X X for ( c = 0; c < MAXENTRIES; ++c ) X { X if ( ( d_entries[ c ] = X (struct dir_ent *) malloc( sizeof( struct dir_ent ))) == NULL ) X { X gr_deinit(); X kb_deinit(); X fprintf( stderr, "Cannot allocate memory for directory structure %d \n", c ); X exit( 1 ); X } X if ( ( d_titles[ c ] = malloc( TITLESIZE )) == NULL ) X { X gr_deinit(); X kb_deinit(); X fprintf( stderr, "Cannot allocate memory for title array %d \n", c ); X exit( 1 ); X } X } X X /* Clear the screen */ X X ui_setscreen( GR_HIDDEN ); X gr_cls( GR_HIDDEN ); X #ifdef OLD_DEBUG X fprintf( stderr, "Ready to draw main box\n" ); X kb_rx(); #endif X X big_box = ui_window( 0, 0, ui_grwind->xmax, ui_grwind->ymax, X TRUE, WHITE, BLACK, X "A Test of the Bywater Graphical User Interface", FALSE, BLACK, X FALSE, BLACK, WHITE, GRID, BUT_CLOSE | BUT_MOVE | BUT_RESIZE ); X #ifdef OLD_DEBUG X fprintf( stderr, "Drew main box\n" ); X kb_rx(); #endif X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "imsize = %lx", gr_imsize( big_box->u_x1, big_box->u_y1, X big_box->u_x2, big_box->u_y2 ) ); X bw_debug( bw_ebuf ); #endif X X /* initialize the clock */ X /* ui_clinit( big_box->u_x1, big_box->u_y1, BLACK, WHITE ); */ X X /* blit to GR_PRIMARY and switch to primary screen */ X X gr_blit( GR_HIDDEN, GR_PRIMARY, 0, 0, ui_grwind->xmax, X ui_grwind->ymax ); X ui_setscreen( GR_PRIMARY ); #ifdef OLD_DEBUG X kb_rx(); #endif X X x1 = ui_grwind->xmax / 20; X y1 = ui_grwind->ymax / 10; X X /* main program loop, y == TRUE */ X X y = TRUE; X m_box.is_drawn = FALSE; X while( y == TRUE ) X { X #ifdef OLD_DEBUG X bw_message( "Ready to activate list box" ); X kb_rx(); #endif X X /* clear the user area */ X X ui_fbox( big_box->u_x1, big_box->u_y1, big_box->u_x2, big_box->u_y2, X BLACK, SOLID ); X ui_fbox( big_box->u_x1, big_box->u_y1, big_box->u_x2, big_box->u_y2, X WHITE, GRID ); X X X /* call the menu */ X X m_box.is_drawn = FALSE; X item = ui_list( MENU_SLIDERS, X x1 * 2, y1 * 4, x1 * 10, big_box->u_y2 - y1, X "Test Options", MM_ITEMS, t_titles, BLACK, WHITE, WHITE, X &m_box ); X X /* save the screen before executing */ X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "big_box = %08lx, x1 = %d", (long) big_box, X big_box->u_x1 ); X bw_debug( bw_ebuf ); X bw_message( " " ); #endif X X /* gr_save( GR_PRIMARY, TRUE, big_box->u_x1, big_box->u_y1, X big_box->u_x2, big_box->u_y2, buf ); */ X X /* evaluate the item chosen */ X X switch( item ) X { X case 0: X windows(); X break; X case 1: X colors(); X break; X case 2: X styles(); X break; X case 3: X dialog(); X break; X case 4: X yes_no(); X break; X case 5: X test_alarm(); X break; X case 6: X text_file(); X break; X case 7: X icon_file(); X break; X case 8: X pixmap(); X ui_wait(); X break; X case 9: X test_rband(); X break; X case 10: #ifdef TEST_TW X test_tw(); #endif X break; X case TK_EXIT: X case 11: X y = FALSE; X break; X } X X /* restore screen */ X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "big_box = %08lx, x1 = %d", (long) big_box, X big_box->u_x1 ); X bw_debug( bw_ebuf ); X bw_message( " " ); #endif X X /* gr_save( GR_PRIMARY, FALSE, big_box->u_x1, big_box->u_y1, X big_box->u_x2, big_box->u_y2, buf ); */ X X } X X /* Clear screen and restore prior state of computer */ X X gr_cls( GR_PRIMARY ); X kb_deinit(); X gr_deinit(); X X } X windows() X { X int x, y; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X little_box = ui_window( x * 2, y, x * 14, y * 7, 1, 1, 0, X "A Full-Featured Window", X 1, 0, 1, 0, 1, 1, BUT_CLOSE | BUT_MOVE | BUT_RESIZE ); X X ui_wait(); X X /* Experiment: title too long */ X X little_box = ui_window( x * 2, y, x * 8, y * 5, TRUE, WHITE, BLACK, X "A Full-Featured Window with a Rather Extremely Long Title", X TRUE, BLACK, TRUE, BLACK, WHITE, SOLID, 0 ); X X ui_wait(); X X /* Write text to this window */ X X ui_text( little_box->u_x1, little_box->u_y1, X little_box->u_x2, little_box->u_y2, X 29, 1, 0, X "This line of text has been written into this box utilizing the ui_text() function. We need to write a really long string to it\n" ); X X ui_wait(); X X } X colors() X { X register int c; X int x, y; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X for ( c = 0; c < gr_colors; ++c ) X { X sprintf( ui_tbuf, "This is color %d", c ); X little_box = ui_window( x * 2, y, x * 14, y * 6, TRUE, WHITE, X BLACK, ui_tbuf, X TRUE, BLACK, TRUE, BLACK, c, SOLID, 0 ); X ui_wait(); X } X X X } X styles() X { X register int c; X int x, y; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X for ( c = 0; c < 4; ++c ) X { X sprintf( ui_tbuf, "This is style %d", c ); X little_box = ui_window( x * 2, y, x * 14, y * 6, TRUE, WHITE, X BLACK, ui_tbuf, TRUE, BLACK, TRUE, BLACK, WHITE, c, 0 ); X ui_wait(); X } X X } X dialog() X { X char d_buf[ 64 ]; X int x, y; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X ui_dial( x * 2, y, x * 14, y * 6, WHITE, BLACK, BLACK, X TRUE, "A Test Dialog Box", X "Please enter the name of your favorite saint \n(may be Orthodox or Catholic). No Anglicans accepted, or even Protestant or Evangelical Saints. Thanks very much for your help.", X "Your saint: ", d_buf, &d_box ); X sprintf( ui_tbuf, "Saint selected: %s ", d_buf ); X ui_wtitle( d_box, ui_tbuf ); X ui_wait(); X } X yes_no() X { X int x, y, r; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X r = ui_yn( x * 2, y, x * 14, y * 6, WHITE, BLACK, BLACK, TRUE, X "Do you want $ 1,000,000.00 in cash?", " NO ", " YES ", X &d_box ); X } X test_alarm() X { X int x, y, r; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X r = ui_alarm( x * 2, y, x * 14, y * 6, WHITE, BLACK, BLACK, TRUE, X "An alarm box like this would be used in case of a serious program or system problem.", X " OK ", X &d_box ); X } X ui_poll() X { /* ui_clock(); */ X } X bw_error( s ) X char *s; X { X char buf[ BW_EBUFSIZE ]; X X sprintf( buf, "ERROR: %s ", s ); X gr_text( GR_PRIMARY, 5, 5, buf, BLACK, WHITE ); X ui_wait(); X } X #ifdef DEBUG bw_debug( s ) X char *s; X { X char buf[ BW_EBUFSIZE ]; X X sprintf( buf, "DEBUG: %s ", s ); X gr_text( GR_PRIMARY, 5, 5, buf, BLACK, WHITE ); X ui_wait(); X } X #endif X bw_message( s ) X char *s; X { X char buf[ BW_EBUFSIZE ]; X X sprintf( buf, "MESSAGE: %s ", s ); X gr_text( GR_PRIMARY, 5, 5, buf, BLACK, WHITE ); X } X text_file() X { X static struct menu_box m_box; X int x, y, item; X register int c, test; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X m_box.is_drawn = FALSE; X item = ui_ftext( x * 2, y * 2, x * 14, y * 7, dr_all, "File Selector Test", X &m_box, d_titles, d_entries, MAXENTRIES, WHITE, BLACK, WHITE ); X X if ( ( c != TK_ERROR ) && ( c != TK_EXIT )) X { X sprintf( ui_tbuf, "File selected: %s ", X d_entries[ item ]->filename ); X ui_wtitle( m_box.window, ui_tbuf ); X ui_wait(); X } X X } X icon_file() X { X static struct menu_box m_box; X int x, y, item; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X m_box.is_drawn = FALSE; X item = ui_ficon( x * 3, y * 2, x * 13, y * 9, dr_all, "TEST: ui_ficon() ", X &m_box, d_entries, MAXENTRIES, WHITE, BLACK, WHITE ); X X if ( ( item != TK_ERROR ) && ( item != TK_EXIT )) X { X sprintf( ui_tbuf, "File selected: %s ", X d_entries[ item ]->filename ); X ui_wtitle( m_box.window, ui_tbuf ); X ui_wait(); X } X X } X pixmap() X { X static struct pbm_struct pmstruct; X int x, y; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X ui_pbmread( "test.pbm", &pmstruct, WHITE, BLACK ); X X ui_pbmshow( GR_PRIMARY, x * 2, y * 2, &pmstruct ); X X } X test_rband() X { X static int x1, y1, x2, y2; X X /* fill the large area with grid */ X X ui_fbox( big_box->u_x1, big_box->u_y1, big_box->u_x2, big_box->u_y2, BLACK, SOLID ); X ui_fbox( big_box->u_x1, big_box->u_y1, big_box->u_x2, big_box->u_y2, WHITE, GRID ); X X /* get a rubber band rectangle */ X X x1 = 20; X x2 = 200; X y1 = 20; X y2 = 200; X ui_rband( TRUE, &x1, &y1, &x2, &y2 ); X X ui_fbox( x1, y1, x2, y2, BLACK, SOLID ); X ui_fbox( x1 + 1, y1 + 1, x2 - 1, y2 - 1, WHITE, SOLID ); X X bw_message( "Box now received: press a key or click to move it: " ); X ui_wait(); X X /* move it */ X X ui_rband( FALSE, &x1, &y1, &x2, &y2 ); X X ui_fbox( x1, y1, x2, y2, BLACK, SOLID ); X ui_fbox( x1 + 1, y1 + 1, x2 - 1, y2 - 1, WHITE, SOLID ); X X /* wait */ X X bw_message( " Box now moved; press a key or click for main menu" ); X ui_wait(); X X } X #ifdef TEST_TW test_tw() X { X int c; X int x, y; X struct ui_twstruct *uibw; X X x = ui_grwind->xmax / 20; X y = ui_grwind->ymax / 10; X X uibw = ui_twinit( "Test Text Window", X x * 4, y * 6, 12, 52, 0, 0, X ui_grwind->xmax, ui_grwind->ymax ); X X tw_cursor( TRUE ); X X c = 0; X while ( c != 0x1b ) X { X c = kb_rx(); X tw_outc( c ); X } X X tw_cursor( FALSE ); X } X #endif X SHAR_EOF chmod 0644 io/ui/ui_test.c || echo 'restore of io/ui/ui_test.c failed' Wc_c="`wc -c < 'io/ui/ui_test.c'`" test 11977 -eq "$Wc_c" || echo 'io/ui/ui_test.c: original size 11977, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= io/ui/ui_test.mak ============== if test -f 'io/ui/ui_test.mak' -a X"$1" != X"-c"; then echo 'x - skipping io/ui/ui_test.mak (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting io/ui/ui_test.mak (Text)' sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_test.mak' && PROJ =UI_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 = /CP:0xffff /NOI /SE:0x80 /ST:0x800 LFLAGS_D = /CO /INCR LFLAGS_R = LFLAGS =$(LFLAGS_G) $(LFLAGS_R) RUNFLAGS = OBJS_EXT = LIBS_EXT = X all: $(PROJ).exe X ui_boxes.obj: ui_boxes.c X ui_clock.obj: ui_clock.c X ui_dial.obj: ui_dial.c X ui_gets.obj: ui_gets.c X ui_icon.obj: ui_icon.c X ui_init.obj: ui_init.c X ui_list.obj: ui_list.c X ui_test.obj: ui_test.c X ui_text.obj: ui_text.c X dr_ibmpc.obj: ..\dr\dr_ibmpc.c X gr_ibmpc.obj: ..\gr\gr_ibmpc.c X kb_ibmpc.obj: ..\kb\kb_ibmpc.c X ui_rband.obj: ui_rband.c X tw_ibmpc.obj: ..\tw\tw_ibmpc.c X ui_tw.obj: ui_tw.c X ui_pbm.obj: ui_pbm.c X $(PROJ).exe: ui_boxes.obj ui_clock.obj ui_dial.obj ui_gets.obj ui_icon.obj ui_init.obj \ X ui_list.obj ui_test.obj ui_text.obj dr_ibmpc.obj gr_ibmpc.obj kb_ibmpc.obj ui_rband.obj \ X tw_ibmpc.obj ui_tw.obj ui_pbm.obj $(OBJS_EXT) X echo >NUL @<<$(PROJ).crf ui_boxes.obj + ui_clock.obj + ui_dial.obj + ui_gets.obj + ui_icon.obj + ui_init.obj + ui_list.obj + ui_test.obj + ui_text.obj + dr_ibmpc.obj + gr_ibmpc.obj + kb_ibmpc.obj + ui_rband.obj + tw_ibmpc.obj + ui_tw.obj + ui_pbm.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/ui/ui_test.mak || echo 'restore of io/ui/ui_test.mak failed' Wc_c="`wc -c < 'io/ui/ui_test.mak'`" test 1354 -eq "$Wc_c" || echo 'io/ui/ui_test.mak: original size 1354, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= io/ui/ui_text.c ============== if test -f 'io/ui/ui_text.c' -a X"$1" != X"-c"; then echo 'x - skipping io/ui/ui_text.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting io/ui/ui_text.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_text.c' && /**************************************************************** X X ui_text.c Text handling routines for X The Bywater Graphical User Interface 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 "ctype.h" #include "string.h" #include "gr.h" #include "bw.h" #include "ui.h" X #define MAXBUF 128 #define PIXEL_SPACES 3 #define SAFETY_MARGIN 1 X /* #define GRDIRECT */ /* use gr_text function from ui_text */ X /* else use ui_str from ui_text */ X ui_str( x1, y1, x2, background, foreground, buffer ) X int x1, y1, x2, background, foreground; X char *buffer; X { X char buf[ MAXBUF ]; X int y, c; X X /* Write to buffer until overflow occurs */ X X c = 0; X y = FALSE; X buf[ 0 ] = 0; X while( y == FALSE ) X { X buf[ c ] = buffer[ c ]; X ++c; X buf[ c ] = 0; X X if ( c >= MAXBUF ) X { X y = TRUE; X } X else if ( gr_strlen( buf ) > ( x2 - x1 ) ) X { X y = TRUE; X } X else if ( buffer[ c ] == 0 ) X { X y = TRUE; X } X } X X /* Now reverse until last whitespace */ X X --c; X if ( gr_strlen( buf ) > ( x2 - x1 )) X { X while( isspace( buf[ c ] ) == FALSE ) X { X buf[ c ] = 0; X --c; X } X } X X if ( isspace( buf[ c ] ) != FALSE ) X { X buf[ c ] = 0; X } X X /* Display the string in the appropriate colors */ X X gr_text( ui_screen, x1, y1, buf, foreground, background ); X X } X ui_text( x1, y1, x2, y2, maxlines, background, foreground, main_buffer ) X int x1, y1, x2, y2; /* Coordinates of box */ X int maxlines; /* Maximum lines to be used */ X int background; /* Background color */ X int foreground; /* Foreground color */ X char *main_buffer; /* Text buffer */ X { X int l, c, y, main_pos, word_pos, lcount, line_pos, newline; X int line_start, line_end, word_start, word_end; X static char line_buffer[ 128 ]; X static char word_buffer[ 64 ]; #ifdef OLD_DEBUG X int X; X static char Dbuffer[ BW_EBUFSIZE ]; #endif X X if ( ui_ready == FALSE ) X { X bw_error( "The user interface is not initialized." ); X return; X } X X /* set initial values */ X X l = y2 - ( ui_grwind->fysize + PIXEL_SPACES ); /* l = location on y axis */ X y = TRUE; /* continue loop */ X main_pos = 0; /* position in main buffer */ X lcount = 0; /* count of lines */ X line_start = line_end = 0; X X /* loop for each word detected */ X X while( y == TRUE ) X { X newline = FALSE; X X /* if l extends below the box, abort */ X X if ( l < y1 ) X { X return; X } X X /* if line count exceeds max allowed, abort */ X X if ( lcount >= maxlines ) X { X return; X } X X /* Get one word (up to white space or end) in buffer */ X X word_start = word_end = main_pos; X word_pos = 0; X word_buffer[ 0 ] = 0; X while( ( isspace( main_buffer[ main_pos ] ) == FALSE ) X && ( main_buffer[ main_pos ] != 0 )) X { X word_buffer[ word_pos ] = main_buffer[ main_pos ]; X ++word_end; X ++main_pos; X ++word_pos; X word_buffer[ word_pos ] = 0; /* terminate word with 0 */ X } X X /* Advance past any whitespace */ X X while ( ( isspace( main_buffer[ main_pos ] ) != FALSE ) X && ( main_buffer[ main_pos ] != 0 )) X { X if ( main_buffer[ main_pos ] == '\n' ) X { X newline = TRUE; X word_buffer[ word_pos ] = 0; X } X else X { X word_buffer[ word_pos ] = main_buffer[ main_pos ]; X } X ++main_pos; X ++word_pos; X ++word_end; X word_buffer[ word_pos ] = 0; /* set end of buffer to 0 */ X } X #ifdef OLD_DEBUG X if ( gr_strlen( word_buffer ) > 100 ) X { X sprintf( Dbuffer, "String element [%s]: may contain CR/LF", X word_buffer ); X bw_debug( Dbuffer ); X } #endif X X /* Get the current line into the buffer */ X X line_pos = 0; X line_buffer[ 0 ] = 0; X for ( c = line_start; c < line_end; ++c ) X { X line_buffer[ line_pos ] = main_buffer[ c ]; X ++line_pos; X line_buffer[ line_pos ] = 0; /* terminate with 0 */ X } X #ifdef OLD_DEBUG X sprintf( Dbuffer, "line_buffer [%s], word_buffer [%s]", line_buffer, word_buffer ); X bw_debug( Dbuffer ); #endif X X /* Now, what do we do with the word we have detected? */ X /* 1. Check to see if new word will extend past limits */ X /* if so, output 'line_buffer' only, and make word the */ X /* new line_buffer */ X X if ( ( x1 + gr_strlen( line_buffer ) + gr_strlen( word_buffer ) ) >= ( x2 - SAFETY_MARGIN )) X { #ifdef OLD_DEBUG X sprintf( Dbuffer, "Flush line: x1 = %d, line = %d, word = %d", X x1, gr_strlen( line_buffer ), gr_strlen( word_buffer ) ); X bw_debug( Dbuffer ); X sprintf( Dbuffer, "Flush line: x1 + word + line = %d, x2 = %d", X x1 + gr_strlen( line_buffer ) + gr_strlen( word_buffer ), x2 ); X bw_debug( Dbuffer ); X sprintf( Dbuffer, "Flush line: strlen( line ) = %d", X strlen( line_buffer ) ); X bw_debug( Dbuffer ); #endif #ifdef GRDIRECT X gr_text( ui_screen, x1, l, line_buffer, foreground, X background ); #else X ui_str( x1, l, x2, background, foreground, line_buffer ); #endif X ++lcount; X l -= ( ui_grwind->fysize + PIXEL_SPACES ); X X /* now make the current word the new line */ X X line_start = word_start; X line_end = word_end; X X } X X /* 2. check to see if this is the end of the main buffer */ X /* if so, flush and return */ X X else if ( main_buffer[ main_pos ] == 0 ) X { X strcat( line_buffer, word_buffer ); #ifdef GRDIRECT X gr_text( ui_screen, x1, l, line_buffer, X foreground, background ); #else X ui_str( x1, l, x2, background, foreground, line_buffer ); #endif X return; X } X X /* 3. check to see if a newline has been encountered; if so */ X /* output the current line */ X X else if ( newline == TRUE ) X { X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "Got a newline after %s|%s", X line_buffer, word_buffer ); X bw_debug( bw_ebuf ); #endif X X strcat( line_buffer, word_buffer ); #ifdef GRDIRECT X gr_text( ui_screen, x1, l, line_buffer, X foreground, background ); #else X ui_str( x1, l, x2, background, foreground, line_buffer ); #endif X ++lcount; X l -= ( ui_grwind->fysize + PIXEL_SPACES ); X line_start = line_end = main_pos; X } X X /* 4. else set end of current line to word_end and loop through */ X /* again to get another word */ X X else X { X line_end = word_end; X } X } X } X X SHAR_EOF chmod 0644 io/ui/ui_text.c || echo 'restore of io/ui/ui_text.c failed' Wc_c="`wc -c < 'io/ui/ui_text.c'`" test 7529 -eq "$Wc_c" || echo 'io/ui/ui_text.c: original size 7529, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= io/ui/ui_tw.c ============== if test -f 'io/ui/ui_tw.c' -a X"$1" != X"-c"; then echo 'x - skipping io/ui/ui_tw.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting io/ui/ui_tw.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_tw.c' && /**************************************************************** X X ui_tw.c Text Window Box under UI X The Bywater Graphical User Interface 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 "bw.h" #include "gr.h" #include "tw.h" #include "ui.h" X #ifdef __STDC__ #include "malloc.h" #else extern char * malloc(); #endif X struct ui_twstruct * ui_twinit( title, rq_x1, rq_y2, rq_lines, rq_cols, X min_x1, min_y1, max_x2, max_y2 ) X char *title; /* ttle for window */ X int rq_x1; /* requested x1 (left, graphics) position */ X int rq_y2; /* requested y2 (top, graphics) position */ X int rq_lines; /* requested text lines */ X int rq_cols; /* requested text columns */ X int min_x1; /* leftmost allowable position */ X int min_y1; /* bottommost allowable position */ X int max_x2; /* rightmost allowable position */ X int max_y2; /* topmost allowable position */ X { X static struct tw_struct *tw; X static struct ui_twstruct uitw; X static struct uiwindow *uiwind; X X tw = tw_init( rq_x1 + 6, rq_y2 - ( ui_grwind->fysize + 8 ), X rq_lines, rq_cols, X min_x1, min_y1, max_x2, max_y2 ); X #ifdef OLD_DEBUG X sprintf( bw_ebuf, "ui_twinit(): request box: x1 %d y1 %d x2 %d y1 %d", X tw->x1 - 3, tw->y1 - 3, tw->x2 + 3, X tw->y2 + ui_grwind->fysize + 2 ); X bw_debug( bw_ebuf ); #endif X X uiwind = ui_window( tw->x1 - 6, tw->y1 - 8, tw->x2 + 8, X tw->y2 + ui_grwind->fysize + 8, TRUE, WHITE, BLACK, X title, X TRUE, WHITE, TRUE, BLACK, BLACK, SOLID, BUT_CLOSE | BUT_MOVE | BUT_RESIZE ); X X uitw.tw = tw; X uitw.uiw = uiwind; X X return &uitw; X X } X ui_twdeinit() X { X } SHAR_EOF chmod 0644 io/ui/ui_tw.c || echo 'restore of io/ui/ui_tw.c failed' Wc_c="`wc -c < 'io/ui/ui_tw.c'`" test 2839 -eq "$Wc_c" || echo 'io/ui/ui_tw.c: original size 2839, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= io/ui/uitest_n.mak ============== if test -f 'io/ui/uitest_n.mak' -a X"$1" != X"-c"; then echo 'x - skipping io/ui/uitest_n.mak (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting io/ui/uitest_n.mak (Text)' sed 's/^X//' << 'SHAR_EOF' > 'io/ui/uitest_n.mak' && PROJ =UI_TEST DEBUG =0 CC =qcl CFLAGS_G = /AL /W1 /Ze /DDEBUG /DTEST_TW /I..\..\include CFLAGS_D = /Zi /Zr /Gi$(PROJ).mdt /Od CFLAGS_R = /O /Ot /DNDEBUG CFLAGS =$(CFLAGS_G) $(CFLAGS_R) LFLAGS_G = /CP:0xffff /NOI /SE:0x80 /ST:0x800 LFLAGS_D = /CO /INCR LFLAGS_R = LFLAGS =$(LFLAGS_G) $(LFLAGS_R) RUNFLAGS = OBJS_EXT = LIBS_EXT = X all: $(PROJ).exe X ui_boxes.obj: ui_boxes.c X ui_clock.obj: ui_clock.c X ui_dial.obj: ui_dial.c X ui_gets.obj: ui_gets.c X ui_icon.obj: ui_icon.c X ui_init.obj: ui_init.c X ui_list.obj: ui_list.c X ui_pbm.obj: ui_pbm.c X ui_test.obj: ui_test.c X ui_text.obj: ui_text.c X ui_rband.obj: ui_rband.c X ui_tw.obj: ui_tw.c X dr_ibmpc.obj: X $(CC) $(CFLAGS) -c ..\dr\dr_ibmpc.c X gr_ibmpc.obj: X $(CC) $(CFLAGS) -c ..\gr\gr_ibmpc.c X kb_ibmpc.obj: X $(CC) $(CFLAGS) -c ..\kb\kb_ibmpc.c X tw_ibmpc.obj: X $(CC) $(CFLAGS) -c ..\tw\tw_ibmpc.c X $(PROJ).exe: ui_boxes.obj ui_clock.obj ui_dial.obj ui_gets.obj \ X ui_icon.obj ui_init.obj \ X ui_list.obj ui_pbm.obj ui_test.obj ui_text.obj \ X ui_rband.obj ui_tw.obj tw_ibmpc.obj \ X dr_ibmpc.obj gr_ibmpc.obj kb_ibmpc.obj $(OBJS_EXT) X echo >NUL @<<$(PROJ).crf ui_boxes.obj + ui_clock.obj + ui_dial.obj + ui_gets.obj + ui_icon.obj + ui_init.obj + ui_list.obj + ui_pbm.obj + ui_test.obj + ui_text.obj + ui_rband.obj + ui_tw.obj + tw_ibmpc.obj + dr_ibmpc.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/ui/uitest_n.mak || echo 'restore of io/ui/uitest_n.mak failed' Wc_c="`wc -c < 'io/ui/uitest_n.mak'`" test 1458 -eq "$Wc_c" || echo 'io/ui/uitest_n.mak: original size 1458, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= io/ui/up.pbm ============== if test -f 'io/ui/up.pbm' -a X"$1" != X"-c"; then echo 'x - skipping io/ui/up.pbm (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting io/ui/up.pbm (Text)' sed 's/^X//' << 'SHAR_EOF' > 'io/ui/up.pbm' && P1 # blank.pbm 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 SHAR_EOF chmod 0644 io/ui/up.pbm || echo 'restore of io/ui/up.pbm failed' Wc_c="`wc -c < 'io/ui/up.pbm'`" test 221 -eq "$Wc_c" || echo 'io/ui/up.pbm: original size 221, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= sfs/as/as.h ============== if test ! -d 'sfs'; then echo 'x - creating directory sfs' mkdir 'sfs' fi if test ! -d 'sfs/as'; then echo 'x - creating directory sfs/as' mkdir 'sfs/as' fi if test -f 'sfs/as/as.h' -a X"$1" != X"-c"; then echo 'x - skipping sfs/as/as.h (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting sfs/as/as.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as.h' && /*************************************************************** X X as.h General header file X for astronomy (as) subsystem 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 #define RAD_DEG 5.729577951e1 /* Convert radians to degrees */ #define DEG_RAD 1.745329252e-2 /* Convert degrees to radians */ #define PI 3.141592654 /* Value of PI */ #define UGC (6.6631110e-23) /* Universal Gravitational Constant */ #define ELEPOCH 315532800 /* Epoch for calculating elapsed X time, = 1980/01/01 00:00:00 */ X #define SPJ_NEARSIDE 0 /* near side only of spj calculations */ #define SPJ_FARSIDE 1 /* far side only of spj calculations */ #define SPJ_ALLSIDES 2 /* calculate (show) near and far sides */ X /* Minimum and Maximum Values for Orbital Elements */ X #define OR_RAD_MIN 0 /* radius cannot be < 0 km */ #define OR_SID_MIN 0 /* sidereal day cannot be < 0 seconds */ #define OR_MAS_MIN 0.0 /* mass cannot be < 0.0 grams */ #define OR_INC_MIN -180.0 /* inclination cannot be < -180.0 degrees */ #define OR_INC_MAX 180.0 /* inclination cannot be > 180.0 degrees */ #define OR_LAN_MIN -180.0 /* longitude of asc. node cannot be < -180.0 degrees */ #define OR_LAN_MAX 180.0 /* longitude of asc. node cannot be > 180.0 degrees */ #define OR_ARP_MIN -180.0 /* argument of perigee cannot be < -180.0 degrees */ #define OR_ARP_MAX 180.0 /* argument of perigee cannot be > 180.0 degrees */ #define OR_PER_MIN 0.0 /* period cannot be < 0.0 seconds */ #define OR_ECC_MIN 0.0 /* eccentricity cannot be < 0.0 */ #define OR_ECC_MAX 1.0 /* eccentricity cannot be > 1.0 */ X struct as_focus X { X double radius; /* radius of orbital focus in kilometers */ X double sid_day; /* sidereal period of orbital focus in seconds */ X double mass; /* mass of orbital focus in kilograms */ X char *name; /* pointer to name of orbital focus */ X char *adjective; /* pointer to adjective for orbital focus */ X char *fdfile; /* pointer to fd filename */ X }; X struct as_orbit X { X struct as_focus *focus; /* orbital focus */ X double apoapsis; /* apoapsis of orbit in kilometers */ X double periapsis; /* periapsis of orbit in kilometers */ X double semimajor; /* Semimajor axis in kilometers */ X double semiminor; /* Semiminor axis in kilometers */ X double dist; /* Focus to orbit distance in kilometers */ X double inclination; /* Inclination in degrees */ X double eccentricity; /* Eccentricity ( 0 < e <= 1 ) */ X double arg_per; /* Argument of the periapsis in degrees */ X double lon_an; /* Longitude of Ascending Node in degrees */ X double lif; /* Longitude increment factor */ X double period; /* Period of orbit in seconds */ X }; X struct spj_pt { X int code; X double latitude; X double longitude; X double radius; X double x; X double y; X int side; X char *name; X struct spj_pt *next; X }; X extern double spj_meridian(); extern double spj_angrad(); extern double spj_degfix(); X extern char *as_fgets(); X extern double as_lfix(); extern double vpt_sin(); extern double vpt_cos(); extern double vpt_tan(); extern int vpt_level; SHAR_EOF chmod 0644 sfs/as/as.h || echo 'restore of sfs/as/as.h failed' Wc_c="`wc -c < 'sfs/as/as.h'`" test 4503 -eq "$Wc_c" || echo 'sfs/as/as.h: original size 4503, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= sfs/as/as_focus.c ============== if test -f 'sfs/as/as_focus.c' -a X"$1" != X"-c"; then echo 'x - skipping sfs/as/as_focus.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting sfs/as/as_focus.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as_focus.c' && /**************************************************************** X X as_focus.c Orbital focus routines X for astronomy (as) subsystem 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 SHAR_EOF true || echo 'restore of sfs/as/as_focus.c failed' fi echo 'End of part 10' echo 'File sfs/as/as_focus.c is continued in part 11' echo 11 > _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.