Scale an image from an absolute point

Ken Norris pixelbird at interisland.net
Sat Jul 23 15:21:43 EDT 2005


Hi Roger,

> Date: Sat, 23 Jul 2005 12:10:52 -0400
> From: Roger.E.Eller at sealedair.com
> Subject: Scale an image from an absolute point
>
> I need to scale an image from an absolute point within the image rect.
> This point will not be the loc or any of the 4 corners. The image must
> stay positioned (locked) by a point where the user clicks during the
> scaling routine. Does anyone have an idea of how to best approach 
> this? I
> could calculate the offset from the loc of the image, but this changes 
> as
> the image is dragged to be larger/smaller. Any ideas?

Get the mouseLoc and use the scale factor to reset the rect of the 
image based on the offset values. There are probably half-a-dozen ways 
to do it that will work. Just work out the math.

Here's a Q&D one (NOTE: Works only for upscale positive values; you'll 
need to tweak and polish for your purposes):

1) Create an image control and center it in the stack window

2) Create a short field named "ScaleFactor"

3) Put this into the script of the image (watch linewraps):

on mouseDown
   global gOrigRect
   put value(cd fld "ScaleFactor") into scaleFactor
   put the rect of me into gOrigRect
   put item 1 of the mouseLoc - (scaleFactor * (item 1 of the mouseLoc - 
the left of me)) into offsetL
   put item 2 of the mouseLoc - (scaleFactor * (item 2 of the mouseLoc - 
the top of me)) into offsetT
   put item 1 of the mouseLoc + (scaleFactor * (the right of me - item 1 
of the mouseLoc)) into offsetR
   put item 2 of the mouseLoc + (scaleFactor * (the bottom of me - item 
2 of the mouseLoc)) into offsetB
   lock screen
   set the rect of me to offsetL,offsetT,offsetR,offsetB
   unlock screen
end mouseDown

on mouseUp
   global gOrigRect
   set the rect of me to gOrigRect
end mouseUp


HTH,
Ken N.




More information about the use-livecode mailing list