Jump to content

Recommended Posts

Posted (edited)

This "cow" seems funny to me,

JS9x1hc.png      vJ807at.png
At this link (https://dodona.ugent.be/en/activities/1605325419/#) a brief rough description of what this script can do (sorry for the laziness, but that description may be fine).
You can use the _CowSayWin() function to display a message formatted in a comic along with an ascii art figure in a standalone window,
or
you can use _String_CowSay() function to format a plain string in a comic along with an ascii art figure and have it returned in a string for your own purposes, you will probably use it in Consolewrite () or whatever ...

The script makes use of the _StringSize() function written by @Melba23 (thanks Melba) of the StringSize.au3 udf that you can extract from the zip file located at this link: https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/. You have to save that udf file in the same directory along with this script.
It also makes use of the _WinSetClientSize() function written by @KaFu. (thanks kafu) This function is already built into the main script.

I hope you have fun

#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <array.au3>
#include <String.au3>
#include "StringSize.au3" ; <-- https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/

_Example()

Func _Example()
    SRandom(@SEC)
    Local $hCowWin, $aMsg = 0
    Local $sMessage, $iWidth, $iClipart, $iTextAlig
    Local $aMessages[] = ["Bottled water companies don’t produce water, they produce plastic bottles.", _
            "The greatest glory in living lies not in never falling, but in rising every time we fall.", _
            "Your time is limited, so don't waste it living someone else's life. " & _
            "Don't be trapped by dogma which is living with the results of other people's thinking.", _
            "Insanity is doing the same thing over and over again and expecting different results", _
            "The way to get started is to quit talking and begin doing."]
    For $i = 1 To 6
        $sMessage = $aMessages[Random(0, UBound($aMessages) - 1, 1)]
        $iWidth = Random(21, 90, 1)
        $iClipart = Random(0, 3, 1)
        $iTextAlign = 1 ; Random(0, 2, 1) Left and right alignments are a bit ugly.
        ;                 they are allowed however if you need them
        ;
        ; You can use the _CowSayWin() function to create the "cowsay" message in a window
        $hCowWin = _CowSayWin($sMessage, $iWidth, $iClipart, $iTextAlign)
        ;
        ; or you can use the _String_CowSay() function to get a string of the "cowsay ascii clipart"
        ; so that you can use it however you like, probably in a Consolewrite () for example ...
        ConsoleWrite(_String_CowSay($sMessage, $iWidth, $iClipart, $iTextAlign) & @CRLF)
        While 1
            $aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
            Switch $aMsg[1]
                Case $hCowWin
                    Switch $aMsg[0]
                        Case -3 ; $GUI_EVENT_CLOSE
                            ExitLoop
                    EndSwitch
            EndSwitch
        WEnd
        GUIDelete(HWnd($hCowWin))
    Next
EndFunc   ;==>_Example

; #FUNCTION# ====================================================================================================================
; Name ..........: _CowSayWin
; Description ...: Display a message in a standalone windows formatted in a balloon along with an ascii art figure
; Syntax ........: _CowSayWin($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]])
; Parameters ....: $sMsg                - a string value. The message to display (in a single line without @cr and or @lf)
;                  $iBoxLen             - [optional] an integer value. Default is 21.
;                                         The wanted width of the Box contining the message
;                  $iShape              - [optional] an integer value. Default is 0.
;                                         The index of the ascii art figure to be displayed along with the message.
;                                         Available values are:
;                                         0 -> a cow
;                                         1 -> a sandwich-man
;                                         2 -> the penguin Tux
;                                         3 -> a hanging monkey
;                                            ..... to be continued  (maybe)
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         How to justify the string within the frame, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
; Return values .: The handle of the created window
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _CowSayWin($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1)
    If $iBoxLen < 21 Then $iBoxLen = 21
    Local $iSize = 12
    Local $iWeight = $FW_NORMAL
    Local $iAttrib = $GUI_FONTNORMAL
    Local $sFont = "Courier new"
    Local $sSay = _String_CowSay($sMsg, $iBoxLen, $iShape, $iAlign)
    Local $aMsgReturn = _StringSize($sSay, $iSize, $iWeight, $iAttrib, $sFont)
    Local $iXpos = (@DesktopWidth - $aMsgReturn[2]) / 2
    If $iXpos < 0 Then $iXpos = 0
    Local $iYpos = (@DesktopHeight - $aMsgReturn[3]) / 2
    If $iYpos < 0 Then $iYpos = 0
    Local $hCow = GUICreate("Cowsay", -1, -1, $iXpos, $iYpos, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) ;0x94C803C5, 0x00010101) ; , $WS_EX_DLGMODALFRAME) ;0x94C803C5,  0x00010101) ; Style & ExStyle same as msgbox
    GUISetFont($iSize, $FW_NORMAL, $GUI_FONTNORMAL, $sFont)
    _WinSetClientSize($hCow, $aMsgReturn[2], $aMsgReturn[3])
    GUICtrlCreateLabel($sSay, 0, 0, $aMsgReturn[2], $aMsgReturn[3])
    GUISetState(@SW_SHOW, $hCow)
    #cs
    While 1
        Switch GUIGetMsg()
            Case -3 ; $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    #ce
    Return $hCow
