home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.2 KB | 2,083 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i003: sfs - Space Flight Simulator, Part03/21
- Message-ID: <1991Dec24.045207.29552@sparky.imd.sterling.com>
- X-Md4-Signature: ce194fd2a5fbe9e3ff1acfba1a2bfc0e
- Date: Tue, 24 Dec 1991 04:52:07 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 3
- Archive-name: sfs/part03
- 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_mgr.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 3; 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_mgr.c'
- else
- echo 'x - continuing file io/gr/gr_mgr.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'io/gr/gr_mgr.c' &&
- X }
- 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
- #if CHECKPARAMS
- X if ( ( x1 < 0 ) || ( x1 > mgr_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 > mgr_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 > mgr_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 > mgr_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 mgr_color( color );
- X if ( screen == MGR_DRAWMAIN )
- X {
- X m_line( x1, mgr_y( y1 ),
- X x2, mgr_y( y2 ) );
- X }
- X else
- X {
- X m_lineto( screen, x1, mgr_y( y1 ),
- X x2, mgr_y( y2 ) );
- X }
- 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
- #if CHECK_PARAMS
- X if ( ( x < 0 ) || ( x > mgr_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 > mgr_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 m_func( B_SET );
- /* m_move( 0, 0 ); */
- X
- X if ( foreground == WHITE )
- X {
- X m_clearmode( M_STANDOUT );
- X }
- X else
- X {
- X m_setmode( M_STANDOUT );
- X }
- X if ( screen == MGR_DRAWMAIN )
- X {
- X m_moveprint( x, mgr_y( y ), string );
- X }
- X else
- X {
- X m_stringto( screen, x, mgr_y( y ), string );
- X }
- X }
- X
- /****************************************************************
- X
- X gr_strlen()
- X
- ****************************************************************/
- X
- unsigned int
- gr_strlen( string )
- X char *string;
- X {
- X return ( strlen( string ) * mgr_grwind->fxsize );
- 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
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > mgr_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 > mgr_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 > mgr_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 > mgr_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 switch( style )
- X {
- X case SOLID:
- X if ( color == WHITE )
- X {
- X m_func( B_SET );
- X }
- X else
- X {
- X m_func( B_CLEAR );
- X }
- X m_bitcopyto( x1, mgr_y( y2 ),
- X abs( x2 - x1 ), abs( y2 - y1 ),
- X x1, mgr_y( y2 ),
- X screen, MGR_DRAWGRID );
- X break;
- X case GRID:
- X case HATCH:
- X m_func( B_SRC );
- X m_bitcopyto( x1, mgr_y( y2 ),
- X abs( x2 - x1 ), abs( y2 - y1 ),
- X x1, mgr_y( y2 ),
- X screen, MGR_DRAWGRID );
- X break;
- X case HOLLOW:
- X default:
- X mgr_color( color );
- X if ( screen == MGR_DRAWMAIN )
- X {
- X m_line( x1, mgr_y( y1 ),
- X x2, mgr_y( y1 ) );
- X m_line( x2, mgr_y( y1 ), x2,
- X mgr_y( y2 ) );
- X m_line( x1, mgr_y( y2 ),
- X x2, mgr_y( y2 ) );
- X m_line( x1, mgr_y( y2 ),
- X x1, mgr_y( y1 ) );
- X }
- X else
- X {
- X m_lineto( screen, x1, mgr_y( y1 ),
- X x2, mgr_y( y1 ) );
- X m_lineto( screen, x2, mgr_y( y1 ), x2,
- X mgr_y( y2 ) );
- X m_lineto( screen, x1, mgr_y( y2 ),
- X x2, mgr_y( y2 ) );
- X m_lineto( screen, x1, mgr_y( y2 ),
- X x1, mgr_y( y1 ) );
- X }
- X break;
- X }
- 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 register int c;
- X
- #if CHECK_PARAMS
- X if ( ( x < 0 ) || ( x > mgr_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 > mgr_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 mgr_color( color );
- X switch( style )
- X {
- X case SOLID:
- X case HATCH:
- X case GRID:
- X for ( c = 0; c <= radius; ++c )
- X {
- X if ( screen == MGR_DRAWMAIN )
- X {
- X m_ellipse( x, mgr_y( y ),
- X c, ( c * gr_pxsize ) / gr_pysize );
- X }
- X else
- X {
- X m_ellipseto( screen, x, mgr_y( y ),
- X c, ( c * gr_pxsize ) / gr_pysize );
- X }
- X }
- X break;
- X case HOLLOW:
- X default:
- X if ( screen == MGR_DRAWMAIN )
- X {
- X m_ellipse( x, mgr_y( y ),
- X radius, ( radius * gr_pxsize ) / gr_pysize );
- X }
- X else
- X {
- X m_ellipseto( screen, x, mgr_y( y ),
- X radius, ( radius * gr_pxsize ) / gr_pysize );
- X }
- X break;
- X }
- 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 > mgr_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 > mgr_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 > mgr_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 > mgr_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 return BW_ERROR;
- X }
- X
- /****************************************************************
- X
- X gr_font()
- X
- ****************************************************************/
- X
- gr_font( screen, type, rq_height )
- X int screen;
- X int type, rq_height;
- X {
- X static int x_fontno;
- X
- X if ( rq_height > 18 )
- X {
- X x_fontno = MGR_FONT4;
- X mgr_grwind->fysize = 20;
- X mgr_grwind->fxsize = 12;
- X }
- X else if ( rq_height > 15 )
- X {
- X x_fontno = MGR_FONT3;
- X mgr_grwind->fysize = 16;
- X mgr_grwind->fxsize = 8;
- X }
- X else if ( rq_height > 13 )
- X {
- X x_fontno = MGR_FONT2;
- X mgr_grwind->fysize = 14;
- X mgr_grwind->fxsize = 7;
- X }
- #ifdef TINYFONT
- X else if ( rq_height > 9 )
- X {
- X x_fontno = MGR_FONT1;
- X mgr_grwind->fysize = 12;
- X mgr_grwind->fxsize = 6;
- X }
- X else
- X {
- X x_fontno = MGR_FONT0;
- X mgr_grwind->fysize = 7;
- X mgr_grwind->fxsize = 4;
- X }
- #else
- X else
- X {
- X x_fontno = MGR_FONT1;
- X mgr_grwind->fysize = 12;
- X mgr_grwind->fxsize = 6;
- X }
- #endif
- X
- X mgr_curspark(); /* get cursor out of the way */
- X m_font( x_fontno );
- 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
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > mgr_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 > mgr_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 > mgr_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 > mgr_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 == dst )
- X {
- X return BW_ERROR;
- X }
- X
- X m_func( B_SRC );
- X m_bitcopyto( x1, mgr_y( y2 ), x2 - x1, y2 - y1,
- X x1, mgr_y( y2 ), dst, src );
- 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
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > mgr_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 > mgr_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 > mgr_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 > mgr_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 if ( mode == TRUE )
- X {
- X *image = mgr_getbno(); /* assign a number */
- X
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nDEBUG: Window number is %d", *i );
- X kb_rx();
- #endif
- X
- X m_bitcreate( *image, abs( x2 - x1 ), abs( y2 - y1 ) );
- X
- X m_func( B_SRC );
- X m_bitcopyto( x1, mgr_y( y2 ),
- X abs( x2 - x1 ), abs( y2 - y1 ),
- X x1, mgr_y( y2 ), *image, MGR_DRAWMAIN );
- X }
- X else
- X {
- #ifdef OLD_DEBUG
- X fprintf( stderr, "\nDEBUG: Window number is %d", *image );
- X kb_rx();
- #endif
- X m_func( B_SRC );
- X m_bitcopyto( x1, mgr_y( y2 ),
- X abs( x2 - x1 ), abs( y2 - y1 ),
- X x1, mgr_y( y2 ), MGR_DRAWMAIN, *image );
- X }
- X }
- X
- /****************************************************************
- X
- X gr_imfree()
- X
- ****************************************************************/
- X
- gr_imfree( image )
- X int image;
- X {
- X m_bitdestroy( image );
- 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 m_pending = FALSE, x_save, y_save;
- X static int m_prevr;
- X int c, r;
- X
- X switch( mode )
- X {
- X case SAMPLE:
- X if ( m_pending == TRUE )
- X {
- X *x = x_save;
- X *y = y_save;
- X return TRUE;
- X }
- X r = mgr_mouse( x, y );
- X *y = mgr_y( *y );
- X if ( r == TRUE )
- X {
- X m_pending = TRUE;
- X x_save = *x;
- X y_save = *y;
- X }
- X return r;
- X break;
- X case WAIT:
- X if ( m_pending == TRUE )
- X {
- X m_pending = FALSE;
- X *x = x_save;
- X *y = y_save;
- X return TRUE;
- X }
- X c = FALSE;
- X while( c == FALSE )
- X {
- X c = r = mgr_mouse( x, y );
- X *y = mgr_y( *y );
- X }
- X m_pending = FALSE;
- X m_prevr = r;
- X return TRUE;
- X break;
- X default:
- #ifdef DEBUG
- X sprintf( bw_ebuf, "gr_mouse() received mode %d", mode );
- X bw_error( bw_ebuf );
- #endif
- X return BW_ERROR;
- X break;
- X }
- X
- X }
- X
- mgr_mouse( x, y )
- X int *x, *y;
- X {
- X static int r = 0, x_prevr = 0;
- X
- X r = get_mouse( x, y );
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "r = %d", r );
- X gr_text( GR_PRIMARY, 12, 12, bw_ebuf, WHITE, BLACK );
- #endif
- X if ( r == x_prevr )
- X {
- X return FALSE;
- X }
- X x_prevr = r;
- X return TRUE;
- X }
- X
- mgr_y( oldyval )
- X int oldyval;
- X {
- X return (( mgr_grwind->ymax ) - oldyval );
- X }
- X
- mgr_color( color )
- X int color;
- X {
- X if ( color == WHITE )
- X {
- X m_func( B_SET );
- X }
- X else
- X {
- X m_func( B_CLEAR );
- X }
- X }
- X
- mgr_getbno()
- X {
- X static int x = MGR_DRAWSTART;
- X
- X ++x;
- X return x;
- X }
- X
- mgr_curspark()
- X {
- X m_movecursor( 0, 85 );
- X }
- X
- SHAR_EOF
- echo 'File io/gr/gr_mgr.c is complete' &&
- chmod 0644 io/gr/gr_mgr.c ||
- echo 'restore of io/gr/gr_mgr.c failed'
- Wc_c="`wc -c < 'io/gr/gr_mgr.c'`"
- test 23877 -eq "$Wc_c" ||
- echo 'io/gr/gr_mgr.c: original size 23877, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/gr/gr_spec.c ==============
- if test -f 'io/gr/gr_spec.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/gr/gr_spec.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/gr/gr_spec.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_spec.c' &&
- /****************************************************************
- X
- X gr_spec.c Specification of Graphics Interface
- X for Space Flight Simulator
- 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 This file specifies the interface for graphics and mouse
- X handling utilized in the Space Flight Simulator. This file
- X may be utilized as the basis for implementations of gr and
- X thus of sfs on varied computers. If you can implement the
- X functions specified in this file, sfs should be implemented.
- X
- X COORDINATE SYSTEM. The gr interface presupposes throughout
- X a Cartesian coordinate system in which pixels on the vertical
- X axis (the y axis) are numbered beginning with 0 from the
- X bottom up, and pixels on the horizontal axis (the x axis)
- X are numbered beginning with 0 from the ;eft to the right.
- X The numbering of the y axis may seem counterintuitive,
- X since in many systems pixels are numbered vertically from
- X the top to the bottom.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- #include "gr.h"
- X
- int gr_colors; /* number of colors available */
- int gr_pxsize; /* relative size of pixel, horizontal */
- int gr_pysize; /* relative size of pixel, vertical */
- int gr_ismouse; /* boolean -- does mouse exist? */
- int gr_clipping; /* boolean -- is clipping implemented? */
- int gr_blitting; /* boolean -- is blitting implemented? */
- int gr_saving; /* boolean -- is screen saving implemented? */
- int gr_screens; /* number of screens, 1 = visible screen
- X (GR_PRIMARY) only, 2 = visible and
- X hidden screen (GR_PRIMARY and GR_HIDDEN)
- X are available */
- X
- /****************************************************************
- X
- X gr_init()
- X
- X This function should initialize the entire graphics and mouse
- X subsystem. The argument "grwindow" is a pointer to a gr_window
- X structure which should be filled in by the function. The
- X argument "font_path" is a pointer to a character string
- X giving the name of a path where the function should look
- X for font and other data files. The function should return
- X BW_ERROR upon any error and TRUE upon a successful setting
- X of the graphics subsystem.
- X
- ****************************************************************/
- X
- gr_init( grwindow, font_path )
- X struct gr_window *grwindow;
- X char * font_path;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_deinit()
- X
- X This function should deinitialize the entire graphics subsystem.
- X
- ****************************************************************/
- X
- gr_deinit()
- X {
- X }
- X
- /****************************************************************
- X
- X gr_cls()
- X
- X This function should clear the entire screen area.
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- ****************************************************************/
- X
- gr_cls( screen )
- X int screen;
- X {
- X }
- X
- X
- /****************************************************************
- X
- X gr_pixel()
- X
- X This function turns on (or off, if the color is BLACK) a single
- X pixel on the display.
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The arguments x and y specify a pixel location on the screen
- X in gr coordinates (see above on the coordinate system) where
- X the pixel is to be located, x on the horizontal axis and y
- X on the vertical axis.
- X
- X The argument "color" is an integer denoting a color defined
- X in the header "gr.h".
- X
- ****************************************************************/
- X
- gr_pixel( screen, x, y, color )
- X int screen;
- X int x, y;
- X int color;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_line()
- X
- X This function draws a line on the designated screen from
- X point x1, y1 to point x2, y2 in a specified color and
- X with a specified style.
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The arguments x1, y1, x2, and y2 specify two pixel locations
- X on the screen in gr coordinates (see above on the coordinate
- X system) denoting the source (x1, y1) and destination (x2, y2)
- X points for the line (x1 and x2 on the horizontal axis, and y1
- X and y2 on the vertical axis.
- X
- X The argument "color" is an integer denoting a color defined
- X in the header "gr.h".
- X
- X The argument "style" is an integer denoting a line style
- X defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- GRID
- X and HATCH denote dotted lines, and HOLLOW erases the area
- X of the 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 }
- X
- /****************************************************************
- X
- X gr_text()
- X
- X This function addresses text to a specified location on the
- X screen in specified colors.
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The arguments x and y specify a pixel location on the screen
- X in gr coordinates (see above on the coordinate system) where
- X the bottom left corner of the text is to be located, x on the
- X horizontal axis and y on the vertical axis.
- X
- X The argument "string" designates a pointer to a character
- X string to be written to the screen.
- X
- X The arguments "foreground" and "background" are integers
- X denoting text foreground and background colors as defined
- X in the header "gr.h".
- 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 }
- X
- /****************************************************************
- X
- X gr_strlen()
- X
- X This function returns the length in pixels on the horizontal
- X (x) axis of a specified character string.
- X
- X The argument "string" designates a pointer to a character
- X string whose horizontal size is to be calculated.
- X
- ****************************************************************/
- X
- unsigned int
- gr_strlen( string )
- X char *string;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_rectangle()
- X
- X This function draws and possibly fills in (or blanks) a
- X rectangular area of the screen.
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The arguments x1, y1, x2, and y2 specify two pixel locations
- X on the screen in gr coordinates (see above on the coordinate
- X system) denoting the bottom left corner (x1, y1) and top right
- X corner (x2, y2) of the rectangle (x1 and x2 on the horizontal
- X axis, and y1 and y2 on the vertical axis).
- X
- X The argument "color" is an integer denoting a color defined
- X in the header "gr.h".
- X
- X The argument "style" is an integer denoting a fill style
- X defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
- X means that only a perimeter is drawn; SOLID means that the
- X area is completely filled with the color, and GRID and HATCH
- X represent varying degrees of partial fill, with GRID the finer
- X and HATCH the rougher).
- 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 }
- X
- /****************************************************************
- X
- X gr_circle()
- X
- X This function draws and possibly fills in (or blanks) a
- X circular area of the screen.
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The arguments x and y specify a pixel location on the screen
- X in gr coordinates (see above on the coordinate system) where
- X the center of the circle is to be located, x on the horizontal
- X axis and y on the vertical axis.
- X
- X The argument "radius" is an integer denoting the radius of the
- X circle on the y (vertical) axis. Implementers should note that
- X the x (horizontal) axis will have to be scaled.
- X
- X The argument "color" is an integer denoting a color defined
- X in the header "gr.h".
- X
- X The argument "style" is an integer denoting a fill style
- X defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
- X means that only a perimeter is drawn; SOLID means that the
- X area is completely filled with the color, and GRID and HATCH
- X represent varying degrees of partial fill, with GRID the finer
- X and HATCH the rougher).
- X
- ****************************************************************/
- X
- gr_circle( screen, x, y, radius, color, style )
- X int screen;
- X int x, y, radius;
- X int color, style;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_ellipse()
- X
- X This function is NOT CURRENTLY USED in any Bywater applications
- X so it's here basically for future development.
- X
- X This function draws and possibly fills in (or blanks) an
- X elliptical area of the screen.
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The arguments x and y specify a pixel location on the screen
- X in gr coordinates (see above on the coordinate system) where
- X the center of the ellipse is to be located, x on the horizontal
- X axis and y on the vertical axis.
- X
- X The arguments "x_radius" and "y_radius" specify the horizontal
- X and vertical sizes, respectively, of the bounding rectangle
- X of the ellipse.
- X
- X The argument "color" is an integer denoting a color defined
- X in the header "gr.h".
- X
- X The argument "style" is an integer denoting a fill style
- X defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
- X means that only a perimeter is drawn; SOLID means that the
- X area is completely filled with the color, and GRID and HATCH
- X represent varying degrees of partial fill, with GRID the finer
- X and HATCH the rougher).
- 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 If clipping is implemented (gr_clipping == TRUE), this
- X function turns on or off clipping for a specified area
- X of the screen.
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The argument "mode" is a boolean integer which tells whether
- X clipping is to be turned on (TRUE) or off (FALSE).
- X
- X The arguments x1, y1, x2, and y2 specify two pixel locations
- X on the screen in gr coordinates (see above on the coordinate
- X system) denoting the bottom left corner (x1, y1) and top right
- X corner (x2, y2) of the clipping rectangle (x1 and x2 on the
- X horizontal axis, and y1 and y2 on the vertical axis).
- X
- ****************************************************************/
- X
- gr_clip( screen, mode, x1, y1, x2, y2 )
- X int screen;
- X int mode;
- X int x1, y1, x2, y2;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_font()
- X
- X This function sets a font for future calls to gr_text().
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The argument "type" is an integer value (not currently
- X implemented in applications by Bywater Software) which would
- X denote a font type (these are defined in "gr.h" as F_DEFAULT,
- X F_ROMAN, F_ITALIC, and F_GOTHIC). Don't worry about it.
- X
- X The argument "rq_height" is an integer value denoting the
- X requested height of the new font in pixels. The function should
- X set the closest available height and then denote the size of
- X the new font in the fysize variable in the gr_display structure.
- X
- ****************************************************************/
- X
- gr_font( screen, type, rq_height )
- X int screen;
- X int type, rq_height;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_blit()
- X
- X This function "blits" (copies) a rectangular area of the screen
- X from GR_PRIMARY to GR_HIDDEN or vice versa (if blitting is
- X implemented, i.e., gr_blitting == TRUE).
- X
- X The arguments "src" and "dst" are integers denoting either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN). Obviously, one should be set to GR_PRIMARY and
- X one to GR_HIDDEN. "src" denotes the source of the blit, and
- X "dst" the destination.
- X
- X The arguments x1, y1, x2, and y2 specify two pixel locations
- X on the screen in gr coordinates (see above on the coordinate
- X system) denoting the bottom left corner (x1, y1) and top right
- X corner (x2, y2) of the area to be blitted (x1 and x2 on the
- X horizontal axis, and y1 and y2 on the vertical axis).
- X
- ****************************************************************/
- X
- gr_blit( src, dst, x1, y1, x2, y2 )
- X int src, dst;
- X int x1, y1, x2, y2;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_imsave()
- X
- X This function either saves a rectangluar area of the screen to
- X a memory buffer (mode == TRUE), or restores a rectangular screen
- X area from the buffer (mode == FALSE). It should free existing memory
- X when mode == FALSE (thus, the area cannot be restored more than once).
- X
- X The argument "screen" is an integer denoted either the
- X visible screen (defined as GR_PRIMARY) or a hidden buffer
- X to which graphics output can be written (defined as
- X GR_HIDDEN).
- X
- X The arguments x1, y1, x2, and y2 specify two pixel locations
- X on the screen in gr coordinates (see above on the coordinate
- X system) denoting the bottom left corner (x1, y1) and top right
- X corner (x2, y2) of the rectangular area to be saved (x1 and x2
- X on the horizontal axis, and y1 and y2 on the vertical axis).
- X
- X The argument "image" is an integer denoting the specific
- X image that has been (or is to be) stored.
- 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 }
- X
- /****************************************************************
- X
- X gr_imfree()
- X
- ****************************************************************/
- X
- gr_imfree( image )
- X int image;
- X {
- X }
- X
- /****************************************************************
- X
- X gr_mouse()
- X
- X This function either tells if a mouse button has been pushed
- X (mode == SAMPLE or STATUS) or waits for a button to be pushed
- X (mode == WAIT).
- X
- X The arguments x and y are integer pointers to be filled with a
- X screen location in gr coordinates (see above on the coordinate
- X system) where the mouse is currently located, x on the horizontal
- X axis and y on the vertical axis.
- X
- X The argument "buttons" is an integer pointer which some great
- X day will be used to specify which of the mouse buttons has been
- X pushed but it hasn't been used yet in any Bywater applications
- X so don't worry about it.
- X
- ****************************************************************/
- X
- gr_mouse( mode, x, y, buttons )
- X int mode;
- X int *x, *y;
- X int *buttons;
- X {
- X }
- X
- SHAR_EOF
- chmod 0644 io/gr/gr_spec.c ||
- echo 'restore of io/gr/gr_spec.c failed'
- Wc_c="`wc -c < 'io/gr/gr_spec.c'`"
- test 17026 -eq "$Wc_c" ||
- echo 'io/gr/gr_spec.c: original size 17026, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/gr/gr_tam.c ==============
- if test -f 'io/gr/gr_tam.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/gr/gr_tam.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/gr/gr_tam.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_tam.c' &&
- /****************************************************************
- X
- X gr_tam.c implementation of Bywater graphics
- X standard for AT&T Unix PC using
- X tam() and wrastop() libraries
- 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 This file specifies the interface for graphics and mouse
- X handling utilized in the Space Flight Simulator. This file
- X may be utilized as the basis for implementations of gr and
- X thus of sfs on varied computers. If you can implement the
- X functions specified in this file, sfs should be implemented.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- #include "fcntl.h"
- #include "tam.h"
- #include "kcodes.h"
- #include "message.h"
- #include "errno.h"
- #include "sys/window.h"
- #include "sys/font.h"
- #include "gr.h"
- #include "bw.h"
- X
- static struct fntdef *tam_fsmall; /* ptr to small fntdef struct */
- static struct fntdef *tam_fmed; /* ptr to medium fntdef struct */
- static struct fntdef *tam_flarge; /* ptr to large fntdef struct */
- static struct fntdef *tam_fhuge; /* ptr to huge fntdef struct */
- static struct fntdef *tam_fdef; /* ptr to selected fntdef struct */
- X
- #define IMAGES 64
- #define FULLSCREEN FALSE
- #define CHECK_PARAMS TRUE
- #define SMALLFONT "/usr/lib/wfont/smallfont"
- #define MEDFONT "/usr/lib/wfont/system.8.ft"
- #define LARGEFONT "/usr/lib/wfont/PLAIN.R.E.18.A"
- #define HUGEFONT "/usr/lib/wfont/PLAIN.R.E.24.A"
- #define ADD_SIZE 1
- #define ADD_HIDDEN 2
- #define WRITE_OUTPUT FALSE
- X
- int gr_colors = 2;
- int gr_pxsize = 287;
- int gr_pysize = 428;
- int gr_ismouse = TRUE;
- int gr_clipping = FALSE;
- int gr_blitting = TRUE;
- int gr_saving = TRUE;
- int gr_screens = 2;
- X
- int w, w_id;
- static unsigned short tam_pixel[ 2 ] = { 0xffff, 0xffff };
- static struct gr_window *grwind;
- static unsigned short *tam_selected;
- static unsigned short *tam_hidden;
- int tam_mready = FALSE; /* is mouse input ready */
- int tam_mx, tam_my; /* mouse position x, y */
- char *tam_images[ IMAGES ]; /* array of pointers to image buffers */
- X
- extern unsigned short patblack[];
- extern unsigned short patwhite[];
- extern unsigned short patgray[];
- extern unsigned short patltgray[];
- X
- extern char * malloc();
- extern unsigned short tam_words();
- extern long tam_imsize();
- X
- #ifdef WRITE_OUTPUT
- extern FILE *outfile;
- #endif
- X
- /****************************************************************
- X
- X gr_init()
- X
- ****************************************************************/
- X
- gr_init( grwindow, font_path )
- X struct gr_window *grwindow;
- X char * font_path;
- X {
- X static struct uwdata uw;
- X static struct umdata um;
- X register int i;
- X int r;
- X
- X grwind = grwindow;
- X
- X close( 0 );
- X close( 1 );
- X close( 2 );
- X w_id = open( "/dev/window", O_RDWR );
- X dup( w_id );
- X dup( w_id );
- X
- X winit();
- X
- #if FULLSCREEN
- X w = wcreate( 1, 0, 24, 80, NBORDER );
- #else
- X w = wcreate( 2, 2, 19, 70, BORDCANCEL );
- #endif
- X wuser( w, "Bywater GR Implementation" );
- X wlabel( w, "Bywater GR Implementation" );
- X wprintf( w, "\033[=1C" );
- X clear();
- X
- X ioctl( w, WIOCGETD, &uw );
- X
- X grwindow->xmax = uw.uw_width - 1;
- X grwindow->ymax = uw.uw_height - 1;
- X grwindow->initialized = TRUE;
- X grwindow->font = F_DEFAULT;
- X
- X tam_readfont( SMALLFONT, &tam_fsmall );
- X tam_readfont( MEDFONT, &tam_fmed );
- X tam_readfont( LARGEFONT, &tam_flarge );
- X tam_readfont( HUGEFONT, &tam_fhuge );
- X
- X if ( tam_fmed == NULL )
- X {
- X fprintf( stderr, "ERROR: failed to load system font.\n" );
- X wgetc( w );
- X wexit( 1 );
- X }
- X
- X tam_fdef = tam_fmed;
- X grwindow->fysize = tam_fdef->ff_vs;
- X grwindow->fxsize = tam_fdef->ff_hs;
- X
- X if ( ( tam_hidden = (unsigned short *)
- X malloc( tam_imsize( 0, 0,
- X grwind->xmax + ADD_HIDDEN, grwind->ymax + ADD_HIDDEN ) )) == NULL )
- X {
- X fprintf( stderr, "Failed to find memory for gr_hidden\n" );
- X return -1;
- X }
- X
- #ifdef OLD_DEBUG
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "test wrastop(): tam_hidden %08lx\n",
- X (long) tam_hidden );
- X kb_rx();
- #endif
- X
- #ifdef OLD_DEBUG
- X gr_text( GR_PRIMARY, 0, 0, " !\"#", WHITE, BLACK );
- #endif
- X
- X /* set image buffer pointers to NULL */
- X
- X for ( i = 0; i < IMAGES; ++i )
- X {
- X tam_images[ i ] = NULL;
- X }
- X
- X um.um_flags = MSDOWN | MSUP;
- X um.um_icon = NULL;
- X r = wsetmouse( w, &um );
- X
- X if ( r == -1 )
- X {
- X fprintf( stderr, "Setmouse() returned -1\n" );
- X kb_rx();
- X }
- X
- X return TRUE;
- X }
- X
- /****************************************************************
- X
- X gr_deinit()
- X
- ****************************************************************/
- X
- gr_deinit( screen )
- X int screen;
- X {
- X wdelete( w );
- X wexit( 0 );
- X }
- X
- /****************************************************************
- X
- X gr_cls()
- X
- ****************************************************************/
- X
- gr_cls( screen )
- X int screen;
- X {
- X
- X if ( screen == GR_PRIMARY )
- X {
- X clear();
- X }
- X else
- X {
- X gr_rectangle( screen, 0, 0, grwind->xmax, grwind->ymax,
- X BLACK, SOLID );
- X }
- 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 int r;
- X
- #if CHECK_PARAMS
- 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 tam_setscreen( screen );
- X
- X r = wrastop( w, tam_pixel, (unsigned short) 2,
- X tam_selected, tam_words( grwind->xmax + ADD_HIDDEN ),
- X (unsigned short) 0, (unsigned short) 0,
- X (unsigned short) x,
- X (unsigned short) ( grwind->ymax - y ),
- X (unsigned short) ADD_SIZE, (unsigned short) ADD_SIZE,
- X SRCSRC, DSTOR, (unsigned short *) 0 );
- X
- #ifdef DEBUG
- X if ( r == -1 )
- X {
- X fprintf( stderr, "gr_pixel(): wrastop() failed, error %d.\n", errno );
- X kb_rx();
- X }
- #endif
- 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
- #if CHECKPARAMS
- 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 if ( x1 == x2 )
- X {
- X gr_rectangle( screen, x1, y1, x2, y2, color, style );
- X }
- X else if ( y1 == y2 )
- X {
- X gr_rectangle( screen, x1, y1, x2, y2, color, style );
- X }
- X else
- X {
- X def_line( screen, x1, y1, x2, y2, color, style );
- X }
- 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 char *s;
- X unsigned short c;
- X char *m;
- X register unsigned int x_pos;
- #ifdef DEBUG
- X static int do_it = 0;
- #endif
- X
- #if CHECK_PARAMS
- 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 tam_setscreen( screen );
- X
- X s = string;
- X x_pos = x;
- X while ( *s != 0 )
- X {
- X c = *s - 32;
- X m = (char *) &(tam_fdef->ff_fc[ c ].fc_mr)
- X + ( tam_fdef->ff_fc[ c ].fc_mr );
- X
- X if ( ( *s > 31 ) && ( *s < 129 ))
- X {
- X if ( ( x_pos + tam_fdef->ff_hs ) >= grwind->xmax )
- X {
- X return BW_ERROR;
- X }
- X tam_char( screen, x_pos, y, m,
- X tam_fdef->ff_fc[ c ].fc_hs,
- X tam_fdef->ff_fc[ c ].fc_vs,
- X foreground, background, (int) *s,
- X &(tam_fdef->ff_fc[ c ] ) );
- X x_pos += tam_fdef->ff_hs;
- X }
- X ++s;
- X }
- X }
- X
- /****************************************************************
- X
- X gr_strlen()
- X
- ****************************************************************/
- X
- unsigned int
- gr_strlen( string )
- X char *string;
- X {
- X char *s;
- X int size;
- X
- X s = string;
- X size = 0;
- X while ( *s != 0 )
- X {
- X size += tam_fdef->ff_hs;
- X ++s;
- X }
- X return size;
- 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 unsigned short *pattern;
- X int r;
- X
- #if CHECK_PARAMS
- 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 tam_setscreen( screen );
- X
- X switch ( style )
- X {
- X case HOLLOW:
- X def_rectangle( screen, x1, y1, x2, y2, color, style );
- X return TRUE;
- X break;
- X case SOLID:
- X if ( color == WHITE )
- X {
- X pattern = patwhite;
- X }
- X else
- X {
- X pattern = patblack;
- X }
- X break;
- X case GRID:
- X pattern = patgray;
- X break;
- X case HATCH:
- X pattern = patltgray;
- X break;
- X }
- X
- X r = wrastop( w, tam_pixel, (unsigned short) 2,
- X tam_selected, tam_words( grwind->xmax + ADD_HIDDEN ),
- X (unsigned short) 0, (unsigned short) 0,
- X (unsigned short) x1,
- X (unsigned short) ( grwind->ymax - y2 ),
- X (unsigned short) abs(x2 - x1) + ADD_SIZE,
- X (unsigned short) abs(y2 - y1) + ADD_SIZE,
- X SRCPAT, DSTSRC, pattern );
- X
- #ifdef DEBUG
- X if ( r == -1 )
- X {
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "gr_rectangle(): wrastop() failed, error %d, screen %d.\n",
- X errno, screen );
- X kb_rx();
- X }
- #endif
- 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
- #if CHECK_PARAMS
- 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 def_circle( screen, x, y, radius, color, style );
- 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 }
- X
- /****************************************************************
- X
- X gr_font()
- X
- ****************************************************************/
- X
- gr_font( screen, type, rq_height )
- X int screen;
- X int type, rq_height;
- X {
- X
- X if ( rq_height > 21 )
- X {
- X tam_fdef = tam_fhuge;
- X if ( tam_fdef > NULL )
- X {
- X grwind->fysize = tam_fdef->ff_vs;
- X grwind->fxsize = tam_fdef->ff_hs;
- X return TRUE;
- X }
- X }
- X else if ( rq_height > 14 )
- X {
- X tam_fdef = tam_flarge;
- X if ( tam_fdef > NULL )
- X {
- X grwind->fysize = tam_fdef->ff_vs;
- X grwind->fxsize = tam_fdef->ff_hs;
- X return TRUE;
- X }
- X }
- X else if ( rq_height > 9 )
- X {
- X tam_fdef = tam_fmed;
- X if ( tam_fdef > NULL )
- X {
- X grwind->fysize = tam_fdef->ff_vs;
- X grwind->fxsize = tam_fdef->ff_hs;
- X return TRUE;
- X }
- X }
- X else
- X {
- X tam_fdef = tam_fsmall;
- X if ( tam_fdef > NULL )
- X {
- X grwind->fysize = tam_fdef->ff_vs;
- X grwind->fxsize = tam_fdef->ff_hs;
- X return TRUE;
- X }
- X }
- X
- X tam_fdef = tam_fmed; /* default if all failed */
- X grwind->fysize = tam_fdef->ff_vs;
- X grwind->fxsize = tam_fdef->ff_hs;
- X return TRUE;
- 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 unsigned short *srcbase, *dstbase;
- X int r;
- X register int l;
- X
- #if CHECK_PARAMS
- 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_PRIMARY )
- X {
- X srcbase = (unsigned short *) NULL;
- X dstbase = tam_hidden;
- X r = wrastop( w, srcbase,
- X tam_words( abs( x2 - x1 ) + ADD_SIZE ),
- X dstbase, tam_words( grwind->xmax + ADD_HIDDEN ),
- X (unsigned short) x1,
- X (unsigned short) y1,
- X (unsigned short) x1,
- X (unsigned short) y1,
- X (unsigned short) abs(x2 - x1),
- X (unsigned short) abs(y2 - y1),
- X SRCSRC, DSTSRC, (unsigned short *) 0 );
- X
- #ifdef DEBUG
- X if ( r == -1 )
- X {
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "gr_blit(): wrastop() failed, error %d.\n", errno );
- X kb_rx();
- X }
- #endif
- X }
- X else
- X {
- X dstbase = (unsigned short *) NULL;
- X srcbase = tam_hidden;
- X
- #ifndef OLD_WAY
- X r = wrastop( w,
- X srcbase, tam_words( grwind->xmax + ADD_HIDDEN ),
- X dstbase, tam_words( grwind->xmax + ADD_HIDDEN ),
- X (unsigned short) x1,
- X (unsigned short) ( grwind->ymax - y2 ),
- X (unsigned short) x1,
- X (unsigned short) ( grwind->ymax - y2 ),
- X (unsigned short) abs(x2 - x1) + ADD_SIZE,
- X (unsigned short) abs(y2 - y1) + ADD_SIZE,
- X SRCSRC, DSTSRC, (unsigned short *) 0 );
- #else
- X for ( l = y1; l < y2; ++l )
- X {
- X r = wrastop( w,
- X srcbase, tam_words( grwind->xmax + ADD_HIDDEN ),
- X dstbase, tam_words( grwind->xmax + ADD_HIDDEN ),
- X (unsigned short) x1,
- X (unsigned short) ( grwind->ymax - l ),
- X (unsigned short) x1,
- X (unsigned short) ( grwind->ymax - l ),
- X (unsigned short) abs(x2 - x1) + ADD_SIZE,
- X (unsigned short) 1,
- X SRCSRC, DSTSRC, (unsigned short *) 0 );
- /* kb_rx(); */
- X }
- #endif
- X
- #ifdef DEBUG
- X if ( r == -1 )
- X {
- X wgoto( w, 0, 0 );
- X fprintf( stderr, "gr_blit(): wrastop() failed, error %d.\n", errno );
- X kb_rx();
- X }
- #endif
- X }
- X }
- X
- /****************************************************************
- X
- X tam_imsize()
- X
- ****************************************************************/
- X
- long
- tam_imsize( x1, y1, x2, y2 )
- X int x1, y1, x2, y2;
- X {
- X return ( sizeof( unsigned short)
- X * ( tam_words(abs(x2 - x1) + ADD_SIZE )
- X * ( abs(y2 - y1)) + ADD_SIZE ));
- 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 int r;
- X int carry_on;
- X
- #if CHECK_PARAMS
- X if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
- X {
- X sprintf( bw_ebuf, "[pr:] gr_imsave(): 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_imsave(): 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_imsave(): 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_imsave(): y2 value is %d", y2 );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- #endif
- X
- X tam_setscreen( screen );
- X
- X if ( mode == TRUE )
- X {
- X
- X
- X /* find an available buffer */
- X
- X carry_on = TRUE;
- X r = 0;
- X while( ( carry_on == TRUE ) && ( r < IMAGES ) )
- X {
- X if ( tam_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 /* get memory */
- X
- X if ( ( tam_images[ *image ] = malloc( (size_t) tam_imsize(
- X x1, grwind->ymax - y2,
- X x2, grwind->ymax - y1 ) ) ) == NULL )
- X {
- X bw_error( "Out of memory to store image" );
- X return FALSE;
- X }
- X
- X /* perform the save operation */
- X
- X r = wrastop( w, tam_selected,
- X tam_words( grwind->xmax + ADD_HIDDEN ),
- X (unsigned short *) tam_images[ *image ],
- X tam_words( abs(x2 - x1)),
- X (unsigned short) x1,
- X (unsigned short) ( grwind->ymax - y2 ),
- X (unsigned short) 0, (unsigned short) 0,
- 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 else
- X {
- X r = wrastop( w, (unsigned short *) tam_images[ *image ],
- X tam_words( abs(x2 - x1)),
- X tam_selected, tam_words( grwind->xmax + ADD_HIDDEN ),
- X (unsigned short) 0, (unsigned short) 0,
- X (unsigned short) x1,
- X (unsigned short) ( grwind->ymax - y2 ),
- SHAR_EOF
- true || echo 'restore of io/gr/gr_tam.c failed'
- fi
- echo 'End of part 3'
- echo 'File io/gr/gr_tam.c is continued in part 4'
- echo 4 > _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.
-