SC, Image Files and MPI

Click on an image to open a fullsized version in another window.

MPI Window Style popup
MPI Window Style popup 414 by 274

MPI UserProps Module
MPI UserProps Module 427 by 212

 158 by 242

Export Window with Size fields
Export Window with Size fields 360 by 262

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
--handle the scaling

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

--reset the scale button
set the name of btn id 323 to 100
--find out the original dimensions of the image
get the imageRect of cd grc 1 of cd 1 of wd 1
--fill the fields
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:
  --handle the scaling

--get the new size

put cd fld "newHeight" into tHeight
put cd fld "newWidth" into tWidth
--then set the window so all the commands are aimed at wd 1
setWindow window 1
--lock screen so we do not see image resizing
lock screen
--store the rect of the graphic so we can restore it
put the rect of cd grc "imageDisplay" into tOriginalRect
--resize the graphic
set the width of cd grc "imageDisplay" to tWidth
set the height of cd grc "imageDisplay" to tHeight

--when we build the export script below
--we export from topLeft to Bottomright of the graphic

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]]")
--reset the graphic
set the rect of cd grc "imageDisplay" to tOriginalRect
end if
close wd "export"
--have changed this from 'close this wd' as this wd is now wd 1 because we used setwindow above