Jump to content

The bouncing button gimic...


PsaltyDS
 Share

Recommended Posts

Just a fun way to make a control bounce while doing something, like an install in progress. The demo bounces a button, but it could be anything:

; Click on progress bar test
#include <guiconstants.au3>

; Global settings
Global $aProgDat[2] = [0, 1] ; [0]=Offset, [1]=Direction
Global $ButtonX = 210, $ButtonY = 30
Opt("GuiOnEventMode", 1)

; Create basic GUI
$GuiId = GUICreate("In-Progress Test", 300, 100, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$LabelId = GUICtrlCreateLabel("Click START to begin:", 10, 40, 180, 20, $SS_Center)
$ButtonId = GUICtrlCreateButton("START", $ButtonX, $ButtonY, 60, 40)
GUICtrlSetOnEvent($ButtonId, "_Button")
GUISetState(@SW_SHOW, $GuiId)
While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Button()
    Switch GUICtrlRead($ButtonId)
        Case "START"
            GUICtrlSetData($LabelId, "Running... click STOP:")
            GUICtrlSetData($ButtonId, "STOP")
            AdlibEnable("_UpdateProg", 100)
        Case "STOP"
            GUICtrlSetData($LabelId, "Click START to begin:")
            GUICtrlSetData($ButtonId, "START")
            GUICtrlSetPos($ButtonId, $ButtonX, $ButtonY)
            AdlibDisable()
    EndSwitch
EndFunc   ;==>_Button

Func _UpdateProg()
    $aProgDat[0] += $aProgDat[1]
    If $aProgDat[0] > 5 Then
        $aProgDat[0] = 4
        $aProgDat[1] = -1
    ElseIf $aProgDat[0] < -5 Then
        $aProgDat[0] = -4
        $aProgDat[1] = 1
    EndIf
    GUICtrlSetPos($ButtonId, $ButtonX, $ButtonY + $aProgDat[0])
EndFunc   ;==>_UpdateProg

:lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This is quite cool. :lmao:

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

cute...

maybe you could make it more of a UDF

Func _UpdateProg($controlID)

$pos = GUICtrlGetPos( $controlID)

etc...

8)

Haven't looked at that yet, the function still needs to know from some Global what the original X, Y, W, and H were for the control. :lmao:

But now behold! The new version bounces a SQUISHY button!

[Crowd Goes Wild]

Sleep(5000)

[/Crowd Goes Wild]

; Click on progress bar test
#include <guiconstants.au3>

; Global settings
Global $aProgDat[3] = [0, 1, 0] ; [0]=Offset, [1]=Direction, [2]=Squish
Global $ButtonX = 210, $ButtonY = 30, $ButtonW = 60, $ButtonH = 40
Opt("GuiOnEventMode", 1)

; Create basic GUI
$GuiId = GUICreate("In-Progress Test", 300, 100, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$LabelId = GUICtrlCreateLabel("Click START to begin:", 10, 40, 180, 20, $SS_Center)
$ButtonId = GUICtrlCreateButton("START", $ButtonX, $ButtonY, $ButtonW, $ButtonH)
GUICtrlSetOnEvent($ButtonId, "_Button")
GUISetState(@SW_SHOW, $GuiId)
While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Button()
    Switch GUICtrlRead($ButtonId)
        Case "START"
            GUICtrlSetData($LabelId, "Running... click STOP:")
            GUICtrlSetData($ButtonId, "STOP")
            AdlibEnable("_UpdateProg", 50)
        Case "STOP"
            GUICtrlSetData($LabelId, "Click START to begin:")
            GUICtrlSetData($ButtonId, "START")
            GUICtrlSetPos($ButtonId, $ButtonX, $ButtonY)
            AdlibDisable()
    EndSwitch
EndFunc   ;==>_Button

Func _UpdateProg()
    If $aProgDat[2] = 0 Then $aProgDat[0] += $aProgDat[1]
    If $aProgDat[0] >= 5 Then
        ; Hit bottom
        $aProgDat[0] = 5 ; stop offset
        $aProgDat[2] += $aProgDat[1] ; Increment squish
        If $aProgDat[2] > 5 Then ; Squish 0 thru 5 then reverse direction
            ; Max squish
            $aProgDat[2] = 5
            ; Reverse direction
            $aProgDat[1] = -1
        EndIf
    ElseIf $aProgDat[0] <= -5 Then
        ; Hit top
        $aProgDat[0] = -5 ; stop offset
        $aProgDat[2] -= $aProgDat[1] ; increment squish
        If $aProgDat[2] > 5 Then ; Squish 0 thru 5 then reverse direction
            ; Max squish
            $aProgDat[2] = 5
            ; Reverse direction
            $aProgDat[1] = 1
        EndIf
    EndIf

    ; Move button
    $NewY = $ButtonY + $aProgDat[0]
    ; Apply squishiness to button height
    $NewH = $ButtonH
    If $aProgDat[0] = 5 Then
        $NewY += $aProgDat[2]
        $NewH -= $aProgDat[2]
    ElseIf $aProgDat[0] = -5 Then
        $NewH -= $aProgDat[2]
    EndIf
    GUICtrlSetPos($ButtonId, $ButtonX, $NewY, $ButtonW, $NewH) ; Change pos to offset and squishiness
EndFunc   ;==>_UpdateProg

:ph34r: . :geek: . :)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

