Jump to content

🎨 "Chiodini colorati" 📌 (colored thumb tacks)


Gianni
 Share

Recommended Posts

... Surfing the net my eye fell on a device called "Divoom".
It reminded me of a little toy I liked to play when I went to kindergarten (more than 55 years ago... :'(), it was called "Chiodini colorati".
So I made this little script to emulate it, ...maybe some kids will have fun playing with it. :)

ORbDFu6.png

The attached zip file contains the script and also some "pixel art" files ready to be loaded.

P.S.

Thanks to @KaFu for it's _WinSetClientSize() function and to @InunoTaishou for it's CaptureWindow() function (references are in the script)

#include <WinAPISysWin.au3>
#include <File.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

#cs -----------------------------------------
    "Chiodini colorati" (colored thumb tacks)
    a little toy for the kids
    16x16 pixel art sheet
    Programmed by Gianni Addiego - Italy
    December 2021
#ce -----------------------------------------

_Chiodini()

Func _Chiodini()
    Local $aColors[16] = [0xffffff, 0xFF0000, 0xFF00FF, 0xFFC0CB, 0x964B00, 0xCD853F, 0xFF6600, 0xFFCC00, _
            0xFFFF00, 0xCCFF00, 0x00FF00, 0x228B22, 0x0000FF, 0x00FFFF, 0x7F7F7F, 0x000000]
    Local $iColor = $aColors[0], $sFileName, $aAzioni, $bOkToSave
    Local $aColori, $aChiodini, $GUIGetMsg, $hShowActiveColor
    Local $hGui = GUICreate("Chiodini colorati")

    $aColori = _GuiControlPanel("Button", 1, 16, 50, 20, 0, 0, 5, 0, 0, 1, True, "Colors")
    For $i = 1 To UBound($aColori) - 1
        GUICtrlSetBkColor($aColori[$i], $aColors[$i - 1])
    Next

    $aChiodini = _GuiControlPanel("Label", 16, 16, 20, 20, ($aColori[0])[11], 0, 3, 3, 1, 1, True, "") ;
    Local $aBackColors[UBound($aChiodini)]

    For $i = 1 To UBound($aChiodini) - 1
        GUICtrlSetBkColor($aChiodini[$i], $iColor)
        $aBackColors[$i] = $iColor
    Next
    $iColor = $aColors[1]

    $aAzioni = _GuiControlPanel("Button", 4, 1, 80, 50, ($aColori[0])[11] + 0, ($aChiodini[0])[12], 0, 0, 5, 1, True, "")
    GUICtrlSetData($aAzioni[1], "Clear with color")
    GUICtrlSetData($aAzioni[2], "Load txt File")
    GUICtrlSetData($aAzioni[3], "Save txt File")
    GUICtrlSetData($aAzioni[4], "Save JPG")

    $hShowActiveColor = _GuiControlPanel('Label', 1, 1, 45, 30, 8, ($aColori[0])[12], 0, 0, 0, 0, True, "Active")
    GUICtrlSetBkColor($hShowActiveColor[1], $iColor)

    _WinSetClientSize($hGui, ($aChiodini[0])[11] + ($aColori[0])[11], ($aChiodini[0])[12] + ($aAzioni[0])[12]) ;

    GUISetState()

    ; ---------
    ; Main loop
    ; ---------
    While True
        $GUIGetMsg = GUIGetMsg()
        ; --------------------------------------------
        ; scan all buttons to check if one was pressed
        ; --------------------------------------------
        For $i = 1 To UBound($aColori) - 1
            If $GUIGetMsg = $aColori[$i] Then
                $iColor = $aColors[$i - 1]
                GUICtrlSetBkColor($hShowActiveColor[1], $iColor)
                ContinueLoop 2
            EndIf
        Next

        For $i = 1 To UBound($aChiodini) - 1
            If $GUIGetMsg = $aChiodini[$i] Then
                GUICtrlSetBkColor($aChiodini[$i], $iColor)
                $aBackColors[$i] = $iColor
                ContinueLoop 2
            EndIf
        Next

        Switch $GUIGetMsg
            Case $aAzioni[1] ; ----- Clear with color
                For $i = 1 To UBound($aChiodini) - 1
                    GUICtrlSetBkColor($aChiodini[$i], $iColor)
                    $aBackColors[$i] = $iColor
                Next
            Case $aAzioni[2] ; ----- File Load
                $sFileName = FileOpenDialog("File to load", @ScriptDir, "Text files (*.txt)")
                If FileExists($sFileName) Then
                    _FileReadToArray($sFileName, $aBackColors, $FRTA_NOCOUNT)
                    For $i = 1 To UBound($aBackColors) - 1
                        GUICtrlSetBkColor($aChiodini[$i], $aBackColors[$i])
                    Next
                Else
                    MsgBox(64, "Info", "File not found")
                EndIf
            Case $aAzioni[3] ;  ----- File Save
                $sFileName = FileSaveDialog("File to save", @ScriptDir, "Text files (*.txt)")
                $bOkToSave = True
                If FileExists($sFileName) Then
                    $bOkToSave = 6 = MsgBox(4 + 48, "warning", "File already exists, do you want overwrite it?")
                EndIf
                If $bOkToSave Then
                    _FileWriteFromArray($sFileName, $aBackColors)
                EndIf
            Case $aAzioni[4] ; ----- Save image
                $sFileName = FileSaveDialog("Image name to save", @ScriptDir, "Image jpg (*.jpg)")
                $bOkToSave = True
                If FileExists($sFileName) Then
                    $bOkToSave = 6 = MsgBox(4 + 48, "warning", "File already exists, do you want overwrite it?")
                EndIf
                If $bOkToSave Then
                    CaptureWindow($sFileName, ($aChiodini[0])[13], ($aChiodini[0])[14], ($aChiodini[0])[15], ($aChiodini[0])[16], $hGui)
                EndIf
        EndSwitch

        If $GUIGetMsg = -3 Then
            Exit ; If 6 = MsgBox(4 + 32, "?", "Do you really want to quit?") Then Exit
        EndIf
    WEnd
