Scale to Window

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
egolombek
Posts: 74
Joined: Thu Jan 30, 2020 2:11 pm

Scale to Window

Post by egolombek » Fri Jul 24, 2020 8:55 am

Hello all!

Setting the fullScreenMode to exactFit is nice for scaling an application to the full screen, but is there an equivalent way to scale it to the window. I.e. when the window is resized, it scales to the window?

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

Re: Scale to Window

Post by richmond62 » Fri Jul 24, 2020 10:09 am

Presumably you are referring to handhelds?

Now, pardon my ignorance, but on my cheap-and-nasty ASUS Android thing a window and the screen seem to
coincide exactly: to the extent that I don't think that I have ever seen a 'window' at all.

So, if you could elaborate a bit that would be very helpful.
when the window is resized, it scales to the window
Not sure at all what that means, but it does seem a bit circular.

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Scale to Window

Post by mrcoollion » Fri Jul 24, 2020 11:38 am

You could try the scaleFactor option (only for mac, windows, Linux ,see dictionary)

Code: Select all

-- scales the stack to half size
set the scaleFactor of stack "myLargeStack" to 0.5
Regards,

Paul

egolombek
Posts: 74
Joined: Thu Jan 30, 2020 2:11 pm

Re: Scale to Window

Post by egolombek » Fri Jul 24, 2020 12:56 pm

I'm not talking about handhelds, for the reason you mentioned -- screensize IS the window.

I'll check out the scalefactor property. Thanks. I have used it before so that I can see a project where the stack is larger than my screen, but haven't used it from a script.

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

Re: Scale to Window

Post by richmond62 » Fri Jul 24, 2020 2:16 pm

Well I'd just do some fairly simple Maths involving the screenRect and the height and width of the stack.

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Scale to Window

Post by mrcoollion » Fri Jul 24, 2020 5:54 pm

I used it to enable the user to select a size.
LC_PrntScrnScale.png
Print Screen

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Scale to Window

Post by bwmilby » Fri Jul 24, 2020 11:54 pm

I think what you are after is the resizeStack handler. There are 2 ways to handle having a stack handle adjustments of the widow size. You can manually write the resizeStack handler which is called whenever the size is changed (there are plenty of threads discussing this). The other option is to use the Geometry Manager and let the engine take care of it for you. The GM works well with simple layouts, but some things are actually easier to do by hand (especially if you are dealing with a large number of objects). It seems to have a bad reputation, but I think it works fine if you understand the limitations and how it works.

One note of caution: Whenever starting to deal with resizing, be sure to save often (and before invoking the resize handlers). Even better to keep multiple revisions. More than once I had something wrong with my code and when I adjusted the window size everything went so bad that I had to revert to the last saved stack (opening with messages locked may be needed in this case).

If you have any specific questions along these lines, I'm sure that we can help.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

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

Re: Scale to Window

Post by richmond62 » Sat Jul 25, 2020 9:27 am

Code: Select all

on mouseUp
   put (the width of this stack) & "," & (the height of this stack) into fld "OD"
 put (the width of this stack) into WIDD
 put (the height of this stack) into HITE
   put item 3 of the screenRect into SW
   put SW/WIDD into WPROP
   put item 4 of the screenRect into SH
   put SH/HITE into HPROP
   ----
   if WIDD/HITE > 1 then
      set the width of this stack to SW
      set the height of this stack to HITE*WPROP
      set the topleft of this stack to 0,0
   else
      set the height of this stack to SH
      set the width of this stack to WIDD*HPROP
      set the topleft of this stack to 0,0
      end if
   ----
end mouseUp
Attachments
Scaler.livecode.zip
Here's the stack.
(1.16 KiB) Downloaded 164 times

egolombek
Posts: 74
Joined: Thu Jan 30, 2020 2:11 pm

Re: Scale to Window

Post by egolombek » Sat Jul 25, 2020 7:28 pm

These are some interesting approaches. Here's what I came up with:

on resizeStack

put 1282 into sw
put 650 into sh

put the left of this stack into l
put the top of this stack into t

put the scaleFactor of this stack into ss
put the width of this stack into ww
put the height of this stack into hh

put ww*ss/sw into nsfw
put hh*ss/sh into nsfh

if abs(nsfw-ss)>abs(nsfh-ss) then put nsfw into nsf else put nsfh into nsf
set the width of this stack to sw
set the height of this stack to sh
set the scaleFactor of this stack to nsf
if l<1 then set the left of this stack to 1 else set the left of this stack to l
if t<1 then set the top of this stack to 1 else set the top of this stack to t

end resizeStack
It seems to work except for the very weird fact that the resizeStack handler seems to get sent 3-8 times every time I resize the window. It is a very awkward effect. Is there a way to tell the script not to run until the user has finished the resizing? The documentation on resizeStack suggests that this should be the effect, but in reality, it does not seem to be so.

egolombek
Posts: 74
Joined: Thu Jan 30, 2020 2:11 pm

Re: Scale to Window

Post by egolombek » Sat Jul 25, 2020 7:51 pm

Just found a genius solution in a 2014 forum post. The script now works!
on reStack
if "reStack" is in the pendingMessages then exit reStack

put 1282 into sw
put 650 into sh

put the left of this stack into l
put the top of this stack into t

put the scaleFactor of this stack into ss
put the width of this stack into ww
put the height of this stack into hh

put ww*ss/sw into nsfw
put hh*ss/sh into nsfh

if abs(nsfw-ss)>abs(nsfh-ss) then put nsfw into nsf else put nsfh into nsf
set the width of this stack to sw
set the height of this stack to sh
set the scaleFactor of this stack to nsf
if l<1 then set the left of this stack to 1 else set the left of this stack to l
if t<1 then set the top of this stack to 1 else set the top of this stack to t

end reStack

on resizeStack
send "reStack" to me in 1 millisecs
end resizeStack

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”