home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.2 KB | 2,147 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i008: sfs - Space Flight Simulator, Part08/21
- Message-ID: <1991Dec24.045434.29990@sparky.imd.sterling.com>
- X-Md4-Signature: 9edb069dcdfe01c53a1b0ef3b368bc58
- Date: Tue, 24 Dec 1991 04:54:34 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 8
- Archive-name: sfs/part08
- 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.h continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 8; 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.h'
- else
- echo 'x - continuing file io/ui/ui.h'
- sed 's/^X//' << 'SHAR_EOF' >> 'io/ui/ui.h' &&
- X int y_logical; /* logical items on y axis */
- X int x_pos; /* current position, x axis */
- X int y_pos; /* current position, y axis */
- X int current; /* currently selected item */
- X int x_start; /* starting position for x axis */
- X int y_start; /* starting position for y axis */
- X int fore; /* foreground color */
- X int back; /* background color */
- X int high; /* highlight color */
- X int number; /* total number of icons/menu items */
- X int i_x1; /* icon area, left */
- X int i_y1; /* icon area, bottom */
- X int i_x2; /* icon area, right */
- X int i_y2; /* icon area, top */
- X int vs_x1; /* vertical slide, left */
- X int vs_y1; /* vertical slide, bottom */
- X int vs_x2; /* vertical slide, right */
- X int vs_y2; /* vertical slide, top */
- X int ve_y1; /* vertical elevator, bottom */
- X int ve_y2; /* vertical elevator, top */
- X int hs_x1; /* horizontal slide, left */
- X int hs_y1; /* horizontal slide, bottom */
- X int hs_x2; /* horizontal slide, right */
- X int hs_y2; /* horizontal slide, top */
- X int he_x1; /* horizontal elevator, left */
- X int he_x2; /* horizontal elevator, right */
- X int vel_x1; /* vertical elevator left */
- X int vel_y1; /* vertical elevator bottom */
- X int vel_x2; /* vertical elevator right */
- X int vel_y2; /* vertical elevator top */
- X int vel_inc; /* vertical elevator increment */
- X int hel_x1; /* horizontal elevator left */
- X int hel_y1; /* horizontal elevator bottom */
- X int hel_x2; /* horizontal elevator right */
- X int hel_y2; /* horizontal elevator top */
- X int hel_inc; /* horizontal elevator increment */
- X };
- X
- struct pbm_struct
- X {
- X int xsize;
- X int ysize;
- X int image;
- X };
- X
- struct tty_struct
- X {
- X struct uiwindow *window; /* pointer to ui window structure */
- X int lines; /* text lines in window */
- X int columns; /* text columns in window */
- X int font_ysize; /* font size, vertical */
- X int font_xsize; /* font size, horizontal */
- X int curs_xpos; /* cursor x (column) position */
- X int curs_ypos; /* cursor y (line) position */
- X int foreground; /* text foreground color */
- X int background; /* text background color */
- X int standout; /* boolean: standout? TRUE = reverse video */
- X int scroll_right; /* boolean: scroll at right margin */
- X /* default: FALSE, do not scroll */
- X char *cbuffer; /* buffer to hold character position */
- X }; /* overwritten by cursor */
- X
- struct ui_twstruct
- X {
- X struct tw_struct *tw;
- X struct uiwindow *uiw;
- X };
- X
- extern struct gr_window *ui_grwind;
- extern char ui_ready;
- X
- extern struct uiwindow * ui_window();
- extern struct tty_struct * tty_init();
- extern struct ui_twstruct * ui_twinit();
- X
- extern char ui_tbuf[ 128 ];
- extern int ui_screen;
- extern char ui_fontpath[ 128 ];
- X
- extern struct pbm_struct ui_elicon; /* elevator icon */
- extern struct pbm_struct ui_lefticn; /* left icon */
- extern struct pbm_struct ui_righticn; /* right icon */
- extern struct pbm_struct ui_upicn; /* up icon */
- extern struct pbm_struct ui_downicn; /* down icon */
- extern struct pbm_struct ui_clicon; /* close window icon */
- extern struct pbm_struct ui_reicon; /* resize window icon */
- extern struct pbm_struct ui_mvicon; /* move window icon */
- extern struct pbm_struct ui_deficon; /* default file icon */
- extern struct pbm_struct ui_foldicon; /* file folder icon */
- extern struct pbm_struct ui_exicon; /* executable file icon */
- SHAR_EOF
- echo 'File io/ui/ui.h is complete' &&
- chmod 0644 io/ui/ui.h ||
- echo 'restore of io/ui/ui.h failed'
- Wc_c="`wc -c < 'io/ui/ui.h'`"
- test 10420 -eq "$Wc_c" ||
- echo 'io/ui/ui.h: original size 10420, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/ui/ui_boxes.c ==============
- if test -f 'io/ui/ui_boxes.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/ui/ui_boxes.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/ui/ui_boxes.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_boxes.c' &&
- /****************************************************************
- X
- X ui_boxes.c Box drawing and window 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 "bw.h"
- #include "gr.h"
- #include "ui.h"
- X
- #ifdef __STDC__
- #include "malloc.h"
- #else
- extern char * malloc();
- #endif
- X
- struct uiwindow *
- ui_window( x1, y1, x2, y2, t_flag, t_bcolor, t_tcolor, t_text,
- X b_flag, b_color,
- X s_flag, s_color, m_color, m_style, buttons )
- X int x1, y1, x2, y2; /* coordinates of whole area */
- X int t_flag; /* title flag */
- X int t_bcolor, t_tcolor; /* title background & text colors */
- X char *t_text; /* text of title */
- X int b_flag, b_color; /* border flag, color */
- X int s_flag, s_color; /* shadow flag, color */
- X int m_color, m_style; /* color & style for main box */
- X int buttons; /* buttons */
- X {
- X static int _x1, _y1, _x2, _y2; /* counters for coordinates */
- X static struct uiwindow *ret_struct; /* structure for return data */
- X int s_ysize;
- X
- X if ( ui_ready == 0 )
- X {
- #ifdef DEBUG
- X bw_error( "The ui system is not initialized." );
- #endif
- X return;
- X }
- X
- X /* Get memory for window structure */
- X
- X if ( ( ret_struct = (struct uiwindow *) malloc( sizeof( struct uiwindow ) )) == 0 )
- X {
- X bw_error( "Cannot allocate storage for window data." );
- X return;
- X }
- X
- X /* Initialize counters */
- X
- X ret_struct->x1 = _x1 = x1;
- X ret_struct->y1 = _y1 = y1;
- X ret_struct->x2 = _x2 = x2;
- X ret_struct->y2 = _y2 = y2;
- X ret_struct->t_flag = t_flag;
- X ret_struct->t_bcolor = t_bcolor;
- X ret_struct->t_tcolor = t_tcolor;
- X ret_struct->s_flag = s_flag;
- X ret_struct->s_color = s_color;
- X ret_struct->b_flag = b_flag;
- X ret_struct->b_color = b_color;
- X ret_struct->m_color = m_color;
- X ret_struct->m_style = m_style;
- X
- X /* display the shadow */
- X
- X if ( s_flag == TRUE )
- X {
- X s_ysize = (SHADOW_XSIZE * gr_pxsize ) / gr_pysize;
- X ui_fbox( x1 + SHADOW_XSIZE, y1, x2, y2 - s_ysize,
- X s_color, SOLID );
- X _y1 += s_ysize;
- X _x2 -= SHADOW_XSIZE;
- X }
- X
- X /* draw a one-pixel black line around the whole area */
- X
- X gr_line( ui_screen, _x1, _y1, _x1, _y2, BLACK, SOLID );
- X gr_line( ui_screen, _x1, _y2, _x2, _y2, BLACK, SOLID );
- X gr_line( ui_screen, _x2, _y1, _x2, _y2, BLACK, SOLID );
- X gr_line( ui_screen, _x1, _y1, _x2, _y1, BLACK, SOLID );
- X
- X ++_x1;
- X ++_y1;
- X --_x2;
- X --_y2;
- X
- X /* display the title box */
- X
- X if ( t_flag != 0 )
- X {
- X
- X /* calculate size of the title bar */
- X
- X ret_struct->tbar_x1 = _x1;
- X ret_struct->tbar_y1 = _y2 - ( ui_grwind->fysize
- X + TITLE_YMARGIN + TITLE_YMARGIN );
- X ret_struct->tbar_x2 = _x2;
- X ret_struct->tbar_y2 = _y2;
- X _y2 = ret_struct->tbar_y1 - 1;
- X
- X /* blank the whole title bar area before buttons */
- X
- X gr_rectangle( ui_screen, ret_struct->tbar_x1, ret_struct->tbar_y1,
- X ret_struct->tbar_x2, ret_struct->tbar_y2, ret_struct->t_bcolor,
- X SOLID );
- X
- X ret_struct->ti_x1 = ret_struct->tbar_x1;
- X ret_struct->ti_y1 = ret_struct->tbar_y1;
- X ret_struct->ti_x2 = ret_struct->tbar_x2;
- X ret_struct->ti_y2 = ret_struct->tbar_y2;
- X
- X ret_struct->buttons = buttons;
- X
- X /* calculate close button area and display the button */
- X
- X if ( ( buttons & BUT_CLOSE ) > 0 )
- X {
- X ret_struct->bt_x1 = ret_struct->ti_x1 + ui_grwind->fxsize;
- X ret_struct->bt_y1 = ret_struct->ti_y1 + TITLE_YMARGIN;
- X ret_struct->bt_x2 = ret_struct->ti_x1
- X + ( ui_grwind->fxsize * 3 );
- X ret_struct->bt_y2 = ret_struct->ti_y2 - TITLE_YMARGIN;
- X ret_struct->ti_x1 = ret_struct->bt_x2 + 1;
- X ui_pbmcenter( ui_screen, ret_struct->bt_x1, ret_struct->bt_y1,
- X ret_struct->bt_x2, ret_struct->bt_y2, &ui_clicon );
- X }
- X
- X /* calculate move button area and display the button */
- X
- X if ( ( buttons & BUT_MOVE ) > 0 )
- X {
- X ret_struct->mv_x1 = ret_struct->ti_x2 - ( ui_grwind->fxsize * 3 );
- X ret_struct->mv_y1 = ret_struct->ti_y1 + TITLE_YMARGIN;
- X ret_struct->mv_x2 = ret_struct->ti_x2 - 2;
- X ret_struct->mv_y2 = ret_struct->ti_y2 - TITLE_YMARGIN;
- X ret_struct->ti_x2 = ret_struct->mv_x1 - 1;
- X ui_pbmcenter( ui_screen, ret_struct->mv_x1, ret_struct->mv_y1,
- X ret_struct->mv_x2, ret_struct->mv_y2, &ui_mvicon );
- X }
- X
- X /* calculate resize button area and display the button */
- X
- X if ( ( buttons & BUT_RESIZE ) > 0 )
- X {
- X ret_struct->re_x1 = ret_struct->ti_x2 - ( ui_grwind->fxsize * 3 );
- X ret_struct->re_y1 = ret_struct->ti_y1 + TITLE_YMARGIN;
- X ret_struct->re_x2 = ret_struct->ti_x2 - 2;
- X ret_struct->re_y2 = ret_struct->ti_y2 - TITLE_YMARGIN;
- X ret_struct->ti_x2 = ret_struct->re_x1 - 1;
- X ui_pbmcenter( ui_screen, ret_struct->re_x1, ret_struct->re_y1,
- X ret_struct->re_x2, ret_struct->re_y2, &ui_reicon );
- X }
- X
- X /* Draw a line under the title bar */
- X
- X gr_line( ui_screen, x1, _y2, _x2, _y2, s_color, SOLID );
- X _y2 -= 1;
- X
- X /* Display the text */
- X
- X ui_wtitle( ret_struct, t_text );
- X
- X }
- X
- X /* display the main area */
- X
- X ui_fbox( _x1, _y1, _x2, _y2, m_color, m_style );
- X
- X /* display the border */
- X
- X if ( b_flag == TRUE )
- X {
- X _x1 += BORDER_SIZE;
- X _y1 += BORDER_SIZE;
- X _x2 -= BORDER_SIZE;
- X _y2 -= BORDER_SIZE;
- X ui_hbox( _x1, _y1, _x2, _y2, b_color );
- X _x1 += 1;
- X _y1 += 1;
- X _x2 -= 1;
- X _y2 -= 1;
- X }
- X
- X /* return coordinates of usable area */
- X
- X ret_struct->u_x1 = _x1;
- X ret_struct->u_y1 = _y1;
- X ret_struct->u_x2 = _x2;
- X ret_struct->u_y2 = _y2;
- X return ret_struct;
- X
- X }
- X
- ui_rewindow( window, newtitle )
- X struct uiwindow *window;
- X char *newtitle;
- X {
- X static int _x1, _y1, _x2, _y2; /* counters for coordinates */
- X int s_ysize;
- X
- X if ( window == 0 )
- X {
- X return;
- X }
- X
- X _x1 = window->x1;
- X _y1 = window->y1;
- X _x2 = window->x2;
- X _y2 = window->y2;
- X
- X /* display the shadow */
- X
- X if ( window->s_flag != 0 )
- X {
- X s_ysize = (SHADOW_XSIZE * gr_pxsize ) / gr_pysize;
- X ui_fbox( window->x1 + SHADOW_XSIZE, window->y1,
- X window->x2, window->y2 - s_ysize,
- X window->s_color, 1 );
- X _y1 += s_ysize;
- X _x2 -= SHADOW_XSIZE;
- X }
- X
- X /* draw a one-pixel black line around the whole area */
- X
- X gr_line( ui_screen, _x1, _y1, _x1, _y2, BLACK, SOLID );
- X gr_line( ui_screen, _x1, _y2, _x2, _y2, BLACK, SOLID );
- X gr_line( ui_screen, _x2, _y1, _x2, _y2, BLACK, SOLID );
- X gr_line( ui_screen, _x1, _y1, _x2, _y1, BLACK, SOLID );
- X
- X ++_x1;
- X ++_y1;
- X --_x2;
- X --_y2;
- X
- X /* display the title box */
- X
- X if ( window->t_flag == TRUE )
- X {
- X
- X gr_rectangle( ui_screen, window->tbar_x1, window->tbar_y1,
- X window->tbar_x2, window->tbar_y2, window->t_bcolor,
- X SOLID );
- X
- X ui_wtitle( window, newtitle );
- X
- X /* Draw a line under the title bar */
- X
- X _y2 = window->tbar_y1;
- X _y2 -= 1;
- X gr_line( ui_screen, window->x1, _y2, _x2, _y2,
- X window->s_color, SOLID );
- X _y2 -= 1;
- X
- X /* display close button */
- X
- X if ( ( window->buttons & BUT_CLOSE ) > 0 )
- X {
- X ui_pbmcenter( ui_screen, window->bt_x1, window->bt_y1,
- X window->bt_x2, window->bt_y2, &ui_clicon );
- X }
- X
- X /* display move button */
- X
- X if ( ( window->buttons & BUT_MOVE ) > 0 )
- X {
- X ui_pbmcenter( ui_screen, window->mv_x1, window->mv_y1,
- X window->mv_x2, window->mv_y2, &ui_mvicon );
- X }
- X
- X /* display resize button */
- X
- X if ( ( window->buttons & BUT_RESIZE ) > 0 )
- X {
- X ui_pbmcenter( ui_screen, window->re_x1, window->re_y1,
- X window->re_x2, window->re_y2, &ui_reicon );
- X }
- X
- X }
- X
- X /* display the main area */
- X
- X ui_fbox( _x1, _y1, _x2, _y2, window->m_color, window->m_style );
- X
- X /* display the border */
- X
- X if ( window->b_flag != 0 )
- X {
- X _x1 += BORDER_SIZE;
- X _y1 += BORDER_SIZE;
- X _x2 -= BORDER_SIZE;
- X _y2 -= BORDER_SIZE;
- X ui_hbox( _x1, _y1, _x2, _y2, window->b_color );
- X }
- X
- X }
- X
- ui_fbox( x1, y1, x2, y2, color, style )
- X int x1, y1, x2, y2, color, style;
- X {
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "[pr:] ui_fbox(): %d %d %d %d", x1, y1, x2, y2 );
- X bw_error( bw_ebuf );
- #endif
- X gr_rectangle( ui_screen, x1, y1, x2, y2, color, style );
- X }
- X
- ui_hbox( x1, y1, x2, y2, color )
- X int x1, y1, x2, y2, color;
- X {
- X gr_rectangle( ui_screen, x1, y1, x2, y2, color, HOLLOW );
- X }
- X
- ui_wtitle( window, buffer )
- X struct uiwindow *window;
- X char *buffer;
- X {
- X
- X /* show the title bar */
- X
- X gr_rectangle( ui_screen, window->ti_x1, window->ti_y1,
- X window->ti_x2, window->ti_y2, window->t_bcolor,
- X SOLID );
- X
- X /* display the title text */
- X
- X ui_str( window->ti_x1 + ui_grwind->fxsize,
- X window->ti_y1 + TITLE_YMARGIN, window->ti_x2,
- X window->t_bcolor, window->t_tcolor, buffer );
- X
- X }
- SHAR_EOF
- chmod 0644 io/ui/ui_boxes.c ||
- echo 'restore of io/ui/ui_boxes.c failed'
- Wc_c="`wc -c < 'io/ui/ui_boxes.c'`"
- test 9808 -eq "$Wc_c" ||
- echo 'io/ui/ui_boxes.c: original size 9808, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/ui/ui_clock.c ==============
- if test -f 'io/ui/ui_clock.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/ui/ui_clock.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/ui/ui_clock.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_clock.c' &&
- /****************************************************************
- X
- X ui_clock.c Clock 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 "time.h"
- #include "gr.h"
- #include "ui.h"
- X
- #ifdef __STDC__
- #include "stdlib.h"
- #else
- #define time_t long
- extern char *getenv();
- #endif
- X
- /* #define USESMALLFONT */
- X
- int cl_initialized = FALSE;
- static int cl_x, cl_y, cl_fore, cl_back;
- static char clock_buf[ 36 ];
- static char env_buf[ 48 ];
- static int last_time;
- X
- ui_clinit( x, y, fore, back )
- X int x, y, fore, back;
- X {
- X static time_t now;
- X struct tm *clock_time;
- X register int c;
- X
- X time( &now );
- X clock_time = localtime( &now );
- X
- X if ( getenv( "TZ" ) == NULL )
- X {
- X strcpy( env_buf, "LOC" );
- X }
- X else
- X {
- X strcpy( env_buf, getenv( "TZ" ) );
- X }
- X
- X if ( clock_time->tm_isdst == 0 )
- X {
- X env_buf[ 3 ] = 0;
- X }
- X else
- X {
- X for ( c = 0; c < 4; ++c )
- X {
- X env_buf[ c ] = env_buf[ c + 4 ];
- X }
- X }
- X
- X cl_x = x;
- X cl_y = y;
- X cl_fore = fore;
- X cl_back = back;
- X cl_initialized = TRUE;
- X }
- X
- ui_clock()
- X {
- X static time_t now;
- #ifdef USESMALLFONT
- X int save_fysize, save_font;
- #endif
- X struct tm *clock_time;
- X
- X if ( cl_initialized == FALSE )
- X {
- X return FALSE;
- X }
- X
- X time( &now );
- X clock_time = localtime( &now );
- X
- X if ( clock_time->tm_min == last_time )
- X {
- X return TRUE;
- X }
- X
- #ifdef USESMALLFONT
- X save_fysize = ui_grwind->fysize;
- X save_font = ui_grwind->font;
- X gr_font( ui_screen, save_font, save_fysize * 4 );
- #endif
- X
- X last_time = clock_time->tm_min;
- X sprintf( clock_buf, "%02d:%02d %s",
- X clock_time->tm_hour, clock_time->tm_min, env_buf );
- X gr_text( ui_screen, cl_x,
- X cl_y, clock_buf, cl_fore, cl_back );
- X
- #ifdef USESMALLFONT
- X gr_font( ui_screen, save_font, save_fysize );
- #endif
- X
- X }
- X
- ui_clforce()
- X {
- X last_time = 63;
- X ui_clock();
- X }
- SHAR_EOF
- chmod 0644 io/ui/ui_clock.c ||
- echo 'restore of io/ui/ui_clock.c failed'
- Wc_c="`wc -c < 'io/ui/ui_clock.c'`"
- test 2853 -eq "$Wc_c" ||
- echo 'io/ui/ui_clock.c: original size 2853, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/ui/ui_dial.c ==============
- if test -f 'io/ui/ui_dial.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/ui/ui_dial.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/ui/ui_dial.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_dial.c' &&
- /****************************************************************
- X
- X ui_dial.c Dialog-box and alarm-box 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 "ui.h"
- X
- ui_dial( x1, y1, x2, y2, background, foreground, marker_color, shadow,
- X title, text, prompt, buffer, i_window )
- X int x1, y1, x2, y2, background, foreground, shadow, marker_color;
- X char *title, *text, *prompt, *buffer;
- X struct uiwindow **i_window;
- X {
- X static struct uiwindow *window;
- X register int x, y;
- X
- X /* Draw the box */
- X
- X if ( *i_window == NULL )
- X {
- X window = *i_window = ui_window( x1, y1, x2, y2, TRUE, background,
- X foreground, title, TRUE, BLACK,
- X shadow, BLACK, background, SOLID, BUT_CLOSE );
- X }
- X else
- X {
- X window = *i_window;
- X ui_rewindow( window, title );
- X }
- X
- X /* Write the text string to the box */
- X
- X ui_text( window->u_x1 + gr_strlen( " " ),
- X window->u_y1 + ( ui_grwind->fysize * 3 ),
- X window->u_x2, window->u_y2, 20, background, foreground,
- X text );
- X
- X /* Set array coordinates for prompt and entry string */
- X
- X x = window->u_x1 + gr_strlen( "======" );
- X y = window->u_y1 + ( ui_grwind->fysize * 2 );
- X
- X /* Display a marker */
- X
- X gr_circle( ui_screen, x,
- X y + ui_grwind->fysize / 2,
- X ui_grwind->fysize / 4, marker_color, SOLID );
- X x += ui_grwind->fysize * 2;
- X
- X /* Display the prompt string */
- X
- X ui_str( x, y, window->u_x2,
- X background, foreground, prompt );
- X x += gr_strlen( prompt );
- X
- X /* Get the string from the box */
- X
- X ui_gets( window, x, y, 64, buffer,
- X TRUE, foreground, background );
- X
- X }
- X
- ui_yn( x1, y1, x2, y2, background, foreground, marker_color, shadow,
- X text, mes0, mes1, i_window )
- X int x1, y1, x2, y2, background, foreground, shadow, marker_color;
- X char *text, *mes0, *mes1;
- X struct uiwindow **i_window;
- X {
- X static struct uiwindow *window;
- X register int x, y;
- X int y_x1, y_y1, y_x2, y_y2;
- X int n_x1, n_y1, n_x2, n_y2;
- X int carry_on, mo_xsrc, mo_ysrc, test, key;
- X static int x_pos, y_pos, b_stat;
- X
- X /* Draw the box */
- X
- X if ( *i_window == NULL )
- X {
- X window = *i_window = ui_window( x1, y1, x2, y2, FALSE, background,
- X foreground, "", 1, 0,
- X shadow, 0, background, 1, 0 );
- X }
- X else
- X {
- X window = *i_window;
- X ui_rewindow( window, "" );
- X }
- X
- X /* Write the text string to the box */
- X
- X ui_text( window->u_x1 + gr_strlen( " " ),
- X window->u_y1 + ( ui_grwind->fysize * 3 ),
- X window->u_x2, window->u_y2, 20, background, foreground,
- X text );
- X
- X /* Set array coordinates for capsules */
- X
- X x = window->u_x1 + (( window->u_x2 - window->u_x1 ) / 3 );
- X y = window->u_y1 + ( ui_grwind->fysize * 2 );
- X
- X y_x1 = x - ( gr_strlen( mes1 ) / 2 );
- X y_x2 = x + ( gr_strlen( mes1 ) / 2 );
- X
- X n_y1 = y_y1 = y;
- X n_y2 = y_y2 = y + (( ui_grwind->fysize * 3 ) / 2 );
- X
- X x = x + (( window->u_x2 - window->u_x1 ) / 3 );
- X n_x1 = x - ( gr_strlen( mes0 ) / 2 );
- X n_x2 = x + ( gr_strlen( mes0 ) / 2 );
- X
- X /* show capsules and their text */
- X
- X uid_capsule( y_x1, y_y1, y_x2, y_y2, BLACK, SOLID );
- X uid_capsule( n_x1, n_y1, n_x2, n_y2, BLACK, SOLID );
- X
- X gr_text( ui_screen, y_x1,
- X y_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
- X mes1, background, foreground );
- X
- X gr_text( ui_screen, n_x1,
- X n_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
- X mes0, background, foreground );
- X
- X /* loop for response */
- X
- X carry_on = TRUE;
- X while ( carry_on == TRUE )
- X {
- X if ( kb_rxstat() == TRUE )
- X {
- X key = kb_rx();
- X
- X switch( key )
- X {
- X case 'Y':
- X case 'y':
- X return TRUE;
- X break;
- X case 'N':
- X case 'n':
- X return FALSE;
- X break;
- X default:
- X break;
- X }
- X }
- X
- X else if ( gr_ismouse == TRUE )
- X {
- X
- X if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat )
- X == TRUE )
- X {
- X key = 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 if ( test == TRUE )
- X {
- X if ( uil_bounds( x_pos, y_pos, y_x1, y_y1, y_x2, y_y2 ) == TRUE )
- X {
- X return TRUE;
- X }
- X else if ( uil_bounds( x_pos, y_pos, n_x1, n_y1, n_x2, n_y2 ) == TRUE )
- X {
- X return FALSE;
- X }
- X }
- X
- X test = FALSE;
- X }
- X
- X else
- X {
- X ui_poll();
- X }
- X }
- X
- X }
- X
- ui_alarm( x1, y1, x2, y2, background, foreground, marker_color, shadow,
- X text, prompt, i_window )
- X int x1, y1, x2, y2, background, foreground, shadow, marker_color;
- X char *text, *prompt;
- X struct uiwindow **i_window;
- X {
- X static struct uiwindow *window;
- X int y_x1, y_y1, y_x2, y_y2;
- X register int x, y;
- X int carry_on, mo_xsrc, mo_ysrc, test, key;
- X static int x_pos, y_pos, b_stat;
- X
- X /* Draw the box */
- X
- X if ( *i_window == NULL )
- X {
- X *i_window = window = ui_window( x1, y1, x2, y2, FALSE, background,
- X foreground, "", 1, 0,
- X shadow, 0, background, 1, 0 );
- X }
- X else
- X {
- X window = *i_window;
- X ui_rewindow( window, "" );
- X }
- X
- X /* Write the text string to the box */
- X
- X ui_text( window->u_x1 + gr_strlen( " " ),
- X window->u_y1 + ( ui_grwind->fysize * 3 ),
- X window->u_x2, window->u_y2, 20, background, foreground,
- X text );
- X
- X /* Set array coordinates for capsules */
- X
- X x = window->u_x1 + ((( window->u_x2 - window->u_x1 ) / 3 ) * 2 );
- X y = window->u_y1 + ( ui_grwind->fysize * 2 );
- X
- X y_x1 = x - ( gr_strlen( prompt ) / 2 );
- X y_x2 = x + ( gr_strlen( prompt ) / 2 );
- X
- X y_y1 = y;
- X y_y2 = y + (( ui_grwind->fysize * 3 ) / 2 );
- X
- X /* show capsule and text */
- X
- X uid_capsule( y_x1, y_y1, y_x2, y_y2, BLACK, SOLID );
- X
- X gr_text( ui_screen, y_x1,
- X y_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
- X prompt, background, foreground );
- X
- X /* loop for response */
- X
- X carry_on = TRUE;
- X while ( carry_on == TRUE )
- X {
- X if ( kb_rxstat() == TRUE )
- X {
- X key = kb_rx();
- X return key;
- X }
- X
- X else if ( gr_ismouse == TRUE )
- X {
- X
- X if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat )
- X == TRUE )
- X {
- X key = 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 if ( test == TRUE )
- X {
- X if ( uil_bounds( x_pos, y_pos, y_x1, y_y1, y_x2, y_y2 ) == TRUE )
- X {
- X return TRUE;
- X }
- X }
- X
- X test = FALSE;
- X }
- X
- X else
- X {
- X ui_poll();
- X }
- X }
- X
- X }
- X
- ui_disp( x1, y1, x2, y2, background, foreground, shadow, title, text,
- X i_window )
- X int x1, y1, x2, y2, background, foreground, shadow;
- X char *title, *text;
- X struct uiwindow **i_window;
- X {
- X static struct uiwindow *window;
- X
- X /* Draw the box */
- X
- X if ( *i_window == 0 )
- X {
- X *i_window = window = ui_window( x1, y1, x2, y2, TRUE, background,
- X foreground, title, 1, 0,
- X shadow, 0, background, 1, BUT_CLOSE );
- X }
- X else
- X {
- X window = *i_window;
- X ui_rewindow( window, title );
- X }
- X
- X /* Write the text string to the box */
- X
- X ui_text( window->u_x1 + gr_strlen( " " ),
- X window->u_y1 + ui_grwind->fysize,
- X window->u_x2, window->u_y2, 20, background, foreground,
- X text );
- X
- X }
- X
- uid_capsule( x1, y1, x2, y2, color, style )
- X int x1, y1, x2, y2, color, style;
- X {
- X int r, x, y;
- X
- X x = x1;
- X r = ((( y2 - y1 ) * 30 ) / 60 );
- X y = y1 + r;
- X gr_circle( ui_screen, x, y, r, color, style );
- X x = x2;
- X gr_circle( ui_screen, x, y, r, color, style );
- X ui_fbox( x1, y1, x2, y2, color, style );
- X
- X }
- SHAR_EOF
- chmod 0644 io/ui/ui_dial.c ||
- echo 'restore of io/ui/ui_dial.c failed'
- Wc_c="`wc -c < 'io/ui/ui_dial.c'`"
- test 9126 -eq "$Wc_c" ||
- echo 'io/ui/ui_dial.c: original size 9126, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/ui/ui_gets.c ==============
- if test -f 'io/ui/ui_gets.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/ui/ui_gets.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/ui/ui_gets.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_gets.c' &&
- /****************************************************************
- X
- X ui_gets.c gets function for
- X The Bywater Graphical User Interface
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- #include "ctype.h"
- #include "gr.h"
- #include "kb.h"
- #include "ui.h"
- X
- #define BACKSPACE 8
- #define CURSOR '_'
- X
- ui_wait()
- X {
- X register int carry_on;
- X static int x_pos, y_pos, b_stat;
- X
- X carry_on = TRUE;
- X while( carry_on == TRUE )
- X {
- X if ( kb_rxstat() == TRUE )
- X {
- X return kb_rx();
- X }
- X if ( gr_ismouse == TRUE )
- X {
- X if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat ) == TRUE )
- X {
- X gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
- X gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
- X return TRUE;
- X }
- X }
- X ui_poll();
- X }
- X }
- X
- ui_getch()
- X {
- X while( kb_rxstat() == FALSE )
- X {
- X ui_poll();
- X }
- X return kb_rx();
- X }
- X
- ui_gets( window, x, y, maxlength, buffer, display, foreground, background )
- X struct gr_window *window;
- X int x, y, maxlength, display, foreground, background;
- X char *buffer;
- X {
- X register int c, p;
- X char disp_string[ 128 ];
- X
- X if ( display == TRUE )
- X {
- X sprintf( disp_string, "%c", CURSOR );
- X gr_text( ui_screen, x, y, disp_string,
- X foreground, background );
- X }
- X
- X buffer[ 0 ] = 0;
- X c = p = 0;
- X while( ( c != CR ) && ( c != LF) && ( strlen( buffer ) < maxlength ))
- X {
- X c = ui_getch();
- X switch( c )
- X {
- X case BACKSPACE:
- X --p;
- X buffer[ p ] = 0;
- X break;
- X case CR:
- X case LF:
- X break;
- X default:
- X buffer[ p ] = c;
- X ++p;
- X buffer[ p ] = 0;
- X break;
- X }
- X if ( display == TRUE )
- X {
- X sprintf( disp_string, "%s%c ", buffer, CURSOR );
- X gr_text( ui_screen, x, y, disp_string,
- X foreground, background );
- X }
- X }
- X
- X if ( display == TRUE )
- X {
- X sprintf( disp_string, "%s ", buffer );
- X gr_text( ui_screen, x, y, disp_string,
- X foreground, background );
- X }
- X
- X }
- SHAR_EOF
- chmod 0644 io/ui/ui_gets.c ||
- echo 'restore of io/ui/ui_gets.c failed'
- Wc_c="`wc -c < 'io/ui/ui_gets.c'`"
- test 2866 -eq "$Wc_c" ||
- echo 'io/ui/ui_gets.c: original size 2866, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/ui/ui_icon.c ==============
- if test -f 'io/ui/ui_icon.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/ui/ui_icon.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/ui/ui_icon.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_icon.c' &&
- /****************************************************************
- X
- X ui_icon.c Icon-based Selection 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 "dr.h"
- #include "kb.h"
- #include "ui.h"
- X
- #define USESMALLFONT
- #define SMALLFONTSIZE 35
- X
- /****************************************************************
- X
- X ui_ficon() File selection -- icon-based
- X
- ****************************************************************/
- X
- ui_ficon( x1, y1, x2, y2, specifier, title, m_box,
- X 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 struct dir_ent **d_entries;
- X {
- X register int c, test;
- X int carry_on, mo_xsrc, mo_ysrc;
- X static int x_pos, y_pos, b_stat, item;
- X
- X uii_draw( x1, y1, x2, y2, specifier, title, m_box,
- X d_entries, max_entries,
- X background, foreground, highlight );
- X
- X uii_activate( m_box, 0 );
- 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 {
- X c = uii_event( m_box, c, mo_xsrc, mo_ysrc, x_pos, y_pos, &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 }
- X
- X uii_deactivate( m_box );
- X
- X return item;
- X
- X }
- X
- /****************************************************************
- X
- X uii_draw() - draw file selection icon area
- X
- ****************************************************************/
- X
- uii_draw( x1, y1, x2, y2, specifier, title, m_box,
- X 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 struct dir_ent **d_entries;
- X {
- X register int number, c;
- X int x, y;
- X int carry_on;
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "uii_draw(): %d %d %d %d", x1, y1, x2, y2 );
- X bw_debug( ui_tbuf );
- X sprintf( ui_tbuf, "uii_draw(): is_drawn = %d", m_box->is_drawn );
- X bw_debug( ui_tbuf );
- #endif
- 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 TK_ERROR;
- X }
- X
- X /* Find all entries */
- X
- X number = 1;
- X while( ( dr_next( d_entries[ number ] ) == TRUE )
- X && ( number < max_entries ))
- X {
- X ++number;
- X }
- X m_box->number = number;
- X
- X /* the following are performed only if the window has not been
- X redrawn -- programmer may force redrawing of the whole menu
- X box by setting the is_drawn int to 0 (FALSE) */
- X
- X if ( m_box->is_drawn != TRUE )
- X {
- X
- X /* draw the menu window */
- X
- X if ( m_box->window == NULL )
- X {
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "uii_draw(): ready to draw window" );
- X bw_debug( ui_tbuf );
- #endif
- X
- X m_box->window = ui_window( x1, y1, x2, y2,
- X TRUE, highlight, foreground,
- X title, TRUE, BLACK,
- X FALSE, BLACK, background, SOLID,
- X BUT_CLOSE | BUT_MOVE | BUT_RESIZE );
- X }
- X else
- X {
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "uii_draw(): redraw window" );
- X bw_debug( ui_tbuf );
- #endif
- X
- X ui_rewindow( m_box->window, title );
- X }
- X }
- X
- X /* on the other hand, if the menu box is not to be redrawn,
- X it should in any case be retitled */
- X
- X else
- X {
- X ui_wtitle( m_box->window, title );
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "uii_draw() found %d entries", m_box->number );
- X bw_debug( ui_tbuf );
- #endif
- X
- X /* save font style and size, then attempt to set small font */
- 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
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "uii_draw(): font_set" );
- X bw_debug( ui_tbuf );
- #endif
- X
- X /* assign colors to structure */
- X
- X m_box->fore = foreground;
- X m_box->back = background;
- X m_box->high = highlight;
- X
- X /* save d_titles */
- X
- X m_box->d_entries = d_entries;
- X m_box->max_entries = max_entries;
- X m_box->type = MENU_ICON;
- X
- X /* calculate icon size */
- X
- X m_box->xsize = gr_strlen( "123456789012345" );
- X m_box->ysize = ui_grwind->fysize * 4;
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "ui_ficon(): icon size calculated" );
- X bw_debug( ui_tbuf );
- #endif
- X
- X /* the sliders have to be redrawn only if the is_drawn int
- X is 0 (FALSE) */
- X
- X if ( m_box->is_drawn != TRUE )
- X {
- X uil_sliders( m_box );
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "ui_ficon(): sliders drawn" );
- X bw_debug( ui_tbuf );
- #endif
- X
- X /* abort if a single icon will not fit */
- X
- X if ( ( m_box->i_x2 - m_box->i_x1 ) < m_box->xsize )
- X {
- #ifdef USESMALLFONT
- X gr_font( ui_screen, m_box->save_font,
- X m_box->save_fysize );
- #endif
- X return TK_ERROR;
- X }
- X
- X if ( ( m_box->i_y2 - m_box->i_y1 ) < m_box->ysize )
- X {
- #ifdef USESMALLFONT
- X gr_font( ui_screen, m_box->save_font,
- X m_box->save_fysize );
- #endif
- X return TK_ERROR;
- X }
- X
- X /* calculate total number of icon spaces */
- X
- X m_box->x_items = m_box->x_logical =
- X ( m_box->i_x2 - m_box->i_x1 ) / m_box->xsize;
- X m_box->y_items =
- X ( m_box->i_y2 - m_box->i_y1 ) / m_box->ysize;
- X
- X /* set roughly equal x and y items if all cannot be shown */
- X
- X if ( ( m_box->x_items * m_box->y_items ) < m_box->number )
- X {
- X for ( x = m_box->x_items + 2; (x * x) < m_box->number; ++x )
- X {
- X }
- X --x;
- X m_box->x_logical = x;
- X }
- X
- X m_box->y_logical = m_box->number / m_box->x_logical;
- X if (( m_box->number % m_box->x_logical ) > 0 )
- X {
- X ++m_box->y_logical;
- X }
- X
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "ui_ficon() point 2" );
- X bw_debug( ui_tbuf );
- #endif
- 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->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
- #ifdef OLD_DEBUG
- X sprintf( ui_tbuf, "window: x1 = %d, y1 = %d, x2 = %d, y2 = %d, \nicon_xsize = %d, icon_ysize = %d, number = %d, x_items = %d, y_items = %d",
- X m_box->i_x1, m_box->i_y1, m_box->i_x2,
- X m_box->i_y2,
- X m_box->xsize, m_box->ysize, number, m_box->x_items, m_box->y_items );
- X bw_debug( ui_tbuf );
- X sprintf( ui_tbuf, "ui_ficon() point 3" );
- X bw_debug( ui_tbuf );
- #endif
- X
- X /* set initial values */
- X
- X m_box->current = m_box->x_start
- X = m_box->y_start = m_box->x_pos = m_box->y_pos = 0;
- X
- X /* Display each icon */
- X
- X uii_display( m_box );
- X
- X /* note that the menu box is now drawn */
- X
- X m_box->is_drawn = TRUE;
- X
- #ifdef USESMALLFONT
- X gr_font( ui_screen, m_box->save_font,
- X m_box->save_fysize );
- #endif
- X
- /* uil_exit( m_box ); */
- X
- X }
- X
- /****************************************************************
- X
- X uii_activate() Activate an icon menu box
- X
- ****************************************************************/
- X
- uii_activate( m_box, item )
- X struct menu_box *m_box;
- X int item;
- X {
- X register int x, y;
- X int carry_on;
- X
- #ifdef OLD_DEBUG
- X if ( m_box->d_entries == NULL )
- X {
- X bw_error( "Programmer error: menu box has not been drawn!" );
- X return FALSE;
- X }
- #endif
- 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 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_DEBUG
- 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 uii_display( m_box );
- X }
- X
- X /* show current item selected */
- X
- 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
- /****************************************************************
- X
- X uii_deactivate() Deactivate an icon menu box
- X
- ****************************************************************/
- X
- uii_deactivate( m_box )
- X struct menu_box *m_box;
- 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
- #ifdef USESMALLFONT
- X gr_font( ui_screen, m_box->save_font,
- X m_box->save_fysize );
- #endif
- X
- X }
- X
- /****************************************************************
- X
- X uii_event() Query if keyboard or mouse actions affect an icon
- X menu box
- X
- ****************************************************************/
- X
- uii_event( 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 switch( c )
- X {
- X
- X case CR:
- X case LF:
- X *item = m_box->current;
- X return EVENT_SELECTED;
- X break;
- X
- X case ESCAPE:
- X case TK_EXIT:
- X case MO_EXIT:
- X *item = m_box->current = TK_EXIT;
- X return EVENT_EXIT;
- X break;
- X
- X case KB_DOWN:
- X
- X /* First test to see if it is possible to move
- X down one line on the y axis */
- X
- X if ( m_box->current <
- X ( m_box->number - m_box->x_logical ))
- 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 /* show current item unselected */
- X
- X uii_icon( m_box, m_box->current, FALSE );
- X
- X /* advance current item and m_box->y_pos */
- X
- X m_box->current += m_box->x_logical;
- X ++m_box->y_pos;
- X
- X /* check to see if this will advance
- X past the visible lines in the icon
- X area */
- X
- X if ( m_box->y_pos == m_box->y_items )
- X {
- X ++m_box->y_start;
- X --m_box->y_pos;
- X uii_display( m_box );
- X }
- X
- X /* show current item selected */
- X
- X uii_icon( m_box, m_box->current, 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 KB_UP:
- X
- X /* First test to see if it is possible to move
- X up one line on the y axis */
- X
- X if ( m_box->current >= m_box->x_logical )
- 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 /* show current item unselected */
- X
- X uii_icon( m_box, m_box->current, FALSE );
- X
- X /* decrement current item and m_box->y_pos */
- X
- X m_box->current -= m_box->x_logical;
- X --m_box->y_pos;
- X
- X /* check to see if this will decrement
- X past the visible lines in the icon
- X area */
- X
- X if ( m_box->y_pos < 0 )
- X {
- X --m_box->y_start;
- X ++m_box->y_pos;
- X uii_display( m_box );
- X }
- X
- X /* show current item selected */
- X
- 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
- X *item = m_box->current;
- X return EVENT_CHANGE;
- X break;
- X
- X case KB_LEFT:
- X
- X /* First test to see if it is possible to move
- X left one column on the x axis */
- X
- X if ( ( m_box->current % m_box->x_logical ) > 0 )
- 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 /* show current item unselected */
- X
- X uii_icon( m_box, m_box->current, FALSE );
- X
- X /* decrement current item and m_box->x_pos */
- X
- X --m_box->current;
- X --m_box->x_pos;
- X
- X /* check to see if this will decrement
- X past the visible lines in the icon
- X area */
- X
- X if ( m_box->x_pos < 0 )
- X {
- X --m_box->x_start;
- X ++m_box->x_pos;
- X uii_display( m_box );
- X }
- X
- X /* show current item selected */
- X
- X uii_icon( m_box, m_box->current, 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 KB_RIGHT:
- X
- X /* First test to see if it is possible to move
- X right one column on the x axis */
- X
- X if ( (( m_box->current % m_box->x_logical ) <
- X ( m_box->x_logical - 1 )) &&
- X ( m_box->current < ( m_box->number-1 ) ))
- 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 /* show current item unselected */
- X
- X uii_icon( m_box, m_box->current,
- X FALSE );
- X
- X /* increment current item and m_box->x_pos */
- X
- X ++m_box->current;
- X ++m_box->x_pos;
- X
- X /* check to see if this will increment
- X past the visible lines in the icon
- X area */
- X
- X if ( m_box->x_pos >= m_box->x_items )
- X {
- X ++m_box->x_start;
- X --m_box->x_pos;
- X uii_display( m_box );
- X }
- X
- X /* show current item selected */
- X
- X uii_icon( m_box, m_box->current,
- 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_UP:
- X
- X /* first see if it is possible to move up
- X at all */
- X
- X if (( m_box->y_start > 0 ) && ( how_far > 0 ))
- 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 /* decrement how_far to an acceptable
- X number */
- X
- X while ( ( m_box->y_start - how_far ) < 0 )
- X {
- X --how_far;
- X }
- X
- X /* assign new values to m_box->y_start and
- X m_box->current */
- X
- X m_box->y_start -= how_far;
- X m_box->current -= how_far * m_box->x_logical;
- X
- X /* display all icons visible */
- X
- X uii_display( m_box );
- X
- X /* display currently selected icon */
- X
- X uii_icon( m_box, m_box->current,
- 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_DN:
- X
- X /* first see if it is possible to move down
- X at all */
- X
- X if (( m_box->y_start <
- X ( m_box->y_logical - m_box->y_items ) )
- X && ( how_far > 0 ))
- 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 /* increment how_far to an acceptable
- X number */
- X
- X while ( ( m_box->y_start + how_far ) >
- X ( m_box->y_logical
- X - m_box->y_items ))
- X {
- X --how_far;
- X }
- X
- X /* assign new values to m_box->y_start and
- X m_box->current */
- X
- X m_box->y_start += how_far;
- X m_box->current += how_far * m_box->x_logical;
- X
- X /* display all icons visible */
- X
- X uii_display( m_box );
- X
- X /* display currently selected icon */
- X
- X uii_icon( m_box, m_box->current,
- 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_RIGHT:
- X
- X /* first see if it is possible to move right
- X at all */
- X
- X if (( m_box->x_start <
- X ( m_box->x_logical - m_box->x_items ) )
- X && ( how_far > 0 ))
- 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 /* increment how_far to an acceptable
- X number */
- X
- X while ( ( m_box->x_start + how_far ) >
- X ( m_box->x_logical
- X - m_box->x_items ))
- X {
- X --how_far;
- X }
- X
- X /* assign new values to m_box->x_start and
- X m_box->current */
- X
- X m_box->x_start += how_far;
- X m_box->current += how_far;
- X
- X /* display all icons visible */
- X
- X uii_display( m_box );
- X
- X /* display currently selected icon */
- X
- X uii_icon( m_box, m_box->current,
- 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_LEFT:
- X
- X /* first see if it is possible to move left
- X at all */
- X
- X if (( m_box->x_start > 0 ) && ( how_far > 0 ))
- 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 /* decrement how_far to an acceptable
- X number */
- X
- X while ( ( m_box->x_start - how_far ) < 0 )
- X {
- X --how_far;
- X }
- X
- X /* assign new values to m_box->x_start and
- X m_box->current */
- X
- X m_box->x_start -= how_far;
- X m_box->current -= how_far;
- X
- X /* display all icons visible */
- X
- X uii_display( m_box );
- X
- X /* display currently selected icon */
- X
- X uii_icon( m_box, m_box->current,
- SHAR_EOF
- true || echo 'restore of io/ui/ui_icon.c failed'
- fi
- echo 'End of part 8'
- echo 'File io/ui/ui_icon.c is continued in part 9'
- echo 9 > _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.
-