Page 1 of 1
Restricting resize of stack by aspect ratio
Posted: Sat Nov 28, 2015 3:59 pm
by pink
This is 2 seperate yet related questions:
1. Can you restrict the resizing of a window/stack to maintain the aspect ratio?
For example, say I've got a square window, and I want it to remain a square with equal sides regardless of how big or small the user makes it
2. Can you restrict resizing of a window/stack within certain ratios?
For example, I have a stack and I want the user only to be able to resize between 4:3 and 16:9
Re: Restricting resize of stack by aspect ratio
Posted: Sun Nov 29, 2015 2:41 am
by Simon
Hi Greg,
This question was recently answered by Scott Rossi but.... I can't find it!
I've spent a fair bit of time searching for it.
He has a demo stack that does exactly what you want (it's not in his demo pages but it was a "go url..." thingy).
Why didn't I save a copy
Simon
Re: Restricting resize of stack by aspect ratio
Posted: Sun Nov 29, 2015 12:07 pm
by bn
Hi Greg, Simon,
how to keep the aspect ratio of a stack:
http://runtime-revolution.278305.n4.nab ... 98910.html
Kind regards
Bernd
Re: Restricting resize of stack by aspect ratio
Posted: Sun Nov 29, 2015 12:12 pm
by Simon
Thanks Bernd!
I'm not insane then. I have to remember which board I'm on.
Simon
Re: Restricting resize of stack by aspect ratio
Posted: Sun Nov 29, 2015 12:51 pm
by bn
Hi Simon,
I'm not insane then
no, I guess just a little tired. What time is it over there?
Kind regards
Bernd
Re: Restricting resize of stack by aspect ratio
Posted: Sun Nov 29, 2015 1:58 pm
by pink
Thanks, that is exactly what I needed.
Re: Restricting resize of stack by aspect ratio
Posted: Sun Nov 29, 2015 9:34 pm
by richmond62
I read this late, and thought I'd "have a bash", and here is my, dead simple method
in the stackScript of a stack called "SQUARE":
on resizeStack
put the width of stack "SQUARE" into WIDD
put the height of stack "SQUARE" into HITE
if (WIDD < HITE) then
set the height of stack "SQUARE" to WIDD
else
set the width of stack "SQUARE" to HITE
end if
end resizeStack
Re: Restricting resize of stack by aspect ratio
Posted: Sun Nov 29, 2015 9:43 pm
by richmond62
And for a 16:9 ratio in a stack called "RATIO":
on resizeStack
put the width of stack "RATIO" into WIDD
set the height of stack "RATIO" to (WIDD * (9 /16))
end resizeStack
This ONLY works for width.
Re: Restricting resize of stack by aspect ratio
Posted: Sun May 01, 2016 3:34 am
by sturgis
Heres my take on this.. Its set up to resize a graphic, but could be adapted for a stack.
To test, open a stack and place 2 rectangles on it. Name one "maskRect' the other "dragRect"
Group them and name the group "maskG", then paste the script into the group.
Code: Select all
local sSizing,sSlope,sMinSize
on mouseDown
if the short name of the target is among the items of "dragRect,maskrect" then
put 4 into x -- define x for ratio calc
put 3 into y -- define y for ration calc
--to constrain to 16x9 set x to 16, y to 9
-- define minimum size of the graphic
put 100 into sMinSize
put y/x into sSlope -- calc the slope. consider the first point to be 0,0 so the slope is just y of the second point / x of the second point.
-- set the flag
put the short name of the target into sSizing
else
clearflag
pass mousedown
end if
end mouseDown
command clearflag
put empty into sSizing
end clearflag
on mouseup
clearflag
end mouseup
on mouserelease
clearFlag
end mouserelease
on mousemove x,y
lock screen
if sSizing is "dragRect" then
-- get the upper left, x and y of the grc
put the top of grc "maskRect" of me into ty
put the left of grc "maskRect" of me into tx
-- put the x of the mouseloc into tx2
put x into tx2
### Can't shrink below specified size
if x - sMinSize < tx then
put sMinSize + tx into tx2
-- adjust tx2 to avoid making the grc smaller than desired
end if
--calculate ty2 and adjust for the offset from 0 (+ ty)
put (sSlope * tx2 - tx) + ty into ty2
-- set the positions of the maskrect and the dragrect
set the rect of grc "maskRect" of me to tx,ty,tx2,ty2
set the bottomright of grc "dragRect" of me to tx2,ty2
else if sSizing is "maskrect" then
grab group "maskG"
end if
unlock screen
end mousemove
I'm working on a project that uses something similar to this. This version is simplified, the other project is constrained to an area when resizing. If x or y hit the boundary, resizing stops and I move the graphic away from the "wall" then continue resizing. Does anyone have a better way? I can post a sample stack if that would help. (I'm resizing graphics, not stacks, but the premise is the same)
I'm thinking of adding a second resizing handle to make things simple, but wonder what others are doing?
The project this is for is interesting (to me.) I have a raspberry pi set up as a wireless hotspot with dhcp server with a raspicam. My app can tell the pi to take a pic, which I then grab and shove into the "current" image. When the next picture is taken, the previous image is moved to a holding container, and the most recent is placed into the app. At that point the user can start them flipping, which makes differences between the two images extremely obvious.
The "mask" will be used to define a "region of interest" (ROI on the pi using raspistill) so that the pi only sends the portion of the image the user is interested in. I'm about to integrate the mask so that I can tell the pi what to send back. So far things are working pretty well. I love pi!