#include-once

; #INDEX# ======================================================================
; Title:           LevelMeter
; AutoIt Version:  3.3.0.0
; Language:        German
; Description:     Audio-Aussteuerungsanzeige
;
; Funktions:
; _GUICtrlLevelMeter_Create()
; _GuiCtrlLevelMeter_Delete()
; _GUICtrlLevelMeter_SetData()
; _GUICtrlLevelMeter_SetStyle()
;===============================================================================


;===============================================================================
; Function Name:   _GUICtrlLevelMeter_Create($hWnd, $iX, $iY[, $iWidth][, $bSmooth])
; Description::    Erstellt eine Audio-Aussteuerungsanzeige
; Parameter(s):    $hWnd = Handle der GUI (Rückgabewert von GuiCreate)
;                  $iX = X-Position
;                  $iY = Y-Position
;                  $iWidth = Breite der Anzeige (wenn kleiner als 250 wird eine
;                            Mindestbreite von 250 benutzt)
;                  $bSmooth = True/False (ausgefüllte oder Balkenanzeige)
; Requirement(s):  ---
; Return Value(s): Im Erfolgsfall wird ein Array für den Aufruf der anderen
;                  Funktionen zurückgegeben.
;                  Bei einem Fehler wird Null zurückgegeben und @error:
;                  1 = $hWnd ist kein Fenster-Handle
;                  2 = X-Position + Breite überschreitet die Fensterbreite
; Author(s):       Oscar (www.autoit.de)
;===============================================================================
Func _GUICtrlLevelMeter_Create($hWnd, $iX, $iY, $iWidth = 250, $bSmooth = False)
	If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0)
	Local $ahLM[2][5], $aColors[4] = [0xFFFFDD, 0x44CC44, 0xFFAA55, 0xFF5555]
	Local $aClientSize, $iPBStyle = 0
	$aClientSize = WinGetClientSize($hWnd)
	If $iWidth < 250 Or $iWidth = Default Then $iWidth = 250
	If $iX + $iWidth > $aClientSize[0] Then Return SetError(2, 0, 0)
	$iWidth -= 30
	If $bSmooth Then $iPBStyle = 0x01
	Local $aWidth[3] = [Int($iWidth / 100 * 88), Int($iWidth / 100 * 9), Int($iWidth / 100 * 3)]
	DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 0)
	$ahLM[0][0] = GUICtrlCreateProgress($iX, $iY + 1, $aWidth[0], 10, $iPBStyle)
	GUICtrlSetColor(-1, $aColors[1])
	GUICtrlSetBkColor(-1, $aColors[0])
	$ahLM[1][0] = GUICtrlCreateProgress($iX, $iY + 18, $aWidth[0], 10, $iPBStyle)
	GUICtrlSetColor(-1, $aColors[1])
	GUICtrlSetBkColor(-1, $aColors[0])
	$iX += $aWidth[0]
	$ahLM[0][1] = GUICtrlCreateProgress($iX, $iY + 1, $aWidth[1], 10, $iPBStyle)
	GUICtrlSetColor(-1, $aColors[2])
	GUICtrlSetBkColor(-1, $aColors[0])
	$ahLM[1][1] = GUICtrlCreateProgress($iX, $iY + 18, $aWidth[1], 10, $iPBStyle)
	GUICtrlSetColor(-1, $aColors[2])
	GUICtrlSetBkColor(-1, $aColors[0])
	$iX += $aWidth[1]
	$ahLM[0][2] = GUICtrlCreateProgress($iX, $iY + 1, $aWidth[2], 10, $iPBStyle)
	GUICtrlSetColor(-1, $aColors[3])
	GUICtrlSetBkColor(-1, $aColors[0])
	$ahLM[1][2] = GUICtrlCreateProgress($iX, $iY + 18, $aWidth[2], 10, $iPBStyle)
	GUICtrlSetColor(-1, $aColors[3])
	GUICtrlSetBkColor(-1, $aColors[0])
	$iX += $aWidth[2] + 4
	$ahLM[0][3] = GUICtrlCreateLabel('Left', $iX, $iY, 26, 12)
	GUICtrlSetFont(-1, 8, 400, 0, 'Tahoma')
	$ahLM[1][3] = GUICtrlCreateLabel('Right', $iX, $iY + 17, 26, 12)
	GUICtrlSetFont(-1, 8, 400, 0, 'Tahoma')
	DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 7)
	$ahLM[0][4] = 0
	$ahLM[1][4] = 0
	Return $ahLM
EndFunc