EndFunc   ;==>_CowSayWin

; 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


; #FUNCTION# ====================================================================================================================
; Name ..........: _StringToColumn
; Description ...: passing a (long) string and a value, it returns that same string
;                  formatted in a column as wide as the value (string is split by @CRs).
;                  Whenever possible, it tries not to break the words but to split
;                  lines in between two words
; Syntax ........: _StringToColumn($sString[, $x = 21])
; Parameters ....: $sString             - a string value. The string to format
;                  $iColumnWidth        - [optional] an integer value. Default is 21.
;                                         The wanted width of the text column
; Return values .: The string formatted as required
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _StringToColumn($sString, $iColumnWidth = 21)
    If $iColumnWidth < 1 Then $iColumnWidth = 1
    Local $iPreviousSplit = 1
    Local $i = $iColumnWidth
    While $i <= StringLen($sString)
        $iSplitPoint = StringInStr($sString, " ", 0, -1, $i + 1)
        If $iSplitPoint = 0 Or $iSplitPoint <= $iPreviousSplit Then
            $iSplitPoint = $i
            $sString = StringLeft($sString, $iSplitPoint) & @CR & StringMid($sString, $iSplitPoint + 1)
            $i = $iSplitPoint + 1
        Else
            $sString = StringReplace($sString, $iSplitPoint, @CR)
            $i = $iSplitPoint
        EndIf
        $iPreviousSplit = $iSplitPoint
        $i += $iColumnWidth
    WEnd
    If StringRight($sString, 1) = @CR Then $sString = StringTrimRight($sString, 1)
    Return $sString
EndFunc   ;==>_StringToColumn

; #FUNCTION# ====================================================================================================================
; Name ..........: _StringToFrame
; Description ...: places borders only to the left and to the right of the passed string block
; Syntax ........: _StringToFrame($sStr, $iFrameWidth[, $iAlign = 1[, $sV = "|"]])
; Parameters ....: $sStr                - The string to format; multiline string must be splitted by a @cr.
;                  $iFrameWidth         - wanted Width of the frame
;                                         If the desired width is less than the length of the string, the exceeding part is cut off
;                                         If the desired width is wider than the length of the string, spaces are added
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         The string is justified within the frame based on the value of the $iAlign variable, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
;                  $sV                  - [optional] a string value. Default is "|".
;                                         This is the character used to draw the two vertical edges
; Return values .: The formatted string
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _StringToFrame($sStr, $iFrameWidth, $iAlign = 1, $sV = "|") ; $iAlign: 0=Left; 1=Center; 2=Right
    If $iFrameWidth < 1 Then $iFrameWidth = 1
    Local $a = StringSplit($sStr, @CR, 2) ; 2 =  $STR_NOCOUNT
    For $i = 0 To UBound($a) - 1
        Switch $iAlign
            Case 1 ; Center string
                $a[$i] = $sV & _StringSetLen(_StringCenter($a[$i], $iFrameWidth), $iFrameWidth) & $sV
            Case 2 ; Align to right
                $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth * -1) & $sV
            Case Else ; otherwise Align to left
                $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth) & $sV
        EndSwitch
    Next
    Return _ArrayToString($a, @CR)
