Button images script
jhurley at infostations.com
Sat Feb 22 18:10:01 EST 2003
> Greg Wills wrote:
>Thanks Jim, this works beautifully. I may however end up playing with
>the images to get them how I want them before I put them into the
>substack. Yet to be decided.
>I noticed that the images in the substack are also resized, but when
>you re-open the stacks, all the images (and button images - but not
>buttons) are back to their original size.
I left out a key component of the process. *Sorry*.
You need to include a preOpenCard handler in the *stack* script. (If
you have any preOpenCard handlers in the card scripts, be sure to
"pass preOpenCard" in those handlers.)
repeat with i = 1 to the number of buttons
put the short name of button i into tName
Where ResizeImage resides in the stack script and looks like this:
on resizeImage theImage
--First get the button width
put the width of button theImage into theButtonWidth
--Reset the image size on the substack card
--so that it will fit inside the button without distortion.
set the defaultStack to "imagesSubstack"
put the formattedWidth of image theImage into tImageWidth
Put the formattedHeight of image theImage into tImageHeight
put tImageWidth/tImageHeight into ratioOfWidthToHeight
set the width of image theImage to theButtonWidth*.94 -- Leave an edge
set the height of image theImage to theButtonWidth/ratioOfWidthToHeight*.94
--Adjust the button height to match the proportions of the image.
set the defaultstack to "images"
set the height of button theImage to theButtonWidth/ratioOfWidthToHeight
So that before each card is opened, the image in the substack is
sized to fit within each button. This is quite fast and very smooth.
I use this method because I use the same image in different cards at
*If the image sizes are fixed*, things are much simpler. You could
alter the "setUp" handler to include
set the locklocation of image theButtonName to "true"
This also locks the image size. (The button name is the same as the
In this way there is no need for a preOpenCard handler and once the
setUp handler is run, when you first construct the stack, you are
done. Next time the stack is opened all images will be sized to fit
within their respective buttons and the image sizes in the subStack
will be locked.
You can of course take the manual approach and import the images to
the substack, lock them, and then fit the buttons to fit the images.
But I find this more time consuming when there are lots of images.
I hope I haven't left something out again.
More information about the Use-livecode