Sign in to follow this  
Followers 0
Malkey

A GDIPlus Gradient Line Brush.

14 posts in this topic

#1 ·  Posted (edited)

[Edit]2008/7/18 Added second Example

On this first post now, we have:-

FUNCTIONS / Wrappers ....all use functions from gdiplus.dll

In 1st Example, 1st Post:-

GDIPlus_CreateLineBrushFromRect .... use of GdipCreateLineBrushFromRect & includes GdipSetLineBlend.

In 2nd Example, 1st Post (Added this Edit):-

GDIPlus_CreateLineBrush ............ uses GdipCreateLineBrush

GDIPlus_SetLineBlend ............... uses GdipSetLineBlend

GDIPlus_SetLineGammaCorrection ..... uses GdipSetLineGammaCorrection

GDIPlus_SetLinePresetBlend ......... uses GdipSetLinePresetBlend

GDIPlus_SetLineSigmaBlend .......... uses GdipSetLineSigmaBlend

Also, double buffering included in eg.2 This double buffering was mentioned here

http://www.autoitscript.com/forum/index.ph...st&p=549536

You can see the difference between eg1 and eg2 by dragging each GUI window off and back onto the desktop.

[End of Edit]

"GdipCreateLineBrushFromRect" is called from gdiplus.dll

Description: Creates a LinearGradientBrush object from a set of boundary points and boundary colors.

For ease of use, I included within the CreateLineBrush function/wrapper, the SetLineBlend routine This DllCall of "GdipSetLineBlend" requires two arrays, an array of blend factors, and an array of the blend factors positions, If these two arrays are not entered into the parameters of the CreateLineBrush function/wrapper, then default arrays are used.

In the example, three Line Brushes are created with slightly different parameters.

All parameters can be tweeked to change the look of the gradient, including the first four -$iX, $iY, $iWidth, $iHeight.

I hope you can find a use for this sometime, somewhere.

First Example Orginal post

#include <GDIPlus.au3>
#include <GuiConstants.au3>
;#include <WinAPI.au3>
;#include <WindowsConstants.au3>

Local $iX = 40, $iY = 20, $iWidth = 400, $iHeight = 120

$hGui = GUICreate("Paths", 480, 440)
GUISetState()

_GDIPlus_Startup()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFF00) ; set background color

;**********************
; Create Line Brush Using minimum number of settings- Brush size same size as Rectangle to fill
$hBrushLin = GDIPlus_CreateLineBrushFromRect(0,20, $iWidth, $iHeight,-1,-1)

;Fill a rectangle using the above brush
_GDIPlus_GraphicsFillRect($hGraphic, $iX, $iY, $iWidth, $iHeight, $hBrushLin)
;***************************

; Factors & Positions Arrays to be used in next two brushes
Local $aFact[4]  = [0.0, 0.3, 0.6, 1.0]
Local $aPosit[4] = [0.0, 0.2, 0.6, 1.0]

;Create another Line Brush with parameters - brush size 200 by 60
$hBrushLin1 = GDIPlus_CreateLineBrushFromRect(1000,1000, $iWidth/2, $iHeight/2, $aFact, $aPosit, _
                                                        0xB00000FF, 0xFFFF0000, 0x00000001, 3)
;Fill a rectangle using the above brush              
_GDIPlus_GraphicsFillRect($hGraphic, $iX, $iY + $iHeight + 20, $iWidth, $iHeight, $hBrushLin1)

;**************************
;Create another Line Brush with parameters - brush size is 400/12 x 120/8 = 33.3 by 15
$hBrushLin2 = GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth/12, $iHeight/8, $aFact, $aPosit, _
                                                        0xFFFF0000, 0xFF00FFFF, 0x00000003, 23)
;Fill a rectangle using the above brush              
_GDIPlus_GraphicsFillRect($hGraphic, $iX, $iY + ($iHeight*2) + 40, $iWidth, $iHeight, $hBrushLin2)
;***************************

_GDIPlus_BrushDispose($hBrushLin2)
_GDIPlus_BrushDispose($hBrushLin1)
_GDIPlus_BrushDispose($hBrushLin)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

Do
    Sleep(25)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

