Jump to content

Recommended Posts

Posted

Cheers Gianni :)

AutoIt x64 was having trouble - So if anyone uses that by default, here's the same code with the DllCalls swapped out for inbult _GDIPlus_* funcs.

; source
; https://autoit.de/thread/17855-led-laufschrift/
;
; reference for this script (by Eukalyptus):
; https://autoit.de/thread/17855-led-laufschrift/?postID=140164#post140164

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GDIPlusConstants.au3>
; #include "LEDTXT.au3" ; (by Eukalyptus) already embedded here below

Local $sText1 = "Hello friends! ☺ best wishes for a happy holiday and a happy new year (me)"
Local $sText2 = "Let us greet together this new year that ages our friendship without aging our hearts. (Victor Hugo)"
Local $sText3 = "The best time to plant a tree was 20 years ago. The second best time is now. (Chinese proverb)"
Local $sText4 = "The future belongs to those who believe in the beauty of their dreams. (Eleanor Roosevelt)"
Local $sText5 = "In the end, what matters is not the years of your life, but the life you put into those years. (Abraham Lincoln)"
HotKeySet("{ESC}", "_Exit")

_GDIPlus_Startup()

$hGuiTrans = GUICreate("", @DesktopWidth, 300, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($hGuiTrans, 0xABCDEF)
GUISetState()
$hGui = GUICreate("", @DesktopWidth, 400, 0, 300, Default, $WS_EX_TOPMOST)
; WinSetTrans($hGui, "", 100)
GUISetState()
#cs
parameters info:
$hGui: Handle to the window
$sText: The text
$iX: X position of the scrolling text
$iY: Y position
$iW: Length
$iH: Height
$iType: Appearance of the LEDs 0=Round with 3D effect, 1=Square with 3D, 2=Round, 3=Square; (the last two are filled and/or outlined, depending on which colors are <>0)
$iLedW = X-size of an LED
$iLedH = Y-size of an LED
$nLedOnCol1 = Color 1 of the ON LEDs (foreground for 3D, fill color for $iType 2 and 3)
$nLedOnCol2 = Color 2 of the ON LEDs (background for 3D, color of the outline for $iType 2 and 3)
$nLedOffCol1 = Color 1 of the OFF LEDs
$nLedOffCol2 = Color 2 of the OFF LEDs
$nBkColor = Background color
$iDistW = X-distance of the LEDs
$iDistH = Y-distance of the LEDs
$sFont = Font
$iTextSize = Font size
$iTextOpt = Font options (see _GDIPlus_FontCreate )
$iTextOffY = Y offset of the font
#ce
$aLed1 = _LEDTXT_Create_Gdi($hGuiTrans, $sText1, 0, 0, @DesktopWidth, 50, 0, 2, 2, 0xFFFFAA00, 0xFF000000, 0xAA111122, 0xAA000000, 0, 0, 0, "Courier New", 40, 1)
$aLed2 = _LEDTXT_Create_Gdi($hGuiTrans, $sText2, 0, 50, @DesktopWidth, 50, 3, 2, 2, 0, 0xFF0088FF, 0, 0xFF000000, 0, 0, 0, "Arial", 40, 1)
$aLed3 = _LEDTXT_Create_Gdi($hGuiTrans, $sText3, 0, 100, @DesktopWidth, 100, 1, 4, 4, 0xFFFF0000, 0xFF000000, 0, 0, 0xFFABCDEF, 1, 1, "Times New Roman", 80, 1)
$aLed4 = _LEDTXT_Create_Gdi($hGuiTrans, $sText4, 0, 200, @DesktopWidth, 100, 1, 4, 4, 0xFF00FF00, 0xFF000000, 0xFFABCDEF, 0xFFABCDEF, 0xFFABCDEF, 0, 0, "Arial", 80, 1)
$aLed5 = _LEDTXT_Create_Gdi($hGui, $sText5, 0, 0, @DesktopWidth, 350, 0, 14, 14, 0xFF00FF00, 0xFF00AA00, 0x44111119, 0x4400EE00, 0x44000000, 0, 0, "Arial", 410, 1, -60)


GUIRegisterMsg($WM_ERASEBKGND, "_WM_ERASEBKGND")

While 1
    _LEDTXT_Step($aLed1, 1)
    _LEDTXT_Step($aLed2, -1)
    _LEDTXT_Step($aLed3, 1)
    _LEDTXT_Step($aLed4, -1)
    _LEDTXT_Step($aLed5, 1)
    _WinAPI_RedrawWindow($hGuiTrans, 0, 0, 5)
    _WinAPI_RedrawWindow($hGui, 0, 0, 5)
    Sleep(10)
WEnd

Func _WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case $hGuiTrans
            _LEDTXT_Draw($aLed1)
            _LEDTXT_Draw($aLed2)
            _LEDTXT_Draw($aLed3)
            _LEDTXT_Draw($aLed4)
        Case $hGui
            _LEDTXT_Draw($aLed5)
    EndSwitch
    Return True
EndFunc   ;==>_WM_ERASEBKGND


Func _Exit()
    _LEDTXT_Destroy($aLed1)
    _LEDTXT_Destroy($aLed2)
    _LEDTXT_Destroy($aLed3)
    _LEDTXT_Destroy($aLed4)
    _LEDTXT_Destroy($aLed5)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

; ===============================
;    LEDTXT.au3 (by Eukalyptus)
; ===============================
Func _LEDTXT_Step(ByRef $aLed, $iDir = 1)
    $aLed[6] -= $aLed[8] * $iDir
    Select
        Case $aLed[6] + $aLed[7] < 0
            $aLed[6] = 0
        Case $aLed[6] > 0
            $aLed[6] = -$aLed[7]
    EndSelect
EndFunc   ;==>_LEDTXT_Step

Func _LEDTXT_Draw($aLed)
    Local $iPos = Round($aLed[6]) - Mod(Round($aLed[6]), $aLed[8])
    Switch $aLed[10]
        Case True
            Switch $iPos
                Case -$aLed[7] To -$aLed[7] + $aLed[4]
                    _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], -$iPos, 0, $iPos + $aLed[7], $aLed[5], $aLed[2], $aLed[3], $iPos + $aLed[7], $aLed[5])
                    If $aLed[6] + $aLed[7] < $aLed[4] Then _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], 0, 0, $aLed[4] - ($iPos + $aLed[7]), $aLed[5], $aLed[2] + $iPos + $aLed[7], $aLed[3], $aLed[4] - ($iPos + $aLed[7]), $aLed[5])
                Case Else
                    _GDIPlus_GraphicsDrawImageRectRect($aLed[0], $aLed[1], -$iPos, 0, $aLed[4], $aLed[5], $aLed[2], $aLed[3], $aLed[4], $aLed[5])
            EndSwitch
        Case Else
            Switch $iPos
                Case -$aLed[7] To -$aLed[7] + $aLed[4]
                    _WinAPI_BitBlt($aLed[0], $aLed[2], $aLed[3], $aLed[2] + $iPos + $aLed[7], $aLed[5], $aLed[1], -$iPos, 0, $MERGECOPY)
                    If $aLed[6] + $aLed[7] < $aLed[4] Then _WinAPI_BitBlt($aLed[0], $aLed[2] + $iPos + $aLed[7], $aLed[3], $aLed[4] - ($iPos + $aLed[7]), $aLed[5], $aLed[1], 0, 0, $MERGECOPY)
                Case Else
                    _WinAPI_BitBlt($aLed[0], $aLed[2], $aLed[3], $aLed[4], $aLed[5], $aLed[1], -$iPos, 0, $MERGECOPY)
            EndSwitch
    EndSwitch
