home *** CD-ROM | disk | FTP | other *** search
/ Comic Book Maker: The Smurfs / COMIC.iso / mac / data_m / dialog / 00041_directoryFieldBhvr.ls < prev    next >
Encoding:
Text File  |  1999-07-07  |  6.5 KB  |  202 lines

  1. property mySprite, maxLines, clickTimer, activeLine, vLoc, IndicatorOffset, pScrollBarHeight, moreThanMax, alphabeticIndex, active, myField, lineHite, lineMax, topOfBarOffset, scrollTopValue, indicatorSprite, upBtnSprite
  2. global gObj5
  3.  
  4. on beginSprite me
  5.   set mySprite to the currentSpriteNum
  6.   set indicatorSprite to 18
  7.   set upBtnSprite to 16
  8.   set myField to the memberNum of sprite mySprite
  9.   set maxLines to the number of lines in the pDataFileDirectoryContents of gObj5
  10.   set vLoc to the locV of sprite mySprite + ((15 + the height of the member of sprite 10 + 10) * active)
  11.   set bugFix to the left of sprite mySprite
  12.   set topOfBarOffset to the height of the member of sprite upBtnSprite
  13.   set pScrollBarHeight to the height of sprite mySprite - (topOfBarOffset * 2) - the height of the member of sprite indicatorSprite + 2
  14.   set lineHite to the textHeight of member myField
  15.   set lineMax to the height of sprite mySprite / lineHite
  16.   if maxLines > lineMax then
  17.     set moreThanMax to 1
  18.     set IndicatorOffset to pScrollBarHeight * 1.0 / (maxLines - lineMax)
  19.   else
  20.     if maxLines = 1 then
  21.       if the pDataFileDirectoryContents of gObj5 = EMPTY then
  22.         set maxLines to 0
  23.       else
  24.         set moreThanMax to 0
  25.       end if
  26.     else
  27.       set moreThanMax to 0
  28.     end if
  29.   end if
  30.   if maxLines then
  31.     set alphabeticIndex to []
  32.     repeat with i = 1 to maxLines
  33.       add(alphabeticIndex, symbol(char 1 of line i of the pDataFileDirectoryContents of gObj5))
  34.     end repeat
  35.     sort(alphabeticIndex)
  36.   end if
  37.   set clickTimer to the ticks
  38. end
  39.  
  40. on updateIndicator me, nosound
  41.   if not moreThanMax then
  42.     set newLoc to 9000
  43.   else
  44.     set newLoc to vLoc + topOfBarOffset + integer(scrollTopValue / lineHite * IndicatorOffset)
  45.     if not (the locV of sprite indicatorSprite = newLoc) and not nosound then
  46.       puppetSound(1, "clickSnd")
  47.     end if
  48.   end if
  49.   set the locV of sprite indicatorSprite to newLoc
  50.   set the locV of sprite (indicatorSprite + 1) to newLoc
  51. end
  52.  
  53. on updateHilite me
  54.   set newHiliteLoc to ((activeLine - 1) * lineHite) + vLoc + 2 - scrollTopValue
  55.   if not ((newHiliteLoc > vLoc) and (newHiliteLoc < (vLoc + (lineHite * lineMax)))) then
  56.     set newHiliteLoc to 9000
  57.   end if
  58.   set the locV of sprite (mySprite + 1) to newHiliteLoc
  59.   set the locV of sprite (mySprite + 3) to newHiliteLoc
  60. end
  61.  
  62. on scrollField me, fromWhichSprite, direction
  63.   set scrollTopValue to max(0, min(scrollTopValue + (lineHite * direction), (maxLines - lineMax) * lineHite))
  64.   set the scrollTop of member myField to scrollTopValue
  65.   if active then
  66.     updateHilite()
  67.   end if
  68.   updateIndicator()
  69.   updateStage()
  70. end
  71.  
  72. on mouseDown me
  73.   if not maxLines or not active then
  74.     exit
  75.   end if
  76.   set whichLine to ((the locV of the clickLoc - 2 - vLoc + (lineHite * 10)) / lineHite) - 10
  77.   set activeLine to whichLine + 1 + (scrollTopValue / lineHite)
  78.   moveHilite(me, 0)
  79.   if (activeLine = (whichLine + 1 + (scrollTopValue / lineHite))) and (clickTimer > the ticks) then
  80.     set defaultSprite to the defaultBtn of script "DialogScripts"
  81.     terminateDialog(script "DialogScripts", the myAction of sprite(defaultSprite), the myObj of sprite(defaultSprite), the myParams of sprite(defaultSprite))
  82.     exit
  83.   else
  84.     set clickTimer to the ticks + 17
  85.   end if
  86.   set lastLine to whichLine
  87.   repeat while the mouseDown
  88.     set mouseV to the mouseV - 2
  89.     set whichLine to ((mouseV - vLoc + (lineHite * 10)) / lineHite) - 10
  90.     if (mouseV < vLoc) or (mouseV > (vLoc + ((lineHite * 10) - 1))) then
  91.       set offLimits to 1
  92.     else
  93.       set offLimits to 0
  94.     end if
  95.     if not (whichLine = lastLine) or offLimits then
  96.       set activeLine to whichLine + 1 + (scrollTopValue / lineHite)
  97.       moveHilite(me, 0)
  98.       set lastLine to whichLine
  99.       if offLimits then
  100.         Del(2)
  101.       end if
  102.     end if
  103.   end repeat
  104.   set the myParams of sprite(4) to activeLine
  105. end
  106.  
  107. on dragIndicator me, theSprite
  108.   set offset to the locV of the clickLoc - the locV of sprite theSprite
  109.   set oldLoc to the locV of the clickLoc
  110.   repeat while the mouseDown
  111.     set newLoc to min(vLoc + pScrollBarHeight + topOfBarOffset, max(vLoc + topOfBarOffset, the mouseV - offset))
  112.     if not (newLoc = oldLoc) then
  113.       set newScrollTopValue to integer((newLoc - vLoc - topOfBarOffset) / IndicatorOffset) * lineHite
  114.       if not (newScrollTopValue = scrollTopValue) then
  115.         set scrollTopValue to newScrollTopValue
  116.         set the scrollTop of member myField to scrollTopValue
  117.         if active then
  118.           updateHilite()
  119.         end if
  120.         puppetSound(1, "clickSnd")
  121.       end if
  122.       set the locV of sprite theSprite to newLoc
  123.       set the locV of sprite (theSprite + 1) to newLoc
  124.       updateStage()
  125.       set oldLoc to newLoc
  126.     end if
  127.   end repeat
  128.   updateIndicator(me, 1)
  129.   updateStage()
  130. end
  131.  
  132. on moveHilite me, direction
  133.   set activeLine to max(1, min(maxLines, activeLine + direction))
  134.   set the myParams of sprite(4) to activeLine
  135.   set scrollMin to scrollTopValue / lineHite
  136.   set diff to activeLine - scrollMin
  137.   if diff > lineMax then
  138.     set scrollTopValue to (scrollMin + diff - lineMax) * lineHite
  139.   else
  140.     if diff < 1 then
  141.       set scrollTopValue to (scrollMin + diff - 1) * lineHite
  142.     end if
  143.   end if
  144.   set the scrollTop of member myField to scrollTopValue
  145.   updateHilite()
  146.   updateIndicator()
  147.   updateStage()
  148. end
  149.  
  150. on processKey me, theKey
  151.   if theKey = "" then
  152.     if not maxLines then
  153.       exit
  154.     end if
  155.     moveHilite(me, -1)
  156.   else
  157.     if theKey = "" then
  158.       if not maxLines then
  159.         exit
  160.       end if
  161.       moveHilite(me, 1)
  162.     else
  163.       if theKey = " " then
  164.         scrollPage(me, 1)
  165.       else
  166.         if theKey = " " then
  167.           scrollPage(me, -1)
  168.         else
  169.           if theKey = "" then
  170.             scrollPage(me, -1000)
  171.           else
  172.             if theKey = "" then
  173.               scrollPage(me, 1000)
  174.             else
  175.               if (theKey = RETURN) or (theKey = ENTER) then
  176.                 handleDefaultKeyDown(script 1)
  177.               else
  178.                 set activeLine to findPosNear(alphabeticIndex, symbol(theKey))
  179.                 moveHilite(me, 0)
  180.               end if
  181.             end if
  182.           end if
  183.         end if
  184.       end if
  185.     end if
  186.   end if
  187. end
  188.  
  189. on scrollPage me, direction
  190.   set scrollTopValue to max(0, min(the scrollTop of member myField + (lineHite * (direction * (lineMax - 1))), (maxLines - lineMax) * lineHite))
  191.   set the scrollTop of member myField to scrollTopValue
  192.   if active then
  193.     updateHilite()
  194.   end if
  195.   updateIndicator()
  196.   updateStage()
  197. end
  198.  
  199. on getPropertyDescriptionList
  200.   return [#active: [#comment: "Active:", #format: #boolean, #default: 1]]
  201. end
  202.