I can get the image to resize maintaining its aspect ratio and the stack maintaining its size proportional to the graphic in one dimension or the other using the following script. In this case the stack and image height resize in tandem but the width is not contained and can vary.
What I want is to have the stack's aspect ration constrained to the graphic's aspect ratio but it looks like using the resizeStack message won't allow me to do that. See the following line in the code below:
Code: Select all
set the width of this stack to the width of graphic "cameraDisplay"
Code: Select all
Local sCameraName, sCameraAspectRatio
# sCameraName and sCameraAspectRatio are set elsewhere in the script when camera opens
on resizeStack pNewStackWidth, pNewStackHeight, pOldWidth, pOldHeight
put item 1 of sCameraAspectRatio into tScreenWidthFactor
put item 2 of sCameraAspectRatio into tScreenHeightFactor
# Width of stack proportional with graphic width -- stack height varies
-- set the width of graphic "cameraDisplay" to pNewStackWidth
-- set the height of graphic "cameraDisplay" to Round(pNewStackWidth/tScreenWidthFactor*tScreenHeightFactor)
# Height of stack proportional with graphic Height -- stack width varies
set the height of graphic "cameraDisplay" to pNewStackHeight - 40 # Leave 40 pixels at bottom of stack for controls.
set the width of graphic "cameraDisplay" to Round(the height of graphic "cameraDisplay"/tScreenHeightFactor*tScreenWidthFactor)
# Try to constrain stack width to image width but it does not work Stack width follows cursor position, image maintains aspect ratio.
set the width of this stack to the width of graphic "cameraDisplay"
# adjust postion of graphic "cameraDisplay"
set the topleft of graphic "cameraDisplay" to "0,0"
# adjust position of other controls on card to be in bottom 40 pixel area
set the bottom of button "open camera" to the bottom of this card - 10
set the bottom of button "record" to the bottom of this card - 10
set the bottom of button "close" to the bottom of this card - 10
set the bottom of Field "presets" to the bottom of this card - 10
resizeCameraDisplay
end resizeStack
on resizeCameraDisplay
cameracontrolset sCameraName, "rect", the rect of graphic "cameraDisplay"
end resizeCameraDisplay
Is there a way to use the resizeStack message to get the results I want?
I the resizeStack message can't handle this then what other techniques I want?
I tried using a button with mouseUp and and mouseMove handler to resize the stack and the image as the button is being dragged but that did not work at all. The stack was jumping between two sizes and locations and eventually hit a recursion limit.
Any suggestions as to how to handle this?
Thanks
Martin