Jump to content

Recommended Posts

Posted (edited)

collection of round buttons

; https://www.autoitscript.com/forum/topic/211721-round-buttons/
;----------------------------------------------------------------------------------------
; Title...........: RoundButtons.au3
; Description.....: collection of round buttons
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $MyGui, $aBtn[7][2]

Example()

Func Example()
    $MyGui = GUICreate(" My GUI Icons", 300, 500)
    $aBtn[0][0] = 6 ; cnt of buttons
    $aBtn[1][1] = "red"
    $aBtn[1][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[1][1] & "_normal.ico", 0, 20, 20, 64, 64, $SS_NOTIFY)
    $aBtn[2][1] = "yellow"
    $aBtn[2][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[2][1] & "_normal.ico", 0, 20, 100, 64, 64, $SS_NOTIFY)
    $aBtn[3][1] = "green"
    $aBtn[3][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[3][1] & "_normal.ico", 0, 20, 180, 64, 64, $SS_NOTIFY)
    $aBtn[4][1] = "turquoise"
    $aBtn[4][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[4][1] & "_normal.ico", 0, 20, 260, 64, 64, $SS_NOTIFY)
    $aBtn[5][1] = "cyan"
    $aBtn[5][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[5][1] & "_normal.ico", 0, 20, 340, 64, 64, $SS_NOTIFY)
    $aBtn[6][1] = "magenta"
    $aBtn[6][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[6][1] & "_normal.ico", 0, 20, 420, 64, 64, $SS_NOTIFY)


    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $aBtn[1][0]
                ConsoleWrite($aBtn[1][1] & @CRLF)
            Case $aBtn[2][0]
                ConsoleWrite($aBtn[2][1] & @CRLF)
            Case $aBtn[3][0]
                ConsoleWrite($aBtn[3][1] & @CRLF)
            Case $aBtn[4][0]
                ConsoleWrite($aBtn[4][1] & @CRLF)
            Case $aBtn[5][0]
                ConsoleWrite($aBtn[5][1] & @CRLF)
            Case $aBtn[6][0]
                ConsoleWrite($aBtn[6][1] & @CRLF)
        EndSwitch

        _IsOver()
    WEnd

    GUIDelete()
EndFunc   ;==>Example

Func _IsOver()
    Local Static $iActive, $iClicked = 0
    Local $aActive = GUIGetCursorInfo($MyGui)

    If $aActive[2] And $iClicked = 1 Then Return

    If $iActive <> $aActive[4] Then
        $iActive = $aActive[4]
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_hover.ico")
            Else
                GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_normal.ico")
            EndIf
        Next
    EndIf

    If $aActive[2] Or $iClicked = 1 Then
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                If $iClicked = 0 Then
                    GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_click.ico")
                    $iClicked = 1
                Else
                    GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_hover.ico")
                    $iClicked = 0
                EndIf
            EndIf
        Next
    EndIf

EndFunc   ;==>_IsOver


Extract buttons folder in @ScriptDir   Buttons.zip

 

Please, every comment is appreciated!
leave your comments and experiences here!
Thank you very much  :)

Edited by ioa747

I know that I know nothing

Posted (edited)
6 hours ago, argumentum said:

And a request would be that the action is on button release ( up ) instead of down

the icon's $SS_NOTIFY style is responsible for this.
I don't know how this can change

Edit:
I found another way

Special Edition:

; https://www.autoitscript.com/forum/topic/211721-round-buttons/
;----------------------------------------------------------------------------------------
; Title...........: RoundButtonsSpecial.au3
; Description.....: collection of round buttons - Special Edition
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $MyGui, $aBtn[7][2]

Example()

;----------------------------------------------------------------------------------------
Func Example()
    $MyGui = GUICreate(" My GUI Icons", 300, 500)
    $aBtn[0][0] = 6 ; cnt of buttons
    $aBtn[1][1] = "red"
    $aBtn[1][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[1][1] & "_normal.ico", 0, 20, 20, 64, 64)
    $aBtn[2][1] = "yellow"
    $aBtn[2][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[2][1] & "_normal.ico", 0, 20, 100, 64, 64)
    $aBtn[3][1] = "green"
    $aBtn[3][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[3][1] & "_normal.ico", 0, 20, 180, 64, 64)
    $aBtn[4][1] = "turquoise"
    $aBtn[4][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[4][1] & "_normal.ico", 0, 20, 260, 64, 64)
    $aBtn[5][1] = "cyan"
    $aBtn[5][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[5][1] & "_normal.ico", 0, 20, 340, 64, 64)
    $aBtn[6][1] = "magenta"
    $aBtn[6][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[6][1] & "_normal.ico", 0, 20, 420, 64, 64)


    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch

        _IsOver()
    WEnd

    GUIDelete()
