home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.2 KB | 2,038 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i009: sfs - Space Flight Simulator, Part09/21
- Message-ID: <1991Dec24.045505.194@sparky.imd.sterling.com>
- X-Md4-Signature: cea7f441b8b27559ebbe15c019dbc851
- Date: Tue, 24 Dec 1991 04:55:05 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 9
- Archive-name: sfs/part09
- 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_icon.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 9; 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_icon.c'
- else
- echo 'x - continuing file io/ui/ui_icon.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'io/ui/ui_icon.c' &&
- X TRUE );
- X
- X
- #ifdef USESMALLFONT
- X gr_font( ui_screen, m_box->save_font,
- X m_box->save_fysize );
- #endif
- X
- X }
- X
- X *item = m_box->current;
- X return EVENT_CHANGE;
- X break;
- X
- X case MO_SEL:
- X if ( ((( y_sel + m_box->y_start ) * m_box->x_logical )
- X + x_sel + m_box->x_start ) == m_box->current )
- X {
- X *item = m_box->current;
- X return EVENT_SELECTED;
- X }
- X else
- X {
- X
- #ifdef USESMALLFONT
- X m_box->save_font = ui_grwind->font;
- X m_box->save_fysize = ui_grwind->fysize;
- X gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
- #endif
- X
- X uii_icon( m_box, m_box->current, FALSE );
- X m_box->current = (( y_sel + m_box->y_start )
- X * m_box->x_logical )
- X + m_box->x_start + x_sel;
- X m_box->x_pos = x_sel;
- X m_box->y_pos = y_sel;
- X uii_icon( m_box, m_box->current, TRUE );
- X
- #ifdef USESMALLFONT
- X gr_font( ui_screen, m_box->save_font,
- X m_box->save_fysize );
- #endif
- X
- X }
- X *item = m_box->current;
- X return EVENT_CHANGE;
- X break;
- X
- X case MO_SRC:
- X
- X *item = (( y_sel + m_box->y_start ) * m_box->x_logical )
- X + m_box->x_start + x_sel;
- X return EVENT_SOURCE;
- X break;
- X
- X default:
- X *item = 0;
- X return EVENT_NULL;
- X break;
- X
- X }
- X }
- X
- /****************************************************************
- X
- X uii_source() Query if keyboard or mouse actions indicate a
- X source within a menu box
- X
- ****************************************************************/
- X
- uii_source( m_box, key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest, item )
- X struct menu_box *m_box;
- X int key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest;
- X int *item;
- X {
- X static int how_far, x_sel, y_sel;
- X int carry_on;
- X register int c;
- X
- X how_far = 0;
- X x_sel = 0;
- X y_sel = 0;
- X c = ui_event( m_box, key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest,
- X &how_far, &x_sel, &y_sel );
- X
- X if ( c == MO_SRC )
- X {
- X *item = (( y_sel + m_box->y_start ) * m_box->x_logical )
- X + m_box->x_start + x_sel;
- X return TRUE;
- X }
- X else
- X {
- X return FALSE;
- X }
- X }
- X
- /****************************************************************
- X
- X uii_display() Show all file icons
- X
- ****************************************************************/
- X
- uii_display( m_box )
- X struct menu_box *m_box;
- X {
- X register int c;
- X
- X /* blank the entire icon area */
- X
- X ui_fbox( m_box->i_x1, m_box->i_y1, m_box->i_x2, m_box->i_y2,
- X m_box->back, SOLID );
- X
- X /* attempt to show each icon */
- X
- X for ( c = 0; c < m_box->number; ++c )
- X {
- X uii_icon( m_box, c,
- X FALSE );
- X }
- X
- X /* show elevators */
- X
- X uil_vel( m_box, m_box->y_start ); /* show vertical elevator */
- X uil_hel( m_box, m_box->x_start ); /* show horizontal elevator */
- X
- X }
- X
- /****************************************************************
- X
- X uii_icon() Draw file icon
- X
- ****************************************************************/
- X
- uii_icon( m_box, n, selected )
- X int n, selected;
- X struct menu_box *m_box;
- X {
- X register int x, y;
- X int x1, y1, x2, y2, textxpos;
- X int restore_clip, clx1, cly1, clx2, cly2;
- X static char buf[ 20 ];
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "uii_icon() called; item %d ", n );
- X ui_wtitle( m_box->window, ui_tbuf );
- X ui_wait();
- #endif
- X
- X x = ( n % m_box->x_logical ) - m_box->x_start;
- X y = ( n / m_box->x_logical ) - m_box->y_start;
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "x = %d, y = %d", x, y );
- X ui_text( m_box->i_x1, m_box->i_y1, m_box->i_x2,
- X m_box->i_y2, 35, m_box->back, m_box->fore, ui_tbuf );
- X ui_wait();
- #endif
- X
- X if ( ( x < 0 ) || ( y < 0 ))
- X {
- X return FALSE;
- X }
- X
- X if ( ( x >= ( m_box->x_items + gr_clipping ))
- X || ( y >= ( m_box->y_items + gr_clipping )))
- X {
- X return FALSE;
- X }
- X
- X x1 = m_box->i_x1 + ( x * m_box->xsize );
- X y1 = m_box->i_y2 - ( ( 1 + y ) * m_box->ysize ) - 1;
- X x2 = m_box->i_x1 + ( ( 1 + x ) * m_box->xsize ) - 1;
- X y2 = m_box->i_y2 - ( y * m_box->ysize );
- X
- X /* see if cliiping is in effect */
- X
- X if ( ( gr_clipping == TRUE ) && ( ui_grwind->clipping == TRUE ))
- X {
- X restore_clip = TRUE;
- X clx1 = ui_grwind->cl_x1;
- X cly1 = ui_grwind->cl_y1;
- X clx2 = ui_grwind->cl_x2;
- X cly2 = ui_grwind->cl_y2;
- X }
- X else
- X {
- X restore_clip = FALSE;
- X }
- X
- X if ( gr_clipping == TRUE )
- X {
- X gr_clip( ui_screen, TRUE, m_box->i_x1, m_box->i_y1,
- X m_box->i_x2, m_box->i_y2 );
- X }
- X
- X /* blank the icon area */
- X
- X ui_fbox( x1, y1, x2, y2, m_box->back, SOLID );
- X
- X /* add two blanks if the name is small */
- X
- X if ( strlen( m_box->d_entries[ n ]->filename ) < 6 )
- X {
- X sprintf( buf, " %s ", m_box->d_entries[ n ]->filename );
- X }
- X else
- X {
- X strcpy( buf, m_box->d_entries[ n ]->filename );
- X }
- X
- X /* calculate centered text position */
- X
- X textxpos = ( x1 + ( m_box->xsize / 2 ))
- X - ( gr_strlen( buf ) / 2 );
- X
- X /* print the text */
- X
- X if ( selected == TRUE )
- X {
- X gr_text( ui_screen, textxpos, y1 + 2,
- X buf, m_box->back, m_box->fore );
- X }
- X else
- X {
- X gr_text( ui_screen, textxpos, y1 + 2,
- X buf, m_box->fore, m_box->back );
- X }
- X
- X /* increment y1 out of text area */
- X
- X y1 += ui_grwind->fysize;
- X
- X /* draw the icon */
- X
- X switch( m_box->d_entries[ n ]->type )
- X {
- X
- X case FILE_DIRECTORY:
- X uii_folder( x1, y1, x2, y2, m_box->fore );
- X break;
- X
- X case FILE_EXECUTABLE:
- X uii_exec( x1, y1, x2, y2, m_box->fore );
- X break;
- X
- X case FILE_NORMAL:
- X default:
- X uii_default( x1, y1, x2, y2, m_box->fore );
- X break;
- X }
- X
- X /* restore clipping or turn off clipping */
- X
- X if ( restore_clip == TRUE )
- X {
- X gr_clip( ui_screen, TRUE, clx1, cly1, clx2, cly2 );
- X }
- X else if ( gr_clipping == TRUE )
- X {
- X gr_clip( ui_screen, FALSE, 0, 0, 0, 0 );
- X }
- X }
- X
- /****************************************************************
- X
- X uii_default() Default (blank or generic) file icon
- X
- ****************************************************************/
- X
- uii_default( x1, y1, x2, y2, color )
- X int x1, y1, x2, y2, color;
- X {
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, x1, y1, x2, y2, &ui_deficon );
- #else
- X int x, y, y_center, x_center;
- X
- X /* calculate the center of the icon area */
- X
- X y_center = y1 + (( y2 - y1 ) / 2 );
- X x_center = x1 + (( x2 - x1 ) / 2 );
- X
- X /* calculate appropriate sizes for the icon */
- X
- X y = ( y2 - y1 ) / 3;
- X x = ((( y * gr_pysize ) / gr_pxsize ) * 3 ) / 4;
- X
- X /* draw the icon rectangle */
- X
- X gr_rectangle( ui_screen, x_center - x,
- X y_center - y,
- X x_center + x,
- X y_center + y, color, HOLLOW );
- X
- X /* draw demarking line across the top */
- X
- X gr_line( ui_screen, x_center - x, ( y_center + y ) - 3,
- X x_center + x, ( y_center + y ) - 3, color, SOLID );
- X
- #endif
- X
- X }
- X
- /****************************************************************
- X
- X uii_folder() File folder (directory) icon
- X
- ****************************************************************/
- X
- uii_folder( x1, y1, x2, y2, color )
- X int x1, y1, x2, y2, color;
- X {
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, x1, y1, x2, y2, &ui_foldicon );
- #else
- X int x, y, y_center, x_center;
- X
- X /* calculate the center of the icon area */
- X
- X y_center = y1 + (( y2 - y1 ) / 2 );
- X x_center = x1 + (( x2 - x1 ) / 2 );
- X
- X /* calculate appropriate sizes for the folder */
- X
- X y = ( y2 - y1 ) / 4;
- X x = ((( y * gr_pysize ) / gr_pxsize ) * 3 ) / 2;
- X
- X /* draw left side of folder */
- X
- X gr_line( ui_screen, x_center - x, y_center - y,
- X x_center - x, y_center + y, color, SOLID );
- X
- X /* draw bottom of folder */
- X
- X gr_line( ui_screen, x_center - x, y_center - y,
- X x_center + x, y_center - y, color, SOLID );
- X
- X /* draw right side of folder */
- X
- X gr_line( ui_screen, x_center + x, y_center - y,
- X x_center + x, y_center + y, color, SOLID );
- X
- X /* draw file tab (upper) */
- X
- X gr_line( ui_screen, x_center + x, y_center + y,
- X x_center + x - 4, y_center + y + 2, color, SOLID );
- X gr_line( ui_screen, x_center + x - 4, y_center + y + 2,
- X x_center + 4, y_center + y + 2, color, SOLID );
- X gr_line( ui_screen, x_center + 4, y_center + y + 2,
- X x_center, y_center + y, color, SOLID );
- X
- X /* draw top of folder (upper) */
- X
- X gr_line( ui_screen, x_center - x, y_center + y,
- X x_center, y_center + y, color, SOLID );
- X
- X /* draw file tab (lower) */
- X
- X gr_line( ui_screen, x_center + x, y_center + y - 4,
- X x_center + 4, y_center + y - 4, color, SOLID );
- X gr_line( ui_screen, x_center + 4, y_center + y - 4,
- X x_center, y_center + y - 2, color, SOLID );
- X
- X /* draw top of folder (lower) */
- X
- X gr_line( ui_screen, x_center - x, y_center + y - 2,
- X x_center, y_center + y - 2, color, SOLID );
- X
- #endif
- X
- X }
- X
- /****************************************************************
- X
- X uii_exec() Icon for executable files
- X
- ****************************************************************/
- X
- uii_exec( x1, y1, x2, y2, color )
- X int x1, y1, x2, y2, color;
- X {
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, x1, y1, x2, y2, &ui_exicon );
- #else
- X int x, y, y_center, x_center;
- X
- X /* calculate the center of the icon area */
- X
- X y_center = y1 + (( y2 - y1 ) / 2 );
- X x_center = x1 + (( x2 - x1 ) / 2 );
- X
- X /* calculate appropriate sizes for the icon */
- X
- X y = ( y2 - y1 ) / 4;
- X x = ( y * gr_pysize ) / gr_pxsize;
- X
- X /* draw the icon rectangle */
- X
- X gr_rectangle( ui_screen, x_center - x,
- X y_center - y,
- X x_center + x,
- X y_center + y, color, HOLLOW );
- X
- X /* show circle to indicate executable */
- X
- X gr_circle( ui_screen, x_center, y_center,
- X y / 3, color, GRID );
- X
- #endif
- X
- X }
- X
- SHAR_EOF
- echo 'File io/ui/ui_icon.c is complete' &&
- chmod 0644 io/ui/ui_icon.c ||
- echo 'restore of io/ui/ui_icon.c failed'
- Wc_c="`wc -c < 'io/ui/ui_icon.c'`"
- test 31158 -eq "$Wc_c" ||
- echo 'io/ui/ui_icon.c: original size 31158, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/ui/ui_init.c ==============
- if test -f 'io/ui/ui_init.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/ui/ui_init.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/ui/ui_init.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_init.c' &&
- /****************************************************************
- X
- X ui_init.c Initialization 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 "gr.h"
- #include "kb.h"
- #include "dr.h"
- #include "ui.h"
- X
- #ifdef __STDC__
- #include "stdlib.h"
- #else
- extern char *getenv();
- #endif
- X
- static struct gr_window ui_fullscreen;
- char ui_tbuf[ 128 ];
- int ui_screen = GR_PRIMARY;
- int x_savescreen;
- struct gr_window *ui_grwind;
- char ui_ready = 0;
- char ui_fontpath[ 128 ];
- struct pbm_struct ui_elicon; /* elevator icon */
- struct pbm_struct ui_lefticn; /* left icon */
- struct pbm_struct ui_righticn; /* right icon */
- struct pbm_struct ui_upicn; /* up icon */
- struct pbm_struct ui_downicn; /* down icon */
- struct pbm_struct ui_clicon; /* close window icon */
- struct pbm_struct ui_reicon; /* resize window icon */
- struct pbm_struct ui_mvicon; /* move window icon */
- struct pbm_struct ui_deficon; /* default file icon */
- struct pbm_struct ui_foldicon; /* file folder icon */
- struct pbm_struct ui_exicon; /* executable file icon */
- X
- ui_init()
- X {
- X char *pp; /* temp path pointer */
- X
- X /* See if BWPATH variable is set */
- X
- X if ( ( pp = getenv( BWENVARNAME ) ) != NULL )
- X {
- X sprintf( ui_fontpath, "%s%c", pp, dr_fs );
- X }
- X
- X /* Initialize the screen and keyboard */
- X
- X gr_init( &ui_fullscreen, ui_fontpath );
- X kb_init();
- X
- X gr_font( GR_PRIMARY, F_DEFAULT,
- X ui_fullscreen.ymax / DEFAULT_FONT_SIZE );
- X
- X ui_grwind = &ui_fullscreen;
- X ui_setscreen( GR_PRIMARY );
- X
- X ui_ready = TRUE;
- X
- X /* initialize icons */
- X
- X ui_seticons( BLACK, WHITE );
- X
- X }
- X
- ui_setscreen( screen )
- X int screen;
- X {
- X ui_screen = screen;
- X }
- X
- ui_push()
- X {
- X x_savescreen = ui_screen;
- X }
- X
- ui_pop()
- X {
- X ui_screen = x_savescreen;
- X }
- X
- ui_seticons( foreground, background )
- X int foreground, background;
- X {
- X
- X ui_pbmread( "elevator.pbm", &ui_elicon, background, foreground );
- X ui_pbmread( "left.pbm", &ui_lefticn, foreground, background );
- X ui_pbmread( "right.pbm", &ui_righticn, foreground, background );
- X ui_pbmread( "up.pbm", &ui_upicn, foreground, background );
- X ui_pbmread( "down.pbm", &ui_downicn, foreground, background );
- X ui_pbmread( "close.pbm", &ui_clicon, foreground, background );
- X ui_pbmread( "resize.pbm", &ui_reicon, foreground, background );
- X ui_pbmread( "move.pbm", &ui_mvicon, foreground, background );
- X ui_pbmread( "default.pbm", &ui_deficon, foreground, background );
- X ui_pbmread( "folder.pbm", &ui_foldicon, foreground, background );
- X ui_pbmread( "exec.pbm", &ui_exicon, foreground, background );
- X
- X }
- SHAR_EOF
- chmod 0644 io/ui/ui_init.c ||
- echo 'restore of io/ui/ui_init.c failed'
- Wc_c="`wc -c < 'io/ui/ui_init.c'`"
- test 3779 -eq "$Wc_c" ||
- echo 'io/ui/ui_init.c: original size 3779, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/ui/ui_list.c ==============
- if test -f 'io/ui/ui_list.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/ui/ui_list.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/ui/ui_list.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_list.c' &&
- /***************************************************************
- X
- X ui_list.c List (Menu) Routines
- X for 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 "kb.h"
- #include "dr.h"
- #include "ui.h"
- X
- #define EXTENSION 1 /* number of pixels to extend
- X size of each menu item beyond
- X the height of the text */
- #define EL_OFFSET 1
- #define ACC 20
- #define SL_YSIZE 3
- #define SL_XMAX 18
- X
- /****************************************************************
- X
- X ui_ftext() File selection -- text based
- X
- ****************************************************************/
- X
- ui_ftext( x1, y1, x2, y2, specifier, title, m_box,
- X d_titles, d_entries, max_entries,
- X background, foreground, highlight )
- X int x1, y1, x2, y2, background, foreground, highlight, max_entries;
- X struct menu_box *m_box;
- X char *specifier, *title;
- X char **d_titles;
- X struct dir_ent **d_entries;
- X {
- X register int number, c;
- X
- X /* First check for existence of the file */
- X
- X number = 0;
- X if ( dr_first( specifier, d_entries[ number ] ) == FALSE )
- X {
- X return FALSE;
- X }
- X strcpy( d_titles[ number ], d_entries[ number ]->filename );
- X
- X /* Find all entries */
- X
- X number = 1;
- X while( ( dr_next( d_entries[ number ] ) == TRUE ) && ( number < max_entries ))
- X {
- X strcpy( d_titles[ number ], d_entries[ number ]->filename );
- X ++number;
- X }
- X m_box->number = number;
- X
- X m_box->d_titles = d_titles;
- X m_box->d_entries = d_entries;
- X m_box->max_entries = max_entries;
- X
- X /* menu */
- X
- X c = ui_list( MENU_SLIDERS, x1, y1, x2, y2,
- X title, number, d_titles, foreground, background, highlight,
- X m_box, TRUE );
- X
- X return c;
- X
- X }
- X
- /****************************************************************
- X
- X ui_list() Scrolling list (menu)
- X
- ****************************************************************/
- X
- ui_list( type, x1, y1, x2, y2, title, number, titles,
- X foreground, background, highlight, m_box )
- X int type, x1, y1, x2, y2, foreground, background,
- X highlight, number;
- X char *title;
- X char **titles;
- X struct menu_box *m_box;
- X {
- X int carry_on;
- X static int c, test;
- X int mo_xsrc, mo_ysrc;
- X static int x_pos, y_pos, b_stat, item;
- X
- X /* draw the list */
- X
- X uil_draw( type, x1, y1, x2, y2, title, number, titles,
- X foreground, background, highlight, m_box );
- X
- X /* activate the list */
- X
- X uil_activate( m_box, type, 0 );
- X
- X /* poll while waiting for keyboard or mouse input, carry_on == TRUE */
- X
- X test = FALSE;
- X carry_on = TRUE;
- X while( carry_on == TRUE )
- X {
- X if ( kb_rxstat() == TRUE )
- X {
- X c = kb_rx();
- X test = TRUE;
- X }
- X else if ( gr_ismouse == TRUE )
- X {
- X if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat )
- X == TRUE )
- X {
- X c = 0;
- X test = TRUE;
- X gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
- X mo_xsrc = x_pos;
- X mo_ysrc = y_pos;
- X gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
- X }
- X }
- X
- X if ( test == TRUE )
- X {
- #ifdef OLD_DEBUG
- X bw_error( "ready to call uil_event()" );
- #endif
- X c = uil_event( m_box, c, mo_xsrc, mo_ysrc, x_pos, y_pos, type,
- X &item );
- X switch( c )
- X {
- X case EVENT_SELECTED:
- X carry_on = FALSE;
- X break;
- X case EVENT_EXIT:
- X item = TK_EXIT;
- X carry_on = FALSE;
- X break;
- X case EVENT_ERROR:
- X bw_error( "Error return from uil_event()" );
- X carry_on = FALSE;
- X break;
- X case EVENT_NULL:
- X default:
- X test = FALSE;
- X break;
- X }
- X }
- X
- X ui_poll();
- X
- X } /* end of main list loop */
- X
- #ifdef OLD_DEBUG
- X bw_error( "Ready to deactivate list box" );
- #endif
- X
- X uil_deactivate( m_box, type );
- X
- #ifdef OLD_DEBUG
- X bw_error( "List box deactivated" );
- #endif
- X
- X return item;
- X
- X }
- X
- /****************************************************************
- X
- X uil_draw() - draw a list box
- X
- ****************************************************************/
- X
- uil_draw( type, x1, y1, x2, y2, title, number, titles,
- X foreground, background, highlight, m_box )
- X int type, x1, y1, x2, y2, foreground, background,
- X highlight, number;
- X char *title;
- X char **titles;
- X struct menu_box *m_box;
- X {
- X register int y;
- X
- #ifdef OLD_DEBUG
- X ui_debug( "entered uil_draw()" );
- #endif
- X
- X /* initial assignments */
- X
- X m_box->current = 0;
- X m_box->x_pos = m_box->y_pos = m_box->y_start = 0;
- X m_box->y_logical = m_box->number = number;
- X m_box->x_items = m_box->x_logical = 1;
- X m_box->ysize = ui_grwind->fysize + EXTENSION;
- X m_box->type = type;
- X m_box->d_titles = titles;
- X m_box->x_start = 0;
- X
- X if ( m_box->is_drawn == FALSE )
- X {
- X
- X /* assign colors to structure */
- X
- X m_box->fore = foreground;
- X m_box->back = background;
- X m_box->high = highlight;
- X
- X /* draw the menu window */
- X
- X if ( m_box->window == NULL )
- X {
- X switch( m_box->type )
- X {
- X
- X case MENU_SLIDERS:
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "make slider window %d %d %d %d",
- X x1, y1, x2, y2 );
- X bw_debug( bw_ebuf );
- #endif
- X m_box->window = ui_window( x1, y1,
- X x2, y2, TRUE,
- X highlight, foreground,
- X title, TRUE, BLACK,
- X FALSE, BLACK, background,
- X SOLID, BUT_CLOSE | BUT_MOVE | BUT_RESIZE );
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "made slider window %d %d %d %d",
- X m_box->window->x1, m_box->window->y1, m_box->window->x2, m_box->window->y2 );
- X bw_debug( bw_ebuf );
- #endif
- X break;
- X
- X case MENU_TITLED:
- X y = ( m_box->y_logical * m_box->ysize )
- X + ( ui_grwind->fysize * 3 );
- X m_box->window = ui_window( x1, y2 - y,
- X x2, y2, TRUE,
- X highlight, foreground,
- X title, TRUE, BLACK,
- X TRUE, BLACK, background,
- X SOLID, BUT_CLOSE | BUT_MOVE | BUT_RESIZE );
- X break;
- X
- X case MENU_PLAIN:
- X default:
- X
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "called uil_draw(): %d %d %d %d (xmax %d) (ymax %d)",
- X x1, y2 - y,
- X x2, y2, ui_grwind->xmax, ui_grwind->ymax );
- X ui_debug( ui_tbuf );
- #endif
- X
- X y = ( m_box->y_logical * m_box->ysize )
- X + ( ui_grwind->fysize );
- X m_box->window = ui_window( x1, y2 - y,
- X x2, y2, FALSE,
- X background, foreground,
- X title, FALSE, BLACK,
- X TRUE, BLACK, background,
- X SOLID, 0 );
- X break;
- X }
- X }
- X
- X else
- X {
- X ui_rewindow( m_box->window, title );
- X }
- X
- X /* display the menu */
- X
- X uil_display( m_box );
- X
- X }
- X }
- X
- /****************************************************************
- X
- X uil_activate() Activate a list box
- X
- ****************************************************************/
- X
- uil_activate( m_box, type, item )
- X struct menu_box *m_box;
- X int type, item;
- X {
- X register int x, y;
- X int carry_on;
- X
- #ifdef DEBUG
- X if ( m_box->d_titles == NULL )
- X {
- X bw_error( "Programmer error: menu box has not been drawn!" );
- X return FALSE;
- X }
- #endif
- X
- X if ( item > m_box->number )
- X {
- X item = 0;
- X }
- X
- X if ( item == 0 )
- X {
- X m_box->x_start = m_box->y_start = m_box->x_pos = m_box->y_pos
- X = m_box->current = 0;
- X }
- X else if ( item != m_box->current )
- X {
- X
- X m_box->current = item;
- X
- X /* calculate y_start */
- X
- X y = 0;
- X carry_on = TRUE;
- X if ( m_box->y_logical <= m_box->y_items )
- X {
- X y = 0;
- X }
- X else while( ( y < m_box->y_logical ) && ( carry_on == TRUE ))
- X {
- X if ( (( m_box->x_logical * y ) +
- X ( m_box->x_logical * m_box->y_items )) > item )
- X {
- X carry_on = FALSE;
- X }
- X else
- X {
- X ++y;
- X }
- X }
- X
- X /* calculate x_start */
- X
- X x = 0;
- X carry_on = TRUE;
- X if ( m_box->x_logical <= m_box->x_items )
- X {
- X x = 0;
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "x_logical <= x_items" );
- X ui_wtitle( m_box->window, ui_tbuf );
- X ui_wait();
- #endif
- X }
- X else while( ( x < m_box->x_logical ) && ( carry_on == TRUE ))
- X {
- X
- #ifdef OLD_DEUG
- X sprintf( ui_tbuf, "item <> x_logical = %d", item % m_box->x_logical );
- X ui_wtitle( m_box->window, ui_tbuf );
- X ui_wait();
- X
- X sprintf( ui_tbuf, "trying %d", x );
- X ui_wtitle( m_box->window, ui_tbuf );
- X ui_wait();
- #endif
- X
- X if (( m_box->x_items + x ) > ( item % m_box->x_logical ))
- X {
- X carry_on = FALSE;
- X }
- X else
- X {
- X ++x;
- X }
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "i %d; x %d; y %d", item, x, y );
- X ui_wtitle( m_box->window, ui_tbuf );
- #endif
- X
- X m_box->y_start = y;
- X m_box->x_start = x;
- X m_box->y_pos = ( item / m_box->x_logical ) - m_box->y_start;
- X m_box->x_pos = ( item % m_box->x_logical ) - m_box->x_start;
- X
- X uil_display( m_box );
- X }
- X
- X /* display the exit button */
- X
- X if ( type != MENU_PLAIN )
- X {
- #ifdef USE_ICONS
- #else
- X ui_fbox( m_box->window->bt_x1, m_box->window->bt_y1,
- X m_box->window->bt_x2, m_box->window->bt_y2, BLACK, SOLID );
- X ui_fbox( m_box->window->bt_x1 + 1, m_box->window->bt_y1 + 1,
- X m_box->window->bt_x2 - 1, m_box->window->bt_y2 - 1, WHITE, GRID );
- #endif
- X }
- X
- X /* show current item selected */
- X
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ], TRUE );
- X
- X }
- X
- /****************************************************************
- X
- X uil_deactivate() Deactivate a list menu box
- X
- ****************************************************************/
- X
- uil_deactivate( m_box, type )
- X struct menu_box *m_box;
- X int type;
- X {
- X
- #ifdef OLD_DEBUG
- X bw_error( "enter deactivate" );
- #endif
- X
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ], FALSE );
- X
- #ifdef OLD_DEBUG
- X bw_error( "exit deactivate" );
- #endif
- X
- X }
- X
- /****************************************************************
- X
- X uil_event() Query if an event affects a list box
- X
- ****************************************************************/
- X
- uil_event( m_box, key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest, type, item )
- X struct menu_box *m_box;
- X int key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest, type;
- X int *item;
- X {
- X static int how_far, x_sel, y_sel;
- X register int c;
- X
- X how_far = 0;
- X c = ui_event( m_box, key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest,
- X &how_far, &x_sel, &y_sel );
- X
- X switch( c )
- X {
- X
- X case FALSE:
- X *item = TK_EXIT;
- X return EVENT_NULL;
- X
- X case CR:
- X case LF:
- X uil_exit( m_box, type );
- X *item = m_box->current;
- X return EVENT_SELECTED;
- X break;
- X
- X case KB_DOWN:
- X if ( m_box->current < ( m_box->number - 1 ))
- X {
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ],
- X FALSE );
- X ++m_box->current;
- X ++m_box->y_pos;
- X if ( m_box->y_pos == m_box->y_items )
- X {
- X ++m_box->y_start;
- X --m_box->y_pos;
- X uil_display( m_box );
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ],
- X TRUE );
- X }
- X else
- X {
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ],
- X TRUE );
- X }
- X }
- X *item = 0;
- X return EVENT_NULL;
- X break;
- X
- X case KB_UP:
- X if ( m_box->current > 0 )
- X {
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ],
- X FALSE );
- X --m_box->current;
- X --m_box->y_pos;
- X if ( ( m_box->y_start > 0 ) && ( m_box->y_pos < 0 ))
- X {
- X --m_box->y_start;
- X ++m_box->y_pos;
- X uil_display( m_box );
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ],
- X TRUE );
- X }
- X else
- X {
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ],
- X TRUE );
- X }
- X }
- X *item = 0;
- X return EVENT_NULL;
- X break;
- X
- X case ESCAPE:
- X case MO_EXIT:
- X uil_exit( m_box, type );
- X *item = 0;
- X return TK_EXIT;
- X break;
- X
- X case MO_UP:
- X if ( m_box->y_start > 0 )
- X {
- X while ( ( m_box->y_start - how_far ) < 0 )
- X {
- X --how_far;
- X }
- X m_box->y_start -= how_far;
- X m_box->current -= how_far;
- X uil_display( m_box );
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ],
- X TRUE );
- X }
- X *item = 0;
- X return EVENT_NULL;
- X break;
- X
- X case MO_DN:
- X if ( ( m_box->y_start + m_box->y_items )
- X < m_box->number )
- X {
- X while ( ( m_box->y_start + how_far + m_box->y_items )
- X > m_box->number )
- X {
- X --how_far;
- X }
- X m_box->y_start += how_far;
- X m_box->current += how_far;
- X uil_display( m_box );
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ],
- X TRUE );
- X }
- X *item = 0;
- X return EVENT_NULL;
- X break;
- X
- X case MO_SEL:
- X if ( y_sel == m_box->y_pos )
- X {
- X uil_exit( m_box, type );
- X *item = m_box->current;
- X return EVENT_SELECTED;
- X }
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ], FALSE );
- X m_box->current = m_box->y_start + y_sel;
- X m_box->y_pos = y_sel;
- X uil_item( m_box, m_box->current,
- X m_box->d_titles[ m_box->current ], TRUE );
- X *item = 0;
- X return EVENT_NULL;
- X break;
- X
- X default:
- X *item = 0;
- X return EVENT_NULL;
- X break;
- X }
- X }
- X
- /****************************************************************
- X
- X uil_display() Show all items in a list box
- X
- ****************************************************************/
- X
- uil_display( m_box )
- X struct menu_box *m_box;
- X {
- X register int c, v;
- X int x, y;
- X
- X if ( m_box->is_drawn == FALSE )
- X {
- X switch( m_box->type )
- X {
- X case MENU_SLIDERS:
- X uil_sliders( m_box );
- X break;
- X case MENU_TITLED:
- X case MENU_PLAIN:
- X default:
- X uil_plain( m_box );
- X break;
- X }
- X }
- X
- X /* calculate visible lines */
- X
- X m_box->y_items = ( m_box->i_y2 - m_box->i_y1 )
- X / m_box->ysize;
- X m_box->xsize = ( m_box->i_x2 - m_box->i_x1 ) / m_box->x_logical;
- X
- X if ( m_box->type == MENU_SLIDERS )
- X {
- X
- X /* calculate increments for elevators */
- X
- X x = ui_grwind->ymax / 15;
- X y = ( x * gr_pxsize ) / gr_pysize;
- X
- X if ( m_box->y_logical <= m_box->y_items )
- X {
- X m_box->vel_inc = 1;
- X }
- X else
- X {
- X m_box->vel_inc = ((( m_box->ve_y2 - ( m_box->ve_y1 + y ))
- X * INC_ACCURACY )
- X / ( m_box->y_logical - m_box->y_items ));
- X }
- X
- X if ( m_box->vel_inc <= 0 ) /* increment cannot be <= 0 */
- X {
- X m_box->vel_inc = 1;
- X }
- X
- X if ( m_box->x_logical <= m_box->x_items )
- X {
- X m_box->hel_inc = 1;
- X }
- X else
- X {
- X m_box->hel_inc = ((( m_box->he_x2 - ( m_box->he_x1 + x ))
- X * INC_ACCURACY )
- X / ( m_box->x_logical - m_box->x_items ));
- X }
- X
- X if ( m_box->vel_inc <= 0 ) /* increment cannot be <= 0 */
- X {
- X m_box->vel_inc = 1;
- X }
- X
- X uil_vel( m_box ); /* show vertical elevator */
- X if ( m_box->is_drawn == FALSE )
- X {
- X uil_hel( m_box ); /* show horizontal elevator */
- X }
- X }
- X
- X c = 0;
- X v = m_box->y_start;
- X while ( ( c < m_box->y_items ) && ( v < m_box->number ))
- X {
- X
- X uil_item( m_box, v, m_box->d_titles[ v ], FALSE );
- X ++c;
- X ++v;
- X }
- X
- X m_box->is_drawn = TRUE;
- X
- X }
- X
- /****************************************************************
- X
- X uil_item() Show a particular item in a list box
- X
- ****************************************************************/
- X
- uil_item( m_box, item, text, selected )
- X struct menu_box *m_box;
- X int item, selected;
- X char *text;
- X {
- X int x1, y1, x2, y2;
- X
- X x1 = m_box->i_x1;
- X y1 = m_box->i_y2 - ( m_box->ysize *
- X ( 1 + item - m_box->y_start ));
- X x2 = m_box->i_x2;
- X y2 = m_box->i_y2 - ( m_box->ysize *
- X ( item - m_box->y_start ));
- X
- X if ( selected == TRUE )
- X {
- X ui_fbox( x1, y1, x2, y2, m_box->fore, SOLID );
- X ui_str( x1, y1 + EXTENSION, x2, m_box->fore, m_box->back,
- X text );
- X }
- X else
- X {
- X ui_fbox( x1, y1, x2, y2, m_box->back, SOLID );
- X ui_str( x1, y1 + EXTENSION, x2, m_box->back, m_box->fore,
- X text );
- X }
- X }
- X
- /****************************************************************
- X
- X uil_vel() Show vertical elevator
- X
- ****************************************************************/
- X
- uil_vel( m_box )
- X struct menu_box *m_box;
- X {
- X int y_pos;
- X
- X /* return if no area (box too small ) */
- X
- X if ( m_box->ve_y2 <= m_box->ve_y1 )
- X {
- #ifdef OLD_DEBUG
- X bw_debug( "No room for vertical slider" );
- #endif
- X return FALSE;
- X }
- X
- #ifdef OLD_DEBUG
- X bw_debug( "Drawing vertical slider" );
- #endif
- X
- X /* first blank the elevator area */
- X
- X ui_fbox( m_box->vs_x1, m_box->ve_y1, m_box->vs_x2, m_box->ve_y2,
- X BLACK, SOLID );
- X ui_fbox( m_box->vs_x1 + 1, m_box->ve_y1 + 1,
- X m_box->vs_x2 - 1, m_box->ve_y2 - 1,
- X m_box->back, GRID );
- X
- X /* calculate size and current position */
- X
- X y_pos = m_box->ve_y2 - (( m_box->y_start * m_box->vel_inc ) / INC_ACCURACY );
- X
- X m_box->vel_y1 = y_pos - ( m_box->ve_y1 - m_box->vs_y1 );
- X m_box->vel_x1 = m_box->vs_x1;
- X m_box->vel_x2 = m_box->vs_x2;
- X m_box->vel_y2 = y_pos;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "vel y1 %d y2 %d y_pos %d",
- X m_box->vel_y1, m_box->vel_y2, y_pos );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /* draw the elevator */
- X
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, m_box->vel_x1, m_box->vel_y1, m_box->vel_x2,
- X m_box->vel_y2, &ui_elicon );
- #else
- X ui_fbox( m_box->vel_x1 + EL_OFFSET, m_box->vel_y1 + EL_OFFSET,
- X m_box->vel_x2 - EL_OFFSET, m_box->vel_y2 - EL_OFFSET,
- X BLACK, SOLID );
- X ui_fbox( m_box->vel_x1 + EL_OFFSET + 1,
- X m_box->vel_y1 + EL_OFFSET + 1,
- X m_box->vel_x2 - ( EL_OFFSET + 1 ),
- X m_box->vel_y2 - ( EL_OFFSET + 1 ),
- X m_box->back, SOLID );
- X gr_circle( ui_screen,
- X m_box->vel_x1 + (( m_box->vel_x2 - m_box->vel_x1 ) / 2 ),
- X m_box->vel_y1 + ( ( m_box->ve_y1 - m_box->vs_y1 ) / 2 ),
- X ( m_box->ve_y1 - m_box->vs_y1 ) / 4, BLACK, SOLID );
- X gr_circle( ui_screen,
- X m_box->vel_x1 + (( m_box->vel_x2 - m_box->vel_x1 ) / 2 ),
- X m_box->vel_y1 + ( ( m_box->ve_y1 - m_box->vs_y1 ) / 2 ),
- X ( m_box->ve_y1 - m_box->vs_y1 ) / 4, m_box->high, GRID );
- #endif
- X }
- X
- /****************************************************************
- X
- X uil_hel() Show horizontal elevator
- X
- ****************************************************************/
- X
- uil_hel( m_box )
- X struct menu_box *m_box;
- X {
- X int x_pos;
- X
- X /* first blank the elevator area */
- X
- X ui_fbox( m_box->he_x1, m_box->hs_y1,
- X m_box->he_x2, m_box->hs_y2,
- X BLACK, SOLID );
- X ui_fbox( m_box->he_x1 + 1, m_box->hs_y1,
- X m_box->he_x2 - 1, m_box->hs_y2,
- X m_box->back, GRID );
- X
- X /* calculate size and current position */
- X
- X m_box->hel_x1 = x_pos = m_box->he_x1
- X + (( m_box->hel_inc * m_box->x_start ) / INC_ACCURACY );
- X m_box->hel_x2 = m_box->hel_x1 + ( m_box->hs_x2 - m_box->he_x2 );
- X m_box->hel_y1 = m_box->hs_y1;
- X m_box->hel_y2 = m_box->hs_y2;
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "he_x1 = %d, inc * start = %d, inc = %d, start = %d, x_pos = %d, hel = %d",
- X m_box->he_x1, ( m_box->hel_inc * start ) / INC_ACCURACY,
- X m_box->hel_inc, m_box->x_start, x_pos, m_box->hel_x1 );
- X ui_wtitle( m_box->window, ui_tbuf );
- X ui_wait();
- #endif
- X
- X /* draw the elevator */
- X
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, m_box->hel_x1, m_box->hel_y1, m_box->hel_x2,
- X m_box->hel_y2, &ui_elicon );
- #else
- X ui_fbox( m_box->hel_x1 + EL_OFFSET, m_box->hel_y1 + EL_OFFSET,
- X m_box->hel_x2 - EL_OFFSET, m_box->hel_y2 - EL_OFFSET,
- X BLACK, SOLID );
- X ui_fbox( m_box->hel_x1 + EL_OFFSET + 1,
- X m_box->hel_y1 + EL_OFFSET + 1,
- X m_box->hel_x2 - ( EL_OFFSET + 1),
- X m_box->hel_y2 - (EL_OFFSET + 1),
- X m_box->back, SOLID );
- X gr_circle( ui_screen,
- X m_box->hel_x1 + ( ( m_box->hs_x2 - m_box->he_x2 ) / 2 ),
- X m_box->hel_y1 + ( ( m_box->hel_y2 - m_box->hel_y1 ) / 2 ),
- X ( m_box->hel_y2 - m_box->hel_y1 ) / 4,
- X BLACK, SOLID );
- X gr_circle( ui_screen,
- X m_box->hel_x1 + ( ( m_box->hs_x2 - m_box->he_x2 ) / 2 ),
- X m_box->hel_y1 + ( ( m_box->hel_y2 - m_box->hel_y1 ) / 2 ),
- X ( m_box->hel_y2 - m_box->hel_y1 ) / 4,
- X m_box->high, GRID );
- #endif
- X
- X }
- X
- uil_exit( m_box, type )
- X struct menu_box *m_box;
- X int type;
- X {
- X
- X /* blank the exit button */
- X
- X if ( type != MENU_PLAIN )
- X {
- #ifdef USE_ICONS
- #else
- X ui_fbox( m_box->window->bt_x1, m_box->window->bt_y1,
- X m_box->window->bt_x2, m_box->window->bt_y2, BLACK, SOLID );
- #endif
- X }
- X
- X /* fill elevators with grid */
- X
- X if ( type == MENU_SLIDERS )
- X {
- X if ( m_box->ve_y2 > m_box->ve_y1 )
- X {
- X ui_fbox( m_box->vs_x1, m_box->ve_y1,
- X m_box->vs_x2, m_box->ve_y2, BLACK, SOLID ); /* blank */
- X ui_fbox( m_box->vs_x1 + 1, m_box->ve_y1 + 1,
- X m_box->vs_x2 - 1, m_box->ve_y2 - 1,
- X m_box->back, GRID );
- X }
- X ui_fbox( m_box->he_x1, m_box->hs_y1,
- X m_box->he_x2, m_box->hs_y2, BLACK, SOLID ); /* blank */
- X ui_fbox( m_box->he_x1 + 1, m_box->hs_y1,
- X m_box->he_x2 - 1, m_box->hs_y2,
- X m_box->back, GRID );
- X }
- X
- X }
- X
- /****************************************************************
- X
- X ui_event() Query if keyboard or mouse actions affect
- X a list or icon menu box
- X
- ****************************************************************/
- X
- ui_event( m_box, key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest,
- X how_far, x_sel, y_sel )
- X struct menu_box *m_box;
- X int key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest;
- X int *how_far, *x_sel, *y_sel;
- X {
- X register int c, d;
- X
- X /* if a key is available, simply return it */
- X
- X if ( key != FALSE )
- X {
- X return key;
- X }
- X
- X /* else presume that a mouse event has occurred */
- X
- X /* if the destination point is not within the window check to see if
- X the source point is */
- X
- X else if ( uil_bounds( mo_xdest, mo_ydest, m_box->window->x1,
- X m_box->window->y1, m_box->window->x2, m_box->window->y2 ) == FALSE )
- X {
- X if ( uil_bounds( mo_xsrc, mo_ysrc, m_box->window->x1,
- X m_box->window->y1, m_box->window->x2, m_box->window->y2 ) == TRUE )
- X {
- X
- X /* test for selection bounds */
- X
- X for ( c = 0; c < m_box->y_items; ++c )
- X {
- X for ( d = 0; d < m_box->x_items; ++d )
- X {
- X if ( uil_bounds( mo_xsrc, mo_ysrc,
- X m_box->i_x1 + ( d * m_box->xsize ),
- X m_box->i_y2 - ( ( c + 1 ) * m_box->ysize ),
- X m_box->i_x1 + ( ( d + 1 ) * m_box->xsize ),
- X m_box->i_y2 - ( c * m_box->ysize ) ) == TRUE )
- X {
- X *y_sel = c;
- X *x_sel = d;
- X return MO_SRC;
- X }
- X }
- X }
- X
- X /* selection bounds tests failed */
- X
- X return FALSE;
- X }
- X else
- X {
- X return FALSE;
- X }
- X }
- X
- X /* Check to see if source is within range of the vertical elevator */
- X
- X else if ( uil_bounds( mo_xsrc, mo_ysrc, m_box->vel_x1, m_box->vel_y1,
- X m_box->vel_x2, m_box->vel_y2 ) == TRUE )
- X {
- X if ( ( mo_ysrc - mo_ydest ) == 0 )
- X {
- X return FALSE;
- X }
- X else if ( ( mo_ysrc - mo_ydest ) > 0 )
- X {
- X *how_far = (( mo_ysrc - mo_ydest )
- X * INC_ACCURACY )
- X / m_box->vel_inc;
- X return MO_DN;
- X }
- X else
- X {
- X *how_far = (( mo_ydest - mo_ysrc )
- X * INC_ACCURACY )
- X / m_box->vel_inc;
- X return MO_UP;
- X }
- X }
- X
- X if ( uil_bounds( mo_xsrc, mo_ysrc, m_box->hel_x1, m_box->hel_y1,
- X m_box->hel_x2, m_box->hel_y2 ) == TRUE )
- X {
- X if ( ( mo_xsrc - mo_xdest ) == 0 )
- X {
- X return FALSE;
- X }
- X else if ( ( mo_xsrc - mo_xdest ) > 0 )
- X {
- X *how_far = (( mo_xsrc - mo_xdest )
- X * INC_ACCURACY )
- X / m_box->hel_inc;
- X return MO_LEFT;
- X }
- X else
- X {
- X *how_far = (( mo_xdest - mo_xsrc )
- X * INC_ACCURACY )
- X / m_box->hel_inc;
- X return MO_RIGHT;
- X }
- X }
- X
- X /* test for exit button bounds */
- X
- X if ( uil_bounds( mo_xdest, mo_ydest, m_box->window->bt_x1, m_box->window->bt_y1,
- X m_box->window->bt_x2, m_box->window->bt_y2 ) == TRUE )
- X {
- X return MO_EXIT;
- X }
- X
- X /* test for up arrow bounds */
- X
- X if ( uil_bounds( mo_xdest, mo_ydest, m_box->vs_x1, m_box->ve_y2,
- X m_box->vs_x2, m_box->vs_y2 ) == TRUE )
- X {
- X *how_far = 1;
- X return MO_UP;
- X }
- X
- X /* test for down arrow bounds */
- X
- X if ( uil_bounds( mo_xdest, mo_ydest, m_box->vs_x1, m_box->vs_y1,
- X m_box->vs_x2, m_box->ve_y1 ) == TRUE )
- X {
- X *how_far = 1;
- X return MO_DN;
- X }
- X
- X /* test for left arrow bounds */
- X
- X if ( uil_bounds( mo_xdest, mo_ydest, m_box->hs_x1, m_box->hs_y1,
- X m_box->he_x1, m_box->hs_y2 ) == TRUE )
- X {
- X *how_far = 1;
- X return MO_LEFT;
- X }
- X
- X /* test for right arrow bounds */
- X
- X if ( uil_bounds( mo_xdest, mo_ydest, m_box->he_x2, m_box->hs_y1,
- X m_box->hs_x2, m_box->hs_y2 ) == TRUE )
- X {
- X *how_far = 1;
- X return MO_RIGHT;
- X }
- X
- X /* test for selection bounds */
- X
- X for ( c = 0; c < m_box->y_items; ++c )
- X {
- X for ( d = 0; d < m_box->x_items; ++d )
- X {
- X if ( uil_bounds( mo_xdest, mo_ydest,
- X m_box->i_x1 + ( d * m_box->xsize ),
- X m_box->i_y2 - ( ( c + 1 ) * m_box->ysize ),
- X m_box->i_x1 + ( ( d + 1 ) * m_box->xsize ),
- X m_box->i_y2 - ( c * m_box->ysize ) ) == TRUE )
- X {
- X *y_sel = c;
- X *x_sel = d;
- X return MO_SEL;
- X }
- X }
- X }
- X }
- X
- /****************************************************************
- X
- X uil_bounds() See if x and y are within bounds of x1, y1, x2, y2
- X
- ****************************************************************/
- X
- uil_bounds( x, y, x1, y1, x2, y2 )
- X int x, y, x1, y1, x2, y2;
- X {
- X if ( x < x1 )
- X {
- X return FALSE;
- X }
- X if ( x > x2 )
- X {
- X return FALSE;
- X }
- X if ( y < y1 )
- X {
- X return FALSE;
- X }
- X if ( y > y2 )
- X {
- X return FALSE;
- X }
- X return TRUE;
- X }
- X
- /****************************************************************
- X
- X uil_sliders() Calculate and draw sliders
- X for menu/icon box
- X
- ****************************************************************/
- X
- uil_sliders( m_box )
- X struct menu_box *m_box;
- X {
- X int midv, midh, toph, both, leftv, rightv;
- X int halfh, halfv, x, y;
- X
- X /* assign sizes to icon area and sliders */
- X
- X x = ui_grwind->fxsize * SL_YSIZE;
- X if ( x > SL_XMAX )
- X {
- X x = SL_XMAX;
- X }
- X y = (( x * gr_pxsize ) * ACC ) / ( gr_pysize * ACC );
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "SL_XMAX = %d; x = %d, y = %d", SL_XMAX, x, y );
- X bw_debug( bw_ebuf );
- #endif
- X
- X m_box->i_x1 = m_box->window->u_x1 + 2;
- X m_box->i_y1 = m_box->window->u_y1 + y;
- X m_box->i_x2 = m_box->window->u_x2 - ( x + 3 );
- X m_box->i_y2 = m_box->window->u_y2 - 1;
- X m_box->vs_x1 = m_box->window->u_x2 - ( x + 1 );
- X m_box->vs_y1 = m_box->i_y1;
- X m_box->vs_x2 = m_box->window->u_x2;
- X m_box->vs_y2 = m_box->window->u_y2 - 1;
- X m_box->hs_x1 = m_box->window->u_x1 + 1;
- X m_box->hs_y1 = m_box->window->u_y1;
- X m_box->hs_x2 = m_box->i_x2;
- X m_box->hs_y2 = m_box->i_y1 - 1;
- X m_box->ve_y1 = m_box->vs_y1 + y;
- X m_box->ve_y2 = m_box->vs_y2 - y;
- X m_box->he_x1 = m_box->window->u_x1 + x;
- X m_box->he_x2 = m_box->hs_x2 - x;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "made horizontal slider %d %d %d %d",
- X m_box->hs_x1, m_box->hs_y1, m_box->hs_x2, m_box->hs_y2 );
- X bw_debug( bw_ebuf );
- #endif
- X
- X /* outline the areas */
- X
- X gr_line( ui_screen, m_box->window->u_x1, m_box->hs_y2,
- X m_box->vs_x2, m_box->hs_y2, m_box->fore, SOLID );
- X --m_box->hs_y2;
- X gr_line( ui_screen, m_box->vs_x1, m_box->hs_y1,
- X m_box->vs_x1, m_box->window->u_y2, m_box->fore, SOLID );
- X ++m_box->vs_x1;
- X
- X /* demarcate arrow areas */
- X
- X gr_line( ui_screen, m_box->he_x1, m_box->hs_y1,
- X m_box->he_x1, m_box->hs_y2, m_box->fore, SOLID );
- X gr_line( ui_screen, m_box->he_x2, m_box->hs_y1,
- X m_box->he_x2, m_box->hs_y2, m_box->fore, SOLID );
- X gr_line( ui_screen, m_box->vs_x1, m_box->ve_y1,
- X m_box->vs_x2, m_box->ve_y1, m_box->fore, SOLID );
- X gr_line( ui_screen, m_box->vs_x1, m_box->ve_y2,
- X m_box->vs_x2, m_box->ve_y2, m_box->fore, SOLID );
- X
- X /* calculate some midpoints */
- X
- X midh = m_box->hs_y1 + (( m_box->hs_y2 - m_box->hs_y1 ) / 2 );
- X toph = m_box->hs_y2 - (( m_box->hs_y2 - m_box->hs_y1 ) / 3 );
- X both = m_box->hs_y1 + (( m_box->hs_y2 - m_box->hs_y1 ) / 3 );
- X midv = m_box->vs_x1 + (( m_box->vs_x2 - m_box->vs_x1 ) / 2 );
- X leftv = m_box->vs_x1 + (( m_box->vs_x2 - m_box->vs_x1 ) / 3 );
- X rightv = m_box->vs_x2 - (( m_box->vs_x2 - m_box->vs_x1 ) / 3 );
- X
- X /* left arrow */
- X
- X ui_fbox( m_box->hs_x1, m_box->hs_y1, m_box->he_x1, m_box->hs_y2,
- X m_box->high, SOLID );
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, m_box->hs_x1, m_box->hs_y1, m_box->he_x1, m_box->hs_y2,
- X &ui_lefticn );
- #else
- X halfh = m_box->hs_x1 + (( m_box->he_x1 - m_box->hs_x1 ) / 2 );
- X uil_arrow( m_box,
- X m_box->hs_x1, midh,
- X halfh, m_box->hs_y1 + 1,
- X halfh, both,
- X m_box->he_x1, both,
- X m_box->he_x1, toph,
- X halfh, toph,
- X halfh, m_box->hs_y2 - 1,
- X m_box->hs_x1, midh );
- X gr_line( ui_screen, halfh + 1, m_box->hs_y1 + 1,
- X halfh + 1, both, m_box->fore, SOLID ); /* shadow */
- X gr_line( ui_screen, halfh + 1, toph,
- X halfh + 1, m_box->hs_y2 - 1, m_box->fore, SOLID );
- X gr_line( ui_screen, halfh, both - 1,
- X m_box->he_x1, both - 1, m_box->fore, SOLID );
- #endif
- X
- X /* right arrow */
- X
- X ui_fbox( m_box->he_x2, m_box->hs_y1, m_box->hs_x2, m_box->hs_y2,
- X m_box->high, SOLID );
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, m_box->he_x2, m_box->hs_y1, m_box->hs_x2, m_box->hs_y2,
- X &ui_righticn );
- #else
- X halfh = m_box->he_x2 + (( m_box->hs_x2 - m_box->he_x2 ) / 2 );
- X uil_arrow( m_box,
- X m_box->hs_x2, midh,
- X halfh, m_box->hs_y1 + 1,
- X halfh, both,
- X m_box->he_x2, both,
- X m_box->he_x2, toph,
- X halfh, toph,
- X halfh, m_box->hs_y2 - 1,
- X m_box->hs_x2, midh );
- X gr_line( ui_screen, halfh, both - 1,
- X m_box->he_x2, both - 1, m_box->fore, SOLID );
- X gr_line( ui_screen, halfh + 1, m_box->hs_y1 + 1,
- X m_box->hs_x2, midh - 1, m_box->fore, SOLID ); /* shadow */
- #endif
- X
- X /* up arrow */
- X
- X ui_fbox( m_box->vs_x1, m_box->ve_y2, m_box->vs_x2, m_box->vs_y2,
- X m_box->high, SOLID );
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, m_box->vs_x1, m_box->ve_y2, m_box->vs_x2, m_box->vs_y2,
- X &ui_upicn );
- #else
- X halfv = m_box->ve_y2 + (( m_box->vs_y2 - m_box->ve_y2 ) / 2 );
- X uil_arrow( m_box,
- X midv, m_box->vs_y2, /* point 1 */
- X m_box->vs_x1 + 1, halfv, /* point 2 */
- X leftv, halfv, /* point 3 */
- X leftv, m_box->ve_y2, /* point 4 */
- X rightv, m_box->ve_y2, /* point 5 */
- X rightv, halfv, /* point 6 */
- X m_box->vs_x2 - 1, halfv, /* point 7 */
- X midv, m_box->vs_y2 ); /* point 8 */
- X gr_line( ui_screen, m_box->vs_x1 + 1, halfv - 1,
- X leftv, halfv - 1, m_box->fore, SOLID );
- X gr_line( ui_screen, rightv, halfv - 1,
- X m_box->vs_x2 - 1, halfv - 1, m_box->fore, SOLID );
- X gr_line( ui_screen, rightv + 1, m_box->ve_y2,
- X rightv + 1, halfv, m_box->fore, SOLID ); /* shadow */
- #endif
- X
- X /* down arrow */
- X
- X ui_fbox( m_box->vs_x1, m_box->vs_y1, m_box->vs_x2, m_box->ve_y1,
- X m_box->high, SOLID );
- #ifdef USE_ICONS
- X ui_pbmcenter( ui_screen, m_box->vs_x1, m_box->vs_y1, m_box->vs_x2, m_box->ve_y1,
- X &ui_downicn );
- #else
- X halfv = m_box->vs_y1 + (( m_box->ve_y1 - m_box->vs_y1 ) / 2 );
- X uil_arrow( m_box,
- X midv, m_box->vs_y1, /* point 1 */
- X m_box->vs_x1 + 1, halfv, /* point 2 */
- X leftv, halfv, /* point 3 */
- X leftv, m_box->ve_y1, /* point 4 */
- X rightv, m_box->ve_y1, /* point 5 */
- X rightv, halfv, /* point 6 */
- X m_box->vs_x2 - 1, halfv, /* point 7 */
- X midv, m_box->vs_y1 ); /* point 8 */
- X gr_line( ui_screen, rightv + 1, halfv,
- X rightv + 1, m_box->ve_y1, m_box->fore, SOLID );
- X gr_line( ui_screen, midv + 1, m_box->vs_y1,
- X m_box->vs_x2 - 1, halfv - 1, m_box->fore, SOLID ); /* shadow */
- #endif
- X
- X /* blank elevator areas with grid */
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "draw horizontal slider %d %d %d %d",
- X m_box->hs_x1, m_box->hs_y1, m_box->hs_x2, m_box->hs_y2 );
- X bw_debug( bw_ebuf );
- #endif
- X
- X if ( m_box->hs_y2 > m_box->hs_y1 )
- X {
- /* gr_rectangle( ui_screen, m_box->he_x1, m_box->hs_y1,
- X m_box->he_x2, m_box->hs_y2, m_box->fore, HOLLOW ); */
- X gr_rectangle( ui_screen, m_box->he_x1 + 1, m_box->hs_y1,
- X m_box->he_x2 - 1, m_box->hs_y2, m_box->fore, GRID );
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "made horizontal slider %d %d %d %d",
- X m_box->hs_x1, m_box->hs_y1, m_box->hs_x2, m_box->hs_y2 );
- X bw_debug( bw_ebuf );
- #endif
- X }
- X
- X if ( m_box->ve_y2 > m_box->ve_y1 )
- X {
- X gr_rectangle( ui_screen, m_box->vs_x1, m_box->ve_y1,
- X m_box->vs_x2, m_box->ve_y2, m_box->fore, HOLLOW );
- X gr_rectangle( ui_screen, m_box->vs_x1 + 1, m_box->ve_y1 + 1,
- X m_box->vs_x2 - 1, m_box->ve_y2 - 1, m_box->fore, GRID );
- X }
- X }
- X
- X
- /****************************************************************
- X
- X uil_arrow() Draw an arrow for the slider box
- X
- ****************************************************************/
- X
- uil_arrow( m_box,
- X x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7, x8, y8 )
- X struct menu_box *m_box;
- X int x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7, x8, y8;
- X {
- X gr_line( ui_screen, x1, y1, x2, y2, m_box->fore, SOLID );
- X gr_line( ui_screen, x2, y2, x3, y3, m_box->fore, SOLID );
- X gr_line( ui_screen, x3, y3, x4, y4, m_box->fore, SOLID );
- X gr_line( ui_screen, x4, y4, x5, y5, m_box->fore, SOLID );
- X gr_line( ui_screen, x5, y5, x6, y6, m_box->fore, SOLID );
- X gr_line( ui_screen, x6, y6, x7, y7, m_box->fore, SOLID );
- X gr_line( ui_screen, x7, y7, x8, y8, m_box->fore, SOLID );
- X }
- X
- /****************************************************************
- X
- X uil_plain() Calculate sizes
- X for plain menu box
- X
- ****************************************************************/
- X
- uil_plain( m_box )
- X struct menu_box *m_box;
- X {
- X
- X /* assign sizes to icon area */
- X
- X m_box->i_x1 = m_box->window->u_x1 + 2;
- X m_box->i_y1 = m_box->window->u_y1;
- X m_box->i_x2 = m_box->window->u_x2 - 2;
- X m_box->i_y2 = m_box->window->u_y2 - 1;
- X m_box->vs_x1 = 1;
- X m_box->vs_y1 = 1;
- X m_box->vs_x2 = 1;
- X m_box->vs_y2 = 1;
- X m_box->hs_x1 = 1;
- X m_box->hs_y1 = 1;
- X m_box->hs_x2 = 1;
- X m_box->hs_y2 = 1;
- X m_box->ve_y1 = 1;
- X m_box->ve_y2 = 1;
- X m_box->he_x1 = 1;
- X m_box->he_x2 = 1;
- X }
- X
- X
- SHAR_EOF
- chmod 0644 io/ui/ui_list.c ||
- echo 'restore of io/ui/ui_list.c failed'
- Wc_c="`wc -c < 'io/ui/ui_list.c'`"
- test 37627 -eq "$Wc_c" ||
- echo 'io/ui/ui_list.c: original size 37627, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/ui/ui_pbm.c ==============
- if test -f 'io/ui/ui_pbm.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/ui/ui_pbm.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/ui/ui_pbm.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_pbm.c' &&
- /***************************************************************
- X
- X ui_pbm.c Portable Bit-Map Routines
- X for 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
- SHAR_EOF
- true || echo 'restore of io/ui/ui_pbm.c failed'
- fi
- echo 'End of part 9'
- echo 'File io/ui/ui_pbm.c is continued in part 10'
- echo 10 > _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.
-