EndFunc   ;==>_Chiodini

; #FUNCTION# ====================================================================================================================
; Name...........: _GuiControlPanel v1.1 2021/12
; Description ...: Creates a rectangular panel with adequate size to contain the required amount of controls
;                  and then fills it with the same controls by placing them according to the parameters
; Syntax.........: _GuiControlPanel( $ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, $xPos = 0, $yPos = 0, $xBorder, $yBorder, $xSpace = 1, $ySpace = 1)
; Parameters ....: $ControlType  - Type of controls to be generated ("Button"; "Text"; .....
;                  $nrPerLine  - Nr. of controls per line in the matrix
;                  $nrOfLines - Nr. of lines in the matrix
;                  $ctrlWidth - Width of each control
;                  $ctrlHeight - Height of each control
;                  $xPanelPos - x Position of panel in GUI
;                  $yPanelPos - y Position of panel in GUI
;                  $xBorder - distance from lateral panel's borders to the matrix (width of left and right margin) default = 0
;                  $yBorder - distance from upper and lower panel's borders to the matrix (width of upper and lower margin) default = 0
;                  $xSpace - horizontal distance between the controls
;                  $ySpace - vertical distance between the controls
;                  $Group - if you want to group the controls (true or false)
;                  $sGrpTitle - title of the group (ignored if above is false)
; Return values .: an 1 based 1d array containing references to each control
;                  element [0] contains an 1d array containing various parameters about the panel
; Author ........: Gianni Addiego (Chimp)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================

Func _GuiControlPanel($ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, $xPanelPos = 0, $yPanelPos = 0, $xBorder = 0, $yBorder = 0, $xSpace = 1, $ySpace = 1, $Group = False, $sGrpTitle = "")

    Local Static $sAllowedControls = "|Label|Input|Edit|Button|CheckBox|Radio|List|Combo|Pic|Icon|Graphic|"
    If Not StringInStr($sAllowedControls, '|' & $ControlType & '|') Then Return SetError(1, 0, "Unkown control")

    Local $col, $row, $left, $top, $text
    Local $PanelWidth = (($ctrlWidth + $xSpace) * $nrPerLine) - $xSpace + ($xBorder * 2)
    Local $PanelHeight = (($ctrlHeight + $ySpace) * $nrOfLines) - $ySpace + ($yBorder * 2)
    Local $InnerXPos = $xPanelPos, $InnerYPos = $yPanelPos, $InnerWidth = $PanelWidth, $InnerHeight = $PanelHeight
    If $Group Then
        $PanelWidth += 2
        $InnerXPos += 1
        If $sGrpTitle = "" Then
            $InnerYPos += 7
            $PanelHeight += 8
            GUICtrlCreateGroup("", $xPanelPos, $yPanelPos, $PanelWidth, $PanelHeight)
        Else
            $InnerYPos += 15
            $PanelHeight += 18
            GUICtrlCreateGroup($sGrpTitle, $xPanelPos, $yPanelPos, $PanelWidth + 2, $PanelHeight)  ; + 18)
        EndIf
    EndIf

    ; create the controls
    Local $aGuiGridCtrls[$nrPerLine * $nrOfLines + 1]
    Local $aPanelParams[17] = [ _
            $ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, _
            $xPanelPos, $yPanelPos, $xBorder, $yBorder, $xSpace, $ySpace, $PanelWidth, $PanelHeight, $InnerXPos, $InnerYPos, $InnerWidth, $InnerHeight]

    For $i = 0 To $nrPerLine * $nrOfLines - 1
        ; coordinates 1 based
        $col = Mod($i, $nrPerLine) + 1 ; Vertical position within the grid (row) $iVtab
        $row = Int($i / $nrPerLine) + 1 ;  Horizontal position within the grid (column) $iHtab
        $left = $InnerXPos + ((($ctrlWidth + $xSpace) * $col) - $xSpace) - $ctrlWidth + $xBorder
        $top = $InnerYPos + ((($ctrlHeight + $ySpace) * $row) - $ySpace) - $ctrlHeight + $yBorder
        $text = '' ; $i + 1 ; "*" ; "." ; "(*)"

        $aGuiGridCtrls[$i + 1] = Execute("GUICtrlCreate" & $ControlType & "($text, $left, $top, $ctrlWidth, $ctrlHeight)")
    Next

    If $Group Then GUICtrlCreateGroup("", -99, -99, 1, 1) ; close group
    $aGuiGridCtrls[0] = $aPanelParams
    Return $aGuiGridCtrls
