Scaling images
I think we have covered all the possibilities for adding image files.
We will now try adding scaling to the export.
Open the Export window and uses MPI's control popup to change the style of the window to standard.
We are going to add a popup button for scaling.
Drag a Bevel Button from MPI's Tools Module and use the PI to change its behaviour to popUpButton.
In the RTE you need to choose the bevel button tool and draw a button.
We need to add the
popupData userProp to the button, you can use the PI and the popupData button to open MPI's
popUpData dialog, but it might be quicker with the
UserProp module. Open this while the button is selected and define the popupData of the button. Set the popupData to a list from 100 down to 10 in 10s.
Make sure the buttons showName is set to true in the PI, switch to the browse tool (
control tab in MPI) and try the button out (I've added text graphics labling the button scale and a percent sign after the button.
Now we need to change the script of our
Export button to handle the scale.
to find the scale choosen in the button we need to refer to the button by
id in my case the id is 323 you can find out the id in the PI.
put the short name of btn id 323 into tScale
if tScale=100
then
--we dont need to scale the grc
if tfileType is not "jpeg"
then do merge("export the pictureData of cd grc `imageDisplay` of cd 1 of wd 1 to [[tFileType]] file `[[tfilepath]]`")
else do merge("export the pictureData of cd grc `imageDisplay` of cd 1 of wd 1 to [[tFileType]] file `[[tfilepath]]` with [[tquality]]")
else
end if
We need to thing about what information we need to scale and to present it.
We can find the original size of the pictureData by getting the imageRect.
I've added 4 new fields to the Export window and labled them.
Names: originalWidth, originalHeight, newWidth and newHeight
LockText true -
PI
ShowFill false -
Color module
and added a script to the card:
on openCard
set the name of btn id 323 to 100
get the imageRect of cd grc 1 of cd 1 of wd 1
put item 3 of it into cd fld "originalWidth"
put item 4 of it into cd fld "originalHeight"
put item 3 of it into cd fld "newWidth"
put item 4 of it into cd fld "newHeight"
end openCard
We can add a script to the
Scale popup:
on mouseUp
put round(cd fld "originalWidth"*the short name of me/100) into cd fld "newWidth"
put round(cd fld "originalHeight"*the short name of me/100) into cd fld "newHeight"
end mouseUp
We then use that information in the
Export buttons script:
put cd fld "newHeight" into tHeight
put cd fld "newWidth" into tWidth
setWindow window 1
lock screen
put the rect of cd grc "imageDisplay" into tOriginalRect
set the width of cd grc "imageDisplay" to tWidth
set the height of cd grc "imageDisplay" to tHeight
if tfileType is not "jpeg"
then do merge("export card from Topleft of cd grc `imageDisplay` to bottomright of cd grc `imageDisplay` to [[tFileType]] file `[[tfilepath]]`")
else do merge("export card from Topleft of cd grc `imageDisplay` to bottomright of cd grc `imageDisplay` to [[tFileType]] file `[[tfilepath]]` with [[tquality]]")
set the rect of cd grc "imageDisplay" to tOriginalRect
end if
close wd "export"