Stupid Question Again - Proportional Scaling

Peter Reid preid at reidit.co.uk
Sun Mar 18 16:13:03 CET 2018


Hi Jacqueline & hh

Thanks for the feedback. After I sent my query I came across a relevant response in the forum:

https://forums.livecode.com/viewtopic.php?t=30385

In particular MaxV's response which is very similar to yours Jacqueline. When I tried this I too realised that I'd need a "send" to tidy-up afterwards!

Here's my complete code (all in the stack script):

local tAdjustingStack

on resizeStack
   if not tAdjustingStack then
      put the top of image "myImage" into tTop
      put the left of image "myImage" into tLeft
      put the realSize of image "MyImage" into tSize
      put the startsizeStack of image "myImage" into tSS
      set the width of image "myImage" to (item 1 of tSize * the width of this stack / item 1 of tSS )
      set the height of image "myImage" to (item 2 of tSize * the height of this stack / item 2 of tSS )
      if the width of image "myImage" > the height of image "myImage" then
         set the width of image "myImage" to (item 1 of tSize / item 2 of tSize * the height of image "myImage")
      else
         set the height of image "myImage" to (item 2 of tSize / item 1 of tSize * the width of image "myImage")
      end if
      set the top of image "myImage" to tTop
      set the left of image "myImage" to tLeft
   end if
   pass resizeStack
end resizeStack

on tidyUpAfterwards
   put the topLeft of this stack into tTL
   if the width of this stack <> the width of image "myImage" then
      lock screen
      put true into tAdjustingStack
      set the width of this stack to the width of image "myImage"
      set the topLeft of this stack to tTL
   end if
   if the height of this stack <> the height of image "myImage" then
      lock screen
      put true into tAdjustingStack
      set the height of this stack to the height of image "myImage"
      set the topLeft of this stack to tTL
   end if
   unlock screen
   put false into tAdjustingStack
   send "tidyUpAfterwards" to me in 5 ticks
end tidyUpAfterwards

on preOpenStack
   put false into tAdjustingStack
   set the realsize of image "myImage" to (the width of image "myImage", the height of image "myImage")
   set the startSizeStack of image "myImage" to (the width of this stack, the height of this stack) 
   send "tidyUpAfterwards" to me in 5 ticks
end preOpenStack

It's a pity that this proved a bit more convoluted than perhaps it should have been.

Thanks again.

Peter
--
Peter Reid
71 Leconfield Road, Loughborough, Leics. LE11 3SP, UK
Tel: +44 (0)1509 268843
Mobile/Cell: 07778 632533
Email: peter at reidit.net

