home *** CD-ROM | disk | FTP | other *** search
/ Better Homes & Gardens: …oking for Today - Chicken / Image.iso / pc / shared.dxr / 01013_Scrollbar.ls < prev    next >
Encoding:
Text File  |  1995-11-21  |  5.9 KB  |  209 lines

  1. property minButton, maxButton, thumbButton, trackButton, thumbSprite, trackSprite, scrollSprite, scrollSpriteLoc, scrollField, scrollFieldOut, ratio, startLine, scrollHeight, scrollMin, scrollMax, handler, scrollLinks, scrollLinkLocs
  2.  
  3. on birth me, argList
  4.   return me
  5. end
  6.  
  7. on init me
  8.   set ratio to 0.0
  9.   set the group of the minButton of me to me
  10.   set the group of the maxButton of me to me
  11.   set the group of the thumbButton of me to me
  12.   set the group of the trackButton of me to me
  13.   set thumbSprite to the spriteChan of the thumbButton of me
  14.   set trackSprite to the spriteChan of the trackButton of me
  15.   set topOffset to the locV of sprite thumbSprite - the top of sprite thumbSprite
  16.   set bottomOffset to the bottom of sprite thumbSprite - the locV of sprite thumbSprite
  17.   set scrollMin to the top of the rect of sprite trackSprite + topOffset
  18.   set scrollMax to the bottom of the rect of sprite trackSprite - bottomOffset
  19.   set scrollHeight to scrollMax - scrollMin + 1
  20.   if integerp(scrollSprite) then
  21.     puppetSprite(scrollSprite, 1)
  22.     set the scrollSpriteLoc of me to the locV of sprite scrollSprite
  23.     if listp(scrollLinks) then
  24.       set scrollLinkLocs to [:]
  25.       repeat with aSprite in scrollLinks
  26.         puppetSprite(aSprite, 1)
  27.         addProp(scrollLinkLocs, aSprite, the locV of sprite aSprite)
  28.       end repeat
  29.     end if
  30.   end if
  31. end
  32.  
  33. on click me, clickedbutton
  34.   if clickedbutton = the minButton of me then
  35.     trackEndButton(me, clickedbutton)
  36.   else
  37.     if clickedbutton = the maxButton of me then
  38.       trackEndButton(me, clickedbutton)
  39.     else
  40.       if clickedbutton = the thumbButton of me then
  41.         trackThumb(me)
  42.       else
  43.         if clickedbutton = the trackButton of me then
  44.           trackTrack(me)
  45.         end if
  46.       end if
  47.     end if
  48.   end if
  49.   if stringp(handler) then
  50.     do(handler && ratio)
  51.   end if
  52. end
  53.  
  54. on trackThumb me
  55.   press(the thumbButton of me)
  56.   repeat while the mouseDown
  57.     set the locV of sprite thumbSprite to max(scrollMin, min(the mouseV, scrollMax))
  58.     if the locV of sprite thumbSprite = scrollMax then
  59.       set ratio to 1.0
  60.     else
  61.       set ratio to float(the locV of sprite thumbSprite - scrollMin) / scrollHeight
  62.     end if
  63.     scroll(me)
  64.     updateStage()
  65.   end repeat
  66.   release(the thumbButton of me)
  67. end
  68.  
  69. on trackEndButton me, clickedbutton
  70.   if stringp(scrollField) then
  71.     set disp to the textHeight of field scrollField
  72.   else
  73.     set disp to 14
  74.   end if
  75.   if clickedbutton = the maxButton of me then
  76.     set disp to -disp
  77.   end if
  78.   press(clickedbutton)
  79.   set doOnce to 1
  80.   repeat while the mouseDown or doOnce
  81.     shift(me, disp)
  82.     if doOnce = 1 then
  83.       set t to the ticks
  84.       repeat while the ticks < (t + 8)
  85.         nothing()
  86.       end repeat
  87.       set doOnce to 0
  88.     end if
  89.   end repeat
  90.   release(clickedbutton)
  91. end
  92.  
  93. on trackTrack me
  94.   if stringp(scrollField) then
  95.     set disp to the height of sprite scrollFieldOut
  96.   else
  97.     set disp to scrollHeight
  98.   end if
  99.   if the mouseV > the locV of sprite thumbSprite then
  100.     set disp to -disp
  101.   end if
  102.   press(the trackButton of me)
  103.   set doOnce to 1
  104.   repeat while the mouseDown or doOnce
  105.     if (disp < 0) and (the locV of sprite thumbSprite > the mouseV) then
  106.       trackThumb(me)
  107.     else
  108.       if (disp > 0) and (the locV of sprite thumbSprite < the mouseV) then
  109.         trackThumb(me)
  110.       else
  111.         shift(me, disp)
  112.       end if
  113.     end if
  114.     if doOnce = 1 then
  115.       set t to the ticks
  116.       repeat while the ticks < (t + 8)
  117.       end repeat
  118.       set doOnce to 0
  119.     end if
  120.   end repeat
  121.   release(the trackButton of me)
  122. end
  123.  
  124. on scroll me
  125.   if ratio > 1 then
  126.     set ratio to 1
  127.   else
  128.     if ratio < 0 then
  129.       set ratio to 0
  130.     end if
  131.   end if
  132.   if integerp(scrollSprite) then
  133.     set aHeight to the height of cast the castNum of sprite scrollSprite
  134.     set shift to (-aHeight + scrollHeight) * ratio
  135.     if shift <= 0 then
  136.       set the locV of sprite scrollSprite to scrollSpriteLoc + shift
  137.     end if
  138.     if listp(scrollLinks) then
  139.       repeat with aSprite in scrollLinks
  140.         set aLocV to getProp(scrollLinkLocs, aSprite)
  141.         if shift <= 0 then
  142.           set the locV of sprite aSprite to aLocV + shift
  143.         end if
  144.       end repeat
  145.     end if
  146.   else
  147.     if stringp(scrollField) then
  148.       set lines to the height of cast scrollField / the textHeight of field scrollField
  149.       set size to the height of sprite scrollFieldOut / the textHeight of field scrollField
  150.       set startLine to integer((lines * ratio) - (size * ratio)) + 1
  151.       set lineMax to the number of lines in field scrollField - 3
  152.       if startLine > lineMax then
  153.         set startLine to lineMax
  154.       end if
  155.       set endLine to the number of lines in field scrollField
  156.       set fieldName to the name of cast the castNum of sprite scrollFieldOut
  157.       put line startLine to endLine of field scrollField into field fieldName
  158.     end if
  159.   end if
  160.   if stringp(handler) then
  161.     do(handler && ratio)
  162.   end if
  163. end
  164.  
  165. on editScroll me
  166.   set endLine to the number of lines in field scrollField
  167.   delete line startLine to endLine of field scrollField
  168.   if startLine > 1 then
  169.     put RETURN after field scrollField
  170.   end if
  171.   set fieldName to the name of cast the castNum of sprite scrollFieldOut
  172.   put field fieldName after field scrollField
  173. end
  174.  
  175. on shift me, pixels
  176.   if stringp(scrollField) then
  177.     set offset to the height of sprite scrollFieldOut - the height of cast scrollField
  178.   else
  179.     set offset to scrollHeight - the height of cast the castNum of sprite scrollSprite
  180.   end if
  181.   if offset > 0 then
  182.     exit
  183.   end if
  184.   if offset = 0 then
  185.     set ratio to 0
  186.   else
  187.     set ratio to (pixels / float(offset)) + ratio
  188.   end if
  189.   controlPosition(me, ratio)
  190. end
  191.  
  192. on controlPosition me, newratio
  193.   set ratio to newratio
  194.   if ratio > 1 then
  195.     set ratio to 1
  196.   else
  197.     if ratio < 0 then
  198.       set ratio to 0
  199.     end if
  200.   end if
  201.   set the locV of sprite thumbSprite to scrollMin + (ratio * scrollHeight)
  202.   scroll(me)
  203.   updateStage()
  204. end
  205.  
  206. on newScrollField me, newField
  207.   set scrollField to newField
  208. end
  209.