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

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  3. Subject:  v27i003:  sfs - Space Flight Simulator, Part03/21
  4. Message-ID: <1991Dec24.045207.29552@sparky.imd.sterling.com>
  5. X-Md4-Signature: ce194fd2a5fbe9e3ff1acfba1a2bfc0e
  6. Date: Tue, 24 Dec 1991 04:52:07 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 3
  11. Archive-name: sfs/part03
  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_mgr.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" != 3; 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_mgr.c'
  32. else
  33. echo 'x - continuing file io/gr/gr_mgr.c'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'io/gr/gr_mgr.c' &&
  35. X      }
  36. X   }
  37. X         
  38. /****************************************************************
  39. X
  40. X   gr_line()
  41. X
  42. ****************************************************************/
  43. X
  44. gr_line( screen, x1, y1, x2, y2, color, style )
  45. X   int screen;
  46. X   int x1, y1, x2, y2;
  47. X   int color, style;
  48. X   {
  49. X
  50. #if    CHECKPARAMS
  51. X   if ( ( x1 < 0 ) || ( x1 > mgr_grwind->xmax ))
  52. X      {
  53. X      sprintf( bw_ebuf, "[pr:] gr_line(): x1 value is %d", x1 );
  54. X      bw_error( bw_ebuf );
  55. X      return BW_ERROR;
  56. X      }
  57. X   if ( ( x2 < 0 ) || ( x2 > mgr_grwind->xmax ))
  58. X      {
  59. X      sprintf( bw_ebuf, "[pr:] gr_line(): x2 value is %d", x2 );
  60. X      bw_error( bw_ebuf );
  61. X      return BW_ERROR;
  62. X      }
  63. X   if ( ( y1 < 0 ) || ( y1 > mgr_grwind->ymax ))
  64. X      {
  65. X      sprintf( bw_ebuf, "[pr:] gr_line(): y1 value is %d", y1 );
  66. X      bw_error( bw_ebuf );
  67. X      return BW_ERROR;
  68. X      }
  69. X   if ( ( y2 < 0 ) || ( y2 > mgr_grwind->ymax ))
  70. X      {
  71. X      sprintf( bw_ebuf, "[pr:] gr_line(): y2 value is %d", y2 );
  72. X      bw_error( bw_ebuf );
  73. X      return BW_ERROR;
  74. X      }
  75. #endif
  76. X
  77. X   mgr_color( color );
  78. X   if ( screen == MGR_DRAWMAIN )
  79. X      {
  80. X      m_line( x1, mgr_y( y1 ),
  81. X         x2, mgr_y( y2 ) );
  82. X      }
  83. X   else
  84. X      {
  85. X      m_lineto( screen, x1, mgr_y( y1 ),
  86. X         x2, mgr_y( y2 ) );
  87. X      }
  88. X   }
  89. X
  90. /****************************************************************
  91. X
  92. X   gr_text()
  93. X
  94. ****************************************************************/
  95. X
  96. gr_text( screen, x, y, string, foreground, background )
  97. X   int screen;
  98. X   int x, y;
  99. X   int foreground, background;
  100. X   char *string;
  101. X   {
  102. X
  103. #if    CHECK_PARAMS
  104. X   if ( ( x < 0 ) || ( x > mgr_grwind->xmax ))
  105. X      {
  106. X      fprintf( stderr, "ERROR: [pr:] gr_text(): x value is %d", x );
  107. X      kb_rx();
  108. X      return BW_ERROR;
  109. X      }
  110. X   if ( ( y < 0 ) || ( y > mgr_grwind->ymax ))
  111. X      {
  112. X      fprintf( stderr, "ERROR: [pr:] gr_text(): y value is %d", y );
  113. X      kb_rx();
  114. X      return BW_ERROR;
  115. X      }
  116. #endif
  117. X
  118. X   m_func( B_SET );
  119. /*   m_move( 0, 0 ); */
  120. X
  121. X   if ( foreground == WHITE )
  122. X      {
  123. X      m_clearmode( M_STANDOUT );
  124. X      }
  125. X   else
  126. X      {
  127. X      m_setmode( M_STANDOUT );
  128. X      }
  129. X   if ( screen == MGR_DRAWMAIN )
  130. X      {
  131. X      m_moveprint( x, mgr_y( y ), string );
  132. X      }
  133. X   else
  134. X      {
  135. X      m_stringto( screen, x, mgr_y( y ), string );
  136. X      }
  137. X   }
  138. X
  139. /****************************************************************
  140. X
  141. X   gr_strlen()
  142. X
  143. ****************************************************************/
  144. X
  145. unsigned int
  146. gr_strlen( string )
  147. X   char *string;
  148. X   {
  149. X   return ( strlen( string ) * mgr_grwind->fxsize );
  150. X   }
  151. X
  152. /****************************************************************
  153. X
  154. X   gr_rectangle()
  155. X
  156. ****************************************************************/
  157. X
  158. gr_rectangle( screen, x1, y1, x2, y2, color, style )
  159. X   int screen;
  160. X   int x1, y1, x2, y2;
  161. X   int color, style;
  162. X   {
  163. X
  164. #if    CHECK_PARAMS
  165. X   if ( ( x1 < 0 ) || ( x1 > mgr_grwind->xmax ))
  166. X      {
  167. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x1 value is %d", x1 );
  168. X      bw_error( bw_ebuf );
  169. X      return BW_ERROR;
  170. X      }
  171. X   if ( ( x2 < 0 ) || ( x2 > mgr_grwind->xmax ))
  172. X      {
  173. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x2 value is %d", x2 );
  174. X      bw_error( bw_ebuf );
  175. X      return BW_ERROR;
  176. X      }
  177. X   if ( ( y1 < 0 ) || ( y1 > mgr_grwind->ymax ))
  178. X      {
  179. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y1 value is %d", y1 );
  180. X      bw_error( bw_ebuf );
  181. X      return BW_ERROR;
  182. X      }
  183. X   if ( ( y2 < 0 ) || ( y2 > mgr_grwind->ymax ))
  184. X      {
  185. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y2 value is %d", y2 );
  186. X      bw_error( bw_ebuf );
  187. X      return BW_ERROR;
  188. X      }
  189. #endif
  190. X
  191. X   switch( style )
  192. X      {
  193. X      case SOLID:
  194. X         if ( color == WHITE )
  195. X            {
  196. X            m_func( B_SET );
  197. X            }
  198. X         else
  199. X            {
  200. X            m_func( B_CLEAR );
  201. X            }
  202. X         m_bitcopyto( x1, mgr_y( y2 ), 
  203. X            abs( x2 - x1 ), abs( y2 - y1 ),
  204. X            x1, mgr_y( y2 ),
  205. X            screen, MGR_DRAWGRID ); 
  206. X         break;
  207. X      case GRID:
  208. X      case HATCH:
  209. X         m_func( B_SRC );
  210. X         m_bitcopyto( x1, mgr_y( y2 ),
  211. X            abs( x2 - x1 ), abs( y2 - y1 ),
  212. X            x1, mgr_y( y2 ),
  213. X            screen, MGR_DRAWGRID ); 
  214. X         break;
  215. X      case HOLLOW:
  216. X      default:
  217. X         mgr_color( color );
  218. X         if ( screen == MGR_DRAWMAIN )
  219. X            {
  220. X            m_line( x1, mgr_y( y1 ), 
  221. X               x2, mgr_y( y1 ) );
  222. X            m_line( x2, mgr_y( y1 ), x2, 
  223. X               mgr_y( y2 ) );
  224. X            m_line( x1, mgr_y( y2 ), 
  225. X               x2, mgr_y( y2 ) );
  226. X            m_line( x1, mgr_y( y2 ), 
  227. X               x1, mgr_y( y1 ) );
  228. X            }
  229. X         else
  230. X            {
  231. X            m_lineto( screen, x1, mgr_y( y1 ), 
  232. X               x2, mgr_y( y1 ) );
  233. X            m_lineto( screen, x2, mgr_y( y1 ), x2, 
  234. X               mgr_y( y2 ) );
  235. X            m_lineto( screen, x1, mgr_y( y2 ), 
  236. X               x2, mgr_y( y2 ) );
  237. X            m_lineto( screen, x1, mgr_y( y2 ), 
  238. X               x1, mgr_y( y1 ) );
  239. X            }
  240. X         break;
  241. X      }
  242. X   }
  243. X
  244. /****************************************************************
  245. X
  246. X   gr_circle()
  247. X
  248. ****************************************************************/
  249. X
  250. gr_circle( screen, x, y, radius, color, style )
  251. X   int screen;
  252. X   int x, y, radius;
  253. X   int color, style;
  254. X   {
  255. X   register int c;
  256. X
  257. #if    CHECK_PARAMS
  258. X   if ( ( x < 0 ) || ( x > mgr_grwind->xmax ))
  259. X      {
  260. X      sprintf( bw_ebuf, "[pr:] gr_circle(): x value is %d", x );
  261. X      bw_error( bw_ebuf );
  262. X      return BW_ERROR;
  263. X      }
  264. X   if ( ( y < 0 ) || ( y > mgr_grwind->ymax ))
  265. X      {
  266. X      sprintf( bw_ebuf, "[pr:] gr_circle(): y value is %d", y );
  267. X      bw_error( bw_ebuf );
  268. X      return BW_ERROR;
  269. X      }
  270. #endif
  271. X
  272. X   mgr_color( color );
  273. X   switch( style )
  274. X      {
  275. X      case SOLID:
  276. X      case HATCH:
  277. X      case GRID:
  278. X         for ( c = 0; c <= radius; ++c )
  279. X            {
  280. X            if ( screen == MGR_DRAWMAIN )
  281. X               {
  282. X               m_ellipse( x, mgr_y( y ), 
  283. X                  c, ( c * gr_pxsize ) / gr_pysize );
  284. X               }
  285. X            else
  286. X               {
  287. X               m_ellipseto( screen, x, mgr_y( y ), 
  288. X                  c, ( c * gr_pxsize ) / gr_pysize );
  289. X               }
  290. X            }
  291. X         break;
  292. X      case HOLLOW:
  293. X      default:
  294. X         if ( screen == MGR_DRAWMAIN )
  295. X            {
  296. X            m_ellipse( x, mgr_y( y ), 
  297. X               radius, ( radius * gr_pxsize ) / gr_pysize );
  298. X            }
  299. X         else
  300. X            {
  301. X            m_ellipseto( screen, x, mgr_y( y ), 
  302. X               radius, ( radius * gr_pxsize ) / gr_pysize );
  303. X            }
  304. X         break;
  305. X      }
  306. X   }
  307. X
  308. /****************************************************************
  309. X
  310. X   gr_ellipse()
  311. X
  312. ****************************************************************/
  313. X
  314. gr_ellipse( screen, x, y, x_radius, y_radius, mode, color, style )
  315. X   int screen;
  316. X   int x, y, x_radius, y_radius;
  317. X   int mode, color, style;
  318. X   {
  319. X   }
  320. X         
  321. /****************************************************************
  322. X
  323. X   gr_clip()
  324. X
  325. ****************************************************************/
  326. X
  327. gr_clip( screen, mode, x1, y1, x2, y2 )
  328. X   int screen;
  329. X   int mode;
  330. X   int x1, y1, x2, y2;
  331. X   {
  332. X
  333. #ifdef  DEBUG
  334. X   if ( ( x1 < 0 ) || ( x1 > mgr_grwind->xmax ))
  335. X      {
  336. X      sprintf( bw_ebuf, "[pr:] gr_clip(): x1 value is %d", x1 );
  337. X      bw_error( bw_ebuf );
  338. X      return BW_ERROR;
  339. X      }
  340. X   if ( ( x2 < 0 ) || ( x2 > mgr_grwind->xmax ))
  341. X      {
  342. X      sprintf( bw_ebuf, "[pr:] gr_clip(): x2 value is %d", x2 );
  343. X      bw_error( bw_ebuf );
  344. X      return BW_ERROR;
  345. X      }
  346. X   if ( ( y1 < 0 ) || ( y1 > mgr_grwind->ymax ))
  347. X      {
  348. X      sprintf( bw_ebuf, "[pr:] gr_clip(): y1 value is %d", y1 );
  349. X      bw_error( bw_ebuf );
  350. X      return BW_ERROR;
  351. X      }
  352. X   if ( ( y2 < 0 ) || ( y2 > mgr_grwind->ymax ))
  353. X      {
  354. X      sprintf( bw_ebuf, "[pr:] gr_clip(): y2 value is %d", y2 );
  355. X      bw_error( bw_ebuf );
  356. X      return BW_ERROR;
  357. X      }
  358. #endif
  359. X
  360. X   return BW_ERROR;
  361. X   }
  362. X
  363. /****************************************************************
  364. X
  365. X   gr_font()
  366. X
  367. ****************************************************************/
  368. X
  369. gr_font( screen, type, rq_height )
  370. X   int screen;
  371. X   int type, rq_height;
  372. X   {
  373. X   static int x_fontno;
  374. X
  375. X   if ( rq_height > 18 )
  376. X      {
  377. X      x_fontno = MGR_FONT4;
  378. X      mgr_grwind->fysize = 20;
  379. X      mgr_grwind->fxsize = 12;
  380. X      }
  381. X   else if ( rq_height > 15 )
  382. X      {
  383. X      x_fontno = MGR_FONT3;
  384. X      mgr_grwind->fysize = 16;
  385. X      mgr_grwind->fxsize = 8;
  386. X      }
  387. X   else if ( rq_height > 13 )
  388. X      {
  389. X      x_fontno = MGR_FONT2;
  390. X      mgr_grwind->fysize = 14;
  391. X      mgr_grwind->fxsize = 7;
  392. X      }
  393. #ifdef    TINYFONT
  394. X    else if ( rq_height > 9 )
  395. X      {
  396. X      x_fontno = MGR_FONT1;
  397. X      mgr_grwind->fysize = 12;
  398. X      mgr_grwind->fxsize = 6;
  399. X      }
  400. X   else 
  401. X      {
  402. X      x_fontno = MGR_FONT0;
  403. X      mgr_grwind->fysize = 7;
  404. X      mgr_grwind->fxsize = 4;
  405. X      }
  406. #else
  407. X   else
  408. X      {
  409. X      x_fontno = MGR_FONT1;
  410. X      mgr_grwind->fysize = 12;
  411. X      mgr_grwind->fxsize = 6;
  412. X      }
  413. #endif      
  414. X
  415. X   mgr_curspark();            /* get cursor out of the way */
  416. X   m_font( x_fontno );
  417. X
  418. X   }
  419. X
  420. /****************************************************************
  421. X
  422. X   gr_blit()
  423. X
  424. ****************************************************************/
  425. X
  426. gr_blit( src, dst, x1, y1, x2, y2 )
  427. X   int src, dst;
  428. X   int x1, y1, x2, y2;
  429. X   {
  430. X
  431. #if    CHECK_PARAMS
  432. X   if ( ( x1 < 0 ) || ( x1 > mgr_grwind->xmax ))
  433. X      {
  434. X      sprintf( bw_ebuf, "[pr:] gr_blit(): x1 value is %d", x1 );
  435. X      bw_error( bw_ebuf );
  436. X      return BW_ERROR;
  437. X      }
  438. X   if ( ( x2 < 0 ) || ( x2 > mgr_grwind->xmax ))
  439. X      {
  440. X      sprintf( bw_ebuf, "[pr:] gr_blit(): x2 value is %d", x2 );
  441. X      bw_error( bw_ebuf );
  442. X      return BW_ERROR;
  443. X      }
  444. X   if ( ( y1 < 0 ) || ( y1 > mgr_grwind->ymax ))
  445. X      {
  446. X      sprintf( bw_ebuf, "[pr:] gr_blit(): y1 value is %d", y1 );
  447. X      bw_error( bw_ebuf );
  448. X      return BW_ERROR;
  449. X      }
  450. X   if ( ( y2 < 0 ) || ( y2 > mgr_grwind->ymax ))
  451. X      {
  452. X      sprintf( bw_ebuf, "[pr:] gr_blit(): y2 value is %d", y2 );
  453. X      bw_error( bw_ebuf );
  454. X      return BW_ERROR;
  455. X      }
  456. X   if ( src == dst )
  457. X      {
  458. X      sprintf( bw_ebuf, "[pr:] gr_blit(): src == dst" );
  459. X      bw_error( bw_ebuf );
  460. X      return BW_ERROR;
  461. X      }
  462. #endif
  463. X
  464. X   if ( src == dst )
  465. X      {
  466. X      return BW_ERROR;
  467. X      }
  468. X
  469. X   m_func( B_SRC );
  470. X   m_bitcopyto( x1, mgr_y( y2 ), x2 - x1, y2 - y1, 
  471. X      x1, mgr_y( y2 ), dst, src );
  472. X   }
  473. X
  474. /****************************************************************
  475. X
  476. X   gr_imsave()
  477. X
  478. ****************************************************************/
  479. X
  480. gr_imsave( screen, mode, x1, y1, x2, y2, image )
  481. X   int screen; 
  482. X   int mode, x1, y1, x2, y2;
  483. X   int *image;
  484. X   {
  485. X
  486. #if    CHECK_PARAMS
  487. X   if ( ( x1 < 0 ) || ( x1 > mgr_grwind->xmax ))
  488. X      {
  489. X      sprintf( bw_ebuf, "[pr:] gr_save(): x1 value is %d", x1 );
  490. X      bw_error( bw_ebuf );
  491. X      return BW_ERROR;
  492. X      }
  493. X   if ( ( x2 < 0 ) || ( x2 > mgr_grwind->xmax ))
  494. X      {
  495. X      sprintf( bw_ebuf, "[pr:] gr_save(): x2 value is %d", x2 );
  496. X      bw_error( bw_ebuf );
  497. X      return BW_ERROR;
  498. X      }
  499. X   if ( ( y1 < 0 ) || ( y1 > mgr_grwind->ymax ))
  500. X      {
  501. X      sprintf( bw_ebuf, "[pr:] gr_save(): y1 value is %d", y1 );
  502. X      bw_error( bw_ebuf );
  503. X      return BW_ERROR;
  504. X      }
  505. X   if ( ( y2 < 0 ) || ( y2 > mgr_grwind->ymax ))
  506. X      {
  507. X      sprintf( bw_ebuf, "[pr:] gr_save(): y2 value is %d", y2 );
  508. X      bw_error( bw_ebuf );
  509. X      return BW_ERROR;
  510. X      }
  511. #endif
  512. X
  513. X   if ( mode == TRUE )
  514. X      {
  515. X      *image = mgr_getbno();                /* assign a number */
  516. X
  517. #ifdef OLD_DEBUG
  518. X      fprintf( stderr, "\nDEBUG: Window number is %d", *i );
  519. X      kb_rx();
  520. #endif
  521. X
  522. X      m_bitcreate( *image, abs( x2 - x1 ), abs( y2 - y1 ) );
  523. X
  524. X      m_func( B_SRC );
  525. X      m_bitcopyto( x1, mgr_y( y2 ), 
  526. X         abs( x2 - x1 ), abs( y2 - y1 ),
  527. X     x1, mgr_y( y2 ), *image, MGR_DRAWMAIN );
  528. X      }
  529. X   else
  530. X      {
  531. #ifdef OLD_DEBUG
  532. X      fprintf( stderr, "\nDEBUG: Window number is %d", *image );
  533. X      kb_rx();
  534. #endif
  535. X      m_func( B_SRC );
  536. X      m_bitcopyto( x1, mgr_y( y2 ),
  537. X         abs( x2 - x1 ), abs( y2 - y1 ),
  538. X     x1, mgr_y( y2 ), MGR_DRAWMAIN, *image );
  539. X      }
  540. X   }
  541. X
  542. /****************************************************************
  543. X
  544. X    gr_imfree()
  545. X
  546. ****************************************************************/
  547. X
  548. gr_imfree( image )
  549. X   int image;
  550. X   {
  551. X   m_bitdestroy( image );
  552. X   }
  553. X
  554. /****************************************************************
  555. X
  556. X   gr_mouse()
  557. X
  558. ****************************************************************/
  559. X
  560. gr_mouse( mode, x, y, buttons )
  561. X   int mode;
  562. X   int *x, *y;
  563. X   int *buttons;
  564. X   {
  565. X   static int m_pending = FALSE, x_save, y_save;
  566. X   static int m_prevr;
  567. X   int c, r;
  568. X
  569. X   switch( mode )
  570. X      {
  571. X      case SAMPLE:
  572. X         if ( m_pending == TRUE )
  573. X            {
  574. X            *x = x_save;
  575. X            *y = y_save;
  576. X            return TRUE;
  577. X            }
  578. X         r = mgr_mouse( x, y );
  579. X         *y = mgr_y( *y );
  580. X         if ( r == TRUE )
  581. X            {
  582. X            m_pending = TRUE;
  583. X            x_save = *x;
  584. X            y_save = *y;
  585. X            }
  586. X         return r;
  587. X         break;
  588. X      case WAIT:
  589. X         if ( m_pending == TRUE )
  590. X            {
  591. X            m_pending = FALSE;
  592. X            *x = x_save;
  593. X            *y = y_save;
  594. X            return TRUE;
  595. X            }
  596. X         c = FALSE;
  597. X         while( c == FALSE )
  598. X            {
  599. X            c = r = mgr_mouse( x, y );
  600. X            *y = mgr_y( *y );
  601. X            }
  602. X         m_pending = FALSE;
  603. X         m_prevr = r;
  604. X         return TRUE;
  605. X         break;
  606. X      default:
  607. #ifdef    DEBUG
  608. X         sprintf( bw_ebuf, "gr_mouse() received mode %d", mode );
  609. X         bw_error( bw_ebuf );
  610. #endif
  611. X         return BW_ERROR;
  612. X         break;
  613. X      }
  614. X   
  615. X   }
  616. X
  617. mgr_mouse( x, y )
  618. X   int *x, *y;
  619. X   {
  620. X   static int r = 0, x_prevr = 0;
  621. X
  622. X   r = get_mouse( x, y );
  623. #ifdef    OLD_DEBUG
  624. X   sprintf( bw_ebuf, "r = %d", r );
  625. X   gr_text( GR_PRIMARY, 12, 12, bw_ebuf, WHITE, BLACK );
  626. #endif
  627. X   if ( r == x_prevr )
  628. X      {
  629. X      return FALSE;
  630. X      }
  631. X   x_prevr = r;
  632. X   return TRUE;
  633. X   }
  634. X
  635. mgr_y( oldyval )
  636. X   int oldyval;
  637. X   {
  638. X   return (( mgr_grwind->ymax  ) - oldyval );
  639. X   }
  640. X
  641. mgr_color( color )
  642. X   int color;
  643. X   {
  644. X   if ( color == WHITE )
  645. X      {
  646. X      m_func( B_SET );
  647. X      }
  648. X   else
  649. X      {
  650. X      m_func( B_CLEAR );
  651. X      }
  652. X   }
  653. X
  654. mgr_getbno()
  655. X   {
  656. X   static int x = MGR_DRAWSTART;
  657. X
  658. X   ++x;
  659. X   return x;
  660. X   }
  661. X
  662. mgr_curspark()
  663. X   {
  664. X   m_movecursor( 0, 85 );
  665. X   }
  666. X
  667. SHAR_EOF
  668. echo 'File io/gr/gr_mgr.c is complete' &&
  669. chmod 0644 io/gr/gr_mgr.c ||
  670. echo 'restore of io/gr/gr_mgr.c failed'
  671. Wc_c="`wc -c < 'io/gr/gr_mgr.c'`"
  672. test 23877 -eq "$Wc_c" ||
  673.     echo 'io/gr/gr_mgr.c: original size 23877, current size' "$Wc_c"
  674. rm -f _shar_wnt_.tmp
  675. fi
  676. # ============= io/gr/gr_spec.c ==============
  677. if test -f 'io/gr/gr_spec.c' -a X"$1" != X"-c"; then
  678.     echo 'x - skipping io/gr/gr_spec.c (File already exists)'
  679.     rm -f _shar_wnt_.tmp
  680. else
  681. > _shar_wnt_.tmp
  682. echo 'x - extracting io/gr/gr_spec.c (Text)'
  683. sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_spec.c' &&
  684. /****************************************************************
  685. X
  686. X    gr_spec.c    Specification of Graphics Interface 
  687. X            for Space Flight Simulator
  688. X
  689. X            Copyright (c) 1991, Ted A. Campbell
  690. X
  691. X            Bywater Software
  692. X            P. O. Box 4023 
  693. X            Duke Station 
  694. X            Durham, NC  27706
  695. X
  696. X            email: tcamp@hercules.acpub.duke.edu
  697. X
  698. X    Copyright and Permissions Information:
  699. X
  700. X    All U.S. and international copyrights are claimed by the
  701. X    author. The author grants permission to use this code
  702. X    and software based on it under the following conditions:
  703. X    (a) in general, the code and software based upon it may be 
  704. X    used by individuals and by non-profit organizations; (b) it
  705. X    may also be utilized by governmental agencies in any country,
  706. X    with the exception of military agencies; (c) the code and/or
  707. X    software based upon it may not be sold for a profit without
  708. X    an explicit and specific permission from the author, except
  709. X    that a minimal fee may be charged for media on which it is
  710. X    copied, and for copying and handling; (d) the code must be 
  711. X    distributed in the form in which it has been released by the
  712. X    author; and (e) the code and software based upon it may not 
  713. X    be used for illegal activities. 
  714. X
  715. X    This file specifies the interface for graphics and mouse 
  716. X    handling utilized in the Space Flight Simulator.  This file
  717. X    may be utilized as the basis for implementations of gr and 
  718. X    thus of sfs on varied computers.  If you can implement the
  719. X    functions specified in this file, sfs should be implemented.
  720. X
  721. X    COORDINATE SYSTEM. The gr interface presupposes throughout
  722. X    a Cartesian coordinate system in which pixels on the vertical
  723. X    axis (the y axis) are numbered beginning with 0 from the
  724. X    bottom up, and pixels on the horizontal axis (the x axis)
  725. X    are numbered beginning with 0 from the ;eft to the right.
  726. X    The numbering of the y axis may seem counterintuitive,
  727. X    since in many systems pixels are numbered vertically from
  728. X    the top to the bottom.
  729. X
  730. ****************************************************************/
  731. X
  732. #include "stdio.h"
  733. #include "gr.h"
  734. X
  735. int     gr_colors;      /* number of colors available */
  736. int     gr_pxsize;      /* relative size of pixel, horizontal */
  737. int     gr_pysize;      /* relative size of pixel, vertical */
  738. int     gr_ismouse;     /* boolean -- does mouse exist? */
  739. int     gr_clipping;    /* boolean -- is clipping implemented? */
  740. int     gr_blitting;    /* boolean -- is blitting implemented? */
  741. int     gr_saving;      /* boolean -- is screen saving implemented? */
  742. int     gr_screens;     /* number of screens, 1 = visible screen
  743. X               (GR_PRIMARY) only, 2 = visible and
  744. X               hidden screen (GR_PRIMARY and GR_HIDDEN)
  745. X               are available */
  746. X
  747. /****************************************************************
  748. X
  749. X   gr_init()
  750. X
  751. X   This function should initialize the entire graphics and mouse
  752. X   subsystem. The argument "grwindow" is a pointer to a gr_window
  753. X   structure which should be filled in by the function. The
  754. X   argument "font_path" is a pointer to a character string
  755. X   giving the name of a path where the function should look
  756. X   for font and other data files. The function should return
  757. X   BW_ERROR upon any error and TRUE upon a successful setting
  758. X   of the graphics subsystem.
  759. X
  760. ****************************************************************/
  761. X
  762. gr_init( grwindow, font_path )
  763. X   struct gr_window *grwindow;
  764. X   char * font_path;
  765. X   {
  766. X   }
  767. X
  768. /****************************************************************
  769. X
  770. X   gr_deinit()
  771. X
  772. X   This function should deinitialize the entire graphics subsystem.
  773. X
  774. ****************************************************************/
  775. X
  776. gr_deinit()
  777. X   {
  778. X   }
  779. X
  780. /****************************************************************
  781. X
  782. X   gr_cls()
  783. X
  784. X   This function should clear the entire screen area.
  785. X
  786. X   The argument "screen" is an integer denoted either the
  787. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  788. X   to which graphics output can be written (defined as
  789. X   GR_HIDDEN).
  790. X
  791. ****************************************************************/
  792. X
  793. gr_cls( screen )
  794. X   int screen;
  795. X   {
  796. X   }
  797. X
  798. X
  799. /****************************************************************
  800. X
  801. X   gr_pixel()
  802. X
  803. X   This function turns on (or off, if the color is BLACK) a single
  804. X   pixel on the display.
  805. X
  806. X   The argument "screen" is an integer denoted either the
  807. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  808. X   to which graphics output can be written (defined as
  809. X   GR_HIDDEN).
  810. X
  811. X   The arguments x and y specify a pixel location on the screen
  812. X   in gr coordinates (see above on the coordinate system) where
  813. X   the pixel is to be located, x on the horizontal axis and y
  814. X   on the vertical axis.
  815. X
  816. X   The argument "color" is an integer denoting a color defined
  817. X   in the header "gr.h".
  818. X
  819. ****************************************************************/
  820. X
  821. gr_pixel( screen, x, y, color )
  822. X   int screen;
  823. X   int x, y;
  824. X   int color;
  825. X   {
  826. X   }
  827. X         
  828. /****************************************************************
  829. X
  830. X   gr_line()
  831. X
  832. X   This function draws a line on the designated screen from
  833. X   point x1, y1 to point x2, y2 in a specified color and
  834. X   with a specified style.
  835. X
  836. X   The argument "screen" is an integer denoted either the
  837. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  838. X   to which graphics output can be written (defined as
  839. X   GR_HIDDEN).
  840. X
  841. X   The arguments x1, y1, x2, and y2 specify two pixel locations
  842. X   on the screen in gr coordinates (see above on the coordinate
  843. X   system) denoting the source (x1, y1) and destination (x2, y2)
  844. X   points for the line (x1 and x2 on the horizontal axis, and y1
  845. X   and y2 on the vertical axis.
  846. X
  847. X   The argument "color" is an integer denoting a color defined
  848. X   in the header "gr.h".
  849. X
  850. X   The argument "style" is an integer denoting a line style
  851. X   defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- GRID
  852. X   and HATCH denote dotted lines, and HOLLOW erases the area
  853. X   of the line).
  854. X
  855. ****************************************************************/
  856. X
  857. gr_line( screen, x1, y1, x2, y2, color, style )
  858. X   int screen;
  859. X   int x1, y1, x2, y2;
  860. X   int color, style;
  861. X   {
  862. X   }
  863. X
  864. /****************************************************************
  865. X
  866. X   gr_text()
  867. X
  868. X   This function addresses text to a specified location on the
  869. X   screen in specified colors.
  870. X
  871. X   The argument "screen" is an integer denoted either the
  872. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  873. X   to which graphics output can be written (defined as
  874. X   GR_HIDDEN).
  875. X
  876. X   The arguments x and y specify a pixel location on the screen
  877. X   in gr coordinates (see above on the coordinate system) where
  878. X   the bottom left corner of the text is to be located, x on the
  879. X   horizontal axis and y on the vertical axis.
  880. X
  881. X   The argument "string" designates a pointer to a character
  882. X   string to be written to the screen.
  883. X
  884. X   The arguments "foreground" and "background" are integers
  885. X   denoting text foreground and background colors as defined
  886. X   in the header "gr.h".
  887. X
  888. ****************************************************************/
  889. X
  890. gr_text( screen, x, y, string, foreground, background )
  891. X   int screen;
  892. X   int x, y;
  893. X   int foreground, background;
  894. X   char *string;
  895. X   {
  896. X   }
  897. X
  898. /****************************************************************
  899. X
  900. X   gr_strlen()
  901. X
  902. X   This function returns the length in pixels on the horizontal
  903. X   (x) axis of a specified character string.
  904. X
  905. X   The argument "string" designates a pointer to a character
  906. X   string whose horizontal size is to be calculated.
  907. X
  908. ****************************************************************/
  909. X
  910. unsigned int
  911. gr_strlen( string )
  912. X   char *string;
  913. X   {
  914. X   }
  915. X
  916. /****************************************************************
  917. X
  918. X   gr_rectangle()
  919. X
  920. X   This function draws and possibly fills in (or blanks) a
  921. X   rectangular area of the screen.
  922. X
  923. X   The argument "screen" is an integer denoted either the
  924. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  925. X   to which graphics output can be written (defined as
  926. X   GR_HIDDEN).
  927. X
  928. X   The arguments x1, y1, x2, and y2 specify two pixel locations
  929. X   on the screen in gr coordinates (see above on the coordinate
  930. X   system) denoting the bottom left corner (x1, y1) and top right
  931. X   corner (x2, y2) of the rectangle (x1 and x2 on the horizontal
  932. X   axis, and y1 and y2 on the vertical axis).
  933. X
  934. X   The argument "color" is an integer denoting a color defined
  935. X   in the header "gr.h".
  936. X
  937. X   The argument "style" is an integer denoting a fill style
  938. X   defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
  939. X   means that only a perimeter is drawn; SOLID means that the
  940. X   area is completely filled with the color, and GRID and HATCH
  941. X   represent varying degrees of partial fill, with GRID the finer
  942. X   and HATCH the rougher).
  943. X
  944. ****************************************************************/
  945. X
  946. gr_rectangle( screen, x1, y1, x2, y2, color, style )
  947. X   int screen;
  948. X   int x1, y1, x2, y2;
  949. X   int color, style;
  950. X   {
  951. X   }
  952. X
  953. /****************************************************************
  954. X
  955. X   gr_circle()
  956. X
  957. X   This function draws and possibly fills in (or blanks) a
  958. X   circular area of the screen.
  959. X
  960. X   The argument "screen" is an integer denoted either the
  961. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  962. X   to which graphics output can be written (defined as
  963. X   GR_HIDDEN).
  964. X
  965. X   The arguments x and y specify a pixel location on the screen
  966. X   in gr coordinates (see above on the coordinate system) where
  967. X   the center of the circle is to be located, x on the horizontal
  968. X   axis and y on the vertical axis.
  969. X
  970. X   The argument "radius" is an integer denoting the radius of the
  971. X   circle on the y (vertical) axis. Implementers should note that
  972. X   the x (horizontal) axis will have to be scaled.
  973. X
  974. X   The argument "color" is an integer denoting a color defined
  975. X   in the header "gr.h".
  976. X
  977. X   The argument "style" is an integer denoting a fill style
  978. X   defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
  979. X   means that only a perimeter is drawn; SOLID means that the
  980. X   area is completely filled with the color, and GRID and HATCH
  981. X   represent varying degrees of partial fill, with GRID the finer
  982. X   and HATCH the rougher).
  983. X
  984. ****************************************************************/
  985. X
  986. gr_circle( screen, x, y, radius, color, style )
  987. X   int screen;
  988. X   int x, y, radius;
  989. X   int color, style;
  990. X   {
  991. X   }
  992. X
  993. /****************************************************************
  994. X
  995. X   gr_ellipse()
  996. X
  997. X   This function is NOT CURRENTLY USED in any Bywater applications
  998. X   so it's here basically for future development.
  999. X
  1000. X   This function draws and possibly fills in (or blanks) an
  1001. X   elliptical area of the screen.
  1002. X
  1003. X   The argument "screen" is an integer denoted either the
  1004. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  1005. X   to which graphics output can be written (defined as
  1006. X   GR_HIDDEN).
  1007. X
  1008. X   The arguments x and y specify a pixel location on the screen
  1009. X   in gr coordinates (see above on the coordinate system) where
  1010. X   the center of the ellipse is to be located, x on the horizontal
  1011. X   axis and y on the vertical axis.
  1012. X
  1013. X   The arguments "x_radius" and "y_radius" specify the horizontal
  1014. X   and vertical sizes, respectively, of the bounding rectangle
  1015. X   of the ellipse.
  1016. X
  1017. X   The argument "color" is an integer denoting a color defined
  1018. X   in the header "gr.h".
  1019. X
  1020. X   The argument "style" is an integer denoting a fill style
  1021. X   defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
  1022. X   means that only a perimeter is drawn; SOLID means that the
  1023. X   area is completely filled with the color, and GRID and HATCH
  1024. X   represent varying degrees of partial fill, with GRID the finer
  1025. X   and HATCH the rougher).
  1026. X
  1027. ****************************************************************/
  1028. X
  1029. gr_ellipse( screen, x, y, x_radius, y_radius, mode, color, style )
  1030. X   int screen;
  1031. X   int x, y, x_radius, y_radius;
  1032. X   int mode, color, style;
  1033. X   {
  1034. X   }
  1035. X         
  1036. /****************************************************************
  1037. X
  1038. X   gr_clip()
  1039. X
  1040. X   If clipping is implemented (gr_clipping == TRUE), this
  1041. X   function turns on or off clipping for a specified area
  1042. X   of the screen.
  1043. X
  1044. X   The argument "screen" is an integer denoted either the
  1045. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  1046. X   to which graphics output can be written (defined as
  1047. X   GR_HIDDEN).
  1048. X
  1049. X   The argument "mode" is a boolean integer which tells whether
  1050. X   clipping is to be turned on (TRUE) or off (FALSE).
  1051. X
  1052. X   The arguments x1, y1, x2, and y2 specify two pixel locations
  1053. X   on the screen in gr coordinates (see above on the coordinate
  1054. X   system) denoting the bottom left corner (x1, y1) and top right
  1055. X   corner (x2, y2) of the clipping rectangle (x1 and x2 on the
  1056. X   horizontal axis, and y1 and y2 on the vertical axis).
  1057. X
  1058. ****************************************************************/
  1059. X
  1060. gr_clip( screen, mode, x1, y1, x2, y2 )
  1061. X   int screen;
  1062. X   int mode;
  1063. X   int x1, y1, x2, y2;
  1064. X   {
  1065. X   }
  1066. X
  1067. /****************************************************************
  1068. X
  1069. X   gr_font()
  1070. X
  1071. X   This function sets a font for future calls to gr_text().
  1072. X
  1073. X   The argument "screen" is an integer denoted either the
  1074. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  1075. X   to which graphics output can be written (defined as
  1076. X   GR_HIDDEN).
  1077. X
  1078. X   The argument "type" is an integer value (not currently
  1079. X   implemented in applications by Bywater Software) which would
  1080. X   denote a font type (these are defined in "gr.h" as F_DEFAULT,
  1081. X   F_ROMAN, F_ITALIC, and F_GOTHIC). Don't worry about it.
  1082. X
  1083. X   The argument "rq_height" is an integer value denoting the
  1084. X   requested height of the new font in pixels. The function should
  1085. X   set the closest available height and then denote the size of
  1086. X   the new font in the fysize variable in the gr_display structure.
  1087. X
  1088. ****************************************************************/
  1089. X
  1090. gr_font( screen, type, rq_height )
  1091. X   int screen;
  1092. X   int type, rq_height;
  1093. X   {
  1094. X   }
  1095. X
  1096. /****************************************************************
  1097. X
  1098. X   gr_blit()
  1099. X
  1100. X   This function "blits" (copies) a rectangular area of the screen
  1101. X   from GR_PRIMARY to GR_HIDDEN or vice versa (if blitting is
  1102. X   implemented, i.e., gr_blitting == TRUE).
  1103. X
  1104. X   The arguments "src" and "dst" are integers denoting either the
  1105. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  1106. X   to which graphics output can be written (defined as
  1107. X   GR_HIDDEN). Obviously, one should be set to GR_PRIMARY and
  1108. X   one to GR_HIDDEN. "src" denotes the source of the blit, and
  1109. X   "dst" the destination.
  1110. X
  1111. X   The arguments x1, y1, x2, and y2 specify two pixel locations
  1112. X   on the screen in gr coordinates (see above on the coordinate
  1113. X   system) denoting the bottom left corner (x1, y1) and top right
  1114. X   corner (x2, y2) of the area to be blitted (x1 and x2 on the
  1115. X   horizontal axis, and y1 and y2 on the vertical axis).
  1116. X
  1117. ****************************************************************/
  1118. X
  1119. gr_blit( src, dst, x1, y1, x2, y2 )
  1120. X   int src, dst;
  1121. X   int x1, y1, x2, y2;
  1122. X   {
  1123. X   }
  1124. X
  1125. /****************************************************************
  1126. X
  1127. X   gr_imsave()
  1128. X
  1129. X   This function either saves a rectangluar area of the screen to
  1130. X   a memory buffer (mode == TRUE), or restores a rectangular screen
  1131. X   area from the buffer (mode == FALSE). It should free existing memory
  1132. X   when mode == FALSE (thus, the area cannot be restored more than once).
  1133. X
  1134. X   The argument "screen" is an integer denoted either the
  1135. X   visible screen (defined as GR_PRIMARY) or a hidden buffer
  1136. X   to which graphics output can be written (defined as
  1137. X   GR_HIDDEN).
  1138. X
  1139. X   The arguments x1, y1, x2, and y2 specify two pixel locations
  1140. X   on the screen in gr coordinates (see above on the coordinate
  1141. X   system) denoting the bottom left corner (x1, y1) and top right
  1142. X   corner (x2, y2) of the rectangular area to be saved (x1 and x2
  1143. X   on the horizontal axis, and y1 and y2 on the vertical axis).
  1144. X
  1145. X   The argument "image" is an integer denoting the specific
  1146. X   image that has been (or is to be) stored.
  1147. X
  1148. ****************************************************************/
  1149. X
  1150. gr_imsave( screen, mode, x1, y1, x2, y2, image )
  1151. X   int screen; 
  1152. X   int mode, x1, y1, x2, y2;
  1153. X   int *image;
  1154. X   {
  1155. X   }
  1156. X
  1157. /****************************************************************
  1158. X
  1159. X    gr_imfree()
  1160. X
  1161. ****************************************************************/
  1162. X
  1163. gr_imfree( image )
  1164. X   int image;
  1165. X   {
  1166. X   }
  1167. X
  1168. /****************************************************************
  1169. X
  1170. X   gr_mouse()
  1171. X
  1172. X   This function either tells if a mouse button has been pushed
  1173. X   (mode == SAMPLE or STATUS) or waits for a button to be pushed
  1174. X   (mode == WAIT).
  1175. X
  1176. X   The arguments x and y are integer pointers to be filled with a
  1177. X   screen location in gr coordinates (see above on the coordinate
  1178. X   system) where the mouse is currently located, x on the horizontal
  1179. X   axis and y on the vertical axis.
  1180. X
  1181. X   The argument "buttons" is an integer pointer which some great
  1182. X   day will be used to specify which of the mouse buttons has been
  1183. X   pushed but it hasn't been used yet in any Bywater applications
  1184. X   so don't worry about it.
  1185. X
  1186. ****************************************************************/
  1187. X
  1188. gr_mouse( mode, x, y, buttons )
  1189. X   int mode;
  1190. X   int *x, *y;
  1191. X   int *buttons;
  1192. X   {
  1193. X   }
  1194. X
  1195. SHAR_EOF
  1196. chmod 0644 io/gr/gr_spec.c ||
  1197. echo 'restore of io/gr/gr_spec.c failed'
  1198. Wc_c="`wc -c < 'io/gr/gr_spec.c'`"
  1199. test 17026 -eq "$Wc_c" ||
  1200.     echo 'io/gr/gr_spec.c: original size 17026, current size' "$Wc_c"
  1201. rm -f _shar_wnt_.tmp
  1202. fi
  1203. # ============= io/gr/gr_tam.c ==============
  1204. if test -f 'io/gr/gr_tam.c' -a X"$1" != X"-c"; then
  1205.     echo 'x - skipping io/gr/gr_tam.c (File already exists)'
  1206.     rm -f _shar_wnt_.tmp
  1207. else
  1208. > _shar_wnt_.tmp
  1209. echo 'x - extracting io/gr/gr_tam.c (Text)'
  1210. sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_tam.c' &&
  1211. /****************************************************************
  1212. X
  1213. X    gr_tam.c    implementation of Bywater graphics
  1214. X            standard for AT&T Unix PC using
  1215. X            tam() and wrastop() libraries
  1216. X
  1217. X            Copyright (c) 1991, Ted A. Campbell
  1218. X
  1219. X            Bywater Software
  1220. X            P. O. Box 4023 
  1221. X            Duke Station 
  1222. X            Durham, NC  27706
  1223. X
  1224. X            email: tcamp@hercules.acpub.duke.edu
  1225. X
  1226. X    Copyright and Permissions Information:
  1227. X
  1228. X    All U.S. and international copyrights are claimed by the
  1229. X    author. The author grants permission to use this code
  1230. X    and software based on it under the following conditions:
  1231. X    (a) in general, the code and software based upon it may be 
  1232. X    used by individuals and by non-profit organizations; (b) it
  1233. X    may also be utilized by governmental agencies in any country,
  1234. X    with the exception of military agencies; (c) the code and/or
  1235. X    software based upon it may not be sold for a profit without
  1236. X    an explicit and specific permission from the author, except
  1237. X    that a minimal fee may be charged for media on which it is
  1238. X    copied, and for copying and handling; (d) the code must be 
  1239. X    distributed in the form in which it has been released by the
  1240. X    author; and (e) the code and software based upon it may not 
  1241. X    be used for illegal activities. 
  1242. X
  1243. X    This file specifies the interface for graphics and mouse 
  1244. X    handling utilized in the Space Flight Simulator.  This file
  1245. X    may be utilized as the basis for implementations of gr and 
  1246. X    thus of sfs on varied computers.  If you can implement the
  1247. X    functions specified in this file, sfs should be implemented.
  1248. X
  1249. ****************************************************************/
  1250. X
  1251. #include "stdio.h"
  1252. #include "fcntl.h"
  1253. #include "tam.h"
  1254. #include "kcodes.h"
  1255. #include "message.h"
  1256. #include "errno.h"
  1257. #include "sys/window.h"
  1258. #include "sys/font.h"
  1259. #include "gr.h"
  1260. #include "bw.h"
  1261. X
  1262. static struct fntdef *tam_fsmall; /* ptr to small fntdef struct */
  1263. static struct fntdef *tam_fmed;      /* ptr to medium fntdef struct */
  1264. static struct fntdef *tam_flarge; /* ptr to large fntdef struct */
  1265. static struct fntdef *tam_fhuge;  /* ptr to huge fntdef struct */
  1266. static struct fntdef *tam_fdef;   /* ptr to selected fntdef struct */
  1267. X
  1268. #define IMAGES          64
  1269. #define    FULLSCREEN    FALSE
  1270. #define    CHECK_PARAMS    TRUE
  1271. #define SMALLFONT       "/usr/lib/wfont/smallfont"
  1272. #define MEDFONT         "/usr/lib/wfont/system.8.ft"
  1273. #define LARGEFONT       "/usr/lib/wfont/PLAIN.R.E.18.A"
  1274. #define HUGEFONT        "/usr/lib/wfont/PLAIN.R.E.24.A"
  1275. #define    ADD_SIZE    1
  1276. #define ADD_HIDDEN    2
  1277. #define    WRITE_OUTPUT    FALSE
  1278. X
  1279. int    gr_colors = 2;
  1280. int    gr_pxsize = 287;
  1281. int    gr_pysize = 428;
  1282. int    gr_ismouse = TRUE;
  1283. int     gr_clipping = FALSE;
  1284. int     gr_blitting = TRUE;
  1285. int     gr_saving = TRUE;
  1286. int    gr_screens = 2;
  1287. X
  1288. int w, w_id;
  1289. static unsigned short tam_pixel[ 2 ] = { 0xffff, 0xffff };
  1290. static struct gr_window *grwind;
  1291. static unsigned short *tam_selected;
  1292. static unsigned short *tam_hidden;
  1293. int tam_mready = FALSE;        /* is mouse input ready */
  1294. int tam_mx, tam_my;        /* mouse position x, y */
  1295. char    *tam_images[ IMAGES ];  /* array of pointers to image buffers */
  1296. X
  1297. extern unsigned short patblack[];
  1298. extern unsigned short patwhite[];
  1299. extern unsigned short patgray[];
  1300. extern unsigned short patltgray[];
  1301. X
  1302. extern char * malloc();
  1303. extern unsigned short tam_words();
  1304. extern long tam_imsize();
  1305. X
  1306. #ifdef    WRITE_OUTPUT
  1307. extern FILE *outfile;
  1308. #endif
  1309. X
  1310. /****************************************************************
  1311. X
  1312. X    gr_init()
  1313. X
  1314. ****************************************************************/
  1315. X
  1316. gr_init( grwindow, font_path )
  1317. X   struct gr_window *grwindow;
  1318. X   char * font_path;
  1319. X   {
  1320. X   static struct uwdata uw;
  1321. X   static struct umdata um;
  1322. X   register int i;
  1323. X   int r;
  1324. X
  1325. X   grwind = grwindow;
  1326. X
  1327. X   close( 0 );
  1328. X   close( 1 );
  1329. X   close( 2 );
  1330. X   w_id = open( "/dev/window", O_RDWR );
  1331. X   dup( w_id );
  1332. X   dup( w_id );
  1333. X
  1334. X   winit();
  1335. X   
  1336. #if    FULLSCREEN
  1337. X   w = wcreate( 1, 0, 24, 80, NBORDER );
  1338. #else
  1339. X   w = wcreate( 2, 2, 19, 70, BORDCANCEL );
  1340. #endif
  1341. X   wuser( w, "Bywater GR Implementation" );
  1342. X   wlabel( w, "Bywater GR Implementation" );
  1343. X   wprintf( w, "\033[=1C" );
  1344. X   clear();
  1345. X
  1346. X   ioctl( w, WIOCGETD, &uw );
  1347. X
  1348. X   grwindow->xmax = uw.uw_width - 1;
  1349. X   grwindow->ymax = uw.uw_height - 1;
  1350. X   grwindow->initialized = TRUE;
  1351. X   grwindow->font = F_DEFAULT;
  1352. X
  1353. X   tam_readfont( SMALLFONT, &tam_fsmall );
  1354. X   tam_readfont( MEDFONT, &tam_fmed );
  1355. X   tam_readfont( LARGEFONT, &tam_flarge );
  1356. X   tam_readfont( HUGEFONT, &tam_fhuge );
  1357. X
  1358. X   if ( tam_fmed == NULL )
  1359. X     {
  1360. X     fprintf( stderr, "ERROR: failed to load system font.\n" );
  1361. X     wgetc( w );
  1362. X     wexit( 1 );
  1363. X     }
  1364. X
  1365. X   tam_fdef = tam_fmed;
  1366. X   grwindow->fysize = tam_fdef->ff_vs;
  1367. X   grwindow->fxsize = tam_fdef->ff_hs;
  1368. X
  1369. X   if ( ( tam_hidden = (unsigned short *) 
  1370. X      malloc( tam_imsize( 0, 0,
  1371. X      grwind->xmax + ADD_HIDDEN, grwind->ymax + ADD_HIDDEN ) )) == NULL )
  1372. X      {
  1373. X      fprintf( stderr, "Failed to find memory for gr_hidden\n" );
  1374. X      return -1;
  1375. X      }
  1376. X
  1377. #ifdef    OLD_DEBUG
  1378. X      wgoto( w, 0, 0 );
  1379. X      fprintf( stderr, "test wrastop(): tam_hidden %08lx\n",
  1380. X         (long) tam_hidden );
  1381. X      kb_rx();
  1382. #endif
  1383. X
  1384. #ifdef    OLD_DEBUG
  1385. X   gr_text( GR_PRIMARY, 0, 0, " !\"#", WHITE, BLACK );
  1386. #endif
  1387. X
  1388. X   /* set image buffer pointers to NULL */
  1389. X
  1390. X   for ( i = 0; i < IMAGES; ++i )
  1391. X      {
  1392. X      tam_images[ i ] = NULL;
  1393. X      }
  1394. X
  1395. X   um.um_flags = MSDOWN | MSUP;
  1396. X   um.um_icon = NULL;
  1397. X   r = wsetmouse( w, &um );
  1398. X
  1399. X   if ( r == -1 )
  1400. X      {
  1401. X      fprintf( stderr, "Setmouse() returned -1\n" );
  1402. X      kb_rx();
  1403. X      }
  1404. X
  1405. X   return TRUE;
  1406. X   }
  1407. X
  1408. /****************************************************************
  1409. X
  1410. X   gr_deinit()
  1411. X
  1412. ****************************************************************/
  1413. X
  1414. gr_deinit( screen )
  1415. X   int screen;
  1416. X   {
  1417. X   wdelete( w );
  1418. X   wexit( 0 );
  1419. X   }
  1420. X
  1421. /****************************************************************
  1422. X
  1423. X   gr_cls()
  1424. X
  1425. ****************************************************************/
  1426. X
  1427. gr_cls( screen )
  1428. X   int screen;
  1429. X   {
  1430. X
  1431. X   if ( screen == GR_PRIMARY )
  1432. X      {
  1433. X      clear();
  1434. X      }
  1435. X   else
  1436. X      {
  1437. X      gr_rectangle( screen, 0, 0, grwind->xmax, grwind->ymax,
  1438. X         BLACK, SOLID );
  1439. X      }
  1440. X   }
  1441. X
  1442. X
  1443. /****************************************************************
  1444. X
  1445. X   gr_pixel()
  1446. X
  1447. ****************************************************************/
  1448. X
  1449. gr_pixel( screen, x, y, color )
  1450. X   int screen;
  1451. X   int x, y;
  1452. X   int color;
  1453. X   {
  1454. X   int r;
  1455. X
  1456. #if    CHECK_PARAMS
  1457. X   if ( ( x < 0 ) || ( x > grwind->xmax ))
  1458. X      {
  1459. X      sprintf( bw_ebuf, "[pr:] gr_pixel(): x value is %d", x );
  1460. X      bw_error( bw_ebuf );
  1461. X      return BW_ERROR;
  1462. X      }
  1463. X   if ( ( y < 0 ) || ( y > grwind->ymax ))
  1464. X      {
  1465. X      sprintf( bw_ebuf, "[pr:] gr_pixel(): y value is %d", y );
  1466. X      bw_error( bw_ebuf );
  1467. X      return BW_ERROR;
  1468. X      }
  1469. #endif
  1470. X
  1471. X   tam_setscreen( screen );
  1472. X
  1473. X   r = wrastop( w, tam_pixel, (unsigned short) 2,
  1474. X      tam_selected, tam_words( grwind->xmax + ADD_HIDDEN ),
  1475. X      (unsigned short) 0, (unsigned short) 0,
  1476. X      (unsigned short) x, 
  1477. X      (unsigned short) ( grwind->ymax - y ),
  1478. X      (unsigned short) ADD_SIZE, (unsigned short) ADD_SIZE,
  1479. X      SRCSRC, DSTOR, (unsigned short *) 0 );
  1480. X
  1481. #ifdef    DEBUG
  1482. X   if ( r == -1 )
  1483. X      {
  1484. X      fprintf( stderr, "gr_pixel(): wrastop() failed, error %d.\n", errno );
  1485. X      kb_rx();
  1486. X      }
  1487. #endif
  1488. X   }
  1489. X         
  1490. /****************************************************************
  1491. X
  1492. X   gr_line()
  1493. X
  1494. ****************************************************************/
  1495. X
  1496. gr_line( screen, x1, y1, x2, y2, color, style )
  1497. X   int screen;
  1498. X   int x1, y1, x2, y2;
  1499. X   int color, style;
  1500. X   {
  1501. X
  1502. #if    CHECKPARAMS
  1503. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1504. X      {
  1505. X      sprintf( bw_ebuf, "[pr:] gr_line(): x1 value is %d", x1 );
  1506. X      bw_error( bw_ebuf );
  1507. X      return BW_ERROR;
  1508. X      }
  1509. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1510. X      {
  1511. X      sprintf( bw_ebuf, "[pr:] gr_line(): x2 value is %d", x2 );
  1512. X      bw_error( bw_ebuf );
  1513. X      return BW_ERROR;
  1514. X      }
  1515. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1516. X      {
  1517. X      sprintf( bw_ebuf, "[pr:] gr_line(): y1 value is %d", y1 );
  1518. X      bw_error( bw_ebuf );
  1519. X      return BW_ERROR;
  1520. X      }
  1521. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1522. X      {
  1523. X      sprintf( bw_ebuf, "[pr:] gr_line(): y2 value is %d", y2 );
  1524. X      bw_error( bw_ebuf );
  1525. X      return BW_ERROR;
  1526. X      }
  1527. #endif
  1528. X
  1529. X   if ( x1 == x2 )
  1530. X      {
  1531. X      gr_rectangle( screen, x1, y1, x2, y2, color, style );
  1532. X      }
  1533. X   else if ( y1 == y2 )
  1534. X      {
  1535. X      gr_rectangle( screen, x1, y1, x2, y2, color, style );
  1536. X      }
  1537. X   else
  1538. X      {
  1539. X      def_line( screen, x1, y1, x2, y2, color, style );
  1540. X      }
  1541. X   }
  1542. X
  1543. /****************************************************************
  1544. X
  1545. X   gr_text()
  1546. X
  1547. ****************************************************************/
  1548. X
  1549. gr_text( screen, x, y, string, foreground, background )
  1550. X   int screen;
  1551. X   int x, y;
  1552. X   int foreground, background;
  1553. X   char *string;
  1554. X   {
  1555. X   char *s;
  1556. X   unsigned short c;
  1557. X   char *m;
  1558. X   register unsigned int x_pos;
  1559. #ifdef    DEBUG
  1560. X   static int do_it = 0;
  1561. #endif
  1562. X
  1563. #if    CHECK_PARAMS
  1564. X   if ( ( x < 0 ) || ( x > grwind->xmax ))
  1565. X      {
  1566. X      fprintf( stderr, "ERROR: [pr:] gr_text(): x value is %d", x );
  1567. X      kb_rx();
  1568. X      return BW_ERROR;
  1569. X      }
  1570. X   if ( ( y < 0 ) || ( y > grwind->ymax ))
  1571. X      {
  1572. X      fprintf( stderr, "ERROR: [pr:] gr_text(): y value is %d", y );
  1573. X      kb_rx();
  1574. X      return BW_ERROR;
  1575. X      }
  1576. #endif
  1577. X
  1578. X   tam_setscreen( screen );
  1579. X
  1580. X   s = string;
  1581. X   x_pos = x;
  1582. X   while ( *s != 0 )
  1583. X      {
  1584. X      c = *s - 32;
  1585. X      m = (char *) &(tam_fdef->ff_fc[ c ].fc_mr)
  1586. X         + ( tam_fdef->ff_fc[ c ].fc_mr );
  1587. X
  1588. X      if ( ( *s > 31 ) && ( *s < 129 ))
  1589. X         {
  1590. X         if ( ( x_pos + tam_fdef->ff_hs ) >= grwind->xmax )
  1591. X            {
  1592. X            return BW_ERROR;
  1593. X            }
  1594. X         tam_char( screen, x_pos, y, m,
  1595. X            tam_fdef->ff_fc[ c ].fc_hs,
  1596. X            tam_fdef->ff_fc[ c ].fc_vs,
  1597. X        foreground, background, (int) *s,
  1598. X            &(tam_fdef->ff_fc[ c ] ) );
  1599. X         x_pos += tam_fdef->ff_hs;
  1600. X         }
  1601. X      ++s;
  1602. X      }
  1603. X   }
  1604. X
  1605. /****************************************************************
  1606. X
  1607. X   gr_strlen()
  1608. X
  1609. ****************************************************************/
  1610. X
  1611. unsigned int
  1612. gr_strlen( string )
  1613. X   char *string;
  1614. X   {
  1615. X   char *s;
  1616. X   int size;
  1617. X
  1618. X   s = string;
  1619. X   size = 0;
  1620. X   while ( *s != 0 )
  1621. X      {
  1622. X      size += tam_fdef->ff_hs;
  1623. X      ++s;
  1624. X      }
  1625. X   return size;
  1626. X   }
  1627. X
  1628. /****************************************************************
  1629. X
  1630. X   gr_rectangle()
  1631. X
  1632. ****************************************************************/
  1633. X
  1634. gr_rectangle( screen, x1, y1, x2, y2, color, style )
  1635. X   int screen;
  1636. X   int x1, y1, x2, y2;
  1637. X   int color, style;
  1638. X   {
  1639. X   unsigned short *pattern;
  1640. X   int r;
  1641. X
  1642. #if    CHECK_PARAMS
  1643. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1644. X      {
  1645. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x1 value is %d", x1 );
  1646. X      bw_error( bw_ebuf );
  1647. X      return BW_ERROR;
  1648. X      }
  1649. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1650. X      {
  1651. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x2 value is %d", x2 );
  1652. X      bw_error( bw_ebuf );
  1653. X      return BW_ERROR;
  1654. X      }
  1655. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1656. X      {
  1657. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y1 value is %d", y1 );
  1658. X      bw_error( bw_ebuf );
  1659. X      return BW_ERROR;
  1660. X      }
  1661. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1662. X      {
  1663. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y2 value is %d", y2 );
  1664. X      bw_error( bw_ebuf );
  1665. X      return BW_ERROR;
  1666. X      }
  1667. #endif
  1668. X
  1669. X   tam_setscreen( screen );
  1670. X
  1671. X   switch ( style )
  1672. X      {
  1673. X      case HOLLOW:
  1674. X         def_rectangle( screen, x1, y1, x2, y2, color, style );
  1675. X         return TRUE;
  1676. X         break;
  1677. X      case SOLID:
  1678. X         if ( color == WHITE )
  1679. X            {
  1680. X            pattern = patwhite;
  1681. X            }
  1682. X         else
  1683. X            {
  1684. X            pattern = patblack;
  1685. X            }
  1686. X         break;
  1687. X      case GRID:
  1688. X         pattern = patgray;
  1689. X         break;
  1690. X      case HATCH:
  1691. X         pattern = patltgray;
  1692. X         break;
  1693. X      }
  1694. X
  1695. X   r = wrastop( w, tam_pixel, (unsigned short) 2,
  1696. X      tam_selected, tam_words( grwind->xmax + ADD_HIDDEN ),
  1697. X      (unsigned short) 0, (unsigned short) 0,
  1698. X      (unsigned short) x1,
  1699. X      (unsigned short) ( grwind->ymax - y2 ),
  1700. X      (unsigned short) abs(x2 - x1) + ADD_SIZE,
  1701. X      (unsigned short) abs(y2 - y1) + ADD_SIZE,
  1702. X      SRCPAT, DSTSRC, pattern );
  1703. X
  1704. #ifdef    DEBUG
  1705. X   if ( r == -1 )
  1706. X      {
  1707. X      wgoto( w, 0, 0 );
  1708. X      fprintf( stderr, "gr_rectangle(): wrastop() failed, error %d, screen %d.\n",
  1709. X         errno, screen );
  1710. X      kb_rx();
  1711. X      }
  1712. #endif
  1713. X   }
  1714. X
  1715. /****************************************************************
  1716. X
  1717. X   gr_circle()
  1718. X
  1719. ****************************************************************/
  1720. X
  1721. gr_circle( screen, x, y, radius, color, style )
  1722. X   int screen;
  1723. X   int x, y, radius;
  1724. X   int color, style;
  1725. X   {
  1726. X
  1727. #if    CHECK_PARAMS
  1728. X   if ( ( x < 0 ) || ( x > grwind->xmax ))
  1729. X      {
  1730. X      sprintf( bw_ebuf, "[pr:] gr_circle(): x value is %d", x );
  1731. X      bw_error( bw_ebuf );
  1732. X      return BW_ERROR;
  1733. X      }
  1734. X   if ( ( y < 0 ) || ( y > grwind->ymax ))
  1735. X      {
  1736. X      sprintf( bw_ebuf, "[pr:] gr_circle(): y value is %d", y );
  1737. X      bw_error( bw_ebuf );
  1738. X      return BW_ERROR;
  1739. X      }
  1740. #endif
  1741. X
  1742. X   def_circle( screen, x, y, radius, color, style );
  1743. X   }
  1744. X
  1745. /****************************************************************
  1746. X
  1747. X   gr_ellipse()
  1748. X
  1749. ****************************************************************/
  1750. X
  1751. gr_ellipse( screen, x, y, x_radius, y_radius, mode, color, style )
  1752. X   int screen;
  1753. X   int x, y, x_radius, y_radius;
  1754. X   int mode, color, style;
  1755. X   {
  1756. X   }
  1757. X         
  1758. /****************************************************************
  1759. X
  1760. X   gr_clip()
  1761. X
  1762. ****************************************************************/
  1763. X
  1764. gr_clip( screen, mode, x1, y1, x2, y2 )
  1765. X   int screen;
  1766. X   int mode;
  1767. X   int x1, y1, x2, y2;
  1768. X   {
  1769. X   }
  1770. X
  1771. /****************************************************************
  1772. X
  1773. X   gr_font()
  1774. X
  1775. ****************************************************************/
  1776. X
  1777. gr_font( screen, type, rq_height )
  1778. X   int screen;
  1779. X   int type, rq_height;
  1780. X   {
  1781. X
  1782. X   if ( rq_height > 21 )
  1783. X      {
  1784. X      tam_fdef = tam_fhuge;
  1785. X      if ( tam_fdef > NULL )
  1786. X         {
  1787. X         grwind->fysize = tam_fdef->ff_vs;
  1788. X         grwind->fxsize = tam_fdef->ff_hs;
  1789. X         return TRUE;
  1790. X         }
  1791. X      }
  1792. X   else if ( rq_height > 14 )
  1793. X      {
  1794. X      tam_fdef = tam_flarge;
  1795. X      if ( tam_fdef > NULL )
  1796. X         {
  1797. X         grwind->fysize = tam_fdef->ff_vs;
  1798. X         grwind->fxsize = tam_fdef->ff_hs;
  1799. X         return TRUE;
  1800. X         }
  1801. X      }
  1802. X   else if ( rq_height > 9 )
  1803. X      {
  1804. X      tam_fdef = tam_fmed;
  1805. X      if ( tam_fdef > NULL )
  1806. X         {
  1807. X         grwind->fysize = tam_fdef->ff_vs;
  1808. X         grwind->fxsize = tam_fdef->ff_hs;
  1809. X         return TRUE;
  1810. X         }
  1811. X      }
  1812. X   else
  1813. X      {
  1814. X      tam_fdef = tam_fsmall;
  1815. X      if ( tam_fdef > NULL )
  1816. X         {
  1817. X         grwind->fysize = tam_fdef->ff_vs;
  1818. X         grwind->fxsize = tam_fdef->ff_hs;
  1819. X         return TRUE;
  1820. X         }
  1821. X      }
  1822. X
  1823. X   tam_fdef = tam_fmed;        /* default if all failed */
  1824. X   grwind->fysize = tam_fdef->ff_vs;
  1825. X   grwind->fxsize = tam_fdef->ff_hs;
  1826. X   return TRUE;
  1827. X   }
  1828. X
  1829. /****************************************************************
  1830. X
  1831. X   gr_blit()
  1832. X
  1833. ****************************************************************/
  1834. X
  1835. gr_blit( src, dst, x1, y1, x2, y2 )
  1836. X   int src, dst;
  1837. X   int x1, y1, x2, y2;
  1838. X   {
  1839. X   unsigned short *srcbase, *dstbase;
  1840. X   int r;
  1841. X   register int l;
  1842. X
  1843. #if    CHECK_PARAMS
  1844. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1845. X      {
  1846. X      sprintf( bw_ebuf, "[pr:] gr_blit(): x1 value is %d", x1 );
  1847. X      bw_error( bw_ebuf );
  1848. X      return BW_ERROR;
  1849. X      }
  1850. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1851. X      {
  1852. X      sprintf( bw_ebuf, "[pr:] gr_blit(): x2 value is %d", x2 );
  1853. X      bw_error( bw_ebuf );
  1854. X      return BW_ERROR;
  1855. X      }
  1856. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1857. X      {
  1858. X      sprintf( bw_ebuf, "[pr:] gr_blit(): y1 value is %d", y1 );
  1859. X      bw_error( bw_ebuf );
  1860. X      return BW_ERROR;
  1861. X      }
  1862. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1863. X      {
  1864. X      sprintf( bw_ebuf, "[pr:] gr_blit(): y2 value is %d", y2 );
  1865. X      bw_error( bw_ebuf );
  1866. X      return BW_ERROR;
  1867. X      }
  1868. X   if ( src == dst )
  1869. X      {
  1870. X      sprintf( bw_ebuf, "[pr:] gr_blit(): src == dst" );
  1871. X      bw_error( bw_ebuf );
  1872. X      return BW_ERROR;
  1873. X      }
  1874. #endif
  1875. X
  1876. X   if ( src == GR_PRIMARY )
  1877. X      {
  1878. X      srcbase = (unsigned short *) NULL;
  1879. X      dstbase = tam_hidden;
  1880. X      r = wrastop( w, srcbase,
  1881. X         tam_words( abs( x2 - x1 ) + ADD_SIZE ),
  1882. X         dstbase, tam_words( grwind->xmax + ADD_HIDDEN ),
  1883. X         (unsigned short) x1,
  1884. X         (unsigned short) y1,
  1885. X         (unsigned short) x1, 
  1886. X         (unsigned short) y1,
  1887. X         (unsigned short) abs(x2 - x1),
  1888. X         (unsigned short) abs(y2 - y1),
  1889. X         SRCSRC, DSTSRC, (unsigned short *) 0 );
  1890. X
  1891. #ifdef    DEBUG
  1892. X      if ( r == -1 )
  1893. X         {
  1894. X         wgoto( w, 0, 0 );
  1895. X         fprintf( stderr, "gr_blit(): wrastop() failed, error %d.\n", errno );
  1896. X         kb_rx();
  1897. X         }
  1898. #endif
  1899. X      }
  1900. X   else
  1901. X      {
  1902. X      dstbase = (unsigned short *) NULL;
  1903. X      srcbase = tam_hidden;
  1904. X
  1905. #ifndef OLD_WAY
  1906. X      r = wrastop( w,
  1907. X         srcbase, tam_words( grwind->xmax + ADD_HIDDEN ),
  1908. X         dstbase, tam_words( grwind->xmax + ADD_HIDDEN ),
  1909. X         (unsigned short) x1,
  1910. X         (unsigned short) ( grwind->ymax - y2 ),
  1911. X         (unsigned short) x1,
  1912. X         (unsigned short) ( grwind->ymax - y2 ),
  1913. X         (unsigned short) abs(x2 - x1) + ADD_SIZE,
  1914. X         (unsigned short) abs(y2 - y1) + ADD_SIZE,
  1915. X         SRCSRC, DSTSRC, (unsigned short *) 0 );
  1916. #else
  1917. X      for ( l = y1; l < y2; ++l )
  1918. X         {
  1919. X         r = wrastop( w,
  1920. X            srcbase, tam_words( grwind->xmax + ADD_HIDDEN ),
  1921. X            dstbase, tam_words( grwind->xmax + ADD_HIDDEN ),
  1922. X            (unsigned short) x1,
  1923. X            (unsigned short) ( grwind->ymax - l ),
  1924. X            (unsigned short) x1,
  1925. X            (unsigned short) ( grwind->ymax - l ),
  1926. X            (unsigned short) abs(x2 - x1) + ADD_SIZE,
  1927. X            (unsigned short) 1,
  1928. X            SRCSRC, DSTSRC, (unsigned short *) 0 );
  1929. /*         kb_rx(); */
  1930. X         }
  1931. #endif
  1932. X      
  1933. #ifdef    DEBUG
  1934. X      if ( r == -1 )
  1935. X         {
  1936. X         wgoto( w, 0, 0 );
  1937. X         fprintf( stderr, "gr_blit(): wrastop() failed, error %d.\n", errno );
  1938. X         kb_rx();
  1939. X         }
  1940. #endif
  1941. X      }
  1942. X   }
  1943. X
  1944. /****************************************************************
  1945. X
  1946. X   tam_imsize()
  1947. X
  1948. ****************************************************************/
  1949. X
  1950. long
  1951. tam_imsize( x1, y1, x2, y2 )
  1952. X   int x1, y1, x2, y2;
  1953. X   {
  1954. X   return ( sizeof( unsigned short)
  1955. X      * ( tam_words(abs(x2 - x1) + ADD_SIZE )
  1956. X      * ( abs(y2 - y1)) + ADD_SIZE ));
  1957. X   }
  1958. X
  1959. /****************************************************************
  1960. X
  1961. X   gr_imsave()
  1962. X
  1963. ****************************************************************/
  1964. X
  1965. gr_imsave( screen, mode, x1, y1, x2, y2, image )
  1966. X   int screen; 
  1967. X   int mode, x1, y1, x2, y2;
  1968. X   int *image;
  1969. X   {
  1970. X   int r;
  1971. X   int carry_on;
  1972. X
  1973. #if    CHECK_PARAMS
  1974. X   if ( ( x1 < 0 ) || ( x1 > grwind->xmax ))
  1975. X      {
  1976. X      sprintf( bw_ebuf, "[pr:] gr_imsave(): x1 value is %d", x1 );
  1977. X      bw_error( bw_ebuf );
  1978. X      return BW_ERROR;
  1979. X      }
  1980. X   if ( ( x2 < 0 ) || ( x2 > grwind->xmax ))
  1981. X      {
  1982. X      sprintf( bw_ebuf, "[pr:] gr_imsave(): x2 value is %d", x2 );
  1983. X      bw_error( bw_ebuf );
  1984. X      return BW_ERROR;
  1985. X      }
  1986. X   if ( ( y1 < 0 ) || ( y1 > grwind->ymax ))
  1987. X      {
  1988. X      sprintf( bw_ebuf, "[pr:] gr_imsave(): y1 value is %d", y1 );
  1989. X      bw_error( bw_ebuf );
  1990. X      return BW_ERROR;
  1991. X      }
  1992. X   if ( ( y2 < 0 ) || ( y2 > grwind->ymax ))
  1993. X      {
  1994. X      sprintf( bw_ebuf, "[pr:] gr_imsave(): y2 value is %d", y2 );
  1995. X      bw_error( bw_ebuf );
  1996. X      return BW_ERROR;
  1997. X      }
  1998. #endif
  1999. X
  2000. X   tam_setscreen( screen );
  2001. X
  2002. X   if ( mode == TRUE )
  2003. X      {
  2004. X
  2005. X
  2006. X      /* find an available buffer */
  2007. X
  2008. X      carry_on = TRUE;
  2009. X      r = 0;
  2010. X      while( ( carry_on == TRUE ) && ( r < IMAGES ) )
  2011. X     {
  2012. X     if ( tam_images[ r ] == NULL )
  2013. X        {
  2014. X        carry_on = FALSE;
  2015. X        }
  2016. X     else
  2017. X        {
  2018. X        ++r;
  2019. X        }
  2020. X     }
  2021. X
  2022. X      if ( r >= IMAGES )
  2023. X     {
  2024. X     bw_error( "No more slots for image storage" );
  2025. X     return FALSE;
  2026. X     }
  2027. X
  2028. X      *image = r;
  2029. X
  2030. X      /* get memory */
  2031. X
  2032. X      if ( ( tam_images[ *image ] = malloc( (size_t) tam_imsize(
  2033. X     x1, grwind->ymax - y2,
  2034. X     x2, grwind->ymax - y1 ) ) ) == NULL )
  2035. X     {
  2036. X     bw_error( "Out of memory to store image" );
  2037. X     return FALSE;
  2038. X     }
  2039. X
  2040. X      /* perform the save operation */
  2041. X
  2042. X      r = wrastop( w, tam_selected,
  2043. X         tam_words( grwind->xmax + ADD_HIDDEN ),
  2044. X     (unsigned short *) tam_images[ *image ],
  2045. X         tam_words( abs(x2 - x1)),
  2046. X         (unsigned short) x1, 
  2047. X         (unsigned short) ( grwind->ymax - y2 ),
  2048. X         (unsigned short) 0, (unsigned short) 0,
  2049. X         (unsigned short) abs(x2 - x1) + ADD_SIZE,
  2050. X         (unsigned short) abs(y2 - y1) + ADD_SIZE,
  2051. X         SRCSRC, DSTSRC, (unsigned short *) 0 );
  2052. X
  2053. #ifdef    DEBUG
  2054. X      if ( r == -1 )
  2055. X         {
  2056. X         wgoto( w, 0, 0 );
  2057. X         fprintf( stderr, "gr_imsave(): wrastop() failed, error %d.\n", errno );
  2058. X         kb_rx();
  2059. X         }
  2060. #endif
  2061. X      }
  2062. X   else
  2063. X      {
  2064. X      r = wrastop( w, (unsigned short *) tam_images[ *image ],
  2065. X         tam_words( abs(x2 - x1)),
  2066. X         tam_selected, tam_words( grwind->xmax + ADD_HIDDEN ),
  2067. X         (unsigned short) 0, (unsigned short) 0,
  2068. X         (unsigned short) x1,
  2069. X         (unsigned short) ( grwind->ymax - y2 ),
  2070. SHAR_EOF
  2071. true || echo 'restore of io/gr/gr_tam.c failed'
  2072. fi
  2073. echo 'End of  part 3'
  2074. echo 'File io/gr/gr_tam.c is continued in part 4'
  2075. echo 4 > _shar_seq_.tmp
  2076. exit 0
  2077. exit 0 # Just in case...
  2078. -- 
  2079. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2080. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2081. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2082. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2083.