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...)
#include <GDIPlus.au3>
Opt('GUIOnEventMode', 1)
[/autoit] [autoit][/autoit] [autoit]Global Const $PI = 3.14159265358979
Global Const $Deg2Rad = $PI / 180
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)
$SLI = GUICtrlCreateSlider(5, 5, 490, 30)
GUICtrlSetLimit(-1, 1000, 0)
$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)
OnAutoItExitRegister('_Dispose')
GUISetOnEvent(-3, '_Event', $GUI)
GUISetState(@SW_SHOW, $GUI)
While Sleep(10)
$PER = GUICtrlRead($SLI) / 1000
If $PER < 1 Then GUICtrlSetData($SLI, GUICtrlRead($SLI) + 1)
$CNT += 1
_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
_ProgressSet($PRO[0], $PER)
_ProgressSet($PRO[1], 1 - $PER)
_ProgressSet($PRO[2], $PER/2)
_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])
_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
Func _ProgressSet(ByRef $aProgress, $nPercent)
If $nPercent <= 1 Then
$aProgress[9] = $nPercent
Else
$aProgress[9] = $nPercent / 100
EndIf
EndFunc
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
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
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
Func _ProgressDelete(ByRef $aProgress)
_GDIPlus_PenDispose($aProgress[0])
$aProgress = 0
EndFunc ;==>_ProgressDelete
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
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
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
Func _Image_Delete(ByRef $vStruct)
_WinAPI_DeleteObject(DllStructGetData($vStruct, 1, 5))
_WinAPI_DeleteDC(DllStructGetData($vStruct, 1, 1))
$vStruct = 0
EndFunc ;==>_Image_Delete
Func _Event()
Exit
EndFunc ;==>_Event
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
lg
Mars