this is what i meant...

not perfected... just added to your original script

; Click on progress bar test
#include <guiconstants.au3>

; Global settings
Global $aProgDat[3] = [0, 1, 0] ; [0]=Offset, [1]=Direction, [2]=Squish
;Global $ButtonX = 210, $ButtonY = 30, $ButtonW = 60, $ButtonH = 40
Global $GlobalID = "", $ButtonX, $ButtonY, $ButtonW, $ButtonH
Opt("GuiOnEventMode", 1)

; Create basic GUI
$GuiId = GUICreate("In-Progress Test", 300, 100, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$LabelId = GUICtrlCreateLabel("Click START to begin:", 10, 40, 180, 20, $SS_Center)
; $ButtonId = GUICtrlCreateButton("START", $ButtonX, $ButtonY, $ButtonW, $ButtonH)
$ButtonId = GUICtrlCreateButton("START", 210, 30, 60, 40)
GUICtrlSetOnEvent($ButtonId, "_Button")
GUISetState(@SW_SHOW, $GuiId)
While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Button()
    Switch GUICtrlRead($ButtonId)
        Case "START"
            GUICtrlSetData($LabelId, "Running... click STOP:")
            GUICtrlSetData($ButtonId, "STOP")
            _GlobalizeID( $GuiId, $ButtonId)
            AdlibEnable("_UpdateProg", 50)
        Case "STOP"
            AdlibDisable()
            GUICtrlSetData($LabelId, "Click START to begin:")
            GUICtrlSetData($ButtonId, "START")
            GUICtrlSetPos($ButtonId, $ButtonX, $ButtonY)
            $GlobalID = ""
    EndSwitch
EndFunc   ;==>_Button

Func _GlobalizeID($hWin, $controlID)
    $GlobalID = $controlID
    $GID = ControlGetPos($hWin, "", $GlobalID)
        $ButtonX = $GID[0]
        $ButtonY = $GID[1]
        $ButtonW = $GID[2]
        $ButtonH = $GID[3]
        ;MsgBox(0x0,"Info", "$ButtonX =" & $GID[0] & @CRLF & "$ButtonY =" & $GID[1] & @CRLF & "$ButtonW =" & $GID[2] & @CRLF & "$ButtonH =" & $GID[3]) 
EndFunc
Func _UpdateProg()
    If $aProgDat[2] = 0 Then $aProgDat[0] += $aProgDat[1]
    If $aProgDat[0] >= 5 Then
        ; Hit bottom
        $aProgDat[0] = 5 ; stop offset
        $aProgDat[2] += $aProgDat[1] ; Increment squish
        If $aProgDat[2] > 5 Then ; Squish 0 thru 5 then reverse direction
            ; Max squish
            $aProgDat[2] = 5
            ; Reverse direction
            $aProgDat[1] = -1
        EndIf
    ElseIf $aProgDat[0] <= -5 Then
        ; Hit top
        $aProgDat[0] = -5 ; stop offset
        $aProgDat[2] -= $aProgDat[1] ; increment squish
        If $aProgDat[2] > 5 Then ; Squish 0 thru 5 then reverse direction
            ; Max squish
            $aProgDat[2] = 5
            ; Reverse direction
            $aProgDat[1] = 1
        EndIf
    EndIf

    ; Move button
    $NewY = $ButtonY + $aProgDat[0]
    ; Apply squishiness to button height
    $NewH = $ButtonH
    If $aProgDat[0] = 5 Then
        $NewY += $aProgDat[2]
        $NewH -= $aProgDat[2]
    ElseIf $aProgDat[0] = -5 Then
        $NewH -= $aProgDat[2]
    EndIf
    GUICtrlSetPos($ButtonId, $ButtonX, $NewY, $ButtonW, $NewH) ; Change pos to offset and squishiness
EndFunc   ;==>_UpdateProg

i think you can see the direction for an interchangeable control-ID, thus a UDF

8)

