Limit stack aspect ratio

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

pderocco
Posts: 44
Joined: Fri May 16, 2008 1:26 am

Limit stack aspect ratio

Post by pderocco » Mon Sep 17, 2018 10:17 am

I'm trying to figure out how to place limits on the aspect ratio of a stack, when the user resizes it. I'd like it to be limited to something between 4:3 and 16:9. I'd like it to accomplish this by reducing the height or the width in order to stay within the limits.

I've tried all sorts of stuff in the resizeStack handler. The thing that comes closest to working is to set the height or width, if the ratio is out of range. But if I maximize the window on a screen that has an 8:5 aspect ratio, which is within the limits, it ends up smaller than the screen in both dimensions, no matter what dimensions the window has before maximizing it. Also, I'd expect doing that to recursively call resizeStack, but it doesn't seem to.

I've also called revChangeWindowSize inside resizeStack, but that does ugly stuff. And I've tried dynamically manipulating maxHeight and maxWidth.

Is there any other way to do this?
Ciao,
Paul

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Limit stack aspect ratio

Post by dunbarx » Mon Sep 17, 2018 4:06 pm

Hi.

I have not played with this, but surely you can (assuming you have a fld 1):

Code: Select all

on resizeStack
   put the rect of this stack into fld 1
end resizeStack
And with the final rect, you can do the math and resize the stack to the ratio you want, including fitting as best as you can into the screenrect.

So is the issue that there is no "reSizeStackEnd" message, that is, you cannot do something automatically when the user is finished with the resize action, because there is no message sent when the action is done? In other words, there is no analog to the "dragEnd" message, for example?

We can do anything, as long as inelegance is not a factor. Write back...

Craig Newman

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Limit stack aspect ratio

Post by jmburnod » Mon Sep 17, 2018 4:32 pm

Hi All,
there is no "reSizeStackEnd" message
Bernd did one 8) :

Code: Select all

local sResizeIsGoingOn = false
on resizeStack
   -- stuff you do inside resizeStack here
   if not sResizeIsGoingOn then
      send checkEndResize to me in 0 milliseconds
      put true into sResizeIsGoingOn
   end if
end resizeStack

on checkEndResize
   --  if not sResizeIsGoingOn then exit checkEndResize
   if the mouse is down then
      send checkEndResize to me in 50 milliseconds
   else
      put false into sResizeIsGoingOn
      wait 2 milliseconds
   end if
end checkEndResize
Best regards
Jean-Marc
https://alternatic.ch

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Limit stack aspect ratio

Post by FourthWorld » Mon Sep 17, 2018 4:52 pm

Operating systems make it easy to handle the contents of a window however you like, but make it harder to introduce non-standard behavior for the window itself.

I've also found that users sometimes use windows for proposes beyond just viewing the content we put in them, such as maximizing them to cover things they find distracting while using an app.

Would simply constraining the contents of the window, leaving the user in control of the window itself, be an option?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Limit stack aspect ratio

Post by dunbarx » Mon Sep 17, 2018 6:09 pm

Bernd did one
I would not characterize that as "inelegant". :wink:

That is what I meant, that there are secret pathways within LC to ferret out such gadgetry.

But, pderocco, is that the issue? To determine when the user has stopped resizing, and get LC to take over?

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Limit stack aspect ratio

Post by richmond62 » Mon Sep 17, 2018 6:54 pm

Something doesn't work here, and I don't quite know why:
on resizeStack NW, NH
put the round of (NW/16) into F1
put (F1*9) into NewH
set the height of me to NewH
pass resizeStack
end resizeStack
I suspect that the "set the width of me to NewH" tips the thing into an endless loop.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Limit stack aspect ratio

Post by richmond62 » Mon Sep 17, 2018 7:15 pm

This works with no obvious problems if one changes the WIDTH of the stack:
Global NewH

on resizeStack
send "mouseDown" to me
end resizeStack

on mouseDown
put the width of me into NW
put the round of (NW/16) into F1
put (F1*9) into NewH
set the height of me to NewH
end mouseDown

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Limit stack aspect ratio

Post by richmond62 » Mon Sep 17, 2018 8:14 pm

Well, it isn't perfect, but it is a lot simpler than all the stuff above:

in the stackScript:
on resizeStack
send "mouseDown" to me
send "mouseUp" to me
pass resizeStack
end resizeStack

on mouseDown
put the width of me into NW
put the round of (NW/16) into F1
put (F1*9) into NewH
set the height of me to NewH
end mouseDown

on mouseUp
put the height of me into NH
put the round of (NH/9) into F2
put (F2*16) into NewW
set the width of me to NewW
end mouseUp

pderocco
Posts: 44
Joined: Fri May 16, 2008 1:26 am

Re: Limit stack aspect ratio

Post by pderocco » Tue Sep 18, 2018 6:02 am