EndFunc   ;==>_LEDTXT_Draw


Func _LEDTXT_Create_GdiPlus($hGui, $sText, $iX, $iY, $iW, $iH, $iType, $iLedW = 8, $iLedH = 8, $nLedOnCol1 = 0xFFFFAA00, $nLedOnCol2 = 0xFF000000, $nLedOffCol1 = 0xAA111122, $nLedOffCol2 = 0xAA000000, $nBkColor = 0xFF000000, $iDistW = 0, $iDistH = 0, $sFont = "Arial", $iTextSize = 0, $iTextOpt = 1, $iTextOffY = 0)
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Local $hLedOn = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOnCol1, $nLedOnCol2)
    Local $hLedOff = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOffCol1, $nLedOffCol2)
    Local $hLed, $iWidth
    $hLed = _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, $iWidth)
    Local $aReturn[11]
    $aReturn[0] = $hGraphics
    $aReturn[1] = $hLed
    $aReturn[2] = $iX
    $aReturn[3] = $iY
    $aReturn[4] = $iW
    $aReturn[5] = $iH
    $aReturn[6] = 0
    $aReturn[7] = $iWidth
    $aReturn[8] = $iLedW + $iDistW
    $aReturn[9] = 0
    $aReturn[10] = True ; True = _GdiPlus, False=_WinApi
    Return $aReturn
EndFunc   ;==>_LEDTXT_Create_GdiPlus



