#include <GDIPlus.au3>
#include <Misc.au3>


; #FUNCTION# ======================================================================================
; Name ..........: _GDIPlus_CreateRoundSlider()
; Syntax ........: _GDIPlus_CreateRoundSlider($hWnd, $hGraphics, $mittelpunktx, $mittelpunkty, $radius, $wert, $color1, $color2[, $pointradius = 5[, $maxwert = 100]])
; Parameters ....: $hWnd         - Window Handle
;                  $hGraphics    - Handle zu einem Graphics Objekt
;                  $mittelpunktx - X Kooardinate des Mittelpunktes
;                  $mittelpunkty - Y Kooardinate des Mittelpunktes
;                  $radius       - Radius des Sliders
;                  $wert         - Startwert
;                  $color1       - Farbe der Linie
;                  $color2       - Farbe des Punktes
;                  $pointradius  - [optional] Radius des punktes (default:5)
;                  $maxwert      - [optional] Maximalwert (default:100)
; Return values .: Success: Slider Handle
;                  Failure: @error = 1 Startwert > Maximalwert
; Author ........: yxyx
; Related .......: _GDIPlus_CheckRoundSlider, _GDIPlus_ReadSlider, _GDIPlus_SetSlider
; =================================================================================================


Func _GDIPlus_CreateRoundSlider($hWnd, $hGraphics, $mittelpunktx, $mittelpunkty, $radius, $wert, $color1, $color2, $pointradius = 5, $maxwert = 100)
	If $wert > $maxwert Then Return SetError(1,0,0)
	Local $dll, $pen
	$pen = _GDIPlus_PenCreate($color1, 2)
	$brush = _GDIPlus_BrushCreateSolid($color2)
	$dll = DllStructCreate("int;int;int;int;int;int;int;int;int;int")
	DllStructSetData($dll, 1, $mittelpunktx)
	DllStructSetData($dll, 2, $mittelpunkty)
	DllStructSetData($dll, 3, $wert)
	DllStructSetData($dll, 4, $pen)
	DllStructSetData($dll, 5, $brush)
	DllStructSetData($dll, 6, $hGraphics)
	DllStructSetData($dll, 8, $maxwert)
	DllStructSetData($dll, 9, $radius)
	DllStructSetData($dll, 10, $pointradius)
	DllStructSetData($dll, 11, $hWnd)
	Return $dll
EndFunc


; #FUNCTION# ======================================================================================
; Name ..........: _GDIPlus_CheckRoundSlider()
; Syntax ........: _GDIPlus_CheckRoundSlider($handle)
; Parameters ....: $handle - Round Slider Handle
; Author ........: yxyx
; Related .......: _GDIPlus_CreateRoundSlider, _GDIPlus_ReadSlider, _GDIPlus_SetSlider
; =================================================================================================


Func _GDIPlus_CheckRoundSlider($handle)
	Local $dllread[11] = [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), DllStructGetData($handle, 11), DllStructGetData($handle, 10)]
	Local $dllwrite, $iAngel, $pos = GUIGetCursorInfo($dllread[9]), $pi = ATan(1)*4, $userdll = DllOpen("user32.dll")
	If not IsArray($pos) Then
	_GDIPlus_GraphicsDrawArc($dllread[5], $dllread[0]-$dllread[8],	$dllread[1]-$dllread[8],2*$dllread[8],2*$dllread[8],130,280, $dllread[3])
	_GDIPlus_GraphicsfillEllipse($dllread[5], $dllread[0] - cos((280/$dllread[7]*$dllread[2]-50)/180*$pi)*$dllread[8]-$dllread[10] , $dllread[1]- sin((280/$dllread[7]*$dllread[2]-50)/180*$pi)*$dllread[8]-$dllread[10], 2*$dllread[10], 2*$dllread[10], $dllread[4])
	Return
	EndIf
    $iAngle = Round(__GetLineDegreeX($pos[0] - $dllread[0], $pos[1] - $dllread[1]), 2)+50
    If $pos[0] >= $dllread[0] Then $iAngle += 180
    If $pos[1] >= $dllread[1] And $pos[0] <= $dllread[0] Then $iAngle +=360
	If $iAngle > 360 Then $iAngle -= 360
	If _IsPressed("01", $userdll) Then
		If __PointIsInCircle($pos[0], $pos[1], $dllread[0] - cos((280/$dllread[7]*$dllread[2]-50)/180*$pi)*$dllread[8], $dllread[1] - sin((280/$dllread[7]*$dllread[2]-50)/180*$pi)*$dllread[8], $dllread[10]) or $dllread[6] Then
			DllStructSetData($handle, 7, "1")
			$dllwrite = Round($iAngle/(280/$dllread[7]))
			If $iAngle > 320 Then $dllwrite = 0
			If $dllwrite <= 0 Then $dllwrite = 0
			If $dllwrite > $dllread[7] Then $dllwrite = $dllread[7]
			DllStructSetData($handle, 3, $dllwrite)
		Else
			DllStructSetData($handle, 7, "0")
		EndIf
	Else
		DllStructSetData($handle, 7, "0")
	EndIf

	_GDIPlus_GraphicsDrawArc($dllread[5], $dllread[0]-$dllread[8],	$dllread[1]-$dllread[8],2*$dllread[8],2*$dllread[8],130,280, $dllread[3])
	_GDIPlus_GraphicsfillEllipse($dllread[5], $dllread[0] - cos((280/$dllread[7]*$dllread[2]-50)/180*$pi)*$dllread[8]-$dllread[10] , $dllread[1]- sin((280/$dllread[7]*$dllread[2]-50)/180*$pi)*$dllread[8]-$dllread[10], 2*$dllread[10], 2*$dllread[10], $dllread[4])
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_CheckRoundSlider, _GDIPlus_CreateRoundSlider, _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_CheckRoundSlider, _GDIPlus_CreateRoundSlider, _GDIPlus_ReadSlider
; =================================================================================================
Func _GDIPlus_SetSlider($handle, $value)
	If $value <= DllStructGetData($handle, 8) and $value >= 0 Then Return DllStructSetData($handle, 3, $value)
EndFunc

Func __PointIsInCircle($iX_Point, $iY_Point, $iX_Circle, $iY_Circle, $iRadius_Circle)
	;Author: name22
    $iDistPoints = Sqrt(($iX_Point - $iX_Circle) ^ 2 + ($iY_Point - $iY_Circle) ^ 2)
    If ($iRadius_Circle > 0 And $iDistPoints < $iRadius_Circle) Or ($iRadius_Circle < 0 And $iDistPoints > $iRadius_Circle) Or $iDistPoints = 0 Then Return True
    Return False
EndFunc   ;==>_PointIsInCircle

Func __GetLineDegreeX($iX_Point, $iY_Point, $iFlag = 0)
	;Author: name22
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, 0)
	Return ATan($iY_Point / $iX_Point) / (ACos(-1) / 180)
EndFunc