EndFunc   ;==>_StringToFrame

; passing a string and a value it returns that string with a len as required
; By Gianni Addiego
Func _StringSetLen($sString, $iWantedLen = 1, $sFillChr = " ")
    If $iWantedLen = 0 Then Return ""
    Local $iLen = StringLen($sString)
    Local $iKeepLeft = $iWantedLen > 0 ; else keep the right side of the string
    $iWantedLen = Abs($iWantedLen)
    If $iLen >= $iWantedLen Then ; reduce the string length
        If $iKeepLeft Then
            Return StringLeft($sString, $iWantedLen)
        Else
            Return StringRight($sString, $iWantedLen)
        EndIf
    Else ; add chars to the string to reach the wanted len
        If $iKeepLeft Then
            Return $sString & _StringRepeat($sFillChr, $iWantedLen - $iLen)
        Else
            Return _StringRepeat($sFillChr, $iWantedLen - $iLen) & $sString
        EndIf
    EndIf
EndFunc   ;==>_StringSetLen

; place a string in the middle of a given space
; By Gianni Addiego
Func _StringCenter($sString, $iSpace)
    Local $iLen = StringLen($sString)
    $iHloc = Int($iSpace / 2) - Int($iLen / 2)
    If $iHloc < 0 Then
        Return StringMid($sString, Abs($iHloc) + 1, $iSpace)
    Else
        Return _StringRepeat(" ", $iHloc) & $sString
    EndIf
EndFunc   ;==>_StringCenter

; #FUNCTION# ====================================================================================================================
; Name ..........: _String_CowSay
; Description ...: Formats a string in a balloon along with an ascii art figure
; Syntax ........: _String_CowSay($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]])
; Parameters ....: $sMsg                - a string value. The String to format (in a single line without @cr and or @lf)
;                  $iBoxLen             - [optional] an integer value. Default is 21.
;                                         The wanted width of the Box contining the message
;                  $iShape              - [optional] an integer value. Default is 0.
;                                         The index of the ascii art figure to be displayed along with the message.
;                                         Available values are:
;                                         0 -> a cow
;                                         1 -> a sandwich-man
;                                         2 -> the penguin Tux
;                                         3 -> a hanging monkey
;                                            ..... to be continued  (maybe)
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         How to justify the string within the frame, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
; Return values .: The passed string formatted in the required format.
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _String_CowSay($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1) ; minimum $iBoxLen is 21
    If $iBoxLen / 2 = Int($iBoxLen / 2) Then $iBoxLen += 1
    If $iBoxLen < 22 Then
        $x = 0
    Else
        $x = Ceiling(($iBoxLen - 21) / 2)
    EndIf
    Local $sS = _StringRepeat(" ", $x), $sT = _StringRepeat("~", $x)
    Local $sHeader, $sFooter
    Switch $iShape
        Case 1
            $sHeader = _
                    $sS & "         \|||/" & @CRLF & _
                    $sS & "         (o o)" & @CRLF & _
                    "," & $sT & "oo0~~~~~~(_)~~~~~~~~~" & $sT & "," & @CRLF ; header

            $sFooter = _
                    "'" & $sT & "~~~~~~~~~~~~~~~~~~oo0" & $sT & "'" & @CRLF & _ ; footer
                    $sS & "        |__|__|" & @CRLF & _
                    $sS & "         || ||" & @CRLF & _
                    $sS & "        oo0 0oo"
        Case 2
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _
                    "        \    .--." & @CRLF & _
                    "         \  |o_o |" & @CRLF & _
                    "            |:_/ |" & @CRLF & _
                    "           //   \ \" & @CRLF & _
                    "          (|     | )" & @CRLF & _
                    "         /'\_   _/`\" & @CRLF & _
                    "         \___)=(___/"
        Case 3
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'" & $sT & "oo0~~~~~~~~~~~~~~~0oo" & $sT & "'" & @CRLF & _ ; footer
                    $sS & "  \\               //" & @CRLF & _
                    $sS & "  > \   \\|||//   / <" & @CRLF & _
                    $sS & "   > \   _   _   / <" & @CRLF & _
                    $sS & "    > \ / \ / \ / <" & @CRLF & _
                    $sS & "     > \\_o_o_// <" & @CRLF & _
                    $sS & "      > ( (_) ) <" & @CRLF & _
                    $sS & "       >|     |<" & @CRLF & _
                    $sS & "      / |\___/| \" & @CRLF & _
                    $sS & "      / (_____) \" & @CRLF & _
                    $sS & "       /   o   \" & @CRLF & _
                    $sS & "        ) ___ (" & @CRLF & _
                    $sS & "       / /   \ \" & @CRLF & _
                    $sS & "      ( /     \ )" & @CRLF & _
                    $sS & "      ><       ><" & @CRLF & _
                    $sS & "     ///\     /\\\" & @CRLF & _
                    $sS & "     '''       '''"
        Case Else
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _
                    "        \   ^__^" & @CRLF & _
                    "         \  (oo)\_______" & @CRLF & _
                    "            (__)\       )\/\" & @CRLF & _
                    "                ||----w |" & @CRLF & _
                    "                ||     ||"
    EndSwitch

    Return $sHeader & _StringToFrame(_StringToColumn($sMsg, $iBoxLen), $iBoxLen, $iAlign) & @CRLF & $sFooter