Func _LEDTXT_Create_Gdi($hGui, $sText, $iX, $iY, $iW, $iH, $iType, $iLedW = 8, $iLedH = 8, $nLedOnCol1 = 0xFFFFAA00, $nLedOnCol2 = 0xFF000000, $nLedOffCol1 = 0xAA111122, $nLedOffCol2 = 0xAA000000, $nBkColor = 0xFF000000, $iDistW = 0, $iDistH = 0, $sFont = "Arial", $iTextSize = 0, $iTextOpt = 1, $iTextOffY = 0)
    Local $bGdiStarted = True
    If Not $__g_hGDIPDll Then
        $bGdiStarted = False
        _GDIPlus_Startup()
    EndIf
    Local $hDC = _WinAPI_GetDC($hGui)
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC)
    Local $hLedOn = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOnCol1, $nLedOnCol2)
    Local $hLedOff = _LEDTXT_Create_Led($hGraphics, $iType, $iLedW - $iDistW, $iLedH - $iDistH, $nLedOffCol1, $nLedOffCol2)
    Local $hLed, $iWidth
    $hLed = _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, $iWidth)

    Local $hBmpDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hLed)
    _WinAPI_SelectObject($hBmpDC, $hBmp)
    Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hLed)
    Local $aReturn[11]
    $aReturn[0] = $hDC
    $aReturn[1] = $hBmpDC
    $aReturn[2] = $iX
    $aReturn[3] = $iY
    $aReturn[4] = $iW
    $aReturn[5] = $iH
    $aReturn[6] = 0
    $aReturn[7] = $iWidth
    $aReturn[8] = $iLedW + $iDistW
    $aReturn[9] = $hBmp ; zum späteren destroy?!
    $aReturn[10] = False ; True = _GdiPlus, False=_WinApi
    _GDIPlus_GraphicsDispose($hGraphics)
    If Not $bGdiStarted Then _GDIPlus_Shutdown()
    Return $aReturn
EndFunc   ;==>_LEDTXT_Create_Gdi



Func _LEDTXT_Destroy($aLed)
    Switch $aLed[10]
        Case True
            _GDIPlus_BitmapDispose($aLed[1])
            _GDIPlus_GraphicsDispose($aLed[0])
        Case Else
            _WinAPI_DeleteObject($aLed[9])
            _WinAPI_ReleaseDC(0, $aLed[1])
            _WinAPI_DeleteDC($aLed[0])
    EndSwitch
EndFunc   ;==>_LEDTXT_Destroy





