Stupid Question Again - Proportional Scaling

hh hh at hyperhh.de
Sun Mar 18 15:09:35 EDT 2018


Never tried to script that. It's *eventually* simple -- as always with LC.
Here again a little bit optimised, changing the size also by the scrollWheel:

-- 1. Don't use a resizestack handler
-- 2. Set resizable of the stack to FALSE

local l0, t0, ff

on mouseDown
 put the long id of the target into tgt
 if not tgt begins with "image " then exit mouseDown
 put the left of this stack into l0
 put the top of this stack into t0
 -- if the image is always the same then ff can be computed once
 put the formattedHeight of tgt/the formattedWidth of tgt into ff
 put the right of tgt - the clickH into dx
 setRects dx,tgt
end mouseDown

on setRects dx,tgt
 if setRects is in the pendingmessages then exit setRects
 lock screen; lock messages
 put dx+the mouseH into w0
 put ff*w0 into h0
 set the rect of this stack to (l0,t0,l0+w0,t0+h0)
 set the rect of tgt to (0,0,w0,h0)
 if the mouse is down --> TMHO, polling the mouse is here OK
 then send "setRects dx,tgt" to me in 8 millisecs --> 8-16 millisecs
end setRects

on rawkeydown k
 put the long id of the target into tgt
 if not tgt begins with "image " then pass rawkeydown
 lock screen; lock messages
 put the left of this stack into l0
 put the top of this stack into t0
 switch k
   case 65308; put  16 into d; break -- scrollwheel backward
   case 65309; put -16 into d; break -- scrollwheel forward
 end switch
 put d+the width of tgt into w0
 -- if the image is always the same then this becomes: put w0*ff into h0
 put w0*the formattedHeight of tgt/the formattedWidth of tgt into h0
 set the rect of this stack to (l0,t0,l0+w0,t0+h0)
 set the rect of tgt to (0,0,w0,h0)
end rawkeydown




More information about the use-livecode mailing list