home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume27 / sfs / part10 < prev    next >
Encoding:
Text File  |  1991-12-27  |  55.2 KB  |  2,168 lines

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  3. Subject:  v27i010:  sfs - Space Flight Simulator, Part10/21
  4. Message-ID: <1991Dec24.191522.20578@sparky.imd.sterling.com>
  5. X-Md4-Signature: dab3c2e71feb4339a67498ea5b8efa23
  6. Date: Tue, 24 Dec 1991 19:15:22 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  10. Posting-number: Volume 27, Issue 10
  11. Archive-name: sfs/part10
  12. Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11,
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file io/ui/ui_pbm.c continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 10; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping io/ui/ui_pbm.c'
  32. else
  33. echo 'x - continuing file io/ui/ui_pbm.c'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'io/ui/ui_pbm.c' &&
  35. X    and software based on it under the following conditions:
  36. X    (a) in general, the code and software based upon it may be 
  37. X    used by individuals and by non-profit organizations; (b) it
  38. X    may also be utilized by governmental agencies in any country,
  39. X    with the exception of military agencies; (c) the code and/or
  40. X    software based upon it may not be sold for a profit without
  41. X    an explicit and specific permission from the author, except
  42. X    that a minimal fee may be charged for media on which it is
  43. X    copied, and for copying and handling; (d) the code must be 
  44. X    distributed in the form in which it has been released by the
  45. X    author; and (e) the code and software based upon it may not 
  46. X    be used for illegal activities. 
  47. X
  48. ***************************************************************/
  49. X
  50. X
  51. #include "stdio.h"
  52. #include "ctype.h"
  53. X
  54. #ifdef  __STDC__
  55. #include "malloc.h"
  56. #include "stdlib.h"
  57. #else
  58. extern char * malloc();
  59. #include "math.h"
  60. #endif
  61. X
  62. #include "bw.h"
  63. #include "gr.h"
  64. #include "ui.h"
  65. X
  66. #define BUFSIZE 128
  67. #define TESTINT 0
  68. #define ACC 50
  69. X
  70. extern char *pbm_fgets();
  71. X
  72. ui_pbmread( file, pmstruct, foreground, background )
  73. X   char *file;
  74. X   struct pbm_struct *pmstruct;
  75. X   int foreground, background;
  76. X   {
  77. X   FILE *fp;
  78. X   char *p;
  79. X   static int w, h, i, ctr;
  80. X   register int x, y;
  81. X   static char tbuf[ BW_EBUFSIZE ];
  82. X
  83. X   if ( ( fp = fopen( file, "r" ) ) == NULL )
  84. X      {
  85. X      strcpy( tbuf, ui_fontpath );
  86. X      strcat( tbuf, file );
  87. X      if ( ( fp = fopen( tbuf, "r" ) ) == NULL )
  88. X     {
  89. X     strcpy( tbuf, "../../fonts/" );
  90. X     strcat( tbuf, file );
  91. X     if ( ( fp = fopen( tbuf, "r" ) ) == NULL )
  92. X        {
  93. #ifdef OLD_DEBUG
  94. X        fprintf( stderr, "Failed to open file %s \n", file );
  95. #endif
  96. X        return FALSE;
  97. X        }
  98. X     }
  99. X      }
  100. X
  101. #ifdef OLD_DEBUG
  102. X   sprintf( bw_ebuf, "Opened: %s   ", file );
  103. X   bw_debug( bw_ebuf );
  104. #endif
  105. X
  106. X   /* Read first line to check for PBM magic number */
  107. X
  108. X   p = pbm_fgets( tbuf, BUFSIZE, fp );
  109. X   if ( tbuf[ 0 ] != 'P' )
  110. X      {
  111. #ifdef DEBUG
  112. X      sprintf( bw_ebuf, "File %s is not in PBM format", file );
  113. X      bw_error( bw_ebuf );
  114. #endif
  115. X      return BW_ERROR;
  116. X      }
  117. X   if ( tbuf[ 1 ] != '1' )
  118. X      {
  119. #ifdef DEBUG
  120. X      sprintf( bw_ebuf, "File %s is not in PBM format", file );
  121. X      bw_error( bw_ebuf );
  122. #endif
  123. X      return BW_ERROR;
  124. X      }
  125. X
  126. X   /* Read next line to get width and height */
  127. X
  128. X   p = pbm_fgets( tbuf, BUFSIZE, fp );
  129. X   sscanf( tbuf, "%d %d", &w, &h );
  130. X   pmstruct->xsize = w;
  131. X   pmstruct->ysize = h;
  132. X
  133. #ifdef OLD_DEBUG
  134. X   sprintf( bw_ebuf, "Sizes read: x: %03d  y: %03d   ", pmstruct->xsize, pmstruct->ysize );
  135. X   bw_debug( bw_ebuf );
  136. #endif
  137. X
  138. X   /* display the bitmap in hidden memory before getting image */
  139. X
  140. X   y = 0;
  141. X   while ( ( y < pmstruct->ysize ) && ( feof( fp ) == 0 ))
  142. X      {
  143. X      x = 0;
  144. X      p = pbm_fgets( tbuf, BUFSIZE, fp );
  145. X      ctr = 0;
  146. X      if ( p == NULL )
  147. X     {
  148. #ifdef DEBUG
  149. X     bw_error( "PBM file terminated prematurely" );
  150. #endif
  151. X     return FALSE;
  152. X     }
  153. X      while( ( x < pmstruct->xsize ) && ( tbuf[ ctr ] != '\n' ))
  154. X     {
  155. X     i = pbm_nextc( tbuf, &ctr );
  156. X     if ( i == 0 )
  157. X        {
  158. X        gr_pixel( GR_HIDDEN, x, ( pmstruct->ysize - y), background );
  159. X        }
  160. X     else if ( i == 1 )
  161. X        {
  162. X        gr_pixel( GR_HIDDEN, x, ( pmstruct->ysize - y), foreground );
  163. X        }
  164. X     ++x;
  165. X     }
  166. X      ++y;
  167. X      }
  168. X
  169. X   /* close the bitmap file */
  170. X
  171. X   fclose( fp );
  172. X
  173. X   /* save the image */
  174. X
  175. X   gr_imsave( GR_HIDDEN, TRUE, 0, 1, x - 1, y, &( pmstruct->image ) );
  176. X
  177. X   return TRUE;
  178. X
  179. X   }
  180. X
  181. ui_pbmshow( screen, x, y, pmstruct )
  182. X   int screen;
  183. X   int x, y;
  184. X   struct pbm_struct *pmstruct;
  185. X   {
  186. X
  187. X   if ( pmstruct == NULL )
  188. X      {
  189. #ifdef DEBUG
  190. X      bw_error( "ui_pmshow() received NULL pbm structure" );
  191. #endif
  192. X      return BW_ERROR;
  193. X      }
  194. X
  195. #ifdef OLD_DEBUG
  196. X   bw_debug( "Ready to show image" );
  197. #endif
  198. X   gr_imsave( screen, FALSE, x, y + 1, x + pmstruct->xsize - 1,
  199. X      y + pmstruct->ysize - 1, &( pmstruct->image ) );
  200. X
  201. X   }
  202. X
  203. char *
  204. pbm_fgets( string, n, stream )
  205. X   char *string;
  206. X   int n;
  207. X   FILE *stream;
  208. X   {
  209. X   register int c;
  210. X   char *p;
  211. X
  212. X   c = TRUE;
  213. X   while( c == TRUE )
  214. X      {
  215. X      p = fgets( string, n, stream );
  216. X      if ( p == NULL )
  217. X     {
  218. X     return NULL;
  219. X     }
  220. X      if ( string[ 0 ] != '#' )
  221. X     {
  222. #ifdef OLD_DEBUG
  223. X     sprintf( bw_ebuf, "read line <%s>", string );
  224. X     bw_debug( bw_ebuf );
  225. #endif
  226. X     return p;
  227. X     }
  228. X      }
  229. X   }
  230. X
  231. pbm_nextc( s, ctr )
  232. X   char *s;
  233. X   int *ctr;
  234. X   {
  235. X   static char tbuf[ 12 ];
  236. X   register int c;
  237. X
  238. #ifdef OLD_DEBUG
  239. X   bw_message( "entered pbm_nextc()" );
  240. #endif
  241. X
  242. X   while( isspace( s[ *ctr ] ) != FALSE )
  243. X      {
  244. X      ++*ctr;
  245. X      }
  246. X
  247. X   c = 0;
  248. X   while( isspace( s[*ctr ] ) == FALSE )
  249. X      {
  250. X      tbuf[ c ] = s[ *ctr ];
  251. X      ++*ctr;
  252. X      ++c;
  253. X      tbuf[ c ] = 0;
  254. X      }
  255. X
  256. #ifdef OLD_DEBUG
  257. X   sprintf( bw_ebuf, "read char %d", atoi( tbuf ) );
  258. X   bw_debug( bw_ebuf );
  259. #endif
  260. X
  261. X   return atoi( tbuf );
  262. X   }
  263. X
  264. ui_pbmcenter( screen, x1, y1, x2, y2, pmstruct )
  265. X   int screen;
  266. X   int x1, y1, x2, y2;
  267. X   struct pbm_struct *pmstruct;
  268. X   {
  269. X   register int x, y;
  270. X
  271. X   /* calculate coordinates */
  272. X
  273. X   x = x1 + ((( x2 - x1 ) - ( pmstruct->xsize )) / 2 );
  274. X   y = y1 + ((( y2 - y1 ) - ( pmstruct->ysize )) / 2 );
  275. X
  276. X   /* show the icon */
  277. X
  278. X   ui_pbmshow( screen, x, y, pmstruct );
  279. X
  280. X   }
  281. X
  282. ui_pbmtile( screen, x1, y1, x2, y2, pmstruct )
  283. X   int screen;
  284. X   int x1, y1, x2, y2;
  285. X   struct pbm_struct *pmstruct;
  286. X   {
  287. X   register int x, y;
  288. X   static int image;
  289. X
  290. X   /* check size */
  291. X
  292. X   if ( ( x2 - x1 ) < pmstruct->xsize )
  293. X      {
  294. #ifdef DEBUG
  295. X      sprintf( bw_ebuf, "Area too small: x1 %d x2 %d:  xsize %d",
  296. X     x1, x2, pmstruct->xsize );
  297. X      bw_error( bw_ebuf );
  298. #endif
  299. X      return BW_ERROR;
  300. X      }
  301. X
  302. X   if ( ( y2 - y1 ) < pmstruct->ysize )
  303. X      {
  304. #ifdef DEBUG
  305. X      sprintf( bw_ebuf, "Area too small: y1 %d y2 %d:  ysize %d",
  306. X     y1, y2, pmstruct->ysize );
  307. X      bw_error( bw_ebuf );
  308. #endif
  309. X      return BW_ERROR;
  310. X      }
  311. X
  312. #ifdef OLD_DEBUG
  313. X   sprintf( bw_ebuf, "x1 %d, y1 %d, x2, %d, y2 %d, xsize, %d, ysize %d",
  314. X      x1, y1, x2, y2, pmstruct->xsize, pmstruct->ysize );
  315. X   bw_debug( bw_ebuf );
  316. X   bw_message( "           " );
  317. #endif
  318. X
  319. X   /* fill area with tile except right and top areas */
  320. X
  321. X   for ( x = x1; x < ( x2 - pmstruct->xsize ); x += pmstruct->xsize )
  322. X      {
  323. X
  324. #ifdef OLD_DEBUG
  325. X      sprintf( bw_ebuf, "x = %d", x );
  326. X      bw_debug( bw_ebuf );
  327. X      bw_message( "           " );
  328. #endif
  329. X      for ( y = y1; y < ( y2 - pmstruct->ysize ); y += pmstruct->ysize )
  330. X     {
  331. #ifdef OLD_DEBUG
  332. X     sprintf( bw_ebuf, "y = %d", y );
  333. X     bw_debug( bw_ebuf );
  334. X     bw_message( "               " );
  335. #endif
  336. X     ui_pbmshow( screen, x, y, pmstruct );
  337. #ifdef OLD_DEBUG
  338. X     bw_debug( "icon displayed" );
  339. X     bw_message( "              " );
  340. #endif
  341. X     }
  342. X
  343. X      }
  344. X
  345. X   /* first the right remaining area */
  346. X
  347. X   if ( x != x2 )
  348. X      {
  349. X      gr_imsave( screen, TRUE, x1, y1, x1 + ( x2 - x ), y, &image );
  350. X      gr_imsave( screen, FALSE, x, y1, x2, y, &image );
  351. X      }
  352. X   gr_imfree( image );
  353. X
  354. X   /* then the top remaining area */
  355. X
  356. X   if ( y != y2 )
  357. X      {
  358. X      gr_imsave( screen, TRUE, x1, y1, x2, y1 + ( y2 - y ), &image );
  359. X      gr_imsave( screen, FALSE, x1, y, x2, y2, &image );
  360. X      }
  361. X   gr_imfree( image );
  362. X   }
  363. SHAR_EOF
  364. echo 'File io/ui/ui_pbm.c is complete' &&
  365. chmod 0644 io/ui/ui_pbm.c ||
  366. echo 'restore of io/ui/ui_pbm.c failed'
  367. Wc_c="`wc -c < 'io/ui/ui_pbm.c'`"
  368. test 7475 -eq "$Wc_c" ||
  369.     echo 'io/ui/ui_pbm.c: original size 7475, current size' "$Wc_c"
  370. rm -f _shar_wnt_.tmp
  371. fi
  372. # ============= io/ui/ui_rband.c ==============
  373. if test -f 'io/ui/ui_rband.c' -a X"$1" != X"-c"; then
  374.     echo 'x - skipping io/ui/ui_rband.c (File already exists)'
  375.     rm -f _shar_wnt_.tmp
  376. else
  377. > _shar_wnt_.tmp
  378. echo 'x - extracting io/ui/ui_rband.c (Text)'
  379. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_rband.c' &&
  380. X /***************************************************************
  381. X
  382. X    ui_rband.c      rubber-band routine for ui
  383. X
  384. X            Copyright (c) 1991, Ted A. Campbell
  385. X
  386. X            Bywater Software
  387. X            P. O. Box 4023 
  388. X            Duke Station 
  389. X            Durham, NC  27706
  390. X
  391. X            email: tcamp@hercules.acpub.duke.edu
  392. X
  393. X    Copyright and Permissions Information:
  394. X
  395. X    All U.S. and international copyrights are claimed by the
  396. X    author. The author grants permission to use this code
  397. X    and software based on it under the following conditions:
  398. X    (a) in general, the code and software based upon it may be 
  399. X    used by individuals and by non-profit organizations; (b) it
  400. X    may also be utilized by governmental agencies in any country,
  401. X    with the exception of military agencies; (c) the code and/or
  402. X    software based upon it may not be sold for a profit without
  403. X    an explicit and specific permission from the author, except
  404. X    that a minimal fee may be charged for media on which it is
  405. X    copied, and for copying and handling; (d) the code must be 
  406. X    distributed in the form in which it has been released by the
  407. X    author; and (e) the code and software based upon it may not 
  408. X    be used for illegal activities. 
  409. X
  410. ***************************************************************/
  411. X
  412. #include "stdio.h"
  413. #include "ctype.h"
  414. X
  415. #include "bw.h"
  416. #include "kb.h"
  417. #include "gr.h"
  418. #include "ui.h"
  419. X
  420. #ifdef __STDC__
  421. #include "malloc.h"
  422. #else
  423. extern char * malloc();
  424. #endif
  425. X
  426. #ifndef   __STDC__
  427. #define   time_t    long
  428. #define   size_t   int
  429. #endif
  430. X
  431. #define ERR_RBAND       "Memory error in ui_rband() routine"
  432. X
  433. ui_rband( mode, x1, y1, x2, y2 )
  434. X   int mode;
  435. X   int *x1, *y1, *x2, *y2;
  436. X   {
  437. X   static int left, right, top, bottom;
  438. X   static int b, k;
  439. X   static int y, x;             /* current position */
  440. X   static int yy, xx;           /* dummy arguments */
  441. X   int start_x, start_y;        /* start x, y, position */
  442. X   int prev_x, prev_y;          /* previous x, y position */
  443. X   int rxstat;                  /* receive status (keyboard or mouse) */
  444. X
  445. X   /* Check mode */
  446. X
  447. X   if ( mode != TRUE )
  448. X      {
  449. X      goto movebox;
  450. X      }
  451. X
  452. X   /*** RBAND FUNCTION TRUE: RUBBERBAND FOR VARIABLE_SIZED BOX ****/
  453. X
  454. X   /* save initial screen areas */
  455. X
  456. X   x = *x2;
  457. X   y = *y1;
  458. X   gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x1, *y2, &left );
  459. X   gr_imsave( GR_PRIMARY, TRUE, *x2, *y1, *x2, *y2, &right );
  460. X   gr_imsave( GR_PRIMARY, TRUE, *x1, *y2, *x2, *y2, &top );
  461. X   gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x2, *y1, &bottom );
  462. X
  463. X   /* reposition mouse to begin sizing */
  464. X
  465. X   if ( gr_ismouse == TRUE )
  466. X      {
  467. X      gr_mouse( POSITION, &x, &y, &b );
  468. X      }
  469. X
  470. X   /* draw the initial box */
  471. X
  472. X   gr_line( GR_PRIMARY, *x1, *y1, *x1, *y2, BLACK, SOLID );               /* left */
  473. X   gr_line( GR_PRIMARY, *x2, *y1, *x2, *y2, BLACK, SOLID );               /* right */
  474. X   gr_line( GR_PRIMARY, *x1, *y2, *x2, *y2, BLACK, SOLID );               /* top */
  475. X   gr_line( GR_PRIMARY, *x1, *y1, *x2, *y1, BLACK, SOLID );               /* bottom */
  476. X
  477. #ifdef  OLD_DEBUG
  478. X   sprintf( bw_ebuf, "gr_mouse( SAMPLE ) == %d     ",
  479. X      gr_mouse( SAMPLE, x2, y1, &b ) );
  480. X   bw_message( bw_ebuf );
  481. #endif
  482. X
  483. X   /* main rband loop: wait until first mouse click or RETURN */
  484. X
  485. X   if ( gr_ismouse == TRUE )
  486. X      {
  487. X      bw_message( " Use Mouse to Size Window, Click to Fix Size " );
  488. X      }
  489. X   else
  490. X      {
  491. X      bw_message( " Use Arrow Keys to Size Window, RETURN to Fix Size " );
  492. X      }
  493. X
  494. X   rxstat = FALSE;
  495. X   while ( rxstat != TRUE )
  496. X      {
  497. X
  498. X      if (( x != *x2 ) || ( y != *y1 ))
  499. X     {
  500. X
  501. X     /* restore old screen areas */
  502. X
  503. X     gr_imsave( GR_PRIMARY, FALSE, *x1, y, *x1, *y2, &left );
  504. X     gr_imsave( GR_PRIMARY, FALSE, x, y, x, *y2, &right );
  505. X     gr_imsave( GR_PRIMARY, FALSE, *x1, *y2, x, *y2, &top );
  506. X     gr_imsave( GR_PRIMARY, FALSE, *x1, y, x, y, &bottom );
  507. X
  508. X     /* release memory */
  509. X
  510. X     gr_imfree( top );
  511. X     gr_imfree( left );
  512. X     gr_imfree( bottom );
  513. X     gr_imfree( right );
  514. X
  515. X     /* check for position above or left of point */
  516. X
  517. X     if ( *x2 < *x1 )
  518. X        {
  519. X        *x2 = *x1;
  520. X        }
  521. X
  522. X     if ( *y1 > *y2 )
  523. X        {
  524. X        *y1 = *y2;
  525. X        }
  526. X
  527. X     /* save new screen areas */
  528. X
  529. X     gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x1, *y2, &left );
  530. X     gr_imsave( GR_PRIMARY, TRUE, *x2, *y1, *x2, *y2, &right );
  531. X     gr_imsave( GR_PRIMARY, TRUE, *x1, *y2, *x2, *y2, &top );
  532. X     gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x2, *y1, &bottom );
  533. X
  534. X     /* draw lines */
  535. X
  536. #ifdef OLD_DEBUG
  537. X         bw_message( "Drawing...      " );
  538. #endif
  539. X
  540. X     gr_line( GR_PRIMARY, *x1, *y1, *x1, *y2, BLACK, SOLID );               /* left */
  541. X     gr_line( GR_PRIMARY, *x2, *y1, *x2, *y2, BLACK, SOLID );               /* right */
  542. X     gr_line( GR_PRIMARY, *x1, *y2, *x2, *y2, BLACK, SOLID );               /* top */
  543. X     gr_line( GR_PRIMARY, *x1, *y1, *x2, *y1, BLACK, SOLID );               /* bottom */
  544. X
  545. X     x = *x2;
  546. X     y = *y1;
  547. X     }
  548. #ifdef OLD_DEBUG
  549. X      else
  550. X         {
  551. X         bw_message( "No change...      " );
  552. X         }
  553. #endif
  554. X
  555. X      /* check keyboard or mouse status */
  556. X
  557. X      if ( gr_ismouse == TRUE )
  558. X     {
  559. X     rxstat = gr_mouse( SAMPLE, x2, y1, &b );
  560. X     }
  561. X      else
  562. X     {
  563. X     if ( kb_rxstat() == TRUE )
  564. X        {
  565. X        k = kb_rx();
  566. X        switch (k)
  567. X           {
  568. X           case '\n':
  569. X           case '\r':
  570. X          rxstat = TRUE;
  571. X          break;
  572. X           case KB_UP:
  573. X          ++(*y1);
  574. X          break;
  575. X           case KB_DOWN:
  576. X          --(*y1);
  577. X          break;
  578. X           case KB_LEFT:
  579. X          --(*x2);
  580. X          break;
  581. X           case KB_RIGHT:
  582. X          ++(*x2);
  583. X          break;
  584. X           }
  585. X        }
  586. X     }
  587. X
  588. X      }                         /* end main rband loop */
  589. X
  590. X   /* wait until the mouse is released */
  591. X
  592. X   if ( gr_ismouse == TRUE )
  593. X      {
  594. X      gr_mouse( WAIT, &xx, &yy, &b );                /* down */
  595. X      gr_mouse( WAIT, &xx, &yy, &b );                /* up */
  596. X      }
  597. X
  598. #ifdef  OLD_DEBUG
  599. X   bw_message( "Loop Finished     " );
  600. #endif
  601. X
  602. X   /* restore old screen areas */
  603. X
  604. X   gr_imsave( GR_PRIMARY, FALSE, *x1, y, *x1, *y2, &left );
  605. X   gr_imsave( GR_PRIMARY, FALSE, x, y, x, *y2, &right );
  606. X   gr_imsave( GR_PRIMARY, FALSE, *x1, *y2, x, *y2, &top );
  607. X   gr_imsave( GR_PRIMARY, FALSE, *x1, y, x, y, &bottom );
  608. X
  609. X   /* release memory */
  610. X
  611. X   gr_imfree( top );
  612. X   gr_imfree( left );
  613. X   gr_imfree( bottom );
  614. X   gr_imfree( right );
  615. X
  616. X   goto end;
  617. X
  618. X   /*** RBAND FUNCTION NOT TRUE: MOVE FIXED_SIZE BOX ***/
  619. X
  620. X   movebox:
  621. X
  622. X   /* reposition the mouse */
  623. X
  624. X   start_x = x = *x2;
  625. X   start_y = y = *y1;
  626. X
  627. X   if ( gr_ismouse == TRUE )
  628. X      {
  629. X      gr_mouse( POSITION, &x, &y, &b );
  630. X      }
  631. X
  632. X   /* save the initial area */
  633. X
  634. X   gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x1, *y2, &left );
  635. X   gr_imsave( GR_PRIMARY, TRUE, *x2, *y1, *x2, *y2, &right );
  636. X   gr_imsave( GR_PRIMARY, TRUE, *x1, *y2, *x2, *y2, &top );
  637. X   gr_imsave( GR_PRIMARY, TRUE, *x1, *y1, *x2, *y1, &bottom );
  638. X
  639. X   /* show the initial rectangle */
  640. X
  641. X   gr_line( GR_PRIMARY, *x1, *y1, *x1, *y2, BLACK, SOLID );
  642. X   gr_line( GR_PRIMARY, *x2, *y1, *x2, *y2, BLACK, SOLID );
  643. X   gr_line( GR_PRIMARY, *x1, *y2, *x2, *y2, BLACK, SOLID );
  644. X   gr_line( GR_PRIMARY, *x1, *y1, *x2, *y1, BLACK, SOLID );
  645. X
  646. X   /* main rband loop */
  647. X
  648. X   prev_x = x = start_x;
  649. X   prev_y = y = start_y;
  650. X
  651. X   if ( gr_ismouse == TRUE )
  652. X      {
  653. X      bw_message( " Use Mouse to Move Window, Click to Fix Position " );
  654. X      }
  655. X   else
  656. X      {
  657. X      bw_message( " Use Arrow Keys to Move Window, RETURN to Fix Position " );
  658. X      }
  659. X
  660. X   rxstat = FALSE;
  661. X   while( rxstat != TRUE )
  662. X      {
  663. X
  664. X      if ( ( x != prev_x ) || ( y != prev_y ))
  665. X     {
  666. X
  667. X     /* restore the old area */
  668. X
  669. X     gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x1 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &left );
  670. X     gr_imsave( GR_PRIMARY, FALSE, *x2 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &right );
  671. X     gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &top );
  672. X     gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), &bottom );
  673. X
  674. X     /* release memory */
  675. X
  676. X     gr_imfree( top );
  677. X     gr_imfree( left );
  678. X     gr_imfree( bottom );
  679. X     gr_imfree( right );
  680. X
  681. X     /* check for position out of bounds */
  682. X
  683. X     if ( ( *x1 + ( x - start_x )) < 0 )
  684. X         {
  685. X         x = prev_x;
  686. X         }
  687. X     else if ( ( *x2 + ( x - start_x )) > ui_grwind->xmax )
  688. X         {
  689. X         x = prev_x;
  690. X         }
  691. X
  692. X     if ( ( *y1 + ( y - start_y )) < 0 )
  693. X         {
  694. X         y = prev_y;
  695. X         }
  696. X     else if ( ( *y2 + ( y - start_y )) > ui_grwind->ymax )
  697. X         {
  698. X         y = prev_y;
  699. X         }
  700. X
  701. X     /* save the new area */
  702. X
  703. X     gr_imsave( GR_PRIMARY, TRUE, *x1 + ( x - start_x ), *y1 + ( y - start_y ), *x1 + ( x - start_x ), *y2 + ( y - start_y ), &left );
  704. X     gr_imsave( GR_PRIMARY, TRUE, *x2 + ( x - start_x ), *y1 + ( y - start_y ), *x2 + ( x - start_x ), *y2 + ( y - start_y ), &right );
  705. X     gr_imsave( GR_PRIMARY, TRUE, *x1 + ( x - start_x ), *y2 + ( y - start_y ), *x2 + ( x - start_x ), *y2 + ( y - start_y ), &top );
  706. X     gr_imsave( GR_PRIMARY, TRUE, *x1 + ( x - start_x ), *y1 + ( y - start_y ), *x2 + ( x - start_x ), *y1 + ( y - start_y ), &bottom );
  707. X
  708. X     /* draw the new area */
  709. X
  710. X     gr_line( GR_PRIMARY, *x1 + ( x - start_x ), *y1 + ( y - start_y ), *x1 + ( x - start_x ), *y2 + ( y - start_y ), BLACK, SOLID );
  711. X     gr_line( GR_PRIMARY, *x2 + ( x - start_x ), *y1 + ( y - start_y ), *x2 + ( x - start_x ), *y2 + ( y - start_y ), BLACK, SOLID );
  712. X     gr_line( GR_PRIMARY, *x1 + ( x - start_x ), *y2 + ( y - start_y ), *x2 + ( x - start_x ), *y2 + ( y - start_y ), BLACK, SOLID );
  713. X     gr_line( GR_PRIMARY, *x1 + ( x - start_x ), *y1 + ( y - start_y ), *x2 + ( x - start_x ), *y1 + ( y - start_y ), BLACK, SOLID );
  714. X
  715. X     prev_x = x;
  716. X     prev_y = y;
  717. X     }
  718. X
  719. X      /* check keyboard or mouse status */
  720. X
  721. X      if ( gr_ismouse == TRUE )
  722. X     {
  723. X     rxstat = gr_mouse( SAMPLE, &x, &y, &b );
  724. X     }
  725. X      else
  726. X     {
  727. X     if ( kb_rxstat() == TRUE )
  728. X        {
  729. X        k = kb_rx();
  730. X        switch (k)
  731. X           {
  732. X           case '\n':
  733. X           case '\r':
  734. X          rxstat = TRUE;
  735. X          break;
  736. X           case KB_UP:
  737. X          ++y;
  738. X          break;
  739. X           case KB_DOWN:
  740. X          --y;
  741. X          break;
  742. X           case KB_LEFT:
  743. X          --x;
  744. X          break;
  745. X           case KB_RIGHT:
  746. X          ++x;
  747. X          break;
  748. X           }
  749. X        }
  750. X     }
  751. X
  752. X      }                                 /* end of main rband loop */
  753. X
  754. X   /* restore the old area */
  755. X
  756. X   gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x1 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &left );
  757. X   gr_imsave( GR_PRIMARY, FALSE, *x2 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &right );
  758. X   gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y2 + ( prev_y - start_y ), &top );
  759. X   gr_imsave( GR_PRIMARY, FALSE, *x1 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), *x2 + ( prev_x - start_x ), *y1 + ( prev_y - start_y ), &bottom );
  760. X
  761. X   /* release memory */
  762. X
  763. X   gr_imfree( top );
  764. X   gr_imfree( left );
  765. X   gr_imfree( bottom );
  766. X   gr_imfree( right );
  767. X
  768. X   /* get final mouse position */
  769. X
  770. X   if ( gr_ismouse == TRUE )
  771. X      {
  772. X      gr_mouse( WAIT, &x, &y, &b );        /* click down */
  773. X      gr_mouse( WAIT, &xx, &yy, &b );        /* click up */
  774. X      }
  775. X
  776. X   *x1 = *x1 + ( x - start_x );
  777. X   *x2 = *x2 + ( x - start_x );
  778. X   *y1 = *y1 + ( y - start_y );
  779. X   *y2 = *y2 + ( y - start_y );
  780. X
  781. X   end:
  782. X
  783. X   bw_message( " " );
  784. X
  785. X   return TRUE;
  786. X
  787. X   }
  788. X
  789. SHAR_EOF
  790. chmod 0644 io/ui/ui_rband.c ||
  791. echo 'restore of io/ui/ui_rband.c failed'
  792. Wc_c="`wc -c < 'io/ui/ui_rband.c'`"
  793. test 11199 -eq "$Wc_c" ||
  794.     echo 'io/ui/ui_rband.c: original size 11199, current size' "$Wc_c"
  795. rm -f _shar_wnt_.tmp
  796. fi
  797. # ============= io/ui/ui_test.c ==============
  798. if test -f 'io/ui/ui_test.c' -a X"$1" != X"-c"; then
  799.     echo 'x - skipping io/ui/ui_test.c (File already exists)'
  800.     rm -f _shar_wnt_.tmp
  801. else
  802. > _shar_wnt_.tmp
  803. echo 'x - extracting io/ui/ui_test.c (Text)'
  804. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_test.c' &&
  805. /***************************************************************
  806. X
  807. X    ui_test.c       Test GR and UI
  808. X
  809. X            Copyright (c) 1991, Ted A. Campbell
  810. X
  811. X            Bywater Software
  812. X            P. O. Box 4023 
  813. X            Duke Station 
  814. X            Durham, NC  27706
  815. X
  816. X            email: tcamp@hercules.acpub.duke.edu
  817. X
  818. X    Copyright and Permissions Information:
  819. X
  820. X    All U.S. and international copyrights are claimed by the
  821. X    author. The author grants permission to use this code
  822. X    and software based on it under the following conditions:
  823. X    (a) in general, the code and software based upon it may be 
  824. X    used by individuals and by non-profit organizations; (b) it
  825. X    may also be utilized by governmental agencies in any country,
  826. X    with the exception of military agencies; (c) the code and/or
  827. X    software based upon it may not be sold for a profit without
  828. X    an explicit and specific permission from the author, except
  829. X    that a minimal fee may be charged for media on which it is
  830. X    copied, and for copying and handling; (d) the code must be 
  831. X    distributed in the form in which it has been released by the
  832. X    author; and (e) the code and software based upon it may not 
  833. X    be used for illegal activities. 
  834. X
  835. ***************************************************************/
  836. X
  837. /* #define  TEST_TW */
  838. X
  839. #include "stdio.h"
  840. #ifdef    __STDC__
  841. #include "malloc.h"
  842. #else
  843. extern char *malloc();
  844. #define size_t int
  845. #endif
  846. #include "bw.h"
  847. #include "gr.h"
  848. #include "kb.h"
  849. #include "dr.h"
  850. #ifdef TEST_TW
  851. #include "tw.h"
  852. #endif
  853. #include "ui.h"
  854. X
  855. #define TITLESIZE    64
  856. #define MAXENTRIES      64
  857. X
  858. #define MM_ITEMS        12              /* items in main menu */
  859. X
  860. char bw_ebuf[ BW_EBUFSIZE ];
  861. X
  862. struct uiwindow *big_box, *little_box, *d_box;
  863. struct menu_box m_box;
  864. struct dir_ent *d_entries[ MAXENTRIES ];
  865. X
  866. char *d_titles[ MAXENTRIES ];
  867. X
  868. char *t_titles[] = {
  869. X   " Test Windows", 
  870. X   " Test Colors",
  871. X   " Test Styles", 
  872. X   " Dialog Box", 
  873. X   " Yes/No Box",
  874. X   " Alarm Box ",
  875. X   " Text File Selector",
  876. X   " Icon File Selector ",
  877. X   " Test Pixel Map ",
  878. X   " Test Rubberbanding ",
  879. #ifdef TEST_TW
  880. X   " Test GR Text Window ",
  881. #else
  882. X   " [UNAVAILABLE] ",
  883. #endif
  884. X   " Exit from Test" };
  885. X
  886. char tbuf[ 128 ];
  887. static char *buf;
  888. X
  889. main()
  890. X   {
  891. X   register int c, y;
  892. X   int x1, y1, item;
  893. X   
  894. X   /* Initialize the screen and keyboard */
  895. X
  896. X   /* Initialize the toolkit */
  897. X
  898. X   ui_init();
  899. X   if ( ui_grwind->initialized == FALSE )
  900. X      {
  901. X      printf( "The graphics system has not been initialized.\n" );
  902. X      return -1;
  903. X      }
  904. X
  905. X   /* get memory for directory/menu arrays */
  906. X
  907. X   for ( c = 0; c < MAXENTRIES; ++c )
  908. X      {
  909. X      if ( ( d_entries[ c ] =
  910. X         (struct dir_ent *) malloc( sizeof( struct dir_ent ))) == NULL )
  911. X         {
  912. X         gr_deinit();
  913. X         kb_deinit();
  914. X         fprintf( stderr, "Cannot allocate memory for directory structure %d \n", c );
  915. X         exit( 1 );
  916. X         }
  917. X      if ( ( d_titles[ c ] = malloc( TITLESIZE )) == NULL )
  918. X         {
  919. X         gr_deinit();
  920. X         kb_deinit();
  921. X         fprintf( stderr, "Cannot allocate memory for title array %d \n", c );
  922. X         exit( 1 );
  923. X         }
  924. X      }         
  925. X
  926. X   /* Clear the screen */
  927. X
  928. X   ui_setscreen( GR_HIDDEN );
  929. X   gr_cls( GR_HIDDEN );
  930. X
  931. #ifdef  OLD_DEBUG
  932. X   fprintf( stderr, "Ready to draw main box\n" );
  933. X   kb_rx();
  934. #endif
  935. X
  936. X   big_box = ui_window( 0, 0, ui_grwind->xmax, ui_grwind->ymax,
  937. X      TRUE, WHITE, BLACK,
  938. X      "A Test of the Bywater Graphical User Interface", FALSE, BLACK,
  939. X      FALSE, BLACK, WHITE, GRID, BUT_CLOSE | BUT_MOVE | BUT_RESIZE );
  940. X
  941. #ifdef  OLD_DEBUG
  942. X      fprintf( stderr, "Drew main box\n" );
  943. X      kb_rx();
  944. #endif
  945. X
  946. #ifdef OLD_DEBUG
  947. X   sprintf( bw_ebuf, "imsize = %lx", gr_imsize( big_box->u_x1, big_box->u_y1,
  948. X      big_box->u_x2, big_box->u_y2 ) );
  949. X   bw_debug( bw_ebuf );
  950. #endif
  951. X
  952. X   /* initialize the clock */
  953. X
  954. /*        ui_clinit( big_box->u_x1, big_box->u_y1, BLACK, WHITE ); */
  955. X
  956. X      /* blit to GR_PRIMARY and switch to primary screen */
  957. X
  958. X      gr_blit( GR_HIDDEN, GR_PRIMARY, 0, 0, ui_grwind->xmax,
  959. X     ui_grwind->ymax );
  960. X      ui_setscreen( GR_PRIMARY );
  961. #ifdef  OLD_DEBUG
  962. X      kb_rx();
  963. #endif
  964. X
  965. X      x1 = ui_grwind->xmax / 20;
  966. X      y1 = ui_grwind->ymax / 10;
  967. X
  968. X   /* main program loop, y == TRUE */
  969. X
  970. X   y = TRUE;
  971. X   m_box.is_drawn = FALSE;
  972. X   while( y == TRUE )
  973. X      {
  974. X
  975. #ifdef  OLD_DEBUG
  976. X      bw_message( "Ready to activate list box" );
  977. X      kb_rx();
  978. #endif
  979. X
  980. X      /* clear the user area */
  981. X
  982. X      ui_fbox( big_box->u_x1, big_box->u_y1, big_box->u_x2, big_box->u_y2,
  983. X     BLACK, SOLID );
  984. X      ui_fbox( big_box->u_x1, big_box->u_y1, big_box->u_x2, big_box->u_y2,
  985. X     WHITE, GRID );
  986. X
  987. X
  988. X      /* call the menu */
  989. X
  990. X      m_box.is_drawn = FALSE;
  991. X      item = ui_list( MENU_SLIDERS,
  992. X     x1 * 2, y1 * 4, x1 * 10, big_box->u_y2 - y1,
  993. X     "Test Options", MM_ITEMS, t_titles, BLACK, WHITE, WHITE,
  994. X     &m_box );
  995. X
  996. X      /* save the screen before executing */
  997. X
  998. #ifdef OLD_DEBUG
  999. X      sprintf( bw_ebuf, "big_box = %08lx, x1 = %d", (long) big_box,
  1000. X     big_box->u_x1 );
  1001. X      bw_debug( bw_ebuf );
  1002. X      bw_message( " " );
  1003. #endif
  1004. X
  1005. X      /* gr_save( GR_PRIMARY, TRUE, big_box->u_x1, big_box->u_y1,
  1006. X     big_box->u_x2, big_box->u_y2, buf ); */
  1007. X
  1008. X      /* evaluate the item chosen */
  1009. X
  1010. X      switch( item )
  1011. X         {
  1012. X         case 0:
  1013. X            windows();
  1014. X            break;
  1015. X         case 1:
  1016. X            colors();
  1017. X            break;
  1018. X         case 2:
  1019. X            styles();
  1020. X            break;
  1021. X         case 3:
  1022. X            dialog();
  1023. X            break;
  1024. X         case 4:
  1025. X            yes_no();
  1026. X            break;
  1027. X         case 5:
  1028. X            test_alarm();
  1029. X            break;
  1030. X         case 6:
  1031. X            text_file();
  1032. X            break;
  1033. X         case 7:
  1034. X            icon_file();
  1035. X            break;
  1036. X         case 8:
  1037. X        pixmap();
  1038. X        ui_wait();
  1039. X            break;
  1040. X         case 9:
  1041. X            test_rband();
  1042. X        break;
  1043. X     case 10:
  1044. #ifdef TEST_TW
  1045. X        test_tw();
  1046. #endif
  1047. X        break;
  1048. X         case TK_EXIT:
  1049. X     case 11:
  1050. X            y = FALSE;
  1051. X            break;
  1052. X         }
  1053. X
  1054. X      /* restore screen */
  1055. X
  1056. #ifdef OLD_DEBUG
  1057. X      sprintf( bw_ebuf, "big_box = %08lx, x1 = %d", (long) big_box,
  1058. X     big_box->u_x1 );
  1059. X      bw_debug( bw_ebuf );
  1060. X      bw_message( " " );
  1061. #endif
  1062. X
  1063. X      /* gr_save( GR_PRIMARY, FALSE, big_box->u_x1, big_box->u_y1,
  1064. X     big_box->u_x2, big_box->u_y2, buf ); */
  1065. X
  1066. X      }
  1067. X
  1068. X   /* Clear screen and restore prior state of computer */
  1069. X
  1070. X   gr_cls( GR_PRIMARY );
  1071. X   kb_deinit();
  1072. X   gr_deinit();
  1073. X
  1074. X   }
  1075. X
  1076. windows()
  1077. X   {
  1078. X   int x, y;
  1079. X
  1080. X   x = ui_grwind->xmax / 20;
  1081. X   y = ui_grwind->ymax / 10;
  1082. X   little_box = ui_window( x * 2, y, x * 14, y * 7, 1, 1, 0,
  1083. X      "A Full-Featured Window",
  1084. X      1, 0, 1, 0, 1, 1, BUT_CLOSE | BUT_MOVE | BUT_RESIZE );
  1085. X
  1086. X   ui_wait();
  1087. X
  1088. X   /* Experiment:  title too long */
  1089. X
  1090. X   little_box = ui_window( x * 2, y, x * 8, y * 5, TRUE, WHITE, BLACK,
  1091. X      "A Full-Featured Window with a Rather Extremely Long Title",
  1092. X      TRUE, BLACK, TRUE, BLACK, WHITE, SOLID, 0 );
  1093. X
  1094. X   ui_wait();
  1095. X
  1096. X   /* Write text to this window */
  1097. X
  1098. X   ui_text( little_box->u_x1, little_box->u_y1,
  1099. X      little_box->u_x2, little_box->u_y2, 
  1100. X      29, 1, 0, 
  1101. X      "This line of text has been written into this box utilizing the ui_text() function. We need to write a really long string to it\n" );
  1102. X
  1103. X   ui_wait();
  1104. X
  1105. X   }
  1106. X
  1107. colors()
  1108. X   {
  1109. X   register int c;
  1110. X   int x, y;
  1111. X
  1112. X   x = ui_grwind->xmax / 20;
  1113. X   y = ui_grwind->ymax / 10;
  1114. X
  1115. X   for ( c = 0; c < gr_colors; ++c )
  1116. X      {
  1117. X      sprintf( ui_tbuf, "This is color %d", c );
  1118. X      little_box = ui_window( x * 2, y, x * 14, y * 6, TRUE, WHITE,
  1119. X     BLACK, ui_tbuf,
  1120. X     TRUE, BLACK, TRUE, BLACK, c, SOLID, 0 );
  1121. X      ui_wait();
  1122. X      }
  1123. X
  1124. X
  1125. X   }
  1126. X
  1127. styles()
  1128. X   {
  1129. X   register int c;
  1130. X   int x, y;
  1131. X
  1132. X   x = ui_grwind->xmax / 20;
  1133. X   y = ui_grwind->ymax / 10;
  1134. X
  1135. X   for ( c = 0; c < 4; ++c )
  1136. X      {
  1137. X      sprintf( ui_tbuf, "This is style %d", c );
  1138. X      little_box = ui_window( x * 2, y, x * 14, y * 6, TRUE, WHITE,
  1139. X     BLACK, ui_tbuf, TRUE, BLACK, TRUE, BLACK, WHITE, c, 0 );
  1140. X      ui_wait();
  1141. X      }
  1142. X
  1143. X   }
  1144. X
  1145. dialog()
  1146. X   {
  1147. X   char d_buf[ 64 ];
  1148. X   int x, y;
  1149. X
  1150. X   x = ui_grwind->xmax / 20;
  1151. X   y = ui_grwind->ymax / 10;
  1152. X
  1153. X   ui_dial( x * 2, y, x * 14, y * 6, WHITE, BLACK, BLACK,
  1154. X      TRUE, "A Test Dialog Box",
  1155. X      "Please enter the name of your favorite saint \n(may be Orthodox or Catholic). No Anglicans accepted, or even Protestant or Evangelical Saints.  Thanks very much for your help.", 
  1156. X      "Your saint:  ", d_buf, &d_box );
  1157. X   sprintf( ui_tbuf, "Saint selected: %s ", d_buf );
  1158. X   ui_wtitle( d_box, ui_tbuf );
  1159. X   ui_wait();
  1160. X   }
  1161. X
  1162. yes_no()
  1163. X   {
  1164. X   int x, y, r;
  1165. X
  1166. X   x = ui_grwind->xmax / 20;
  1167. X   y = ui_grwind->ymax / 10;
  1168. X
  1169. X   r = ui_yn( x * 2, y, x * 14, y * 6, WHITE, BLACK, BLACK, TRUE,
  1170. X      "Do you want $ 1,000,000.00 in cash?", "  NO  ", "  YES  ",
  1171. X      &d_box );
  1172. X   }
  1173. X
  1174. test_alarm()
  1175. X   {
  1176. X   int x, y, r;
  1177. X
  1178. X   x = ui_grwind->xmax / 20;
  1179. X   y = ui_grwind->ymax / 10;
  1180. X
  1181. X   r = ui_alarm( x * 2, y, x * 14, y * 6, WHITE, BLACK, BLACK, TRUE,
  1182. X      "An alarm box like this would be used in case of a serious program or system problem.",
  1183. X      "  OK  ",
  1184. X      &d_box );
  1185. X   }
  1186. X
  1187. ui_poll()
  1188. X   {
  1189. /*        ui_clock(); */
  1190. X   }
  1191. X
  1192. bw_error( s )
  1193. X   char *s;
  1194. X   {
  1195. X   char buf[ BW_EBUFSIZE ];
  1196. X
  1197. X   sprintf( buf, "ERROR: %s   ", s );
  1198. X   gr_text( GR_PRIMARY, 5, 5, buf, BLACK, WHITE );
  1199. X   ui_wait();
  1200. X   }
  1201. X
  1202. #ifdef  DEBUG
  1203. bw_debug( s )
  1204. X   char *s;
  1205. X   {
  1206. X   char buf[ BW_EBUFSIZE ];
  1207. X
  1208. X   sprintf( buf, "DEBUG: %s     ", s );
  1209. X   gr_text( GR_PRIMARY, 5, 5, buf, BLACK, WHITE );
  1210. X   ui_wait();
  1211. X   }
  1212. X
  1213. #endif
  1214. X
  1215. bw_message( s )
  1216. X   char *s;
  1217. X   {
  1218. X   char buf[ BW_EBUFSIZE ];
  1219. X
  1220. X   sprintf( buf, "MESSAGE: %s   ", s );
  1221. X   gr_text( GR_PRIMARY, 5, 5, buf, BLACK, WHITE );
  1222. X   }
  1223. X
  1224. text_file()
  1225. X   {
  1226. X   static struct menu_box m_box;
  1227. X   int x, y, item;
  1228. X   register int c, test;
  1229. X
  1230. X   x = ui_grwind->xmax / 20;
  1231. X   y = ui_grwind->ymax / 10;
  1232. X
  1233. X   m_box.is_drawn = FALSE;
  1234. X   item = ui_ftext( x * 2, y * 2, x * 14, y * 7, dr_all, "File Selector Test",
  1235. X      &m_box, d_titles, d_entries, MAXENTRIES, WHITE, BLACK, WHITE );
  1236. X
  1237. X   if ( ( c != TK_ERROR ) && ( c != TK_EXIT ))
  1238. X      {
  1239. X      sprintf( ui_tbuf, "File selected: %s ",
  1240. X         d_entries[ item ]->filename );
  1241. X      ui_wtitle( m_box.window, ui_tbuf );
  1242. X      ui_wait();
  1243. X      }
  1244. X
  1245. X   }
  1246. X
  1247. icon_file()
  1248. X   {
  1249. X   static struct menu_box m_box;
  1250. X   int x, y, item;
  1251. X
  1252. X   x = ui_grwind->xmax / 20;
  1253. X   y = ui_grwind->ymax / 10;
  1254. X
  1255. X   m_box.is_drawn = FALSE;
  1256. X   item = ui_ficon( x * 3, y * 2, x * 13, y * 9, dr_all, "TEST: ui_ficon() ",
  1257. X      &m_box, d_entries, MAXENTRIES, WHITE, BLACK, WHITE );
  1258. X
  1259. X   if ( ( item != TK_ERROR ) && ( item != TK_EXIT ))
  1260. X      {
  1261. X      sprintf( ui_tbuf, "File selected: %s ",
  1262. X     d_entries[ item ]->filename );
  1263. X      ui_wtitle( m_box.window, ui_tbuf );
  1264. X      ui_wait();
  1265. X      }
  1266. X
  1267. X   }
  1268. X
  1269. pixmap()
  1270. X   {
  1271. X   static struct pbm_struct pmstruct;
  1272. X   int x, y;
  1273. X
  1274. X   x = ui_grwind->xmax / 20;
  1275. X   y = ui_grwind->ymax / 10;
  1276. X
  1277. X   ui_pbmread( "test.pbm", &pmstruct, WHITE, BLACK );
  1278. X
  1279. X   ui_pbmshow( GR_PRIMARY, x * 2, y * 2, &pmstruct );
  1280. X
  1281. X   }
  1282. X
  1283. test_rband()
  1284. X   {
  1285. X   static int x1, y1, x2, y2;
  1286. X   
  1287. X   /* fill the large area with grid */
  1288. X
  1289. X   ui_fbox( big_box->u_x1, big_box->u_y1, big_box->u_x2, big_box->u_y2, BLACK, SOLID );
  1290. X   ui_fbox( big_box->u_x1, big_box->u_y1, big_box->u_x2, big_box->u_y2, WHITE, GRID );
  1291. X
  1292. X   /* get a rubber band rectangle */
  1293. X
  1294. X   x1 = 20;
  1295. X   x2 = 200;
  1296. X   y1 = 20;
  1297. X   y2 = 200;
  1298. X   ui_rband( TRUE, &x1, &y1, &x2, &y2 );
  1299. X
  1300. X   ui_fbox( x1, y1, x2, y2, BLACK, SOLID );
  1301. X   ui_fbox( x1 + 1, y1 + 1, x2 - 1, y2 - 1, WHITE, SOLID );
  1302. X
  1303. X   bw_message( "Box now received: press a key or click to move it: " );
  1304. X   ui_wait();
  1305. X
  1306. X   /* move it */
  1307. X
  1308. X   ui_rband( FALSE, &x1, &y1, &x2, &y2 );
  1309. X
  1310. X   ui_fbox( x1, y1, x2, y2, BLACK, SOLID );
  1311. X   ui_fbox( x1 + 1, y1 + 1, x2 - 1, y2 - 1, WHITE, SOLID );
  1312. X
  1313. X   /* wait */
  1314. X
  1315. X   bw_message( " Box now moved; press a key or click for main menu" );
  1316. X   ui_wait();
  1317. X   
  1318. X   }
  1319. X
  1320. #ifdef TEST_TW
  1321. test_tw()
  1322. X   {
  1323. X   int c;
  1324. X   int x, y;
  1325. X   struct ui_twstruct *uibw;
  1326. X
  1327. X   x = ui_grwind->xmax / 20;
  1328. X   y = ui_grwind->ymax / 10;
  1329. X
  1330. X   uibw = ui_twinit( "Test Text Window",
  1331. X        x * 4, y * 6, 12, 52, 0, 0,
  1332. X        ui_grwind->xmax, ui_grwind->ymax );
  1333. X
  1334. X   tw_cursor( TRUE );
  1335. X
  1336. X   c = 0;
  1337. X   while ( c != 0x1b )
  1338. X      {
  1339. X      c = kb_rx();
  1340. X      tw_outc( c );
  1341. X      }
  1342. X
  1343. X   tw_cursor( FALSE );
  1344. X   }
  1345. X
  1346. #endif
  1347. X
  1348. SHAR_EOF
  1349. chmod 0644 io/ui/ui_test.c ||
  1350. echo 'restore of io/ui/ui_test.c failed'
  1351. Wc_c="`wc -c < 'io/ui/ui_test.c'`"
  1352. test 11977 -eq "$Wc_c" ||
  1353.     echo 'io/ui/ui_test.c: original size 11977, current size' "$Wc_c"
  1354. rm -f _shar_wnt_.tmp
  1355. fi
  1356. # ============= io/ui/ui_test.mak ==============
  1357. if test -f 'io/ui/ui_test.mak' -a X"$1" != X"-c"; then
  1358.     echo 'x - skipping io/ui/ui_test.mak (File already exists)'
  1359.     rm -f _shar_wnt_.tmp
  1360. else
  1361. > _shar_wnt_.tmp
  1362. echo 'x - extracting io/ui/ui_test.mak (Text)'
  1363. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_test.mak' &&
  1364. PROJ    =UI_TEST
  1365. DEBUG    =0
  1366. CC    =qcl
  1367. CFLAGS_G    = /AL /W1 /Ze /DDEBUG /I..\..\include 
  1368. CFLAGS_D    = /Zi /Zr /Gi$(PROJ).mdt /Od 
  1369. CFLAGS_R    = /O /Ot /DNDEBUG 
  1370. CFLAGS    =$(CFLAGS_G) $(CFLAGS_R)
  1371. LFLAGS_G    = /CP:0xffff /NOI /SE:0x80 /ST:0x800 
  1372. LFLAGS_D    = /CO /INCR 
  1373. LFLAGS_R    = 
  1374. LFLAGS    =$(LFLAGS_G) $(LFLAGS_R)
  1375. RUNFLAGS    =
  1376. OBJS_EXT =     
  1377. LIBS_EXT =     
  1378. X
  1379. all:    $(PROJ).exe
  1380. X
  1381. ui_boxes.obj:    ui_boxes.c
  1382. X
  1383. ui_clock.obj:    ui_clock.c
  1384. X
  1385. ui_dial.obj:    ui_dial.c
  1386. X
  1387. ui_gets.obj:    ui_gets.c
  1388. X
  1389. ui_icon.obj:    ui_icon.c
  1390. X
  1391. ui_init.obj:    ui_init.c
  1392. X
  1393. ui_list.obj:    ui_list.c
  1394. X
  1395. ui_test.obj:    ui_test.c
  1396. X
  1397. ui_text.obj:    ui_text.c
  1398. X
  1399. dr_ibmpc.obj:    ..\dr\dr_ibmpc.c
  1400. X
  1401. gr_ibmpc.obj:    ..\gr\gr_ibmpc.c
  1402. X
  1403. kb_ibmpc.obj:    ..\kb\kb_ibmpc.c
  1404. X
  1405. ui_rband.obj:    ui_rband.c
  1406. X
  1407. tw_ibmpc.obj:    ..\tw\tw_ibmpc.c
  1408. X
  1409. ui_tw.obj:    ui_tw.c
  1410. X
  1411. ui_pbm.obj:    ui_pbm.c
  1412. X
  1413. $(PROJ).exe:    ui_boxes.obj ui_clock.obj ui_dial.obj ui_gets.obj ui_icon.obj ui_init.obj \
  1414. X    ui_list.obj ui_test.obj ui_text.obj dr_ibmpc.obj gr_ibmpc.obj kb_ibmpc.obj ui_rband.obj \
  1415. X    tw_ibmpc.obj ui_tw.obj ui_pbm.obj $(OBJS_EXT)
  1416. X    echo >NUL @<<$(PROJ).crf
  1417. ui_boxes.obj +
  1418. ui_clock.obj +
  1419. ui_dial.obj +
  1420. ui_gets.obj +
  1421. ui_icon.obj +
  1422. ui_init.obj +
  1423. ui_list.obj +
  1424. ui_test.obj +
  1425. ui_text.obj +
  1426. dr_ibmpc.obj +
  1427. gr_ibmpc.obj +
  1428. kb_ibmpc.obj +
  1429. ui_rband.obj +
  1430. tw_ibmpc.obj +
  1431. ui_tw.obj +
  1432. ui_pbm.obj +
  1433. $(OBJS_EXT)
  1434. $(PROJ).exe
  1435. X
  1436. $(LIBS_EXT);
  1437. <<
  1438. X    link $(LFLAGS) @$(PROJ).crf
  1439. X
  1440. run: $(PROJ).exe
  1441. X    $(PROJ) $(RUNFLAGS)
  1442. X
  1443. SHAR_EOF
  1444. chmod 0644 io/ui/ui_test.mak ||
  1445. echo 'restore of io/ui/ui_test.mak failed'
  1446. Wc_c="`wc -c < 'io/ui/ui_test.mak'`"
  1447. test 1354 -eq "$Wc_c" ||
  1448.     echo 'io/ui/ui_test.mak: original size 1354, current size' "$Wc_c"
  1449. rm -f _shar_wnt_.tmp
  1450. fi
  1451. # ============= io/ui/ui_text.c ==============
  1452. if test -f 'io/ui/ui_text.c' -a X"$1" != X"-c"; then
  1453.     echo 'x - skipping io/ui/ui_text.c (File already exists)'
  1454.     rm -f _shar_wnt_.tmp
  1455. else
  1456. > _shar_wnt_.tmp
  1457. echo 'x - extracting io/ui/ui_text.c (Text)'
  1458. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_text.c' &&
  1459. /****************************************************************
  1460. X
  1461. X    ui_text.c       Text handling routines for
  1462. X            The Bywater Graphical User Interface
  1463. X
  1464. X            Copyright (c) 1991, Ted A. Campbell
  1465. X
  1466. X            Bywater Software
  1467. X            P. O. Box 4023
  1468. X            Duke Station
  1469. X            Durham, NC  27706
  1470. X
  1471. X            email: tcamp@hercules.acpub.duke.edu
  1472. X
  1473. X    Copyright and Permissions Information:
  1474. X
  1475. X    All U.S. and international copyrights are claimed by the
  1476. X    author. The author grants permission to use this code
  1477. X    and software based on it under the following conditions:
  1478. X    (a) in general, the code and software based upon it may be
  1479. X    used by individuals and by non-profit organizations; (b) it
  1480. X    may also be utilized by governmental agencies in any country,
  1481. X    with the exception of military agencies; (c) the code and/or
  1482. X    software based upon it may not be sold for a profit without
  1483. X    an explicit and specific permission from the author, except
  1484. X    that a minimal fee may be charged for media on which it is
  1485. X    copied, and for copying and handling; (d) the code must be
  1486. X    distributed in the form in which it has been released by the
  1487. X    author; and (e) the code and software based upon it may not
  1488. X    be used for illegal activities.
  1489. X
  1490. ****************************************************************/
  1491. X
  1492. #include "stdio.h"
  1493. #include "ctype.h"
  1494. #include "string.h"
  1495. #include "gr.h"
  1496. #include "bw.h"
  1497. #include "ui.h"
  1498. X
  1499. #define MAXBUF  128
  1500. #define PIXEL_SPACES    3
  1501. #define SAFETY_MARGIN   1
  1502. X
  1503. /* #define GRDIRECT */               /* use gr_text function from ui_text */
  1504. X                /* else use ui_str from ui_text */
  1505. X
  1506. ui_str( x1, y1, x2, background, foreground, buffer )
  1507. X   int x1, y1, x2, background, foreground;
  1508. X   char *buffer;
  1509. X   {
  1510. X   char buf[ MAXBUF ];
  1511. X   int y, c;
  1512. X
  1513. X   /* Write to buffer until overflow occurs */
  1514. X
  1515. X   c = 0;
  1516. X   y = FALSE;
  1517. X   buf[ 0 ] = 0;
  1518. X   while( y == FALSE )
  1519. X      {
  1520. X      buf[ c ] = buffer[ c ];
  1521. X      ++c;
  1522. X      buf[ c ] = 0;
  1523. X
  1524. X      if ( c >= MAXBUF )
  1525. X     {
  1526. X     y = TRUE;
  1527. X     }
  1528. X      else if ( gr_strlen( buf ) > ( x2 - x1 ) )
  1529. X     {
  1530. X     y = TRUE;
  1531. X     }
  1532. X      else if ( buffer[ c ] == 0 )
  1533. X     {
  1534. X     y = TRUE;
  1535. X     }
  1536. X      }
  1537. X
  1538. X   /* Now reverse until last whitespace */
  1539. X
  1540. X   --c;
  1541. X   if ( gr_strlen( buf ) > ( x2 - x1 ))
  1542. X      {
  1543. X      while( isspace( buf[ c ] ) == FALSE )
  1544. X     {
  1545. X     buf[ c ] = 0;
  1546. X     --c;
  1547. X     }
  1548. X      }
  1549. X
  1550. X   if ( isspace( buf[ c ] ) != FALSE )
  1551. X      {
  1552. X      buf[ c ] = 0;
  1553. X      }
  1554. X
  1555. X   /* Display the string in the appropriate colors */
  1556. X
  1557. X   gr_text( ui_screen, x1, y1, buf, foreground, background );
  1558. X   }
  1559. X
  1560. ui_text( x1, y1, x2, y2, maxlines, background, foreground, main_buffer )
  1561. X   int x1, y1, x2, y2;          /* Coordinates of box */
  1562. X   int maxlines;                /* Maximum lines to be used */
  1563. X   int background;              /* Background color */
  1564. X   int foreground;              /* Foreground color */
  1565. X   char *main_buffer;           /* Text buffer */
  1566. X   {
  1567. X   int l, c, y, main_pos, word_pos, lcount, line_pos, newline;
  1568. X   int line_start, line_end, word_start, word_end;
  1569. X   static char line_buffer[ 128 ];
  1570. X   static char word_buffer[ 64 ];
  1571. #ifdef  OLD_DEBUG
  1572. X   int X;
  1573. X   static char Dbuffer[ BW_EBUFSIZE ];
  1574. #endif
  1575. X
  1576. X   if ( ui_ready == FALSE )
  1577. X      {
  1578. X      bw_error( "The user interface is not initialized." );
  1579. X      return;
  1580. X      }
  1581. X
  1582. X   /* set initial values */
  1583. X
  1584. X   l = y2 - ( ui_grwind->fysize + PIXEL_SPACES );       /* l = location on y axis */
  1585. X   y = TRUE;                                    /* continue loop */
  1586. X   main_pos = 0;                                /* position in main buffer */
  1587. X   lcount = 0;                                  /* count of lines */
  1588. X   line_start = line_end = 0;
  1589. X
  1590. X   /* loop for each word detected */
  1591. X
  1592. X   while( y == TRUE )
  1593. X      {
  1594. X      newline = FALSE;
  1595. X
  1596. X      /* if l extends below the box, abort */
  1597. X
  1598. X      if ( l < y1 )
  1599. X     {
  1600. X     return;
  1601. X     }
  1602. X
  1603. X      /* if line count exceeds max allowed, abort */
  1604. X
  1605. X      if ( lcount >= maxlines )
  1606. X     {
  1607. X     return;
  1608. X     }
  1609. X
  1610. X      /* Get one word (up to white space or end) in buffer */
  1611. X
  1612. X      word_start = word_end = main_pos;
  1613. X      word_pos = 0;
  1614. X      word_buffer[ 0 ] = 0;
  1615. X      while( ( isspace( main_buffer[ main_pos ] ) == FALSE )
  1616. X     && ( main_buffer[ main_pos ] != 0 ))
  1617. X     {
  1618. X     word_buffer[ word_pos ] = main_buffer[ main_pos ];
  1619. X     ++word_end;
  1620. X     ++main_pos;
  1621. X     ++word_pos;
  1622. X     word_buffer[ word_pos ] = 0;                 /* terminate word with 0 */
  1623. X     }
  1624. X
  1625. X      /* Advance past any whitespace */
  1626. X
  1627. X      while ( ( isspace( main_buffer[ main_pos ] ) != FALSE )
  1628. X     && ( main_buffer[ main_pos ] != 0 ))
  1629. X     {
  1630. X     if ( main_buffer[ main_pos ] == '\n' )
  1631. X        {
  1632. X        newline = TRUE;
  1633. X        word_buffer[ word_pos ] = 0;
  1634. X        }
  1635. X     else
  1636. X        {
  1637. X        word_buffer[ word_pos ] = main_buffer[ main_pos ];
  1638. X        }
  1639. X     ++main_pos;
  1640. X     ++word_pos;
  1641. X     ++word_end;
  1642. X     word_buffer[ word_pos ] = 0;                 /* set end of buffer to 0 */
  1643. X     }
  1644. X
  1645. #ifdef  OLD_DEBUG
  1646. X      if ( gr_strlen( word_buffer ) > 100 )
  1647. X     {
  1648. X     sprintf( Dbuffer, "String element [%s]: may contain CR/LF",
  1649. X         word_buffer );
  1650. X     bw_debug( Dbuffer );
  1651. X     }
  1652. #endif
  1653. X
  1654. X      /* Get the current line into the buffer */
  1655. X
  1656. X      line_pos = 0;
  1657. X      line_buffer[ 0 ] = 0;
  1658. X      for ( c = line_start; c < line_end; ++c )
  1659. X     {
  1660. X     line_buffer[ line_pos ] = main_buffer[ c ];
  1661. X     ++line_pos;
  1662. X     line_buffer[ line_pos ] = 0;                   /* terminate with 0 */
  1663. X     }
  1664. X
  1665. #ifdef  OLD_DEBUG
  1666. X      sprintf( Dbuffer, "line_buffer [%s], word_buffer [%s]", line_buffer, word_buffer );
  1667. X      bw_debug( Dbuffer );
  1668. #endif
  1669. X
  1670. X      /* Now, what do we do with the word we have detected? */
  1671. X      /* 1. Check to see if new word will extend past limits */
  1672. X      /*    if so, output 'line_buffer' only, and make word the */
  1673. X      /*    new line_buffer */
  1674. X
  1675. X      if ( ( x1 + gr_strlen( line_buffer ) + gr_strlen( word_buffer ) ) >= ( x2 - SAFETY_MARGIN ))
  1676. X     {
  1677. #ifdef  OLD_DEBUG
  1678. X     sprintf( Dbuffer, "Flush line: x1 = %d, line = %d, word = %d",
  1679. X        x1, gr_strlen( line_buffer ), gr_strlen( word_buffer ) );
  1680. X     bw_debug( Dbuffer );
  1681. X     sprintf( Dbuffer, "Flush line: x1 + word + line = %d, x2 = %d",
  1682. X        x1 + gr_strlen( line_buffer ) + gr_strlen( word_buffer ), x2 );
  1683. X     bw_debug( Dbuffer );
  1684. X     sprintf( Dbuffer, "Flush line: strlen( line ) = %d",
  1685. X        strlen( line_buffer ) );
  1686. X     bw_debug( Dbuffer );
  1687. #endif
  1688. #ifdef  GRDIRECT
  1689. X     gr_text( ui_screen, x1, l, line_buffer, foreground,
  1690. X        background );
  1691. #else
  1692. X     ui_str( x1, l, x2, background, foreground, line_buffer );
  1693. #endif
  1694. X     ++lcount;
  1695. X     l -= ( ui_grwind->fysize + PIXEL_SPACES );
  1696. X
  1697. X     /* now make the current word the new line */
  1698. X
  1699. X     line_start = word_start;
  1700. X     line_end   = word_end;
  1701. X
  1702. X     }
  1703. X
  1704. X      /* 2. check to see if this is the end of the main buffer */
  1705. X      /*    if so, flush and return */
  1706. X
  1707. X      else if ( main_buffer[ main_pos ] == 0 )
  1708. X     {
  1709. X     strcat( line_buffer, word_buffer );
  1710. #ifdef  GRDIRECT
  1711. X     gr_text( ui_screen, x1, l, line_buffer,
  1712. X        foreground, background );
  1713. #else
  1714. X     ui_str( x1, l, x2, background, foreground, line_buffer );
  1715. #endif
  1716. X     return;
  1717. X     }
  1718. X
  1719. X      /* 3. check to see if a newline has been encountered; if so */
  1720. X      /*    output the current line */
  1721. X
  1722. X      else if ( newline == TRUE )
  1723. X     {
  1724. X
  1725. #ifdef  OLD_DEBUG
  1726. X     sprintf( bw_ebuf, "Got a newline after %s|%s",
  1727. X        line_buffer, word_buffer );
  1728. X     bw_debug( bw_ebuf );
  1729. #endif
  1730. X
  1731. X     strcat( line_buffer, word_buffer );
  1732. #ifdef  GRDIRECT
  1733. X     gr_text( ui_screen, x1, l, line_buffer,
  1734. X        foreground, background );
  1735. #else
  1736. X     ui_str( x1, l, x2, background, foreground, line_buffer );
  1737. #endif
  1738. X     ++lcount;
  1739. X     l -= ( ui_grwind->fysize + PIXEL_SPACES );
  1740. X     line_start = line_end = main_pos;
  1741. X     }
  1742. X
  1743. X      /* 4. else set end of current line to word_end and loop through */
  1744. X      /*    again to get another word */
  1745. X
  1746. X      else
  1747. X     {
  1748. X     line_end = word_end;
  1749. X     }
  1750. X      }
  1751. X   }
  1752. X
  1753. X
  1754. SHAR_EOF
  1755. chmod 0644 io/ui/ui_text.c ||
  1756. echo 'restore of io/ui/ui_text.c failed'
  1757. Wc_c="`wc -c < 'io/ui/ui_text.c'`"
  1758. test 7529 -eq "$Wc_c" ||
  1759.     echo 'io/ui/ui_text.c: original size 7529, current size' "$Wc_c"
  1760. rm -f _shar_wnt_.tmp
  1761. fi
  1762. # ============= io/ui/ui_tw.c ==============
  1763. if test -f 'io/ui/ui_tw.c' -a X"$1" != X"-c"; then
  1764.     echo 'x - skipping io/ui/ui_tw.c (File already exists)'
  1765.     rm -f _shar_wnt_.tmp
  1766. else
  1767. > _shar_wnt_.tmp
  1768. echo 'x - extracting io/ui/ui_tw.c (Text)'
  1769. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_tw.c' &&
  1770. /****************************************************************
  1771. X
  1772. X    ui_tw.c         Text Window Box under UI
  1773. X            The Bywater Graphical User Interface
  1774. X
  1775. X            Copyright (c) 1991, Ted A. Campbell
  1776. X
  1777. X            Bywater Software
  1778. X            P. O. Box 4023
  1779. X            Duke Station
  1780. X            Durham, NC  27706
  1781. X
  1782. X            email: tcamp@hercules.acpub.duke.edu
  1783. X
  1784. X    Copyright and Permissions Information:
  1785. X
  1786. X    All U.S. and international copyrights are claimed by the
  1787. X    author. The author grants permission to use this code
  1788. X    and software based on it under the following conditions:
  1789. X    (a) in general, the code and software based upon it may be
  1790. X    used by individuals and by non-profit organizations; (b) it
  1791. X    may also be utilized by governmental agencies in any country,
  1792. X    with the exception of military agencies; (c) the code and/or
  1793. X    software based upon it may not be sold for a profit without
  1794. X    an explicit and specific permission from the author, except
  1795. X    that a minimal fee may be charged for media on which it is
  1796. X    copied, and for copying and handling; (d) the code must be
  1797. X    distributed in the form in which it has been released by the
  1798. X    author; and (e) the code and software based upon it may not
  1799. X    be used for illegal activities.
  1800. X
  1801. ****************************************************************/
  1802. X
  1803. #include "stdio.h"
  1804. #include "bw.h"
  1805. #include "gr.h"
  1806. #include "tw.h"
  1807. #include "ui.h"
  1808. X
  1809. #ifdef  __STDC__
  1810. #include "malloc.h"
  1811. #else
  1812. extern  char * malloc();
  1813. #endif
  1814. X
  1815. struct ui_twstruct *
  1816. ui_twinit( title, rq_x1, rq_y2, rq_lines, rq_cols,
  1817. X       min_x1, min_y1, max_x2, max_y2 )
  1818. X   char *title;                 /* ttle for window */
  1819. X   int rq_x1;                   /* requested x1 (left, graphics) position */
  1820. X   int rq_y2;                   /* requested y2 (top,  graphics) position */
  1821. X   int rq_lines;                /* requested text lines */
  1822. X   int rq_cols;                 /* requested text columns */
  1823. X   int min_x1;                  /* leftmost   allowable position */
  1824. X   int min_y1;                  /* bottommost allowable position */
  1825. X   int max_x2;                  /* rightmost  allowable position */
  1826. X   int max_y2;                  /* topmost    allowable position */
  1827. X   {
  1828. X   static struct tw_struct *tw;
  1829. X   static struct ui_twstruct uitw;
  1830. X   static struct uiwindow *uiwind;
  1831. X
  1832. X   tw = tw_init( rq_x1 + 6, rq_y2 - ( ui_grwind->fysize + 8 ),
  1833. X         rq_lines, rq_cols,
  1834. X         min_x1, min_y1, max_x2, max_y2 );
  1835. X
  1836. #ifdef OLD_DEBUG
  1837. X   sprintf( bw_ebuf, "ui_twinit(): request box: x1 %d y1 %d x2 %d y1 %d",
  1838. X      tw->x1 - 3, tw->y1 - 3, tw->x2 + 3,
  1839. X      tw->y2 + ui_grwind->fysize + 2 );
  1840. X   bw_debug( bw_ebuf );
  1841. #endif
  1842. X
  1843. X   uiwind = ui_window( tw->x1 - 6, tw->y1 - 8, tw->x2 + 8,
  1844. X      tw->y2 + ui_grwind->fysize + 8, TRUE, WHITE, BLACK,
  1845. X      title,
  1846. X      TRUE, WHITE, TRUE, BLACK, BLACK, SOLID, BUT_CLOSE | BUT_MOVE | BUT_RESIZE  );
  1847. X
  1848. X   uitw.tw = tw;
  1849. X   uitw.uiw = uiwind;
  1850. X
  1851. X   return &uitw;
  1852. X
  1853. X   }
  1854. X
  1855. ui_twdeinit()
  1856. X   {
  1857. X   }
  1858. SHAR_EOF
  1859. chmod 0644 io/ui/ui_tw.c ||
  1860. echo 'restore of io/ui/ui_tw.c failed'
  1861. Wc_c="`wc -c < 'io/ui/ui_tw.c'`"
  1862. test 2839 -eq "$Wc_c" ||
  1863.     echo 'io/ui/ui_tw.c: original size 2839, current size' "$Wc_c"
  1864. rm -f _shar_wnt_.tmp
  1865. fi
  1866. # ============= io/ui/uitest_n.mak ==============
  1867. if test -f 'io/ui/uitest_n.mak' -a X"$1" != X"-c"; then
  1868.     echo 'x - skipping io/ui/uitest_n.mak (File already exists)'
  1869.     rm -f _shar_wnt_.tmp
  1870. else
  1871. > _shar_wnt_.tmp
  1872. echo 'x - extracting io/ui/uitest_n.mak (Text)'
  1873. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/uitest_n.mak' &&
  1874. PROJ    =UI_TEST
  1875. DEBUG    =0
  1876. CC    =qcl
  1877. CFLAGS_G    = /AL /W1 /Ze /DDEBUG /DTEST_TW /I..\..\include 
  1878. CFLAGS_D    = /Zi /Zr /Gi$(PROJ).mdt /Od 
  1879. CFLAGS_R    = /O /Ot /DNDEBUG 
  1880. CFLAGS    =$(CFLAGS_G) $(CFLAGS_R)
  1881. LFLAGS_G    = /CP:0xffff /NOI /SE:0x80 /ST:0x800 
  1882. LFLAGS_D    = /CO /INCR 
  1883. LFLAGS_R    = 
  1884. LFLAGS    =$(LFLAGS_G) $(LFLAGS_R)
  1885. RUNFLAGS    =
  1886. OBJS_EXT =     
  1887. LIBS_EXT =     
  1888. X
  1889. all:    $(PROJ).exe
  1890. X
  1891. ui_boxes.obj:    ui_boxes.c
  1892. X
  1893. ui_clock.obj:    ui_clock.c
  1894. X
  1895. ui_dial.obj:    ui_dial.c
  1896. X
  1897. ui_gets.obj:    ui_gets.c
  1898. X
  1899. ui_icon.obj:    ui_icon.c
  1900. X
  1901. ui_init.obj:    ui_init.c
  1902. X
  1903. ui_list.obj:    ui_list.c
  1904. X
  1905. ui_pbm.obj:    ui_pbm.c
  1906. X
  1907. ui_test.obj:    ui_test.c
  1908. X
  1909. ui_text.obj:    ui_text.c
  1910. X
  1911. ui_rband.obj:    ui_rband.c
  1912. X
  1913. ui_tw.obj:    ui_tw.c
  1914. X
  1915. dr_ibmpc.obj:    
  1916. X        $(CC) $(CFLAGS) -c ..\dr\dr_ibmpc.c
  1917. X
  1918. gr_ibmpc.obj:    
  1919. X        $(CC) $(CFLAGS) -c ..\gr\gr_ibmpc.c
  1920. X
  1921. kb_ibmpc.obj:    
  1922. X        $(CC) $(CFLAGS) -c ..\kb\kb_ibmpc.c
  1923. X
  1924. tw_ibmpc.obj:    
  1925. X        $(CC) $(CFLAGS) -c ..\tw\tw_ibmpc.c
  1926. X
  1927. $(PROJ).exe:    ui_boxes.obj ui_clock.obj ui_dial.obj ui_gets.obj \
  1928. X    ui_icon.obj ui_init.obj \
  1929. X    ui_list.obj ui_pbm.obj ui_test.obj ui_text.obj \
  1930. X    ui_rband.obj ui_tw.obj tw_ibmpc.obj \
  1931. X    dr_ibmpc.obj gr_ibmpc.obj kb_ibmpc.obj $(OBJS_EXT)
  1932. X    echo >NUL @<<$(PROJ).crf
  1933. ui_boxes.obj +
  1934. ui_clock.obj +
  1935. ui_dial.obj +
  1936. ui_gets.obj +
  1937. ui_icon.obj +
  1938. ui_init.obj +
  1939. ui_list.obj +
  1940. ui_pbm.obj +
  1941. ui_test.obj +
  1942. ui_text.obj +
  1943. ui_rband.obj +
  1944. ui_tw.obj +
  1945. tw_ibmpc.obj +
  1946. dr_ibmpc.obj +
  1947. gr_ibmpc.obj +
  1948. kb_ibmpc.obj +
  1949. $(OBJS_EXT)
  1950. $(PROJ).exe
  1951. X
  1952. $(LIBS_EXT);
  1953. <<
  1954. X    link $(LFLAGS) @$(PROJ).crf
  1955. X
  1956. run: $(PROJ).exe
  1957. X    $(PROJ) $(RUNFLAGS)
  1958. X
  1959. SHAR_EOF
  1960. chmod 0644 io/ui/uitest_n.mak ||
  1961. echo 'restore of io/ui/uitest_n.mak failed'
  1962. Wc_c="`wc -c < 'io/ui/uitest_n.mak'`"
  1963. test 1458 -eq "$Wc_c" ||
  1964.     echo 'io/ui/uitest_n.mak: original size 1458, current size' "$Wc_c"
  1965. rm -f _shar_wnt_.tmp
  1966. fi
  1967. # ============= io/ui/up.pbm ==============
  1968. if test -f 'io/ui/up.pbm' -a X"$1" != X"-c"; then
  1969.     echo 'x - skipping io/ui/up.pbm (File already exists)'
  1970.     rm -f _shar_wnt_.tmp
  1971. else
  1972. > _shar_wnt_.tmp
  1973. echo 'x - extracting io/ui/up.pbm (Text)'
  1974. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/up.pbm' &&
  1975. P1
  1976. # blank.pbm
  1977. 10 10
  1978. 0 0 0 0 0 0 0 0 0 0
  1979. 0 0 0 0 1 1 0 0 0 0
  1980. 0 0 0 0 1 1 0 0 0 0
  1981. 0 0 0 1 1 1 1 0 0 0
  1982. 0 0 0 1 1 1 1 0 0 0
  1983. 0 0 1 1 1 1 1 1 0 0
  1984. 0 0 1 1 1 1 1 1 0 0
  1985. 0 1 1 1 1 1 1 1 1 0
  1986. 0 1 1 1 1 1 1 1 1 0
  1987. 0 0 0 0 0 0 0 0 0 0
  1988. SHAR_EOF
  1989. chmod 0644 io/ui/up.pbm ||
  1990. echo 'restore of io/ui/up.pbm failed'
  1991. Wc_c="`wc -c < 'io/ui/up.pbm'`"
  1992. test 221 -eq "$Wc_c" ||
  1993.     echo 'io/ui/up.pbm: original size 221, current size' "$Wc_c"
  1994. rm -f _shar_wnt_.tmp
  1995. fi
  1996. # ============= sfs/as/as.h ==============
  1997. if test ! -d 'sfs'; then
  1998.     echo 'x - creating directory sfs'
  1999.     mkdir 'sfs'
  2000. fi
  2001. if test ! -d 'sfs/as'; then
  2002.     echo 'x - creating directory sfs/as'
  2003.     mkdir 'sfs/as'
  2004. fi
  2005. if test -f 'sfs/as/as.h' -a X"$1" != X"-c"; then
  2006.     echo 'x - skipping sfs/as/as.h (File already exists)'
  2007.     rm -f _shar_wnt_.tmp
  2008. else
  2009. > _shar_wnt_.tmp
  2010. echo 'x - extracting sfs/as/as.h (Text)'
  2011. sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as.h' &&
  2012. /***************************************************************
  2013. X
  2014. X    as.h        General header file
  2015. X            for astronomy (as) subsystem
  2016. X
  2017. X            Copyright (c) 1991, Ted A. Campbell
  2018. X
  2019. X            Bywater Software
  2020. X            P. O. Box 4023 
  2021. X            Duke Station 
  2022. X            Durham, NC  27706
  2023. X
  2024. X            email: tcamp@hercules.acpub.duke.edu
  2025. X
  2026. X    Copyright and Permissions Information:
  2027. X
  2028. X    All U.S. and international copyrights are claimed by the
  2029. X    author. The author grants permission to use this code
  2030. X    and software based on it under the following conditions:
  2031. X    (a) in general, the code and software based upon it may be 
  2032. X    used by individuals and by non-profit organizations; (b) it
  2033. X    may also be utilized by governmental agencies in any country,
  2034. X    with the exception of military agencies; (c) the code and/or
  2035. X    software based upon it may not be sold for a profit without
  2036. X    an explicit and specific permission from the author, except
  2037. X    that a minimal fee may be charged for media on which it is
  2038. X    copied, and for copying and handling; (d) the code must be 
  2039. X    distributed in the form in which it has been released by the
  2040. X    author; and (e) the code and software based upon it may not 
  2041. X    be used for illegal activities. 
  2042. X
  2043. ***************************************************************/
  2044. X
  2045. #define RAD_DEG         5.729577951e1   /* Convert radians to degrees   */
  2046. #define DEG_RAD         1.745329252e-2  /* Convert degrees to radians   */
  2047. #define PI              3.141592654     /* Value of PI                  */
  2048. #define UGC             (6.6631110e-23) /* Universal Gravitational Constant */
  2049. #define ELEPOCH         315532800       /* Epoch for calculating elapsed
  2050. X                       time, = 1980/01/01 00:00:00    */
  2051. X
  2052. #define    SPJ_NEARSIDE    0    /* near side only of spj calculations */
  2053. #define    SPJ_FARSIDE    1    /* far side only of spj calculations */
  2054. #define SPJ_ALLSIDES    2    /* calculate (show) near and far sides */
  2055. X
  2056. /* Minimum and Maximum Values for Orbital Elements */
  2057. X
  2058. #define OR_RAD_MIN      0       /* radius cannot be < 0 km */
  2059. #define OR_SID_MIN      0       /* sidereal day cannot be < 0 seconds */
  2060. #define OR_MAS_MIN      0.0     /* mass cannot be < 0.0 grams */
  2061. #define OR_INC_MIN      -180.0  /* inclination cannot be < -180.0 degrees */
  2062. #define OR_INC_MAX      180.0   /* inclination cannot be > 180.0 degrees */
  2063. #define OR_LAN_MIN      -180.0  /* longitude of asc. node cannot be < -180.0 degrees */
  2064. #define OR_LAN_MAX      180.0   /* longitude of asc. node cannot be > 180.0 degrees */
  2065. #define OR_ARP_MIN      -180.0  /* argument of perigee cannot be < -180.0 degrees */
  2066. #define OR_ARP_MAX      180.0   /* argument of perigee cannot be > 180.0 degrees */
  2067. #define OR_PER_MIN      0.0     /* period cannot be < 0.0 seconds */
  2068. #define OR_ECC_MIN      0.0     /* eccentricity cannot be < 0.0 */
  2069. #define OR_ECC_MAX      1.0     /* eccentricity cannot be > 1.0 */
  2070. X
  2071. struct as_focus
  2072. X   {
  2073. X   double       radius;         /* radius of orbital focus in kilometers */
  2074. X   double       sid_day;        /* sidereal period of orbital focus in seconds */
  2075. X   double       mass;           /* mass of orbital focus in kilograms */
  2076. X   char         *name;          /* pointer to name of orbital focus */
  2077. X   char         *adjective;     /* pointer to adjective for orbital focus */
  2078. X   char         *fdfile;        /* pointer to fd filename */
  2079. X   };
  2080. X
  2081. struct as_orbit
  2082. X   {
  2083. X   struct   as_focus   *focus; /* orbital focus */
  2084. X   double   apoapsis;          /* apoapsis of orbit in kilometers  */
  2085. X   double   periapsis;         /* periapsis of orbit in kilometers */
  2086. X   double   semimajor;         /* Semimajor axis in kilometers */
  2087. X   double   semiminor;         /* Semiminor axis in kilometers */
  2088. X   double   dist;              /* Focus to orbit distance in kilometers */
  2089. X   double   inclination;       /* Inclination in degrees */
  2090. X   double   eccentricity;      /* Eccentricity ( 0 < e <= 1 ) */
  2091. X   double   arg_per;           /* Argument of the periapsis in degrees */
  2092. X   double   lon_an;            /* Longitude of Ascending Node in degrees */
  2093. X   double   lif;               /* Longitude increment factor */
  2094. X   double   period;            /* Period of orbit in seconds */
  2095. X   };
  2096. X
  2097. struct spj_pt {
  2098. X   int    code;
  2099. X   double latitude;
  2100. X   double longitude;
  2101. X   double radius;
  2102. X   double x;
  2103. X   double y;
  2104. X   int    side;
  2105. X   char   *name;
  2106. X   struct spj_pt *next;
  2107. X   };
  2108. X
  2109. extern double   spj_meridian();
  2110. extern double   spj_angrad();
  2111. extern double   spj_degfix();
  2112. X
  2113. extern  char *as_fgets();
  2114. X
  2115. extern  double  as_lfix();
  2116. extern    double    vpt_sin();
  2117. extern    double    vpt_cos();
  2118. extern    double    vpt_tan();
  2119. extern  int    vpt_level;
  2120. SHAR_EOF
  2121. chmod 0644 sfs/as/as.h ||
  2122. echo 'restore of sfs/as/as.h failed'
  2123. Wc_c="`wc -c < 'sfs/as/as.h'`"
  2124. test 4503 -eq "$Wc_c" ||
  2125.     echo 'sfs/as/as.h: original size 4503, current size' "$Wc_c"
  2126. rm -f _shar_wnt_.tmp
  2127. fi
  2128. # ============= sfs/as/as_focus.c ==============
  2129. if test -f 'sfs/as/as_focus.c' -a X"$1" != X"-c"; then
  2130.     echo 'x - skipping sfs/as/as_focus.c (File already exists)'
  2131.     rm -f _shar_wnt_.tmp
  2132. else
  2133. > _shar_wnt_.tmp
  2134. echo 'x - extracting sfs/as/as_focus.c (Text)'
  2135. sed 's/^X//' << 'SHAR_EOF' > 'sfs/as/as_focus.c' &&
  2136. /****************************************************************
  2137. X
  2138. X    as_focus.c      Orbital focus routines
  2139. X            for astronomy (as) subsystem
  2140. X
  2141. X            Copyright (c) 1991, Ted A. Campbell
  2142. X
  2143. X            Bywater Software
  2144. X            P. O. Box 4023 
  2145. X            Duke Station 
  2146. X            Durham, NC  27706
  2147. X
  2148. X            email: tcamp@hercules.acpub.duke.edu
  2149. X
  2150. X    Copyright and Permissions Information:
  2151. X
  2152. X    All U.S. and international copyrights are claimed by the
  2153. X    author. The author grants permission to use this code
  2154. SHAR_EOF
  2155. true || echo 'restore of sfs/as/as_focus.c failed'
  2156. fi
  2157. echo 'End of  part 10'
  2158. echo 'File sfs/as/as_focus.c is continued in part 11'
  2159. echo 11 > _shar_seq_.tmp
  2160. exit 0
  2161. exit 0 # Just in case...
  2162. -- 
  2163. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2164. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2165. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2166. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2167.