OK... Thanks to the brainstrust, we have an answer on this one.
For whatever reason, when you scale an image and then rotate it, or rotate an image and scale it, there is a degree of distortion that occurs unless some specific steps are taken in the operation. As long-winded as these are, they work to scale and rotate images without loss or distortion.
Below I have provided the code for 2 buttons: SCALE and ROTATE. These will effectively a) scale a rotated image and; b) rotate a scaled image.
These will work around the following issue: images will resize to original when rotated and will distort if the lockloc is set to true.
SCALE:
Code: Select all
on mouseDown
put the cScale of img "V0" into sCurrentScale --this is a custom property for the image that tracks the current scale: 1=100%, 0.5=50% etc. and will need to be set sometime before translating image.
--Gather the current image dimensions, location and rotation
put the width of img "V0" into sWidth
put the height of img "V0" into sHeight
put the loc of img "V0" into sLoc
put the angle of img "V0" into sAngle
--Necessary for the following translation
set the lockloc of img "V0" to true
lock screen
-- Set the new scale. However you want to handle the scaling of the image, do it here and put the new scale value into sScale
put 0.5 into sScale
--Not necessary, but will speed up the redrawing process
set the visible of img "V0" to false
--For whatever reason, the ordering of the following will produce the correct result, despite the fact that the image is derotated, then rotated
set the angle of img "V0" to 0
--Necessary for the following translation
set the lockloc of img "V0" to false
set the angle of img "V0" to sAngle
--Gather the reformatted sized (i.e. reset to imported sized automatically by Livecode)
put the width of img "V0" into sWidth
put the height of img "V0" into sHeight
--Necessary for the following translation
set the lockloc of img "V0" to true
-- Rescale the image to original scale
set the width of img "V0" to (sWidth * sScale)
set the height of img "V0" to (sHeight * sScale)
--Relocate centre to centre
set the loc of img "V0" to sloc
--Not necessary if the set to false was not used earlier
set the visible of img "V0" to true
unlock screen
end mousedown
ROTATE:
Code: Select all
on mouseDown
--Gather information of image about location and rotation
put the loc of img "V0" into sLoc
--I have used a custom property here to track the angle of image, as it suits my other application.
put the cRotation of img "V0" into sValue
--put the angle of img "V0" into sValue --Alternative code
--Necessary for the following translation
set the lockloc of img "V0" to false
--Change the angle. Can be handled many ways, I have just added 5 degrees anti-clockwise rotation
add 5 to sValue
--I track the rotation in the custom property, and ensure it's between 0 and 360 degrees. This is not necessary.
if sValue >360 then set the cRotation of img "V0" to (sValue - 360)
set the cRotation of img "V0" to sValue
lock screen
-- Rotate Image, this will reset the size of the image to imported size!
set the angle of img "V0" to sValue
--Relocate image to original place
set the loc of img "V0" to sLoc
--Necessary for the following translation
set the lockloc of img "V0" to true
-- Rescale the image based on sizes gathered at start of function
-- Gather current size information
put the width of img "V0" into sWdim
put the height of img "V0" into sHdim
--Use custom scale property, as this will not be altered when the image was reset earlier
put the cScale of img "V0" into tScaleValue
--Rescale image to prior size
set the width of img "V0" to (sWdim * tScaleValue)
set the height of img "V0" to (sHdim * tScaleValue)
--Relocate image
set the loc of img "V0" to sloc
unlock screen
end mousedown
I have stripped a lot of the original code I was given and tested it, and this was as tight as I could make it while still working. Any further work to cut it down would be appreciated.
It should be noted that this is not my original code, just an adapted version. Much kudos goes to the original coders, originally by Paul Hibbert (and I am sure someone else, but I can't remember who! SORRY!!!)
XdM