No, on both sizes works.
Scale image proportionally on resizestack
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Scale image proportionally on resizestack
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Scale image proportionally on resizestack
You can use either of these, depending on whether you want to scale the image to fit an existing object, or you want to pass a rectangle's dimensions.
The second version could use the card rect if the image should be the full size of the card. You can also change the last line of the second version to set the loc of the image rather than the topleft if you want. In the app this was for, we needed the topleft to remain stable.
Code: Select all
-- using an object as target rect:
on scaleToFit pImg,pObj -- the image name, the target object
put the formattedheight of img pImg into theFHt
put the formattedwidth of img pImg into theFWd
put max(the height of pObj/theFHt, the width of pObj/theFWd) into theRatio
set the height of img pImg to theFHt*theRatio
set the width of img pImg to theFWd*theRatio
set the loc of img pImg to the loc of pObj
end scaleToFit
-- passing a rect instead:
on scaleToRect pImg,pRect -- the image name, the target rect
put the formattedheight of img pImg into theFHt
put the formattedwidth of img pImg into theFWd
put max((item 4 of pRect - item 2 of pRect)/theFHt, (item 3 of pRect - item 1 of pRect)/theFWd) into theRatio
set the height of img pImg to theFHt*theRatio
set the width of img pImg to theFWd*theRatio
set the topleft of img pImg to item 1 of pRect,item 2 of pRect
end scaleToRect
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Scale image proportionally on resizestack
Got it thanks much.
I got it working but ended up not liking with stack resize effect for this UI so I went with using a slider set with ratios to resize the image contained with some similar code.
Seriously thanks to everyone that posted, this forum has been so helpful I'm nearly finished with the inner workings of my project.
I got it working but ended up not liking with stack resize effect for this UI so I went with using a slider set with ratios to resize the image contained with some similar code.
Seriously thanks to everyone that posted, this forum has been so helpful I'm nearly finished with the inner workings of my project.
Re: Scale image proportionally on resizestack
I am new to LC and am having problems resizing the screens to fit correctly. I have put the following code into my stact script:
on preOpenStack
if the environment is "mobile" then
mobileSetAllowedOrientations "landscape left,landscape right"
set the fullscreenMode of this stack to "noBorder"
end if
end preOpenstack
it still does not scale correctly. Is this the correct syntax and location to place the code? Any help would be appreciated. I just want everything to expand and shrink appropriately to use on various size devices.
thanks. Mike
on preOpenStack
if the environment is "mobile" then
mobileSetAllowedOrientations "landscape left,landscape right"
set the fullscreenMode of this stack to "noBorder"
end if
end preOpenstack
it still does not scale correctly. Is this the correct syntax and location to place the code? Any help would be appreciated. I just want everything to expand and shrink appropriately to use on various size devices.
thanks. Mike
-
- Posts: 253
- Joined: Wed Aug 19, 2015 4:29 pm
Re: Scale image proportionally on resizestack
It's been a while since I did anything on the mobile side of things, but have you tried using "exactfit" instead of "noborder"?
Code: Select all
set the fullscreenMode of this stack to "exactfit"
Re: Scale image proportionally on resizestack
that worked, sot of, but when put into portrait mode, it cuts of the right side of controls which dont fit. it does not scale down to the narrower size. show it not shrink it down when in the portrait mode?
thanks.
Mike
thanks.
Mike
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Scale image proportionally on resizestack
Your script handlers are in the right place, but "exactFit" isn't usually the best choice on mobile. If your stack is in landscape mode, "noBorder" usually works well, and for portrait, "showAll" is best. NoBorder scales the stack so the content height is completely shown, and ShowAll scales the stack to show the complete width of the content. In either case, some edges may be cropped or have empty borders if the screen ratio is different than the stack size ratio.
You can set the correct fullscreenMode on orientationChanged, which is sent before the card redraws.
If you set the stack's backgroundColor or backgroundPattern, the borders won't be too noticable.
The other way of doing it is to avoid fullscreenMode and just calculate new positions for every object on the card and reset their rectangles in a resizeStack handler.
You can set the correct fullscreenMode on orientationChanged, which is sent before the card redraws.
Code: Select all
on orientationChanged
if the fullscreenMode of this stack = "noBorder" then
set the fullscreenMode of this stack to "showAll"
else
set the fullscreenMode of this stack to "noBorder"
end if
end orientationChanged
The other way of doing it is to avoid fullscreenMode and just calculate new positions for every object on the card and reset their rectangles in a resizeStack handler.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Scale image proportionally on resizestack
If you want to put a test stack on your device to see how size/orientation changes are impacted by different fullscreenmodes, I've posted a demo:
https://milby.us/lc/MobileDemo2.livecode
Here's a thread on the list that discusses it:
https://www.mail-archive.com/use-liveco ... 97462.html
https://milby.us/lc/MobileDemo2.livecode
Here's a thread on the list that discusses it:
https://www.mail-archive.com/use-liveco ... 97462.html
Brian Milby
Script Tracker https://github.com/bwmilby/scriptTracker
Script Tracker https://github.com/bwmilby/scriptTracker