EndFunc   ;==>_String_CowSay

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Posted (edited)

Nice.
Thanks for sharing.

Some minior fix:

;~ https://www.autoitscript.com/forum/topic/205659-cow-say/

#include <array.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>
#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
;~ #include "StringSize.au3" ; <-- https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/
#include "Z:\!!!_SVN_AU3\UDF_Forum\Other_Members\StringSize.au3" ; < - -https : / / www.autoitscript.com / forum / topic / 114034 - stringsize - m23 - new - version - 16 - aug - 11 /

_Example()

Func _Example()
    SRandom(@SEC)
    Local $hCowWin, $aMsg = 0
    Local $sMessage, $iWidth, $iClipart, $iTextAlign
    Local $aMessages[] = ["Bottled water companies don’t produce water, they produce plastic bottles.", _
            "The greatest glory in living lies not in never falling, but in rising every time we fall.", _
            "Your time is limited, so don't waste it living someone else's life. " & _
            "Don't be trapped by dogma which is living with the results of other people's thinking.", _
            "Insanity is doing the same thing over and over again and expecting different results", _
            "The way to get started is to quit talking and begin doing."]
    For $i = 1 To 6
        $sMessage = $aMessages[Random(0, UBound($aMessages) - 1, 1)]
        $iWidth = Random(21, 90, 1)
        $iClipart = Random(0, 3, 1)
        $iTextAlign = 1 ; Random(0, 2, 1) Left and right alignments are a bit ugly.
        ;                 they are allowed however if you need them
        ;
        ; You can use the _CowSayWin() function to create the "cowsay" message in a window
        $hCowWin = _CowSayWin($sMessage, $iWidth, $iClipart, $iTextAlign)
        ;
        ; or you can use the _String_CowSay() function to get a string of the "cowsay ascii clipart"
        ; so that you can use it however you like, probably in a Consolewrite () for example ...
        ConsoleWrite(_String_CowSay($sMessage, $iWidth, $iClipart, $iTextAlign) & @CRLF)
        While 1
            $aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
            Switch $aMsg[1]
                Case $hCowWin
                    Switch $aMsg[0]
                        Case -3 ; $GUI_EVENT_CLOSE
                            ExitLoop
                    EndSwitch
            EndSwitch
        WEnd
        GUIDelete(HWnd($hCowWin))
    Next
EndFunc   ;==>_Example

