Recommended Posts

Malkey 187

Malkey 187

From the example, you can see the center color is set and blends with the surround colors which are white, zero.

This is the problem I need help with. The problem being, the surround colors should not all be white. They should be the different colors that are in the array of colors, $aColors[].

My thoughts on the problem is, the array of the surround colors is in the wrong format. So the "GdipSetPathGradientSurroundColorsWithCount" wrapper will not accept the surround colors, This function/wrapper accepts the number of colors but not the color values.

This line of thinking may also be my problem.

Guessing has not helped.

I have not been able to find the format output of the "Color colors[] = {Color(255, 0, 0, 0), .... " statement in the example at

Share this post

Link to post

Share on other sites

Malkey 187

Malkey 187

#include <GDIPlus.au3>#include <WinAPI.au3>#include <GuiConstants.au3>;#include <WindowsConstants.au3>; The following example creates a GraphicsPath object path, adds an arc to path, closes the arc, and then draws path.; Creating a Path Gradient @ http://msdn.microsoft.com/en-us/library/ms533917(VS.85).aspxGlobal$aPoints[11][2]=[[10,0],[75,0],[100,50],[150,50],[112,75],[150,150],[75,100],[0,150],[37,75],[0,50],[50,50]];Opt("GUIOnEventMode", 1);GUISetOnEvent(-3, "close")GlobalConst$iOpacity=255Local$hPathGlobal$GuiSizeX=400,$GuiSizeY=400$hGui=GUICreate("Paths",$GuiSizeX,$GuiSizeY)GUISetState()_GDIPlus_Startup(); Create Double Buffer, so the doesn't need to be repainted on PAINT-Event$hGraphicGUI=_GDIPlus_GraphicsCreateFromHWND($hGui)$hBMPBuff=_GDIPlus_BitmapCreateFromGraphics(400,400,$hGraphicGUI)$hGraphic=_GDIPlus_ImageGetGraphicsContext($hBMPBuff);End Double Buffer add-in 1 of 3;======== CreatePath =====; $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", $FillModeAlternate, "ptr", $pPath); $FillModeAlternate = 0; $FillModeWinding = 1$hPath=DllCall($ghGDIPDll,"int","GdipCreatePath","int",0,"int*",0);======> End of CreatePath ===#cs
;======= AddPathArc =========
;$aResult = DllCall($ghGDIPDll, "int", "GdipAddPathArc", "int", $iX, "int", $iY, "int", $iWidth, "int", $iHeight, "int", $iStartAng, "int", $iSweepAng)
$aResult = DllCall($ghGDIPDll, "int", "GdipAddPathArc", "hwnd", $hPath[2], "int", _WinAPI_FloatToInt(150), _
"int", _WinAPI_FloatToInt(150), "int", _WinAPI_FloatToInt(100), "int", _WinAPI_FloatToInt(100), _
"int", _WinAPI_FloatToInt(10), "int", _WinAPI_FloatToInt(180))
$res = "GdipAddPathArc " & @CRLF
for $x = 0 to 7
$res &= $x & " " & $aResult[$x] & @CRLF
Next
ConsoleWrite($res & @CRLF)
;=======> End of AddPathArc =========
#ce_GDIPlus_AddPathLine2($hPath,$aPoints);GdipCreatePathGradientFromPath(GDIPCONST GpPath* path, GpPathGradient **polyGradient)$hBrushGrad=DllCall($ghGDIPDll,"int","GdipCreatePathGradientFromPath","hwnd",$hPath[2],"int*",0);$hBrushGrad = _GDIPlus_BrushCreateSolid(0xFFFF0000)
GDIPlus_SetPathGradientCenterColor($hBrushGrad[2],0xFFFF0000)Global$aColors[10]=[0xFF00FFFF,0xFF00FF00,0xFF0000FF,0xFFFFFFFF,0xFF000000,0xFF00FF00,0xFF0000FF,0xFFFFFFFF,0xFF000000,0xFF00FF00]$status= GDIPlus_SetPathGradientSurroundColorsWithCount($hBrushGrad[2],$aColors)$aArr= GDIPlus_GetPathGradientSurroundColorsWithCount($hBrushGrad[2])$aResult1=DllCall($ghGDIPDll,"int","GdipClosePathFigure","hwnd",$hPath[2])$hPen=_GDIPlus_PenCreate(0xFF000000,4)_GDIPlus_GraphicsClear($hGraphic,0xFFFFFFFF);_GDIPlus_GraphicsDrawLine ($hGraphic, 10, 150, 390, 150, $hPen);========= DrawPath =========$aResult2=DllCall($ghGDIPDll,"int","GdipDrawPath","hwnd",$hGraphic,"hwnd",$hPen,"hwnd",$hPath[2]);=========> End of DrawPath =========;======= Fill Path - Color path object ==;GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)DllCall($ghGDIPDll,"int","GdipFillPath","hwnd",$hGraphic,"hwnd",$hBrushGrad[2],"hwnd",$hPath[2]);=======> End of Fill Path ==============; Create Double Buffer, so the doesn't need to be repainted on PAINT-EventGUIRegisterMsg(0xF,"MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)_WinAPI_RedrawWindow($hGui,0,0,2);PAINT the window Flag $RDW_INTERNALPAINT = 0x0002;End Double Buffer add-in 2 of 3DoSleep(25)UntilGUIGetMsg()=$GUI_EVENT_CLOSE;Func to redraw the BMP on PAINT MSGFunc MY_PAINT($hWnd,$Msg,$wParam,$lParam); Check, if the GUI with the Graphic should be repaintedIf$hWnd=$hGuiThen_GDIPlus_GraphicsDrawImage($hGraphicGUI,$hBMPBuff,0,0)EndFunc;==>MY_PAINT & End Double Buffer add-in 3 of 3Func close()_GDIPlus_BrushDispose($hBrushGrad)_GDIPlus_PenDispose($hPen)DllCall($ghGDIPDll,"int","GdipDeletePath","hwnd",$hPath)_GDIPlus_GraphicsDispose($hGraphicGUI)_GDIPlus_BitmapDispose($hBMPBuff)_GDIPlus_GraphicsDispose($hGraphic)_GDIPlus_Shutdown()ExitEndFunc;==>close;GdipAddPathPolygon(GpPath *path, GDIPCONST GpPointF *points, INT count)Func_GDIPlus_AddPathPolygon($hPath,$aPoints)Local$iI,$iCount,$pPoints,$tPoints,$aResult,$tmpError,$tmpExError$iCount=$aPoints[0][0]$tPoints=DllStructCreate("int["&$iCount*2&"]")$pPoints=DllStructGetPtr($tPoints)For$iI=1To$iCountDllStructSetData($tPoints,1,_WinAPI_FloatToInt($aPoints[$iI][0]),(($iI-1)*2)+1)DllStructSetData($tPoints,1,_WinAPI_FloatToInt($aPoints[$iI][1]),(($iI-1)*2)+2)Next$aResult=DllCall($ghGDIPDll,"int","GdipAddPathPolygon","hwnd",$hPath[2],"ptr",_$pPoints,"int",$iCount)$tmpError=@error$tmpExError=@extended_GDIPlus_BrushDefDispose()If$tmpErrorThenReturnSetError($tmpError,$tmpExError,False)ReturnSetError($aResult[0],0,$aResult[0]=0)EndFunc;==>_GDIPlus_AddPathPolygon;GpStatus WINGDIPAPI GdipAddPathLine2(GpPath *path, GDIPCONST GpPointF *points, INT count)Func_GDIPlus_AddPathLine2($hPath,$aPoints)Local$iI,$iCount,$pPoints,$tPoints,$aResult,$tmpError,$tmpExError$iCount=$aPoints[0][0]$tPoints=DllStructCreate("int["&$iCount*2&"]")$pPoints=DllStructGetPtr($tPoints)For$iI=1To$iCountDllStructSetData($tPoints,1,_WinAPI_FloatToInt($aPoints[$iI][0]),(($iI-1)*2)+1)DllStructSetData($tPoints,1,_WinAPI_FloatToInt($aPoints[$iI][1]),(($iI-1)*2)+2)Next$aResult=DllCall($ghGDIPDll,"int","GdipAddPathLine2","hwnd",$hPath[2],"ptr",_$pPoints,"int",$iCount)$tmpError=@error$tmpExError=@extended_GDIPlus_BrushDefDispose()If$tmpErrorThenReturnSetError($tmpError,$tmpExError,False)ReturnSetError($aResult[0],0,$aResult[0]=0)EndFunc;==>_GDIPlus_AddPathLine2;================> GDIPlus_SetPathGradientCenterColor ===============; Description Sets the center color of this path gradient brush. The center color is the; color that appears at the brush's center point.;Parameters;brush [in] Pointer to the PathGradientBrush object.;colors [in] An ARGB color that specifies the center color.;Remarks By default the center point is the centroid of the brush's boundary path,; but you can set the center point to any location inside or outside the path.;Func GDIPlus_SetPathGradientCenterColor($hBrush,$iARGB)Local$aResult$aResult=DllCall($ghGDIPDll,"int","GdipSetPathGradientCenterColor","hwnd",$hBrush,"int",$iARGB)If@errorThenReturnSetError(@error,@extended,False)Return$aResult;SetError($aResult[0], 0, $aResult[0] = 0)EndFunc;==>GDIPlus_SetPathGradientCenterColor;=================================================;==============> GDIPlus_SetPathGradientSurroundColorsWithCount ===================================;Description Sets the surround colors of this path gradient brush. The surround colors are colors; specified for discrete points on the brush's boundary path.;Parameters;brush [in] Pointer to the PathGradientBrush object.;colors [in] Pointer to an array of ARGB colors that specify the surround colors.;count [in, out] Pointer to a long integer that, on input, specifies the number of Color objects; in the colors array. If the method succeeds, this parameter, on output, receives the number; of surround colors set. If the method fails, this parameter does not receive a value.;Remarks A path gradient brush has a boundary path and a center point. The center point is set; to a single color, but you can specify different colors for several points on the boundary.; For example, suppose you specify red for the center color, and you specify blue, green,; and yellow for distinct points on the boundary. Then as you move along the boundary,; the color will change gradually from blue to green to yellow and back to blue.; As you move along a straight line from any point on the boundary to the center point,; the color will change from that boundary point's color to red.;Func GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush,$aArgb)Local$iI,$iCount,$aResult,$res,$x,$pArgb,$tArgb$iCount=UBound($aArgb)$tArgb=DllStructCreate("int["&$iCount&"]")$pArgb=DllStructGetPtr($tArgb)For$iI=0To$iCount-1DllStructSetData($tArgb,1,$aArgb[$iI],$iI+1)Next$aResult=DllCall($ghGDIPDll,"int","GdipSetPathGradientSurroundColorsWithCount","hwnd",$hBrush,"ptr",$pArgb,"int*",$iCount)$res="SetPathGradientSurroundColorsWithCount"&@CRLFFor$x=0To3$res&=$x&" "&$aResult[$x]&@CRLFNextConsoleWrite($res&@CRLF)If@errorThenReturnSetError(@error,@extended,0)Return$aResult;SetError($aResult[0], 0, $aResult[2])EndFunc;==>GDIPlus_SetPathGradientSurroundColorsWithCount;=================================================; Gets the number of colors that have been specified for the boundary path of this path gradient brush.Func GDIPlus_GetPathGradientSurroundColorCount($hBrush)Local$iCount,$res,$x;GdipGetPointCount(GpPath* path, INT* count)$iCount=DllCall($ghGDIPDll,"int","GdipGetPathGradientSurroundColorCount","hwnd",$hBrush,"int*",0)$res="GdipGetPathGradientSurroundColorCount"&@CRLFFor$x=0To2$res&=$x&" "&$iCount[$x]&@CRLFNextConsoleWrite($res&@CRLF)Return$iCount[2]EndFunc;==>GDIPlus_GetPathGradientSurroundColorCount;GdipGetPathGradientSurroundColorsWithCount( GpPathGradient *brush, ARGB* color, INT* count)Func GDIPlus_GetPathGradientSurroundColorsWithCount($hBrush)Local$iI,$iCount,$aArgb,$tArgb,$pArgb,$aResult,$res$iCount= GDIPlus_GetPathGradientSurroundColorCount($hBrush)Local$aArgb[$iCount]$aResult=DllCall($ghGDIPDll,"int","GdipGetPathGradientSurroundColorsWithCount","hwnd",$hBrush,"int",$aArgb,"int*",$iCount)$res="GdipGetPathGradientSurroundColorsWithCount"&@CRLFFor$x=0To3$res&=$x&" "&$aResult[$x]&@CRLFNextConsoleWrite($res&@CRLF)$res="GdipGetPathGradientSurroundColorsWithCount Array Return"&@CRLFFor$x=0To$iCount-1$res&=$x&" "&$aArgb[$x]&@CRLFNextConsoleWrite($res&@CRLF)If@errorThenReturnSetError(@error,@extended,0)Return$aResult;SetError($aResult[0], 0, $aResult[2])EndFunc;==>GDIPlus_GetPathGradientSurroundColorsWithCount; Return number of points in PathFunc GDIPlus_GetPointCount($hPath)Local$iCount,$res,$x;GdipGetPointCount(GpPath* path, INT* count)$iCount=DllCall($ghGDIPDll,"int","GdipGetPointCount","hwnd",$hPath,"int*",0)$res="GdipGetPointCount"&@CRLFFor$x=0To2$res&=$x&" "&$iCount[$x]&@CRLFNextConsoleWrite($res&@CRLF)Return$iCount[2]EndFunc;==>GDIPlus_GetPointCount;=================> GDIPlus_SetPathGradientCenterPoint ================================;Description Sets the center point of this path gradient brush. By default,; the center point is at the centroid of the brush's boundary path, but you; can set the center point to any location inside or outside the path.;Parameters brush [in] Pointer to the PathGradientBrush object.; points [out] Pointer to a PointF structure that receives the center point.;Remarks By default, the center point of a PathGradientBrush object is at the centroid of; the brush's boundary path, but you can set the center point to any location, inside; or outside the path, by calling the GdipSetPathGradientCenterPoint function.Func GDIPlus_SetPathGradientCenterPoint($hBrush,$iX,$iY)Local$tPoint,$pPoint,$aResult$tPoint=DllStructCreate("int X;int Y")$pPoint=DllStructGetPtr($tPoint)DllStructSetData($tPoint,"X",_WinAPI_FloatToInt($iX))DllStructSetData($tPoint,"Y",_WinAPI_FloatToInt($iY))$aResult=DllCall($ghGDIPDll,"int","GdipSetPathGradientCenterPoint","hwnd",$hBrush,"ptr",$pPoint)Return$aResultEndFunc;==>GDIPlus_SetPathGradientCenterPoint

Edit: Reloaded script with Double buffering to redraw on PAINT MSG. It appears to work well. The problem with GDIPlus graphics disappearing seems to be solved.