home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 8 / boot-disc-1997-04.iso / Media / Demos.dxr / 00056_Field_56.txt < prev    next >
Text File  |  1997-02-10  |  15KB  |  343 lines

  1.  
  2. --on startmovie
  3. --  global gScroller, gscroller2, gscroller3
  4. --  set gScroller to birth(script "scrollParent", 3, 2, 1, 4, 20, 12, 14)
  5. --  set gScroller2 to birth(script "scrollParent", 11, 9, 8, 10, 19, 12, 18)
  6. --  set gScroller3 to birth(script "scrollParent", 14, 16, 15, 17, 18, 12, 9)
  7. --  set the actorlist = [gScroller3, gScroller2, gScroller]
  8. --end
  9. --
  10. --Parameters..........
  11. --TopArrowSprite, BottomArrowSprite, BarSprite, SliderBoxSprite, TextField, textSource, PageStep
  12. --
  13. ---------------------------------------------------------------------
  14. --on stopMovie
  15. --  put " " into field 18
  16. --  put " " into field 19
  17. --  put " " into field 20
  18. --end 
  19.  
  20.  
  21.  
  22. --SCROLL BAR PARENT SCRIPT -- ACTORLIST VERSION .............
  23. --┬⌐ Yair Sageev, 1995 ... not really a copyrite--it just means I wrote it.  };->
  24. --My custom scrollbar attempts to mimic that standard Macintosh scrollbar
  25. --in every way, except that it doesn't have a ghost rect on the draggable
  26. --box.  Rather, it (more-or-less) scrolls in real time with the drag (a-la X-Windows).
  27. --
  28. --This version utilizes the
  29. --actorlist to handle stage updates.  Thus, it allows other processes
  30. --to execute.  However, I have a (barely) faster version that 
  31. --utilizes repeat loops, but does not allow anything else to happen
  32. --while scrolling.  Anyways, the speed of scrolling is dependent up
  33. --the tempo of your movie and the amount of other stuff going on.  
  34. --For maximum thrills, run the script at a tempo of 120 fps on a 
  35. --power mac.
  36. -- 
  37. --remember to put all  instances in the actorlist.
  38. --
  39. --Attach dummy mouseup scripts to the respective 
  40. --sprites or cast members.  Otherwise, everything is taken care of 
  41. --for you here.  Just put a fixed text field on stage, position 
  42. --four pieces of artwork accordingly, and pass their sprite numbers
  43. --in the birth statement.
  44. --
  45. --Unfortunately, Director defines a line to be a chunk of text 
  46. --delimited by a carriage return, so the scrollbar requires that 
  47. --each line (as we think of it) finish with a return  -- Yair
  48. ---------------------------------------------------------------------
  49. ---------------------------------------------------------------------
  50. property    pTopLine, pBottomLine, pLineCount, pPageStep, pUpFlag
  51. property    pHalfHeight, pBarHeight, pLineStep, pCounter, pScrollJump, pTopPosition
  52. property    pBottomPosition, pDownArrowTop, pTopArrowBot, gRightBoundary, pBarFlag
  53. property    pLeftBoundary, pShortFlag, pTextField, pTextSource, pHandlerList, 
  54. property    pTopArrowSprite, pBottomArrowSprite, pBarSprite, pSliderBoxSprite
  55. property    pCounterStore, pReallyOldLocV, pStillDownFlag, pStepFrameDownFlag,
  56. property     pRestoreFlag, pSlideFlag, pSpritePropList,  pRepeatNum, pMouseDiff 
  57.  
  58. global gVeryLongRepeatFlag --speeds responsiveness (barely) if you have multiple scrollBars on stage
  59. ------------------- at the same time.  If you only have one, you may make this a property.
  60.  
  61. --I decided to factor out the the constant sprite positions and 
  62. --pixel distances (e.g. "the locV of sprite x", pHalfHeight) into 
  63. --properties,  because I figured it would be faster to simply 
  64. --reference a variable each time than to get sprite info constantly.
  65. --In addition, because the object depends on the stepframe, local variables 
  66. --don't maintain their values over repeated executions.  So they needed to 
  67. --be turned into (static) property variables as well.
  68. --All this accounts for the rather large 
  69. --number of property variables.  If you need the scroll bar to 
  70. --update to different sizes or to correspond to different text 
  71. --sources throughout the movie, then the 
  72. --strategy is to call the birthed object's "init" method when an
  73. --update is needed. 
  74. ---------------------------------------------------------------------
  75. --PARAMETERS:
  76. --topArrowSprite = the sprite associated with the top arrow
  77. --BottomArrowSprite = the sprite associated with the bottom arrow
  78. --BarSprite = the sprite associated with the bar
  79. --SliderBoxSprite = the sprite associated with the draggable box
  80. --TextField = the field on stage which recieves text chunks
  81. --TextSource = the source field of text
  82. --pageStep = the number of lines that are visible at any one time in the field
  83. --
  84. --If you don't know how to birth objects, simply add the following line of code to your movie:
  85. --on makeScrollBar
  86. --  global gscroller
  87. --  set gscroller = birth(script "scrollParent", [parameters])
  88. --  add (the actorlist, gScroller)
  89. --end makeScrollBar
  90.  
  91. on birth me, TopArrowSprite, BottomArrowSprite, BarSprite, SliderBoxSprite, TextField, textSource, pagestep
  92.   set pTopArrowSprite = TopArrowSprite
  93.   set pBottomArrowSprite = BottomArrowSprite
  94.   set pBarSprite = BarSprite
  95.   set pSliderBoxSprite = SliderBoxSprite
  96.   set pTextField = TextField
  97.   put field textSource into pTextSource
  98.   set pPageStep = pagestep
  99.   set pHandlerList = ["DownButtonMouseDown me", "TopButtonMouseDown me", "BarMouseDown me", "SliderMouseDown me"]
  100.   set pSpritePropList = [ pBottomArrowSprite, pTopArrowSprite, pBarSprite, pSliderBoxSprite]
  101.   repeat with x in pSpritePropList
  102.     puppetSprite (x), TRUE
  103.   end repeat
  104.   init me
  105.   return me  
  106. end birth
  107. ---------------------------------------------------------------------
  108. on init me
  109.   put the number of lines of pTextSource into pLineCount
  110.   set pTopLine = 1
  111.   set pBottomLine = pPageStep
  112.   put line pTopLine to pBottomLine of pTextSource into field pTextField
  113.   if pLineCount <= pPageStep then
  114.     set pShortFlag = TRUE
  115.     --What follows is merely a default.  You can do whatever you want right
  116.     --here (switch castmembers, do the hokey pokey......).
  117.     --BEGIN DEFAULT
  118.     set the ink of sprite pBarSprite = 38
  119.     set the blend of sprite pBottomArrowSprite = 39
  120.     set the blend of sprite pTopArrowSprite = 39
  121.     set the ink of sprite pSliderBoxSprite = 39
  122.     --END DEFAULT
  123.   else
  124.     set pStepFrameDownFlag = FALSE
  125.     set pShortFlag =  FALSE
  126.     set pSlideFlag = FALSE
  127.     set pBarFlag = FALSE
  128.     set pRestoreFlag = TRUE
  129.     set pStillDownFlag = TRUE
  130.     set gVeryLongRepeatFlag = FALSE
  131.     set pReallyOldLocV = 0
  132.     set pTopArrowBot = the bottom of sprite pTopArrowSprite
  133.     set pDownArrowTop = the top of sprite pBottomArrowSprite
  134.     set pLeftBoundary = (the locH of sprite pSliderBoxSprite) + 36
  135.     set gRightBoundary = (the locH of sprite pSliderBoxSprite) - 36
  136.     set pBarHeight = float(pDownArrowTop - pTopArrowBot - the height of sprite pSliderBoxSprite)
  137.     set pHalfHeight = (the bottom of sprite pSliderBoxSprite - the top of sprite pSliderBoxSprite)/2
  138.     set pTopPosition = pTopArrowBot + pHalfHeight 
  139.     set the locV of sprite pSliderBoxSprite to pTopPosition
  140.     set pCounter = float(the locV of sprite pSliderBoxSprite)
  141.     
  142.     set pCounterStore = pCounter
  143.     set pBottomPosition = pDownArrowTop - pHalfHeight
  144.     set pLineStep = float(pBarHeight)/(float(pLineCount) - float(pPageStep))
  145.     set pScrollJump = float(pBarHeight)/((float(pLineCount) - float(pPageStep))/float(pPageStep))
  146.   end if
  147. end init
  148. ---------------------------------------------------------------------
  149. on stepFrame me
  150.   if pshortFlag = FALSE then
  151.     if the stilldown then
  152.       set pStillDownFlag = FALSE
  153.       if gVeryLongRepeatFlag = FALSE then
  154.         repeat with pRepeatNum = 1 to 4
  155.           if getaprop(pSpritePropList, pRepeatNum) = the clickon then
  156.             set pStepFrameDownFlag = TRUE
  157.             set gVeryLongRepeatFlag = TRUE
  158.             exit repeat
  159.           end if
  160.         end repeat
  161.       end if
  162.       if pStepFrameDownFlag then
  163.         do getaprop(pHandlerList, pRepeatNum)
  164.       end if
  165.     else if pStillDownFlag = FALSE then
  166.       set pStillDownFlag = TRUE
  167.       if gVeryLongRepeatFlag = TRUE then
  168.         set the ink of sprite (the clickon) = 0
  169.         set gVeryLongRepeatFlag = FALSE
  170.       end if
  171.       set pStepFrameDownFlag = FALSE
  172.       set pSlideFlag = FALSE
  173.       set pBarFlag = FALSE
  174.       if pRestoreFlag = FALSE then
  175.         restoreMySlider
  176.       end if
  177.     end if
  178.   end if
  179. end stepframe 
  180. ---------------------------------------------------------------------
  181. on restoreMySlider me
  182.   set pCounter = pCounterStore
  183.   set temp = (the locV of sprite pSliderBoxSprite - pReallyOldLocV)
  184.   set proportion = abs((the locV of sprite pSliderBoxSprite - pReallyOldLocV)/pBarHeight)
  185.   set scrollAmount = (pLineCount - pPageStep) * proportion
  186.   set the locV of sprite pSliderBoxSprite = pReallyOldLocV
  187.   set pRestoreFlag = TRUE
  188.   if temp < 0 then
  189.     scroll me, "down", scrollAmount
  190.   else if temp > 0 then
  191.     scroll me, "up", scrollAmount
  192.   end if
  193.   set the ink of sprite pSliderBoxSprite to 0
  194. end restoreMySlider
  195. ---------------------------------------------------------------------
  196. on BarMouseDown me
  197.   if pShortFlag = FALSE then
  198.     if pBarFlag = FALSE then
  199.       if the mouseV < (the top of sprite pSliderBoxSprite) then
  200.         set pUpFlag = TRUE
  201.       else if the mouseV > (the bottom of sprite pSliderBoxSprite) then
  202.         set pUpFlag = FALSE
  203.       end if
  204.       set pBarFlag = TRUE
  205.     end if
  206.     
  207.     if rollover (pBarSprite) then
  208.       if (pUpFlag AND (the mouseV < pcounter - phalfheight)) then
  209.         if ((pcounter - phalfheight - pScrollJump) < pTopArrowBot) then
  210.           set the locV of sprite pSliderBoxSprite = pTopPosition
  211.           set pCounter = pTopPosition
  212.           scroll me, "up", pPageStep
  213.         else 
  214.           set pCounter = pCounter - pScrollJump
  215.           set the locV of sprite pSliderBoxSprite = pCounter
  216.           scroll me, "up", pPageStep
  217.         end if
  218.       else if ((pUpFlag = FALSE) AND (the mouseV > pcounter + phalfheight)) then
  219.         if ((pcounter + phalfheight + pScrollJump) > pDownArrowTop) then
  220.           set the locV of sprite pSliderBoxSprite = pBottomPosition
  221.           set pCounter = pBottomPosition
  222.           scroll me, "down", pPageStep
  223.         else 
  224.           set pCounter = pCounter + pScrollJump
  225.           set the locv of sprite pSliderBoxSprite = pCounter
  226.           scroll me, "down", pPageStep
  227.         end if
  228.       end if
  229.     end if
  230.   end if
  231. end BarMouseDown
  232. ---------------------------------------------------------------------
  233. on DownButtonMouseDown me
  234.   if pShortFlag = FALSE then
  235.     if rollover (pBottomArrowSprite) then
  236.       set the ink of sprite pBottomArrowSprite to 36
  237.       if pBottomLine <> pLineCount then
  238.         if pDownArrowTop - (the bottom of sprite pSliderBoxSprite) > pLineStep then
  239.           set pCounter = pCounter + pLineStep
  240.           set the locV of Sprite pSliderBoxSprite = pCounter
  241.           scroll me, "down", 1
  242.         else 
  243.           scroll me, "down", 1
  244.         end if
  245.       else
  246.         set the locv of sprite pSliderBoxSprite = pBottomPosition
  247.         set pCounter = pBottomPosition
  248.       end if
  249.     else 
  250.       set the ink of sprite pBottomArrowSprite to 0
  251.     end if
  252.   end if
  253. end DownButtonMouseDown
  254. ---------------------------------------------------------------------
  255. on TopButtonMouseDown me
  256.   if pShortFlag = FALSE then
  257.     if rollover (pTopArrowSprite) then
  258.       set the ink of sprite pTopArrowSprite to 36
  259.       if pTopLine <> 1 then
  260.         if (the top of sprite pSliderBoxSprite) - pTopArrowBot > pLineStep then
  261.           set pCounter = pCounter - pLineStep
  262.           set the locV of Sprite pSliderBoxSprite = pCounter
  263.           scroll me, "up", 1
  264.         else
  265.           scroll me, "up", 1
  266.         end if
  267.       else
  268.         set the locv of sprite pSliderBoxSprite = pTopPosition
  269.         set pCounter = pTopPosition
  270.       end if
  271.     else
  272.       set the ink of sprite pTopArrowSprite to 0
  273.     end if
  274.   end if
  275. end TopButtonMouseDown
  276. ---------------------------------------------------------------------
  277. on SliderMouseDown me
  278.   if pShortFlag = FALSE then
  279.     if (pSlideFlag = FALSE) then 
  280.       set pMouseDiff = (the mouseV - the locv of sprite pSliderBoxSprite)
  281.       set pReallyOldLocV = the locV of sprite pSliderBoxSprite
  282.       put pCounter into PCounterStore
  283.       set pSlideFlag = TRUE
  284.     end if
  285.     if (the mouseH > gRightBoundary)  AND (the MouseH < pLeftBoundary) then
  286.       set pRestoreFlag = TRUE
  287.       set the ink of sprite pSliderBoxSprite to 0
  288.       set oldLocV = the locV of sprite pSliderBoxSprite
  289.       if (the mouseV - pMouseDiff + pHalfHeight) > pDownArrowTop then
  290.         set the locv of sprite pSliderBoxSprite = pBottomPosition
  291.         set pCounter = pBottomPosition
  292.         set pBottomLine = pLineCount
  293.         scroll me, "down", 1
  294.       else if (the mouseV - pMouseDiff - pHalfHeight) < pTopArrowBot then
  295.         set the locv of sprite pSliderBoxSprite = pTopPosition
  296.         set pCounter = pTopPosition
  297.         set pTopLine = 1
  298.         scroll me, "up", 1
  299.       else
  300.         set the locv of sprite pSliderBoxSprite = the mouseV - pMouseDiff
  301.         set temp = the locV of sprite pSliderBoxSprite - oldLocV
  302.         set proportion = abs((the locV of sprite pSliderBoxSprite - oldLocV)/pBarHeight)
  303.         set scrollAmount = (pLineCount - pPageStep) * proportion
  304.         set pCounter = pCounter + temp
  305.         if temp > 0 then
  306.           scroll me, "down", scrollAmount
  307.         else if temp < 0 then
  308.           scroll me, "up", scrollAmount
  309.         end if
  310.       end if
  311.     else 
  312.       set pRestoreFlag = FALSE
  313.       --BEGIN DEFAULT
  314.       set the ink of sprite pSliderBoxSprite to 39
  315.       --END DEFAULT
  316.     end if
  317.   end if
  318. end SliderBoxMouseDown
  319. ---------------------------------------------------------------------
  320. on scroll me, UpOrDown, howMuch
  321.   if UpOrDown = "Down" then
  322.     if pBottomLine + howMuch <= pLineCount then
  323.       set pBottomLine = pBottomLine + howMuch
  324.       set pTopLine = pTopLine + howMuch
  325.       put line pTopLine to pBottomLine of pTextSource into field pTextField
  326.     else
  327.       set pBottomLine = pLineCount
  328.       set pTopLine = pBottomLine - pPageStep
  329.       put line pTopLine to pBottomLine of pTextSource into field pTextField
  330.     end if
  331.   else if UpOrDown = "Up" then
  332.     if pTopLine - howMuch > 0 then
  333.       set pTopLine = pTopLine -  howMuch
  334.       set pBottomLine = pBottomLine - howMuch
  335.       put line pTopLine to pBottomLine of pTextSource into field pTextField
  336.     else
  337.       set pTopLine = 1
  338.       set pBottomLine = pPageStep
  339.       put line pTopLine to pBottomLine of pTextSource into field pTextField
  340.     end if
  341.   end if
  342. end scroll
  343. ---------------------------------------------------------------------