AnimateResize

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Emily-Elizabeth
Posts: 101
Joined: Mon Jan 03, 2022 7:10 pm

AnimateResize

Post by Emily-Elizabeth » Sat Feb 12, 2022 2:25 am

Place the following code into the stack script of a library stack.
This will animate the resizing of a window. For those that use macOS think of the System Preferences when switching between preferences. I can only test on macOS.

Usage:
AnimateResize the long id of stack, newWidth, newHeight
AnimateResizeStop

Code: Select all

// converted from stackoverflow[DOT]com/questions/1769317/animate-window-resize-width-and-height-c-sharp-wpf


local mNewWidth
local mNewHeight
local mWinID
local mWinLeft
local mWinTop
local mAnimateResizeStop
local mAnimateResizeRatioHeight
local mAnimateResizeRatioWidth
local mAnimateResizeMessageID


on AnimateResize winID, newWidth, newHeight
   if (word 1 of winID = "stack") then
      put winID into mWinID
      put the left of winID into mWinLeft
      put the top of winID into mWinTop
      put newWidth into mNewWidth
      put newHeight into mNewHeight
      send "AnimateResizeTick" to me in 20 milliseconds
      put the result into mAnimateResizeMessageID
   end if
end AnimateResize


on AnimateResizeStop
   cancel mAnimateResizeMessageID
end AnimateResizeStop


on AnimateResizeTick
   if (mAnimateResizeStop = 0) then
      put (((the height of mWinID - mNewHeight) / 12) * -1) into mAnimateResizeRatioHeight
      put (((the width of mWinID - mNewWidth) / 12) * -1) into mAnimateResizeRatioWidth
   end if
   add 1 to mAnimateResizeStop
   
   lock screen
   set the height of mWinID to (the height of mWinID + mAnimateResizeRatioHeight)
   set the width of mWinID to (the width of mWinID + mAnimateResizeRatioWidth)
   set the topLeft of mWinID to mWinLeft, mWinTop
   unlock screen
   
   send "AnimateResizeTick" to me in 20 milliseconds
   put the result into mAnimateResizeMessageID
   
   if (mAnimateResizeStop = 12) then
      cancel mAnimateResizeMessageID
      lock screen
      set the height of mWinID to mNewHeight
      set the width of mWinID to mNewWidth
      set the topLeft of mWinID to mWinLeft, mWinTop
      unlock screen
      
      put 0 into mAnimateResizeStop
      put 0 into mAnimateResizeRatioHeight
      put 0 into mAnimateResizeRatioWidth
      put 0 into mNewHeight
      put 0 into mNewWidth
      put 0 into mWinID
      put 0 into mWinLeft
      put 0 into mWinTop
   end if
end AnimateResizeTick
Last edited by Emily-Elizabeth on Sat Feb 12, 2022 9:08 pm, edited 1 time in total.

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

Re: AnimateResize

Post by dunbarx » Sat Feb 12, 2022 5:36 pm

Another blockBuster from the mysterious Emily.

Where has she been all our lives?

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: AnimateResize

Post by bn » Sat Feb 12, 2022 5:40 pm

Thank you Elisabeth for this very nice piece of code. It works well.

I would just add a lock screen to the final setting of the dimensions of the stack right after this:

Code: Select all

if (mAnimateResizeStop = 12) then
      cancel mAnimateResizeMessageID
This avoids the final "jump"

And handler "AnimateResizeStop" seems not to be used.

Again thanks for this

Kind regards
Bernd

Emily-Elizabeth
Posts: 101
Joined: Mon Jan 03, 2022 7:10 pm

Re: AnimateResize

Post by Emily-Elizabeth » Sat Feb 12, 2022 9:11 pm

I edited the above code to include the Lock Screen, as mentioned by Bernd.
The AnimateResizeStop handler is to be used by the developer incase the window is being closed mid-resized. You would call it from the 'closeStack' message handler.

Post Reply

Return to “Talking LiveCode”