#include <GDIPlus.au3>
#include <Misc.au3>

; #FUNCTION# ======================================================================================
; Name ..........: _GDIPlus_CreateSlider()
; Syntax ........: _GDIPlus_CreateSlider($hGraphics, $x, $y, $width, $wert, $color1, $color2[, $maxwert = 100])
; Parameters ....: $hGraphics - Handle zu dem Grafik-Objekt
;                  $x         - X-Koordinate
;                  $y         - y-Koordinate
;                  $width     - Die Breite des Sliders
;                  $wert      - Der Startwert
;                  $color1    - Die Farbe der Linie und der Umrandung des Reglers
;                  $color2    - Die Füllfarbe des Reglers
;                  $maxwert   - [optional] Der Maximalwert (default:100)
; Return values .: Slider Handle
; Author ........: yxyx
; Related .......: _GDIPlus_CheckSlider, _GDIPlus_ReadSlider, _GDIPlus_SetSlider
; =================================================================================================
Func _GDIPlus_CreateSlider($hGraphics, $x, $y, $width, $wert, $color1, $color2, $maxwert = 100)
	If $wert > $maxwert Then Return SetError(1,0,0)
	Opt("MouseCoordMode", 0)
	Local $dll, $pen
	$pen = _GDIPlus_PenCreate($color1, 2)
	$brush = _GDIPlus_BrushCreateSolid($color2)
	$dll = DllStructCreate("int;int;int;int;int;int;int;int;int")
	DllStructSetData($dll, 1, $x)
	DllStructSetData($dll, 2, $y)
	DllStructSetData($dll, 3, $wert)
	DllStructSetData($dll, 4, $pen)
	DllStructSetData($dll, 5, $brush)
	DllStructSetData($dll, 6, $hGraphics)
	DllStructSetData($dll, 8, $maxwert)
	DllStructSetData($dll, 9, $width)
	Return $dll
EndFunc


; #FUNCTION# ======================================================================================
; Name ..........: _GDIPlus_CheckSlider()
; Syntax ........: _GDIPlus_CheckSlider($handle)
; Parameters ....: $handle - Slider Handle
; Author ........: yxyx
; Related .......: _GDIPlus_CreateSlider, _GDIPlus_ReadSlider, _GDIPlus_SetSlider
; =================================================================================================

Func _GDIPlus_CheckSlider($handle)
	Local $pos = MouseGetPos(), $userdll = DllOpen("user32.dll"), $dllread[9] = [DllStructGetData($handle, 1), DllStructGetData($handle, 2), DllStructGetData($handle, 3), DllStructGetData($handle, 4), DllStructGetData($handle, 5), DllStructGetData($handle, 6), DllStructGetData($handle, 7), DllStructGetData($handle, 8), DllStructGetData($handle, 9)]
	Local $dllwrite, $step = $dllread[8]/$dllread[7]
	_GDIPlus_GraphicsDrawLine($dllread[5], $dllread[0], $dllread[1]+10, $dllread[0]+$dllread[8], $dllread[1]+10, $dllread[3])
	$pos[1] -= 23
	If _IsPressed("01", $userdll) Then
		If ($pos[0] > $dllread[0]+$step*$dllread[2]-5 and $pos[0] < $dllread[0]+$step*$dllread[2]+5 and $pos[1] > $dllread[1] and $pos[1] < $dllread[1]+20) or $dllread[6] Then
			DllStructSetData($handle, 7, "1")
			$dllwrite = Round(($pos[0]-$dllread[0])/$step)
			If $pos[0] <= $dllread[0] Then $dllwrite = 0
			If $pos[0] >= $dllread[0]+$dllread[8] Then $dllwrite = $dllread[7]
			DllStructSetData($handle, 3, $dllwrite)
		Else
			DllStructSetData($handle, 7, "0")
		EndIf
	Else
		DllStructSetData($handle, 7, "0")
	EndIf
	Local $points[6][2] = [[5,0], [$dllread[0]+$step*$dllread[2] -5, $dllread[1]],[$dllread[0]+$step*$dllread[2] -5, $dllread[1]+17],[$dllread[0]+$step*$dllread[2], $dllread[1]+20],[$dllread[0]+$step*$dllread[2] +5, $dllread[1]+17],[$dllread[0]+$step*$dllread[2] +5, $dllread[1]]]

	_GDIPlus_GraphicsFillPolygon($dllread[5], $points, $dllread[4])
	_GDIPlus_GraphicsDrawPolygon($dllread[5], $points, $dllread[3])
EndFunc

; #FUNCTION# ======================================================================================
; Name ..........: _GDIPlus_ReadSlider()
; Syntax ........: _GDIPlus_ReadSlider($handle)
; Parameters ....: $handle - Slider Handle
; Return values .: Success: Aktueller Wert des Slider Handles
;                  Failure: 1
; Author ........: yxyx
; Related .......: _GDIPlus_CheckSlider, _GDIPlus_CreateSlider, _GDIPlus_SetSlider
; =================================================================================================
Func _GDIPlus_ReadSlider($handle)
	Return DllStructGetData($handle, 3)
EndFunc


; #FUNCTION# ======================================================================================
; Name ..........: _GDIPlus_SetSlider()
; Description ...: Description
; Syntax ........: _GDIPlus_SetSlider($handle, $value)
; Parameters ....: $handle - Slider Handle
;                  $value  - Wert
; Return values .: Success: 0
;                  Failure: 1
; Author ........: yxyx
; Related .......: _GDIPlus_CheckSlider, _GDIPlus_CreateSlider, _GDIPlus_ReadSlider
; =================================================================================================
Func _GDIPlus_SetSlider($handle, $value)
	If $value <= DllStructGetData($handle, 8) and $value >= 0 Then Return DllStructSetData($handle, 3, $value)
EndFunc