;===============================================================================
; Function Name:   _GuiCtrlLevelMeter_Delete($hWnd)
; Description::    Löscht eine Audio-Aussteuerungsanzeige
; Parameter(s):    $hWnd = Rückgabewert von _GUICtrlLevelMeter_Create
; Requirement(s):  ---
; Return Value(s): Im Erfolgsfall wird 1 zurückgegeben.
;                  Bei einem Fehler wird Null zurückgegeben und @error:
;                  1 = $hWnd ist kein Array
;                  2 = $hWnd ist kein 2D Array
;                  3 = das Array hat nicht die richtigen Dimensionen
; Author(s):       Oscar (www.autoit.de)
;===============================================================================
Func _GuiCtrlLevelMeter_Delete(ByRef $hWnd)
	If Not IsArray($hWnd) Then Return SetError(1, 0, 0)
	If UBound($hWnd, 0) <> 2 Then Return SetError(2, 0, 0)
	If UBound($hWnd, 1) <> 2 Or UBound($hWnd, 2) <> 5 Then Return SetError(3, 0, 0)
	For $i = 0 To 3
		GUICtrlDelete($hWnd[0][$i])
		GUICtrlDelete($hWnd[1][$i])
	Next
	$hWnd = 0
	Return SetError(0, 0, 1)
EndFunc

;===============================================================================
; Function Name:   _GUICtrlLevelMeter_SetData($hWnd, $iLeft, $iRight)
; Description::    Setzt die Links/Rechts-Werte für eine Audio-Aussteuerungsanzeige
; Parameter(s):    $hWnd = Rückgabewert von _GUICtrlLevelMeter_Create
;                  $iLeft = Wert für die linke Anzeige (0...100)
;                  $iRight = Wert für die rechte Anzeige (0...100)
; Requirement(s):  ---
; Return Value(s): Im Erfolgsfall wird 1 zurückgegeben.
;                  Bei einem Fehler wird Null zurückgegeben und @error:
;                  1 = $hWnd ist kein Array
;                  2 = $hWnd ist kein 2D Array
;                  3 = das Array hat nicht die richtigen Dimensionen
; Author(s):       Oscar (www.autoit.de)
;===============================================================================
Func _GUICtrlLevelMeter_SetData(ByRef $hWnd, $iLeft, $iRight)
	If Not IsArray($hWnd) Then Return SetError(1, 0, 0)
	If UBound($hWnd, 0) <> 2 Then Return SetError(2, 0, 0)
	If UBound($hWnd, 1) <> 2 Or UBound($hWnd, 2) <> 5 Then Return SetError(3, 0, 0)
	If $iLeft > 100 Then $iLeft = 100
	If $iLeft < 0 Then $iLeft = 0
	If $iRight > 100 Then $iRight = 100
	If $iRight < 0 Then $iRight = 0
	Local $iVal[2][3]
	$iVal[0][0] = 100 / 88 * $iLeft
	$iVal[1][0] = 100 / 88 * $iRight
	$iVal[0][1] = ($iLeft - 88) * 10
	$iVal[1][1] = ($iRight - 88) * 10
	$iVal[0][2] = ($iLeft - 97) * 33.4
	$iVal[1][2] = ($iRight - 97) * 33.4
	For $i = 0 To 2
		GUICtrlSetData($hWnd[0][$i], $iVal[0][$i])
		GUICtrlSetData($hWnd[1][$i], $iVal[1][$i])
	Next
	$hWnd[0][4] = $iLeft
	$hWnd[1][4] = $iRight
	Return SetError(0, 0, 1)
EndFunc

;===============================================================================
; Function Name:   _GUICtrlLevelMeter_SetStyle($hWnd, $bSmooth)
; Description::    Setzt den Style einer Audio-Aussteuerungsanzeige
; Parameter(s):    $hWnd = Rückgabewert von _GUICtrlLevelMeter_Create
;                  $bSmooth = True/False (ausgefüllte oder Balkenanzeige)
; Requirement(s):  ---
; Return Value(s): Im Erfolgsfall wird 1 zurückgegeben.
;                  Bei einem Fehler wird Null zurückgegeben und @error:
;                  1 = $hWnd ist kein Array
;                  2 = $hWnd ist kein 2D Array
;                  3 = das Array hat nicht die richtigen Dimensionen
; Author(s):       Oscar (www.autoit.de)
;===============================================================================
Func _GUICtrlLevelMeter_SetStyle(ByRef $hWnd, $bSmooth)
	If Not IsArray($hWnd) Then Return SetError(1, 0, 0)
	If UBound($hWnd, 0) <> 2 Then Return SetError(2, 0, 0)
	If UBound($hWnd, 1) <> 2 Or UBound($hWnd, 2) <> 5 Then Return SetError(3, 0, 0)
	Local $iPBStyle = 0
	If $bSmooth Then $iPBStyle = 0x01
	For $i = 0 To 2
		GUICtrlSetStyle($hWnd[0][$i], $iPBStyle)
		GUICtrlSetStyle($hWnd[1][$i], $iPBStyle)
	Next
	_GUICtrlLevelMeter_SetData($hWnd, $hWnd[0][4], $hWnd[1][4])
	Return SetError(0, 0, 1)
EndFunc
