[Code Snippet] Tombalachi's Hiding Menu Script Revised

https://www.wincustomize.com/skins.aspx?skinid=2903&libid=3
As I use Tombalachi's Hiding Menu Script  quite a bit I've revised and cut 20 lines of code. Since his email seems to be dead I thought I'd post my revised script here. My suggestion is to download his original in order to understand this a bit better.

Code: vbscript
  1. '--Note the With Statement is only used where the savings are obvious   
  2.     '----------CUSTOMIZE HERE----------
  3. Const    hideTop = -160,hideLeft = -160,hideSpeed = 10,hideDelay = 700,_
  4.             showTop = -50,showLeft = 0,showSpeed = 16
  5.     '-----------END CUSTOMIZE----------
  6. Dim delay
  7. 'Called when the script is executed
  8. Sub Object_OnScriptEnter
  9.     delay = 0
  10.     'Timer for hiding the object
  11.     Object.SetTimer 4321, 100
  12. End Sub
  13. 'Called when the script is terminated
  14. Sub Object_OnScriptExit
  15.     Object.KillTimer 4321
  16.     Object.KillTimer 1234
  17. End Sub
  18. Sub Object_OnStateChange(state)
  19. With Object
  20.     If state = "Mouse over" Then
  21.         'Kill the hide timer
  22.         .KillTimer 4321
  23.         'Start the show timer
  24.         .SetTimer    1234, 100
  25.     Else
  26.         'Kill the show timer
  27.         .KillTimer 1234
  28.         'Start the kill timer
  29.         .SetTimer 4321, 100
  30.     End If
  31. End With
  32. End Sub
  33. Sub Object_OnTimer1234
  34. 'Show the object
  35.         Call MoveIt(showTop, showLeft, showSpeed)
  36.     If (Object.Top = showTop) And (Object.Left = showLeft) Then
  37.         delay = hideDelay
  38.     End If
  39. End Sub
  40. Sub Object_OnTimer4321
  41. 'Hide the object
  42.     If delay <> 0 Then
  43.         'We wait until delay is over
  44.         delay = delay - 100
  45.     Else
  46.         Call MoveIt(hideTop, hideLeft, hideSpeed)
  47.     End If
  48. End Sub
  49. Sub MoveIt(destTop, destLeft, speed)
  50. With Object
  51.     'Are we there yet?
  52.     If (.Top <> destTop) Or (.Left <> destLeft) Then
  53.         'Go ahead and hide
  54.         Dim diffTop,diffLeft,distance,speedTop,speedLeft
  55.        
  56.         diffTop = destTop - .Top
  57.         diffLeft = destLeft - .Left
  58.         distance = (diffTop^2 + diffLeft^2)^0.5
  59.         speedTop = speed * diffTop / distance
  60.         speedLeft = speed * diffLeft / distance
  61.        
  62.         If Abs(speedTop) > Abs(diffTop) Then
  63.             speedTop = diffTop
  64.         End If
  65.         If Abs(speedLeft) > Abs(diffLeft) Then
  66.             speedLeft = diffLeft
  67.         End If
  68.        
  69.         .Move .Left + speedLeft, .Top + speedTop
  70.     End If
  71. End With
  72. End Sub



1,422 views 0 replies