home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume27 / sfs / part04 < prev    next >
Encoding:
Text File  |  1991-12-27  |  55.4 KB  |  2,082 lines

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  3. Subject:  v27i004:  sfs - Space Flight Simulator, Part04/21
  4. Message-ID: <1991Dec24.045237.29640@sparky.imd.sterling.com>
  5. X-Md4-Signature: 64fb49892016f3a4c9ddd1b8946762c1
  6. Date: Tue, 24 Dec 1991 04:52:37 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 4
  11. Archive-name: sfs/part04
  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/gr/gr_tam.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" != 4; 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/gr/gr_tam.c'
  32. else
  33. echo 'x - continuing file io/gr/gr_tam.c'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'io/gr/gr_tam.c' &&
  35. X         (unsigned short) abs(x2 - x1) + ADD_SIZE,
  36. X         (unsigned short) abs(y2 - y1) + ADD_SIZE,
  37. X         SRCSRC, DSTSRC, (unsigned short *) 0 );
  38. X
  39. #ifdef    DEBUG
  40. X      if ( r == -1 )
  41. X         {
  42. X         wgoto( w, 0, 0 );
  43. X         fprintf( stderr, "gr_imsave(): wrastop() failed, error %d.\n", errno );
  44. X         kb_rx();
  45. X         }
  46. #endif
  47. X      }
  48. X   }
  49. X
  50. /****************************************************************
  51. X
  52. X    gr_imfree()
  53. X
  54. ****************************************************************/
  55. X
  56. gr_imfree( image )
  57. X   int image;
  58. X   {
  59. X
  60. #ifdef DEBUG
  61. X   if ( tam_images[ image ] == NULL )
  62. X      {
  63. X      bw_error( "gr_imfree(): NULL image requested" );
  64. X      return FALSE;
  65. X      }
  66. #endif
  67. X
  68. X   free( tam_images[ image ] );
  69. X   tam_images[ image ] = NULL;
  70. X
  71. X   }
  72. X
  73. /****************************************************************
  74. X
  75. X   gr_mouse()
  76. X
  77. ****************************************************************/
  78. X
  79. gr_mouse( mode, x, y, buttons )
  80. X   int mode;
  81. X   int *x, *y;
  82. X   int *buttons;
  83. X   {
  84. X   static int b, r;
  85. X   
  86. X   if (( mode == STATUS ) || ( mode == SAMPLE ))
  87. X      {
  88. X
  89. #if WRITE_OUTPUT
  90. X   fprintf( outfile, "gr_mouse() STATUS: enter\n" );
  91. X   fflush( outfile );
  92. #endif
  93. X
  94. X      if ( tam_mready == FALSE )
  95. X         {
  96. X         att_rxstat();
  97. X         }
  98. X      return tam_mready;
  99. X      }
  100. X   else if ( mode == WAIT )
  101. X      {
  102. X
  103. #if WRITE_OUTPUT
  104. X   fprintf( outfile, "gr_mouse() WAIT: enter\n" );
  105. X   fflush( outfile );
  106. #endif
  107. X
  108. X      while( tam_mready == FALSE )
  109. X         {
  110. X         att_rxstat();
  111. X         }
  112. X      *x = tam_mx;
  113. X      *y = grwind->ymax - tam_my;
  114. X      tam_mready = FALSE;
  115. X      return TRUE;
  116. X      }
  117. X   }
  118. X
  119. tam_setscreen( screen )
  120. X   int screen;
  121. X   {
  122. X   if ( screen == GR_HIDDEN )
  123. X      {
  124. X      tam_selected = tam_hidden;
  125. X      }
  126. X   else
  127. X      {
  128. X      tam_selected = (unsigned short *) 0;
  129. X      }    
  130. X   }
  131. X
  132. tam_readfont( fontfile, sptr )
  133. X   char *fontfile;
  134. X   struct fntdef **sptr;
  135. X   {
  136. X   FILE *ff_fp;
  137. X   int size;
  138. X   char *m;
  139. X
  140. X   /* open the font file */
  141. X
  142. X   if ( ( ff_fp = fopen( fontfile, "r" )) == NULL )
  143. X      {
  144. X      fprintf( stderr, "Failed to open font file\n" );
  145. X      wgetc( w );
  146. X      wexit( 1 );
  147. X      }
  148. X
  149. X   /* find the size of the file */
  150. X
  151. X   size = 0;
  152. X   while( !feof( ff_fp ) )
  153. X      {
  154. X      ++size;
  155. X      fgetc( ff_fp );
  156. X      }
  157. X
  158. X   /* allocate memory for the file */
  159. X
  160. X   if ( ( m = malloc( size )) == NULL )
  161. X      {
  162. X      fprintf( stderr, "No memory for font file <%s> \n",
  163. X         fontfile );
  164. X      *sptr = NULL;
  165. X      wgetc( w );
  166. X      return BW_ERROR;
  167. X      }
  168. X   *sptr = (struct fntdef *) m;
  169. X
  170. #ifdef    OLD_DEBUG
  171. X   clear();
  172. X   wgoto( w, 0, 0 );
  173. X   fprintf( stderr, "Loading font <%s> \n", fontfile );
  174. X   fprintf( stderr, "Size %d bytes sptr 0x%08lX top 0x%08lX \n",
  175. X      size, (long) *sptr, (long) *sptr + size );
  176. X   wgetc( w );
  177. X   clear();
  178. X   wgoto( 0, 0 );
  179. #endif
  180. X
  181. X   /* now read the file into memory */
  182. X
  183. X   rewind( ff_fp );
  184. X   while( !feof( ff_fp ) )
  185. X      {
  186. X      *m = fgetc( ff_fp );
  187. X      ++m;
  188. X      }
  189. X
  190. X   /* close the font file */
  191. X
  192. X   fclose( ff_fp );
  193. X
  194. #ifdef    OLD_DEBUG
  195. X   fprintf( stderr, "Loaded font <%s>, %d by %d pixels\n",
  196. X      fontfile, (*sptr)->ff_vs, (*sptr)->ff_hs );
  197. X   wgetc( w );
  198. #endif
  199. X
  200. X   }
  201. X
  202. tam_char( screen, x, y, icon, x_size, y_size,
  203. X   foreground, background, c, cdef )
  204. X   int screen, x, y, x_size, y_size, foreground, background, c;
  205. X   unsigned short *icon;
  206. X   struct fcdef *cdef;
  207. X   {
  208. X   int r;
  209. X
  210. X   /* paint the background */
  211. X
  212. X   gr_rectangle( screen, x, y,
  213. X      x + tam_fdef->ff_hs, y + tam_fdef->ff_vs,
  214. X      background, SOLID );
  215. X
  216. X   /* call wrastop() to display the character as an icon */
  217. X
  218. X   r = wrastop( w, icon, tam_words( y_size ),
  219. X      tam_selected, tam_words( grwind->xmax + ADD_HIDDEN ),
  220. X      (unsigned short) 0, (unsigned short) 0,
  221. X      (unsigned short) x + cdef->fc_ha,
  222. X      (unsigned short) (grwind->ymax - y) + ( cdef->fc_va - 1 ),
  223. X      (unsigned short) x_size,
  224. X      (unsigned short) y_size,
  225. X      SRCSRC, DSTXOR, (unsigned short *) 0 );
  226. X
  227. #ifdef    OLD_DEBUG
  228. X   wgoto( w, 10, 0 );
  229. X   if ( r == -1 )
  230. X      {
  231. X      fprintf( stderr, "tam_char(): wrastop() failed, error %d, screen %d.\n",
  232. X         errno, screen );
  233. X      wgetc( w );
  234. X      }
  235. #ifdef OLD_STUFF
  236. X   fprintf( stderr, "Character 0x%X <%c>:  offset %d (0x%04X\n",
  237. X      c, c, cdef->fc_mr, cdef->fc_mr );
  238. X   fprintf( stderr, "  x_size %d, y_size %d, words %d \n",
  239. X      x_size, y_size, tam_words( y_size ) );
  240. X   fprintf( stderr, "  fc_ha %d, fc_va %d, fc_hi %d, fc_vi %d \n",
  241. X      cdef->fc_ha, cdef->fc_va, cdef->fc_hi, cdef->fc_vi );
  242. X   fprintf( stderr, "  x pos %d, y pos %d\n",
  243. X      x, y );
  244. X   fprintf( stderr, "  icon %08lX selected %08lX\n",
  245. X      (long) icon, (long) tam_selected );
  246. X   wgetc( w );
  247. X   clear();
  248. #endif
  249. #endif
  250. X   }
  251. X
  252. /* determine the number of 16-bit words necessary
  253. X   for horizontal axis */
  254. X
  255. unsigned short
  256. tam_words( pixels )
  257. X   int pixels;
  258. X   {
  259. X   return ((( pixels + 15) / 16 ) * 2);
  260. X   }
  261. X
  262. #ifdef T_WRASTOP
  263. t_wrastop( tw, srcbase, srcwidth, dstbase, dstwidth,
  264. X   srcx, srcy, dstx, dsty, width, height,
  265. X   srcop, dstop, pattern )
  266. X   int tw;
  267. X   unsigned short *srcbase, *dstbase, *pattern;
  268. X   unsigned short srcwidth, dstwidth;
  269. X   unsigned short srcx, srcy, dstx, dsty;
  270. X   char srcop, dstop;
  271. X   {
  272. X
  273. X
  274. X   if ( tam_wtest == TRUE )
  275. X      {
  276. /*      gr_rectangle( GR_PRIMARY, 0, grwind->ymax - 40,
  277. X         grwind->xmax, grwind->ymax, BLACK, SOLID ); */
  278. X      wgoto( w, 0, 0 );
  279. X      fprintf( stderr, "test wrastop(): srcwidth %d, dstwidth %d\n",
  280. X         srcwidth, dstwidth );
  281. X      kb_rx();
  282. /*      gr_rectangle( GR_PRIMARY, 0, grwind->ymax - 40,
  283. X         grwind->xmax, grwind->ymax, BLACK, SOLID ); */
  284. X      wgoto( w, 0, 0 );
  285. X      fprintf( stderr, "test wrastop(): srcbase %08lx, dstbase %08lx\n",
  286. X         (long) srcbase, (long) dstbase );
  287. X      kb_rx();
  288. /*      gr_rectangle( GR_PRIMARY, 0, grwind->ymax - 40,
  289. X         grwind->xmax, grwind->ymax, BLACK, SOLID ); */
  290. X      wgoto( w, 0, 0 );
  291. X      fprintf( stderr, "test wrastop(): srcx %d, srcy %d, dstx %d dsty %d\n",
  292. X         srcx, srcy, dstx, dsty );
  293. X      kb_rx();
  294. /*      gr_rectangle( GR_PRIMARY, 0, grwind->ymax - 40,
  295. X         grwind->xmax, grwind->ymax, BLACK, SOLID ); */
  296. X      wgoto( w, 0, 0 );
  297. X      fprintf( stderr, "test wrastop(): width %d, height %d\n",
  298. X         width, height );
  299. X      kb_rx();
  300. X      }
  301. X
  302. X   return wrastop( tw, srcbase, srcwidth, dstbase, dstwidth,
  303. X      srcx, srcy, dstx, dsty, width, height,
  304. X      srcop, dstop, pattern );
  305. X
  306. X   }
  307. #endif
  308. SHAR_EOF
  309. echo 'File io/gr/gr_tam.c is complete' &&
  310. chmod 0644 io/gr/gr_tam.c ||
  311. echo 'restore of io/gr/gr_tam.c failed'
  312. Wc_c="`wc -c < 'io/gr/gr_tam.c'`"
  313. test 27360 -eq "$Wc_c" ||
  314.     echo 'io/gr/gr_tam.c: original size 27360, current size' "$Wc_c"
  315. rm -f _shar_wnt_.tmp
  316. fi
  317. # ============= io/gr/gr_test.c ==============
  318. if test -f 'io/gr/gr_test.c' -a X"$1" != X"-c"; then
  319.     echo 'x - skipping io/gr/gr_test.c (File already exists)'
  320.     rm -f _shar_wnt_.tmp
  321. else
  322. > _shar_wnt_.tmp
  323. echo 'x - extracting io/gr/gr_test.c (Text)'
  324. sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_test.c' &&
  325. /****************************************************************
  326. X
  327. X    gr_test.c       Validation program for Bywater
  328. X            Graphics Interface standard
  329. X
  330. X            Copyright (c) 1991, Ted A. Campbell
  331. X
  332. X            Bywater Software
  333. X            P. O. Box 4023 
  334. X            Duke Station 
  335. X            Durham, NC  27706
  336. X
  337. X            email: tcamp@hercules.acpub.duke.edu
  338. X
  339. X    Copyright and Permissions Information:
  340. X
  341. X    All U.S. and international copyrights are claimed by the
  342. X    author. The author grants permission to use this code
  343. X    and software based on it under the following conditions:
  344. X    (a) in general, the code and software based upon it may be 
  345. X    used by individuals and by non-profit organizations; (b) it
  346. X    may also be utilized by governmental agencies in any country,
  347. X    with the exception of military agencies; (c) the code and/or
  348. X    software based upon it may not be sold for a profit without
  349. X    an explicit and specific permission from the author, except
  350. X    that a minimal fee may be charged for media on which it is
  351. X    copied, and for copying and handling; (d) the code must be 
  352. X    distributed in the form in which it has been released by the
  353. X    author; and (e) the code and software based upon it may not 
  354. X    be used for illegal activities. 
  355. X
  356. ****************************************************************/
  357. X
  358. #include "stdio.h"
  359. #include "signal.h"
  360. X
  361. #ifdef __STDC__
  362. #include "malloc.h"
  363. #else
  364. extern char * malloc();
  365. #define size_t  int
  366. #endif
  367. X
  368. #include "bw.h"
  369. #include "gr.h"
  370. #include "kb.h"
  371. X
  372. struct gr_window main_window;
  373. char tbuf[ 128 ];
  374. char bw_ebuf[ BW_EBUFSIZE ];
  375. int x_pos, y_pos, b_stat;
  376. int x, y;
  377. int bsize;
  378. static int image;
  379. int test_quit();
  380. X
  381. main()
  382. X   {
  383. X   register int c;
  384. X
  385. X   gr_init( &main_window, NULL );
  386. X   kb_init();
  387. X
  388. X   signal( SIGTERM, test_quit );
  389. X
  390. X   /* set a font equal to 1/25 of the screen height */
  391. X
  392. X   gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 25 );
  393. X
  394. X   c = 0;
  395. X   while ( c != 0x1b )
  396. X      {
  397. X      gr_cls( GR_PRIMARY );
  398. X      gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  399. X     WHITE, SOLID );
  400. X      gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  401. X     " Bywater gr (Graphics and Mouse) Interface Validation: ",
  402. X     BLACK, WHITE );
  403. X      if ( gr_ismouse == TRUE )
  404. X     {
  405. X     gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 3 ),
  406. X        "Mouse detected.", WHITE, BLACK );
  407. X     }
  408. X      else
  409. X     {
  410. X     gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 3 ),
  411. X        "No mouse detected.", WHITE, BLACK );
  412. X     }
  413. X      sprintf( tbuf, "Screens supported:  %d ", gr_screens );
  414. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 4 ), tbuf, WHITE, BLACK );
  415. X      sprintf( tbuf, "Window size:  X axis, %d pixels; Y axis, %d pixels",
  416. X     main_window.xmax, main_window.ymax );
  417. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 5 ), tbuf, WHITE, BLACK );
  418. X
  419. X      sprintf( tbuf, "Pixel size:  X axis, %d pixels; Y axis, %d pixels",
  420. X     gr_pxsize, gr_pysize );
  421. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 6 ), tbuf, WHITE, BLACK );
  422. X
  423. X      sprintf( tbuf, "Font size:  X axis, %d pixels; Y axis, %d pixels",
  424. X     main_window.fxsize, main_window.fysize );
  425. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 7 ), tbuf, WHITE, BLACK );
  426. X
  427. X      sprintf( tbuf, "Colors available: %d", gr_colors );
  428. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 8 ), tbuf, WHITE, BLACK );
  429. X
  430. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 10 ),
  431. X     " 1  Validate gr_font() and gr_text()", WHITE, BLACK );
  432. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 11 ),
  433. X     " 2  Validate gr_pixel()", WHITE, BLACK );
  434. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 12 ),
  435. X     " 3  Validate gr_line()", WHITE, BLACK );
  436. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 13 ),
  437. X     " 4  Validate gr_rectangle()", WHITE, BLACK );
  438. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 14 ),
  439. X     " 5  Validate gr_circle()", WHITE, BLACK );
  440. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 15 ),
  441. X     " 6  Validate gr_imsave()", WHITE, BLACK );
  442. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 16 ),
  443. X     " 7  Validate gr_blit()", WHITE, BLACK );
  444. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 17 ),
  445. X     " 8  Validate gr_mouse()", WHITE, BLACK );
  446. X      gr_text( GR_PRIMARY, txt_x( 5 ), txt_y( 19 ),
  447. X     " 9  EXIT", WHITE, BLACK );
  448. X
  449. X      c = kb_rx();
  450. X
  451. X      switch( c )
  452. X     {
  453. X     case '1':
  454. X        val_font();
  455. X        break;
  456. X     case '2':
  457. X        val_pixel();
  458. X        break;
  459. X     case '3':
  460. X        val_line();
  461. X        break;
  462. X     case '4':
  463. X        val_rectangle();
  464. X        break;
  465. X     case '5':
  466. X        val_circle();
  467. X        break;
  468. X     case '6':
  469. X        val_save();
  470. X        break;
  471. X     case '7':
  472. X        val_blit();
  473. X        break;
  474. X     case '8':
  475. X        val_mouse();
  476. X        break;
  477. X     case '9':
  478. X     case 0x1b:
  479. X        c = 0x1b;
  480. X        break;
  481. X     }
  482. X
  483. X
  484. X      }
  485. X
  486. X   val_exit();
  487. X
  488. X   }
  489. X
  490. X
  491. /* 1: validate gr_font(), and gr_text()   */
  492. X
  493. val_font()
  494. X   {
  495. X   gr_cls( GR_PRIMARY );
  496. X   gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  497. X      WHITE, SOLID );
  498. X   gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  499. X      "GR test # 1:  gr_font() validation.",
  500. X      BLACK, WHITE );
  501. X
  502. X   x = main_window.xmax / 10;
  503. X   y = main_window.ymax / 18;
  504. X
  505. X   gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 40 );
  506. X   sprintf( tbuf, "Test size ymax / 40:  %dx%d font",
  507. X      main_window.fysize, main_window.fxsize );
  508. X   gr_text( GR_PRIMARY, x, y, tbuf, WHITE, BLACK );
  509. X
  510. X   gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 30 );
  511. X   sprintf( tbuf, "Test size ymax / 30:  %dx%d font",
  512. X      main_window.fysize, main_window.fxsize );
  513. X   gr_text( GR_PRIMARY, x, y * 2, tbuf, WHITE, BLACK );
  514. X
  515. X   gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 25 );
  516. X   sprintf( tbuf, "Test size ymax / 25:  %dx%d font",
  517. X      main_window.fysize, main_window.fxsize );
  518. X   gr_text( GR_PRIMARY, x, y * 4, tbuf, WHITE, BLACK );
  519. X
  520. X   gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 20 );
  521. X   sprintf( tbuf, "Test size ymax / 20:  %dx%d font",
  522. X      main_window.fysize, main_window.fxsize );
  523. X   gr_text( GR_PRIMARY, x, y * 8, tbuf, WHITE, BLACK );
  524. X
  525. X   gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 15 );
  526. X   sprintf( tbuf, "Test size ymax / 15:  %dx%d font",
  527. X      main_window.fysize, main_window.fxsize );
  528. X   gr_text( GR_PRIMARY, x, y * 12, tbuf, WHITE, BLACK );
  529. X
  530. X   gr_font( GR_PRIMARY, F_DEFAULT, main_window.ymax / 25 );
  531. X   kb_rx();
  532. X
  533. X   }
  534. X
  535. /* 2: validate gr_pixel() */
  536. X
  537. val_pixel()
  538. X   {
  539. X   register int c;
  540. X
  541. X   gr_cls( GR_PRIMARY );
  542. X   gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  543. X      WHITE, SOLID );
  544. X   gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  545. X      "GR test # 2:  gr_pixel() validation.",
  546. X      BLACK, WHITE );
  547. X
  548. X   x = main_window.xmax / 4;
  549. X   y = ( main_window.ymax / 4 ) * 3;
  550. X   c = 0;
  551. X   while ( ( c < gr_colors ) && ( y > main_window.fysize ) )
  552. X      {
  553. X      gr_pixel( GR_PRIMARY, x, y, c );
  554. X      sprintf( tbuf, " <- pixel color %d at x = %d, y = %d", 
  555. X         c, x, y );
  556. X      gr_text( GR_PRIMARY, x + ( 3 * main_window.fxsize ), 
  557. X         y - ( main_window.fysize / 2 ), tbuf, WHITE, BLACK );
  558. X      ++c;
  559. X      y -= ( main_window.fysize / 2 ) * 3;
  560. X      }
  561. X   kb_rx();
  562. X
  563. X   }
  564. X
  565. /* 3: validate gr_line() */
  566. X
  567. val_line()
  568. X   {
  569. X   register int c;
  570. X
  571. X   gr_cls( GR_PRIMARY );
  572. X   gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  573. X      WHITE, SOLID );
  574. X   gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  575. X      "GR test # 3:  gr_line() validation.",
  576. X      BLACK, WHITE );
  577. X
  578. X   x = main_window.xmax / 8;
  579. X   y = ( main_window.ymax / 4 ) * 3;
  580. X   c = 0;
  581. X   while ( ( c < gr_colors ) && ( y > main_window.fysize ) )
  582. X      {
  583. X      gr_line( GR_PRIMARY, x, y, x + main_window.xmax / 20, y, 
  584. X         c, SOLID );
  585. X      x += main_window.xmax / 10;
  586. X      gr_line( GR_PRIMARY, x, y, x + main_window.xmax / 20, y, 
  587. X         c, HATCH );
  588. X      sprintf( tbuf, " <- lines, color %d at x = %d, y = %d", 
  589. X         c, x, y );
  590. X      gr_text( GR_PRIMARY, x + ( 3 * ( main_window.xmax / 20 )), 
  591. X         y - ( main_window.fysize / 2 ), tbuf, WHITE, BLACK );
  592. X      ++c;
  593. X      x -= main_window.xmax / 10;
  594. X      y -= ( main_window.fysize / 2 ) * 3;
  595. X      }
  596. X   kb_rx();
  597. X
  598. X   gr_cls( GR_PRIMARY );
  599. X   for ( x = 0; x < main_window.xmax; x += 15 )
  600. X      {
  601. X      gr_line( GR_PRIMARY, x, 0, 0, main_window.ymax,
  602. X     WHITE, SOLID );
  603. X      }
  604. X
  605. X   for ( y = main_window.ymax - 10; y > 0; y -= 15 )
  606. X      {
  607. X      gr_line( GR_PRIMARY, 0, y, main_window.xmax, 0,
  608. X     WHITE, SOLID );
  609. X      }
  610. X
  611. X   kb_rx();
  612. X
  613. X   }
  614. X
  615. /* 4: validate gr_rectangle() */
  616. X
  617. val_rectangle()
  618. X   {
  619. X
  620. X   gr_cls( GR_PRIMARY );
  621. X   gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  622. X      WHITE, SOLID );
  623. X   gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  624. X      "GR test # 4:  gr_rectangle() validation.",
  625. X      BLACK, WHITE );
  626. X
  627. X   x = main_window.xmax / 40;
  628. X   y = main_window.ymax / 20;
  629. X   gr_rectangle( GR_PRIMARY, x * 4, y * 16, x * 6, y * 18, WHITE, HOLLOW );
  630. X   gr_text( GR_PRIMARY, x * 10, y * 17, "Hollow rectangle", WHITE, BLACK );
  631. X   gr_rectangle( GR_PRIMARY, x * 4, y * 12, x * 6, y * 14, WHITE, SOLID );
  632. X   gr_text( GR_PRIMARY, x * 10, y * 13, "Solid rectangle", WHITE, BLACK );
  633. X    gr_rectangle( GR_PRIMARY, x * 4, y * 8, x * 6, y * 10, WHITE, GRID );
  634. X   gr_text( GR_PRIMARY, x * 10, y * 9, "Grid rectangle", WHITE, BLACK );
  635. X    gr_rectangle( GR_PRIMARY, x * 4, y * 4, x * 6, y * 6, WHITE, HATCH );
  636. X   gr_text( GR_PRIMARY, x * 10, y * 5, "Hatch rectangle", WHITE, BLACK );
  637. X   kb_rx();
  638. X   }
  639. X
  640. /* 5: validate gr_circle() */
  641. X
  642. val_circle()
  643. X   {
  644. X   gr_cls( GR_PRIMARY );
  645. X   gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  646. X      WHITE, SOLID );
  647. X   gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  648. X      "GR test # 5:  gr_circle() validation.",
  649. X      BLACK, WHITE );
  650. X
  651. X   x = main_window.xmax / 40;
  652. X   y = main_window.ymax / 20;
  653. X   gr_circle( GR_PRIMARY, x * 5, y * 17, (y/2)*3, WHITE, HOLLOW );
  654. X   gr_text( GR_PRIMARY, x * 10, y * 17, "Hollow circle", WHITE, BLACK );
  655. X   gr_circle( GR_PRIMARY, x * 5, y * 13, (y/2)*3, WHITE, SOLID );
  656. X   gr_text( GR_PRIMARY, x * 10, y * 13, "Solid circle", WHITE, BLACK );
  657. X    gr_circle( GR_PRIMARY, x * 5, y * 9, (y/2)*3, WHITE, GRID );
  658. X   gr_text( GR_PRIMARY, x * 10, y * 9, "Grid circle", WHITE, BLACK );
  659. X    gr_circle( GR_PRIMARY, x * 5, y * 5, (y/2)*3, WHITE, HATCH );
  660. X   gr_text( GR_PRIMARY, x * 10, y * 5, "Hatch circle", WHITE, BLACK );
  661. X   kb_rx();
  662. X   }
  663. X
  664. /* 6: test gr_imsave() */
  665. X
  666. val_save()
  667. X
  668. X   {
  669. X
  670. X   /* if saving is allowed, save a portion of the screen here */
  671. X
  672. X   if ( gr_saving )
  673. X      {
  674. X      x = main_window.xmax / 10;
  675. X      y = main_window.ymax / 18;
  676. X
  677. X      gr_imsave( GR_PRIMARY, TRUE, x, y * 3, x * 6, y * 8, &image );
  678. X       gr_rectangle( GR_PRIMARY, x, y * 3, x * 6, y * 8, WHITE, HOLLOW );
  679. X
  680. X
  681. X
  682. X      /* now show the portion saved earlier */
  683. X
  684. X      gr_cls( GR_PRIMARY );
  685. X      gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  686. X     WHITE, SOLID );
  687. X      gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  688. X     "GR test # 6:  gr_imsave() validation.",
  689. X         BLACK, WHITE );
  690. X
  691. X      gr_imsave( GR_PRIMARY, FALSE, x, y * 3, x * 6, y * 8, &image );
  692. X           gr_rectangle( GR_PRIMARY, x, y * 3, x * 6, y * 8, WHITE, HOLLOW );
  693. X      kb_rx();
  694. X      }
  695. X   }
  696. X
  697. /* 7: validate gr_blit() */
  698. X
  699. val_blit()
  700. X   {
  701. X
  702. X   /* if there is more than one screen, validate screen writes and blits */
  703. X
  704. X   if ( gr_blitting == TRUE )
  705. X      {
  706. X      gr_cls( GR_PRIMARY );
  707. X      gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  708. X     WHITE, SOLID );
  709. X      gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  710. X     "GR test # 7:  gr_blit() validation.",
  711. X     BLACK, WHITE );
  712. X      gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 4 ),
  713. X     "  this has been written to screen GR_PRIMARY.",
  714. X     BLACK, WHITE );
  715. X      gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 5 ),
  716. X     "  but after you hit RETURN GR_HIDDEN ",
  717. X     BLACK, WHITE );
  718. X      gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 6 ),
  719. X     "  will be blitted to this screen  ",
  720. X     BLACK, WHITE );
  721. X      gr_text( GR_HIDDEN, txt_x( 0 ), txt_y( 0 ),
  722. X     "  gr_blit() validation.",
  723. X     BLACK, WHITE );
  724. X      gr_text( GR_HIDDEN, txt_x( 0 ), txt_y( 4 ),
  725. X     "  this has been written to screen GR_HIDDEN.",
  726. X     BLACK, WHITE );
  727. X      gr_text( GR_HIDDEN, txt_x( 0 ), txt_y( 5 ),
  728. X     "  and has now been blitted over ",
  729. X     BLACK, WHITE );
  730. X      gr_text( GR_HIDDEN, txt_x( 0 ), txt_y( 6 ),
  731. X     "  to GR_PRIMARY  ",
  732. X     BLACK, WHITE );
  733. X
  734. X      kb_rx();
  735. X      gr_blit( GR_HIDDEN, GR_PRIMARY, 0, 0,
  736. X     main_window.xmax,
  737. X     main_window.ymax );
  738. X      kb_rx();
  739. X      }
  740. X   }
  741. X
  742. /* 8: validate mouse */
  743. X
  744. val_mouse()
  745. X   {
  746. X   register int c;
  747. X
  748. X   /* If mouse exists, validate it */
  749. X
  750. X   if ( gr_ismouse == TRUE )
  751. X      {
  752. X      gr_cls( GR_PRIMARY );
  753. X      gr_rectangle( GR_PRIMARY, 0, txt_y( 0 ), main_window.xmax, main_window.ymax,
  754. X     WHITE, SOLID );
  755. X      gr_text( GR_PRIMARY, txt_x( 0 ), txt_y( 0 ),
  756. X     "GR test # 8:  gr_mouse() validation.",
  757. X         BLACK, WHITE );
  758. X
  759. X      x = main_window.xmax / 40;
  760. X      y = main_window.ymax / 20;
  761. X
  762. X      while ( gr_mouse( STATUS, &x_pos, &y_pos, &b_stat ) != TRUE )
  763. X     {
  764. X     sprintf( tbuf, "Mouse position:  x = %d, y = %d    ",
  765. X        x_pos, y_pos );
  766. X     gr_text( GR_PRIMARY, x * 10, y * 17, tbuf, WHITE, BLACK );
  767. X     }
  768. X      gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  769. X      gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  770. X
  771. X      c = 0;
  772. X      while( ( kb_rxstat() == FALSE ) && ( c < 12 ))
  773. X         {
  774. X     ++c;
  775. X         gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  776. X         sprintf( tbuf, "Mouse position:  x = %d, y = %d    ",
  777. X            x_pos, y_pos );
  778. X         gr_text( GR_PRIMARY, x * 10, y * 17, tbuf, WHITE, BLACK );
  779. X         }
  780. X      }
  781. X   }
  782. X
  783. val_exit()
  784. X
  785. X   {
  786. X
  787. X   /* Finished with validation:  clear screen and restore original state */
  788. X
  789. X   gr_cls( GR_PRIMARY );
  790. X   kb_deinit();
  791. X   gr_deinit();
  792. X   }
  793. X
  794. txt_y( line )
  795. X   int line;
  796. X   {
  797. X   return ( main_window.ymax ) - ( main_window.fysize * ( line + 1 ));
  798. X   }
  799. X
  800. txt_x( column )
  801. X   int column;
  802. X   {
  803. X   return column * main_window.fxsize;
  804. X   }
  805. X
  806. test_quit()
  807. X   {
  808. X   gr_cls( GR_PRIMARY );
  809. X   kb_deinit();
  810. X   gr_deinit();
  811. X   }
  812. X
  813. bw_error( m )
  814. X   char *m;
  815. X   {
  816. X   fprintf( stderr, "ERROR: %s \n", m );
  817. X   }
  818. X
  819. X
  820. SHAR_EOF
  821. chmod 0644 io/gr/gr_test.c ||
  822. echo 'restore of io/gr/gr_test.c failed'
  823. Wc_c="`wc -c < 'io/gr/gr_test.c'`"
  824. test 13731 -eq "$Wc_c" ||
  825.     echo 'io/gr/gr_test.c: original size 13731, current size' "$Wc_c"
  826. rm -f _shar_wnt_.tmp
  827. fi
  828. # ============= io/gr/gr_test.mak ==============
  829. if test -f 'io/gr/gr_test.mak' -a X"$1" != X"-c"; then
  830.     echo 'x - skipping io/gr/gr_test.mak (File already exists)'
  831.     rm -f _shar_wnt_.tmp
  832. else
  833. > _shar_wnt_.tmp
  834. echo 'x - extracting io/gr/gr_test.mak (Text)'
  835. sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_test.mak' &&
  836. PROJ    =GR_TEST
  837. DEBUG    =0
  838. CC    =qcl
  839. CFLAGS_G        = /AL /W1 /Ze /DDEBUG /I..\..\include
  840. CFLAGS_D    = /Zi /Zr /Gi$(PROJ).mdt /Od 
  841. CFLAGS_R    = /O /Ot /DNDEBUG 
  842. CFLAGS    =$(CFLAGS_G) $(CFLAGS_R)
  843. LFLAGS_G    =/NOI
  844. LFLAGS_D    =/INCR /CO
  845. LFLAGS_R    =
  846. LFLAGS    =$(LFLAGS_G) $(LFLAGS_R)
  847. RUNFLAGS    =
  848. OBJS_EXT =     
  849. LIBS_EXT =     
  850. X
  851. all:    $(PROJ).exe
  852. X
  853. gr_test.obj:    gr_test.c
  854. X
  855. gr_ibmpc.obj:    gr_ibmpc.c
  856. X
  857. kb_ibmpc.obj:    ..\kb\kb_ibmpc.c
  858. X
  859. $(PROJ).exe:    gr_test.obj gr_ibmpc.obj kb_ibmpc.obj $(OBJS_EXT)
  860. X    echo >NUL @<<$(PROJ).crf
  861. gr_test.obj +
  862. gr_ibmpc.obj +
  863. kb_ibmpc.obj +
  864. $(OBJS_EXT)
  865. $(PROJ).exe
  866. X
  867. $(LIBS_EXT);
  868. <<
  869. X    link $(LFLAGS) @$(PROJ).crf
  870. X
  871. run: $(PROJ).exe
  872. X    $(PROJ) $(RUNFLAGS)
  873. X
  874. SHAR_EOF
  875. chmod 0644 io/gr/gr_test.mak ||
  876. echo 'restore of io/gr/gr_test.mak failed'
  877. Wc_c="`wc -c < 'io/gr/gr_test.mak'`"
  878. test 643 -eq "$Wc_c" ||
  879.     echo 'io/gr/gr_test.mak: original size 643, current size' "$Wc_c"
  880. rm -f _shar_wnt_.tmp
  881. fi
  882. # ============= io/gr/gr_x.c ==============
  883. if test -f 'io/gr/gr_x.c' -a X"$1" != X"-c"; then
  884.     echo 'x - skipping io/gr/gr_x.c (File already exists)'
  885.     rm -f _shar_wnt_.tmp
  886. else
  887. > _shar_wnt_.tmp
  888. echo 'x - extracting io/gr/gr_x.c (Text)'
  889. sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_x.c' &&
  890. /****************************************************************
  891. X
  892. X    gr_x.c        X Windows Implementation
  893. X            of Bywater Graphics Interface Standard
  894. X
  895. X            Tested on DecStation 2100 and 3100
  896. X
  897. X            Copyright (c) 1991, Ted A. Campbell
  898. X
  899. X            Bywater Software
  900. X            P. O. Box 4023 
  901. X            Duke Station 
  902. X            Durham, NC  27706
  903. X
  904. X            email: tcamp@hercules.acpub.duke.edu
  905. X
  906. X    Copyright and Permissions Information:
  907. X
  908. X    All U.S. and international copyrights are claimed by the
  909. X    author. The author grants permission to use this code
  910. X    and software based on it under the following conditions:
  911. X    (a) in general, the code and software based upon it may be 
  912. X    used by individuals and by non-profit organizations; (b) it
  913. X    may also be utilized by governmental agencies in any country,
  914. X    with the exception of military agencies; (c) the code and/or
  915. X    software based upon it may not be sold for a profit without
  916. X    an explicit and specific permission from the author, except
  917. X    that a minimal fee may be charged for media on which it is
  918. X    copied, and for copying and handling; (d) the code must be 
  919. X    distributed in the form in which it has been released by the
  920. X    author; and (e) the code and software based upon it may not 
  921. X    be used for illegal activities. 
  922. X
  923. ****************************************************************/
  924. X
  925. #include "stdio.h"
  926. #ifdef __STDC__
  927. #include "stdlib.h"
  928. #endif
  929. X
  930. #include "X11/Xlib.h"
  931. #include "X11/Xutil.h"
  932. #include "X11/keysym.h"
  933. #include "X11/keysymdef.h"
  934. #include "X11/cursorfont.h"
  935. X
  936. #include "bw.h"
  937. #include "kb.h"
  938. #include "gr.h"
  939. X
  940. #define IMAGES                  64
  941. #define KEY_NEEDED              FALSE
  942. #define    MAX_SCREEN_HEIGHT    500
  943. #define MAX_SCREEN_WIDTH        800
  944. #define X_OFFSET                 30
  945. #define Y_OFFSET                 30
  946. #define REQ_BORDER_WIDTH          3
  947. #define    EVENT_MASK              ( ButtonPressMask   | \
  948. X                                  ButtonReleaseMask | \
  949. X                                  KeyPressMask )
  950. #define KEYBUF_LENGTH            64
  951. X
  952. /****************************************************************
  953. X
  954. X   The following globals are defined in the gr specification 
  955. X   and are accessible to users of gr-based programs.  
  956. X
  957. ****************************************************************/
  958. X
  959. int   gr_screens = 2;
  960. int   gr_colors = 2;
  961. int   gr_pxsize = 30;
  962. int   gr_pysize = 30;
  963. int   gr_ismouse = TRUE;
  964. int   gr_blitting = TRUE;
  965. int   gr_clipping = FALSE;        /* Not yet */
  966. int   gr_saving = TRUE;
  967. X
  968. /****************************************************************
  969. X
  970. X   The following globals are specific to the X Windows implementaion
  971. X   of the gr standard and should not be accessible to users of 
  972. X   gr-based programs.  
  973. X
  974. ****************************************************************/
  975. X
  976. struct gr_window      *grwind;          /* primary gr window */
  977. Display               *x_display;    /* primary X Windows display */
  978. Colormap              x_colormap;    /* system color map */
  979. XXColor                rgbcolor, hardwarecolor;
  980. int                   x_screen;        /* which screen is in use */
  981. XXSetWindowAttributes  x_windattributes; /* send requested attributes */
  982. XXSizeHints            x_sizehints;      /* send size "hints" */
  983. unsigned long         x_windmask;       /* send window mask */
  984. Window                x_primary;        /* the principal X Window, used 
  985. X                       when GR_PRIMARY is specified */
  986. Pixmap                x_hidden;         /* a second X Window, used 
  987. X                       when GR_HIDDEN is specified */
  988. Drawable              x_selected;       /* X Drawable variable, which may be set
  989. X                       to either x_primary or x_hidden */
  990. int                   x_mousevent;      /* is mouse event pending? */
  991. int                   x_keybevent;      /* is keyboard event pending? */
  992. int                   x_moxpos;         /* mouse x position pending */
  993. int                   x_moypos;         /* mouse y position pending */
  994. int                   x_keypending;     /* key pending */
  995. int                   x_depth;        /* depth (color planes ) */
  996. XXFontStruct           *x_font10;     /* font structure: 10 y */
  997. XXFontStruct           *x_font13;     /* font structure: 13 y */
  998. XXFontStruct           *x_font15;     /* font structure: 15 y */
  999. XXFontStruct           *x_font20;     /* font structure: 20 y */
  1000. XXFontStruct           *x_font31;     /* font structure: 31 y */
  1001. XXFontStruct           *x_curfont;       /* font struct in use */
  1002. XXGCValues             x_gcvals;         /* graphics content values */
  1003. GC                    x_fontgc;       /* graphics context for font */
  1004. GC                    x_drawgc;       /* graphics context for drawing */
  1005. Cursor                x_cursor;         /* cursor to use for this X Window */
  1006. Pixmap                x_stippm;         /* stipple pixmap */
  1007. X
  1008. char                  x_stipple[] = { 170, 85, 170, 85, 170, 85, 170, 85 };
  1009. unsigned long         x_colchart[ 16 ];    /* chart of sixteen colors */
  1010. extern unsigned long  x_color();    /* see function below */
  1011. Pixmap                x_images[ IMAGES ]; /* images */
  1012. X
  1013. /****************************************************************
  1014. X
  1015. X   gr_init()
  1016. X
  1017. ****************************************************************/
  1018. X
  1019. gr_init( window, path )
  1020. X   struct gr_window *window;
  1021. X   char *path;
  1022. X   {
  1023. X   int x_xsize, x_ysize;
  1024. X   int req_xsize, req_ysize;
  1025. X   register int i;
  1026. X   
  1027. X   /*    Part 1 of the Initialization:
  1028. X   **
  1029. X   **    Open and X Windows Display and Window and set system parameters
  1030. X   **    based on it.
  1031. X   */
  1032. X
  1033. X   grwind = window;
  1034. X
  1035. X   /* Open an X Windows display */ 
  1036. X
  1037. X   x_display = XOpenDisplay( NULL );
  1038. X   
  1039. X   /* If the display is null, return */
  1040. X
  1041. X   if ( x_display == NULL )
  1042. X      {
  1043. X      return FALSE;
  1044. X      }
  1045. X
  1046. X   /* get the screen currently in use and some basic data */
  1047. X
  1048. X   x_screen = DefaultScreen( x_display );
  1049. X   x_depth = DefaultDepth( x_display, x_screen );
  1050. X   x_colormap = DefaultColormap( x_display, x_screen );
  1051. X   x_xsize = DisplayWidth( x_display, x_screen );
  1052. X   x_ysize = DisplayHeight( x_display, x_screen );
  1053. X   
  1054. X   /* determine requested height and width of X Window */
  1055. X
  1056. X   if ( x_xsize >= ( MAX_SCREEN_WIDTH + X_OFFSET ))
  1057. X      {
  1058. X      req_xsize = MAX_SCREEN_WIDTH;
  1059. X      }
  1060. X   else
  1061. X      {
  1062. X      req_xsize = x_xsize;
  1063. X      }
  1064. X
  1065. X   if ( x_ysize >= ( MAX_SCREEN_HEIGHT + Y_OFFSET ))
  1066. X      {
  1067. X      req_ysize = MAX_SCREEN_HEIGHT;
  1068. X      }
  1069. X   else
  1070. X      {
  1071. X      req_ysize = x_ysize;
  1072. X      }
  1073. X
  1074. X   /*   Set a cursor for this application */
  1075. X
  1076. X   x_cursor = XCreateFontCursor( x_display, XC_left_ptr );
  1077. X
  1078. X   /* set requested window attributes in structure to be passed */
  1079. X
  1080. X   x_windattributes.border_pixel =
  1081. X      WhitePixel( x_display, x_screen );
  1082. X   x_windattributes.background_pixel =
  1083. X      BlackPixel( x_display, x_screen );
  1084. X   x_windattributes.cursor = x_cursor;
  1085. X   x_windmask = ( CWCursor | CWBackPixel | CWBorderPixel 
  1086. X      | CWOverrideRedirect );
  1087. X
  1088. X   /* now create the window and hidden pixmap */
  1089. X
  1090. X   x_primary = XCreateWindow( x_display, RootWindow( x_display, x_screen ),
  1091. X      X_OFFSET, Y_OFFSET, req_xsize, req_ysize, REQ_BORDER_WIDTH, x_depth,
  1092. X      InputOutput, CopyFromParent, x_windmask, &x_windattributes );
  1093. X
  1094. X   x_hidden = XCreatePixmap( x_display, x_primary,
  1095. X      req_xsize, req_ysize, x_depth );
  1096. X
  1097. X   x_selected = x_primary;
  1098. X
  1099. X   /* Send size hints to the window manager */
  1100. X
  1101. X   x_sizehints.flags  = USPosition | USSize;
  1102. X   x_sizehints.x      = X_OFFSET;
  1103. X   x_sizehints.y      = Y_OFFSET;
  1104. X   x_sizehints.width  = req_xsize;
  1105. X   x_sizehints.height = req_ysize;
  1106. X   XSetNormalHints( x_display, x_primary, &x_sizehints );
  1107. X
  1108. X   /* Display the X Window */
  1109. X
  1110. X   XMapRaised( x_display, x_primary );
  1111. X
  1112. X   /* "Flush" the display to send all output to the screen */
  1113. X
  1114. X   XFlush( x_display );
  1115. X
  1116. X   /* Establish a graphics content for drawing */
  1117. X
  1118. X   x_drawgc = XCreateGC( x_display, x_primary, (unsigned long) 0,
  1119. X      &x_gcvals );
  1120. X
  1121. X   /* Set the stipple pattern for filling */
  1122. X
  1123. X   x_stippm = XCreateBitmapFromData( x_display, x_primary, x_stipple, 8, 8 );
  1124. X   XSetStipple( x_display, x_drawgc, x_stippm );
  1125. X
  1126. X   /* Set global gr variables based on this window */
  1127. X   
  1128. X   window->xmax = req_xsize;
  1129. X   window->ymax = req_ysize;
  1130. X
  1131. X   /*    Part 2 of the Initialization:
  1132. X   **
  1133. X   **    Set a default font.
  1134. X   */
  1135. X
  1136. X   x_font10 = XLoadQueryFont( x_display, "6x10" );
  1137. X   x_font13 = XLoadQueryFont( x_display, "8x13" );
  1138. X   x_font15 = XLoadQueryFont( x_display, "9x15" );
  1139. X   x_font20 = XLoadQueryFont( x_display, "vr-20" );
  1140. X   x_font31 = XLoadQueryFont( x_display, "vr-31" );
  1141. X   x_fontgc = XCreateGC( x_display, x_primary, (unsigned long) 0,
  1142. X      &x_gcvals );
  1143. X   XSetForeground( x_display, x_fontgc, WhitePixel( x_display, x_screen ));
  1144. X   XSetBackground( x_display, x_fontgc, BlackPixel( x_display, x_screen ));
  1145. X   XSetFont( x_display, x_fontgc, x_font13->fid );
  1146. X
  1147. X   x_curfont = x_font13;
  1148. X   grwind->fysize = x_font13->ascent + x_font13->descent;
  1149. X   grwind->fxsize = XTextWidth( x_font13, "m", 1 );
  1150. X
  1151. X   x_initcolor();        /* initialize color */
  1152. X
  1153. X   /*   clear the screen */
  1154. X
  1155. X   gr_cls( GR_PRIMARY );
  1156. X   gr_cls( GR_HIDDEN );
  1157. X   XFlush( x_display );
  1158. X
  1159. X   /*    Part 3 of the Initialization:
  1160. X   **
  1161. X   **    Initialize X events so the keyboard and mouse imput can
  1162. X   **    be processed. 
  1163. X   */
  1164. X
  1165. X   /* select input from key press, button press, and button release */   
  1166. X
  1167. X   XSelectInput( x_display, x_primary, EVENT_MASK );
  1168. X
  1169. X   /* set image buffer pointers to NULL */
  1170. X
  1171. X   for ( i = 0; i < IMAGES; ++i )
  1172. X      {
  1173. X      x_images[ i ] = NULL;
  1174. X      }
  1175. X
  1176. X   /* start out at null state for keyboard and mouse entries */
  1177. X
  1178. X   x_mousevent = FALSE;
  1179. X   x_keybevent = FALSE;
  1180. X   x_pollevent();
  1181. X
  1182. X   window->initialized = grwind->initialized = TRUE;
  1183. X
  1184. #if    KEY_NEEDED
  1185. X   kb_rx();
  1186. #endif
  1187. X   return TRUE;
  1188. X   }
  1189. X
  1190. /****************************************************************
  1191. X
  1192. X   gr_deinit()
  1193. X
  1194. ****************************************************************/
  1195. X
  1196. gr_deinit( screen )
  1197. X   int screen;
  1198. X   {
  1199. X
  1200. X   /* remove the X Window */
  1201. X
  1202. X   XDestroyWindow( x_display, x_primary );
  1203. X   XFreePixmap( x_display, x_hidden );
  1204. X   
  1205. X   /* close the X Display */
  1206. X
  1207. X   XCloseDisplay( x_display );
  1208. X
  1209. X   }
  1210. X
  1211. /****************************************************************
  1212. X
  1213. X   gr_cls()
  1214. X
  1215. ****************************************************************/
  1216. X
  1217. gr_cls( screen )
  1218. X   int screen;
  1219. X   {
  1220. X   if ( screen == GR_PRIMARY )
  1221. X      {
  1222. X      XClearWindow( x_display, x_primary );
  1223. X      }
  1224. X   else
  1225. X      {
  1226. X      gr_rectangle( GR_HIDDEN, 0, 0, grwind->xmax - 1, grwind->ymax - 1,
  1227. X         BLACK, SOLID );
  1228. X      }
  1229. X   XFlush( x_display );
  1230. X   }
  1231. X
  1232. X
  1233. /****************************************************************
  1234. X
  1235. X   gr_pixel()
  1236. X
  1237. ****************************************************************/
  1238. X
  1239. gr_pixel( screen, x, y, color )
  1240. X   int screen;
  1241. X   int x, y;
  1242. X   int color;
  1243. X   {
  1244. X
  1245. #ifdef  DEBUG
  1246. X   if ( ( x < 0 ) || ( x > grwind->xmax ))
  1247. X      {
  1248. X      sprintf( bw_ebuf, "[pr:] gr_pixel(): x value is %d", x );
  1249. X      bw_error( bw_ebuf );
  1250. X      return BW_ERROR;
  1251. X      }
  1252. X   if ( ( y < 0 ) || ( y > grwind->ymax ))
  1253. X      {
  1254. X      sprintf( bw_ebuf, "[pr:] gr_pixel(): y value is %d", y );
  1255. X      bw_error( bw_ebuf );
  1256. X      return BW_ERROR;
  1257. X      }
  1258. #endif
  1259. X
  1260. X   x_setscreen( screen );
  1261. X   XSetForeground( x_display, x_drawgc, x_color( color ) );
  1262. X   XDrawPoint( x_display, x_selected, x_drawgc, x, grwind->ymax - y );
  1263. X   XFlush( x_display );
  1264. X   }
  1265. X         
  1266. /****************************************************************
  1267. X
  1268. X   gr_line()
  1269. X
  1270. ****************************************************************/
  1271. X
  1272. gr_line( screen, x1, y1, x2, y2, color, style )
  1273. X   int screen;
  1274. X   int x1, y1, x2, y2;
  1275. X   int color, style;
  1276. X   {
  1277. X
  1278. #ifdef  DEBUG
  1279. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1280. X      {
  1281. X      sprintf( bw_ebuf, "[pr:] gr_line(): x1 value is %d", x1 );
  1282. X      bw_error( bw_ebuf );
  1283. X      return BW_ERROR;
  1284. X      }
  1285. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1286. X      {
  1287. X      sprintf( bw_ebuf, "[pr:] gr_line(): x2 value is %d", x2 );
  1288. X      bw_error( bw_ebuf );
  1289. X      return BW_ERROR;
  1290. X      }
  1291. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1292. X      {
  1293. X      sprintf( bw_ebuf, "[pr:] gr_line(): y1 value is %d", y1 );
  1294. X      bw_error( bw_ebuf );
  1295. X      return BW_ERROR;
  1296. X      }
  1297. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1298. X      {
  1299. X      sprintf( bw_ebuf, "[pr:] gr_line(): y2 value is %d", y2 );
  1300. X      bw_error( bw_ebuf );
  1301. X      return BW_ERROR;
  1302. X      }
  1303. #endif
  1304. X
  1305. X   x_setscreen( screen );
  1306. X   XSetLineAttributes( x_display, x_drawgc, (unsigned) 1, 
  1307. X      x_linestyle( style ), 
  1308. X      CapNotLast, JoinMiter );
  1309. X   XSetForeground( x_display, x_drawgc, x_color( color ) );
  1310. X   XDrawLine( x_display, x_selected, x_drawgc, x1, grwind->ymax - y1, 
  1311. X      x2, grwind->ymax - y2 );
  1312. X   XFlush( x_display );
  1313. X   }
  1314. X
  1315. /****************************************************************
  1316. X
  1317. X   gr_text()
  1318. X
  1319. ****************************************************************/
  1320. X
  1321. gr_text( screen, x, y, string, foreground, background )
  1322. X   int screen;
  1323. X   int x, y;
  1324. X   int foreground, background;
  1325. X   char *string;
  1326. X   {
  1327. X
  1328. #ifdef  DEBUG
  1329. X   if ( ( x < 0 ) || ( x > grwind->xmax ))
  1330. X      {
  1331. X      fprintf( stderr, "ERROR: [pr:] gr_text(): x value is %d", x );
  1332. X      kb_rx();
  1333. X      return BW_ERROR;
  1334. X      }
  1335. X   if ( ( y < 0 ) || ( y > grwind->ymax ))
  1336. X      {
  1337. X      fprintf( stderr, "ERROR: [pr:] gr_text(): y value is %d", y );
  1338. X      kb_rx();
  1339. X      return BW_ERROR;
  1340. X      }
  1341. #endif
  1342. X
  1343. X   x_setscreen( screen );
  1344. X
  1345. X   XSetForeground( x_display, x_fontgc, x_color( foreground ) );
  1346. X   XSetBackground( x_display, x_fontgc, x_color( background ) );
  1347. X
  1348. X   XDrawImageString( x_display, x_selected, x_fontgc, x, 
  1349. X      grwind->ymax - ( y + x_curfont->descent ), string,
  1350. X      strlen( string) );
  1351. X   XFlush( x_display );
  1352. X   }
  1353. X
  1354. /****************************************************************
  1355. X
  1356. X   gr_strlen()
  1357. X
  1358. ****************************************************************/
  1359. X
  1360. unsigned int
  1361. gr_strlen( string )
  1362. X   char *string;
  1363. X   {
  1364. X   return XTextWidth( x_curfont, string, strlen( string ) );
  1365. X   }
  1366. X
  1367. /****************************************************************
  1368. X
  1369. X   gr_rectangle()
  1370. X
  1371. ****************************************************************/
  1372. X
  1373. gr_rectangle( screen, x1, y1, x2, y2, color, style )
  1374. X   int screen;
  1375. X   int x1, y1, x2, y2;
  1376. X   int color, style;
  1377. X   {
  1378. X
  1379. #ifdef  DEBUG
  1380. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1381. X      {
  1382. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x1 value is %d", x1 );
  1383. X      bw_error( bw_ebuf );
  1384. X      return BW_ERROR;
  1385. X      }
  1386. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1387. X      {
  1388. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x2 value is %d", x2 );
  1389. X      bw_error( bw_ebuf );
  1390. X      return BW_ERROR;
  1391. X      }
  1392. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1393. X      {
  1394. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y1 value is %d", y1 );
  1395. X      bw_error( bw_ebuf );
  1396. X      return BW_ERROR;
  1397. X      }
  1398. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1399. X      {
  1400. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y2 value is %d", y2 );
  1401. X      bw_error( bw_ebuf );
  1402. X      return BW_ERROR;
  1403. X      }
  1404. #endif
  1405. X
  1406. X   x_setscreen( screen );
  1407. X
  1408. X   if ( style == HOLLOW )
  1409. X      {
  1410. X      XSetLineAttributes( x_display, x_drawgc, (unsigned int) 1,
  1411. X         LineSolid, CapNotLast, JoinMiter );
  1412. X      XSetForeground( x_display, x_drawgc, x_color( color ) );
  1413. X      XDrawRectangle( x_display, x_selected, x_drawgc, 
  1414. X         x1, grwind->ymax - y2, x2 - x1, y2 - y1 );
  1415. X      }
  1416. X   else
  1417. X      {
  1418. X      XSetFillRule( x_display, x_drawgc, EvenOddRule );
  1419. X      XSetFillStyle( x_display, x_drawgc, x_fillstyle( style ) );
  1420. X      XSetForeground( x_display, x_drawgc, x_color( color ) );
  1421. X      XSetBackground( x_display, x_drawgc, x_color( BLACK ) );
  1422. X      XFillRectangle( x_display, x_selected, x_drawgc, 
  1423. X         x1, grwind->ymax - y2, x2 - x1, y2 - y1 );
  1424. X      }
  1425. X   XFlush( x_display );
  1426. X   }
  1427. X
  1428. /****************************************************************
  1429. X
  1430. X   gr_circle()
  1431. X
  1432. ****************************************************************/
  1433. X
  1434. gr_circle( screen, x, y, radius, color, style )
  1435. X   int screen;
  1436. X   int x, y, radius;
  1437. X   int color, style;
  1438. X   {
  1439. X
  1440. #ifdef  DEBUG
  1441. X   if ( ( x < 0 ) || ( x > grwind->xmax ))
  1442. X      {
  1443. X      sprintf( bw_ebuf, "[pr:] gr_circle(): x value is %d", x );
  1444. X      bw_error( bw_ebuf );
  1445. X      return BW_ERROR;
  1446. X      }
  1447. X   if ( ( y < 0 ) || ( y > grwind->ymax ))
  1448. X      {
  1449. X      sprintf( bw_ebuf, "[pr:] gr_circle(): y value is %d", y );
  1450. X      bw_error( bw_ebuf );
  1451. X      return BW_ERROR;
  1452. X      }
  1453. #endif
  1454. X
  1455. X   x_setscreen( screen );
  1456. X
  1457. X   if ( style == HOLLOW )
  1458. X      {
  1459. X      XSetLineAttributes( x_display, x_drawgc, (unsigned int) 1,
  1460. X         LineSolid, CapNotLast, JoinMiter );
  1461. X      XSetForeground( x_display, x_drawgc, x_color( color ) );
  1462. X      XDrawArc( x_display, x_selected, x_drawgc, 
  1463. X         x - radius, ( grwind->ymax - y ) - radius, radius * 2, radius * 2,
  1464. X         0, 360 * 64 );
  1465. X      }
  1466. X   else
  1467. X      {
  1468. X      XSetFillRule( x_display, x_drawgc, EvenOddRule );
  1469. X      XSetFillStyle( x_display, x_drawgc, x_fillstyle( style ) );
  1470. X      XSetForeground( x_display, x_drawgc, x_color( color ) );
  1471. X      XSetBackground( x_display, x_drawgc, x_color( BLACK ) ); 
  1472. X      XFillArc( x_display, x_selected, x_drawgc, 
  1473. X         x - radius, ( grwind->ymax - y ) - radius, radius * 2, radius * 2,
  1474. X         0, 360 * 64 );
  1475. X      }
  1476. X   XFlush( x_display );
  1477. X   }
  1478. X
  1479. /****************************************************************
  1480. X
  1481. X   gr_ellipse()
  1482. X
  1483. ****************************************************************/
  1484. X
  1485. gr_ellipse( screen, x, y, x_radius, y_radius, mode, color, style )
  1486. X   int screen;
  1487. X   int x, y, x_radius, y_radius;
  1488. X   int mode, color, style;
  1489. X   {
  1490. X   }
  1491. X         
  1492. /****************************************************************
  1493. X
  1494. X   gr_clip()
  1495. X
  1496. ****************************************************************/
  1497. X
  1498. gr_clip( screen, mode, x1, y1, x2, y2 )
  1499. X   int screen;
  1500. X   int mode;
  1501. X   int x1, y1, x2, y2;
  1502. X   {
  1503. X
  1504. #ifdef  DEBUG
  1505. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1506. X      {
  1507. X      sprintf( bw_ebuf, "[pr:] gr_clip(): x1 value is %d", x1 );
  1508. X      bw_error( bw_ebuf );
  1509. X      return BW_ERROR;
  1510. X      }
  1511. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1512. X      {
  1513. X      sprintf( bw_ebuf, "[pr:] gr_clip(): x2 value is %d", x2 );
  1514. X      bw_error( bw_ebuf );
  1515. X      return BW_ERROR;
  1516. X      }
  1517. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1518. X      {
  1519. X      sprintf( bw_ebuf, "[pr:] gr_clip(): y1 value is %d", y1 );
  1520. X      bw_error( bw_ebuf );
  1521. X      return BW_ERROR;
  1522. X      }
  1523. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1524. X      {
  1525. X      sprintf( bw_ebuf, "[pr:] gr_clip(): y2 value is %d", y2 );
  1526. X      bw_error( bw_ebuf );
  1527. X      return BW_ERROR;
  1528. X      }
  1529. #endif
  1530. X
  1531. X   }
  1532. X
  1533. /****************************************************************
  1534. X
  1535. X   gr_font()
  1536. X
  1537. ****************************************************************/
  1538. X
  1539. gr_font( screen, type, rq_height )
  1540. X   int screen;
  1541. X   int type, rq_height;
  1542. X   {
  1543. X   XFontStruct *oldfont;
  1544. X
  1545. X   oldfont = x_curfont;
  1546. X
  1547. X   if ( rq_height > 25 )
  1548. X      {
  1549. X      x_curfont = x_font31;
  1550. X      }
  1551. X   else if ( rq_height > 17 )
  1552. X      {
  1553. X      x_curfont = x_font20;
  1554. X      }
  1555. X   else if ( rq_height > 14 )
  1556. X      {
  1557. X      x_curfont = x_font15;
  1558. X      }
  1559. X   else if ( rq_height > 11 )
  1560. X      {
  1561. X      x_curfont = x_font13;
  1562. X      }
  1563. X   else 
  1564. X      {
  1565. X      x_curfont = x_font10;
  1566. X      }
  1567. X      
  1568. X   if ( ( x_curfont == NULL ) || ( x_curfont->fid == 0 ))
  1569. X      {
  1570. X      x_curfont = oldfont;
  1571. X      }
  1572. X
  1573. X   XSetFont( x_display, x_fontgc, x_curfont->fid );
  1574. X   grwind->fysize = x_curfont->ascent + x_curfont->descent;
  1575. X   grwind->fxsize = XTextWidth( x_curfont, "m", 1 );
  1576. X
  1577. X   }
  1578. X
  1579. /****************************************************************
  1580. X
  1581. X    gr_blit()
  1582. X
  1583. ****************************************************************/
  1584. X
  1585. gr_blit( src, dst, x1, y1, x2, y2 )
  1586. X   int src, dst;
  1587. X   int x1, y1, x2, y2;
  1588. X   {
  1589. X
  1590. #ifdef  DEBUG
  1591. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1592. X      {
  1593. X      sprintf( bw_ebuf, "[pr:] gr_blit(): x1 value is %d", x1 );
  1594. X      bw_error( bw_ebuf );
  1595. X      return BW_ERROR;
  1596. X      }
  1597. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1598. X      {
  1599. X      sprintf( bw_ebuf, "[pr:] gr_blit(): x2 value is %d", x2 );
  1600. X      bw_error( bw_ebuf );
  1601. X      return BW_ERROR;
  1602. X      }
  1603. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1604. X      {
  1605. X      sprintf( bw_ebuf, "[pr:] gr_blit(): y1 value is %d", y1 );
  1606. X      bw_error( bw_ebuf );
  1607. X      return BW_ERROR;
  1608. X      }
  1609. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1610. X      {
  1611. X      sprintf( bw_ebuf, "[pr:] gr_blit(): y2 value is %d", y2 );
  1612. X      bw_error( bw_ebuf );
  1613. X      return BW_ERROR;
  1614. X      }
  1615. X   if ( src == dst )
  1616. X      {
  1617. X      sprintf( bw_ebuf, "[pr:] gr_blit(): src == dst" );
  1618. X      bw_error( bw_ebuf );
  1619. X      return BW_ERROR;
  1620. X      }
  1621. #endif
  1622. X
  1623. X   if ( src == GR_HIDDEN )
  1624. X      {
  1625. X      XCopyArea( x_display, x_hidden, x_primary, x_drawgc,
  1626. X         x1, grwind->ymax - y2, x2 - x1, y2 - y1, x1, grwind->ymax - y2 );
  1627. X      }
  1628. X
  1629. X   else
  1630. X      {
  1631. X      XCopyArea( x_display, x_primary, x_hidden, x_drawgc,
  1632. X         x1, grwind->ymax - y2, x2 - x1, y2 - y1, x1, grwind->ymax - y2 );
  1633. X      }
  1634. X
  1635. X   }
  1636. X
  1637. /****************************************************************
  1638. X
  1639. X   gr_imsave()
  1640. X
  1641. ****************************************************************/
  1642. X
  1643. gr_imsave( screen, mode, x1, y1, x2, y2, image )
  1644. X   int screen; 
  1645. X   int mode, x1, y1, x2, y2;
  1646. X   int *image;
  1647. X   {
  1648. X   register int r;
  1649. X   int carry_on;
  1650. X
  1651. #ifdef  DEBUG
  1652. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1653. X      {
  1654. X      sprintf( bw_ebuf, "[pr:] gr_save(): x1 value is %d", x1 );
  1655. X      bw_error( bw_ebuf );
  1656. X      return BW_ERROR;
  1657. X      }
  1658. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1659. X      {
  1660. X      sprintf( bw_ebuf, "[pr:] gr_save(): x2 value is %d", x2 );
  1661. X      bw_error( bw_ebuf );
  1662. X      return BW_ERROR;
  1663. X      }
  1664. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1665. X      {
  1666. X      sprintf( bw_ebuf, "[pr:] gr_save(): y1 value is %d", y1 );
  1667. X      bw_error( bw_ebuf );
  1668. X      return BW_ERROR;
  1669. X      }
  1670. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1671. X      {
  1672. X      sprintf( bw_ebuf, "[pr:] gr_save(): y2 value is %d", y2 );
  1673. X      bw_error( bw_ebuf );
  1674. X      return BW_ERROR;
  1675. X      }
  1676. #endif
  1677. X
  1678. X   x_setscreen( screen );
  1679. X
  1680. X   /* mode == TRUE, save the area */
  1681. X
  1682. X   if ( mode == TRUE )
  1683. X      {
  1684. X
  1685. X      /* find an available slot */
  1686. X
  1687. X      carry_on = TRUE;
  1688. X      r = 0;
  1689. X      while( ( carry_on == TRUE ) && ( r < IMAGES ) )
  1690. X     {
  1691. X     if ( x_images[ r ] == NULL )
  1692. X        {
  1693. X        carry_on = FALSE;
  1694. X        }
  1695. X     else
  1696. X        {
  1697. X        ++r;
  1698. X        }
  1699. X     }
  1700. X
  1701. X      if ( r >= IMAGES )
  1702. X     {
  1703. X     bw_error( "No more slots for image storage" );
  1704. X     return FALSE;
  1705. X     }
  1706. X
  1707. X      *image = r;
  1708. X
  1709. X      /* create a new pixmap */
  1710. X
  1711. X      x_images[ *image ] = XCreatePixmap( x_display, x_selected,
  1712. X     ( x2 - x1 ) + 1, ( y2 - y1 ) + 1, x_depth );
  1713. X
  1714. X      /* copy the area */
  1715. X
  1716. X      XCopyArea( x_display, x_selected, x_images[ *image ], x_drawgc,
  1717. X         x1, grwind->ymax - y2, x2 - x1, y2 - y1, 0, 0 );
  1718. X      }
  1719. X
  1720. X   /* mode == FALSE, restore the area */
  1721. X
  1722. X   else
  1723. X      {
  1724. X      XCopyArea( x_display, x_images[ *image ], x_selected, x_drawgc,
  1725. X         0, 0, x2 - x1, y2 - y1, x1, grwind->ymax - y2 );
  1726. X      }
  1727. X   }
  1728. X
  1729. /****************************************************************
  1730. X
  1731. X   gr_imfree()
  1732. X
  1733. ****************************************************************/
  1734. X
  1735. gr_imfree( image )
  1736. X   int image;
  1737. X   {
  1738. X   XFreePixmap( x_display, x_images[ image ] );
  1739. X   x_images[ image ] = NULL;
  1740. X   }
  1741. X
  1742. /****************************************************************
  1743. X
  1744. X   gr_mouse()
  1745. X
  1746. ****************************************************************/
  1747. X
  1748. gr_mouse( mode, x, y, buttons )
  1749. X   int mode;
  1750. X   int *x, *y;
  1751. X   int *buttons;
  1752. X   {
  1753. X
  1754. X   switch ( mode )
  1755. X      {
  1756. X      case STATUS:
  1757. X      case SAMPLE:
  1758. X         if ( x_mousevent == TRUE )
  1759. X            {
  1760. X            *x = x_moxpos;
  1761. X            *y = grwind->ymax - x_moypos;
  1762. X            return TRUE;
  1763. X            }
  1764. X         x_pollevent();
  1765. X         if ( x_mousevent == TRUE )
  1766. X            {
  1767. X            *x = x_moxpos;
  1768. X            *y = grwind->ymax - x_moypos;
  1769. X            return TRUE;
  1770. X            }
  1771. X         return FALSE;
  1772. X         break;
  1773. X      
  1774. X      case WAIT:
  1775. X         while( x_mousevent == FALSE )
  1776. X            {
  1777. X            x_pollevent();
  1778. X            }
  1779. X         x_mousevent = FALSE;
  1780. X         *x = x_moxpos;
  1781. X         *y = grwind->ymax - x_moypos;
  1782. X         break;
  1783. X         
  1784. X      }
  1785. X
  1786. X   }
  1787. X
  1788. /****************************************************************
  1789. X
  1790. X   x_pollevent()
  1791. X
  1792. ****************************************************************/
  1793. X
  1794. x_pollevent()
  1795. X   {
  1796. X   static XEvent x_event;
  1797. X   static XComposeStatus x_cstatus;
  1798. X   static KeySym x_keysym;
  1799. X   static int x_keybufmaxlen = KEYBUF_LENGTH - 1;
  1800. X   static char x_keybuf[ KEYBUF_LENGTH ];
  1801. X   int length;
  1802. X  
  1803. #ifdef OLD_DEBUG
  1804. X   fprintf( stderr, "Polling...\n" );
  1805. #endif
  1806. X
  1807. X   /* poll X Window to see if there is an event */
  1808. X
  1809. X   if ( XCheckMaskEvent( x_display, (unsigned long) EVENT_MASK, &x_event ) 
  1810. X      == True )
  1811. X      {
  1812. X      switch ( x_event.type )
  1813. X         {
  1814. X         case ButtonPress:
  1815. X         case ButtonRelease:
  1816. #ifdef OLD_DEBUG
  1817. X            fprintf( stderr, "Mouse event...\n" );
  1818. #endif
  1819. X            x_mousevent = TRUE;
  1820. X            x_moxpos    = x_event.xbutton.x;
  1821. X            x_moypos    = x_event.xbutton.y;
  1822. X            break;
  1823. X         case KeyPress:
  1824. #ifdef OLD_DEBUG
  1825. X            fprintf( stderr, "Keyboard event...\n" );
  1826. #endif
  1827. X            x_keybevent  = TRUE;
  1828. X            length = XLookupString( &x_event, x_keybuf, x_keybufmaxlen, 
  1829. X               &x_keysym,
  1830. X               &x_cstatus );
  1831. X            if ( ( x_keysym >= ' ' ) && ( x_keysym <= '~' )
  1832. X               && ( length > 0 ))
  1833. X               {
  1834. X               x_keypending = x_keysym;
  1835. X               }
  1836. X            else
  1837. X               {
  1838. X               switch( x_keysym )
  1839. X                  {
  1840. X                  case XK_Return:
  1841. X                     x_keypending = '\r';
  1842. X                     break;
  1843. X                  case XK_BackSpace:
  1844. X                     x_keypending = '\010';
  1845. X                     break;
  1846. X                  case XK_Escape:
  1847. X                     x_keypending = '\033';
  1848. X                     break;
  1849. X                  case XK_Delete:
  1850. X                     x_keypending = KB_DELETE;
  1851. X                     break;
  1852. X                  case XK_Up:
  1853. X                     x_keypending = KB_UP;
  1854. X                     break;
  1855. X                  case XK_Down:
  1856. X                     x_keypending = KB_DOWN;
  1857. X                     break;
  1858. X                  case XK_Right:
  1859. X                     x_keypending = KB_RIGHT;
  1860. X                     break;
  1861. X                  case XK_Left:
  1862. X                     x_keypending = KB_LEFT;
  1863. X                     break;
  1864. X                  case XK_F1:
  1865. X                     x_keypending = KB_FK1;
  1866. X                     break;
  1867. X                  case XK_F2:
  1868. X                     x_keypending = KB_FK2;
  1869. X                     break;
  1870. X                  case XK_F3:
  1871. X                     x_keypending = KB_FK3;
  1872. X                     break;
  1873. X                  default:
  1874. X                     x_keypending = 0;
  1875. X                     break;
  1876. X                  }
  1877. X               }
  1878. X            break;
  1879. X         }      
  1880. X      return TRUE;
  1881. X      }
  1882. X
  1883. X   return FALSE;
  1884. X      
  1885. X   }
  1886. X
  1887. /****************************************************************
  1888. X
  1889. X   x_initcolor()
  1890. X
  1891. ****************************************************************/
  1892. X
  1893. x_initcolor()
  1894. X   {
  1895. X   
  1896. X   if ( x_depth <= 1 )
  1897. X      {
  1898. X      return FALSE;
  1899. X      }
  1900. X
  1901. X   gr_colors = 16;
  1902. X
  1903. X   XLookupColor( x_display, x_colormap, "Black", &rgbcolor, &hardwarecolor );
  1904. X   XAllocColor( x_display, x_colormap, &hardwarecolor );
  1905. X   x_colchart[ BLACK ] = hardwarecolor.pixel;
  1906. X   
  1907. X   XLookupColor( x_display, x_colormap, "White", &rgbcolor, &hardwarecolor );
  1908. X   XAllocColor( x_display, x_colormap, &hardwarecolor );
  1909. X   x_colchart[ WHITE ] = hardwarecolor.pixel;
  1910. X   
  1911. X   XLookupColor( x_display, x_colormap, "Red", &rgbcolor, &hardwarecolor );
  1912. X   XAllocColor( x_display, x_colormap, &hardwarecolor );
  1913. X   x_colchart[ LIGHT_RED ] = hardwarecolor.pixel;
  1914. X   x_colchart[ DARK_RED ] = hardwarecolor.pixel;
  1915. X   
  1916. X   XLookupColor( x_display, x_colormap, "Green", &rgbcolor, &hardwarecolor );
  1917. X   XAllocColor( x_display, x_colormap, &hardwarecolor );
  1918. X   x_colchart[ LIGHT_GREEN ] = hardwarecolor.pixel;
  1919. X   x_colchart[ DARK_GREEN ] = hardwarecolor.pixel;
  1920. X
  1921. X   XLookupColor( x_display, x_colormap, "Blue", &rgbcolor, &hardwarecolor );
  1922. X   XAllocColor( x_display, x_colormap, &hardwarecolor );
  1923. X   x_colchart[ LIGHT_BLUE ] = hardwarecolor.pixel;
  1924. X   x_colchart[ DARK_BLUE ] = hardwarecolor.pixel;
  1925. X
  1926. X   XLookupColor( x_display, x_colormap, "Yellow", &rgbcolor, &hardwarecolor );
  1927. X   XAllocColor( x_display, x_colormap, &hardwarecolor );
  1928. X   x_colchart[ LIGHT_YELLOW ] = hardwarecolor.pixel;
  1929. X   x_colchart[ DARK_YELLOW ] = hardwarecolor.pixel;
  1930. X
  1931. X   XLookupColor( x_display, x_colormap, "Cyan", &rgbcolor, &hardwarecolor );
  1932. X   XAllocColor( x_display, x_colormap, &hardwarecolor );
  1933. X   x_colchart[ LIGHT_CYAN ] = hardwarecolor.pixel;
  1934. X   x_colchart[ DARK_CYAN ] = hardwarecolor.pixel;
  1935. X
  1936. X   XLookupColor( x_display, x_colormap, "Magenta", &rgbcolor, &hardwarecolor );
  1937. X   XAllocColor( x_display, x_colormap, &hardwarecolor );
  1938. X   x_colchart[ LIGHT_MAGENTA ] = hardwarecolor.pixel;
  1939. X   x_colchart[ DARK_MAGENTA ] = hardwarecolor.pixel;
  1940. X
  1941. X   return TRUE;
  1942. X   }
  1943. X
  1944. /****************************************************************
  1945. X
  1946. X   x_color()
  1947. X
  1948. ****************************************************************/
  1949. X
  1950. unsigned long
  1951. x_color( gr_color )
  1952. X   int gr_color;
  1953. X   {
  1954. X
  1955. X
  1956. X   if ( x_depth <= 1 )
  1957. X      {
  1958. X      switch ( gr_color )
  1959. X         {
  1960. X         case WHITE:
  1961. X            return WhitePixel( x_display, x_screen );
  1962. X            break;
  1963. X         case BLACK:
  1964. X         default:
  1965. X            return BlackPixel( x_display, x_screen );
  1966. X            break;
  1967. X         }
  1968. X      }
  1969. X
  1970. X   else
  1971. X      {
  1972. X      return x_colchart[ gr_color ];
  1973. X      }
  1974. X   }
  1975. X
  1976. /****************************************************************
  1977. X
  1978. X   x_fillstyle()
  1979. X
  1980. ****************************************************************/
  1981. X
  1982. x_fillstyle( gr_fillstyle )
  1983. X   int gr_fillstyle;
  1984. X   {
  1985. X   switch( gr_fillstyle )
  1986. X      {
  1987. X      case GRID:
  1988. X         return FillStippled;
  1989. X         break;
  1990. X      case HATCH:
  1991. X         return FillTiled;
  1992. X         break;
  1993. X      case HOLLOW:
  1994. X      case SOLID:
  1995. X      default:
  1996. X         return FillSolid;
  1997. X         break;
  1998. X      } 
  1999. X   }
  2000. X
  2001. /****************************************************************
  2002. X
  2003. X   x_linestyle()
  2004. X
  2005. ****************************************************************/
  2006. X
  2007. x_linestyle( gr_linestyle )
  2008. X   int gr_linestyle;
  2009. X   {
  2010. X   switch( gr_linestyle )
  2011. X      {
  2012. X      case GRID:
  2013. X         return LineOnOffDash;
  2014. X         break;
  2015. X      case SOLID:
  2016. X      case HOLLOW:
  2017. X      default:
  2018. X         return LineSolid;
  2019. X         break;
  2020. X      }
  2021. X   }
  2022. X
  2023. /****************************************************************
  2024. X
  2025. X   x_setscreen()
  2026. X
  2027. ****************************************************************/
  2028. X
  2029. x_setscreen( screen )
  2030. X   int screen;
  2031. X   {
  2032. X   switch( screen )
  2033. X      {
  2034. X      case GR_PRIMARY:
  2035. X         x_selected = (Drawable) x_primary;
  2036. X         break;
  2037. X      case GR_HIDDEN:
  2038. X         x_selected = (Drawable) x_hidden;
  2039. X         break;
  2040. X      default:
  2041. #ifdef DEBUG
  2042. X         sprintf( bw_ebuf, "[pr:] x_screen received %d", screen );
  2043. X         bw_error( bw_ebuf );
  2044. #endif
  2045. X         return BW_ERROR;
  2046. X         break;
  2047. X      }
  2048. X   return TRUE;
  2049. X   }
  2050. X
  2051. X
  2052. SHAR_EOF
  2053. chmod 0644 io/gr/gr_x.c ||
  2054. echo 'restore of io/gr/gr_x.c failed'
  2055. Wc_c="`wc -c < 'io/gr/gr_x.c'`"
  2056. test 30654 -eq "$Wc_c" ||
  2057.     echo 'io/gr/gr_x.c: original size 30654, current size' "$Wc_c"
  2058. rm -f _shar_wnt_.tmp
  2059. fi
  2060. # ============= io/gr/makefile.tam ==============
  2061. if test -f 'io/gr/makefile.tam' -a X"$1" != X"-c"; then
  2062.     echo 'x - skipping io/gr/makefile.tam (File already exists)'
  2063.     rm -f _shar_wnt_.tmp
  2064. else
  2065. > _shar_wnt_.tmp
  2066. echo 'x - extracting io/gr/makefile.tam (Binary)'
  2067. sed 's/^X//' << 'SHAR_EOF' > _shar_tmp_.tmp &&
  2068. begin 600 io/gr/makefile.tam
  2069. SHAR_EOF
  2070. true || echo 'restore of io/gr/makefile.tam failed'
  2071. fi
  2072. echo 'End of  part 4'
  2073. echo 'File io/gr/makefile.tam is continued in part 5'
  2074. echo 5 > _shar_seq_.tmp
  2075. exit 0
  2076. exit 0 # Just in case...
  2077. -- 
  2078. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2079. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2080. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2081. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2082.