;==== GDIPlus_CreateLineBrushFromRect ===
;Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors.
; $aFactors - If non-array, default array will be used.
;           Pointer to an array of real numbers that specify blend factors. Each number in the array
;           specifies a percentage of the ending color and should be in the range from 0.0 through 1.0.
;$aPositions - If non-array, default array will be used.
;            Pointer to an array of real numbers that specify blend factors' positions. Each number in the array
;            indicates a percentage of the distance between the starting boundary and the ending boundary
;            and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the
;            gradient and 1.0 indicates the ending boundary. There must be at least two positions
;            specified: the first position, which is always 0.0, and the last position, which is always
;            1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a
;            line, parallel to the boundary lines, that is a certain fraction of the distance from the
;            starting boundary to the ending boundary. For example, a blend position of 0.7 indicates
;            the line that is 70 percent of the distance from the starting boundary to the ending boundary.
;            The color is constant on lines that are parallel to the boundary lines.
; $iArgb1    - First Top color in 0xAARRGGBB format
; $iArgb2    - Second color in 0xAARRGGBB format
; $LinearGradientMode -  LinearGradientModeHorizontal       = 0x00000000,
;                        LinearGradientModeVertical         = 0x00000001,
;                        LinearGradientModeForwardDiagonal  = 0x00000002,
;                        LinearGradientModeBackwardDiagonal = 0x00000003
; $WrapMode  - WrapModeTile       = 0,
;              WrapModeTileFlipX  = 1,
;              WrapModeTileFlipY  = 2,
;              WrapModeTileFlipXY = 3,
;              WrapModeClamp      = 4
; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2,
;             LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient)
; Reference:  http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx
;
Func GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
        $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

    Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount

    If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF
    If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000
    If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001
    If $WrapMode = -1 Then $WrapMode = 1

    $tRect = DllStructCreate("float X;float Y;float Width;float Height")
    $pRect = DllStructGetPtr($tRect)
    DllStructSetData($tRect, "X", $iX)
    DllStructSetData($tRect, "Y", $iY)
    DllStructSetData($tRect, "Width", $iWidth)
    DllStructSetData($tRect, "Height", $iHeight)

    ;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
    $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
            "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

    If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
    If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

    $iCount = UBound($aPositions)
    $tFactors = DllStructCreate("float[" & $iCount & "]")
    $pFactors = DllStructGetPtr($tFactors)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
    Next
    $tPositions = DllStructCreate("float[" & $iCount & "]")
    $pPositions = DllStructGetPtr($tPositions)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
    Next

    $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
            "ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
    Return $aRet[6] ; Handle of Line Brush
EndFunc   ;==>GDIPlus_CreateLineBrushFromRect

And thankyou JMeyer, Bert (my fellow Australian), and Andreik for your encouraging replies.

I hope the AutoIt community benefits from my contributions.

Edited by Malkey

Share this post


Link to post
Share on other sites



This is pretty cool. I have been using GDI+ more and more in Autoit. I learn the most from great examples... like this one. Thanks!


Share this post


Link to post
Share on other sites

Nice work Malkey! I like this function, will be very useful. muttley


When the words fail... music speaks

Share this post


Link to post
Share on other sites

And thankyou JMeyer, Bert (my fellow Australian), and Andreik for your encouraging replies.

I hope the AutoIt community benefits from my contributions.

This post is to inform you all the first post has been updated with a second example. This 2nd eg contains wrappers for the functions in gdiplus.dll and shows their use:-

GDIPlus_CreateLineBrush ................. uses GdipCreateLineBrush

GDIPlus_SetLineBlend ...................... uses GdipSetLineBlend

GDIPlus_SetLineGammaCorrection ... uses GdipSetLineGammaCorrection

GDIPlus_SetLinePresetBlend ............ uses GdipSetLinePresetBlend

GDIPlus_SetLineSigmaBlend ............. uses GdipSetLineSigmaBlend

Share this post


Link to post
Share on other sites

@Malkey

Thanks for sharing! Very nice work! muttley :)


When the words fail... music speaks

Share this post


Link to post
Share on other sites

already made ... here us my work...