Func _LEDTXT_Create_Bmp($hGraphics, $sText, $iW, $iH, $iLedW, $iLedH, $hLedOn, $hLedOff, $iDistW, $iDistH, $sFont, $iTextSize, $iTextOpt, $iTextOffY, $nBkColor, ByRef $iReturnW)
    $sText = StringReplace($sText, @LF, "")
    $iW -= Mod($iW, $iLedW + $iDistW)
    If Not $iTextSize Then $iTextSize = $iH
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iTextSize, $iTextOpt, 2)
    Local $tLayout = _GDIPlus_RectFCreate($iW, 0, 0, 0)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width")) + $iW
    $iWidth -= Mod($iWidth, $iLedW + $iDistW)
    Local $iHeight = $iH ;Ceiling(DllStructGetData($aInfo[0], "Height"))
    DllStructSetData($aInfo[0], "Y", $iTextOffY)
    Local $hBmpTxt = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
    Local $hBmpLed = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
    Local $hBmpTmp = _GDIPlus_BitmapCreateFromGraphics($iLedW, $iHeight, $hGraphics)
    Local $hGfxTxt = _GDIPlus_ImageGetGraphicsContext($hBmpTxt)
    Local $hGfxLed = _GDIPlus_ImageGetGraphicsContext($hBmpLed)
    Local $hGfxTmp = _GDIPlus_ImageGetGraphicsContext($hBmpTmp)
    Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    _GDIPlus_GraphicsClear($hGfxTxt, 0xFF000000)
    If $nBkColor Then _GDIPlus_GraphicsClear($hGfxLed, $nBkColor)
    _GDIPlus_GraphicsDrawStringEx($hGfxTxt, $sText, $hFont, $aInfo[0], $hFormat, $hBrush)
    Local $BitmapData = _GDIPlus_BitmapLockBits($hBmpTxt, $iW, 0, $iWidth - $iW, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    Local $Stride = DllStructGetData($BitmapData, "Stride")
    Local $Width = DllStructGetData($BitmapData, "Width")
    Local $Height = DllStructGetData($BitmapData, "Height")
    Local $Scan0 = DllStructGetData($BitmapData, "Scan0")
    Local $PixelData = DllStructCreate("ubyte lData[" & (Abs($Stride) * $Height - 1) & "]", $Scan0)
    If $hLedOff Then
        For $i = 0 To $Height - 1 Step $iLedH + $iDistH
            _GDIPlus_GraphicsDrawImage($hGfxTmp, $hLedOff, 0, $i)
        Next
        For $i = 0 To $iW - 1 Step $iLedW + $iDistW
            _GDIPlus_GraphicsDrawImage($hGfxLed, $hBmpTmp, $i, 0)
        Next
    EndIf
    For $col = 0 To $Width - 1 Step $iLedW + $iDistW
        If $hLedOff Then _GDIPlus_GraphicsDrawImage($hGfxLed, $hBmpTmp, $col + $iW, 0)
        For $row = 0 To $Height - 1 Step $iLedH + $iDistH
            If DllStructGetData($PixelData, 1, $row * $Stride + ($col * 4) + 1) Then _GDIPlus_GraphicsDrawImage($hGfxLed, $hLedOn, $col + $iW, $row)
        Next
    Next
    _GDIPlus_BitmapUnlockBits($hBmpTxt, $BitmapData)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BitmapDispose($hBmpTxt)
    _GDIPlus_GraphicsDispose($hGfxTxt)
    _GDIPlus_BitmapDispose($hBmpTmp)
    _GDIPlus_GraphicsDispose($hGfxTmp)
    _GDIPlus_GraphicsDispose($hGfxLed)
    $iReturnW = $iWidth
    Return $hBmpLed
EndFunc   ;==>_LEDTXT_Create_Bmp



Func _LEDTXT_Create_Led($hGraphics, $iType, $iWidth, $iHeight, $nColor1, $nColor2)
    If Not $nColor1 And Not $nColor2 Then Return 0
    Local $hBmp = _GDIPlus_BitmapCreateFromGraphics($iWidth + 1, $iHeight + 1, $hGraphics)
    Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBmp)
    Switch $iType
        Case 0
            Local $hPen = _GDIPlus_PenCreate()
            Local $hPath = _GDIPlus_PathCreate()
            _GDIPlus_PathAddEllipse($hPath, 0, 0, $iWidth, $iHeight)
           Local $hBrushGrad = _GDIPlus_PathBrushCreateFromPath($hPath)
            _GDIPlus_PathBrushSetGammaCorrection($hBrushGrad, True)
            Local $aColors[2] = [1, $nColor2]
            _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrushGrad, $aColors)
            _GDIPlus_PathBrushSetCenterColor($hBrushGrad, $nColor1)
            _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrushGrad)
            _GDIPlus_PathCloseFigure($hPath)
            _GDIPlus_GraphicsDrawEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hPen)
            _GDIPlus_PenDispose($hPen)
            _GDIPlus_BrushDispose($hBrushGrad)
            _GDIPlus_PathDispose($hPath)
        Case 1
            Local $hPen = _GDIPlus_PenCreate()
            Local $hPath = _GDIPlus_PathCreate()
            _GDIPlus_PathAddRectangle($hPath, 0, 0, $iWidth, $iHeight)

            Local $hBrushGrad = _GDIPlus_PathBrushCreateFromPath($hPath)
            _GDIPlus_PathBrushSetGammaCorrection($hBrushGrad, True)
            Local $aColors[2] = [1, $nColor2]
            _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrushGrad, $aColors)
            _GDIPlus_PathBrushSetCenterColor($hBrushGrad, $nColor1)
            _GDIPlus_GraphicsFillPath($hGfx, $hPath, $hBrushGrad)
            _GDIPlus_PathCloseFigure($hPath)
            _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $iWidth, $iHeight, $hPen)
            _GDIPlus_PenDispose($hPen)
            _GDIPlus_BrushDispose($hBrushGrad)
            _GDIPlus_PathDispose($hPath)
        Case 2
            If $nColor1 Then
                Local $hBrush = _GDIPlus_BrushCreateSolid($nColor1)
                _GDIPlus_GraphicsFillEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hBrush)
                _GDIPlus_BrushDispose($hBrush)
            EndIf
            If $nColor2 Then
                Local $hPen = _GDIPlus_PenCreate($nColor2)
                _GDIPlus_GraphicsDrawEllipse($hGfx, 0, 0, $iWidth, $iHeight, $hPen)
                _GDIPlus_PenDispose($hPen)
            EndIf
        Case 3
            If $nColor1 Then
                Local $hBrush = _GDIPlus_BrushCreateSolid($nColor1)
                _GDIPlus_GraphicsFillRect($hGfx, 0, 0, $iWidth, $iHeight, $hBrush)
                _GDIPlus_BrushDispose($hBrush)
            EndIf
            If $nColor2 Then
                Local $hPen = _GDIPlus_PenCreate($nColor2)
                _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $iWidth, $iHeight, $hPen)
                _GDIPlus_PenDispose($hPen)
            EndIf
    EndSwitch
    _GDIPlus_GraphicsDispose($hGfx)
    Return $hBmp
EndFunc   ;==>_LEDTXT_Create_Led

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
  • Recently Browsing   0 members

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