|
|
Progress Bar
Added on 10/6/1999
|
Drop this behavior on a sprite, and it"s rect will be modified to match the percentage passed in Another sprite is needed to act as the bounding rect for the progress bar
Use the SetProgressBar() method via sendSprite to tell the bar what percent to show
Example:
sendSprite( progressBarSprite, #SetProgressBar, 50 )
-- Mark Castle
-- Castle Productions, 9/99
-- markie@the-castle.com
-- http://www.the-castle.com
-- Drop this behavior on a sprite, and it"s rect will be modified to match the percentage passed in
-- Another sprite is needed to act as the bounding rect for the progress bar
-- Use the SetProgressBar() method via sendSprite to tell the bar what percent to show
-- Example:
-- sendSprite( progressBarSprite, #SetProgressBar, 50 )
-- The above sample would set the progress bar to 50%, whether it was horizontal or vertical
property spriteNum
-- Can be either vertical or horizontal orientation
property pOrientation
-- Channel with bounding rect for the progress bar
property pBoundingRectSprite
-- Vertical values for progress
property pVerticalTopLoc
property pVerticalBottomLoc
-- Horizontal values for progress
property pHorizontalLeftLoc
property pHorizontalRightLoc
-- Complete range for progress
property pProgressRange
on beginSprite me
spriteRef = sprite( pBoundingRectSprite )
pVerticalTopLoc = spriteRef.top
pVerticalBottomLoc = spriteRef.bottom
pHorizontalLeftLoc = spriteRef.left
pHorizontalRightLoc = spriteRef.right
if ( pOrientation = #vertical ) then
pProgressRange = pVerticalBottomLoc - pVerticalTopLoc
else
pProgressRange = pHorizontalRightLoc - pHorizontalLeftLoc
end if
-- Set the initial position of the progress bar
SetProgressBar( me, 0 )
end
-- Make the progress bar draw a certain percentage
on SetProgressBar me, percentToDisplay
-- Convert an integer into a float percentage
if integerP( percentToDisplay ) then percentToDisplay = percentToDisplay / 100.0
if ( percentToDisplay > 1 ) OR ( percentToDisplay < 0 ) then
alert "Percentage is not correct and cannot be displayed:" && percentToDisplay
exit
end if
pixelOffset = integer( pProgressRange * percentToDisplay )
spriteRef = sprite( spriteNum )
if ( pOrientation = #vertical ) then
theTop = pVerticalBottomLoc - pixelOffset
theRight = pHorizontalRightLoc
else
theTop = pVerticalTopLoc
theRight = pHorizontalLeftLoc + pixelOffset
end if
spriteRef.rect = rect( pHorizontalLeftLoc, theTop, theRight, pVerticalBottomLoc )
end
on getPropertyDescriptionList
defaultChannel = the currentSpriteNum
-- Exit if this is being run by a recompile
if defaultChannel < 1 then exit
-- Set the default channel for the bounding sprite
defaultChannel = defaultChannel + 1
set descriptList = [:]
setAProp( descriptList, #pOrientation, [ #comment: "Orientation" ,#format: #symbol, #default: #vertical, #range: [#vertical,#horizontal] ] )
setAProp( descriptList, #pBoundingRectSprite, [ #comment: "Channel to use as bounding rect:" ,#format: #integer, #default: defaultChannel] )
return descriptList
end
|
|