home *** CD-ROM | disk | FTP | other *** search
- property minButton, maxButton, thumbButton, trackButton, thumbSprite, trackSprite, scrollSprite, scrollSpriteLoc, scrollField, scrollFieldOut, ratio, startLine, scrollHeight, scrollMin, scrollMax, handler, scrollLinks, scrollLinkLocs
-
- on birth me, argList
- return me
- end
-
- on init me
- set ratio to 0.0
- set the group of the minButton of me to me
- set the group of the maxButton of me to me
- set the group of the thumbButton of me to me
- set the group of the trackButton of me to me
- set thumbSprite to the spriteChan of the thumbButton of me
- set trackSprite to the spriteChan of the trackButton of me
- set topOffset to the locV of sprite thumbSprite - the top of sprite thumbSprite
- set bottomOffset to the bottom of sprite thumbSprite - the locV of sprite thumbSprite
- set scrollMin to the top of the rect of sprite trackSprite + topOffset
- set scrollMax to the bottom of the rect of sprite trackSprite - bottomOffset
- set scrollHeight to scrollMax - scrollMin + 1
- if integerp(scrollSprite) then
- puppetSprite(scrollSprite, 1)
- set the scrollSpriteLoc of me to the locV of sprite scrollSprite
- if listp(scrollLinks) then
- set scrollLinkLocs to [:]
- repeat with aSprite in scrollLinks
- puppetSprite(aSprite, 1)
- addProp(scrollLinkLocs, aSprite, the locV of sprite aSprite)
- end repeat
- end if
- end if
- end
-
- on click me, clickedbutton
- if clickedbutton = the minButton of me then
- trackEndButton(me, clickedbutton)
- else
- if clickedbutton = the maxButton of me then
- trackEndButton(me, clickedbutton)
- else
- if clickedbutton = the thumbButton of me then
- trackThumb(me)
- else
- if clickedbutton = the trackButton of me then
- trackTrack(me)
- end if
- end if
- end if
- end if
- if stringp(handler) then
- do(handler && ratio)
- end if
- end
-
- on trackThumb me
- press(the thumbButton of me)
- repeat while the mouseDown
- set the locV of sprite thumbSprite to max(scrollMin, min(the mouseV, scrollMax))
- if the locV of sprite thumbSprite = scrollMax then
- set ratio to 1.0
- else
- set ratio to float(the locV of sprite thumbSprite - scrollMin) / scrollHeight
- end if
- scroll(me)
- updateStage()
- end repeat
- release(the thumbButton of me)
- end
-
- on trackEndButton me, clickedbutton
- if stringp(scrollField) then
- set disp to the textHeight of field scrollField
- else
- set disp to 14
- end if
- if clickedbutton = the maxButton of me then
- set disp to -disp
- end if
- press(clickedbutton)
- set doOnce to 1
- repeat while the mouseDown or doOnce
- shift(me, disp)
- if doOnce = 1 then
- set t to the ticks
- repeat while the ticks < (t + 8)
- nothing()
- end repeat
- set doOnce to 0
- end if
- end repeat
- release(clickedbutton)
- end
-
- on trackTrack me
- if stringp(scrollField) then
- set disp to the height of sprite scrollFieldOut
- else
- set disp to scrollHeight
- end if
- if the mouseV > the locV of sprite thumbSprite then
- set disp to -disp
- end if
- press(the trackButton of me)
- set doOnce to 1
- repeat while the mouseDown or doOnce
- if (disp < 0) and (the locV of sprite thumbSprite > the mouseV) then
- trackThumb(me)
- else
- if (disp > 0) and (the locV of sprite thumbSprite < the mouseV) then
- trackThumb(me)
- else
- shift(me, disp)
- end if
- end if
- if doOnce = 1 then
- set t to the ticks
- repeat while the ticks < (t + 8)
- end repeat
- set doOnce to 0
- end if
- end repeat
- release(the trackButton of me)
- end
-
- on scroll me
- if ratio > 1 then
- set ratio to 1
- else
- if ratio < 0 then
- set ratio to 0
- end if
- end if
- if integerp(scrollSprite) then
- set aHeight to the height of cast the castNum of sprite scrollSprite
- set shift to (-aHeight + scrollHeight) * ratio
- if shift <= 0 then
- set the locV of sprite scrollSprite to scrollSpriteLoc + shift
- end if
- if listp(scrollLinks) then
- repeat with aSprite in scrollLinks
- set aLocV to getProp(scrollLinkLocs, aSprite)
- if shift <= 0 then
- set the locV of sprite aSprite to aLocV + shift
- end if
- end repeat
- end if
- else
- if stringp(scrollField) then
- set lines to the height of cast scrollField / the textHeight of field scrollField
- set size to the height of sprite scrollFieldOut / the textHeight of field scrollField
- set startLine to integer((lines * ratio) - (size * ratio)) + 1
- set lineMax to the number of lines in field scrollField - 3
- if startLine > lineMax then
- set startLine to lineMax
- end if
- set endLine to the number of lines in field scrollField
- set fieldName to the name of cast the castNum of sprite scrollFieldOut
- put line startLine to endLine of field scrollField into field fieldName
- end if
- end if
- if stringp(handler) then
- do(handler && ratio)
- end if
- end
-
- on editScroll me
- set endLine to the number of lines in field scrollField
- delete line startLine to endLine of field scrollField
- if startLine > 1 then
- put RETURN after field scrollField
- end if
- set fieldName to the name of cast the castNum of sprite scrollFieldOut
- put field fieldName after field scrollField
- end
-
- on shift me, pixels
- if stringp(scrollField) then
- set offset to the height of sprite scrollFieldOut - the height of cast scrollField
- else
- set offset to scrollHeight - the height of cast the castNum of sprite scrollSprite
- end if
- if offset > 0 then
- exit
- end if
- if offset = 0 then
- set ratio to 0
- else
- set ratio to (pixels / float(offset)) + ratio
- end if
- controlPosition(me, ratio)
- end
-
- on controlPosition me, newratio
- set ratio to newratio
- if ratio > 1 then
- set ratio to 1
- else
- if ratio < 0 then
- set ratio to 0
- end if
- end if
- set the locV of sprite thumbSprite to scrollMin + (ratio * scrollHeight)
- scroll(me)
- updateStage()
- end
-
- on newScrollField me, newField
- set scrollField to newField
- end
-