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

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  3. Subject:  v27i008:  sfs - Space Flight Simulator, Part08/21
  4. Message-ID: <1991Dec24.045434.29990@sparky.imd.sterling.com>
  5. X-Md4-Signature: 9edb069dcdfe01c53a1b0ef3b368bc58
  6. Date: Tue, 24 Dec 1991 04:54:34 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 8
  11. Archive-name: sfs/part08
  12. Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11,
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file io/ui/ui.h 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" != 8; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping io/ui/ui.h'
  32. else
  33. echo 'x - continuing file io/ui/ui.h'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'io/ui/ui.h' &&
  35. X   int     y_logical;              /* logical items on y axis      */
  36. X   int     x_pos;                  /* current position, x axis     */
  37. X   int     y_pos;                  /* current position, y axis     */
  38. X   int     current;                /* currently selected item      */
  39. X   int     x_start;                /* starting position for x axis */
  40. X   int     y_start;                /* starting position for y axis */
  41. X   int     fore;                   /* foreground color             */
  42. X   int     back;                   /* background color             */
  43. X   int     high;                   /* highlight color              */
  44. X   int     number;                 /* total number of icons/menu items */
  45. X   int     i_x1;                   /* icon area, left              */
  46. X   int     i_y1;                   /* icon area, bottom            */
  47. X   int     i_x2;                   /* icon area, right             */
  48. X   int     i_y2;                   /* icon area, top               */
  49. X   int     vs_x1;                  /* vertical slide, left         */
  50. X   int     vs_y1;                  /* vertical slide, bottom       */
  51. X   int     vs_x2;                  /* vertical slide, right        */
  52. X   int     vs_y2;                  /* vertical slide, top          */
  53. X   int     ve_y1;                  /* vertical elevator, bottom    */
  54. X   int     ve_y2;                  /* vertical elevator, top       */
  55. X   int     hs_x1;                  /* horizontal slide, left       */
  56. X   int     hs_y1;                  /* horizontal slide, bottom     */
  57. X   int     hs_x2;                  /* horizontal slide, right      */
  58. X   int     hs_y2;                  /* horizontal slide, top        */
  59. X   int     he_x1;                  /* horizontal elevator, left    */
  60. X   int     he_x2;                  /* horizontal elevator, right   */
  61. X   int     vel_x1;                 /* vertical elevator left       */
  62. X   int     vel_y1;                 /* vertical elevator bottom     */
  63. X   int     vel_x2;                 /* vertical elevator right      */
  64. X   int     vel_y2;                 /* vertical elevator top        */
  65. X   int     vel_inc;                /* vertical elevator increment  */
  66. X   int     hel_x1;                 /* horizontal elevator left     */
  67. X   int     hel_y1;                 /* horizontal elevator bottom   */
  68. X   int     hel_x2;                 /* horizontal elevator right    */
  69. X   int     hel_y2;                 /* horizontal elevator top      */
  70. X   int     hel_inc;                /* horizontal elevator increment */
  71. X   };
  72. X
  73. struct pbm_struct
  74. X   {
  75. X   int xsize;
  76. X   int ysize;
  77. X   int image;
  78. X   };
  79. X
  80. struct tty_struct
  81. X   {
  82. X   struct uiwindow *window;     /* pointer to ui window structure */
  83. X   int lines;                   /* text lines in window */
  84. X   int columns;                 /* text columns in window */
  85. X   int font_ysize;              /* font size, vertical */
  86. X   int font_xsize;              /* font size, horizontal */
  87. X   int curs_xpos;               /* cursor x (column) position */
  88. X   int curs_ypos;               /* cursor y (line) position */
  89. X   int foreground;              /* text foreground color */
  90. X   int background;              /* text background color */
  91. X   int standout;                /* boolean: standout? TRUE = reverse video */
  92. X   int scroll_right;            /* boolean: scroll at right margin */
  93. X                /* default: FALSE, do not scroll */
  94. X   char *cbuffer;               /* buffer to hold character position */
  95. X   };                           /* overwritten by cursor */
  96. X
  97. struct ui_twstruct
  98. X   {
  99. X   struct tw_struct *tw;
  100. X   struct uiwindow  *uiw;
  101. X   };
  102. X
  103. extern  struct gr_window *ui_grwind;
  104. extern  char   ui_ready;
  105. X
  106. extern  struct uiwindow * ui_window();
  107. extern  struct tty_struct * tty_init();
  108. extern  struct ui_twstruct * ui_twinit();
  109. X
  110. extern  char ui_tbuf[ 128 ];
  111. extern    int  ui_screen;
  112. extern  char   ui_fontpath[ 128 ];
  113. X
  114. extern  struct pbm_struct ui_elicon;         /* elevator icon */
  115. extern  struct pbm_struct ui_lefticn;        /* left icon */
  116. extern  struct pbm_struct ui_righticn;       /* right icon */
  117. extern  struct pbm_struct ui_upicn;          /* up icon */
  118. extern  struct pbm_struct ui_downicn;        /* down icon */
  119. extern  struct pbm_struct ui_clicon;         /* close window icon */
  120. extern  struct pbm_struct ui_reicon;         /* resize window icon */
  121. extern  struct pbm_struct ui_mvicon;         /* move window icon */
  122. extern  struct pbm_struct ui_deficon;        /* default file icon */
  123. extern  struct pbm_struct ui_foldicon;       /* file folder icon */
  124. extern  struct pbm_struct ui_exicon;         /* executable file icon */
  125. SHAR_EOF
  126. echo 'File io/ui/ui.h is complete' &&
  127. chmod 0644 io/ui/ui.h ||
  128. echo 'restore of io/ui/ui.h failed'
  129. Wc_c="`wc -c < 'io/ui/ui.h'`"
  130. test 10420 -eq "$Wc_c" ||
  131.     echo 'io/ui/ui.h: original size 10420, current size' "$Wc_c"
  132. rm -f _shar_wnt_.tmp
  133. fi
  134. # ============= io/ui/ui_boxes.c ==============
  135. if test -f 'io/ui/ui_boxes.c' -a X"$1" != X"-c"; then
  136.     echo 'x - skipping io/ui/ui_boxes.c (File already exists)'
  137.     rm -f _shar_wnt_.tmp
  138. else
  139. > _shar_wnt_.tmp
  140. echo 'x - extracting io/ui/ui_boxes.c (Text)'
  141. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_boxes.c' &&
  142. /****************************************************************
  143. X
  144. X    ui_boxes.c      Box drawing and window routines for
  145. X            The Bywater Graphical User Interface
  146. X
  147. X            Copyright (c) 1991, Ted A. Campbell
  148. X
  149. X            Bywater Software
  150. X            P. O. Box 4023
  151. X            Duke Station
  152. X            Durham, NC  27706
  153. X
  154. X            email: tcamp@hercules.acpub.duke.edu
  155. X
  156. X    Copyright and Permissions Information:
  157. X
  158. X    All U.S. and international copyrights are claimed by the
  159. X    author. The author grants permission to use this code
  160. X    and software based on it under the following conditions:
  161. X    (a) in general, the code and software based upon it may be
  162. X    used by individuals and by non-profit organizations; (b) it
  163. X    may also be utilized by governmental agencies in any country,
  164. X    with the exception of military agencies; (c) the code and/or
  165. X    software based upon it may not be sold for a profit without
  166. X    an explicit and specific permission from the author, except
  167. X    that a minimal fee may be charged for media on which it is
  168. X    copied, and for copying and handling; (d) the code must be
  169. X    distributed in the form in which it has been released by the
  170. X    author; and (e) the code and software based upon it may not
  171. X    be used for illegal activities.
  172. X
  173. ****************************************************************/
  174. X
  175. #include "stdio.h"
  176. #include "bw.h"
  177. #include "gr.h"
  178. #include "ui.h"
  179. X
  180. #ifdef     __STDC__
  181. #include "malloc.h"
  182. #else
  183. extern  char * malloc();
  184. #endif
  185. X
  186. struct uiwindow *
  187. ui_window( x1, y1, x2, y2, t_flag, t_bcolor, t_tcolor, t_text,
  188. X   b_flag, b_color,
  189. X   s_flag, s_color, m_color, m_style, buttons )
  190. X   int x1, y1, x2, y2;          /* coordinates of whole area    */
  191. X   int t_flag;                  /* title flag         */
  192. X   int t_bcolor, t_tcolor;      /* title background & text colors */
  193. X   char *t_text;                /* text of title      */
  194. X   int b_flag, b_color;         /* border flag, color      */
  195. X   int s_flag, s_color;         /* shadow flag, color      */
  196. X   int m_color, m_style;        /* color & style for main box   */
  197. X   int buttons;                 /* buttons */
  198. X   {
  199. X   static int _x1, _y1, _x2, _y2;  /* counters for coordinates     */
  200. X   static struct uiwindow *ret_struct;     /* structure for return data    */
  201. X   int s_ysize;
  202. X
  203. X   if ( ui_ready == 0 )
  204. X      {
  205. #ifdef DEBUG
  206. X      bw_error( "The ui system is not initialized." );
  207. #endif
  208. X      return;
  209. X      }
  210. X
  211. X   /* Get memory for window structure */
  212. X
  213. X   if ( ( ret_struct = (struct uiwindow *) malloc( sizeof( struct uiwindow ) )) == 0 )
  214. X      {
  215. X      bw_error( "Cannot allocate storage for window data." );
  216. X      return;
  217. X      }
  218. X
  219. X   /* Initialize counters */
  220. X
  221. X   ret_struct->x1 = _x1 = x1;
  222. X   ret_struct->y1 = _y1 = y1;
  223. X   ret_struct->x2 = _x2 = x2;
  224. X   ret_struct->y2 = _y2 = y2;
  225. X   ret_struct->t_flag = t_flag;
  226. X   ret_struct->t_bcolor = t_bcolor;
  227. X   ret_struct->t_tcolor = t_tcolor;
  228. X   ret_struct->s_flag = s_flag;
  229. X   ret_struct->s_color = s_color;
  230. X   ret_struct->b_flag = b_flag;
  231. X   ret_struct->b_color = b_color;
  232. X   ret_struct->m_color = m_color;
  233. X   ret_struct->m_style = m_style;
  234. X
  235. X   /* display the shadow */
  236. X
  237. X   if ( s_flag == TRUE )
  238. X      {
  239. X      s_ysize = (SHADOW_XSIZE * gr_pxsize ) / gr_pysize;
  240. X      ui_fbox( x1 + SHADOW_XSIZE, y1, x2, y2 - s_ysize,
  241. X     s_color, SOLID );
  242. X      _y1 += s_ysize;
  243. X      _x2 -= SHADOW_XSIZE;
  244. X      }
  245. X
  246. X   /* draw a one-pixel black line around the whole area */
  247. X
  248. X   gr_line( ui_screen, _x1, _y1, _x1, _y2, BLACK, SOLID );
  249. X   gr_line( ui_screen, _x1, _y2, _x2, _y2, BLACK, SOLID );
  250. X   gr_line( ui_screen, _x2, _y1, _x2, _y2, BLACK, SOLID );
  251. X   gr_line( ui_screen, _x1, _y1, _x2, _y1, BLACK, SOLID );
  252. X
  253. X   ++_x1;
  254. X   ++_y1;
  255. X   --_x2;
  256. X   --_y2;
  257. X
  258. X   /* display the title box */
  259. X
  260. X   if ( t_flag != 0 )
  261. X      {
  262. X
  263. X      /* calculate size of the title bar */
  264. X
  265. X      ret_struct->tbar_x1 = _x1;
  266. X      ret_struct->tbar_y1 = _y2 - ( ui_grwind->fysize
  267. X     + TITLE_YMARGIN + TITLE_YMARGIN );
  268. X      ret_struct->tbar_x2 = _x2;
  269. X      ret_struct->tbar_y2 = _y2;
  270. X      _y2 = ret_struct->tbar_y1 - 1;
  271. X
  272. X      /* blank the whole title bar area before buttons */
  273. X
  274. X      gr_rectangle( ui_screen, ret_struct->tbar_x1, ret_struct->tbar_y1,
  275. X     ret_struct->tbar_x2, ret_struct->tbar_y2, ret_struct->t_bcolor,
  276. X     SOLID );
  277. X
  278. X      ret_struct->ti_x1 = ret_struct->tbar_x1;
  279. X      ret_struct->ti_y1 = ret_struct->tbar_y1;
  280. X      ret_struct->ti_x2 = ret_struct->tbar_x2;
  281. X      ret_struct->ti_y2 = ret_struct->tbar_y2;
  282. X
  283. X      ret_struct->buttons = buttons;
  284. X
  285. X      /* calculate close button area and display the button */
  286. X
  287. X      if ( ( buttons & BUT_CLOSE ) > 0 )
  288. X     {
  289. X     ret_struct->bt_x1 = ret_struct->ti_x1 + ui_grwind->fxsize;
  290. X     ret_struct->bt_y1 = ret_struct->ti_y1 + TITLE_YMARGIN;
  291. X     ret_struct->bt_x2 = ret_struct->ti_x1
  292. X        + ( ui_grwind->fxsize * 3 );
  293. X     ret_struct->bt_y2 = ret_struct->ti_y2 - TITLE_YMARGIN;
  294. X     ret_struct->ti_x1 = ret_struct->bt_x2 + 1;
  295. X     ui_pbmcenter( ui_screen, ret_struct->bt_x1, ret_struct->bt_y1,
  296. X        ret_struct->bt_x2, ret_struct->bt_y2, &ui_clicon );
  297. X     }
  298. X
  299. X      /* calculate move button area and display the button */
  300. X
  301. X      if ( ( buttons & BUT_MOVE ) > 0 )
  302. X     {
  303. X     ret_struct->mv_x1 = ret_struct->ti_x2 - ( ui_grwind->fxsize * 3 );
  304. X     ret_struct->mv_y1 = ret_struct->ti_y1 + TITLE_YMARGIN;
  305. X     ret_struct->mv_x2 = ret_struct->ti_x2 - 2;
  306. X     ret_struct->mv_y2 = ret_struct->ti_y2 - TITLE_YMARGIN;
  307. X     ret_struct->ti_x2 = ret_struct->mv_x1 - 1;
  308. X     ui_pbmcenter( ui_screen, ret_struct->mv_x1, ret_struct->mv_y1,
  309. X        ret_struct->mv_x2, ret_struct->mv_y2, &ui_mvicon );
  310. X     }
  311. X
  312. X      /* calculate resize button area and display the button */
  313. X
  314. X      if ( ( buttons & BUT_RESIZE ) > 0 )
  315. X     {
  316. X     ret_struct->re_x1 = ret_struct->ti_x2 - ( ui_grwind->fxsize * 3 );
  317. X     ret_struct->re_y1 = ret_struct->ti_y1 + TITLE_YMARGIN;
  318. X     ret_struct->re_x2 = ret_struct->ti_x2 - 2;
  319. X     ret_struct->re_y2 = ret_struct->ti_y2 - TITLE_YMARGIN;
  320. X     ret_struct->ti_x2 = ret_struct->re_x1 - 1;
  321. X     ui_pbmcenter( ui_screen, ret_struct->re_x1, ret_struct->re_y1,
  322. X        ret_struct->re_x2, ret_struct->re_y2, &ui_reicon );
  323. X     }
  324. X
  325. X      /* Draw a line under the title bar */
  326. X
  327. X      gr_line( ui_screen, x1, _y2, _x2, _y2, s_color, SOLID );
  328. X     _y2 -= 1;
  329. X
  330. X      /* Display the text */
  331. X
  332. X      ui_wtitle( ret_struct, t_text );
  333. X
  334. X      }
  335. X
  336. X   /* display the main area */
  337. X
  338. X   ui_fbox( _x1, _y1, _x2, _y2, m_color, m_style );
  339. X
  340. X   /* display the border */
  341. X
  342. X   if ( b_flag == TRUE )
  343. X      {
  344. X      _x1 += BORDER_SIZE;
  345. X      _y1 += BORDER_SIZE;
  346. X      _x2 -= BORDER_SIZE;
  347. X      _y2 -= BORDER_SIZE;
  348. X      ui_hbox( _x1, _y1, _x2, _y2, b_color );
  349. X      _x1 += 1;
  350. X      _y1 += 1;
  351. X      _x2 -= 1;
  352. X      _y2 -= 1;
  353. X      }
  354. X
  355. X   /* return coordinates of usable area */
  356. X
  357. X   ret_struct->u_x1 = _x1;
  358. X   ret_struct->u_y1 = _y1;
  359. X   ret_struct->u_x2 = _x2;
  360. X   ret_struct->u_y2 = _y2;
  361. X   return ret_struct;
  362. X
  363. X   }
  364. X
  365. ui_rewindow( window, newtitle )
  366. X   struct uiwindow *window;
  367. X   char *newtitle;
  368. X   {
  369. X   static int _x1, _y1, _x2, _y2;  /* counters for coordinates     */
  370. X   int s_ysize;
  371. X
  372. X   if ( window == 0 )
  373. X      {
  374. X      return;
  375. X      }
  376. X
  377. X   _x1 = window->x1;
  378. X   _y1 = window->y1;
  379. X   _x2 = window->x2;
  380. X   _y2 = window->y2;
  381. X
  382. X   /* display the shadow */
  383. X
  384. X   if ( window->s_flag != 0 )
  385. X      {
  386. X      s_ysize = (SHADOW_XSIZE * gr_pxsize ) / gr_pysize;
  387. X      ui_fbox( window->x1 + SHADOW_XSIZE, window->y1,
  388. X     window->x2, window->y2 - s_ysize,
  389. X     window->s_color, 1 );
  390. X      _y1 += s_ysize;
  391. X      _x2 -= SHADOW_XSIZE;
  392. X      }
  393. X
  394. X   /* draw a one-pixel black line around the whole area */
  395. X
  396. X   gr_line( ui_screen, _x1, _y1, _x1, _y2, BLACK, SOLID );
  397. X   gr_line( ui_screen, _x1, _y2, _x2, _y2, BLACK, SOLID );
  398. X   gr_line( ui_screen, _x2, _y1, _x2, _y2, BLACK, SOLID );
  399. X   gr_line( ui_screen, _x1, _y1, _x2, _y1, BLACK, SOLID );
  400. X
  401. X   ++_x1;
  402. X   ++_y1;
  403. X   --_x2;
  404. X   --_y2;
  405. X
  406. X   /* display the title box */
  407. X
  408. X   if ( window->t_flag == TRUE )
  409. X      {
  410. X
  411. X      gr_rectangle( ui_screen, window->tbar_x1, window->tbar_y1,
  412. X     window->tbar_x2, window->tbar_y2, window->t_bcolor,
  413. X     SOLID );
  414. X
  415. X      ui_wtitle( window, newtitle );
  416. X
  417. X      /* Draw a line under the title bar */
  418. X
  419. X      _y2 = window->tbar_y1;
  420. X      _y2 -= 1;
  421. X      gr_line( ui_screen, window->x1, _y2, _x2, _y2,
  422. X     window->s_color, SOLID );
  423. X      _y2 -= 1;
  424. X
  425. X      /* display close button */
  426. X
  427. X      if ( ( window->buttons & BUT_CLOSE ) > 0 )
  428. X     {
  429. X     ui_pbmcenter( ui_screen, window->bt_x1, window->bt_y1,
  430. X        window->bt_x2, window->bt_y2, &ui_clicon );
  431. X     }
  432. X
  433. X      /* display move button */
  434. X
  435. X      if ( ( window->buttons & BUT_MOVE ) > 0 )
  436. X     {
  437. X     ui_pbmcenter( ui_screen, window->mv_x1, window->mv_y1,
  438. X        window->mv_x2, window->mv_y2, &ui_mvicon );
  439. X     }
  440. X
  441. X      /* display resize button */
  442. X
  443. X      if ( ( window->buttons & BUT_RESIZE ) > 0 )
  444. X     {
  445. X     ui_pbmcenter( ui_screen, window->re_x1, window->re_y1,
  446. X        window->re_x2, window->re_y2, &ui_reicon );
  447. X     }
  448. X
  449. X      }
  450. X
  451. X   /* display the main area */
  452. X
  453. X   ui_fbox( _x1, _y1, _x2, _y2, window->m_color, window->m_style );
  454. X
  455. X   /* display the border */
  456. X
  457. X   if ( window->b_flag != 0 )
  458. X      {
  459. X      _x1 += BORDER_SIZE;
  460. X      _y1 += BORDER_SIZE;
  461. X      _x2 -= BORDER_SIZE;
  462. X      _y2 -= BORDER_SIZE;
  463. X      ui_hbox( _x1, _y1, _x2, _y2, window->b_color );
  464. X      }
  465. X
  466. X   }
  467. X
  468. ui_fbox( x1, y1, x2, y2, color, style )
  469. X   int x1, y1, x2, y2, color, style;
  470. X   {
  471. #ifdef  OLD_DEBUG
  472. X   sprintf( bw_ebuf, "[pr:] ui_fbox(): %d %d %d %d", x1, y1, x2, y2 );
  473. X   bw_error( bw_ebuf );
  474. #endif
  475. X   gr_rectangle( ui_screen, x1, y1, x2, y2, color, style );
  476. X   }
  477. X
  478. ui_hbox( x1, y1, x2, y2, color )
  479. X   int x1, y1, x2, y2, color;
  480. X   {
  481. X   gr_rectangle( ui_screen, x1, y1, x2, y2, color, HOLLOW );
  482. X   }
  483. X
  484. ui_wtitle( window, buffer )
  485. X   struct uiwindow *window;
  486. X   char *buffer;
  487. X   {
  488. X
  489. X   /* show the title bar */
  490. X
  491. X   gr_rectangle( ui_screen, window->ti_x1, window->ti_y1,
  492. X      window->ti_x2, window->ti_y2, window->t_bcolor,
  493. X      SOLID );
  494. X
  495. X   /* display the title text */
  496. X
  497. X   ui_str( window->ti_x1 + ui_grwind->fxsize,
  498. X      window->ti_y1 + TITLE_YMARGIN, window->ti_x2,
  499. X      window->t_bcolor, window->t_tcolor, buffer );
  500. X
  501. X   }
  502. SHAR_EOF
  503. chmod 0644 io/ui/ui_boxes.c ||
  504. echo 'restore of io/ui/ui_boxes.c failed'
  505. Wc_c="`wc -c < 'io/ui/ui_boxes.c'`"
  506. test 9808 -eq "$Wc_c" ||
  507.     echo 'io/ui/ui_boxes.c: original size 9808, current size' "$Wc_c"
  508. rm -f _shar_wnt_.tmp
  509. fi
  510. # ============= io/ui/ui_clock.c ==============
  511. if test -f 'io/ui/ui_clock.c' -a X"$1" != X"-c"; then
  512.     echo 'x - skipping io/ui/ui_clock.c (File already exists)'
  513.     rm -f _shar_wnt_.tmp
  514. else
  515. > _shar_wnt_.tmp
  516. echo 'x - extracting io/ui/ui_clock.c (Text)'
  517. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_clock.c' &&
  518. /****************************************************************
  519. X
  520. X    ui_clock.c      Clock routines for
  521. X            The Bywater Graphical User Interface
  522. X
  523. X            Copyright (c) 1991, Ted A. Campbell
  524. X
  525. X            Bywater Software
  526. X            P. O. Box 4023 
  527. X            Duke Station 
  528. X            Durham, NC  27706
  529. X
  530. X            email: tcamp@hercules.acpub.duke.edu
  531. X
  532. X    Copyright and Permissions Information:
  533. X
  534. X    All U.S. and international copyrights are claimed by the
  535. X    author. The author grants permission to use this code
  536. X    and software based on it under the following conditions:
  537. X    (a) in general, the code and software based upon it may be 
  538. X    used by individuals and by non-profit organizations; (b) it
  539. X    may also be utilized by governmental agencies in any country,
  540. X    with the exception of military agencies; (c) the code and/or
  541. X    software based upon it may not be sold for a profit without
  542. X    an explicit and specific permission from the author, except
  543. X    that a minimal fee may be charged for media on which it is
  544. X    copied, and for copying and handling; (d) the code must be 
  545. X    distributed in the form in which it has been released by the
  546. X    author; and (e) the code and software based upon it may not 
  547. X    be used for illegal activities. 
  548. X
  549. ****************************************************************/
  550. X
  551. #include "stdio.h"
  552. #include "time.h"
  553. #include "gr.h"
  554. #include "ui.h"
  555. X
  556. #ifdef  __STDC__
  557. #include "stdlib.h"
  558. #else
  559. #define time_t  long
  560. extern char *getenv();
  561. #endif
  562. X
  563. /* #define      USESMALLFONT    */
  564. X
  565. int cl_initialized = FALSE;
  566. static int cl_x, cl_y, cl_fore, cl_back;
  567. static char clock_buf[ 36 ];
  568. static char env_buf[ 48 ];
  569. static int last_time;
  570. X
  571. ui_clinit( x, y, fore, back )
  572. X    int x, y, fore, back;
  573. X    {
  574. X    static time_t now;
  575. X    struct tm *clock_time;
  576. X    register int c;
  577. X
  578. X    time( &now );
  579. X    clock_time = localtime( &now );
  580. X
  581. X    if ( getenv( "TZ" ) == NULL )
  582. X        {
  583. X        strcpy( env_buf, "LOC" );
  584. X        }
  585. X    else
  586. X        {
  587. X        strcpy( env_buf, getenv( "TZ" ) );
  588. X        }
  589. X
  590. X    if ( clock_time->tm_isdst == 0 )
  591. X        {
  592. X        env_buf[ 3 ] = 0;
  593. X        }
  594. X    else
  595. X        {
  596. X        for ( c = 0; c < 4; ++c )
  597. X            {
  598. X            env_buf[ c ] = env_buf[ c + 4 ];
  599. X            }
  600. X        }
  601. X
  602. X    cl_x = x;
  603. X    cl_y = y;
  604. X    cl_fore = fore;
  605. X    cl_back = back;
  606. X    cl_initialized = TRUE;
  607. X    }
  608. X
  609. ui_clock()
  610. X    {
  611. X    static time_t now;
  612. #ifdef  USESMALLFONT
  613. X    int save_fysize, save_font;
  614. #endif
  615. X    struct tm *clock_time;
  616. X
  617. X    if ( cl_initialized == FALSE )
  618. X        {
  619. X        return FALSE;
  620. X        }
  621. X
  622. X    time( &now );
  623. X    clock_time = localtime( &now );
  624. X
  625. X    if ( clock_time->tm_min == last_time )
  626. X        {
  627. X        return TRUE;
  628. X        }
  629. X
  630. #ifdef  USESMALLFONT
  631. X    save_fysize = ui_grwind->fysize;
  632. X    save_font   = ui_grwind->font;
  633. X    gr_font( ui_screen, save_font, save_fysize * 4 );
  634. #endif
  635. X
  636. X    last_time = clock_time->tm_min;
  637. X    sprintf( clock_buf, "%02d:%02d %s",
  638. X        clock_time->tm_hour, clock_time->tm_min, env_buf );
  639. X    gr_text( ui_screen, cl_x,
  640. X        cl_y, clock_buf, cl_fore, cl_back );
  641. X
  642. #ifdef  USESMALLFONT
  643. X    gr_font( ui_screen, save_font, save_fysize );
  644. #endif
  645. X
  646. X    }
  647. X
  648. ui_clforce()
  649. X    {
  650. X    last_time = 63;
  651. X    ui_clock();
  652. X    }
  653. SHAR_EOF
  654. chmod 0644 io/ui/ui_clock.c ||
  655. echo 'restore of io/ui/ui_clock.c failed'
  656. Wc_c="`wc -c < 'io/ui/ui_clock.c'`"
  657. test 2853 -eq "$Wc_c" ||
  658.     echo 'io/ui/ui_clock.c: original size 2853, current size' "$Wc_c"
  659. rm -f _shar_wnt_.tmp
  660. fi
  661. # ============= io/ui/ui_dial.c ==============
  662. if test -f 'io/ui/ui_dial.c' -a X"$1" != X"-c"; then
  663.     echo 'x - skipping io/ui/ui_dial.c (File already exists)'
  664.     rm -f _shar_wnt_.tmp
  665. else
  666. > _shar_wnt_.tmp
  667. echo 'x - extracting io/ui/ui_dial.c (Text)'
  668. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_dial.c' &&
  669. /****************************************************************
  670. X
  671. X    ui_dial.c       Dialog-box and alarm-box routines for
  672. X            The Bywater Graphical User Interface
  673. X
  674. X            Copyright (c) 1991, Ted A. Campbell
  675. X
  676. X            Bywater Software
  677. X            P. O. Box 4023 
  678. X            Duke Station 
  679. X            Durham, NC  27706
  680. X
  681. X            email: tcamp@hercules.acpub.duke.edu
  682. X
  683. X    Copyright and Permissions Information:
  684. X
  685. X    All U.S. and international copyrights are claimed by the
  686. X    author. The author grants permission to use this code
  687. X    and software based on it under the following conditions:
  688. X    (a) in general, the code and software based upon it may be 
  689. X    used by individuals and by non-profit organizations; (b) it
  690. X    may also be utilized by governmental agencies in any country,
  691. X    with the exception of military agencies; (c) the code and/or
  692. X    software based upon it may not be sold for a profit without
  693. X    an explicit and specific permission from the author, except
  694. X    that a minimal fee may be charged for media on which it is
  695. X    copied, and for copying and handling; (d) the code must be 
  696. X    distributed in the form in which it has been released by the
  697. X    author; and (e) the code and software based upon it may not 
  698. X    be used for illegal activities. 
  699. X
  700. ****************************************************************/
  701. X
  702. #include "stdio.h"
  703. #include "gr.h"
  704. #include "ui.h"
  705. X
  706. ui_dial( x1, y1, x2, y2, background, foreground, marker_color, shadow,
  707. X   title, text, prompt, buffer, i_window )
  708. X   int x1, y1, x2, y2, background, foreground, shadow, marker_color;
  709. X   char *title, *text, *prompt, *buffer;
  710. X   struct uiwindow **i_window;
  711. X   {
  712. X   static struct uiwindow *window;
  713. X   register int x, y;
  714. X
  715. X   /* Draw the box */
  716. X
  717. X   if ( *i_window == NULL )
  718. X      {
  719. X      window = *i_window = ui_window( x1, y1, x2, y2, TRUE, background,
  720. X     foreground, title, TRUE, BLACK,
  721. X     shadow, BLACK, background, SOLID, BUT_CLOSE );
  722. X      }
  723. X   else
  724. X      {
  725. X      window = *i_window;
  726. X      ui_rewindow( window, title );
  727. X      }
  728. X
  729. X   /* Write the text string to the box */
  730. X
  731. X   ui_text( window->u_x1 + gr_strlen( "   " ),
  732. X      window->u_y1 + ( ui_grwind->fysize * 3 ),
  733. X      window->u_x2, window->u_y2, 20, background, foreground, 
  734. X      text );
  735. X
  736. X   /* Set array coordinates for prompt and entry string */
  737. X
  738. X   x = window->u_x1 + gr_strlen( "======" );
  739. X   y = window->u_y1 + ( ui_grwind->fysize * 2 );
  740. X
  741. X   /* Display a marker */ 
  742. X
  743. X   gr_circle( ui_screen, x,
  744. X      y + ui_grwind->fysize / 2,
  745. X      ui_grwind->fysize / 4, marker_color, SOLID );
  746. X   x += ui_grwind->fysize * 2;
  747. X
  748. X   /* Display the prompt string */
  749. X
  750. X   ui_str( x, y, window->u_x2,
  751. X      background, foreground, prompt );
  752. X   x += gr_strlen( prompt );
  753. X
  754. X   /* Get the string from the box */
  755. X
  756. X   ui_gets( window, x, y, 64, buffer,
  757. X      TRUE, foreground, background );
  758. X
  759. X   }
  760. X
  761. ui_yn( x1, y1, x2, y2, background, foreground, marker_color, shadow,
  762. X   text, mes0, mes1, i_window )
  763. X   int x1, y1, x2, y2, background, foreground, shadow, marker_color;
  764. X   char *text, *mes0, *mes1;
  765. X   struct uiwindow **i_window;
  766. X   {
  767. X   static struct uiwindow *window;
  768. X   register int x, y;
  769. X   int y_x1, y_y1, y_x2, y_y2;
  770. X   int n_x1, n_y1, n_x2, n_y2;
  771. X   int carry_on, mo_xsrc, mo_ysrc, test, key;
  772. X   static int x_pos, y_pos, b_stat;
  773. X   
  774. X   /* Draw the box */
  775. X
  776. X   if ( *i_window == NULL )
  777. X      {
  778. X      window = *i_window = ui_window( x1, y1, x2, y2, FALSE, background,
  779. X         foreground, "", 1, 0, 
  780. X     shadow, 0, background, 1, 0 );
  781. X      }
  782. X   else
  783. X      {
  784. X      window = *i_window;
  785. X      ui_rewindow( window, "" );
  786. X      }
  787. X
  788. X   /* Write the text string to the box */
  789. X
  790. X   ui_text( window->u_x1 + gr_strlen( "   " ),
  791. X      window->u_y1 + ( ui_grwind->fysize * 3 ),
  792. X      window->u_x2, window->u_y2, 20, background, foreground, 
  793. X      text );
  794. X
  795. X   /* Set array coordinates for capsules */
  796. X
  797. X   x = window->u_x1 + (( window->u_x2 - window->u_x1 ) / 3 );
  798. X   y = window->u_y1 + ( ui_grwind->fysize * 2 );
  799. X
  800. X   y_x1 = x - ( gr_strlen( mes1 ) / 2 );
  801. X   y_x2 = x + ( gr_strlen( mes1 ) / 2 );
  802. X
  803. X   n_y1 = y_y1 = y;
  804. X   n_y2 = y_y2 = y + (( ui_grwind->fysize * 3 ) / 2 );
  805. X
  806. X   x = x + (( window->u_x2 - window->u_x1 ) / 3 );
  807. X   n_x1 = x - ( gr_strlen( mes0 ) / 2 );
  808. X   n_x2 = x + ( gr_strlen( mes0 ) / 2 );
  809. X
  810. X   /* show capsules and their text */
  811. X
  812. X   uid_capsule( y_x1, y_y1, y_x2, y_y2, BLACK, SOLID );
  813. X   uid_capsule( n_x1, n_y1, n_x2, n_y2, BLACK, SOLID );
  814. X
  815. X   gr_text( ui_screen, y_x1,
  816. X      y_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
  817. X      mes1, background, foreground );
  818. X
  819. X   gr_text( ui_screen, n_x1,
  820. X      n_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
  821. X      mes0, background, foreground );
  822. X
  823. X   /* loop for response */
  824. X
  825. X   carry_on = TRUE;
  826. X   while ( carry_on == TRUE )
  827. X      {
  828. X      if ( kb_rxstat() == TRUE )
  829. X         {
  830. X         key = kb_rx();
  831. X
  832. X         switch( key )
  833. X            {
  834. X            case 'Y':
  835. X            case 'y':
  836. X               return TRUE;
  837. X               break;
  838. X            case 'N':
  839. X            case 'n':
  840. X               return FALSE;
  841. X               break;
  842. X            default:
  843. X               break;
  844. X            }
  845. X         }
  846. X
  847. X      else if ( gr_ismouse == TRUE )
  848. X         {
  849. X
  850. X         if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat )
  851. X            == TRUE )
  852. X            {
  853. X            key = 0;
  854. X            test = TRUE;
  855. X            gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  856. X            mo_xsrc = x_pos;
  857. X            mo_ysrc = y_pos;
  858. X            gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  859. X            }
  860. X         
  861. X         if ( test == TRUE )
  862. X            {
  863. X        if ( uil_bounds( x_pos, y_pos, y_x1, y_y1, y_x2, y_y2 ) == TRUE )
  864. X               {
  865. X               return TRUE;
  866. X               }
  867. X        else if ( uil_bounds( x_pos, y_pos, n_x1, n_y1, n_x2, n_y2 ) == TRUE )
  868. X               {
  869. X               return FALSE;
  870. X               }
  871. X            }
  872. X
  873. X         test = FALSE;
  874. X         }
  875. X
  876. X      else
  877. X         {
  878. X     ui_poll();
  879. X         }
  880. X      }
  881. X
  882. X   }
  883. X
  884. ui_alarm( x1, y1, x2, y2, background, foreground, marker_color, shadow,
  885. X   text, prompt, i_window )
  886. X   int x1, y1, x2, y2, background, foreground, shadow, marker_color;
  887. X   char *text, *prompt;
  888. X   struct uiwindow **i_window;
  889. X   {
  890. X   static struct uiwindow *window;
  891. X   int y_x1, y_y1, y_x2, y_y2;
  892. X   register int x, y;
  893. X   int carry_on, mo_xsrc, mo_ysrc, test, key;
  894. X   static int x_pos, y_pos, b_stat;
  895. X
  896. X   /* Draw the box */
  897. X
  898. X   if ( *i_window == NULL )
  899. X      {
  900. X      *i_window = window = ui_window( x1, y1, x2, y2, FALSE, background,
  901. X         foreground, "", 1, 0, 
  902. X     shadow, 0, background, 1, 0 );
  903. X      }
  904. X   else
  905. X      {
  906. X      window = *i_window;
  907. X      ui_rewindow( window, "" );
  908. X      }
  909. X
  910. X   /* Write the text string to the box */
  911. X
  912. X   ui_text( window->u_x1 + gr_strlen( "   " ),
  913. X      window->u_y1 + ( ui_grwind->fysize * 3 ),
  914. X      window->u_x2, window->u_y2, 20, background, foreground, 
  915. X      text );
  916. X
  917. X   /* Set array coordinates for capsules */
  918. X
  919. X   x = window->u_x1 + ((( window->u_x2 - window->u_x1 ) / 3 ) * 2 );
  920. X   y = window->u_y1 + ( ui_grwind->fysize * 2 );
  921. X
  922. X   y_x1 = x - ( gr_strlen( prompt ) / 2 );
  923. X   y_x2 = x + ( gr_strlen( prompt ) / 2 );
  924. X
  925. X   y_y1 = y;
  926. X   y_y2 = y + (( ui_grwind->fysize * 3 ) / 2 );
  927. X
  928. X   /* show capsule and text */
  929. X
  930. X   uid_capsule( y_x1, y_y1, y_x2, y_y2, BLACK, SOLID );
  931. X
  932. X   gr_text( ui_screen, y_x1,
  933. X      y_y1 + (( ui_grwind->fysize * 10 ) / 40 ),
  934. X      prompt, background, foreground );
  935. X
  936. X   /* loop for response */
  937. X
  938. X   carry_on = TRUE;
  939. X   while ( carry_on == TRUE )
  940. X      {
  941. X      if ( kb_rxstat() == TRUE )
  942. X         {
  943. X         key = kb_rx();
  944. X         return key;
  945. X         }
  946. X
  947. X      else if ( gr_ismouse == TRUE )
  948. X         {
  949. X
  950. X         if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat )
  951. X            == TRUE )
  952. X            {
  953. X            key = 0;
  954. X            test = TRUE;
  955. X            gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  956. X            mo_xsrc = x_pos;
  957. X            mo_ysrc = y_pos;
  958. X            gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  959. X            }
  960. X         
  961. X         if ( test == TRUE )
  962. X            {
  963. X        if ( uil_bounds( x_pos, y_pos, y_x1, y_y1, y_x2, y_y2 ) == TRUE )
  964. X               {
  965. X               return TRUE;
  966. X               }
  967. X            }
  968. X
  969. X         test = FALSE;
  970. X         }
  971. X
  972. X      else
  973. X         {
  974. X     ui_poll();
  975. X         }
  976. X      }
  977. X
  978. X   }
  979. X
  980. ui_disp( x1, y1, x2, y2, background, foreground, shadow, title, text,
  981. X   i_window )
  982. X   int x1, y1, x2, y2, background, foreground, shadow;
  983. X   char *title, *text;
  984. X   struct uiwindow **i_window;
  985. X   {
  986. X   static struct uiwindow *window;
  987. X
  988. X   /* Draw the box */
  989. X
  990. X   if ( *i_window == 0 )
  991. X      {
  992. X      *i_window = window = ui_window( x1, y1, x2, y2, TRUE, background,
  993. X         foreground, title, 1, 0, 
  994. X     shadow, 0, background, 1, BUT_CLOSE );
  995. X      }
  996. X   else
  997. X      {
  998. X      window = *i_window;
  999. X      ui_rewindow( window, title );
  1000. X      }
  1001. X
  1002. X   /* Write the text string to the box */
  1003. X
  1004. X   ui_text( window->u_x1 + gr_strlen( "   " ),
  1005. X      window->u_y1 + ui_grwind->fysize,
  1006. X      window->u_x2, window->u_y2, 20, background, foreground, 
  1007. X      text );
  1008. X
  1009. X   }
  1010. X
  1011. uid_capsule( x1, y1, x2, y2, color, style )
  1012. X   int x1, y1, x2, y2, color, style;
  1013. X   {
  1014. X   int r, x, y;
  1015. X
  1016. X   x = x1;
  1017. X   r = ((( y2 - y1 ) * 30 ) / 60 );
  1018. X   y = y1 + r;
  1019. X   gr_circle( ui_screen, x, y, r, color, style );
  1020. X   x = x2;
  1021. X   gr_circle( ui_screen, x, y, r, color, style );
  1022. X   ui_fbox( x1, y1, x2, y2, color, style );
  1023. X   
  1024. X   }
  1025. SHAR_EOF
  1026. chmod 0644 io/ui/ui_dial.c ||
  1027. echo 'restore of io/ui/ui_dial.c failed'
  1028. Wc_c="`wc -c < 'io/ui/ui_dial.c'`"
  1029. test 9126 -eq "$Wc_c" ||
  1030.     echo 'io/ui/ui_dial.c: original size 9126, current size' "$Wc_c"
  1031. rm -f _shar_wnt_.tmp
  1032. fi
  1033. # ============= io/ui/ui_gets.c ==============
  1034. if test -f 'io/ui/ui_gets.c' -a X"$1" != X"-c"; then
  1035.     echo 'x - skipping io/ui/ui_gets.c (File already exists)'
  1036.     rm -f _shar_wnt_.tmp
  1037. else
  1038. > _shar_wnt_.tmp
  1039. echo 'x - extracting io/ui/ui_gets.c (Text)'
  1040. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_gets.c' &&
  1041. /****************************************************************
  1042. X
  1043. X    ui_gets.c       gets function for
  1044. X            The Bywater Graphical User Interface
  1045. X
  1046. X            Copyright (c) 1991, Ted A. Campbell
  1047. X
  1048. X            Bywater Software
  1049. X            P. O. Box 4023 
  1050. X            Duke Station 
  1051. X            Durham, NC  27706
  1052. X
  1053. X            email: tcamp@hercules.acpub.duke.edu
  1054. X
  1055. X    Copyright and Permissions Information:
  1056. X
  1057. X    All U.S. and international copyrights are claimed by the
  1058. X    author. The author grants permission to use this code
  1059. X    and software based on it under the following conditions:
  1060. X    (a) in general, the code and software based upon it may be 
  1061. X    used by individuals and by non-profit organizations; (b) it
  1062. X    may also be utilized by governmental agencies in any country,
  1063. X    with the exception of military agencies; (c) the code and/or
  1064. X    software based upon it may not be sold for a profit without
  1065. X    an explicit and specific permission from the author, except
  1066. X    that a minimal fee may be charged for media on which it is
  1067. X    copied, and for copying and handling; (d) the code must be 
  1068. X    distributed in the form in which it has been released by the
  1069. X    author; and (e) the code and software based upon it may not 
  1070. X    be used for illegal activities. 
  1071. X
  1072. ****************************************************************/
  1073. X
  1074. #include "stdio.h"
  1075. #include "ctype.h"
  1076. #include "gr.h"
  1077. #include "kb.h"
  1078. #include "ui.h"
  1079. X
  1080. #define    BACKSPACE    8
  1081. #define    CURSOR        '_'
  1082. X
  1083. ui_wait()
  1084. X    {
  1085. X    register int carry_on;
  1086. X    static int x_pos, y_pos, b_stat;
  1087. X
  1088. X    carry_on = TRUE;
  1089. X    while( carry_on == TRUE )
  1090. X        {
  1091. X        if ( kb_rxstat() == TRUE )
  1092. X            {
  1093. X            return kb_rx();
  1094. X            }
  1095. X        if ( gr_ismouse == TRUE )
  1096. X            {
  1097. X            if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat ) == TRUE )
  1098. X                {
  1099. X                gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  1100. X                gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  1101. X                return TRUE;
  1102. X                }
  1103. X            }
  1104. X        ui_poll();
  1105. X        }
  1106. X    }
  1107. X
  1108. ui_getch()
  1109. X    {
  1110. X    while( kb_rxstat() == FALSE )
  1111. X        {
  1112. X        ui_poll();
  1113. X        }
  1114. X    return kb_rx();
  1115. X    }
  1116. X
  1117. ui_gets( window, x, y, maxlength, buffer, display, foreground, background  )
  1118. X    struct gr_window *window;
  1119. X    int x, y, maxlength, display, foreground, background;
  1120. X    char *buffer;
  1121. X    {
  1122. X    register int c, p;
  1123. X    char disp_string[ 128 ];
  1124. X
  1125. X    if ( display == TRUE )
  1126. X        {
  1127. X        sprintf( disp_string, "%c", CURSOR );
  1128. X        gr_text( ui_screen, x, y, disp_string,
  1129. X            foreground, background );
  1130. X        }
  1131. X
  1132. X    buffer[ 0 ] = 0;
  1133. X    c = p = 0;
  1134. X    while( ( c != CR ) && ( c != LF) && ( strlen( buffer ) < maxlength ))
  1135. X        {
  1136. X        c = ui_getch();
  1137. X        switch( c )
  1138. X            {
  1139. X            case BACKSPACE:
  1140. X                --p;
  1141. X                buffer[ p ] = 0;
  1142. X                break;                
  1143. X            case CR:
  1144. X            case LF:
  1145. X                break;
  1146. X            default:
  1147. X                buffer[ p ] = c;
  1148. X                ++p;
  1149. X                buffer[ p ] = 0;
  1150. X                break;
  1151. X            }
  1152. X        if ( display == TRUE )
  1153. X            {
  1154. X            sprintf( disp_string, "%s%c ", buffer, CURSOR );
  1155. X            gr_text( ui_screen, x, y, disp_string,
  1156. X                foreground, background );
  1157. X            }
  1158. X        }
  1159. X
  1160. X    if ( display == TRUE )
  1161. X        {
  1162. X        sprintf( disp_string, "%s ", buffer );
  1163. X        gr_text( ui_screen, x, y, disp_string,
  1164. X            foreground, background );
  1165. X        }
  1166. X
  1167. X    }
  1168. SHAR_EOF
  1169. chmod 0644 io/ui/ui_gets.c ||
  1170. echo 'restore of io/ui/ui_gets.c failed'
  1171. Wc_c="`wc -c < 'io/ui/ui_gets.c'`"
  1172. test 2866 -eq "$Wc_c" ||
  1173.     echo 'io/ui/ui_gets.c: original size 2866, current size' "$Wc_c"
  1174. rm -f _shar_wnt_.tmp
  1175. fi
  1176. # ============= io/ui/ui_icon.c ==============
  1177. if test -f 'io/ui/ui_icon.c' -a X"$1" != X"-c"; then
  1178.     echo 'x - skipping io/ui/ui_icon.c (File already exists)'
  1179.     rm -f _shar_wnt_.tmp
  1180. else
  1181. > _shar_wnt_.tmp
  1182. echo 'x - extracting io/ui/ui_icon.c (Text)'
  1183. sed 's/^X//' << 'SHAR_EOF' > 'io/ui/ui_icon.c' &&
  1184. /****************************************************************
  1185. X
  1186. X    ui_icon.c       Icon-based Selection routines for
  1187. X            The Bywater Graphical User Interface
  1188. X
  1189. X            Copyright (c) 1991, Ted A. Campbell
  1190. X
  1191. X            Bywater Software
  1192. X            P. O. Box 4023 
  1193. X            Duke Station 
  1194. X            Durham, NC  27706
  1195. X
  1196. X            email: tcamp@hercules.acpub.duke.edu
  1197. X
  1198. X    Copyright and Permissions Information:
  1199. X
  1200. X    All U.S. and international copyrights are claimed by the
  1201. X    author. The author grants permission to use this code
  1202. X    and software based on it under the following conditions:
  1203. X    (a) in general, the code and software based upon it may be 
  1204. X    used by individuals and by non-profit organizations; (b) it
  1205. X    may also be utilized by governmental agencies in any country,
  1206. X    with the exception of military agencies; (c) the code and/or
  1207. X    software based upon it may not be sold for a profit without
  1208. X    an explicit and specific permission from the author, except
  1209. X    that a minimal fee may be charged for media on which it is
  1210. X    copied, and for copying and handling; (d) the code must be 
  1211. X    distributed in the form in which it has been released by the
  1212. X    author; and (e) the code and software based upon it may not 
  1213. X    be used for illegal activities. 
  1214. X
  1215. ****************************************************************/
  1216. X
  1217. #include "stdio.h"
  1218. #include "gr.h"
  1219. #include "dr.h"
  1220. #include "kb.h"
  1221. #include "ui.h"
  1222. X
  1223. #define USESMALLFONT
  1224. #define SMALLFONTSIZE   35
  1225. X
  1226. /****************************************************************
  1227. X
  1228. X   ui_ficon()   File selection -- icon-based
  1229. X
  1230. ****************************************************************/
  1231. X
  1232. ui_ficon( x1, y1, x2, y2, specifier, title, m_box,
  1233. X   d_entries, max_entries,
  1234. X   background, foreground, highlight )
  1235. X   int x1, y1, x2, y2, background, foreground, highlight, max_entries;
  1236. X   struct menu_box *m_box;
  1237. X   char *specifier, *title;
  1238. X   struct dir_ent **d_entries;
  1239. X   {
  1240. X   register int c, test;
  1241. X   int carry_on, mo_xsrc, mo_ysrc;
  1242. X   static int x_pos, y_pos, b_stat, item;
  1243. X
  1244. X   uii_draw( x1, y1, x2, y2, specifier, title, m_box,
  1245. X      d_entries, max_entries,
  1246. X      background, foreground, highlight );
  1247. X
  1248. X   uii_activate( m_box, 0 );
  1249. X
  1250. X   test = FALSE;
  1251. X   carry_on = TRUE;
  1252. X   while( carry_on == TRUE )
  1253. X      {
  1254. X      if ( kb_rxstat() == TRUE )
  1255. X     {
  1256. X     c = kb_rx();
  1257. X     test = TRUE;
  1258. X     }
  1259. X      else if ( gr_ismouse == TRUE )
  1260. X     {
  1261. X     if ( gr_mouse( SAMPLE, &x_pos, &y_pos, &b_stat )
  1262. X        == TRUE )
  1263. X        {
  1264. X        c = 0;
  1265. X        test = TRUE;
  1266. X        gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  1267. X        mo_xsrc = x_pos;
  1268. X        mo_ysrc = y_pos;
  1269. X        gr_mouse( WAIT, &x_pos, &y_pos, &b_stat );
  1270. X        }
  1271. X     }
  1272. X
  1273. X      if ( test == TRUE )
  1274. X     {
  1275. X     c = uii_event( m_box, c, mo_xsrc, mo_ysrc, x_pos, y_pos, &item );
  1276. X        switch( c )
  1277. X        {
  1278. X        case EVENT_SELECTED:
  1279. X           carry_on = FALSE;
  1280. X           break;
  1281. X        case EVENT_EXIT:
  1282. X           item = TK_EXIT;
  1283. X           carry_on = FALSE;
  1284. X           break;
  1285. X        case EVENT_ERROR:
  1286. X           bw_error( "Error return from uil_event()" );
  1287. X           carry_on = FALSE;
  1288. X           break;
  1289. X        case EVENT_NULL:
  1290. X        default:
  1291. X           test = FALSE;
  1292. X           break;
  1293. X        }
  1294. X     }
  1295. X
  1296. X      ui_poll();
  1297. X
  1298. X      }
  1299. X
  1300. X   uii_deactivate( m_box );
  1301. X
  1302. X   return item;
  1303. X
  1304. X   }
  1305. X
  1306. /****************************************************************
  1307. X
  1308. X    uii_draw()      - draw file selection icon area
  1309. X
  1310. ****************************************************************/
  1311. X
  1312. uii_draw( x1, y1, x2, y2, specifier, title, m_box,
  1313. X   d_entries, max_entries,
  1314. X   background, foreground, highlight )
  1315. X   int x1, y1, x2, y2, background, foreground, highlight, max_entries;
  1316. X   struct menu_box *m_box;
  1317. X   char *specifier, *title;
  1318. X   struct dir_ent **d_entries;
  1319. X   {
  1320. X   register int number, c;
  1321. X   int x, y;
  1322. X   int carry_on;
  1323. X
  1324. #ifdef  OLD_DEBUG
  1325. X   sprintf( ui_tbuf, "uii_draw(): %d %d %d %d", x1, y1, x2, y2 );
  1326. X   bw_debug( ui_tbuf );
  1327. X   sprintf( ui_tbuf, "uii_draw(): is_drawn = %d", m_box->is_drawn );
  1328. X   bw_debug( ui_tbuf );
  1329. #endif
  1330. X
  1331. X   /* First check for existence of the file */
  1332. X
  1333. X   number = 0;
  1334. X   if ( dr_first( specifier, d_entries[ number ] ) == FALSE )
  1335. X      {
  1336. X      return TK_ERROR;
  1337. X      }
  1338. X
  1339. X   /* Find all entries */
  1340. X
  1341. X   number = 1;
  1342. X   while( ( dr_next( d_entries[ number ] ) == TRUE )
  1343. X      && ( number < max_entries ))
  1344. X      {
  1345. X      ++number;
  1346. X      }
  1347. X   m_box->number = number;
  1348. X
  1349. X   /* the following are performed only if the window has not been
  1350. X      redrawn -- programmer may force redrawing of the whole menu
  1351. X      box by setting the is_drawn int to 0 (FALSE) */
  1352. X
  1353. X   if ( m_box->is_drawn != TRUE )
  1354. X      {
  1355. X
  1356. X      /* draw the menu window */
  1357. X
  1358. X      if ( m_box->window == NULL )
  1359. X         {
  1360. X
  1361. #ifdef  OLD_DEBUG
  1362. X   sprintf( ui_tbuf, "uii_draw(): ready to draw window" );
  1363. X   bw_debug( ui_tbuf );
  1364. #endif
  1365. X
  1366. X     m_box->window = ui_window( x1, y1, x2, y2,
  1367. X            TRUE, highlight, foreground,
  1368. X            title, TRUE, BLACK,
  1369. X        FALSE, BLACK, background, SOLID,
  1370. X        BUT_CLOSE | BUT_MOVE | BUT_RESIZE );
  1371. X         }
  1372. X      else
  1373. X         {
  1374. X
  1375. #ifdef  OLD_DEBUG
  1376. X   sprintf( ui_tbuf, "uii_draw(): redraw window" );
  1377. X   bw_debug( ui_tbuf );
  1378. #endif
  1379. X
  1380. X     ui_rewindow( m_box->window, title );
  1381. X         }
  1382. X      }
  1383. X
  1384. X   /* on the other hand, if the menu box is not to be redrawn,
  1385. X      it should in any case be retitled */
  1386. X
  1387. X   else
  1388. X      {
  1389. X      ui_wtitle( m_box->window, title );
  1390. X      }
  1391. X
  1392. #ifdef  OLD_DEBUG
  1393. X   sprintf( ui_tbuf, "uii_draw() found %d entries", m_box->number );
  1394. X   bw_debug( ui_tbuf );
  1395. #endif
  1396. X
  1397. X   /* save font style and size, then attempt to set small font */
  1398. X
  1399. #ifdef  USESMALLFONT
  1400. X   m_box->save_font = ui_grwind->font;
  1401. X   m_box->save_fysize = ui_grwind->fysize;
  1402. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  1403. #endif
  1404. X
  1405. #ifdef OLD_DEBUG
  1406. X   sprintf( ui_tbuf, "uii_draw(): font_set" );
  1407. X   bw_debug( ui_tbuf );
  1408. #endif
  1409. X
  1410. X   /* assign colors to structure */
  1411. X
  1412. X   m_box->fore = foreground;
  1413. X   m_box->back = background;
  1414. X   m_box->high = highlight;
  1415. X
  1416. X   /* save d_titles */
  1417. X
  1418. X   m_box->d_entries = d_entries;
  1419. X   m_box->max_entries = max_entries;
  1420. X   m_box->type = MENU_ICON;
  1421. X
  1422. X   /* calculate icon size */
  1423. X
  1424. X   m_box->xsize = gr_strlen( "123456789012345" );
  1425. X   m_box->ysize = ui_grwind->fysize * 4;
  1426. X
  1427. #ifdef  OLD_DEBUG
  1428. X   sprintf( ui_tbuf, "ui_ficon(): icon size calculated" );
  1429. X   bw_debug( ui_tbuf );
  1430. #endif
  1431. X
  1432. X   /* the sliders have to be redrawn only if the is_drawn int
  1433. X      is 0 (FALSE) */
  1434. X
  1435. X   if ( m_box->is_drawn != TRUE )
  1436. X      {
  1437. X      uil_sliders( m_box );
  1438. X      }
  1439. X
  1440. #ifdef  OLD_DEBUG
  1441. X   sprintf( ui_tbuf, "ui_ficon(): sliders drawn" );
  1442. X   bw_debug( ui_tbuf );
  1443. #endif
  1444. X
  1445. X   /* abort if a single icon will not fit */
  1446. X
  1447. X   if ( ( m_box->i_x2 - m_box->i_x1 ) < m_box->xsize )
  1448. X      {
  1449. #ifdef  USESMALLFONT
  1450. X   gr_font( ui_screen, m_box->save_font,
  1451. X      m_box->save_fysize );
  1452. #endif
  1453. X      return TK_ERROR;
  1454. X      }
  1455. X
  1456. X   if ( ( m_box->i_y2 - m_box->i_y1 ) < m_box->ysize )
  1457. X      {
  1458. #ifdef  USESMALLFONT
  1459. X   gr_font( ui_screen, m_box->save_font,
  1460. X      m_box->save_fysize );
  1461. #endif
  1462. X      return TK_ERROR;
  1463. X      }
  1464. X
  1465. X   /* calculate total number of icon spaces */
  1466. X
  1467. X   m_box->x_items = m_box->x_logical =
  1468. X      ( m_box->i_x2 - m_box->i_x1 ) / m_box->xsize;
  1469. X   m_box->y_items =
  1470. X      ( m_box->i_y2 - m_box->i_y1 ) / m_box->ysize;
  1471. X
  1472. X   /* set roughly equal x and y items if all cannot be shown */
  1473. X
  1474. X   if ( ( m_box->x_items * m_box->y_items ) < m_box->number )
  1475. X      {
  1476. X      for ( x = m_box->x_items + 2; (x * x) < m_box->number; ++x )
  1477. X         {
  1478. X         }
  1479. X      --x;
  1480. X      m_box->x_logical = x;
  1481. X      }
  1482. X
  1483. X   m_box->y_logical = m_box->number / m_box->x_logical;
  1484. X   if (( m_box->number % m_box->x_logical ) > 0 )
  1485. X      {
  1486. X      ++m_box->y_logical;
  1487. X      }
  1488. X
  1489. #ifdef  OLD_DEBUG
  1490. X   sprintf( ui_tbuf, "ui_ficon() point 2" );
  1491. X   bw_debug( ui_tbuf );
  1492. #endif
  1493. X
  1494. X   /* calculate increments for elevators */
  1495. X
  1496. X   x = ui_grwind->ymax / 15;
  1497. X   y = ( x * gr_pxsize ) / gr_pysize;
  1498. X
  1499. X   if ( m_box->y_logical <= m_box->y_items )
  1500. X      {
  1501. X      m_box->vel_inc = 1;
  1502. X      }
  1503. X   else
  1504. X      {
  1505. X      m_box->vel_inc = ((( m_box->ve_y2 - ( m_box->ve_y1 + y ))
  1506. X         * INC_ACCURACY )
  1507. X         / ( m_box->y_logical - m_box->y_items ));
  1508. X      }
  1509. X
  1510. X   if ( m_box->x_logical <= m_box->x_items )
  1511. X      {
  1512. X      m_box->hel_inc = 1;
  1513. X      }
  1514. X   else
  1515. X      {
  1516. X      m_box->hel_inc = ((( m_box->he_x2 - ( m_box->he_x1 + x ))
  1517. X         * INC_ACCURACY )
  1518. X         / ( m_box->x_logical - m_box->x_items ));
  1519. X      }
  1520. X
  1521. #ifdef  OLD_DEBUG
  1522. X   sprintf( ui_tbuf, "window:  x1 = %d, y1 = %d, x2 = %d, y2 = %d, \nicon_xsize = %d, icon_ysize = %d, number = %d, x_items = %d, y_items = %d",
  1523. X      m_box->i_x1, m_box->i_y1, m_box->i_x2,
  1524. X      m_box->i_y2,
  1525. X      m_box->xsize, m_box->ysize, number, m_box->x_items, m_box->y_items );
  1526. X   bw_debug( ui_tbuf );
  1527. X   sprintf( ui_tbuf, "ui_ficon() point 3" );
  1528. X   bw_debug( ui_tbuf );
  1529. #endif
  1530. X
  1531. X   /* set initial values */
  1532. X
  1533. X   m_box->current = m_box->x_start 
  1534. X      = m_box->y_start = m_box->x_pos = m_box->y_pos = 0;
  1535. X
  1536. X   /* Display each icon */
  1537. X
  1538. X   uii_display( m_box );
  1539. X
  1540. X   /* note that the menu box is now drawn */
  1541. X
  1542. X   m_box->is_drawn = TRUE;
  1543. X
  1544. #ifdef  USESMALLFONT
  1545. X   gr_font( ui_screen, m_box->save_font,
  1546. X      m_box->save_fysize );
  1547. #endif
  1548. X
  1549. /*   uil_exit( m_box ); */
  1550. X
  1551. X   }
  1552. X
  1553. /****************************************************************
  1554. X
  1555. X   uii_activate()   Activate an icon menu box
  1556. X
  1557. ****************************************************************/
  1558. X
  1559. uii_activate( m_box, item )
  1560. X   struct menu_box *m_box;
  1561. X   int item;
  1562. X   {
  1563. X   register int x, y;
  1564. X   int carry_on;
  1565. X   
  1566. #ifdef  OLD_DEBUG
  1567. X   if ( m_box->d_entries == NULL )
  1568. X      {
  1569. X      bw_error( "Programmer error: menu box has not been drawn!" );
  1570. X      return FALSE;
  1571. X      }
  1572. #endif
  1573. X
  1574. #ifdef  USESMALLFONT
  1575. X   m_box->save_font = ui_grwind->font;
  1576. X   m_box->save_fysize = ui_grwind->fysize;
  1577. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  1578. #endif
  1579. X
  1580. X   if ( item > m_box->number )
  1581. X      {
  1582. X      item = 0;
  1583. X      }
  1584. X
  1585. X   if ( item == 0 )
  1586. X      {
  1587. X      m_box->x_start = m_box->y_start = m_box->x_pos = m_box->y_pos
  1588. X         = m_box->current = 0;
  1589. X      }
  1590. X   else if ( item != m_box->current )
  1591. X      {
  1592. X
  1593. X      m_box->current = item;
  1594. X      
  1595. X      /* calculate y_start */
  1596. X
  1597. X      y = 0;
  1598. X      carry_on = TRUE;
  1599. X      if ( m_box->y_logical <= m_box->y_items )
  1600. X         {
  1601. X         y = 0;
  1602. X         }
  1603. X      else while( ( y < m_box->y_logical ) && ( carry_on == TRUE ))
  1604. X         {
  1605. X         if ( (( m_box->x_logical * y ) +
  1606. X            ( m_box->x_logical * m_box->y_items )) > item )
  1607. X            {
  1608. X            carry_on = FALSE;
  1609. X            }
  1610. X         else
  1611. X            {
  1612. X            ++y;
  1613. X            }
  1614. X         }
  1615. X
  1616. X      /* calculate x_start */
  1617. X
  1618. X      x = 0;
  1619. X      carry_on = TRUE;
  1620. X      if ( m_box->x_logical <= m_box->x_items )
  1621. X         {
  1622. X         x = 0;
  1623. X
  1624. #ifdef OLD_DEBUG
  1625. X      sprintf( ui_tbuf, "x_logical <= x_items" );
  1626. X      ui_wtitle( m_box->window, ui_tbuf );
  1627. X      ui_wait();
  1628. #endif
  1629. X         }
  1630. X      else while( ( x < m_box->x_logical ) && ( carry_on == TRUE ))
  1631. X         {
  1632. X
  1633. #ifdef OLD_DEBUG
  1634. X      sprintf( ui_tbuf, "item <> x_logical = %d",  item % m_box->x_logical );
  1635. X      ui_wtitle( m_box->window, ui_tbuf );
  1636. X      ui_wait();
  1637. X      
  1638. X      sprintf( ui_tbuf, "trying %d", x );
  1639. X      ui_wtitle( m_box->window, ui_tbuf );
  1640. X      ui_wait();
  1641. #endif
  1642. X
  1643. X         if (( m_box->x_items + x ) > ( item % m_box->x_logical ))
  1644. X            {
  1645. X            carry_on = FALSE;
  1646. X            }
  1647. X         else
  1648. X            {
  1649. X            ++x;
  1650. X            }
  1651. X         }
  1652. X
  1653. #ifdef OLD_DEBUG
  1654. X      sprintf( ui_tbuf, "i %d; x %d; y %d", item, x, y );
  1655. X      ui_wtitle( m_box->window, ui_tbuf );
  1656. #endif
  1657. X
  1658. X      m_box->y_start = y;
  1659. X      m_box->x_start = x;
  1660. X      m_box->y_pos = ( item / m_box->x_logical ) - m_box->y_start;
  1661. X      m_box->x_pos = ( item % m_box->x_logical ) - m_box->x_start;
  1662. X
  1663. X      uii_display( m_box );
  1664. X      }
  1665. X
  1666. X   /* show current item selected */
  1667. X
  1668. X   uii_icon( m_box, m_box->current, TRUE );
  1669. X
  1670. #ifdef  USESMALLFONT
  1671. X   gr_font( ui_screen, m_box->save_font,
  1672. X      m_box->save_fysize );
  1673. #endif
  1674. X
  1675. X   }
  1676. X
  1677. /****************************************************************
  1678. X
  1679. X   uii_deactivate()   Deactivate an icon menu box
  1680. X
  1681. ****************************************************************/
  1682. X
  1683. uii_deactivate( m_box )
  1684. X   struct menu_box *m_box;
  1685. X   {
  1686. X
  1687. #ifdef  USESMALLFONT
  1688. X   m_box->save_font = ui_grwind->font;
  1689. X   m_box->save_fysize = ui_grwind->fysize;
  1690. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  1691. #endif
  1692. X
  1693. X   uii_icon( m_box, m_box->current, FALSE );
  1694. X
  1695. #ifdef  USESMALLFONT
  1696. X   gr_font( ui_screen, m_box->save_font,
  1697. X      m_box->save_fysize );
  1698. #endif
  1699. X
  1700. X   }
  1701. X
  1702. /****************************************************************
  1703. X
  1704. X   uii_event()   Query if keyboard or mouse actions affect an icon
  1705. X                menu box
  1706. X
  1707. ****************************************************************/
  1708. X
  1709. uii_event( m_box, key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest, item )
  1710. X   struct menu_box *m_box;
  1711. X   int key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest;
  1712. X   int *item;
  1713. X   {
  1714. X   static int how_far, x_sel, y_sel;
  1715. X   int carry_on;
  1716. X   register int c;
  1717. X
  1718. X   how_far = 0;
  1719. X   x_sel = 0;
  1720. X   y_sel = 0;
  1721. X   c = ui_event( m_box, key, mo_xsrc, mo_ysrc, mo_xdest, mo_ydest,
  1722. X      &how_far, &x_sel, &y_sel );
  1723. X
  1724. X   switch( c )
  1725. X      {
  1726. X
  1727. X      case CR:
  1728. X      case LF:
  1729. X         *item = m_box->current;
  1730. X         return EVENT_SELECTED;
  1731. X     break;
  1732. X
  1733. X      case ESCAPE:
  1734. X      case TK_EXIT:
  1735. X      case MO_EXIT:
  1736. X     *item = m_box->current = TK_EXIT;
  1737. X         return EVENT_EXIT;
  1738. X     break;
  1739. X
  1740. X      case KB_DOWN:
  1741. X
  1742. X     /* First test to see if it is possible to move
  1743. X        down one line on the y axis */
  1744. X
  1745. X     if ( m_box->current <
  1746. X        ( m_box->number - m_box->x_logical ))
  1747. X        {
  1748. X
  1749. #ifdef  USESMALLFONT
  1750. X   m_box->save_font = ui_grwind->font;
  1751. X   m_box->save_fysize = ui_grwind->fysize;
  1752. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  1753. #endif
  1754. X
  1755. X        /* show current item unselected */
  1756. X
  1757. X        uii_icon( m_box, m_box->current, FALSE );
  1758. X
  1759. X        /* advance current item and m_box->y_pos */
  1760. X
  1761. X        m_box->current += m_box->x_logical;
  1762. X        ++m_box->y_pos;
  1763. X
  1764. X        /* check to see if this will advance
  1765. X           past the visible lines in the icon
  1766. X           area */
  1767. X
  1768. X        if ( m_box->y_pos == m_box->y_items )
  1769. X           {
  1770. X           ++m_box->y_start;
  1771. X           --m_box->y_pos;
  1772. X           uii_display( m_box );
  1773. X           }
  1774. X
  1775. X        /* show current item selected */
  1776. X
  1777. X        uii_icon( m_box, m_box->current, TRUE );
  1778. X
  1779. X
  1780. #ifdef  USESMALLFONT
  1781. X   gr_font( ui_screen, m_box->save_font,
  1782. X      m_box->save_fysize );
  1783. #endif
  1784. X
  1785. X        }
  1786. X
  1787. X     *item = m_box->current;
  1788. X     return EVENT_CHANGE;
  1789. X     break;
  1790. X
  1791. X      case KB_UP:
  1792. X
  1793. X     /* First test to see if it is possible to move
  1794. X        up one line on the y axis */
  1795. X
  1796. X     if ( m_box->current >=  m_box->x_logical )
  1797. X        {
  1798. X
  1799. #ifdef  USESMALLFONT
  1800. X   m_box->save_font = ui_grwind->font;
  1801. X   m_box->save_fysize = ui_grwind->fysize;
  1802. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  1803. #endif
  1804. X
  1805. X        /* show current item unselected */
  1806. X
  1807. X        uii_icon( m_box, m_box->current, FALSE );
  1808. X
  1809. X        /* decrement current item and m_box->y_pos */
  1810. X
  1811. X        m_box->current -= m_box->x_logical;
  1812. X        --m_box->y_pos;
  1813. X
  1814. X        /* check to see if this will decrement
  1815. X           past the visible lines in the icon
  1816. X           area */
  1817. X
  1818. X        if ( m_box->y_pos < 0 )
  1819. X           {
  1820. X           --m_box->y_start;
  1821. X           ++m_box->y_pos;
  1822. X           uii_display( m_box );
  1823. X           }
  1824. X
  1825. X        /* show current item selected */
  1826. X
  1827. X        uii_icon( m_box, m_box->current, TRUE );
  1828. X
  1829. #ifdef  USESMALLFONT
  1830. X   gr_font( ui_screen, m_box->save_font,
  1831. X      m_box->save_fysize );
  1832. #endif
  1833. X
  1834. X        }
  1835. X
  1836. X     *item = m_box->current;
  1837. X     return EVENT_CHANGE;
  1838. X     break;
  1839. X
  1840. X      case KB_LEFT:
  1841. X
  1842. X     /* First test to see if it is possible to move
  1843. X        left one column on the x axis */
  1844. X
  1845. X     if ( ( m_box->current % m_box->x_logical ) > 0 )
  1846. X        {
  1847. X
  1848. #ifdef  USESMALLFONT
  1849. X   m_box->save_font = ui_grwind->font;
  1850. X   m_box->save_fysize = ui_grwind->fysize;
  1851. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  1852. #endif
  1853. X
  1854. X        /* show current item unselected */
  1855. X
  1856. X        uii_icon( m_box, m_box->current, FALSE );
  1857. X
  1858. X        /* decrement current item and m_box->x_pos */
  1859. X
  1860. X        --m_box->current;
  1861. X        --m_box->x_pos;
  1862. X
  1863. X        /* check to see if this will decrement
  1864. X           past the visible lines in the icon
  1865. X           area */
  1866. X
  1867. X        if ( m_box->x_pos < 0 )
  1868. X           {
  1869. X           --m_box->x_start;
  1870. X           ++m_box->x_pos;
  1871. X           uii_display( m_box );
  1872. X           }
  1873. X
  1874. X        /* show current item selected */
  1875. X
  1876. X        uii_icon( m_box, m_box->current, TRUE );
  1877. X
  1878. X
  1879. #ifdef  USESMALLFONT
  1880. X   gr_font( ui_screen, m_box->save_font,
  1881. X      m_box->save_fysize );
  1882. #endif
  1883. X
  1884. X        }
  1885. X
  1886. X     *item = m_box->current;
  1887. X     return EVENT_CHANGE;
  1888. X     break;
  1889. X
  1890. X      case KB_RIGHT:
  1891. X
  1892. X     /* First test to see if it is possible to move
  1893. X        right one column on the x axis */
  1894. X
  1895. X     if ( (( m_box->current % m_box->x_logical ) <
  1896. X        ( m_box->x_logical - 1 )) &&
  1897. X        ( m_box->current < ( m_box->number-1 ) ))
  1898. X        {
  1899. X
  1900. #ifdef  USESMALLFONT
  1901. X   m_box->save_font = ui_grwind->font;
  1902. X   m_box->save_fysize = ui_grwind->fysize;
  1903. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  1904. #endif
  1905. X
  1906. X        /* show current item unselected */
  1907. X
  1908. X        uii_icon( m_box, m_box->current,
  1909. X           FALSE );
  1910. X
  1911. X        /* increment current item and m_box->x_pos */
  1912. X
  1913. X        ++m_box->current;
  1914. X        ++m_box->x_pos;
  1915. X
  1916. X        /* check to see if this will increment
  1917. X           past the visible lines in the icon
  1918. X           area */
  1919. X
  1920. X        if ( m_box->x_pos >= m_box->x_items )
  1921. X           {
  1922. X           ++m_box->x_start;
  1923. X           --m_box->x_pos;
  1924. X           uii_display( m_box );
  1925. X           }
  1926. X
  1927. X        /* show current item selected */
  1928. X
  1929. X        uii_icon( m_box, m_box->current,
  1930. X           TRUE );
  1931. X
  1932. X
  1933. #ifdef  USESMALLFONT
  1934. X   gr_font( ui_screen, m_box->save_font,
  1935. X      m_box->save_fysize );
  1936. #endif
  1937. X
  1938. X        }
  1939. X
  1940. X     *item = m_box->current;
  1941. X     return EVENT_CHANGE;
  1942. X     break;
  1943. X
  1944. X      case MO_UP:
  1945. X
  1946. X     /* first see if it is possible to move up
  1947. X        at all */
  1948. X
  1949. X     if (( m_box->y_start > 0 ) && ( how_far > 0 ))
  1950. X        {
  1951. X
  1952. #ifdef  USESMALLFONT
  1953. X   m_box->save_font = ui_grwind->font;
  1954. X   m_box->save_fysize = ui_grwind->fysize;
  1955. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  1956. #endif
  1957. X
  1958. X        /* decrement how_far to an acceptable
  1959. X           number */
  1960. X
  1961. X        while ( ( m_box->y_start - how_far ) < 0 )
  1962. X           {
  1963. X           --how_far;
  1964. X           }
  1965. X
  1966. X        /* assign new values to m_box->y_start and
  1967. X           m_box->current */
  1968. X
  1969. X        m_box->y_start -= how_far;
  1970. X        m_box->current -= how_far * m_box->x_logical;
  1971. X
  1972. X        /* display all icons visible */
  1973. X
  1974. X        uii_display( m_box );
  1975. X
  1976. X        /* display currently selected icon */
  1977. X
  1978. X        uii_icon( m_box, m_box->current,
  1979. X           TRUE );
  1980. X
  1981. X
  1982. #ifdef  USESMALLFONT
  1983. X   gr_font( ui_screen, m_box->save_font,
  1984. X      m_box->save_fysize );
  1985. #endif
  1986. X
  1987. X        }
  1988. X
  1989. X     *item = m_box->current;
  1990. X     return EVENT_CHANGE;
  1991. X     break;
  1992. X
  1993. X      case MO_DN:
  1994. X
  1995. X     /* first see if it is possible to move down
  1996. X        at all */
  1997. X
  1998. X     if (( m_box->y_start <
  1999. X        ( m_box->y_logical - m_box->y_items ) )
  2000. X        && ( how_far > 0 ))
  2001. X        {
  2002. X
  2003. #ifdef  USESMALLFONT
  2004. X   m_box->save_font = ui_grwind->font;
  2005. X   m_box->save_fysize = ui_grwind->fysize;
  2006. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  2007. #endif
  2008. X
  2009. X        /* increment how_far to an acceptable
  2010. X           number */
  2011. X
  2012. X        while ( ( m_box->y_start + how_far ) >
  2013. X           ( m_box->y_logical
  2014. X           - m_box->y_items ))
  2015. X           {
  2016. X           --how_far;
  2017. X           }
  2018. X
  2019. X        /* assign new values to m_box->y_start and
  2020. X           m_box->current */
  2021. X
  2022. X        m_box->y_start += how_far;
  2023. X        m_box->current += how_far * m_box->x_logical;
  2024. X
  2025. X        /* display all icons visible */
  2026. X
  2027. X        uii_display( m_box );
  2028. X
  2029. X        /* display currently selected icon */
  2030. X
  2031. X        uii_icon( m_box, m_box->current,
  2032. X           TRUE );
  2033. X
  2034. X
  2035. #ifdef  USESMALLFONT
  2036. X   gr_font( ui_screen, m_box->save_font,
  2037. X      m_box->save_fysize );
  2038. #endif
  2039. X
  2040. X        }
  2041. X
  2042. X     *item = m_box->current;
  2043. X     return EVENT_CHANGE;
  2044. X     break;
  2045. X
  2046. X      case MO_RIGHT:
  2047. X
  2048. X     /* first see if it is possible to move right
  2049. X        at all */
  2050. X
  2051. X     if (( m_box->x_start <
  2052. X        ( m_box->x_logical - m_box->x_items ) )
  2053. X        && ( how_far > 0 ))
  2054. X        {
  2055. X
  2056. #ifdef  USESMALLFONT
  2057. X   m_box->save_font = ui_grwind->font;
  2058. X   m_box->save_fysize = ui_grwind->fysize;
  2059. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  2060. #endif
  2061. X
  2062. X        /* increment how_far to an acceptable
  2063. X           number */
  2064. X
  2065. X        while ( ( m_box->x_start + how_far ) >
  2066. X           ( m_box->x_logical
  2067. X           - m_box->x_items ))
  2068. X           {
  2069. X           --how_far;
  2070. X           }
  2071. X
  2072. X        /* assign new values to m_box->x_start and
  2073. X           m_box->current */
  2074. X
  2075. X        m_box->x_start += how_far;
  2076. X            m_box->current += how_far;
  2077. X
  2078. X            /* display all icons visible */
  2079. X
  2080. X        uii_display( m_box );
  2081. X
  2082. X            /* display currently selected icon */
  2083. X
  2084. X        uii_icon( m_box, m_box->current,
  2085. X               TRUE );
  2086. X
  2087. X
  2088. #ifdef  USESMALLFONT
  2089. X   gr_font( ui_screen, m_box->save_font,
  2090. X      m_box->save_fysize );
  2091. #endif
  2092. X
  2093. X            }
  2094. X
  2095. X     *item = m_box->current;
  2096. X     return EVENT_CHANGE;
  2097. X         break;
  2098. X
  2099. X      case MO_LEFT:
  2100. X
  2101. X         /* first see if it is possible to move left
  2102. X            at all */
  2103. X
  2104. X         if (( m_box->x_start > 0 ) && ( how_far > 0 ))
  2105. X            {
  2106. X
  2107. #ifdef  USESMALLFONT
  2108. X   m_box->save_font = ui_grwind->font;
  2109. X   m_box->save_fysize = ui_grwind->fysize;
  2110. X   gr_font( ui_screen, F_DEFAULT, ui_grwind->ymax / SMALLFONTSIZE );
  2111. #endif
  2112. X
  2113. X            /* decrement how_far to an acceptable
  2114. X               number */
  2115. X
  2116. X            while ( ( m_box->x_start - how_far ) < 0 )
  2117. X               {
  2118. X               --how_far;
  2119. X               }
  2120. X
  2121. X            /* assign new values to m_box->x_start and
  2122. X               m_box->current */
  2123. X
  2124. X            m_box->x_start -= how_far;
  2125. X            m_box->current -= how_far;
  2126. X
  2127. X            /* display all icons visible */
  2128. X
  2129. X        uii_display( m_box );
  2130. X
  2131. X            /* display currently selected icon */
  2132. X
  2133. X        uii_icon( m_box, m_box->current,
  2134. SHAR_EOF
  2135. true || echo 'restore of io/ui/ui_icon.c failed'
  2136. fi
  2137. echo 'End of  part 8'
  2138. echo 'File io/ui/ui_icon.c is continued in part 9'
  2139. echo 9 > _shar_seq_.tmp
  2140. exit 0
  2141. exit 0 # Just in case...
  2142. -- 
  2143. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2144. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2145. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2146. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2147.