EndFunc   ;==>_GuiControlPanel

; By kafu
; https://www.autoitscript.com/forum/topic/201524-guicreate-and-wingetclientsize-mismatch/?do=findComment&comment=1446141
Func _WinSetClientSize($hWnd, $iW, $iH)
    Local $aWinPos = WinGetPos($hWnd)
    Local $sRect = DllStructCreate("int;int;int;int;")
    DllStructSetData($sRect, 3, $iW)
    DllStructSetData($sRect, 4, $iH)
    _WinAPI_AdjustWindowRectEx($sRect, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE))
    WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], _
            $aWinPos[2] + (DllStructGetData($sRect, 3) - $aWinPos[2]) - DllStructGetData($sRect, 1), _
            $aWinPos[3] + (DllStructGetData($sRect, 4) - $aWinPos[3]) - DllStructGetData($sRect, 2))
EndFunc   ;==>_WinSetClientSize

; By InunoTaishou
; https://www.autoitscript.com/forum/topic/181655-redraw-your-desktop-with-gdi/?tab=comments#comment-1304386
Func CaptureWindow($sFileName = "", $iLeft = -1, $iTop = -1, $iWidth = -1, $iHeight = -1, $hWnd = WinGetHandle("[Active]"), $bClientArea = True)
    If (Not IsHWnd($hWnd)) Then $hWnd = WinGetHandle($hWnd)
    If (@error) Then Return SetError(1, 0, False)
    If (BitAND(WinGetState($hWnd), 16) = 16) Then Return SetError(2, 0, False)
    Local $iSrcWidth = 0
    Local $iSrcHeight = 0

    Local $tRectWindow = _WinAPI_GetWindowRect($hWnd)
    ; Get the absolute width, using Abs on all of the memembers because the [1] index of the struct may be negative, supports multiple monitors
    Local $iAbsWidth = Abs(Abs(DllStructGetData($tRectWindow, 3)) - Abs(DllStructGetData($tRectWindow, 1)))
    ; Get the absolute height, using Abs on all of the memembers because the [1] index of the struct may be negative, supports multiple monitors
    ; Subtracts the caption bar if $bClientArea only
    Local $iAbsHeight = Abs(Abs(DllStructGetData($tRectWindow, 4)) - Abs(DllStructGetData($tRectWindow, 2))) - ($bClientArea ? _WinAPI_GetSystemMetrics($SM_CYCAPTION) : 0)
    If ($iWidth = -1 Or $iWidth = 0 Or $iWidth = Default Or $iWidth > $iAbsWidth) Then $iWidth = $iAbsWidth
    If ($iHeight = -1 Or $iHeight = 0 Or $iHeight = Default Or $iHeight > $iAbsHeight) Then $iHeight = $iAbsHeight
    $iSrcWidth = $iAbsWidth
    $iSrcHeight = $iAbsHeight

    If ($iLeft = -1 Or $iLeft = Default) Then $iLeft = 0
    If ($iTop = -1 Or $iTop = Default) Then $iTop = 0

    Local $hDC = _WinAPI_GetWindowDC($hWnd)
    Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hDestBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hDestBitmap)
    Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $iSrcWidth, $iSrcHeight)
    Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp)

    _WinAPI_PrintWindow($hWnd, $hSrcDC, True)

    _WinAPI_BitBlt($hDestDC, 0, 0, $iWidth, $iHeight, $hSrcDC, $iLeft, $iTop, $MERGECOPY)

    _WinAPI_SelectObject($hDestDC, $hDestSv)
    _WinAPI_SelectObject($hSrcDC, $hSrcSv)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hDestDC)
    _WinAPI_DeleteDC($hSrcDC)
    _WinAPI_DeleteObject($hBmp)
    $tPoint = 0
    $tRectWindow = 0
    $tDesktop = 0

    If ($sFileName) Then
        _GDIPlus_Startup()
        Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hDestBitmap)
        _GDIPlus_ImageSaveToFile($hBitmap, $sFileName)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_Shutdown()
    EndIf
    ; Return $hDestBitmap
