-- STRETCH 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 stretchFrom -- #topLeft | #center | #regPoint property widthMode -- #fixed | #ratio | #ignore property minimumWidth -- property maximumWidth -- property heightMode -- #fixed | #ratio | #ignore property minimumHeight -- property maximumHeight -- property sourceWidth property sourceHeight -- property mySprite -- sprite(spriteNum) property myMember -- sprite(spriteNum).member property myType -- sprite(spriteNum).member.type -- property myFixedPoint -- point from which the sprite stretches property myLeftRatio -- proportion of stage to left of myFixedPoint property myWidthData -- proportion of stage to right of myFixedPoint property myTopRatio -- proportion of stage above myFixedPoint property myHeightData -- proportion of stage below myFixedPoint -- 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 stretchFrom of #topLeft: leftToRight = stageWidth - mySprite.left topToBottom = stageHeight - mySprite.top case widthMode of #ratio: newWidth = leftToRight * myWidthData #fixed: newWidth = leftToRight - myWidthData #ignore: newWidth = sourceWidth end case case heightMode of #ratio: newHeight = topToBottom * myHeightData #fixed: newHeight = topToBottom - myHeightData #ignore: newHeight = sourceHeight end case newWidth = max(minimumWidth, min (newWidth, maximumWidth)) newHeight = max(minimumHeight, min(newHeight, maximumHeight)) bottomLeft = myFixedPoint + [newWidth, newHeight] spriteRect = rect(myFixedPoint, bottomLeft) #center: #regPoint: end case me.setRect(spriteRect) end reposition -- PRIVATE METHODS -- on initialize(me) mySprite = sprite(spriteNum) myMember = mySprite.member myType = myMember.type -- Convert localized string parameter to symbol stretchFrom = (me.getSymbolList(#fixed)).getOne(stretchFrom) widthMode = (me.getSymbolList(#mode)).getOne(widthMode) heightMode = (me.getSymbolList(#mode)).getOne(heightMode) stageRect = (the activeWindow).sourceRect stageWidth = stageRect.width stageHeight = stageRect.height case stretchFrom of #topLeft: myFixedPoint = point(mySprite.left, mySprite.top) leftToRight = stageWidth - mySprite.left topToBottom = stageHeight - mySprite.top case widthMode of #ratio: myWidthData = sourceWidth / float(leftToRight) #fixed: myWidthData = leftToRight - sourceWidth end case case heightMode of #ratio: myHeightData = sourceHeight / float(topToBottom) #fixed: myHeightData = topToBottom - sourceHeight end case #center: centreH = (mySprite.left + mySprite.right) / 2 centreV = (mySprite.top + mySprite.bottom) / 2 myFixedPoint = point(centreH, centreV) #regPoint: myFixedPoint = mySprite.loc end case if stageRect <> (the activeWindow).rect then me.reposition((the activeWindow).rect) end if end initialize on setRect(me, spriteRect) case myType of #field, #text: if myMember.boxType = #scroll then memberRect = spriteRect - [0, 0, 16, 0] else memberRect = spriteRect end if myMember.rect = memberRect mySprite.rect = spriteRect otherwise mySprite.rect = spriteRect end case end setRect -- UTILITY HANDLERS -- on getSymbolList(me, whichList, returnAsLinearList) case whichList of #fixed: symbolList = [ \ #topLeft: "top left", \ #center: "centre", \ #regPoint: "bottom" \ ] #mode: symbolList = [ \ #fixed: "to maintain a fixed distance from the edge", \ #ratio: "as a proportion of the stage size", \ #ignore: "don't stretch" \ ] end case if returnAsLinearList then temp = symbolList symbolList = [] i = temp.count repeat while i symbolList[i] = temp[i] i = i - 1 end repeat end if return symbolList end getSymbolLists -- BEHAVIOR DESCRIPTION AND PARAMETERS -- on getPropertyDescriptionList(me) propertiesList = [:] if the currentSpriteNum then spriteRect = sprite(the currentSpriteNum).rect spriteWidth = spriteRect.width spriteHeight = spriteRect.height else spriteWidth = 1 spriteHeight = 1 end if fixedList = me.getSymbolList(#fixed, 1) modeList = me.getSymbolList(#mode, 1) propertiesList[ \ #stretchFrom] = [ \ #comment: "Stretch sprite from:", \ #format: #symbol, \ #range: fixedList, \ #default: fixedList[1] \ ] propertiesList[ \ #widthMode] = [ \ #comment: "Stretch horizontally:", \ #format: #string, \ #range: modeList, \ #default: modeList[1] \ ] propertiesList[ \ #minimumWidth] = [ \ #comment: "Minimum width:", \ #format: #integer, \ #range: [#min: 0, #max: spriteWidth], \ #default: 0 \ ] propertiesList[ \ #maximumWidth] = [ \ #comment: "Maximum width:", \ #format: #integer, \ #range: [#min: spriteWidth, #max: 1200], \ #default: 1200 \ ] propertiesList[ \ #heightMode] = [ \ #comment: "Stretch vertically:", \ #format: #string, \ #range: modeList, \ #default: modeList[1] \ ] propertiesList[ \ #minimumHeight] = [ \ #comment: "Minimum height:", \ #format: #integer, \ #range: [#min: 0, #max: spriteHeight], \ #default: 0 \ ] propertiesList[ \ #maximumHeight] = [ \ #comment: "Maximum height:", \ #format: #integer, \ #range: [#min: spriteHeight, #max: 960], \ #default: 960 \ ] propertiesList[ \ #sourceWidth] = [ \ #comment: "(source width)", \ #format: #integer, \ #range: [#min: spriteWidth, #max: spriteWidth], \ #default: spriteWidth \ ] propertiesList[ \ #sourceHeight] = [ \ #comment: "(source height):", \ #format: #integer, \ #range: [#min: spriteHeight, #max: spriteHeight], \ #default: spriteHeight \ ] return propertiesList end getPropertyDescriptionList on getBehaviorTooltip(me) return \ "Changes the width and height"&RETURN&\ "of a sprite in proportion to"&RETURN&\ "the size of the active window." end getBehaviorTooltip on getBehaviorDescription(me) return \ "STRETCH ON RESIZE"&RETURN&RETURN&\ "Changes the width and height of a sprite in proportion to the size of the active window." end getBehaviorDescription