Page 1 of 1
geometry question (how to lock proportions)
Posted: Sat Feb 24, 2007 8:52 pm
by rfarnold
Hello.
I have been using RR for some time but I am making my first stack that requires scaling of interface objects when the stack is resized. Revs solution seems great only I wan objects (images) and the stack itself to retain proportions as they change size. I can't find any means of locking the proportion of the stack or an object. I tried dealing with this using the resizestack message, to change one of the values in proportion to the other, but I couldn' get it to work. Is there some way to lock proportions? if not, shouldn't there be? I am sure someone must have encountered this before, when resizing images. Any help would be much appreciated.
Bob Arnold
Posted: Sat Feb 24, 2007 9:46 pm
by malte
Hi Bob,
I'm afraid you need to script it on your own. Even though the geometry manager does a job for simple layouts, I ended up scripting the geometry bits for all of my stacks.
Concerning your problem:
calculate the with to height ratio of your images and scale them accordingly. You will want to look at the formattedHeight and formattedWidth properties.
If you need any help with the scripting part just let us know.
All the best,
malte
Posted: Sun Feb 25, 2007 1:19 pm
by xApple
Locking proportions for a window that is resizable is really considered not user friendly. It's kinda against the rules. Either the window is resizable with some lower bounds but complete freedom or it is not.
Indeed, if you look around you can't find many windows that do such a thing huh ?
A comprehensive document about what to do or not to do to preserve the user experience can be found here:
http://developer.apple.com/documentatio ... ion_1.html
Just my 2 cents.
Have a nice day.
Posted: Sun Feb 25, 2007 1:31 pm
by xApple
Otherwise here is a script I use for manually setting the location of objects as the stack is resized:
Code: Select all
on resizeStack
lock screen
updateEveryControl
unlock screen
end resizeStack
on updateEveryControl
repeat with x = 1 to the number of cards of this stack
put the objects of card x into cardObjects
repeat with y = 1 to the number of lines of cardObjects
put line y of cardObjects into currentObject
switch the autoPlace of currentObject
case "playMiddle"
put the width of currentObject into objX
put the width of this stack into stackX
put toolHorizSize + (stackX - toolHorizSize)/2 - objX/2 into middlePoint
set the left of currentObject to middlePoint
break
case "bkgndGlue"
set the lockLoc of currentObject to false
set the rect of currentObject to toolHorizSize & ",0," & the width of this stack & comma & the height of this stack
set the lockLoc of currentObject to true
break
end switch
end repeat
end repeat
end updateEveryControl
getProp objects
repeat with x = 1 to number of controls of the target
put the long name of control x of the target & return after myList
end repeat
sort myList
return myList
end objects
Posted: Sun Feb 25, 2007 5:01 pm
by marielle
A resize function I use to guarantee that width and height proportions are always maintained is the one below. It is primarily used on images, but it could be used on any control.
Code: Select all
function image.resize pImgRef, pRatio, pOriginalWidth, pOriginalHeight
-------------
if not exists(pImgRef) then exit image.resize
if pRatio is not a number then exit image.resize
if pRatio < 0 then exit image.resize
if pOriginalWidth is not an integer then exit image.resize
if pOriginalHeight is not an integer then exit image.resize
... any other data validation ...
--------------
put the loc of pImgRef into tLoc
--------------
lock screen
put max(100,(pOriginalHeight*(pRatio/100))) into tNewH
put tNewH/pOriginalHeight into pRatio
put pOriginalWidth*pRatio into tNewW
----
set the width of pImgRef to tNewW
set the height of pImgRef to tNewH
set the loc of pImgRef to tLoc
------
unlock screen
end image.resize
Note that pImgRef holds a value like (the long id of image 1 of card x of stack y).
You are very much welcome to improve on this.
Ah, yes, I had a few more function to handle cases where you want to resize such that the control is guaranteed to fill a given bounding rectangle or such that the picture is made smaller only if larger than a given bounding rectangle. The function below don't manipulate any object directly. They only return the new dimensions after rescaling.
Code: Select all
#####################################################
function scale.withinBoudingRect pW, pH, pMaxW, pMaxH
put pW,pH into tDim
-----------------
if (pW > pMaxW) or (pH > pMaxH) then
put scale.touchingBoudingRect(pW, pH, pMaxW, pMaxH) into tDim
end if
return tDim
end scale.withinBoudingRect
#####################################################
function scale.touchingBoudingRect pW, pH, pMaxW, pMaxH
IF max(pW,pH) = pW THEN
put (pMaxW / pW) into tRatio
ELSE
put (pMaxH / pH) into tRatio
END IF
return scale.ratio(pW, pH, tRatio)
end scale.touchingBoudingRect
#####################################################
function scale.ratio pW, pH, pRatio
return round(pW * pRatio), round(pH * pRatio)
end scale.ratio
Feel free to improve on any of this. If you do, simply post your code back here.
Marielle
Posted: Mon Feb 26, 2007 8:45 pm
by BIX
to resize stack with locked proportions you can use:
Code: Select all
on resizeStack
set height of me to width of me / 1.333333
end resizeStack
it looks bad but it works