Restricting resize of stack by aspect ratio

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Restricting resize of stack by aspect ratio

Post by pink » Sat Nov 28, 2015 3:59 pm

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
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Restricting resize of stack by aspect ratio

Post by Simon » Sun Nov 29, 2015 2:41 am

Hi Greg,
This question was recently answered by Scott Rossi but.... I can't find it! :x
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 :roll:

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Restricting resize of stack by aspect ratio

Post by bn » Sun Nov 29, 2015 12:07 pm

Hi Greg, Simon,

how to keep the aspect ratio of a stack:
http://runtime-revolution.278305.n4.nab ... 98910.html

Kind regards

Bernd

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Restricting resize of stack by aspect ratio

Post by Simon » Sun Nov 29, 2015 12:12 pm

Thanks Bernd!
I'm not insane then. I have to remember which board I'm on.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Restricting resize of stack by aspect ratio

Post by bn » Sun Nov 29, 2015 12:51 pm

Hi Simon,
I'm not insane then
no, I guess just a little tired. What time is it over there? :)

Kind regards
Bernd

pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Re: Restricting resize of stack by aspect ratio

Post by pink » Sun Nov 29, 2015 1:58 pm

Thanks, that is exactly what I needed.
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Restricting resize of stack by aspect ratio

Post by richmond62 » Sun Nov 29, 2015 9:34 pm

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
Attachments
SQUARE.livecode.zip
Here's the stack to play with.
(14.81 KiB) Downloaded 256 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Restricting resize of stack by aspect ratio

Post by richmond62 » Sun Nov 29, 2015 9:43 pm

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.
Attachments
RATIO.livecode.zip
Here's the stack so you can play with it.
(7.64 KiB) Downloaded 234 times

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Restricting resize of stack by aspect ratio

Post by sturgis » Sun May 01, 2016 3:34 am

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!

Post Reply