added path gradient functions, try this :

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
Global $ghA3LGDIPDll
_GDIPlus_Startup()
$Form3 = GUICreate("Gradient Form", 800, 600, 0, 0)
GUISetState()
$Form3 = WinGetHandle($Form3)
$nColor1 = 0xFF00FF00
$nColor2 = 0xFFFFFFFF
Global $CurrentRed = 0, $OLDRed
Global $CurrentGreen = 0, $OldGreen
Global $CurrentBlue = 0, $OldBlue
$nHeight = 200
ConsoleWrite(Hex(_makecolorARGB(255, 0, 255, 0)))
;Exit
;MakeGradientForm($Form3,$nHeight,$nColor1,$nColor2)
;sleep(2000)
;MakePathGradientForm($Form3)
Dim $tabColors[8][2]
$tabColors[0][1] = 0
$tabColors[0][0] = 0xFF000000
$tabColors[1][1] = 0
$tabColors[1][0] = 0x00000000
$tabColors[2][1] = 0
$tabColors[2][0] = 0x00000000
$tabColors[3][1] = 0
$tabColors[3][0] = 0x00000000
$tabColors[4][1] = 0
$tabColors[4][0] = 0x00000000
$tabColors[5][1] = 0
$tabColors[5][0] = 0x00000000
$tabColors[6][1] = 0
$tabColors[6][0] = 0x00000000
$tabColors[7][1] = 0
$tabColors[7][0] = 0x00000000
; Points
Dim $DefinePoints[9][2]
$DefinePoints[0][0] = 8
$DefinePoints[1][0] = 0
$DefinePoints[1][1] = 200
$DefinePoints[2][0] = 267
$DefinePoints[2][1] = 0
$DefinePoints[3][0] = 534
$DefinePoints[3][1] = 0
$DefinePoints[4][0] = 800
$DefinePoints[4][1] = 200
$DefinePoints[5][0] = 800
$DefinePoints[5][1] = 400
$DefinePoints[6][0] = 534
$DefinePoints[6][1] = 600
$DefinePoints[7][0] = 267
$DefinePoints[7][1] = 600
$DefinePoints[8][0] = 0
$DefinePoints[8][1] = 400
;Dim $tabColorNew[4][2]
$vFactor = 10
$YcenterPointMax = 800 / $vFactor
$XcenterPointMax = 600 / $vFactor
$YcenterPointMin = 0
$XcenterPointMin = 0
Dim $CenterPointPos[2][2]
$CenterPointPos[0][0] = 200
$CenterPointPos[0][1] = 0
$CenterPointPos[1][0] = 200
$CenterPointPos[1][1] = 0
Do
    
    If $CenterPointPos[0][1] = 0 Then $CenterPointPos[0][1] = Random($XcenterPointMin, $XcenterPointMax, 1) * $vFactor
    If $CenterPointPos[1][1] = 0 Then $CenterPointPos[1][1] = Random($YcenterPointMin, $YcenterPointMax, 1) * $vFactor
    For $pos = 0 To 1
        Select
            Case $CenterPointPos[$pos][0] < $CenterPointPos[$pos][1]
                $CenterPointPos[$pos][0] += 5
                ConsoleWrite($pos & "<" & @CRLF)
            Case $CenterPointPos[$pos][0] > $CenterPointPos[$pos][1]
                $CenterPointPos[$pos][0] -= 5
                ConsoleWrite($pos & "<" & @CRLF)
            Case Else
                $CenterPointPos[$pos][1] = 0
                ConsoleWrite($pos & "Reset" & @CRLF)
        EndSelect
    Next
    For $ii = 0 To 7
        If $tabColors[$ii][1] = 0 Then
            $tabColors[$ii][1] = Random(0xFF000000, 0xFFFFFFFF, 1)
            ;ConsoleWrite(" mod " & Mod($tabColors[$ii][1], 2) & @CRLF)
            If Mod($tabColors[$ii][1], 2) <> -1 Then $tabColors[$ii][1] -= 1
        EndIf
        
    Next
    
    ;$aPos = WinGetPos($Form3)
    $oGFX = _GDIPlus_GraphicsCreateFromHWND($Form3)
    $tColors = DllStructCreate("int;int;int;int;int;int")
    $pColors = DllStructGetPtr($tColors)
    $iiii = 0
    For $iiii = 0 To 7
        
        ;ConsoleWrite(" > " & $tabColors[$iiii][1] & @tab & $tabColors[$iiii][0] & @crlf)
        ;DllStructSetData($tColors, $ii + 1,$tabColors[$ii][0])
        Select
            Case $tabColors[$iiii][0] < $tabColors[$iiii][1]
                $tabColors[$iiii][0] = $tabColors[$iiii][0] - 10
                DllStructSetData($tColors, ($iiii + 1), $tabColors[$iiii][0])
                ConsoleWrite("Decrease " & $iiii & "  " & $tabColors[$iiii][0] & " < " & $tabColors[$iiii][1] & @CRLF)
            Case Hex($tabColors[$iiii][0]) > Hex($tabColors[$iiii][1])
                $tabColors[$iiii][0] = $tabColors[$iiii][0] + 10
                DllStructSetData($tColors, ($iiii + 1), $tabColors[$iiii][0])
                ConsoleWrite("Increase " & $iiii & "  " & $tabColors[$iiii][0] & " > " & $tabColors[$iiii][1] & @CRLF)
                
            Case $tabColors[$iiii][0] = $tabColors[$iiii][1]
                DllStructSetData($tColors, ($iiii + 1), $tabColors[$iiii][0])
                $tabColors[$iiii][1] = 0
                ;ConsoleWrite("Same, reset " & $iiii & "  " & $tabColors[$iiii][0] & " > " & $tabColors[$iiii][1] & @CRLF)
            Case Else
                ;ConsoleWrite("> " & (Hex($tabColors[$iiii][0]) - Hex($tabColors[$iiii][1])) & @CRLF)
        EndSelect
    Next
    ;      $nColor1, $nColor2, 0, DllStructGetPtr($tBrush))
    $hBrush = _GDIPlus_CreatePathGradient($DefinePoints)
    ;ConsoleWrite($hBrush & @crlf & $oGFX)
    ;_GDIPlus_GraphicsFillRect($oGFX,$apos[0], $apos[1], $apos[2], $apos[3],$hBrush)
    ;_GDIPlus_SetPathGradientCenterColor($hBrush, 0xFF9D9D9D)
    _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush, $pColors, 6)
    ;_GDIPlus_SetPathGradientCenterPoint($hBrush, $CenterPointPos[0][0], $CenterPointPos[1][0])
    _GDIPlus_GraphicsFillRect($oGFX, 0, 0, 800, 600, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($oGFX)
    _GDIPlus_GraphicsClear($oGFX)
    $tColors = 0
    $pColors = 0
    Sleep(5000)
    Exit
    ;sleep(100)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_Shutdown()
Exit
Do
    Switch Random(1, 3, 1)
        Case 1
            
            $OLDRed = $CurrentRed
            $CurrentRed = Random(0, 255, 1)
            Local $step = 1
            If $OLDRed > $CurrentRed Then $step = -1
            ConsoleWrite("OldRed " & $OLDRed & @CRLF & " NewRed " & $CurrentRed & @CRLF)
            For $i = $OLDRed To $CurrentRed Step $step
                $nColor1 = _makecolorARGB(255, $i, $CurrentGreen, $CurrentBlue)
                MakeGradientForm($Form3, $nHeight, $nColor1, $nColor2)
                Sleep(10)
            Next
        Case 2
            $OldGreen = $CurrentGreen
            $CurrentGreen = Random(0, 255, 1)
            Local $step = 1
            If $OldGreen > $CurrentGreen Then $step = -1
            ConsoleWrite("Oldgreen " & $OldGreen & @CRLF & " Newgreen " & $CurrentGreen & @CRLF)
            For $i = $OldGreen To $CurrentGreen Step $step
                $nColor1 = _makecolorARGB(255, $CurrentRed, $i, $CurrentBlue)
                MakeGradientForm($Form3, $nHeight, $nColor1, $nColor2)
                Sleep(10)
            Next
        Case 3
            $OldBlue = $CurrentBlue
            $CurrentBlue = Random(0, 255, 1)
            Local $step = 1
            If $OldBlue > $CurrentBlue Then $step = -1
            ConsoleWrite("Oldblue " & $OldBlue & @CRLF & " Newblue " & $CurrentBlue & @CRLF)
            For $i = $OldBlue To $CurrentBlue Step $step
                $nColor1 = _makecolorARGB(255, $CurrentRed, $CurrentGreen, $i)
                MakeGradientForm($Form3, $nHeight, $nColor1, $nColor2)
                Sleep(10)
            Next
    EndSwitch
    #cs
        for $i = 1 to 255
        $nColor1 = _makecolorARGB(255,0,$i,0)
        
        MakeGradientForm($Form3,$nHeight,$nColor1,$nColor2)
        sleep(10)
        Next
    #ce
    ;sleep(100)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _makecolorARGB($hAlpha, $hRed, $hGreen, $hBlue)
    $hARGBColor = 0x00000000
    $hARGBColor = BitOR($hARGBColor, $hAlpha * 256 * 256 * 256)
    $hARGBColor = BitOR($hARGBColor, $hRed * 256 * 256)
    $hARGBColor = BitOR($hARGBColor, $hGreen * 256)
    $hARGBColor = BitOR($hARGBColor, $hBlue)
    Return $hARGBColor
EndFunc   ;==>_makecolorARGB
Func MakeGradientForm($cForm, $nHeight, $nColor1, $nColor2)
    $oGFX = _GDIPlus_GraphicsCreateFromHWND($Form3)
    $aPos = WinGetPos($cForm)
    ;_gdiplus_CreateLineBrush($aPos[0], _
    ;      $aPos[1]+$apos[3] , _
    ;      $nColor1, $nColor2, 0, DllStructGetPtr($tBrush))
    $hBrush = _GDIPlus_CreateLineBrush(0, _
            0, 10, $aPos[3], _
            $nColor1, $nColor2, 0)
    ;ConsoleWrite($hBrush & @crlf & $oGFX)
    _GDIPlus_GraphicsFillRect($oGFX, $aPos[0], $aPos[1], $aPos[2], $aPos[3], $hBrush)
    _GDIPlus_GraphicsDispose($oGFX)
    _GDIPlus_GraphicsClear($oGFX)
    ;sleep(1000)
EndFunc   ;==>MakeGradientForm
Func MakePathGradientForm($cForm)
    $oGFX = _GDIPlus_GraphicsCreateFromHWND($cForm)
    $aPos = WinGetPos($cForm)
    Local $aPoints[5][2]
    $aPoints[0][0] = 4
    $aPoints[1][0] = 0
    $aPoints[1][1] = 0
    $aPoints[2][0] = 800
    $aPoints[2][1] = 0
    $aPoints[3][0] = 800
    $aPoints[3][1] = 600
    $aPoints[4][0] = 0
    $aPoints[4][1] = 600
    
    $tColors = DllStructCreate("int;int;int;int")
    $pColors = DllStructGetPtr($tColors)
    
    DllStructSetData($tColors, 1, 0xFF42599F)
    DllStructSetData($tColors, 2, 0xFFA8B4DC)
    DllStructSetData($tColors, 3, 0xFFA9B7E6)
    DllStructSetData($tColors, 4, 0xFFA9B7E6)
    ;DllStructSetData($tColors, 1, $aColors[$iI][1], (($iI - 1) * 2) + 2)
    ;_gdiplus_CreateLineBrush($aPos[0], _
    ;      $aPos[1]+$apos[3] , _
    ;      $nColor1, $nColor2, 0, DllStructGetPtr($tBrush))
    $hBrush = _GDIPlus_CreatePathGradient($aPoints)
    ;ConsoleWrite($hBrush & @crlf & $oGFX)
    ;_GDIPlus_GraphicsFillRect($oGFX,$apos[0], $apos[1], $apos[2], $apos[3],$hBrush)
    _GDIPlus_SetPathGradientCenterColor($hBrush, 0xFF9D9D9D)
    _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush, $pColors, 4)
    _GDIPlus_GraphicsFillRect($oGFX, 0, 0, 800, 600, $hBrush)
    _GDIPlus_GraphicsDispose($oGFX)
    _GDIPlus_GraphicsClear($oGFX)
    ;sleep(1000)