; #FUNCTION# ====================================================================================================================
; Name ..........: _CowSayWin
; Description ...: Display a message in a standalone windows formatted in a balloon along with an ascii art figure
; Syntax ........: _CowSayWin($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]])
; Parameters ....: $sMsg                - a string value. The message to display (in a single line without @cr and or @lf)
;                  $iBoxLen             - [optional] an integer value. Default is 21.
;                                         The wanted width of the Box contining the message
;                  $iShape              - [optional] an integer value. Default is 0.
;                                         The index of the ascii art figure to be displayed along with the message.
;                                         Available values are:
;                                         0 -> a cow
;                                         1 -> a sandwich-man
;                                         2 -> the penguin Tux
;                                         3 -> a hanging monkey
;                                            ..... to be continued  (maybe)
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         How to justify the string within the frame, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
; Return values .: The handle of the created window
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _CowSayWin($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1)
    If $iBoxLen < 21 Then $iBoxLen = 21
    Local $iSize = 12
    Local $iWeight = $FW_NORMAL
    Local $iAttrib = $GUI_FONTNORMAL
    Local $sFont = "Courier new"
    Local $sSay = _String_CowSay($sMsg, $iBoxLen, $iShape, $iAlign)
    Local $aMsgReturn = _StringSize($sSay, $iSize, $iWeight, $iAttrib, $sFont)
    Local $iXpos = (@DesktopWidth - $aMsgReturn[2]) / 2
    If $iXpos < 0 Then $iXpos = 0
    Local $iYpos = (@DesktopHeight - $aMsgReturn[3]) / 2
    If $iYpos < 0 Then $iYpos = 0
    Local $hCow = GUICreate("Cowsay", -1, -1, $iXpos, $iYpos, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) ;0x94C803C5, 0x00010101) ; , $WS_EX_DLGMODALFRAME) ;0x94C803C5,  0x00010101) ; Style & ExStyle same as msgbox
    GUISetFont($iSize, $FW_NORMAL, $GUI_FONTNORMAL, $sFont)
    _WinSetClientSize($hCow, $aMsgReturn[2], $aMsgReturn[3])
    GUICtrlCreateLabel($sSay, 0, 0, $aMsgReturn[2], $aMsgReturn[3])
    GUISetState(@SW_SHOW, $hCow)
    #cs
    While 1
        Switch GUIGetMsg()
            Case -3 ; $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    #ce
    Return $hCow
EndFunc   ;==>_CowSayWin

; 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


; #FUNCTION# ====================================================================================================================
; Name ..........: _StringToColumn
; Description ...: passing a (long) string and a value, it returns that same string
;                  formatted in a column as wide as the value (string is split by @CRs).
;                  Whenever possible, it tries not to break the words but to split
;                  lines in between two words
; Syntax ........: _StringToColumn($sString[, $x = 21])
; Parameters ....: $sString             - a string value. The string to format
;                  $iColumnWidth        - [optional] an integer value. Default is 21.
;                                         The wanted width of the text column
; Return values .: The string formatted as required
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _StringToColumn($sString, $iColumnWidth = 21)
    If $iColumnWidth < 1 Then $iColumnWidth = 1
    Local $iPreviousSplit = 1
    Local $i = $iColumnWidth
    Local $iSplitPoint
    While $i <= StringLen($sString)
        $iSplitPoint = StringInStr($sString, " ", 0, -1, $i + 1)
        If $iSplitPoint = 0 Or $iSplitPoint <= $iPreviousSplit Then
            $iSplitPoint = $i
            $sString = StringLeft($sString, $iSplitPoint) & @CR & StringMid($sString, $iSplitPoint + 1)
            $i = $iSplitPoint + 1
        Else
            $sString = StringReplace($sString, $iSplitPoint, @CR)
            $i = $iSplitPoint
        EndIf
        $iPreviousSplit = $iSplitPoint
        $i += $iColumnWidth
    WEnd
    If StringRight($sString, 1) = @CR Then $sString = StringTrimRight($sString, 1)
    Return $sString
EndFunc   ;==>_StringToColumn

