-- REPOSITION ON RESIZE -- -- -- © December 2000, James Newton -- -- Requires a movie script with the handlers: -- -- on activateWindow() -- (the activeWindow).windowType = 8 -- Zoomable:12, resizable:0 -- end resizeWindow -- -- on resizeWindow() -- sendAllSprites(#reposition, (the activeWindow).rect) -- end -- -- on zoomWindow() -- sendAllSprites(#reposition, (the activeWindow).rect) -- end -- PROPERTY DECLARATIONS -- property spriteNum -- property hEdge -- #center | #right | #ignore property hLimit -- don't move left of this limit property vEdge -- #center | #bottom | #ignore property vLimit -- don't move above this limit -- property mySprite -- sprite(spriteNum).member property myDeltaH -- pixels from right edge property myDeltaV -- pixels from left edge property myStageWidth -- initial width of the stage property myStageHeight -- initial height of the stage -- EVENT HANDLERS -- on beginSprite(me) me.initialize() end beginSprite -- PUBLIC METHODS -- on reposition(me, newStageRect) stageWidth = newStageRect.right - newStageRect.left stageHeight = newStageRect.bottom - newStageRect.top case hEdge of #center: hLoc = max(hLimit, (stageWidth / 2) - myDeltaH) #right: hLoc = max(hLimit, stageWidth - myDeltaH) otherwise hLoc = mySprite.locH end case case vEdge of #center: vLoc = max(vLimit, (stageHeight / 2) - myDeltaV) #bottom: vLoc = max(vLimit, stageHeight - myDeltaV) otherwise vLoc = mySprite.locV end case mySprite.loc = point(hLoc, vLoc) end reposition -- PRIVATE METHODS -- on initialize(me) mySprite = sprite(spriteNum) stageRect = (the activeWindow).sourceRect myStageWidth = stageRect.right - stageRect.left myStageHeight = stageRect.bottom - stageRect.top symbolList = me.getSymbolList() hEdge = symbolList.getOne(hEdge) vEdge = symbolList.getOne(vEdge) case hEdge of #center: myDeltaH = (myStageWidth / 2) - mySprite.locH #right: myDeltaH = myStageWidth - mySprite.locH end case case vEdge of #center: myDeltaV = (myStageHeight / 2) - mySprite.locV #bottom: myDeltaV = myStageHeight - mySprite.locV end case if stageRect <> (the activeWindow).rect then me.reposition((the activeWindow).rect) end if end initialize -- UTILITY HANDLERS -- on getSymbolList(me) return [ \ #center: "centre", \ #right: "right", \ #bottom: "bottom", \ #ignore: "ignore" \ ] end getSymbolList -- BEHAVIOR DESCRIPTION AND PARAMETERS -- on getPropertyDescriptionList(me) propertiesList = [:] if the currentSpriteNum then thisSprite = sprite(the currentSpriteNum) leftMax = thisSprite.locH topMax = thisSprite.locV else leftMax = 1 topMax = 1 end if symbolList = me.getSymbolList() propertiesList[ \ #hEdge] = [ \ #comment: "Maintain horizontal position with respect to:", \ #format: #symbol, \ #range: [symbolList.center, symbolList.right, symbolList.ignore], \ #default: symbolList.center \ ] propertiesList[ \ #hLimit] = [ \ #comment: "Leftward limit:", \ #format: #integer, \ #range: [#min: 0, #max: leftMax], \ #default: #center \ ] propertiesList[ \ #vEdge] = [ \ #comment: "Maintain vertical position with respect to:", \ #format: #symbol, \ #range: [symbolList.center, symbolList.bottom, symbolList.ignore], \ #default: #center \ ] propertiesList[ \ #vLimit] = [ \ #comment: "Upward limit:", \ #format: #integer, \ #range: [#min: 0, #max: topMax], \ #default: #center \ ] return propertiesList end getPropertyDescriptionList on getBehaviorTooltip(me) return \ "Repositions the sprite with respect"&RETURN&\ "to the right and bottom edge of the"&RETURN&\ "active window when it is resized." end getBehaviorTooltip on getBehaviorDescription(me) return \ "REPOSITION ON RESIZE"&RETURN&RETURN&\ "Repositions the sprite with respect to the right and bottom edge of the active window when it is resized." end getBehaviorDescription