Stupid Question Again - Proportional Scaling

J. Landman Gay jacque at hyperactivesw.com
Sun Mar 18 07:04:19 CET 2018


On 3/17/18 12:14 PM, Peter Reid via use-livecode wrote:
> I have a sub-stack that contains an image.  I want the user to be able
> to drag the corners and edges of the sub-stack window to make the window
> and its image larger or smaller, but the window and image must maintain
> their original aspect ratio – no stretching, no empty borders etc.


I wish we had a way to determine when a stack resize is finished. The 
best I could do is run a "send" loop to check the mouse state. Maybe 
someone else knows a better way. It doesn't seem possible to change the 
stack size within a resizeStack handler, which makes sense, so the 
adjustment has to be done afterward.

I think this sort of does what you want, but there's a "snap" at the end 
when the stack adjusts to the new image size. It accomodates images of 
any orientation.


constant kImgName = "coinSet"

on resizeStack pNewWidth, pNewHeight, pOldWidth, pOldHeight
   put the formattedWidth of img kImgName into tFWidth
   put the formattedHeight of img kImgName into tFHeight
   if tFHeight > tFWidth then
     resizeToHeight tFHeight,tFWidth
   else
     resizeToWidth tFHeight,tFWidth
   end if
   checkResizeDone
end resizeStack

on resizeToHeight tOrigImgHeight,tOrigImgWidth
   put the height of this cd/tOrigImgHeight  into tRatio
   put (tOrigImgWidth * tRatio) into tNewWidth
   put (tOrigImgHeight * tRatio) into tNewHeight
   set the rect of img kImgName to 0,0,tNewWidth,tNewHeight
end resizeToHeight

on resizeToWidth tOrigImgHeight,tOrigImgWidth
   put the width of this cd into tW
   put tW/tOrigImgWidth into tRatio
   put (tOrigImgWidth * tRatio) into tNewWidth
   put (tOrigImgHeight * tRatio) into tNewHeight
   set the rect of img kImgName to 0,0,tNewWidth,tNewHeight
end resizeToWidth

on checkResizeDone
   if the mouse is up then
     set the rect of this stack to \
       (globalLoc(the topleft of img kImgName) &comma& globalLoc(the 
bottomright of img kImgName))
   else
     send "checkResizeDone" to me in 100 milliseconds
   end if
end checkResizeDone

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list