Scale to Window
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Scale to Window
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?
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?
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Scale to Window
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.
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.
Not sure at all what that means, but it does seem a bit circular.when the window is resized, it scales to the window
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Scale to Window
You could try the scaleFactor option (only for mac, windows, Linux ,see dictionary)
Regards,
Paul
Code: Select all
-- scales the stack to half size
set the scaleFactor of stack "myLargeStack" to 0.5
Paul
Re: Scale to Window
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.
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.
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Scale to Window
Well I'd just do some fairly simple Maths involving the screenRect and the height and width of the stack.
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Scale to Window
I used it to enable the user to select a size.
Re: Scale to Window
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.
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
Script Tracker https://github.com/bwmilby/scriptTracker
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Scale to Window
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
Re: Scale to Window
These are some interesting approaches. Here's what I came up with:
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.
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
Re: Scale to Window
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