EndFunc   ;==>MakePathGradientForm
Func _GDIPlus_CreateLineBrush($point1, $point2, $point3, $point4, $hcolor1, $hcolor2, $wrapMode = 0)
    Local $aResult, $pPoints1, $ppoints2, $tPoints1, $tPoints2
    $tPoints1 = DllStructCreate("int[4]")
    $pPoints1 = DllStructGetPtr($tPoints1)
    For $ii = 1 To 2
        DllStructSetData($tPoints1, 1, $point1, (($ii - 1) * 2) + 1)
        DllStructSetData($tPoints1, 1, $point2, (($ii - 1) * 2) + 2)
    Next
    
    $tPoints2 = DllStructCreate("int[4]")
    $ppoints2 = DllStructGetPtr($tPoints2)
    For $ii = 1 To 2
        DllStructSetData($tPoints2, 1, $point3, (($ii - 1) * 2) + 1)
        DllStructSetData($tPoints2, 1, $point4, (($ii - 1) * 2) + 2)
    Next
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushI", "ptr", $pPoints1, "ptr", $ppoints2, "int", $hcolor1, "int", $hcolor2, "int", $wrapMode, "int*", 0)
    Return SetError($aResult[0], 0, $aResult[6])
EndFunc   ;==>_GDIPlus_CreateLineBrush
Func _GDIPlus_SetPathGradientCenterPoint($hBrush, $iX, $iY)
    Local $tPoints, $pPoints
    $tPoints = DllStructCreate("int[4]")
    $pPoints = DllStructGetPtr($tPoints)
    DllStructSetData($tPoints, 1, $iX, 1)
    DllStructSetData($tPoints, 1, $iY, 2)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterPointI", "hwnd", $hBrush, "int", $pPoints)
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetPathGradientCenterPoint
Func _GDIPlus_CreatePathGradient($aPoints, $wrapMode = 0)
    Local $aResult, $pPoints, $tPoints, $iCount
    $iCount = $aPoints[0][0]
    $tPoints = DllStructCreate("int[" & $iCount * 2 & "]")
    $pPoints = DllStructGetPtr($tPoints)
    For $ii = 1 To $iCount
        DllStructSetData($tPoints, 1, $aPoints[$ii][0], (($ii - 1) * 2) + 1)
        DllStructSetData($tPoints, 1, $aPoints[$ii][1], (($ii - 1) * 2) + 2)
    Next
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePathGradientI", "ptr", $pPoints, "int", $iCount, "int", $wrapMode, "int*", 0)
    Return SetError($aResult[0], 0, $aResult[4])