EndFunc   ;==>Example
;----------------------------------------------------------------------------------------
Func _IsOver()
    Local Static $iActive, $iClicked = 0
    Local $aActive = GUIGetCursorInfo($MyGui)

    If $aActive[2] And $iClicked = 1 Then Return

    If $iActive <> $aActive[4] Then
        $iActive = $aActive[4]
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_hover.ico")
            Else
                GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_normal.ico")
            EndIf
        Next
    EndIf

    If $aActive[2] Or $iClicked = 1 Then
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                If $iClicked = 0 Then
                    GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_click.ico")
                    $iClicked = 1
                Else
                    GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_hover.ico")
                    $iClicked = 0
                    _ButtonCaller($aBtn[$i][0])
                EndIf
            EndIf
        Next
    EndIf

EndFunc   ;==>_IsOver
;----------------------------------------------------------------------------------------
Func _ButtonCaller($Btn)
    Switch $Btn
        Case $aBtn[1][0]
            ConsoleWrite($aBtn[1][1] & @CRLF)
        Case $aBtn[2][0] ;"yellow"
            ConsoleWrite($aBtn[2][1] & @CRLF)
        Case $aBtn[3][0] ;"green"
            ConsoleWrite($aBtn[3][1] & @CRLF)
        Case $aBtn[4][0] ;"turquoise"
            ConsoleWrite($aBtn[4][1] & @CRLF)
        Case $aBtn[5][0] ;"cyan"
            ConsoleWrite($aBtn[5][1] & @CRLF)
        Case $aBtn[6][0] ;"magenta"
            ConsoleWrite($aBtn[6][1] & @CRLF)
    EndSwitch
EndFunc
;----------------------------------------------------------------------------------------

 

Edited by ioa747
I found another way

I know that I know nothing

  • 3 weeks later...
Posted

Method for Colorful Rectangle Buttons

; https://www.autoitscript.com/forum/topic/211721-round-buttons/
;----------------------------------------------------------------------------------------
; Title...........: RectButtonsSpecial.au3
; Description.....: collection of rectangles buttons - Special Edition
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

; ~~~~~~~~~~~~~~~~~  Example - what is ColorLight()
Global $test = ColorLight(0xC800C8, 50)
ConsoleWrite($test & @CRLF)

$test = ColorLight(0xC800C8, 50, 1)
ConsoleWrite($test & @CRLF)

$test = ColorLight(0xC800C8, 50, 2)
ConsoleWrite(StringFormat("RGB(%d,%d,%d)", $test[0], $test[1], $test[2]) & @CRLF & @CRLF)
; ~~~~~~~~~~~~  End of Example - what is ColorLight()


Global $MyGui, $aBtn[6][2], $btnColor = 0xC800C8

$MyGui = GUICreate(@ScriptName, 180, 220)
GUISetBkColor(0x000000)

$aBtn[0][0] = 5     ; cnt of buttons

$aBtn[1][0] = GUICtrlCreateLabel("Button1", 10, 20, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[1][1] = 0xA64500
GUICtrlSetBkColor(-1, $aBtn[1][1])

$aBtn[2][0] = GUICtrlCreateLabel("Button2", 10, 60, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[2][1] = 0x826E00
GUICtrlSetBkColor(-1, $aBtn[2][1])

$aBtn[3][0] = GUICtrlCreateLabel("Button3", 10, 100, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[3][1] = 0x268000
GUICtrlSetBkColor(-1, $aBtn[3][1])

$aBtn[4][0] = GUICtrlCreateLabel("Button4", 10, 140, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[4][1] = 0x0094FF
GUICtrlSetBkColor(-1, $aBtn[4][1])

$aBtn[5][0] = GUICtrlCreateLabel("Button5", 10, 180, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[5][1] = 0x9600D5
GUICtrlSetBkColor(-1, $aBtn[5][1])

GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    _IsOver()
WEnd

;--------------------------------------------------------------------------------------------------------------------------------
Func _IsOver()
    Local Static $iActive, $iClicked = 0
    Local $aActive = GUIGetCursorInfo($MyGui)

    If $aActive[2] And $iClicked = 1 Then Return

    If $iActive <> $aActive[4] Then
        $iActive = $aActive[4]

        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], 30)) ;hover
            Else
                GUICtrlSetBkColor($aBtn[$i][0], $aBtn[$i][1]) ;normal
            EndIf
        Next
    EndIf

    If $aActive[2] Or $iClicked = 1 Then
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                If $iClicked = 0 Then
                    GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], -30)) ;click
                    GUICtrlSetFont($aBtn[$i][0], 10, 800, 2, "MS Sans Serif")
                    GUICtrlSetColor($aBtn[$i][0], 0xCCCCCC)
                    $iClicked = 1
                Else
                    GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], 30)) ;hover
                    GUICtrlSetFont($aBtn[$i][0], 10, 800, 0, "MS Sans Serif")
                    GUICtrlSetColor($aBtn[$i][0], 0xFFFFFF)
                    $iClicked = 0
                    _ButtonCaller($aBtn[$i][0])
                EndIf
            EndIf
        Next
    EndIf