At this point, I'm not interested in having LiveCode fix the aspect ratio when I release the mouse button, because I'm hoping I can get everything inside the window to resize dynamically as I drag, and I don't want it to resize into something really ugly even if temporary. So I'm not looking for a way to detect when it's done resizing.

What I was hoping for was access to what in Windows is called the WM_SIZING message. The OS tells the app "I want to resize to w*h" and the app can ignore it, or can respond with changed w or h. I assume every OS windowing system has some protocol like that.

I created two empty apps and exported them for Windows, Mac, and Linux. The first, aspect-by-set, is an empty stack with the following stack script:

Code: Select all

on resizeStack w, h
  if w > h * 16 div 9 then
    set the width of me to h * 16 div 9
  else if h > w * 3 div 4 then
    set the height of me to w * 3 div 4
  end if
end resizeStack
The second, aspect-by-max, is an empty stack with the following stack script:

Code: Select all

on resizeStack w, h
  set the maxWidth of me to h * 16 div 9
  set the maxHeight of me to w * 3 div 4
end resizeStack
On Windows, aspect-by-set works, but as soon as you try to exceed the aspect ratio, you get flicker as it draws the erroneous border and then erases it. This is tolerable, but looks ugly. (Before, I was having a problem with maximizing it not filling the screen, but that was only because I was running under the IDE, and didn't realize that the IDE redefines "maximizing" to the portion of the screen below the main IDE window. There are a lot of weird, obnoxious things that the IDE does. But this goes away when you build a standalone.) On Windows, aspect-by-max doesn't flicker, but the resize mechanism only reads maxWidth and maxHeight once at the beginning of the drag, and doesn't notice the changes taking place during the drag, so you can only increase the size of the window a little at a time, alternating between horizontal and vertical.

On the Mac, aspect-by-set places no limits on resizing, but if you stretch it too wide or tall, and then move the window around, after a couple of seconds, it notices the error and snaps one dimension back to correct the aspect ratio. This is unusable. On the Mac, aspect-by-max works exactly the way I want it to when I drag, but when I maximize, it naturally only enlarges the window a little.

On Ubuntu Linux, aspect-by-set works just like it does in Windows, with the same ugly but tolerable flicker. On Linux, aspect-by-max works almost the way it does in Windows, but sometimes it's hard to get it to allow me to enlarge the window at all, and I have to really fight with it.

So at this point, I don't see how to get this to work at all on the Mac. I wish that aspect-by-max worked like on the Mac, but there was some other way to temporarily enlarge the limits before a maximize operation takes place.

I may have to abandon the idea of dynamically resizing everything during the drag, and just let it clip everything when reducing the window size, or filling the right and bottom with background color when enlarging it, and then redrawing everything with a new corrected size when the resize is complete, maybe using Jean-Marc's technique.
Ciao,
Paul

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Limit stack aspect ratio

Post by richmond62 » Tue Sep 18, 2018 8:32 am

aspect-by-max

?

Presumably this means you want the stack to be the same size as the screenRect.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Limit stack aspect ratio

Post by Klaus » Tue Sep 18, 2018 1:00 pm

Hi friends,

the trick is NOT to use the "resizestack" message for this, but rather roll your own! :D
The "resizestack" message cannot be overwritten in real-time, as you already have experienced.

Do this:
1. UNcheck "resizable" for your stack
2. Go to -> Menu: Development: Object library
3. Select "Mac or Win style stack resizer"
4. Place that object in the lower right corner in your stack and then
5. Open its script, read it, let it inspire you and then modify as neccessary. 8)

Best

Klaus

pderocco
Posts: 44
Joined: Fri May 16, 2008 1:26 am

Re: Limit stack aspect ratio

Post by pderocco » Wed Sep 19, 2018 12:59 am

richmond62 wrote:
Tue Sep 18, 2018 8:32 am
aspect-by-max
Presumably this means you want the stack to be the same size as the screenRect.
Are you asking about my choice of name? It just means "constrain the aspect ratio by setting maxWidth or maxHeight".

As to screenRect, that's the size of the whole screen. Even when a window is maximized, it is still set to something less than that, to allow for the borders and the title bar.
Ciao,
Paul

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Limit stack aspect ratio

Post by richmond62 » Wed Sep 19, 2018 8:12 am

it is still set to something less than that, to allow for the borders and the title bar.
That is problematic as LiveCode is not very good at "seeing" all the "desktop furniture"
(docks, taskbars, menubars, XFCE panels and so on) that desktop GUI systems offer.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Limit stack aspect ratio

Post by Klaus » Thu Sep 20, 2018 10:19 am

Hm, looks like noone is actually interested in the solution.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Limit stack aspect ratio

Post by richmond62 » Thu Sep 20, 2018 12:41 pm

Well, at least one of the
noone
has spent the last 3 days painting walls
and mounting whiteboards and so on walls as his EFL school was badly in need of
redecoration before the new school year.

That person will be looking at ONE of a number of possible solutions shortly. 8)
the solution
Just a peerie bit dogmatic, forbye.

Post Reply

Return to “Talking LiveCode”