EndFunc   ;==>_GDIPlus_CreatePathGradient
Func _GDIPlus_SetPathGradientCenterColor($hBrush, $hcolor)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterColor", "ptr", $hBrush, "int", $hcolor)
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetPathGradientCenterColor
Func _GDIPlus_GetPathGradientPointCount($hBrush)
    Local $tCount = DllStructCreate("int")
    $aResult = DllCall($ghGDIPDll, "int", "GdipGetPathGradientPointCount", "ptr", $hBrush, "ptr", DllStructGetPtr($tCount))
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_GetPathGradientPointCount
Func _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush, $hcolor, $iCount)
    Local $tCount = DllStructCreate("int")
    DllStructSetData($tCount, 1, $iCount)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientSurroundColorsWithCount", "ptr", $hBrush, "ptr", $hcolor, "ptr", DllStructGetPtr($tCount))
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetPathGradientSurroundColorsWithCount
Func _GDIPlus_SetLineColor($hBrush, $hcolor1, $hcolor2)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineColor", "hwnd", $hBrush, "int", $hcolor1, "int", $hcolor2)
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetLineColor
Func _GDIPlus_SetPathGradientFocusScales($hBrush, $hcolor1, $hcolor2)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientFocusScales", "hwnd", $hBrush, "int", $xScale, "int", $yScale)
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetPathGradientFocusScales

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

already made ... here us my work...