EndFunc   ;==>CaptureWindow

 

Chiodini.zip

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Spoiler
16777215
16777215
16777215
16777215
16777215
16711680
16711680
16711680
16711680
16711680
16711680
16777215
16777215
16777215
16777215
16777215
16777215
16777215
16777215
16777215
16711680
16711680
16711680
16711680
16711680
16711680
16711680
16711680
16711680
16711680
16777215
16777215
16777215
16777215
16777215
16777215
9849600
9849600
9849600
9849600
16763904
16763904
9849600
16763904
16777215
16777215
16777215
16777215
16777215
16777215
16777215
9849600
9849600
16763904
9849600
16763904
16763904
16763904
9849600
16763904
16763904
16763904
16777215
16777215
16777215
16777215
16777215
9849600
9849600
16763904
9849600
9849600
16763904
16763904
16763904
9849600
16763904
16763904
16763904
16777215
16777215
16777215
16777215
9849600
9849600
9849600
16763904
16763904
16763904
16763904
9849600
9849600
9849600
9849600
16777215
16777215
16777215
16777215
16777215
16777215
16777215
16763904
16763904
16763904
16763904
16763904
16763904
16763904
16763904
16777215
16777215
16777215
16777215
16777215
16777215
16777215
9849600
9849600
9849600
16711680
9849600
9849600
9849600
16777215
16777215
16777215
16777215
16777215
16777215
16777215
16777215
9849600
9849600
9849600
9849600
16711680
9849600
9849600
16711680
9849600
9849600
9849600
16777215
16777215
16777215
16777215
9849600
9849600
9849600
9849600
9849600
16711680
16711680
16711680
16711680
9849600
9849600
9849600
9849600
16777215
16777215
16777215
16763904
16763904
16763904
9849600
16711680
16763904
16711680
16711680
16763904
16711680
9849600
16763904
16763904
16777215
16777215
16777215
16763904
16763904
16763904
16763904
16711680
16711680
16711680
16711680
16711680
16711680
16763904
16763904
16763904
16777215
16777215
16777215
16763904
16763904
16763904
16711680
16711680
16711680
16711680
16711680
16711680
16711680
16711680
16763904
16763904
16777215
16777215
16777215
16777215
16777215
16711680
16711680
16711680
16711680
16777215
16711680
16711680
16711680
16711680
16777215
16777215
16777215
16777215
16777215
16777215
9849600
9849600
9849600
9849600
16777215
16777215
16777215
9849600
9849600
9849600
9849600
16777215
16777215
16777215
16777215
9849600
9849600
9849600
9849600
9849600
16777215
16777215
16777215
9849600
9849600
9849600
9849600
9849600
16777215

 

 

Spoiler

Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder
Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

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

×
×
  • Create New...