GDI+ Farbverlauf vom Mittelpunkt eines Kreises

  • Hier die Funktion und ein Beispiel dazu. :)
    Benötigt wird die GDIP.au3 (Anhang).
    Ich hoffe, dass irgendjemand das gebrauchen kann. :D Ich enstschuldige mich schon mal im vorraus für die schlecht formulierte Beschreibung. ^^

    Funktion:

    Spoiler anzeigen
    [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_PathBrushCreatePie
    ; Beschreibung ..: Erstellt einen Farbverlauf in Form eines "Kuchens" (Teil eines Kreises) mit 2 Farben eine beginnend in der Mitte der Ellipse aus der der "Kuchen" erstellt wird und eine die auf dem Umkreis der Ellipse verläuft.
    ; Syntax.........: _GDIPlus_PathBrushCreatePie($iX, $iY, $iWidth, $iHeight, $iStartAngle, $iSweepAngle, $ARGB_Center, $ARGB_Surround, [$iWrapMode = 4])
    ; Parameter .....: $iX - X - Koordinate der linken oberen Ecke des Rechtecks aus dem die Ellipse des Kuchenstücks erstellt wird
    ; $iY - Y - Koordinate der linken oberen Ecke des Rechtecks aus dem die Ellipse des Kuchensstücks erstellt wird
    ; $iWidth - Breite der Ellipse
    ; $iHeight - Höhe der Ellipse
    ; $iStartAngle - Startwinkel des Kuchenstücks
    ; $iSweepAngle - Winkel der zum Startwinkel addiert wird und den Endwinkel bestimmt (Ein negativer Wert bedeutet eine "Rotation" nach links)
    ; $ARGB_Center - Farbe für den Mittelpunkt der Ellipse
    ; $ARGB_Surround - Farbe für den Umkreis der Ellipse
    ; $iWrapMode - Wrap mode der die Aufteilung und die Spiegelung des Brushes definiert (Standard 4):
    ; |0 - Teilen ohne spiegeln
    ; |1 - Teile werden horizontal gespiegelt wenn die Größe des Brush in X Richtung überschritten wird
    ; |2 - Teile werden vertikal gespiegelt wenn die Größe des Brush in Y Richtung überschritten wird
    ; |3 - Kombination aus 1 und 2
    ; |4 - Keine Teilung
    ; Rückgabewerte .: Success - Pointer zu einem neuen Brush Objekt
    ; Failure - -1 und setzt @error:
    ; |1 - $iSweepAngle ist = 0
    ; Bemerkungen ...: Um die Ressourcen für den Brush freizugeben, muss _GDIPlus_BrushDispose aufgerufen werden
    ; Autor .........: name22 @ http://www.autoit.de/
    ; ===============================================================================================================================
    Func _GDIPlus_PathBrushCreatePie($iX, $iY, $iWidth, $iHeight, $iStartAngle, $iSweepAngle, $ARGB_Center, $ARGB_Surround, $iWrapMode = 4)
    Local Const $Pi_Div_180 = ACos(-1) / 180

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

    If $iStartAngle <= 0 Then $iStartAngle = 1
    If $iSweepAngle = 0 Then Return SetError(1, 0, -1)
    If $iSweepAngle < 0 Then
    $iSweepAngle *= -1
    $iStartAngle = 360 - $iSweepAngle + $iStartAngle
    EndIf

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

    Dim $aPoints_Path[$iSweepAngle + 2][2]
    $aPoints_Path[0][0] = $iSweepAngle + 1
    $iI = 1
    For $i = $iStartAngle To $iStartAngle + $iSweepAngle - 1
    $aPoints_Path[$iI][0] = $iX + $iWidth / 2 + Cos(($i - 90) * $Pi_Div_180) * $iWidth / 2
    $aPoints_Path[$iI][1] = $iY + $iHeight / 2 + Sin(($i - 90) * $Pi_Div_180) * $iHeight / 2
    $iI += 1
    Next
    $aPoints_Path[UBound($aPoints_Path) - 1][0] = $iX + $iWidth / 2
    $aPoints_Path[UBound($aPoints_Path) - 1][1] = $iY + $iHeight / 2

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

    Dim $aColors_Path[$iSweepAngle + 1]
    $aColors_Path[0] = $iSweepAngle
    $iI = 1
    For $i = $iStartAngle To $iStartAngle + $iSweepAngle - 1
    $aColors_Path[$iI] = $ARGB_Surround
    $iI += 1
    Next

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

    $hBrush_Pie = _GDIPlus_PathBrushCreate($aPoints_Path, $iWrapMode)
    _GDIPlus_PathBrushSetCenterPoint($hBrush_Pie, $iX + $iWidth / 2, $iY + $iHeight / 2)
    _GDIPlus_PathBrushSetCenterColor($hBrush_Pie, $ARGB_Center)
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush_Pie, $aColors_Path)

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

    Return $hBrush_Pie
    EndFunc ;==>_GDIPlus_PathBrushCreatePie

    [/autoit]

    Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <GDIP.au3>
    #include <GUIConstants.au3>

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

    $hWnd = GUICreate("Example by name22", 200, 200)
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)

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

    $hBrush = _GDIPlus_PathBrushCreatePie(0, 0, 100, 100, 180, -270, 0xFFFF0000, 0x00000000)
    $hBrush2 = _GDIPlus_PathBrushCreatePie(0, 100, 100, 100, 90, 270, 0xFF0000FF, 0x00000000)

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

    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, 100, 100, $hBrush)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 100, 100, 100, $hBrush2)

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

    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_Shutdown()

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

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_PathBrushCreatePie
    ; Beschreibung ..: Erstellt einen Farbverlauf in Form eines "Kuchens" (Teil eines Kreises) mit 2 Farben eine beginnend in der Mitte der Ellipse aus der der "Kuchen" erstellt wird und eine die auf dem Umkreis der Ellipse verläuft.
    ; Syntax.........: _GDIPlus_PathBrushCreatePie($iX, $iY, $iWidth, $iHeight, $iStartAngle, $iSweepAngle, $ARGB_Center, $ARGB_Surround, [$iWrapMode = 4])
    ; Parameter .....: $iX - X - Koordinate der linken oberen Ecke des Rechtecks aus dem die Ellipse des Kuchenstücks erstellt wird
    ; $iY - Y - Koordinate der linken oberen Ecke des Rechtecks aus dem die Ellipse des Kuchensstücks erstellt wird
    ; $iWidth - Breite der Ellipse
    ; $iHeight - Höhe der Ellipse
    ; $iStartAngle - Startwinkel des Kuchenstücks
    ; $iSweepAngle - Winkel der zum Startwinkel addiert wird und den Endwinkel bestimmt (Ein negativer Wert bedeutet eine "Rotation" nach links)
    ; $ARGB_Center - Farbe für den Mittelpunkt der Ellipse
    ; $ARGB_Surround - Farbe für den Umkreis der Ellipse
    ; $iWrapMode - Wrap mode der die Aufteilung und die Spiegelung des Brushes definiert (Standard 4):
    ; |0 - Teilen ohne spiegeln
    ; |1 - Teile werden horizontal gespiegelt wenn die Größe des Brush in X Richtung überschritten wird
    ; |2 - Teile werden vertikal gespiegelt wenn die Größe des Brush in Y Richtung überschritten wird
    ; |3 - Kombination aus 1 und 2
    ; |4 - Keine Teilung
    ; Rückgabewerte .: Success - Pointer zu einem neuen Brush Objekt
    ; Failure - -1 und setzt @error:
    ; |1 - $iSweepAngle ist = 0
    ; Bemerkungen ...: Um die Ressourcen für den Brush freizugeben, muss _GDIPlus_BrushDispose aufgerufen werden
    ; Autor .........: name22 @ http://www.autoit.de/
    ; ===============================================================================================================================
    Func _GDIPlus_PathBrushCreatePie($iX, $iY, $iWidth, $iHeight, $iStartAngle, $iSweepAngle, $ARGB_Center, $ARGB_Surround, $iWrapMode = 4)
    Local Const $Pi_Div_180 = ACos(-1) / 180

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

    If $iStartAngle <= 0 Then $iStartAngle = 1
    If $iSweepAngle = 0 Then Return SetError(1, 0, -1)
    If $iSweepAngle < 0 Then
    $iSweepAngle *= -1
    $iStartAngle = 360 - $iSweepAngle + $iStartAngle
    EndIf

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

    Dim $aPoints_Path[$iSweepAngle + 2][2]
    $aPoints_Path[0][0] = $iSweepAngle + 1
    $iI = 1
    For $i = $iStartAngle To $iStartAngle + $iSweepAngle - 1
    $aPoints_Path[$iI][0] = $iX + $iWidth / 2 + Cos(($i - 90) * $Pi_Div_180) * $iWidth / 2
    $aPoints_Path[$iI][1] = $iY + $iHeight / 2 + Sin(($i - 90) * $Pi_Div_180) * $iHeight / 2
    $iI += 1
    Next
    $aPoints_Path[UBound($aPoints_Path) - 1][0] = $iX + $iWidth / 2
    $aPoints_Path[UBound($aPoints_Path) - 1][1] = $iY + $iHeight / 2

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

    Dim $aColors_Path[$iSweepAngle + 1]
    $aColors_Path[0] = $iSweepAngle
    $iI = 1
    For $i = $iStartAngle To $iStartAngle + $iSweepAngle - 1
    $aColors_Path[$iI] = $ARGB_Surround
    $iI += 1
    Next

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

    $hBrush_Pie = _GDIPlus_PathBrushCreate($aPoints_Path, $iWrapMode)
    _GDIPlus_PathBrushSetCenterPoint($hBrush_Pie, $iX + $iWidth / 2, $iY + $iHeight / 2)
    _GDIPlus_PathBrushSetCenterColor($hBrush_Pie, $ARGB_Center)
    _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush_Pie, $aColors_Path)

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

    Return $hBrush_Pie
    EndFunc ;==>_GDIPlus_PathBrushCreatePie

    [/autoit]
  • Die Funktion ist wirklich super. ;D

    Respekt!

    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%

  • Ach das hab ich ja auch noch gar nicht kommentiert.

    Wieder so ein typischer name :P

    Echt klasse :thumbup:

    mfg Ubuntu