added path gradient functions, try this :

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
Global $ghA3LGDIPDll
_GDIPlus_Startup()
$Form3 = GUICreate("Gradient Form", 800, 600, 0, 0)
GUISetState()
$Form3 = WinGetHandle($Form3)
$nColor1 = 0xFF00FF00
$nColor2 = 0xFFFFFFFF
Global $CurrentRed = 0, $OLDRed
Global $CurrentGreen = 0, $OldGreen
Global $CurrentBlue = 0, $OldBlue
$nHeight = 200
ConsoleWrite(Hex(_makecolorARGB(255, 0, 255, 0)))
;Exit
;MakeGradientForm($Form3,$nHeight,$nColor1,$nColor2)
;sleep(2000)
;MakePathGradientForm($Form3)
Dim $tabColors[8][2]
$tabColors[0][1] = 0
$tabColors[0][0] = 0xFF000000
$tabColors[1][1] = 0
$tabColors[1][0] = 0x00000000
$tabColors[2][1] = 0
$tabColors[2][0] = 0x00000000
$tabColors[3][1] = 0
$tabColors[3][0] = 0x00000000
$tabColors[4][1] = 0
$tabColors[4][0] = 0x00000000
$tabColors[5][1] = 0
$tabColors[5][0] = 0x00000000
$tabColors[6][1] = 0
$tabColors[6][0] = 0x00000000
$tabColors[7][1] = 0
$tabColors[7][0] = 0x00000000
; Points
Dim $DefinePoints[9][2]
$DefinePoints[0][0] = 8
$DefinePoints[1][0] = 0
$DefinePoints[1][1] = 200
$DefinePoints[2][0] = 267
$DefinePoints[2][1] = 0
$DefinePoints[3][0] = 534
$DefinePoints[3][1] = 0
$DefinePoints[4][0] = 800
$DefinePoints[4][1] = 200
$DefinePoints[5][0] = 800
$DefinePoints[5][1] = 400
$DefinePoints[6][0] = 534
$DefinePoints[6][1] = 600
$DefinePoints[7][0] = 267
$DefinePoints[7][1] = 600
$DefinePoints[8][0] = 0
$DefinePoints[8][1] = 400
;Dim $tabColorNew[4][2]
$vFactor = 10
$YcenterPointMax = 800 / $vFactor
$XcenterPointMax = 600 / $vFactor
$YcenterPointMin = 0
$XcenterPointMin = 0
Dim $CenterPointPos[2][2]
$CenterPointPos[0][0] = 200
$CenterPointPos[0][1] = 0
$CenterPointPos[1][0] = 200
$CenterPointPos[1][1] = 0
Do
    
    If $CenterPointPos[0][1] = 0 Then $CenterPointPos[0][1] = Random($XcenterPointMin, $XcenterPointMax, 1) * $vFactor
    If $CenterPointPos[1][1] = 0 Then $CenterPointPos[1][1] = Random($YcenterPointMin, $YcenterPointMax, 1) * $vFactor
    For $pos = 0 To 1
        Select
            Case $CenterPointPos[$pos][0] < $CenterPointPos[$pos][1]
                $CenterPointPos[$pos][0] += 5
                ConsoleWrite($pos & "<" & @CRLF)
            Case $CenterPointPos[$pos][0] > $CenterPointPos[$pos][1]
                $CenterPointPos[$pos][0] -= 5
                ConsoleWrite($pos & "<" & @CRLF)
            Case Else
                $CenterPointPos[$pos][1] = 0
                ConsoleWrite($pos & "Reset" & @CRLF)
        EndSelect
    Next
    For $ii = 0 To 7
        If $tabColors[$ii][1] = 0 Then
            $tabColors[$ii][1] = Random(0xFF000000, 0xFFFFFFFF, 1)
            ;ConsoleWrite(" mod " & Mod($tabColors[$ii][1], 2) & @CRLF)
            If Mod($tabColors[$ii][1], 2) <> -1 Then $tabColors[$ii][1] -= 1
        EndIf
        
    Next
    
    ;$aPos = WinGetPos($Form3)
    $oGFX = _GDIPlus_GraphicsCreateFromHWND($Form3)
    $tColors = DllStructCreate("int;int;int;int;int;int")
    $pColors = DllStructGetPtr($tColors)
    $iiii = 0
    For $iiii = 0 To 7
        
        ;ConsoleWrite(" > " & $tabColors[$iiii][1] & @tab & $tabColors[$iiii][0] & @crlf)
        ;DllStructSetData($tColors, $ii + 1,$tabColors[$ii][0])
        Select
            Case $tabColors[$iiii][0] < $tabColors[$iiii][1]
                $tabColors[$iiii][0] = $tabColors[$iiii][0] - 10
                DllStructSetData($tColors, ($iiii + 1), $tabColors[$iiii][0])
                ConsoleWrite("Decrease " & $iiii & "  " & $tabColors[$iiii][0] & " < " & $tabColors[$iiii][1] & @CRLF)
            Case Hex($tabColors[$iiii][0]) > Hex($tabColors[$iiii][1])
                $tabColors[$iiii][0] = $tabColors[$iiii][0] + 10
                DllStructSetData($tColors, ($iiii + 1), $tabColors[$iiii][0])
                ConsoleWrite("Increase " & $iiii & "  " & $tabColors[$iiii][0] & " > " & $tabColors[$iiii][1] & @CRLF)
                
            Case $tabColors[$iiii][0] = $tabColors[$iiii][1]
                DllStructSetData($tColors, ($iiii + 1), $tabColors[$iiii][0])
                $tabColors[$iiii][1] = 0
                ;ConsoleWrite("Same, reset " & $iiii & "  " & $tabColors[$iiii][0] & " > " & $tabColors[$iiii][1] & @CRLF)
            Case Else
                ;ConsoleWrite("> " & (Hex($tabColors[$iiii][0]) - Hex($tabColors[$iiii][1])) & @CRLF)
        EndSelect
    Next
    ;      $nColor1, $nColor2, 0, DllStructGetPtr($tBrush))
    $hBrush = _GDIPlus_CreatePathGradient($DefinePoints)
    ;ConsoleWrite($hBrush & @crlf & $oGFX)
    ;_GDIPlus_GraphicsFillRect($oGFX,$apos[0], $apos[1], $apos[2], $apos[3],$hBrush)
    ;_GDIPlus_SetPathGradientCenterColor($hBrush, 0xFF9D9D9D)
    _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush, $pColors, 6)
    ;_GDIPlus_SetPathGradientCenterPoint($hBrush, $CenterPointPos[0][0], $CenterPointPos[1][0])
    _GDIPlus_GraphicsFillRect($oGFX, 0, 0, 800, 600, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($oGFX)
    _GDIPlus_GraphicsClear($oGFX)
    $tColors = 0
    $pColors = 0
    Sleep(5000)
    Exit
    ;sleep(100)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_GDIPlus_Shutdown()
Exit
Do
    Switch Random(1, 3, 1)
        Case 1
            
            $OLDRed = $CurrentRed
            $CurrentRed = Random(0, 255, 1)
            Local $step = 1
            If $OLDRed > $CurrentRed Then $step = -1
            ConsoleWrite("OldRed " & $OLDRed & @CRLF & " NewRed " & $CurrentRed & @CRLF)
            For $i = $OLDRed To $CurrentRed Step $step
                $nColor1 = _makecolorARGB(255, $i, $CurrentGreen, $CurrentBlue)
                MakeGradientForm($Form3, $nHeight, $nColor1, $nColor2)
                Sleep(10)
            Next
        Case 2
            $OldGreen = $CurrentGreen
            $CurrentGreen = Random(0, 255, 1)
            Local $step = 1
            If $OldGreen > $CurrentGreen Then $step = -1
            ConsoleWrite("Oldgreen " & $OldGreen & @CRLF & " Newgreen " & $CurrentGreen & @CRLF)
            For $i = $OldGreen To $CurrentGreen Step $step
                $nColor1 = _makecolorARGB(255, $CurrentRed, $i, $CurrentBlue)
                MakeGradientForm($Form3, $nHeight, $nColor1, $nColor2)
                Sleep(10)
            Next
        Case 3
            $OldBlue = $CurrentBlue
            $CurrentBlue = Random(0, 255, 1)
            Local $step = 1
            If $OldBlue > $CurrentBlue Then $step = -1
            ConsoleWrite("Oldblue " & $OldBlue & @CRLF & " Newblue " & $CurrentBlue & @CRLF)
            For $i = $OldBlue To $CurrentBlue Step $step
                $nColor1 = _makecolorARGB(255, $CurrentRed, $CurrentGreen, $i)
                MakeGradientForm($Form3, $nHeight, $nColor1, $nColor2)
                Sleep(10)
            Next
    EndSwitch
    #cs
        for $i = 1 to 255
        $nColor1 = _makecolorARGB(255,0,$i,0)
        
        MakeGradientForm($Form3,$nHeight,$nColor1,$nColor2)
        sleep(10)
        Next
    #ce
    ;sleep(100)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _makecolorARGB($hAlpha, $hRed, $hGreen, $hBlue)
    $hARGBColor = 0x00000000
    $hARGBColor = BitOR($hARGBColor, $hAlpha * 256 * 256 * 256)
    $hARGBColor = BitOR($hARGBColor, $hRed * 256 * 256)
    $hARGBColor = BitOR($hARGBColor, $hGreen * 256)
    $hARGBColor = BitOR($hARGBColor, $hBlue)
    Return $hARGBColor
EndFunc   ;==>_makecolorARGB
Func MakeGradientForm($cForm, $nHeight, $nColor1, $nColor2)
    $oGFX = _GDIPlus_GraphicsCreateFromHWND($Form3)
    $aPos = WinGetPos($cForm)
    ;_gdiplus_CreateLineBrush($aPos[0], _
    ;      $aPos[1]+$apos[3] , _
    ;      $nColor1, $nColor2, 0, DllStructGetPtr($tBrush))
    $hBrush = _GDIPlus_CreateLineBrush(0, _
            0, 10, $aPos[3], _
            $nColor1, $nColor2, 0)
    ;ConsoleWrite($hBrush & @crlf & $oGFX)
    _GDIPlus_GraphicsFillRect($oGFX, $aPos[0], $aPos[1], $aPos[2], $aPos[3], $hBrush)
    _GDIPlus_GraphicsDispose($oGFX)
    _GDIPlus_GraphicsClear($oGFX)
    ;sleep(1000)
EndFunc   ;==>MakeGradientForm
Func MakePathGradientForm($cForm)
    $oGFX = _GDIPlus_GraphicsCreateFromHWND($cForm)
    $aPos = WinGetPos($cForm)
    Local $aPoints[5][2]
    $aPoints[0][0] = 4
    $aPoints[1][0] = 0
    $aPoints[1][1] = 0
    $aPoints[2][0] = 800
    $aPoints[2][1] = 0
    $aPoints[3][0] = 800
    $aPoints[3][1] = 600
    $aPoints[4][0] = 0
    $aPoints[4][1] = 600
    
    $tColors = DllStructCreate("int;int;int;int")
    $pColors = DllStructGetPtr($tColors)
    
    DllStructSetData($tColors, 1, 0xFF42599F)
    DllStructSetData($tColors, 2, 0xFFA8B4DC)
    DllStructSetData($tColors, 3, 0xFFA9B7E6)
    DllStructSetData($tColors, 4, 0xFFA9B7E6)
    ;DllStructSetData($tColors, 1, $aColors[$iI][1], (($iI - 1) * 2) + 2)
    ;_gdiplus_CreateLineBrush($aPos[0], _
    ;      $aPos[1]+$apos[3] , _
    ;      $nColor1, $nColor2, 0, DllStructGetPtr($tBrush))
    $hBrush = _GDIPlus_CreatePathGradient($aPoints)
    ;ConsoleWrite($hBrush & @crlf & $oGFX)
    ;_GDIPlus_GraphicsFillRect($oGFX,$apos[0], $apos[1], $apos[2], $apos[3],$hBrush)
    _GDIPlus_SetPathGradientCenterColor($hBrush, 0xFF9D9D9D)
    _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush, $pColors, 4)
    _GDIPlus_GraphicsFillRect($oGFX, 0, 0, 800, 600, $hBrush)
    _GDIPlus_GraphicsDispose($oGFX)
    _GDIPlus_GraphicsClear($oGFX)
    ;sleep(1000)