> Message: 1
> Date: Sat, 17 Mar 2018 17:14:36 +0000
> From: Peter Reid <preid at reidit.co.uk>
> To: use-livecode at lists.runrev.com
> Subject: Stupid Question Again - Proportional Scaling
> Message-ID: <6DE66FAC-C1BC-4F32-8186-B76D769D791C at reidit.co.uk>
> Content-Type: text/plain;	charset=utf-8
> 
> I know it's possible and I know it's simple really, but I can't remember it/figure it out!
> 
> I have a sub-stack that contains an image.  I want the user to be able to drag the corners and edges of the sub-stack window to make the window and its image larger or smaller, but the window and image must maintain their original aspect ratio ? no stretching, no empty borders etc.  I've tried the following in the card script:
> 
> global gImageRatio
> 
> on resizeStack pNewWidth, pNewHeight, pOldWidth, pOldHeight
>   propSizeImage "coinSet", gImageRatio
>   pass resizeStack
> end resizeStack
> 
> on propSizeImage pImageName, @pImageRatio
>   put the width of this stack into propWidth
>   set the width of image pImageName to propWidth 
>   put propWidth div pImageRatio into propHeight
>   put the width of image pImageName into tWidth
>   put the height of image pImageName into tHeight
>   if propHeight > tHeight then
>      put tHeight into propH
>      put tHeight * pImageRatio into propW
>   else if propHeight < tHeight then
>      put propHeight into propH
>      put propH * pImageRatio into propW
>   else
>      put tWidth into propW
>      put tHeight into propH
>   end if
>   set the height of image pImageName to propH 
>   set the width of image pImageName to propW 
>   set the height of this stack to propH 
>   set the width of this stack to propW
>   set the topLeft of image pImageName to 0,0
> end propSizeImage
> 
> with the following initialisation in the stack script:
> 
> global gImageRatio
> 
> on preOpenStack
>   put the width of image "CoinSet" / the height of image "CoinSet" into gImageRatio
> end preOpenStack
> 
> I'm probably missing something obvious, but can anyone help please?!
> 
> Thanks
> 
> Peter
> --
> Peter Reid
> Loughborough, UK
> 
> ------------------------------
> 
> Message: 10
> Date: Sun, 18 Mar 2018 01:04:19 -0500
> From: "J. Landman Gay" <jacque at hyperactivesw.com>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Re: Stupid Question Again - Proportional Scaling
> Message-ID: <82c5cec5-1b64-6690-60e0-dfce7a1784b7 at hyperactivesw.com>
> Content-Type: text/plain; charset=utf-8; format=flowed
> 
> On 3/17/18 12:14 PM, Peter Reid via use-livecode wrote:
>> I have a sub-stack that contains an image.  I want the user to be able
>> to drag the corners and edges of the sub-stack window to make the window
>> and its image larger or smaller, but the window and image must maintain
>> their original aspect ratio ? no stretching, no empty borders etc.
> 
> 
> I wish we had a way to determine when a stack resize is finished. The 
> best I could do is run a "send" loop to check the mouse state. Maybe 
> someone else knows a better way. It doesn't seem possible to change the 
> stack size within a resizeStack handler, which makes sense, so the 
> adjustment has to be done afterward.
> 
> I think this sort of does what you want, but there's a "snap" at the end 
> when the stack adjusts to the new image size. It accomodates images of 
> any orientation.
> 
> 
> constant kImgName = "coinSet"
> 
> on resizeStack pNewWidth, pNewHeight, pOldWidth, pOldHeight
>   put the formattedWidth of img kImgName into tFWidth
>   put the formattedHeight of img kImgName into tFHeight
>   if tFHeight > tFWidth then
>     resizeToHeight tFHeight,tFWidth
>   else
>     resizeToWidth tFHeight,tFWidth
>   end if
>   checkResizeDone
> end resizeStack
> 
> on resizeToHeight tOrigImgHeight,tOrigImgWidth
>   put the height of this cd/tOrigImgHeight  into tRatio
>   put (tOrigImgWidth * tRatio) into tNewWidth
>   put (tOrigImgHeight * tRatio) into tNewHeight
>   set the rect of img kImgName to 0,0,tNewWidth,tNewHeight
> end resizeToHeight
> 
> on resizeToWidth tOrigImgHeight,tOrigImgWidth
>   put the width of this cd into tW
>   put tW/tOrigImgWidth into tRatio
>   put (tOrigImgWidth * tRatio) into tNewWidth
>   put (tOrigImgHeight * tRatio) into tNewHeight
>   set the rect of img kImgName to 0,0,tNewWidth,tNewHeight
> end resizeToWidth
> 
> on checkResizeDone
>   if the mouse is up then
>     set the rect of this stack to \
>       (globalLoc(the topleft of img kImgName) &comma& globalLoc(the 
> bottomright of img kImgName))
>   else
>     send "checkResizeDone" to me in 100 milliseconds
>   end if
> end checkResizeDone
> 
> -- 
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
> 
> ------------------------------
> 
> Message: 11
> Date: Sun, 18 Mar 2018 07:13:55 +0100
> From: hh <hh at hyperhh.de>
> To: use-livecode at lists.runrev.com
> Subject: Re: Stupid Question Again - Proportional Scaling
> Message-ID: <B74D143D-82B2-4198-98F3-ACD5DC38F8D7 at hyperhh.de>
> Content-Type: text/plain; charset=us-ascii
> 
> For proportional resizing a stack window
> hold the shiftkey down when resizing.
> 
> ------------------------------
> 
> Message: 12
> Date: Sun, 18 Mar 2018 07:26:05 +0100
> From: hh <hh at hyperhh.de>
> To: use-livecode at lists.runrev.com
> Subject: Re: Stupid Question Again - Proportional Scaling
> Message-ID: <5BE02282-3168-480E-8675-F45458671AE9 at hyperhh.de>
> Content-Type: text/plain; charset=us-ascii
> 
> [Sorry lost above half of my answer.]
> 
> You could try the following with user's interaction:
> 
> For proportional resizing a stack window
> hold the shiftkey down when resizing.
> 
> And in card's script add
> 
> on resizestack w,h
>  set rect of img 1 to (0,0,w,h)
> end resizestack
> 
> ------------------------------
> 
> Message: 13
> Date: Sun, 18 Mar 2018 02:11:10 -0500
> From: "J. Landman Gay" <jacque at hyperactivesw.com>
> To: How to use LiveCode <use-livecode at lists.runrev.com>
> Subject: Re: Stupid Question Again - Proportional Scaling
> Message-ID: <baf88d2c-d354-6dec-b1ca-98c2912f8836 at hyperactivesw.com>
> Content-Type: text/plain; charset=utf-8; format=flowed
> 
> On 3/18/18 1:26 AM, hh via use-livecode wrote:
>> [Sorry lost above half of my answer.]
>> 
>> You could try the following with user's interaction:
>> 
>> For proportional resizing a stack window
>> hold the shiftkey down when resizing.
>> 
>> And in card's script add
>> 
>> on resizestack w,h
>>   set rect of img 1 to (0,0,w,h)
>> end resizestack
> 
> If Peter doesn't mind instructing his users to use the shift key, this 
> would be a good solution.
> 
> -- 
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list