home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / stv_427.lzh / STV / source / display.c next >
C/C++ Source or Header  |  1991-01-09  |  6KB  |  274 lines

  1. /*********************************
  2. *  DISPLAY  09/29/90
  3. *  Source file for STV
  4. *  © Copyright 1990 Timm Martin
  5. *  All Rights Reserved Worldwide
  6. **********************************/
  7.  
  8. #include <exec/types.h>
  9. #include <functions.h>
  10. #include <intuition/intuition.h>
  11. #include "func.h"
  12. #include "main.h"
  13.  
  14. /************************
  15. *  STATISTICS STRUCTURE
  16. *************************/
  17.  
  18. struct Statistics stats;  /* GLOBAL */
  19. /*
  20.   Where is everything initialized?
  21.  
  22.   Top .......... initialize()
  23.   PrevTop ...... initialize()
  24.   Rows ......... window_resized()
  25.   Cols ......... window_resized()
  26.   LeftEdge ..... window_resized()
  27.   RightEdge .... window_resized()
  28.   TopEdge ...... window_resized()
  29.   BottomEdge ... window_resized()
  30.   VCenter ...... window_resized()
  31.   Font ......... window_open()
  32.   TextWidth .... window_open()
  33.   TextHeight ... window_open()
  34.   Baseline ..... window_open()
  35.   VPropPot ..... initialize()
  36.   VPropBody .... initialize()
  37.   Scrolling .... initialize()
  38.   Propping ..... initialize()
  39. */
  40.  
  41. /************
  42. *  END DOWN
  43. *************/
  44.  
  45. /*
  46. This procedure displays the last line of the file (if it isn't already
  47. displayed) in the bottom of the window.
  48. */
  49.  
  50. void end_down( void )
  51. {
  52.   int max = current_file.Lines - stats.Rows;
  53.  
  54.   /* if the last line isn't already displayed */
  55.   if (stats.Top < max)
  56.   {
  57.     /* set the top line so the last line will be at the bottom of the window */
  58.     stats.Top = max;
  59.     text_display();
  60.     modify_vprop();
  61.   }
  62. }
  63.  
  64. /**********
  65. *  END UP
  66. ***********/
  67.  
  68. /*
  69. This procedure displays the first line of the file (if it isn't already
  70. displayed).
  71. */
  72.  
  73. void end_up( void )
  74. {
  75.   /* if not already at the top of the file */
  76.   if (stats.Top)
  77.   {
  78.     stats.Top = 0;
  79.     text_display();
  80.     modify_vprop();
  81.   }
  82. }
  83.  
  84. /**************
  85. *  INITIALIZE
  86. ***************/
  87.  
  88. /*
  89. This procedure initializes the Statistics structure after each file is loaded.
  90. */
  91.  
  92. void initialize( void )
  93. {
  94.   stats.Top       =
  95.   stats.PrevTop   =
  96.   stats.VPropPot  =
  97.   stats.Scrolling =
  98.   stats.Propping  = 0;
  99.   stats.VPropBody = current_file.Lines > stats.Rows ?
  100.                     ((long)stats.Rows * MAXBODY) / current_file.Lines : MAXBODY;
  101.   modify_vprop();
  102. }
  103.  
  104. /**************
  105. *  LINE CHECK
  106. ***************/
  107.  
  108. /*
  109. This procedure makes sure the Top value is correct.
  110. */
  111.  
  112. void line_check( void )
  113. {
  114.   int diff;
  115.  
  116.   if ((diff = stats.Top - current_file.Lines + stats.Rows) > 0)
  117.     if ((stats.Top -= diff) < 0)
  118.       stats.Top = 0;
  119. }
  120.  
  121. /*************
  122. *  LINE DOWN
  123. **************/
  124.  
  125. /*
  126. This procedure displays the next line of text (unless the final line of
  127. text is currently displayed).
  128. */
  129.  
  130. void line_down( BOOL modify )
  131.   /* modify ... whether to modify prop gadget */
  132. {
  133.   if (stats.Top + stats.Rows < current_file.Lines)
  134.   {
  135.     stats.Top++;
  136.     ScrollRaster( rp, 0L, (long)stats.TextHeight,
  137.                   (long)stats.LeftEdge, (long)stats.TopEdge,
  138.                   (long)stats.RightEdge, (long)stats.BottomEdge );
  139.     text_line( stats.Rows-1 );
  140.     if (modify) modify_vprop();
  141.   }
  142. }
  143.  
  144. /***********
  145. *  LINE UP
  146. ************/
  147.  
  148. /*
  149. This procedure displays the previous line of text (unless the first line of
  150. text is currently displayed).
  151. */
  152.  
  153. void line_up( BOOL modify )
  154.   /* modify ... whether to modify prop gadget */
  155. {
  156.   if (stats.Top > 0)
  157.   {
  158.     stats.Top--;
  159.     ScrollRaster( rp, 0L, -(long)stats.TextHeight,
  160.                   (long)stats.LeftEdge, (long)stats.TopEdge,
  161.                   (long)stats.RightEdge, (long)stats.BottomEdge );
  162.     text_line( 0 );
  163.     if (modify) modify_vprop();
  164.   }
  165. }
  166.  
  167. /*************
  168. *  PAGE DOWN
  169. **************/
  170.  
  171. /*
  172. This procedure displays the next page of text.
  173. */
  174.  
  175. void page_down( void )
  176. {
  177.   int max = current_file.Lines - stats.Rows;
  178.  
  179.   /* if not already at the bottom of the display */
  180.   if (stats.Top < max)
  181.   {
  182.     /* move down one page */
  183.     stats.Top += stats.Rows;
  184.     /* if moved past bottom, set to bottom of display */
  185.     if (stats.Top > max)
  186.       stats.Top = max;
  187.     text_display();
  188.     modify_vprop();
  189.   }
  190. }
  191.  
  192. /***********
  193. *  PAGE UP
  194. ************/
  195.  
  196. /*
  197. This procedure displays the previous page of text.
  198. */
  199.  
  200. void page_up( void )
  201. {
  202.   /* if not already at the top of the file */
  203.   if (stats.Top)
  204.   {
  205.     /* move up one page */
  206.     stats.Top -= stats.Rows;
  207.     if (stats.Top < 0)
  208.       stats.Top = 0;
  209.     text_display();
  210.     modify_vprop();
  211.   }
  212. }
  213.  
  214. /*******************
  215. *  REFRESH DISPLAY
  216. ********************/
  217.  
  218. /*
  219. This procedure checks to make sure all of the window values are correct,
  220. redisplays the current file, and modifies the prop gadget.
  221. */
  222.  
  223. void refresh_display( void )
  224. {
  225.   BeginRefresh( win );
  226.   EndRefresh( win, TRUE );
  227.  
  228.   window_resized();
  229.   SetAPen( rp, BLUE );
  230.   RectFill( rp, (long)win->BorderLeft, (long)win->BorderTop,
  231.                 (long)(win->Width - win->BorderRight),
  232.                 (long)(win->Height - win->BorderBottom) );
  233.   text_display();
  234.   modify_vprop();
  235. }
  236.  
  237. /******************
  238. *  SCROLL DISPLAY
  239. *******************/
  240.  
  241. /*
  242. This procedure scrolls the display based on the current mouse position.
  243. Placing the pointer all the way at or below the bottom of the window will
  244. cause the display to jump to the end of the file.  Placing the pointer at or
  245. above the top of the window will cause the display to jump to the beginning
  246. of the file.  Otherwise, the display will scroll either up or down based on
  247. the vertical position of the mouse, and a delay will be added if the mouse is
  248. close to the center.
  249. */
  250.  
  251. /* how far from center slow-down in scrolling begins */
  252. #define SCROLL_VERT 32
  253.  
  254. void scroll_display( void )
  255. {
  256.   long wait;  /* how long to delay scroll */
  257.  
  258.   if (win->MouseY <= 0)
  259.     page_up();
  260.   else if (win->MouseY >= win->Height - 1)
  261.     page_down();
  262.  
  263.   wait = win->MouseY - stats.VCenter;
  264.   if (wait > 0)
  265.     line_down( YES );
  266.   else if (wait < 0)
  267.   {
  268.     line_up( YES );
  269.     wait = -wait;
  270.   }
  271.   if (wait < SCROLL_VERT)
  272.     Delay( SCROLL_VERT - wait );
  273. }
  274.