EndFunc   ;==>MakePathGradientForm
Func _GDIPlus_CreateLineBrush($point1, $point2, $point3, $point4, $hcolor1, $hcolor2, $wrapMode = 0)
    Local $aResult, $pPoints1, $ppoints2, $tPoints1, $tPoints2
    $tPoints1 = DllStructCreate("int[4]")
    $pPoints1 = DllStructGetPtr($tPoints1)
    For $ii = 1 To 2
        DllStructSetData($tPoints1, 1, $point1, (($ii - 1) * 2) + 1)
        DllStructSetData($tPoints1, 1, $point2, (($ii - 1) * 2) + 2)
    Next
    
    $tPoints2 = DllStructCreate("int[4]")
    $ppoints2 = DllStructGetPtr($tPoints2)
    For $ii = 1 To 2
        DllStructSetData($tPoints2, 1, $point3, (($ii - 1) * 2) + 1)
        DllStructSetData($tPoints2, 1, $point4, (($ii - 1) * 2) + 2)
    Next
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushI", "ptr", $pPoints1, "ptr", $ppoints2, "int", $hcolor1, "int", $hcolor2, "int", $wrapMode, "int*", 0)
    Return SetError($aResult[0], 0, $aResult[6])
EndFunc   ;==>_GDIPlus_CreateLineBrush
Func _GDIPlus_SetPathGradientCenterPoint($hBrush, $iX, $iY)
    Local $tPoints, $pPoints
    $tPoints = DllStructCreate("int[4]")
    $pPoints = DllStructGetPtr($tPoints)
    DllStructSetData($tPoints, 1, $iX, 1)
    DllStructSetData($tPoints, 1, $iY, 2)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterPointI", "hwnd", $hBrush, "int", $pPoints)
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetPathGradientCenterPoint
Func _GDIPlus_CreatePathGradient($aPoints, $wrapMode = 0)
    Local $aResult, $pPoints, $tPoints, $iCount
    $iCount = $aPoints[0][0]
    $tPoints = DllStructCreate("int[" & $iCount * 2 & "]")
    $pPoints = DllStructGetPtr($tPoints)
    For $ii = 1 To $iCount
        DllStructSetData($tPoints, 1, $aPoints[$ii][0], (($ii - 1) * 2) + 1)
        DllStructSetData($tPoints, 1, $aPoints[$ii][1], (($ii - 1) * 2) + 2)
    Next
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePathGradientI", "ptr", $pPoints, "int", $iCount, "int", $wrapMode, "int*", 0)
    Return SetError($aResult[0], 0, $aResult[4])
