Button images script

Greg Wills gwills at ozemail.com.au
Sat Feb 22 01:54:01 EST 2003


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 ran the script from a 
button and not a preopen card script.) For what I want to do this 
seems a bit of unnecessary processing as they would have to be 
resized every time the stack was opened. Do you think locking "size 
and position" (of the image) after the image have been scaled would 
stop this?

(But then again I can see the advantage in having a larger image to 
size as needed in different options within a stack - as I think 
aloud).

Thanks for sharing the script. It is helpful to see how others 
approach problems.

cheers

Greg


>Greg,
>
>Here is a utility which I use to deal with buttons in the main stack
>whose image icons are in a substack. It relieves you of the need of
>setting  to set the icon id and sizing the images and/or the buttons
>all in one fell swoop.
>
>1) Put all the images on card 1 of the substack (mySubstack below.)
>Don't worry about size or position, that will be taken care  of
>later. And resizing may distort the proportions. Doesn't matter if
>they overlap.
>2) Next go through the main stack (myStack below) and create buttons
>with *the same name as the desired image in the substack* and in the
>desired location on each card. Also adjust the size of the button to
>the desired size of the eventual image. (Actually only the width
>matters. The height will be adjusted to avoid distorting the image
>proportions.)
>3) Run setUp below from the main stack. All buttons will be assigned
>icon numbers of the image corresponding to the button name and the
>image in the substack is adjusted to fit within the button. And, as a
>bonus, you get an image border. If you don't want the border just:
>"set the showBorder of button tButtonName to "false." You can also
>set the color and width of the border. You may want to tinker with
>the edge number of ".98" below.
>4)  You can add images and button later if necessary and rerun "setUP".
>5)  Thanks to members of this list for help in developing this handler.
>
>
>
>On setUpRev
>    Lock screen
>    repeat with i =1 to the number of cards
>      set the defaultstack to "myStack
>      go to card i
>      repeat with j = 1 to the number of buttons
>        put the short name of button j into tButtonName
>        put the width of button j into theButtonWidth
>        set the defaultstack to "mySubstack
>        if there is an image tButtonName then
>          put the id of image tButtonName into tImageID
>          put the formattedWidth of image tButtonName into tImageWidth
>          Put the formattedHeight of image tButtonName into tImageHeight
>          put tImageHeight/tImageWidth into ratioOfHeightToWidth
>          set the width of image tButtonName to theButtonWidth*.98 --
>Leave an edge
>          set the height of image tButtonName to
>theButtonWidth*ratioOfHeightToWidth*.98
>        end if
>        set the defaultstack to "myStack"
>        set the icon of button j to tImageID
>        set the height of button tButtonName to
>theButtonWidth*ratioOfHeightToWidth
>      end repeat
>    end repeat
>    unlock screen
>end setUpRev
>
>Jim



More information about the use-livecode mailing list