[GDI+] Runder, Animierter Ladebalken

  • Moin,
    Vor Urzeiten habe ich schonmal einen Runden Ladebalken gebastelt.
    Als GDI+ Anfänger war es aber bei weitem nicht das, was man so alles rausholen kann.
    Hier mal eine kleine Demonstration meines heutigen Werkes:
    Runde sich drehende Ladebalken mit Animationen (Beim Füllen werden die Segmente Aufgebaut, Bei 100% wird die Rotation beschleunigt und die Größe reduziert)
    Wer daran herumbasteln will darf dies gerne tun, dafür ist der Spaß ja da ;)

    "Skript + Sonstiges"

    Edit: Nun ist der Code etwas besser aufgeräumt
    + ProgressSet Funktion läuft
    + Eine Hand voll mehr Einstellungsmöglichkeiten

    Edit2:
    + Umbenennung von ProgressSet zu ProgressSetDesign
    Der Progress enthält zurzeit keine Informationen über seinen "Füllstand" (keine Prozentzahl)
    Da ich davon ausging, dass bei jedem Neuzeichnen ein neuer Prozentwert übergeben wird, existiert keine Funktion um einen Prozentstand zuzuweisen.

    Edit3:
    + ProgressSet & ProgressGet setzen oder geben den aktuellen Prozentwert.
    + BitBlt statt GDI+ (macht nur das Beispiel schneller, die eigentlichen Funktionen bleiben leider relativ zeitintensiv...)

    [autoit]


    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('GUIOnEventMode', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $PI = 3.14159265358979
    Global Const $Deg2Rad = $PI / 180

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $W = 500, $H = 500

    [/autoit] [autoit][/autoit] [autoit]

    Global $GFX, $SLI, $PER, $PRO[3], $BUF, $CNT, $NUM, $DC, $IMG

    [/autoit] [autoit][/autoit] [autoit]

    $GUI = GUICreate('Test', $W, $H)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $IMG = _Image_Create($W, $H)
    $BUF = DllStructGetData($IMG, 1)
    $DC = _WinAPI_GetDC($GUI)
    $GFX = _GDIPlus_GraphicsCreateFromHDC($BUF)
    _GDIPlus_GraphicsSetSmoothingMode($GFX, 4)

    [/autoit] [autoit][/autoit] [autoit]

    $SLI = GUICtrlCreateSlider(5, 5, 490, 30)
    GUICtrlSetLimit(-1, 1000, 0)

    [/autoit] [autoit][/autoit] [autoit]

    $PRO[0] = _ProgressCreate(7, 10, 0.1, 0x0060FF, 0x30002080)
    $PRO[1] = _ProgressCreate(11, 25, -0.32, 0xFF6000, 0x30802000)
    $PRO[2] = _ProgressCreate(25, 35, 0.2, 0x00FF60, 0x30008020)

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister('_Dispose')
    GUISetOnEvent(-3, '_Event', $GUI)
    GUISetState(@SW_SHOW, $GUI)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    $PER = GUICtrlRead($SLI) / 1000
    If $PER < 1 Then GUICtrlSetData($SLI, GUICtrlRead($SLI) + 1)
    $CNT += 1

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsClear($GFX)

    [/autoit] [autoit][/autoit] [autoit]

    If IsInt($CNT/100) Then
    $NUM += 1
    If $NUM = UBound($PRO) Then $NUM = 0
    _ProgressSetDesign($PRO[$NUM], Random(1, 15, 1), Random(10, 40), Random(-1, 1), '0x' & Hex(Int(Random(0,255, 1)),2) & Hex(Int(Random(0,255, 1)),2) & Hex(Int(Random(0,255, 1)),2), '0x35' & Hex(Int(Random(0,255, 1)),2) & Hex(Int(Random(0,255, 1)),2) & Hex(Int(Random(0,255, 1)),2))
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    _ProgressSet($PRO[0], $PER)
    _ProgressSet($PRO[1], 1 - $PER)
    _ProgressSet($PRO[2], $PER/2)

    [/autoit] [autoit][/autoit] [autoit]

    _ProgressDraw($GFX, $W / 4, $H / 3 + 25, 250, 35, $PRO[0])
    _ProgressDraw($GFX, $W / 4 * 3, $H / 2 + 25, 150, 45, $PRO[1])
    _ProgressDraw($GFX, $W / 2, $H / 4 * 3 + 25, 150, 15, $PRO[2])

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_BitBlt($DC, 0, 50, $W, $H - 50, $BUF, 0, 50, 0xCC0020)

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressGet($aProgress)
    Return $aProgress[9]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressSet(ByRef $aProgress, $nPercent)
    If $nPercent <= 1 Then
    $aProgress[9] = $nPercent
    Else
    $aProgress[9] = $nPercent / 100
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressSetDesign(ByRef $aProgress, $iAnzahl = 0, $nDist = 0, $nAniTempo = 0, $iCol = 0, $iColIdle = 0, $iStartTrans = 0, $iPos = 0)
    If $iCol Then $aProgress[1] = StringRight(Hex($iCol, 8), 6) ; Farbe des Ladebalkens (Alpha wird ignoriert), möglich ist also 0xFFAARRGGBB oder 0xRRGGBB
    If $iColIdle Then $aProgress[2] = $iColIdle ; Farbe der nicht benutzen Flächen (Alpha ist relevant !)
    If $iPos Then $aProgress[4] = $iPos ; Animationscounter (drehanimation)
    If $iAnzahl Then $aProgress[5] = $iAnzahl ; Anzahl Segmente für den Ladebalken
    If $nDist Then $aProgress[6] = 360 - 3.6 * $nDist ; Abstand zwischen den Segmenten (0 < $nDist < 100)
    If $nAniTempo Then $aProgress[7] = $nAniTempo ; Drehgeschwindigkeit in Grad/Frame. (negativer Wert = drehung gegen deh Uhrzeigersinn)
    If $iStartTrans Then $aProgress[8] = $iStartTrans ; Starttransparenz des Segments bei Färbebeginn
    EndFunc ;==>_ProgressSet

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressCreate($iAnzahl = 9, $nDist = 10, $nAniTempo = 0.25, $iCol = 0xFF4080FF, $iColIdle = 0x20808080, $iStartTrans = 32, $iStartPos = 0)
    If Not $iStartPos Then $iStartPos = Random(0, 360)
    Local $a[10]
    $a[0] = _GDIPlus_PenCreate() ; GDI+ Pen
    $a[1] = StringRight(Hex($iCol, 8), 6) ; Farbe des Ladebalkens (Alpha wird ignoriert), möglich ist also 0xFFAARRGGBB oder 0xRRGGBB
    $a[2] = $iColIdle ; Farbe der nicht benutzen Flächen (Alpha ist relevant !)
    $a[3] = 0 ; Animationscounter (100% Animation)
    $a[4] = $iStartPos ; Animationscounter (drehanimation)
    $a[5] = $iAnzahl ; Anzahl Segmente für den Ladebalken
    $a[6] = 360 - 3.6 * $nDist ; Abstand zwischen den Segmenten (0 < $nDist < 100)
    $a[7] = $nAniTempo ; Drehgeschwindigkeit in Grad/Frame. (negativer Wert = drehung gegen deh Uhrzeigersinn)
    $a[8] = $iStartTrans ; Starttransparenz des Segments bei Färbebeginn
    $a[9] = 0 ; Prozentwert von 0 bis 1
    Return $a
    EndFunc ;==>_ProgressCreate

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDraw($hGfx, $mx, $my, $d1, $d2, ByRef $aProgress)
    $aProgress[4] += $aProgress[7]
    Local $nPercent = $aProgress[9], $a, $b = 360 * $nPercent, $c, $d = $aProgress[6] / $aProgress[5], $e = $d1 / 50, $f = ($nPercent = 1), $g = $aProgress[4] - Int($aProgress[4]/360)*360
    If $f Then
    If $aProgress[3] < 15 Then $aProgress[3] += 1
    $d2 *= 0.97 ^ $aProgress[3]
    $aProgress[4] += $aProgress[7] * 1.1 ^ $aProgress[3]
    Else
    If $aProgress[3] > 0 Then
    $aProgress[3] -= 1
    $d2 *= 0.97 ^ $aProgress[3]
    $aProgress[4] += $aProgress[7] * 1.1 ^ $aProgress[3]
    EndIf
    EndIf
    For $i = 0 To $aProgress[5] - 1 Step 1
    $a = $i * 360 / $aProgress[5] + $g
    If $b >= 360 / $aProgress[5] Then
    $c = 1
    $b -= 360 / $aProgress[5]
    Else
    $c = $b / (360 / $aProgress[5])
    EndIf
    Switch $c
    Case 0
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], $aProgress[2])
    Case 0 To 0.33
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x' & Hex(Int($c * 3 * (128-$aProgress[8])+ $aProgress[8]), 2) & $aProgress[1])
    Case 0.33 To 0.66
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2 / 2, $a, $d, $aProgress[0], '0x' & Hex(Int(($c - 0.33) * 150), 2) & 'FFFFFF')
    Case 0.66 To 0.99
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2 / 2, $a, $d, $aProgress[0], '0x32FFFFFF')
    _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x' & Hex(Int(($c - 0.66) * 384), 2) & $aProgress[1], 3)
    Case 0.99 To 1
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2 / 2, $a, $d, $aProgress[0], '0x32FFFFFF')
    _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1], 3)
    If $f Then _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0xFF' & $aProgress[1], $e / 3)
    EndSwitch
    If $c < 1 Then
    DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $aProgress[0], 'dword', $aProgress[2])
    DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $aProgress[0], 'float', $d2)
    For $j = $i + 1 To $aProgress[5] - 1 Step 1
    $a = $j * 360 / $aProgress[5] + $aProgress[4]
    $a -= Int($a / 360) * 360
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0])
    Next
    ExitLoop
    EndIf
    Next
    EndFunc ;==>_ProgressDraw

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDelete(ByRef $aProgress)
    _GDIPlus_PenDispose($aProgress[0])
    $aProgress = 0
    EndFunc ;==>_ProgressDelete

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $fStart, $fSweep, $hPen, $iCol, $dPen)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $hPen, 'dword', $iCol)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $hPen, 'float', $dPen)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $d1 / 2, 'float', $my - $d1 / 2, 'float', $d1, 'float', $d1, 'float', $fStart + ($dPen / ($d1 * $PI)) * 180, 'float', $fSweep - ($dPen / ($d1 * $PI)) * 360)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $d1 / 2 + $d2, 'float', $my - $d1 / 2 + $d2, 'float', $d1 - $d2 * 2, 'float', $d1 - $d2 * 2, 'float', $fStart + ($dPen / (($d1 - $d2) * $PI)) * 180, 'float', $fSweep - ($dPen / (($d1 - $d2) * $PI)) * 360)
    DllCall($ghGDIPDll, 'int', 'GdipDrawLine', 'handle', $hGfx, 'handle', $hPen, 'float', $mx + ($d1 - $d2 * 2 - $dPen) / 2 * Cos($fStart * $Deg2Rad), 'float', $my + ($d1 - $d2 * 2 - $dPen) / 2 * Sin($fStart * $Deg2Rad), 'float', $mx + ($d1 + $dPen) / 2 * Cos($fStart * $Deg2Rad), 'float', $my + ($d1 + $dPen) / 2 * Sin($fStart * $Deg2Rad))
    DllCall($ghGDIPDll, 'int', 'GdipDrawLine', 'handle', $hGfx, 'handle', $hPen, 'float', $mx + ($d1 - $d2 * 2 - $dPen) / 2 * Cos(($fStart + $fSweep) * $Deg2Rad), 'float', $my + ($d1 - $d2 * 2 - $dPen) / 2 * Sin(($fStart + $fSweep) * $Deg2Rad), 'float', $mx + ($d1 + $dPen) / 2 * Cos(($fStart + $fSweep) * $Deg2Rad), 'float', $my + ($d1 + $dPen) / 2 * Sin(($fStart + $fSweep) * $Deg2Rad))
    EndFunc ;==>_ProgressDrawPieSegment

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $fStart, $fSweep, $hPen, $iCol = 0)
    If Not $iCol Then Return DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $d1 / 2 + $d2 / 2, 'float', $my - $d1 / 2 + $d2 / 2, 'float', $d1 - $d2, 'float', $d1 - $d2, 'float', $fStart, 'float', $fSweep)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $hPen, 'dword', $iCol)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $hPen, 'float', $d2)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $d1 / 2 + $d2 / 2, 'float', $my - $d1 / 2 + $d2 / 2, 'float', $d1 - $d2, 'float', $d1 - $d2, 'float', $fStart, 'float', $fSweep)
    EndFunc ;==>_ProgressFillPieSegment

    [/autoit] [autoit][/autoit] [autoit]

    Func _Image_Create($iW, $iH)
    Local $Ptr, $hDC, $hBmp, $tBMI, $aDIB, $vStruct
    $hDC = _WinAPI_CreateCompatibleDC(0)
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, 'Size', DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, 'Width', $iW)
    DllStructSetData($tBMI, 'Height', -$iH)
    DllStructSetData($tBMI, 'Planes', 1)
    DllStructSetData($tBMI, 'BitCount', 32)
    $aDIB = DllCall('GDI32.DLL', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    $hBmp = $aDIB[0]
    $Ptr = $aDIB[4]
    _WinAPI_SelectObject($hDC, $hBmp)
    $vStruct = DllStructCreate('int[5]')
    DllStructSetData($vStruct, 1, $hDC, 1)
    DllStructSetData($vStruct, 1, $iW, 2)
    DllStructSetData($vStruct, 1, $iH, 3)
    DllStructSetData($vStruct, 1, $Ptr, 4)
    DllStructSetData($vStruct, 1, $hBmp, 5)
    Return $vStruct
    EndFunc;==>_Image_Create

    [/autoit] [autoit][/autoit] [autoit]

    Func _Image_Delete(ByRef $vStruct)
    _WinAPI_DeleteObject(DllStructGetData($vStruct, 1, 5))
    _WinAPI_DeleteDC(DllStructGetData($vStruct, 1, 1))
    $vStruct = 0
    EndFunc ;==>_Image_Delete

    [/autoit] [autoit][/autoit] [autoit]

    Func _Event()
    Exit
    EndFunc ;==>_Event

    [/autoit] [autoit][/autoit] [autoit]

    Func _Dispose()
    For $i = 0 To UBound($PRO) - 1 Step 1
    _ProgressDelete($PRO[$i])
    Next
    _Image_Delete($IMG)
    _WinAPI_ReleaseDC($GUI, $DC)
    _GDIPlus_GraphicsDispose($GFX)
    _GDIPlus_Shutdown()
    EndFunc ;==>_Dispose

    [/autoit]


    lg
    Mars

  • Sieht richtig Gut aus!

    Wenn ich es mit Namensnennung verwenden dürfte, dann fällt mir grade nur ein Updater ein,
    Und deshalb war ich mal so frei und habe den Hintergrund transparent gemacht ^^
    Sieht so leider etwas "verpixelt" aus aber immernoch sehr Gut !

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <WindowsConstants.au3> ; <--

    [/autoit] [autoit][/autoit] [autoit]

    Opt('GUIOnEventMode', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $W = 500, $H = 500, $Deg2Rad = 3.14159265358979/180, $Rad2Deg = 180/3.14159265358979

    [/autoit] [autoit][/autoit] [autoit]

    Global $GFX, $SLI, $PER, $PRO[3], $BUF, $BMP

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $GUI = GUICreate('Test', $W, $H,-1,-1,-1,$WS_EX_LAYERED) ; <---
    $GFX = _GDIPlus_GraphicsCreateFromHWND($GUI)
    $BMP = _GDIPlus_BitmapCreateFromGraphics($W, $H, $GFX)
    $BUF = _GDIPlus_ImageGetGraphicsContext($BMP)
    _GDIPlus_GraphicsSetSmoothingMode($BUF, 4)

    [/autoit] [autoit][/autoit] [autoit]

    $SLI = GUICtrlCreateSlider(5,5,490,30)
    GUICtrlSetLimit(-1, 1000, 0)

    [/autoit] [autoit][/autoit] [autoit]

    $PRO[0] = _ProgressCreate(7, 10, 0.1, 0x0060FF)
    $PRO[1] = _ProgressCreate(11, 25, 0.25, 0xFF6000)
    $PRO[2] = _ProgressCreate(25, 35, 0.2, 0x00FF60)

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister('_Dispose')
    GUISetOnEvent(-3, '_Event', $GUI)
    GUISetState(@SW_SHOW, $GUI)

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetLayeredWindowAttributes($GUI, 0x000000) ; <---

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    $PER = GUICtrlRead($SLI)/1000
    If $PER < 1 Then GUICtrlSetData($SLI, GUICtrlRead($SLI) + 1)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsClear($BUF)

    [/autoit] [autoit][/autoit] [autoit]

    _ProgressDraw($BUF, $W/4, $H/3 + 25, 250, 35, $PER, $PRO[0])
    _ProgressDraw($BUF, $W/4*3, $H/2 + 25, 150, 45, $PER, $PRO[1])
    _ProgressDraw($BUF, $W/2, $H/4*3 + 25, 150, 15, $PER, $PRO[2])

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImageRectRect($GFX, $BMP, 0, 50, $W, $H-50, 0, 50, $W, $H-50)

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ; Hier wird noch aufgeräumt.
    Func _ProgressCreate($iAnzahl = 9, $iDist = 10, $nAniTempo = 0.25, $iCol = 0x4080FF)
    Local $a[9]
    $a[0] = _GDIPlus_PenCreate()
    $a[1] = Hex($iCol, 6)
    $a[2] = $iDist
    $a[3] = 0
    $a[4] = Random(0, 10000) ; Animationsposition
    $a[5] = $iAnzahl
    $a[6] = 360 - 360 * $iDist / 100
    $a[7] = $nAniTempo
    $a[8] = _GDIPlus_PenCreate()
    ;~ DllCall($ghGDIPDll, "int", "GdipSetPenEndCap", "handle", $a[8], "int", $GDIP_LINECAPROUND)
    ;~ DllCall($ghGDIPDll, "int", "GdipSetPenStartCap", "handle", $a[8], "int", $GDIP_LINECAPROUND)
    ;~ _GDIPlus_PenSetEndCap($a[8], $GDIP_LINECAPROUND)
    Return $a
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDraw($hGfx, $mx, $my, $d1, $d2, $nPercent, ByRef $aProgress)
    ;~ If Round($nPercent,2) = 0 Then Return
    $aProgress[4] += $aProgress[7]
    Local $a, $b = 360*$nPercent, $c, $d = $aProgress[6]/$aProgress[5], $e = $d1/50, $f = ($nPercent = 1)

    [/autoit] [autoit][/autoit] [autoit]

    If $f Then
    ;~ DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $aProgress[0], 'dword', '0x80' & $aProgress[1])
    ;~ DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $aProgress[0], 'float', $e)
    ;~ DllCall($ghGDIPDll, 'int', 'GdipDrawEllipse', 'handle', $hGfx, 'handle', $aProgress[0], 'float', $mx - $d1/2 + $d2/2, 'float', $my - $d1/2 + $d2/2, 'float', $d1-$d2, 'float', $d1-$d2)
    ;~ DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $aProgress[0], 'dword', '0xEE' & $aProgress[1])
    ;~ DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $aProgress[0], 'float', $e/3)
    ;~ DllCall($ghGDIPDll, 'int', 'GdipDrawEllipse', 'handle', $hGfx, 'handle', $aProgress[0], 'float', $mx - $d1/2 + $d2/2 - $e/2, 'float', $my - $d1/2 + $d2/2 - $e/2, 'float', $d1-$d2+$e, 'float', $d1-$d2+$e)
    ;~ DllCall($ghGDIPDll, 'int', 'GdipDrawEllipse', 'handle', $hGfx, 'handle', $aProgress[0], 'float', $mx - $d1/2 + $d2/2 + $e/2, 'float', $my - $d1/2 + $d2/2 + $e/2, 'float', $d1-$d2-$e, 'float', $d1-$d2-$e)
    ;~ $d1 *= 0.8
    If $aProgress[3] < 15 Then $aProgress[3] += 1
    $d2 *= 0.97^$aProgress[3]
    $aProgress[4] += $aProgress[7]*1.1^$aProgress[3]
    Else
    If $aProgress[3] > 0 Then
    $aProgress[3] -= 1
    $d2 *= 0.97^$aProgress[3]
    $aProgress[4] += $aProgress[7]*1.1^$aProgress[3]
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To $aProgress[5] - 1 Step 1
    $a = $i * 360 / $aProgress[5] + $aProgress[4]
    $a -= Int($a/360)*360

    [/autoit] [autoit][/autoit] [autoit]

    If $b >= 360 / $aProgress[5] Then
    $c = 1
    $b -= 360 / $aProgress[5]
    Else
    $c = $b/(360 / $aProgress[5])
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Switch $c
    Case 0
    Case 0 To 0.33
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x' & Hex(Int($c*3*96)+32,2) & $aProgress[1])
    Case 0.33 To 0.66
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2/2, $a, $d, $aProgress[0], '0x' & Hex(Int(($c-0.33)*3*50),2) & 'FFFFFF')
    Case 0.66 To 0.99
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2/2, $a, $d, $aProgress[0], '0x32FFFFFF')
    _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[8], '0x' & Hex(Int(($c-0.66)*3*128),2) & $aProgress[1], 3)
    Case 0.99 To 1
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2/2, $a, $d, $aProgress[0], '0x32FFFFFF')
    _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[8], '0x80' & $aProgress[1], 3)
    If $f Then _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[8], '0xFF'& $aProgress[1], $e/3)
    EndSwitch
    If $c < 1 Then
    For $j = $i + 1 To $aProgress[5] - 1 Step 1
    $a = $j * 360 / $aProgress[5] + $aProgress[4]
    $a -= Int($a/360)*360
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x20808080')
    Next
    ExitLoop
    EndIf
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; Vorsicht ! Diese Funktion läuft noch nicht !!!
    Func _ProgressSet(ByRef $aProgress, $iAnzahl = 11, $iDist = 25, $nAniTempo = 0.1, $iCol = 0x00FF00)
    $iCol = Hex($iCol, 6)
    $aProgress[5] = $iAnzahl
    $aProgress[6] = 360 - 360 * $iDist / 100
    $aProgress[7] = $nAniTempo
    $aProgress[1] = '0x' & StringMid($iCol, 1, 2)
    $aProgress[2] = '0x' & StringMid($iCol, 3, 2)
    $aProgress[3] = '0x' & StringMid($iCol, 5, 2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDelete(ByRef $aProgress)
    _GDIPlus_PenDispose($aProgress[0])
    $aProgress = 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDrawPieSegment($hGfx, $mX, $mY, $D1, $D2, $fStart, $fSweep, $hPen, $iCol, $dPen)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $hPen, 'dword', $iCol)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $hPen, 'float', $dPen)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $D1/2, 'float', $my - $D1/2, 'float', $D1, 'float', $D1, 'float', $fStart+($dPen/($D1*3.14159265358979))*180, 'float', $fSweep-($dPen/($D1*3.14159265358979))*360)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $D1/2 + $D2, 'float', $my - $D1/2 + $D2, 'float', $D1-$D2*2, 'float', $D1-$D2*2, 'float', $fStart+($dPen/(($D1-$D2)*3.14159265358979))*180, 'float', $fSweep-($dPen/(($D1-$D2)*3.14159265358979))*360)
    DllCall($ghGDIPDll, 'int', 'GdipDrawLine', 'handle', $hGfx, 'handle', $hPen, 'float', $mx + ($D1-$D2*2-$dPen)/2*Cos($fStart*$Deg2Rad), 'float', $my + ($D1-$D2*2-$dPen)/2*Sin($fStart*$Deg2Rad), 'float', $mx + ($D1+$dPen)/2*Cos($fStart*$Deg2Rad), 'float', $my + ($D1+$dPen)/2*Sin($fStart*$Deg2Rad))
    DllCall($ghGDIPDll, 'int', 'GdipDrawLine', 'handle', $hGfx, 'handle', $hPen, 'float', $mx + ($D1-$D2*2-$dPen)/2*Cos(($fStart+$fSweep)*$Deg2Rad),'float', $my + ($D1-$D2*2-$dPen)/2*Sin(($fStart+$fSweep)*$Deg2Rad), 'float', $mx + ($D1+$dPen)/2*Cos(($fStart+$fSweep)*$Deg2Rad), 'float', $my + ($D1+$dPen)/2*Sin(($fStart+$fSweep)*$Deg2Rad))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressFillPieSegment($hGfx, $mX, $mY, $D1, $D2, $fStart, $fSweep, $hPen, $iCol)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $hPen, 'dword', $iCol)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $hPen, 'float', $D2)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mX - $D1 / 2 + $D2 / 2, 'float', $mY - $D1 / 2 + $D2 / 2, 'float', $D1 - $D2, 'float', $D1 - $D2, 'float', $fStart, 'float', $fSweep)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Event()
    Exit
    EndFunc ;==>_Event

    [/autoit] [autoit][/autoit] [autoit]

    Func _Dispose()
    _ProgressDelete($PRO)
    _GDIPlus_GraphicsDispose($BUF)
    _GDIPlus_BitmapDispose($BMP)
    _GDIPlus_GraphicsDispose($GFX)
    _GDIPlus_Shutdown()
    EndFunc ;==>_Dispose

    [/autoit]

    Sind TV-Quizfragen zu einfach? A) Ja B) Harry Potter

    Spoiler anzeigen

    Ich gebe zu dieser Post hat wahrscheinlich nicht viel geholfen,
    aber ich versuche wenigstens zu helfen :rolleyes:

  • Schön, dass es euch gefällt :)
    Selbstverständlich darf jeder nach eigenem Ermessen Modifikationen vornehmen.
    Solange es danach nicht vollkommen entstellt ist ( :D ) darf mein Name irgendwo auftauchen.
    Ein kleines Update (war Gestern Abend nicht mehr Willig im Code aufzuräumen) im ersten Post.

    • Offizieller Beitrag

    Hey

    UEZ: war auch etwas verwirrt ;) probiers mal so, echt schick :)

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('GUIOnEventMode', 1)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global Const $PI = 3.14159265358979
    Global Const $Deg2Rad = $PI / 180

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $W = 500, $H = 500

    [/autoit] [autoit][/autoit] [autoit]

    Global $GFX, $SLI, $PER, $PRO[3], $BUF, $BMP, $CNT, $NUM

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $GUI = GUICreate('Test', $W, $H)
    $GFX = _GDIPlus_GraphicsCreateFromHWND($GUI)
    $BMP = _GDIPlus_BitmapCreateFromGraphics($W, $H, $GFX)
    $BUF = _GDIPlus_ImageGetGraphicsContext($BMP)
    _GDIPlus_GraphicsSetSmoothingMode($BUF, 4)

    [/autoit] [autoit][/autoit] [autoit]

    $SLI = GUICtrlCreateSlider(5, 5, 490, 30)
    GUICtrlSetLimit(-1, 1000, 0)
    ;anz der bars, entfernung, drehrichtung/geschwindigkeit, farbe1, farbe2
    $PRO[0] = _ProgressCreate(50, 20, 0.32, 0x0060FF, 0x30002080)
    $PRO[1] = _ProgressCreate(10, 25, -0.75, 0xFF6000, 0x30802000)
    $PRO[2] = _ProgressCreate(25, 35, 0.2, 0x00FF60, 0x30008020)

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister('_Dispose')
    GUISetOnEvent(-3, '_Event', $GUI)
    GUISetState(@SW_SHOW, $GUI)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While Sleep(40);25fps
    If $PER < 1 Then $PER += 0.01
    $CNT += 1

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsClear($BUF)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _ProgressDraw($BUF, $W / 4, $H / 3 + 25, 250, 35, $PER, $PRO[0])
    _ProgressDraw($BUF, $W / 4 * 3, $H / 2 + 25, 150, 45, $PER, $PRO[1])
    _ProgressDraw($BUF, $W / 2, $H / 4 * 3 + 25, 150, 15, $PER, $PRO[2])

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawImageRectRect($GFX, $BMP, 0, 50, $W, $H - 50, 0, 50, $W, $H - 50)

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressSet(ByRef $aProgress, $iAnzahl = 0, $nDist = 0, $nAniTempo = 0, $iCol = 0, $iColIdle = 0, $iPos = 0)
    If $iCol Then $aProgress[1] = StringRight(Hex($iCol, 8), 6) ; Farbe des Ladebalkens (Alpha wird ignoriert), möglich ist also 0xFFAARRGGBB oder 0xRRGGBB
    If $iColIdle Then $aProgress[2] = $iColIdle ; Farbe der nicht benutzen Flächen (Alpha ist relevant !)
    If $iPos Then $aProgress[4] = $iPos ; Animationscounter (drehanimation)
    If $iAnzahl Then $aProgress[5] = $iAnzahl ; Anzahl Segmente für den Ladebalken
    If $nDist Then $aProgress[6] = 360 - 3.6 * $nDist ; Abstand zwischen den Segmenten (0 < $nDist < 100)
    If $nAniTempo Then $aProgress[7] = $nAniTempo ; Drehgeschwindigkeit in Grad/Frame. (negativer Wert = drehung gegen deh Uhrzeigersinn)
    EndFunc ;==>_ProgressSet

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressCreate($iAnzahl = 9, $nDist = 10, $nAniTempo = 0.25, $iCol = 0xFF4080FF, $iColIdle = 0x20808080, $iStartPos = 0)
    If Not $iStartPos Then $iStartPos = Random(0, 360)
    Local $a[8]
    $a[0] = _GDIPlus_PenCreate() ; GDI+ Pen
    $a[1] = StringRight(Hex($iCol, 8), 6) ; Farbe des Ladebalkens (Alpha wird ignoriert), möglich ist also 0xFFAARRGGBB oder 0xRRGGBB
    $a[2] = $iColIdle ; Farbe der nicht benutzen Flächen (Alpha ist relevant !)
    $a[3] = 0 ; Animationscounter (100% Animation)
    $a[4] = $iStartPos ; Animationscounter (drehanimation)
    $a[5] = $iAnzahl ; Anzahl Segmente für den Ladebalken
    $a[6] = 360 - 3.6 * $nDist ; Abstand zwischen den Segmenten (0 < $nDist < 100)
    $a[7] = $nAniTempo ; Drehgeschwindigkeit in Grad/Frame. (negativer Wert = drehung gegen deh Uhrzeigersinn)
    Return $a
    EndFunc ;==>_ProgressCreate

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDraw($hGfx, $mx, $my, $d1, $d2, $nPercent, ByRef $aProgress)
    $aProgress[4] += $aProgress[7]
    Local $a, $b = 360 * $nPercent, $c, $d = $aProgress[6] / $aProgress[5], $e = $d1 / 50, $f = ($nPercent = 1), $g = $aProgress[4] - Int($aProgress[4]/360)*360
    If $f Then
    If $aProgress[3] < 15 Then $aProgress[3] += 1
    $d2 *= 0.97 ^ $aProgress[3]
    $aProgress[4] += $aProgress[7] * 1.1 ^ $aProgress[3]
    Else
    If $aProgress[3] > 0 Then
    $aProgress[3] -= 1
    $d2 *= 0.97 ^ $aProgress[3]
    $aProgress[4] += $aProgress[7] * 1.1 ^ $aProgress[3]
    EndIf
    EndIf
    For $i = 0 To $aProgress[5] - 1 Step 1
    $a = $i * 360 / $aProgress[5] + $g
    If $b >= 360 / $aProgress[5] Then
    $c = 1
    $b -= 360 / $aProgress[5]
    Else
    $c = $b / (360 / $aProgress[5])
    EndIf
    Switch $c
    Case 0
    Case 0 To 0.33
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x' & Hex(Int($c * 3 * 96) + 32, 2) & $aProgress[1])
    Case 0.33 To 0.66
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2 / 2, $a, $d, $aProgress[0], '0x' & Hex(Int(($c - 0.33) * 150), 2) & 'FFFFFF')
    Case 0.66 To 0.99
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2 / 2, $a, $d, $aProgress[0], '0x32FFFFFF')
    _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x' & Hex(Int(($c - 0.66) * 384), 2) & $aProgress[1], 3)
    Case 0.99 To 1
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1])
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2 / 2, $a, $d, $aProgress[0], '0x32FFFFFF')
    _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0x80' & $aProgress[1], 3)
    If $f Then _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0], '0xFF' & $aProgress[1], $e / 3)
    EndSwitch
    If $c < 1 Then
    DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $aProgress[0], 'dword', $aProgress[2])
    DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $aProgress[0], 'float', $d2)
    For $j = $i + 1 To $aProgress[5] - 1 Step 1
    $a = $j * 360 / $aProgress[5] + $aProgress[4]
    $a -= Int($a / 360) * 360
    _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $a, $d, $aProgress[0])
    Next
    ExitLoop
    EndIf
    Next
    EndFunc ;==>_ProgressDraw

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDelete(ByRef $aProgress, $iSLN = @ScriptLineNumber)
    _GDIPlus_PenDispose($aProgress[0])
    $aProgress = 0
    EndFunc ;==>_ProgressDelete

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressDrawPieSegment($hGfx, $mx, $my, $d1, $d2, $fStart, $fSweep, $hPen, $iCol, $dPen)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $hPen, 'dword', $iCol)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $hPen, 'float', $dPen)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $d1 / 2, 'float', $my - $d1 / 2, 'float', $d1, 'float', $d1, 'float', $fStart + ($dPen / ($d1 * $PI)) * 180, 'float', $fSweep - ($dPen / ($d1 * $PI)) * 360)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $d1 / 2 + $d2, 'float', $my - $d1 / 2 + $d2, 'float', $d1 - $d2 * 2, 'float', $d1 - $d2 * 2, 'float', $fStart + ($dPen / (($d1 - $d2) * $PI)) * 180, 'float', $fSweep - ($dPen / (($d1 - $d2) * $PI)) * 360)
    DllCall($ghGDIPDll, 'int', 'GdipDrawLine', 'handle', $hGfx, 'handle', $hPen, 'float', $mx + ($d1 - $d2 * 2 - $dPen) / 2 * Cos($fStart * $Deg2Rad), 'float', $my + ($d1 - $d2 * 2 - $dPen) / 2 * Sin($fStart * $Deg2Rad), 'float', $mx + ($d1 + $dPen) / 2 * Cos($fStart * $Deg2Rad), 'float', $my + ($d1 + $dPen) / 2 * Sin($fStart * $Deg2Rad))
    DllCall($ghGDIPDll, 'int', 'GdipDrawLine', 'handle', $hGfx, 'handle', $hPen, 'float', $mx + ($d1 - $d2 * 2 - $dPen) / 2 * Cos(($fStart + $fSweep) * $Deg2Rad), 'float', $my + ($d1 - $d2 * 2 - $dPen) / 2 * Sin(($fStart + $fSweep) * $Deg2Rad), 'float', $mx + ($d1 + $dPen) / 2 * Cos(($fStart + $fSweep) * $Deg2Rad), 'float', $my + ($d1 + $dPen) / 2 * Sin(($fStart + $fSweep) * $Deg2Rad))
    EndFunc ;==>_ProgressDrawPieSegment

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProgressFillPieSegment($hGfx, $mx, $my, $d1, $d2, $fStart, $fSweep, $hPen, $iCol = 0)
    If Not $iCol Then Return DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $d1 / 2 + $d2 / 2, 'float', $my - $d1 / 2 + $d2 / 2, 'float', $d1 - $d2, 'float', $d1 - $d2, 'float', $fStart, 'float', $fSweep)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenColor', 'handle', $hPen, 'dword', $iCol)
    DllCall($ghGDIPDll, 'int', 'GdipSetPenWidth', 'handle', $hPen, 'float', $d2)
    DllCall($ghGDIPDll, 'int', 'GdipDrawArc', 'handle', $hGfx, 'handle', $hPen, 'float', $mx - $d1 / 2 + $d2 / 2, 'float', $my - $d1 / 2 + $d2 / 2, 'float', $d1 - $d2, 'float', $d1 - $d2, 'float', $fStart, 'float', $fSweep)
    EndFunc ;==>_ProgressFillPieSegment

    [/autoit] [autoit][/autoit] [autoit]

    Func _Event()
    Exit
    EndFunc ;==>_Event

    [/autoit] [autoit][/autoit] [autoit]

    Func _Dispose($iSLN = @ScriptLineNumber)
    For $i = 0 To UBound($PRO) - 1 Step 1
    _ProgressDelete($PRO[$i])
    Next
    _GDIPlus_GraphicsDispose($BUF)
    _GDIPlus_BitmapDispose($BMP)
    _GDIPlus_GraphicsDispose($GFX)
    _GDIPlus_Shutdown()
    EndFunc ;==>_Dispose

    [/autoit]

    Gruß
    Spider

  • Hi GtaSpider,

    ist schon klar, wenn du die 5 Zeilen weg lässt, dass es geht, aber

    Zitat

    Edit: Nun ist der Code etwas besser aufgeräumt
    + ProgressSet Funktion läuft
    + Eine Hand voll mehr Einstellungsmöglichkeiten


    ProgressSet Funktion läuf bei mir nicht ;)

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Hi GtaSpider,

    ist schon klar, wenn du die 5 Zeilen weg lässt, dass es geht, aber


    ProgressSet Funktion läuf bei mir nicht ;)

    Gruß,
    UEZ


    Eventuell sollte ich die Funktion umbenennen, aber sie tut genau das was sie soll.
    Die Prozentzahl wird schon beim Zeichnen angegeben, daher ist der ProgressSet für diesen Wert überflüssig.
    Die Funktion ist dazu da um die Attribute (Farben, Drehung, usw) anzupassen.
    Alle im Beispiel befindlichen Ladebalken zeigen den gleichen Stand (den vom Slider oben), ProgressSet zeigt nur die verschiedenen Designmöglichkeiten.