EndFunc   ;==>_GDIPlus_CreatePathGradient
Func _GDIPlus_SetPathGradientCenterColor($hBrush, $hcolor)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterColor", "ptr", $hBrush, "int", $hcolor)
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetPathGradientCenterColor
Func _GDIPlus_GetPathGradientPointCount($hBrush)
    Local $tCount = DllStructCreate("int")
    $aResult = DllCall($ghGDIPDll, "int", "GdipGetPathGradientPointCount", "ptr", $hBrush, "ptr", DllStructGetPtr($tCount))
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_GetPathGradientPointCount
Func _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush, $hcolor, $iCount)
    Local $tCount = DllStructCreate("int")
    DllStructSetData($tCount, 1, $iCount)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientSurroundColorsWithCount", "ptr", $hBrush, "ptr", $hcolor, "ptr", DllStructGetPtr($tCount))
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetPathGradientSurroundColorsWithCount
Func _GDIPlus_SetLineColor($hBrush, $hcolor1, $hcolor2)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineColor", "hwnd", $hBrush, "int", $hcolor1, "int", $hcolor2)
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetLineColor
Func _GDIPlus_SetPathGradientFocusScales($hBrush, $hcolor1, $hcolor2)
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientFocusScales", "hwnd", $hBrush, "int", $xScale, "int", $yScale)
    Return SetError($aResult[0], 0, $aResult[0])
EndFunc   ;==>_GDIPlus_SetPathGradientFocusScales
You might like to edit this:-

CODE
Func _GDIPlus_SetPathGradientFocusScales($hBrush, $hcolor1, $hcolor2)

$aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientFocusScales", "hwnd", $hBrush, "int", $xScale, "int", $yScale)

Return SetError($aResult[0], 0, $aResult[0])

EndFunc ;==>_GDIPlus_SetPathGradientFocusScales

I hadn't looked at GdipSetPathGradientFocusScales. Thanks for the wrapper.

You might like to look at this post

http://www.autoitscript.com/forum/index.ph...st&p=551340

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

@Malkey: you and others have inspired me so take a look to my little job here: _GDIPlus_PicSetGradient()

Edited by taz742

Share this post


Link to post
Share on other sites

Thanks Malkey, this will be very usefull!

Excuse my ignorance, but is it possible to employ some sort of a gradient brush to _GDIPlus_GraphicsDrawString? It would awesome to be able to apply a gradient to text!

-A440Hz


Are you experienced?

Share this post


Link to post
Share on other sites

Thanks Malkey, this will be very usefull!

Excuse my ignorance, but is it possible to employ some sort of a gradient brush to _GDIPlus_GraphicsDrawString? It would awesome to be able to apply a gradient to text!

-A440Hz

Just create a gradient brush and pass it to _GDIPlus_GraphicsDrawStringEx()


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Doh, works great! Thanks Monoceres!!


Are you experienced?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0