|
|
|
sprite resize
Added on 6/3/2003
|
|
Compatibilities:
|
This item has not yet been rated
|
This behavior lets you resize a sprite, using its right bottom corner. You can use your own cursor castmember to indite the resizebale mode. The sprite must have active pixels at the right bottom corner, but if it hasn't, it should have the "copy" ink.
When you attach the script to a sprite by script, you should send a beginsprite handler, or set the default values.
If you doubleclick on the resized sprite, it will reset its width and height to the original values.
Download PC Source
-- Sprite resize ; 2003.06.x
-- Author: Roti ; roti@al.pmmf.hu
on getBehaviorDescription me
return "Resizeable sprite"&RETURN&RETURN&"This behavior lets you resize a sprite, using its right bottom corner. You can use your own cursor castmember to indite the resizebale mode. The sprite must have active pixels at the right bottom corner, but if it hasn't, it should have the ""E&"copy""E&" ink." & RETURN & RETURN & "When you attach the script to a sprite by script, you should send a beginsprite handler, or set the default values."& RETURN & RETURN & "If you doubleclick on the resized sprite, it will reset its width and height to the original values."
end getBehaviorDescription
on getBehaviorTooltip me
return "Use this behavior to make a sprite resizeable."
end getBehaviorTooltip
property pMyMinimumWidth -- which is the minimum width to resize
property pMyMinimumHeight -- which is the minimum height to resize
property pMyEdgeWidth -- which is the width of the right bottom edge, where we can grab the sprite
property pMyEdgeHeight -- which is the height of the right bottom edge, where we can grab the sprite
-- 299 is the resize cursor in director, but it hasn't got white border
property pMyCursorMember -- The cursor to indicate the resize ability at the bottom right corner, it can be a number, or member(somemember)
property pMySpritenum -- am I the current sprite to resize
property pMyMoveable -- am I moveable riginally
property pMyWidth -- my original width
property pMyHeight -- my original height
on beginsprite me
-- store my original width
pMyWidth = sprite(me.spritenum).width
-- store my original height
pMyHeight = sprite(me.spritenum).height
-- default values; if we attach this behavior by script, but then we need to send a beginsprite!
if pMyCursorMember = Void then
pMyCursorMember = "299" -- member("resize") (in the example movie)
end if
if pMyMinimumWidth = Void then
pMyMinimumWidth = 10
end if
if pMyMinimumHeight = Void then
pMyMinimumHeight = 10
end if
if pMyEdgeWidth = Void then
pMyEdgeWidth = 10
end if
if pMyEdgeHeight = Void then
pMyEdgeHeight = 10
end if
end
on exitframe me
-- we will use this mouse points
x=the mouseh
y=the mousev
-- if we are working with the current sprite, and the mouse is between the specified right bottom edge
if pMySpritenum=me.spritenum and x>sprite(me.spritenum).left+pMyMinimumWidth and y>sprite(me.spritenum).top+pMyMinimumHeight then
-- keep the right bottom edge under the cursor
sprite(me.spritenum).right=the mouseh+5
updatestage
sprite(me.spritenum).bottom=the mousev+5
end if
-- set the appropriate cursor for the sprite, at the bottom right
if x>sprite(me.spritenum).right-pMyEdgeWidth and xsprite(me.spritenum).bottom-pMyMinimumHeight and y if pMyCursorMember<>Void then
do "sprite(me.spritenum).cursor="&pMyCursorMember
end if
else
sprite(me.spritenum).cursor=-1
end if
end
on mousedown me
x=the mouseh
y=the mousev
if x>sprite(me.spritenum).right-pMyEdgeWidth and xsprite(me.spritenum).bottom-pMyEdgeHeight and y -- store my spritenum
pMySpritenum=me.spritenum
-- store my moveable property
pMyMoveable = sprite(me.spritenum).moveablesprite
-- we have to stop moveability, either to resize correctly, and we will reset to the original state later
sprite(me.spritenum).moveablesprite = 0
end if
end
on mouseup me
-- on doubleclick, we restore the size, at the current location
if the doubleClick then
sprite(me.spritenum).rect=rect(sprite(me.spritenum).rect[1],sprite(me.spritenum).rect[2],sprite(me.spritenum).rect[1]+pMyWidth,sprite(me.spritenum).rect[2]+pMyHeight)
end if
-- forget the current spritenum
pMySpritenum=Void
x=the mouseh
y=the mousev
-- restore the moveable prop.
if x>sprite(me.spritenum).right-pMyEdgeWidth and xsprite(me.spritenum).bottom-pMyEdgeHeight and y sprite(me.spritenum).moveablesprite = pMyMoveable
end if
end
on mouseupoutside me
-- reset the current sprite and my moveable prop.
pMySpritenum=Void
sprite(me.spritenum).moveablesprite = pMyMoveable
end
on isOKToAttach (me, aSpriteType)
case aSpriteType of
#script:
return FALSE
otherwise:
RETURN TRUE
end case
end
on getPropertyDescriptionList
if the currentSpriteNum = 0 then exit
return [ #pMyMinimumWidth: [#comment: "The minimum width limit of the resizing", #format: #integer, #default: 10], #pMyMinimumHeight: [#comment: "The minimum height limit of the resizing", #format: #integer, #default: 10 ], #pMyEdgeWidth: [#comment: "The width of the resize sensitive bottom right corner", #format: #integer, #default: 10 ], #pMyEdgeHeight : [#comment: "The height of the resize sensitive bottom right corner", #format: #integer, #default: 10 ], #pMyCursorMember: [#comment: "The cursor to indicate the resize ability (number, or member(myCursorMember))", #format: #string, #default: "299" ]]
end getPropertyDescriptionList
|
|