home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 December / Dec99.iso / Data / Main.dxr / 00060_thumbObj.ls < prev    next >
Encoding:
Text File  |  1999-10-05  |  3.1 KB  |  70 lines

  1. property target, scrollBar, continuous, uparrow, dnarrow
  2. global v, t, b, H, H2, thePercent, viewingTop, viewingBottom
  3.  
  4. on getPropertyDescriptionList me
  5.   description = [:]
  6.   addProp(description, #target, [#default: 7, #format: #integer, #comment: "The picture to scroll: "])
  7.   addProp(description, #scrollBar, [#default: 8, #format: #integer, #comment: "The spriteNum of the scroll bar:"])
  8.   addProp(description, #uparrow, [#default: 2, #format: #integer, #comment: "The spriteNum of the up arrow:"])
  9.   addProp(description, #dnarrow, [#default: 3, #format: #integer, #comment: "The spriteNum of the down arrow:"])
  10.   addProp(description, #continuous, [#default: 1, #format: #boolean, #comment: "Updated on the fly:"])
  11.   return description
  12. end
  13.  
  14. on getBehaviorDescription me
  15.   return "The behavior for the bar portion of a custom scrollbar."
  16. end
  17.  
  18. on beginSprite me
  19.   set the locV of sprite the spriteNum of me to the top of sprite me.scrollBar + (member(the memberNum of sprite me.spriteNum).height / 2)
  20.   case sprite(me.scrollBar).boundsRect of
  21.     "Fixed":
  22.       viewingTop = the top of sprite sprite(me.scrollBar).uparrow
  23.       viewingBottom = the bottom of sprite sprite(me.scrollBar).dnarrow
  24.     "Stage":
  25.       viewingTop = 0
  26.       viewingBottom = the stageBottom - the stageTop
  27.     "Custom":
  28.       viewingTop = the top of sprite sprite(me.scrollBar).box
  29.       viewingBottom = the bottom of sprite sprite(me.scrollBar).box
  30.   end case
  31. end
  32.  
  33. on mouseDown me
  34.   repeat while the mouseDown
  35.     thePercent = 0
  36.     if me.continuous = 1 then
  37.       getPos(me)
  38.     end if
  39.     updateStage()
  40.   end repeat
  41. end
  42.  
  43. on getPos me
  44.   v = the locV of sprite me.spriteNum
  45.   H = member(the memberNum of sprite me.spriteNum).height / 2
  46.   realT = the top of sprite me.spriteNum
  47.   t = the top of sprite me.scrollBar + H
  48.   b = the bottom of sprite me.scrollBar - H
  49.   H2 = member(the memberNum of sprite me.scrollBar).height - member(the memberNum of sprite me.spriteNum).height
  50.   targetOffset = member(the memberNum of sprite sprite(me.target).spriteNum).height / 2
  51.   scrollTop = viewingTop + targetOffset
  52.   scrollBottom = viewingBottom - targetOffset
  53.   thePercent = float(v - t) / (b - t)
  54.   v = integer(thePercent * (scrollBottom - scrollTop)) + viewingTop + targetOffset
  55.   if (the mouseV >= (the top of sprite me.scrollBar + (member(the memberNum of sprite me.spriteNum).height / 2))) and (the mouseV <= (the bottom of sprite me.scrollBar - (member(the memberNum of sprite me.spriteNum).height / 2))) then
  56.     set the locV of sprite the target of me to v
  57.     set the locV of sprite the spriteNum of me to the mouseV
  58.   else
  59.     if the mouseV <= (the top of sprite me.scrollBar + (member(the memberNum of sprite me.spriteNum).height / 2)) then
  60.       set the locV of sprite the target of me to viewingTop + targetOffset
  61.       set the locV of sprite the spriteNum of me to t
  62.     else
  63.       if the mouseV >= (the bottom of sprite me.scrollBar - (member(the memberNum of sprite me.spriteNum).height / 2)) then
  64.         set the locV of sprite the target of me to viewingBottom - targetOffset
  65.         set the locV of sprite the spriteNum of me to b
  66.       end if
  67.     end if
  68.   end if
  69. end
  70.