EndFunc   ;==>_IsOver
;--------------------------------------------------------------------------------------------------------------------------------
Func _ButtonCaller($Btn)
    Switch $Btn
        Case $aBtn[1][0]
            ConsoleWrite(GUICtrlRead($aBtn[1][0]) & @CRLF)
        Case $aBtn[2][0]
            ConsoleWrite(GUICtrlRead($aBtn[2][0]) & @CRLF)
        Case $aBtn[3][0]
            ConsoleWrite(GUICtrlRead($aBtn[3][0]) & @CRLF)
        Case $aBtn[4][0]
            ConsoleWrite(GUICtrlRead($aBtn[4][0]) & @CRLF)
        Case $aBtn[5][0]
            ConsoleWrite(GUICtrlRead($aBtn[5][0]) & @CRLF)
        Case $aBtn[6][0]
            ConsoleWrite(GUICtrlRead($aBtn[6][0]) & @CRLF)
    EndSwitch
EndFunc   ;==>_ButtonCaller

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: ColorLight()
; Description....: Returns a new color that is a combination of the $HexColor plus the amount of $Lightness it adds to all three RGB channels.
; Syntax.........: ColorLight($HexColor [, $Lightness [,$output]])
; Parameters.....: $HexColor    - The start color to be combined.
;                  $Lightness   - The amount it adds to all three RGB channels. Negative number to subtract (darker)
;                  $output      - Optional: The format of the output string:
;                                     0 = "0x" followed by the hexadecimal value of the new color (default)
;                                     1 = "#" followed by the hexadecimal value of the new color
;                                     2 = an array containing the red, green and blue values of the new color
; Return values..: The new color as a string or an array.
; Author ........: ioa747
; Notes .........:
;--------------------------------------------------------------------------------------------------------------------------------
Func ColorLight($HexColor, $Lightness = 0, $sOutput = 0)

    If StringLeft($HexColor, 1) = "#" Then $HexColor = StringReplace($HexColor, "#", "0x")

    Local $sHexColor = Hex($HexColor, 6)
    ;ConsoleWrite("$sHexColor=" & $sHexColor & @CRLF)

    Local $aSplit = StringSplit($sHexColor, "")
    Local $aRGB[3]

    If $aSplit[0] = 6 Then
        $aRGB[0] = Dec($aSplit[1] & $aSplit[2], 0)
        $aRGB[1] = Dec($aSplit[3] & $aSplit[4], 0)
        $aRGB[2] = Dec($aSplit[5] & $aSplit[6], 0)
        ;ConsoleWrite(StringFormat("aRGB(%d,%d,%d)", $aRGB[0], $aRGB[1], $aRGB[2]) & @CRLF)
    Else
        ConsoleWrite("Something wrong $aSplit[0]=" & $aSplit[0] & @CRLF)
        Return SetError(1, 0, -1)
    EndIf

    Local $aNewRGB[] = [$aRGB[0] + $Lightness, $aRGB[1] + $Lightness, $aRGB[2] + $Lightness]

    If $aNewRGB[0] < 0 Then $aNewRGB[0] = 0
    If $aNewRGB[0] > 255 Then $aNewRGB[0] = 255
    If $aNewRGB[1] < 0 Then $aNewRGB[1] = 0
    If $aNewRGB[1] > 255 Then $aNewRGB[1] = 255
    If $aNewRGB[2] < 0 Then $aNewRGB[2] = 0
    If $aNewRGB[2] > 255 Then $aNewRGB[2] = 255

    ;ConsoleWrite(StringFormat("aNewRGB(%d,%d,%d)", $aNewRGB[0], $aNewRGB[1], $aNewRGB[2]) & @CRLF)

    Local $sColor

    ;$sOutput:  0:="0x" | 1:="#" | 2:=aRGB[R,G,B]
    Switch $sOutput
        Case 0, 1
            $sColor = ($sOutput = 1 ? "#" : "0x")
            $sColor &= Hex(String($aNewRGB[0]), 2)
            $sColor &= Hex(String($aNewRGB[1]), 2)
            $sColor &= Hex(String($aNewRGB[2]), 2)
            ;ConsoleWrite("$sColor=" & $sColor & @CRLF & @CRLF)

        Case 2
            $sColor = $aNewRGB

    EndSwitch

    Return $sColor

EndFunc   ;==>ColorLight
;--------------------------------------------------------------------------------------------------------------------------------

have fun  :)
Thank you very much 

I know that I know nothing

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
×
×
  • Create New...