Sign in to follow this  
Followers 0
CodeMaster Rapture

AutoIt Style Fade Effect!

3 posts in this topic

Hello everyone!

I brought you yet another nifty function. This time I've learned from yall and provided extensive error checking. Thank you everyone who gave me hints and tips on my StringStrip function.

Now, on to the yummies!!!!

#cs
************************************************************************************************
Author: CodeMaster Rapture

Script Function:
    Fades a window in or out if the OS supports it.
Usage:
    Fade(Window Title [,Fade in/out, Speed])
Parameters:
    Window Title -------- The name of the window to be faded.
    Fade in/out ---------- A value of 1 (default) will fade in, a value of 0 will fade out. 
    Speed ---------------- How fast the window fades from 1 (slowest) to 10 (fasest and default)
************************************************************************************************
#ce

Func Fade($Window, $Fade = 1, $Speed = 10)
;Error Checking
    If (NOT IsInt($Fade)) OR (($Fade <> 1) AND ($Fade <> -1)) Then
        MsgBox(16, "Error", "Illegal call to Fade Function: $Fade only allows integers of 1 or -1.")
        Exit
    ElseIf (NOT WinExists($Window)) Then
        MsgBox(16, "Error", "Could not find Window titled: " & $Window & ". Exiting.")
        Exit
    ElseIf (NOT IsString($Window)) Then
        MsgBox(16, "Error", "Illegal call to Fade Function: $Window must be a string.")
        Exit
    ElseIF ($Window == "") Then
        MsgBox(16, "Error", "Illegal call to Fade Function: No Window specified.")
        Exit
    ElseIf (NOT IsNumber($Speed)) Then
        MsgBox(16, "Error", "Illegal call to Fade Function: $Speed must be a number.")
        Exit
    ElseIf ($Speed < 1) Then
        $Speed = 1)
    ElseIf ($Speed > 10) Then
        $Speed = 10
    EndIf

;Begin Fade Effect
    WinSetTrans($Title, "", 255)
    If NOT @error Then  ;If the OS doesn't supporty Transparencies, don't fade.
        If $Fade = 1 Then
        ;Fade-In
            For $loop = 1 to 255 Step 1
                WinSetTrans($Title, "", $loop)
                Sleep(10-$Speed)
            Next
        Else
        ;Fade-Out
            For $loop = 255 to 1 Step -1
                WinSetTrans($Title, "", $loop)
                Sleep(10-$Speed)
            Next
        EndIf
    EndIf
EndFunc

Enjoy!

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0