; #FUNCTION# ====================================================================================================================
; Name ..........: _StringToFrame
; Description ...: places borders only to the left and to the right of the passed string block
; Syntax ........: _StringToFrame($sStr, $iFrameWidth[, $iAlign = 1[, $sV = "|"]])
; Parameters ....: $sStr                - The string to format; multiline string must be splitted by a @cr.
;                  $iFrameWidth         - wanted Width of the frame
;                                         If the desired width is less than the length of the string, the exceeding part is cut off
;                                         If the desired width is wider than the length of the string, spaces are added
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         The string is justified within the frame based on the value of the $iAlign variable, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
;                  $sV                  - [optional] a string value. Default is "|".
;                                         This is the character used to draw the two vertical edges
; Return values .: The formatted string
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _StringToFrame($sStr, $iFrameWidth, $iAlign = 1, $sV = "|") ; $iAlign: 0=Left; 1=Center; 2=Right
    If $iFrameWidth < 1 Then $iFrameWidth = 1
    Local $a = StringSplit($sStr, @CR, 2) ; 2 =  $STR_NOCOUNT
    For $i = 0 To UBound($a) - 1
        Switch $iAlign
            Case 1 ; Center string
                $a[$i] = $sV & _StringSetLen(_StringCenter($a[$i], $iFrameWidth), $iFrameWidth) & $sV
            Case 2 ; Align to right
                $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth * -1) & $sV
            Case Else ; otherwise Align to left
                $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth) & $sV
        EndSwitch
    Next
    Return _ArrayToString($a, @CR)
EndFunc   ;==>_StringToFrame

; passing a string and a value it returns that string with a len as required
; By Gianni Addiego
Func _StringSetLen($sString, $iWantedLen = 1, $sFillChr = " ")
    If $iWantedLen = 0 Then Return ""
    Local $iLen = StringLen($sString)
    Local $iKeepLeft = $iWantedLen > 0 ; else keep the right side of the string
    $iWantedLen = Abs($iWantedLen)
    If $iLen >= $iWantedLen Then ; reduce the string length
        If $iKeepLeft Then
            Return StringLeft($sString, $iWantedLen)
        Else
            Return StringRight($sString, $iWantedLen)
        EndIf
    Else ; add chars to the string to reach the wanted len
        If $iKeepLeft Then
            Return $sString & _StringRepeat($sFillChr, $iWantedLen - $iLen)
        Else
            Return _StringRepeat($sFillChr, $iWantedLen - $iLen) & $sString
        EndIf
    EndIf
EndFunc   ;==>_StringSetLen

; place a string in the middle of a given space
; By Gianni Addiego
Func _StringCenter($sString, $iSpace)
    Local $iLen = StringLen($sString)
    Local $iHloc = Int($iSpace / 2) - Int($iLen / 2)
    If $iHloc < 0 Then
        Return StringMid($sString, Abs($iHloc) + 1, $iSpace)
    Else
        Return _StringRepeat(" ", $iHloc) & $sString
    EndIf
EndFunc   ;==>_StringCenter

