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

  1. /*********************************
  2. *  GADGET  09/28/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. *  PROP GADGET
  16. ****************/
  17.  
  18. struct Image vprop_image;
  19.  
  20. #define VPROP_FLAGS AUTOKNOB|FREEVERT |PROPBORDERLESS
  21.  
  22. struct PropInfo vprop_info =
  23. {
  24.   /* USHORT Flags      */ VPROP_FLAGS,
  25.   /* USHORT HorizPot   */ 0,
  26.   /* USHORT VertPot    */ 0,
  27.   /* USHORT HorizBody  */ 0,
  28.   /* USHORT VertBody   */ MAXBODY,
  29.   /* USHORT CWidth     */ 0,
  30.   /* USHORT CHeight    */ 0,
  31.   /* USHORT HPotRes    */ 0,
  32.   /* USHORT VPotRes    */ 0,
  33.   /* USHORT LeftBorder */ 0,
  34.   /* USHORT TopBorder  */ 0,
  35. };
  36.  
  37. struct Gadget vprop_gadget =
  38. {
  39.   /* struct Gadget *    NextGadget    */ NULL,
  40.   /* SHORT              LeftEdge      */ LATER,
  41.   /* SHORT              TopEdge       */ LATER,
  42.   /* SHORT              Width         */ LATER,
  43.   /* SHORT              Height        */ LATER,
  44.   /* USHORT             Flags         */ GADGHCOMP | GRELHEIGHT | GRELRIGHT,
  45.   /* USHORT             Activation    */ GADGIMMEDIATE,
  46.   /* USHORT             GadgetType    */ PROPGADGET,
  47.   /* APTR               GadgetRender  */ (APTR)&vprop_image,
  48.   /* APTR               SelectRender  */ NULL,
  49.   /* struct IntuiText * GadgetText    */ NULL,
  50.   /* LONG               MutualExclude */ NULL,
  51.   /* APTR               SpecialInfo   */ (APTR)&vprop_info,
  52.   /* USHORT             GadgetID      */ 1,
  53.   /* APTR               UserData      */ NULL,
  54. };
  55.  
  56. /**************
  57. *  GADGET ADD
  58. ***************/
  59.  
  60. /*
  61. This procedure sets the prop gadget size and position, adds it to the window,
  62. and refreshes it.
  63. */
  64.  
  65. /* sizing gadget height under WB 1.x */  #define HEIGHT1  9
  66. /* sizing gadget height under WB 2.x */  #define HEIGHT2 10
  67. /* sizing gadget width under WB 1.x  */  #define WIDTH1  15
  68. /* sizing gadget width under WB 2.x  */  #define WIDTH2  17
  69. /* width of window border            */  #define WIDTH    3
  70.  
  71. void gadget_add( void )
  72. {
  73.  
  74.   if (wb2)
  75.   {
  76.     vprop_gadget.LeftEdge = -WIDTH2 + 2;
  77.     vprop_gadget.Width    = WIDTH2 - WIDTH;
  78.     vprop_gadget.TopEdge  = win->BorderTop + 1;
  79.     vprop_gadget.Height   = -vprop_gadget.TopEdge - HEIGHT2 - 1;
  80.   }
  81.   else
  82.   {
  83.     vprop_gadget.LeftEdge = -WIDTH1;
  84.     vprop_gadget.Width    = WIDTH1 - WIDTH;
  85.     vprop_gadget.TopEdge  = win->BorderTop;
  86.     vprop_gadget.Height   = -vprop_gadget.TopEdge - HEIGHT1 - 1;
  87.   }
  88.  
  89.   AddGadget( win, &vprop_gadget, -1L );
  90.   RefreshGadgets( &vprop_gadget, win, NULL );
  91. }
  92.  
  93. /******************
  94. *  GADGET CURRENT
  95. *******************/
  96.  
  97. /*
  98. This procedure handles the user moving the prop gadget.
  99. */
  100.  
  101. void gadget_current( void )
  102. {
  103.   /* determine if user is still fiddling with the gadget */
  104.   PROPPING = vprop_gadget.Flags & SELECTED;
  105.   /* adjust the display position; if still selected, check if moved */
  106.   move_vprop( PROPPING );
  107. }
  108.  
  109. /************************
  110. *  MODIFY Vertical PROP
  111. *************************/
  112.  
  113. /*
  114. This procedure sets the position of the vertical prop gadget based on the
  115. current Top value.
  116. */
  117.  
  118. void modify_vprop( void )
  119. {
  120.   stats.VPropPot = current_file.Lines == stats.Rows ? 0 :
  121.                    (stats.Top * MAXPOT) / (current_file.Lines - stats.Rows);
  122.   /* stats.VPropBody calculated only once in initialize() */
  123.   NewModifyProp( &vprop_gadget, win, NULL, VPROP_FLAGS,
  124.                  0L, stats.VPropPot, 0L, stats.VPropBody, 1L );
  125. }
  126.  
  127. /**********************
  128. *  MOVE Vertical PROP
  129. ***********************/
  130.  
  131. /*
  132. This procedure calculates the new top line based on the current position of
  133. the vertical prop gadget.  It then checks if the display should be scrolled
  134. (the change is within the predefined limit of SCROLL), completely
  135. redisplayed (the change is greater than the limit), or just left alone (there
  136. is no change).
  137. */
  138.  
  139. #define SCROLL 20
  140.  
  141. void move_vprop( BOOL check )
  142. /*
  143. check ... if should check if moved before doing anything.  This will be
  144.           YES while the gadget is active, meaning that this procedure
  145.           must check if the gadget has moved.  This will be NO when the
  146.           user lets up on the LMB.
  147. */
  148. {
  149.   int scroll;
  150.   long top;
  151.  
  152.   top = current_file.Lines > stats.Rows ?
  153.         (vprop_info.VertPot * (current_file.Lines - stats.Rows)) / MAXPOT : 0;
  154.  
  155.   if (!check ||
  156.       (scroll = stats.PrevTop - top) < -SCROLL || scroll > SCROLL)
  157.   {
  158.     stats.Top = top;
  159.     text_display();
  160.   }
  161.   else if (scroll < 0)
  162.     line_down( NO );
  163.   else if (scroll > 0)
  164.     line_up( NO );
  165.   /* else didn't change so don't move */
  166.  
  167.   /* record new top position in PrevTop for next time */
  168.   stats.PrevTop = stats.Top;
  169. }
  170.