Rotating a picture?

Jeanne A. E. DeVoto jeanne at runrev.com
Fri Apr 25 14:43:06 EDT 2003


At 6:38 AM -0700 4/25/03, Tim Hart wrote:
>My question is, is there a way to have the user drag something and have
>the image rotate?  Maybe like a slider?  I am not sure about sliders, I
>have never used them or know how to make them.  Any help or code would
>be appreciated.  Thanks.

Here's a quick one:

Add a scale bar control and position it/size it the way you want. Set its
startPosition to zero and its endPosition to 359. Put this in its script:

on scrollbarDrag newPosition
  set the angle of graphic "My Image" to newPosition
end scrollbarDrag

For this kind of thing, it's better to use the angle property instead of
the rotate command. The scale bar's position shows the current rotation, so
the user expects the rotation to start from there. Using a property means
you can simply directly set the angle according to the currrent position of
the scale bar.


------

Setting the angle of images is a 2.0 feature, so if you're using 1.1.1 it
won't work yet, and the rotate command is too slow to do continuously as
you drag the scale thumb, so you can do something like this instead:

on mouseUp
  lock screen
  if the originalData of image "My Image" is empty
  then set the originalData of image "My Image" to image "My Image"
  else put the originalData of image "My Image" into image "My Image"
  rotate image "My Image" by the thumbPosition of me
  unlock screen
  send "choose browse tool" to me in 1 tick
end mouseUp

The scrollbarDrag message gets sent continuously as you drag the scale
bar's thumb. However, the mouseUp message only gets sent once, not
continuously, so using a mouseUp handler avoids the problem with the rotate
command's slowness. With this, the image doesn't rotate until you let go of
the scroll thumb.

The rotate command distorts the image, and successive rotations make it
worse, so this handler stores the original, unrotated image in a custom
property and restores it every time you rotate. (This is why the screen
needs to be locked: because this handler actually resets the image back to
its original, and then does the rotation, and seeing it flip back to 0
degrees before it rotates to the new position is annoying.)

If the custom property is empty, the handler figures that this is the first
time you've run it, and sets the custom property to the current image
(which should be the original, unrotated image, since this is the first
time you're rotating it).

--
Jeanne A. E. DeVoto ~ jeanne at runrev.com
Runtime Revolution Limited - Software at the Speed of Thought
http://www.runrev.com/





More information about the Use-livecode mailing list