; #FUNCTION# ====================================================================================================================
; Name ..........: _String_CowSay
; Description ...: Formats a string in a balloon along with an ascii art figure
; Syntax ........: _String_CowSay($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]])
; Parameters ....: $sMsg                - a string value. The String to format (in a single line without @cr and or @lf)
;                  $iBoxLen             - [optional] an integer value. Default is 21.
;                                         The wanted width of the Box contining the message
;                  $iShape              - [optional] an integer value. Default is 0.
;                                         The index of the ascii art figure to be displayed along with the message.
;                                         Available values are:
;                                         0 -> a cow
;                                         1 -> a sandwich-man
;                                         2 -> the penguin Tux
;                                         3 -> a hanging monkey
;                                            ..... to be continued  (maybe)
;                  $iAlign              - [optional] an integer value. Default is 1.
;                                         How to justify the string within the frame, that is:
;                                         0 -> left justified
;                                         1 -> center justified (default)
;                                         2 -> right justified
; Return values .: The passed string formatted in the required format.
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _String_CowSay($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1) ; minimum $iBoxLen is 21
    If $iBoxLen / 2 = Int($iBoxLen / 2) Then $iBoxLen += 1
    Local $x
    If $iBoxLen < 22 Then
        $x = 0
    Else
        $x = Ceiling(($iBoxLen - 21) / 2)
    EndIf
    Local $sS = _StringRepeat(" ", $x), $sT = _StringRepeat("~", $x)
    Local $sHeader, $sFooter
    Switch $iShape
        Case 1
            $sHeader = _
                    $sS & "         \|||/" & @CRLF & _
                    $sS & "         (o o)" & @CRLF & _
                    "," & $sT & "oo0~~~~~~(_)~~~~~~~~~" & $sT & "," & @CRLF ; header

            $sFooter = _
                    "'" & $sT & "~~~~~~~~~~~~~~~~~~oo0" & $sT & "'" & @CRLF & _ ; footer
                    $sS & "        |__|__|" & @CRLF & _
                    $sS & "         || ||" & @CRLF & _
                    $sS & "        oo0 0oo"
        Case 2
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _
                    "        \    .--." & @CRLF & _
                    "         \  |o_o |" & @CRLF & _
                    "            |:_/ |" & @CRLF & _
                    "           //   \ \" & @CRLF & _
                    "          (|     | )" & @CRLF & _
                    "         /'\_   _/`\" & @CRLF & _
                    "         \___)=(___/"
        Case 3
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'" & $sT & "oo0~~~~~~~~~~~~~~~0oo" & $sT & "'" & @CRLF & _ ; footer
                    $sS & "  \\               //" & @CRLF & _
                    $sS & "  > \   \\|||//   / <" & @CRLF & _
                    $sS & "   > \   _   _   / <" & @CRLF & _
                    $sS & "    > \ / \ / \ / <" & @CRLF & _
                    $sS & "     > \\_o_o_// <" & @CRLF & _
                    $sS & "      > ( (_) ) <" & @CRLF & _
                    $sS & "       >|     |<" & @CRLF & _
                    $sS & "      / |\___/| \" & @CRLF & _
                    $sS & "      / (_____) \" & @CRLF & _
                    $sS & "       /   o   \" & @CRLF & _
                    $sS & "        ) ___ (" & @CRLF & _
                    $sS & "       / /   \ \" & @CRLF & _
                    $sS & "      ( /     \ )" & @CRLF & _
                    $sS & "      ><       ><" & @CRLF & _
                    $sS & "     ///\     /\\\" & @CRLF & _
                    $sS & "     '''       '''"
        Case Else
            $sHeader = _
                    "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header
            $sFooter = _
                    "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _
                    "        \   ^__^" & @CRLF & _
                    "         \  (oo)\_______" & @CRLF & _
                    "            (__)\       )\/\" & @CRLF & _
                    "                ||----w |" & @CRLF & _
                    "                ||     ||"
    EndSwitch

    Return $sHeader & _StringToFrame(_StringToColumn($sMsg, $iBoxLen), $iBoxLen, $iAlign) & @CRLF & $sFooter
EndFunc   ;==>_String_CowSay

 

And I notice one small issue:
in SciTE console I get:

  Quote

|  Bottled water companies  dont produce water, they |

Expand  

instead:

  Quote

|  Bottled water companies  don't produce water, they |

Expand  

Wondering why ?
 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Hi mLipok, thanks for the feedback,

  On 4/18/2021 at 9:51 PM, mLipok said:

And I notice one small issue:

in SciTE console I get:

|  Bottled water companies  dont produce water, they |

instead:

|  Bottled water companies  don't produce water, they |

Wondering why ?
 

Expand  

I have no idea, this does not occur on my system.

  On 4/18/2021 at 9:51 PM, mLipok said:

Some minior fix:

Expand  

p.s.
.... ? but what have you fixed? :think:

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Posted (edited)
  On 4/19/2021 at 11:04 AM, Chimp said:

but what have you fixed?

Expand  

Variable declarations....
for example:

Local $sMessage, $iWidth, $iClipart, $iTextAlign

instead:

Local $sMessage, $iWidth, $iClipart, $iTextAlig

and few others.


Check your script with:

#AutoIt3Wrapper_Run_AU3Check=Y
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

And you will see.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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...