NEWHeader1.png

Link to comment
Share on other sites

this is what i meant...

not perfected... just added to your original script

i think you can see the direction for an interchangeable control-ID, thus a UDF

8)

Cool, thanks for the tip. Couldn't do any more than read it today, haven't been in the same room with a Windows box all day (so it's been a GOOD day!). I'll try it out as soon as I get a chance.

:lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I tried to integrate this into my shell program, and it runs really slow. (Not the shell, the button)

Was this one of those Copy/Paste issues i have? Or is it because XSkin is in use?

CODE

#include <XSkin.au3>

#Include <GUIConstants.au3>

#Include <IE.au3>

Global $ButtonX = $pos[0], $ButtonY = $pos[1], $ButtonW = 60, $ButtonH = 40

Global $aProgDat[3] = [0, 1, 0] ; [0]=Offset, [1]=Direction, [2]=Squish

HotKeySet("^x", "exito")

$oIE = _IECreateEmbedded()

Opt("WinTitleMatchMode", 4)

$handle = WinGetHandle("classname=Shell_TrayWnd")

WinSetState ( $handle, "", @sw_hide )

; the two following folders are seperate for building skins

; however in YOUR program put them in the same folder

; folder of skin

$Skin_Folder = @ScriptDir & "\Silent-green"

; icon folder

$Icon_Folder = @ScriptDir & "SkinsDefault"

XSkinGUICreate("Test", 1108, 758, $Skin_Folder)

$Shell = GUICtrlCreateIcon("shell32.dll", 94, 50, 50)

$Shelll = GUICtrlCreateLabel("Run Normal Shell", 50, 90)

$B = GUICtrlCreateButton("START", $ButtonX, $ButtonY, $ButtonW, $ButtonH)

GUISetState()

AdlibEnable("_UpdateProg")

While 1

$msg = GUIGetMsg()

Switch $msg

Case $Shell

Run("explorer.exe")

EndSwitch

WEnd

Func OnAutoitExit()

WinSetState ( $handle, "", @SW_SHOW )

EndFunc

Func Exito()

Exit

EndFunc

Func _UpdateProg()

If $aProgDat[2] = 0 Then $aProgDat[0] += $aProgDat[1]

If $aProgDat[0] >= 5 Then

; Hit bottom

$aProgDat[0] = 5 ; stop offset

$aProgDat[2] += $aProgDat[1] ; Increment squish

If $aProgDat[2] > 5 Then ; Squish 0 thru 5 then reverse direction

; Max squish

$aProgDat[2] = 5

; Reverse direction

$aProgDat[1] = -1

EndIf

ElseIf $aProgDat[0] <= -5 Then

; Hit top

$aProgDat[0] = -5 ; stop offset

$aProgDat[2] -= $aProgDat[1] ; increment squish

If $aProgDat[2] > 5 Then ; Squish 0 thru 5 then reverse direction

; Max squish

$aProgDat[2] = 5

; Reverse direction

$aProgDat[1] = 1

EndIf

EndIf

; Move button

$NewY = $ButtonY + $aProgDat[0]

; Apply squishiness to button height

$NewH = $ButtonH

If $aProgDat[0] = 5 Then

$NewY += $aProgDat[2]

$NewH -= $aProgDat[2]

ElseIf $aProgDat[0] = -5 Then

$NewH -= $aProgDat[2]

EndIf

GUICtrlSetPos($B, $ButtonX, $NewY, $ButtonW, $NewH) ; Change pos to offset and squishiness

EndFunc ;==>_UpdateProg

Link to comment
Share on other sites

It's quite cool. :lmao:

And I knew nothing about Adlib. This is new knowledge to me, thank you.

What about this code?

I think it's a bit smoother.

Func _UpdateProg()
    $aProgDat[0] += 0.3
    GUICtrlSetPos($ButtonId, $ButtonX, $ButtonY + (sin($aProgDat[0]) * 5))
EndFunc   ;==>_UpdateProg
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...