Popular Post andybiochem Posted October 22, 2009 Popular Post Share Posted October 22, 2009 (edited) Last Updated: 20/02/2010Hi!A while back I created a Graph UDF to enable drawing of graphs in a GUI-control-style way.I've converted that UDF to use GDI+ to take advantage of double-buffering.Functions:_GraphGDIPlus_Create - create graph area_GraphGDIPlus_Delete - delete graph & shutdown GDI+_GraphGDIPlus_Clear - clear current drawings_GraphGDIPlus_Set_RangeX - set x axis range_GraphGDIPlus_Set_RangeY - set y axis range_GraphGDIPlus_Set_PenColor - set color of line_GraphGDIPlus_Set_PenSize - set line width_GraphGDIPlus_Set_PenDash - set line dash style_GraphGDIPlus_Set_GridX - add grid (x ticks)_GraphGDIPlus_Set_GridY - add grid (y ticks)_GraphGDIPlus_Plot_Start - define starting position_GraphGDIPlus_Plot_Line - plot line_GraphGDIPlus_Plot_Point - plot a small square_GraphGDIPlus_Plot_Dot - plot a single pixel_GraphGDIPlus_Refresh - refresh graph area (draw)NOTES / UPDATES:- be aware that "WM_ACTIVATE" is registered in_GraphGDIPlus_Create (this allows redrawing of the GDI+ when mini/maximizing the GUI)- due to a hideous over-sight on my part, I've had to update the way that "WM_ACTIVATE" is registered by using a global var in the UDF... so DON'T use "$aGraphGDIPlusaGraphArrayINTERNAL" in your script pls!! (couldn't think of any other way to do this)- be aware that WinSetTrans($hWnd,"",255) is called in _GraphGDIPlus_Create (this prevents GDI+ glitches when moving GUI)- _GraphGDIPlus_Delete must be called upon GUI exit (it shuts down GDI+, and disposes of pens etc)- Using _GraphGDIPlus_Clear will remove grid-lines too. You will need to redraw these using _GraphGDIPlus_Set_Grid... after clearing- updated to allow setting color of the x=0 and y=0 lines when visible (when using -ve and +ve axes)- updated to allow user to decide whether to shut down GDI+ completely when deleting the graph (you may have your own graphics etc)- updated to declare all vars as Local in functions. Sorry if you had problems with this, no excuses, entirely my fault. - updated to clean up pen use- be aware that "WM_MOVE" is registered in_GraphGDIPlus_Create (this allows redrawing of the GDI+ when moving the GUI)The updates should NOT be script breaking, unless you are manually using Pen vars/handles from the returned graph array.TO DO- Look at adding a "save image as..." option (suggested by UEZ - thanks!)- Error checking / returns???? any suggestions ????Example UseThis graph draws Gamma Function in real-time...expandcollapse popup#include "GraphGDIPlus.au3" Opt("GUIOnEventMode", 1) $GUI = GUICreate("",600,600) GUISetOnEvent(-3,"_Exit") GUISetState() ;----- Create Graph area ----- $Graph = _GraphGDIPlus_Create($GUI,40,30,530,520,0xFF000000,0xFF88B3DD) ;----- Set X axis range from -5 to 5 ----- _GraphGDIPlus_Set_RangeX($Graph,-5,5,10,1,1) _GraphGDIPlus_Set_RangeY($Graph,-5,5,10,1,1) ;----- Set Y axis range from -5 to 5 ----- _GraphGDIPlus_Set_GridX($Graph,1,0xFF6993BE) _GraphGDIPlus_Set_GridY($Graph,1,0xFF6993BE) ;----- Draw the graph ----- _Draw_Graph() While 1 Sleep(100) WEnd Func _Draw_Graph() ;----- Set line color and size ----- _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87) _GraphGDIPlus_Set_PenSize($Graph,2) ;----- draw lines ----- $First = True For $i = -5 to 5 Step 0.005 $y = _GammaFunction($i) If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y) $First = False _GraphGDIPlus_Plot_Line($Graph,$i,$y) _GraphGDIPlus_Refresh($Graph) Next EndFunc Func _GammaFunction($iZ) $nProduct = ((2^$iZ) / (1 + $iZ)) For $n = 2 to 1000 $nProduct *= ((1 + (1/$n))^$iZ) / (1 + ($iZ / $n)) Next Return (1/$iZ) * $nProduct EndFunc Func _Exit() ;----- close down GDI+ and clear graphic ----- _GraphGDIPlus_Delete($GUI,$Graph) Exit EndFuncUDF:GraphGDIPlus.au3 Updated 20/02/2010expandcollapse popup;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# =============================================================================== ; Title .........: GraphGDIPlus ; AutoIt Version: 3.3.0.0+ ; Language: English ; Description ...: A Graph control to draw line graphs, using GDI+, also double-buffered. ; Notes .........: ; ======================================================================================= ; #VARIABLES/INCLUDES# ================================================================== #include-once #include <GDIplus.au3> Global $aGraphGDIPlusaGraphArrayINTERNAL[1] ; ======================================================================================= ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Create ; Description ...: Creates graph area, and prepares array of specified data ; Syntax.........: _GraphGDIPlus_Create($hWnd,$iLeft,$iTop,$iWidth,$iHeight,$hColorBorder = 0xFF000000,$hColorFill = 0xFFFFFFFF) ; Parameters ....: $hWnd - Handle to GUI ; $iLeft - left most position in GUI ; $iTop - top most position in GUI ; $iWidth - width of graph in pixels ; $iHeight - height of graph in pixels ; $hColorBorder - Color of graph border (ARGB) ; $hColorFill - Color of background (ARGB) ; Return values .: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] x low ; [7] x high ; [8] y low ; [9] y high ; [10] x ticks handles ; [11] x labels handles ; [12] y ticks handles ; [13] y labels handles ; [14] Border Color ; [15] Fill Color ; [16] Bitmap Handle ; [17] Backbuffer Handle ; [18] Last used x pos ; [19] Last used y pos ; [20] Pen (main) Handle ; [21] Brush (fill) Handle ; [22] Pen (border) Handle ; [23] Pen (grid) Handle ; ======================================================================================= Func _GraphGDIPlus_Create($hWnd, $iLeft, $iTop, $iWidth, $iHeight, $hColorBorder = 0xFF000000, $hColorFill = 0xFFFFFFFF, $iSmooth = 2) Local $graphics, $bitmap, $backbuffer, $brush, $bpen, $gpen, $pen Local $ahTicksLabelsX[1] Local $ahTicksLabelsY[1] Local $ahTicksX[1] Local $ahTicksY[1] Local $aGraphArray[1] ;----- Set GUI transparency to SOLID (prevents GDI+ glitches) ----- ;WinSetTrans($hWnd, "", 255) - causes problems when more than 2 graphs used ;----- GDI+ Initiate ----- _GDIPlus_Startup() $graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) ;graphics area $bitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth + 1, $iHeight + 1, $graphics);buffer bitmap $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ;buffer area _GDIPlus_GraphicsSetSmoothingMode($backbuffer, $iSmooth) ;----- Set background Color ----- $brush = _GDIPlus_BrushCreateSolid($hColorFill) _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $iWidth, $iHeight, $brush) ;----- Set border Pen + color ----- $bpen = _GDIPlus_PenCreate($hColorBorder) _GDIPlus_PenSetEndCap($bpen, $GDIP_LINECAPROUND) ;----- Set Grid Pen + color ----- $gpen = _GDIPlus_PenCreate(0xFFf0f0f0) _GDIPlus_PenSetEndCap($gpen, $GDIP_LINECAPROUND) ;----- set Drawing Pen + Color ----- $pen = _GDIPlus_PenCreate() ;drawing pen initially black, user to set _GDIPlus_PenSetEndCap($pen, $GDIP_LINECAPROUND) _GDIPlus_GraphicsDrawRect($backbuffer, 0, 0, $iWidth, $iHeight, $pen) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, $iLeft, $iTop, $iWidth + 1, $iHeight + 1) ;----- register redraw ----- GUIRegisterMsg(0x0006, "_GraphGDIPlus_ReDraw") ;0x0006 = win activate GUIRegisterMsg(0x0003, "_GraphGDIPlus_ReDraw") ;0x0003 = win move ;----- prep + load array ----- Dim $aGraphArray[24] = ["", $graphics, $iLeft, $iTop, $iWidth, $iHeight, 0, 1, 0, 1, _ $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $hColorBorder, $hColorFill, _ $bitmap, $backbuffer, 0, 0, $pen, $brush, $bpen, $gpen] ;----- prep re-draw array for all graphs created ----- ReDim $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL) + 1] $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1] = $aGraphArray Return $aGraphArray EndFunc ;==>_GraphGDIPlus_Create Func _GraphGDIPlus_ReDraw($hWnd) ;----- Allows redraw of the GDI+ Image upon window min/maximize ----- Local $i _WinAPI_RedrawWindow($hWnd, 0, 0, 0x0100) For $i = 1 To UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1 If $aGraphGDIPlusaGraphArrayINTERNAL[$i] = 0 Then ContinueLoop _GraphGDIPlus_Refresh($aGraphGDIPlusaGraphArrayINTERNAL[$i]) Next EndFunc ;==>_GraphGDIPlus_ReDraw ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Delete ; Description ...: Deletes previously created graph and related ticks/labels ; Syntax.........: _GraphGDIPlus_Delete($hWnd,ByRef $aGraphArray) ; Parameters ....: $hWnd - GUI handle ; $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iKeepGDIPlus - if not zero, function will not _GDIPlus_Shutdown() ; ======================================================================================= Func _GraphGDIPlus_Delete($hWnd, ByRef $aGraphArray, $iKeepGDIPlus = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $i, $aTemp ;----- delete x ticks/labels ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next ;----- delete y ticks/labels ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next ;----- delete graphic control ----- _GDIPlus_GraphicsDispose($aGraphArray[17]) _GDIPlus_BitmapDispose($aGraphArray[16]) _GDIPlus_GraphicsDispose($aGraphArray[1]) _GDIPlus_BrushDispose($aGraphArray[21]) _GDIPlus_PenDispose($aGraphArray[20]) _GDIPlus_PenDispose($aGraphArray[22]) _GDIPlus_PenDispose($aGraphArray[23]) If $iKeepGDIPlus = 0 Then _GDIPlus_Shutdown() _WinAPI_InvalidateRect($hWnd) ;----- remove form global redraw array ----- For $i = 1 To UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1 $aTemp = $aGraphGDIPlusaGraphArrayINTERNAL[$i] If IsArray($aTemp) = 0 Then ContinueLoop If $aTemp[1] = $aGraphArray[1] Then $aGraphGDIPlusaGraphArrayINTERNAL[$i] = 0 Next ;----- close array ----- $aGraphArray = 0 EndFunc ;==>_GraphGDIPlus_Delete ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Clear ; Description ...: Clears graph content ; Syntax.........: _GraphGDIPlus_Clear(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================= Func _GraphGDIPlus_Clear(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- Set background Color ----- _GDIPlus_GraphicsFillRect($aGraphArray[17], 0, 0, $aGraphArray[4], $aGraphArray[5], $aGraphArray[21]) ;----- set border + Color ----- _GraphGDIPlus_RedrawRect($aGraphArray) EndFunc ;==>_GraphGDIPlus_Clear ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Refresh ; Description ...: refreshes the graphic ; Syntax.........: _GraphGDIPlus_Refresh(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================== Func _GraphGDIPlus_Refresh(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($aGraphArray[1], $aGraphArray[16], $aGraphArray[2], _ $aGraphArray[3], $aGraphArray[4] + 1, $aGraphArray[5] + 1) EndFunc ;==>_GraphGDIPlus_Refresh ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeX ; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the X axis (can be negative) ; $iHigh - the highest value for the X axis ; $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray, $iLow, $iHigh, $iXTicks = 1, $bLabels = 1, $iRound = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksX, $ahTicksLabelsX, $i ;----- load user vars to array ----- $aGraphArray[6] = $iLow $aGraphArray[7] = $iHigh ;----- prepare nested array ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] ;----- delete any existing ticks ----- For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next Dim $ahTicksX[1] ;----- create new ticks ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("", (($i - 1) * ($aGraphArray[4] / $iXTicks)) + $aGraphArray[2], _ $aGraphArray[3] + $aGraphArray[5], 1, 5) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetState(-1, 128) Next ;----- delete any existing labels ----- For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($aGraphArray[2] + (($aGraphArray[4] / $iXTicks) * ($i - 1))) - (($aGraphArray[4] / $iXTicks) / 2), _ $aGraphArray[3] + $aGraphArray[5] + 10, $aGraphArray[4] / $iXTicks, 13, 1) GUICtrlSetBkColor(-1, -2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f", _GraphGDIPlus_Reference_Pixel("p", (($i - 1) * ($aGraphArray[4] / $iXTicks)), _ $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[10] = $ahTicksX $aGraphArray[11] = $ahTicksLabelsX EndFunc ;==>_GraphGDIPlus_Set_RangeX ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeY ; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the Y axis (can be negative) ; $iHigh - the highest value for the Y axis ; $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeY(ByRef $aGraphArray, $iLow, $iHigh, $iYTicks = 1, $bLabels = 1, $iRound = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksY, $ahTicksLabelsY, $i ;----- load user vars to array ----- $aGraphArray[8] = $iLow $aGraphArray[9] = $iHigh ;----- prepare nested array ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] ;----- delete any existing ticks ----- For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next Dim $ahTicksY[1] ;----- create new ticks ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 5, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)), 5, 1) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetState(-1, 128) Next ;----- delete any existing labels ----- For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 40, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)) - 6, 30, 13, 2) GUICtrlSetBkColor(-1, -2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i], StringFormat("%." & $iRound & "f", _GraphGDIPlus_Reference_Pixel("p", _ (($i - 1) * ($aGraphArray[5] / $iYTicks)), $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[12] = $ahTicksY $aGraphArray[13] = $ahTicksLabelsY EndFunc ;==>_GraphGDIPlus_Set_RangeY ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Start ; Description ...: Move starting point of plot ; Syntax.........: _GraphGDIPlus_Plot_Start(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to start at ; $iY - y value to start at ; ======================================================================================== Func _GraphGDIPlus_Plot_Start(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- MOVE pen to start point ----- $aGraphArray[18] = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $aGraphArray[19] = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) EndFunc ;==>_GraphGDIPlus_Plot_Start ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Line ; Description ...: draws straight line to x,y from previous point / starting point ; Syntax.........: _GraphGDIPlus_Plot_Line(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw to ; $iY - y value to draw to ; ======================================================================================== Func _GraphGDIPlus_Plot_Line(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw line from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], $aGraphArray[18], $aGraphArray[19], $iX, $iY, $aGraphArray[20]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Line ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Point ; Description ...: draws point at coords ; Syntax.........: _GraphGDIPlus_Plot_Point(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Point(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) _GDIPlus_GraphicsDrawRect($aGraphArray[17], $iX-1, $iY-1, 2, 2, $aGraphArray[20]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Point ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Dot ; Description ...: draws single pixel dot at coords ; Syntax.........: _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) _GDIPlus_GraphicsDrawRect($aGraphArray[17], $iX, $iY, 1, 1, $aGraphArray[20]) ;draws 2x2 dot ?HOW to get 1x1 pixel????? _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Dot ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenColor ; Description ...: sets the Color for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKColor) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $hColor - the Color of the next item (ARGB) ; ======================================================================================== Func _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray, $hColor) If IsArray($aGraphArray) = 0 Then Return ;----- apply pen Color ----- _GDIPlus_PenSetColor($aGraphArray[20], $hColor) EndFunc ;==>_GraphGDIPlus_Set_PenColor ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenSize ; Description ...: sets the pen for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iSize - size of pen line ; ======================================================================================== Func _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray, $iSize = 1) If IsArray($aGraphArray) = 0 Then Return ;----- apply pen size ----- _GDIPlus_PenSetWidth($aGraphArray[20], $iSize) EndFunc ;==>_GraphGDIPlus_Set_PenSize ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenDash ; Description ...: sets the pen dash style for the next drawing ; Syntax.........: GraphGDIPlus_Set_PenDash(ByRef $aGraphArray,$iDash = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iDash - style of dash, where: ; 0 = solid line ; 1 = simple dashed line ; 2 = simple dotted line ; 3 = dash dot line ; 4 = dash dot dot line ; ======================================================================================== Func _GraphGDIPlus_Set_PenDash(ByRef $aGraphArray, $iDash = 0) If IsArray($aGraphArray) = 0 Then Return Local $Style Switch $iDash Case 0 ;solid line _____ $Style = $GDIP_DASHSTYLESOLID Case 1 ;simple dash ----- $Style = $GDIP_DASHSTYLEDASH Case 2 ;simple dotted ..... $Style = $GDIP_DASHSTYLEDOT Case 3 ;dash dot -.-.- $Style = $GDIP_DASHSTYLEDASHDOT Case 4 ;dash dot dot -..-..-.. $Style = $GDIP_DASHSTYLEDASHDOTDOT EndSwitch ;----- apply pen dash ----- _GDIPlus_PenSetDashStyle($aGraphArray[20], $Style) EndFunc ;==>_GraphGDIPlus_Set_PenDash ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridX ; Description ...: Adds X gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorY0 - [optional] RGB value, defining Color of Y=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xFFf0f0f0, $hColorY0 = 0xFF000000) If IsArray($aGraphArray) = 0 Then Return ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[6] To $aGraphArray[7] Step $Ticks If $i = Number($aGraphArray[6]) Or $i = Number($aGraphArray[7]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) Next EndSelect ;----- draw y=0 ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColorY0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;set Color back to user def EndFunc ;==>_GraphGDIPlus_Set_GridX ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridY ; Description ...: Adds Y gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorX0 - [optional] RGB value, defining Color of X=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xFFf0f0f0, $hColorX0 = 0xFF000000) If IsArray($aGraphArray) = 0 Then Return ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[8] To $aGraphArray[9] Step $Ticks If $i = Number($aGraphArray[8]) Or $i = Number($aGraphArray[9]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) Next EndSelect ;----- draw abcissa/ordinate ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColorX0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;set Color back to user def EndFunc ;==>_GraphGDIPlus_Set_GridY ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_RedrawRect ; Description ...: INTERNAL FUNCTION - Re-draws the border ; Syntax.........: _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; Notes..........: This prevents drawing over the border of the graph area ; ========================================================================================= Func _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- draw border ----- _GDIPlus_GraphicsDrawRect($aGraphArray[17], 0, 0, $aGraphArray[4], $aGraphArray[5], $aGraphArray[22]) ;draw border EndFunc ;==>_GraphGDIPlus_RedrawRect ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _GraphGDIPlus_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; ========================================================================================= Func _GraphGDIPlus_Reference_Pixel($iType, $iValue, $iLow, $iHigh, $iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow))))) Case "p" Return ($iValue / ($iTotalPixels / ($iHigh - $iLow))) + $iLow EndSwitch EndFunc ;==>_GraphGDIPlus_Reference_PixelThanks To:joseLB for looking at adding grid lines in the original UDFmonoceres for the e-x-c-e-l-l-e-n-t GDI+ double buffer templateUEZ for suggesting anti-aliasing (now included by default)winux38 for pointing out an error Edited February 20, 2010 by andybiochem mLipok, Deito, GoogleGonnaSaveUs and 4 others 6 1 - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
UEZ Posted October 22, 2009 Share Posted October 22, 2009 Nice work!What about a function _GraphGDIPlus_SaveImage()?UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
insignia96 Posted October 23, 2009 Share Posted October 23, 2009 I love this. Very very good work Visit my website to see all my finished releases!Releases here:UDFs:GUI ResizingColor List (Web Colors)GUIFade_NearestPower Link to comment Share on other sites More sharing options...
andybiochem Posted October 27, 2009 Author Share Posted October 27, 2009 (edited) Updated 27/10/09- due to a hideous over-sight on my part, I've had to update the way that "WM_ACTIVATE" is registered by using a global var in theUDF... so DON'T use "$aGraphGDIPlusaGraphArrayINTERNAL" in your script pls!! (couldn't think of any other way to do this)- Using _GraphGDIPlus_Clear will remove grid-lines too. You will need to redraw these using _GraphGDIPlus_Set_Grid... after clearing- updated to allow setting color of the x=0 and y=0 lines when visible (when using -ve and +ve axes)- updated to allow user to decide whether to shut down GDI+ completely when deleting the graph (you may have your own graphics etc)- updated to declare all vars as Local in functions. Sorry if you had problems with this, no excuses, entirely my fault. - updated to clean up pen use- added pen line-dash optionThe updates should NOT be script breaking, unless you are manually using Pen vars/handles from the returned graph array.. Edited October 27, 2009 by andybiochem - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
KaFu Posted October 27, 2009 Share Posted October 27, 2009 Looks really nice, for sure will be useful at some point , 5 stars from me! P.S.: Update the Example to point to #include "GraphGDIPlus_UDF.au3". OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
andybiochem Posted October 27, 2009 Author Share Posted October 27, 2009 P.S.: Update the Example to point to #include "GraphGDIPlus_UDF.au3".Does it give you an error as #include "GraphGDIPlus UDF.au3" ???I tried changing it:N:\General Scripts\ANDY UDFs\test.au3(1,10) : ERROR: can't open include file "GraphGDIPlus_UDF.au3"??. - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
KaFu Posted October 27, 2009 Share Posted October 27, 2009 (edited) Not really a problem if with or without an underscore , both filenames work fine. Just that the attached UDF download above contains an underscore in the filename and the include in the example code does not. Edited October 27, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
UEZ Posted October 27, 2009 Share Posted October 27, 2009 (edited) Here a modification of your GraphGDIPlus UDF.au:expandcollapse popup#include-once #include <GDIplus.au3> Opt ("GUICoordMode", 1) Global $aGraphGDIPlusaGraphArrayINTERNAL ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Create ; Description ...: Creates graph area, and prepares array of specified data ; Syntax.........: _GraphGDIPlus_Create($hWnd,$iLeft,$iTop,$iWidth,$iHeight,$hColorBorder = 0xFF000000,$hColorFill = 0xFFFFFFFF) ; Parameters ....: $hWnd - Handle to GUI ; $iLeft - left most position in GUI ; $iTop - top most position in GUI ; $iWidth - width of graph in pixels ; $iHeight - height of graph in pixels ; $hColorBorder - Color of graph border (ARGB) ; $hColorFill - Color of background (ARGB) ; Return values .: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] x low ; [7] x high ; [8] y low ; [9] y high ; [10] x ticks handles ; [11] x labels handles ; [12] y ticks handles ; [13] y labels handles ; [14] Border Color ; [15] Fill Color ; [16] Bitmap Handle ; [17] Backbuffer Handle ; [18] Last used x pos ; [19] Last used y pos ; [20] Pen (main) Handle ; [21] Brush (fill) Handle ; [22] Pen (border) Handle ; [23] Pen (grid) Handle ; ======================================================================================= Func _GraphGDIPlus_Create($hWnd,$iLeft,$iTop,$iWidth,$iHeight,$hColorBorder = 0xFF000000,$hColorFill = 0xFFFFFFFF) Local $graphics,$bitmap,$backbuffer,$brush,$bpen,$gpen,$pen Local $ahTicksLabelsX[1] Local $ahTicksLabelsY[1] Local $ahTicksX[1] Local $ahTicksY[1] Local $aGraphArray[1] ;----- Set GUI transparency to SOLID (prevents GDI+ glitches) ----- WinSetTrans($hWnd,"",255) ;----- GDI+ Initiate ----- _GDIPlus_Startup() $graphics=_GDIPlus_GraphicsCreateFromHWND($hWnd) ;graphics area $bitmap=_GDIPlus_BitmapCreateFromGraphics($iWidth+1,$iHeight+1,$graphics);buffer bitmap $backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap) ;buffer area _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4) ;----- Set background Color ----- $brush = _GDIPlus_BrushCreateSolid($hColorFill) _GDIPlus_GraphicsfillRect($backbuffer,0,0,$iWidth,$iHeight,$brush) ;----- Set border Pen + color ----- $bpen = _GDIPlus_PenCreate($hColorBorder) _GDIPlus_PenSetEndCap($bpen,$GDIP_LINECAPROUND) ;----- Set Grid Pen + color ----- $gpen = _GDIPlus_PenCreate(0xFFf0f0f0) _GDIPlus_PenSetEndCap($gpen,$GDIP_LINECAPROUND) ;----- set Drawing Pen + Color ----- $pen = _GDIPlus_PenCreate() ;drawing pen initially black, user to set _GDIPlus_PenSetEndCap($pen,$GDIP_LINECAPROUND) _GDIPlus_GraphicsDrawRect($backbuffer,0,0,$iWidth,$iHeight,$pen) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,$iLeft,$iTop,$iWidth+1,$iHeight+1) ;----- register redraw ----- GUIRegisterMsg(0x0006,"_GraphGDIPlus_ReDraw") ;----- prep + load array ----- Dim $aGraphArray[24] = ["",$graphics,$iLeft,$iTop,$iWidth,$iHeight,0,1,0,1, _ $ahTicksX,$ahTicksLabelsX,$ahTicksY,$ahTicksLabelsY,$hColorBorder,$hColorFill, _ $bitmap,$backbuffer,0,0,$pen,$brush,$bpen,$gpen] $aGraphGDIPlusaGraphArrayINTERNAL = $aGraphArray Return $aGraphArray EndFunc Func _GraphGDIPlus_ReDraw($hWnd) ;----- Allows redraw of the GDI+ Image upon window min/maximize ----- _WinAPI_RedrawWindow($hWnd,0,0,0x0100) _GraphGDIPlus_Refresh($aGraphGDIPlusaGraphArrayINTERNAL) EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Delete ; Description ...: Deletes previously created graph and related ticks/labels ; Syntax.........: _GraphGDIPlus_Delete($hWnd,ByRef $aGraphArray) ; Parameters ....: $hWnd - GUI handle ; $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iKeepGDIPlus - if not zero, function will not _GDIPlus_Shutdown() ; ======================================================================================= Func _GraphGDIPlus_Delete($hWnd,ByRef $aGraphArray,$iKeepGDIPlus = 0) Local $ahTicksX,$ahTicksLabelsX,$ahTicksY,$ahTicksLabelsY,$i ;----- delete x ticks/labels ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] For $i = 1 to (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next For $i = 1 to (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next ;----- delete y ticks/labels ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] For $i = 1 to (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next ;----- delete graphic control ----- _GDIPlus_GraphicsDispose($aGraphArray[17]) _GDIPlus_BitmapDispose($aGraphArray[16]) _GDIPlus_GraphicsDispose($aGraphArray[1]) _GDIPlus_BrushDispose($aGraphArray[21]) _GDIPlus_PenDispose($aGraphArray[20]) _GDIPlus_PenDispose($aGraphArray[22]) _GDIPlus_PenDispose($aGraphArray[23]) If $iKeepGDIPlus = 0 Then _GDIPlus_Shutdown() _WinAPI_InvalidateRect($hWnd) ;----- close array ----- $aGraphArray = 0 EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Clear ; Description ...: Clears graph content ; Syntax.........: _GraphGDIPlus_Clear(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================= Func _GraphGDIPlus_Clear(ByRef $aGraphArray) ;----- Set background Color ----- _GDIPlus_GraphicsfillRect($aGraphArray[17],0,0,$aGraphArray[4],$aGraphArray[5], $aGraphArray[21]) ;----- set border + Color ----- _GraphGDIPlus_RedrawRect($aGraphArray) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($aGraphArray[1],$aGraphArray[16],$aGraphArray[2],$aGraphArray[3],$aGraphArray[4]+1,$aGraphArray[5]+1) EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeX ; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the X axis (can be negative) ; $iHigh - the highest value for the X axis ; $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) Local $ahTicksX,$ahTicksLabelsX,$i ;----- load user vars to array ----- $aGraphArray[6] = $iLow $aGraphArray[7] = $iHigh ;----- prepare nested array ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] ;----- delete any existing ticks ----- For $i = 1 to (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next Dim $ahTicksX[1] ;----- create new ticks ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("",(($i - 1) * ($aGraphArray[4] / $iXTicks)) + $aGraphArray[2], _ $aGraphArray[3] + $aGraphArray[5],1,5) GUICtrlSetBkcolor(-1,0x000000) GUICtrlSetState(-1,128) Next ;----- delete any existing labels ----- For $i = 1 to (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($aGraphArray[2] + (($aGraphArray[4] / $iXTicks) * ($i - 1))) - (($aGraphArray[4] / $iXTicks) / 2), _ $aGraphArray[3] + $aGraphArray[5] + 10,$aGraphArray[4] / $iXTicks,13,1) GUICtrlSetBkcolor(-1,-2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f",_GraphGDIPlus_Reference_Pixel("p",(($i - 1) * ($aGraphArray[4] / $iXTicks)), _ $aGraphArray[6],$aGraphArray[7],$aGraphArray[4]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[10] = $ahTicksX $aGraphArray[11] = $ahTicksLabelsX EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeY ; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the Y axis (can be negative) ; $iHigh - the highest value for the Y axis ; $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeY(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) Local $ahTicksY,$ahTicksLabelsY,$i ;----- load user vars to array ----- $aGraphArray[8] = $iLow $aGraphArray[9] = $iHigh ;----- prepare nested array ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] ;----- delete any existing ticks ----- For $i = 1 to (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next Dim $ahTicksY[1] ;----- create new ticks ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("",$aGraphArray[2] - 5, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)),5,1) GUICtrlSetBkcolor(-1,0x000000) GUICtrlSetState(-1,128) Next ;----- delete any existing labels ----- For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("",$aGraphArray[2] - 40, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)) - 6,30,13,2) GUICtrlSetBkcolor(-1,-2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i],StringFormat("%." & $iRound & "f",_GraphGDIPlus_Reference_Pixel("p", _ (($i - 1) * ($aGraphArray[5] / $iYTicks)),$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[12] = $ahTicksY $aGraphArray[13] = $ahTicksLabelsY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Start ; Description ...: Move starting point of plot ; Syntax.........: _GraphGDIPlus_Plot_Start(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to start at ; $iY - y value to start at ; ======================================================================================== Func _GraphGDIPlus_Plot_Start(ByRef $aGraphArray,$iX,$iY) ;----- MOVE pen to start point ----- $aGraphArray[18] = _GraphGDIPlus_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]) $aGraphArray[19] = _GraphGDIPlus_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Line ; Description ...: draws straight line to x,y from previous point / starting point ; Syntax.........: _GraphGDIPlus_Plot_Line(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw to ; $iY - y value to draw to ; ======================================================================================== Func _GraphGDIPlus_Plot_Line(ByRef $aGraphArray,$iX,$iY) ;----- Draw line from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]) _GDIPlus_GraphicsDrawLine($aGraphArray[17],$aGraphArray[18],$aGraphArray[19],$iX,$iY,$aGraphArray[20]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Point ; Description ...: draws point at coords ; Syntax.........: _GraphGDIPlus_Plot_Point(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Point(ByRef $aGraphArray,$iX,$iY) ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]) _GDIPlus_GraphicsDrawRect($aGraphArray[17],$iX-1,$iY-1,2,2,$aGraphArray[20]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Dot ; Description ...: draws single pixel dot at coords ; Syntax.........: _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x",$iX,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y",$iY,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]) _GDIPlus_GraphicsDrawRect($aGraphArray[17],$iX,$iY,1,1,$aGraphArray[20]) ;draws 2x2 dot ?HOW to get 1x1 pixel????? _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenColor ; Description ...: sets the Color for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKColor) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $hColor - the Color of the next item (ARGB) ; ======================================================================================== Func _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray,$hColor) ;----- apply pen Color ----- _GDIPlus_PenSetColor($aGraphArray[20],$hColor) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenSize ; Description ...: sets the pen for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iSize - size of pen line ; ======================================================================================== Func _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ;----- apply pen size ----- _GDIPlus_PenSetWidth($aGraphArray[20],$iSize) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenDash ; Description ...: sets the pen dash style for the next drawing ; Syntax.........: GraphGDIPlus_Set_PenDash(ByRef $aGraphArray,$iDash = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iDash - style of dash, where: ; 0 = solid line ; 1 = simple dashed line ; 2 = simple dotted line ; 3 = dash dot line ; 4 = dash dot dot line ; ======================================================================================== Func _GraphGDIPlus_Set_PenDash(ByRef $aGraphArray,$iDash = 0) Local $Style Switch $iDash Case 0 ;solid line _____ $Style = $GDIP_DASHSTYLESOLID Case 1 ;simple dash ----- $Style = $GDIP_DASHSTYLEDASH Case 2 ;simple dotted ..... $Style = $GDIP_DASHSTYLEDOT Case 3 ;dash dot -.-.- $Style = $GDIP_DASHSTYLEDASHDOT Case 4 ;dash dot dot -..-..-.. $Style = $GDIP_DASHSTYLEDASHDOTDOT EndSwitch ;----- apply pen dash ----- _GDIPlus_PenSetDashStyle($aGraphArray[20],$Style) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridX ; Description ...: Adds X gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorY0 - [optional] RGB value, defining Color of Y=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks=1, $hColor=0xFFf0f0f0, $hColorY0=0xFF000000) ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23],$hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[6] To $aGraphArray[7] Step $Ticks If $i = Number($aGraphArray[6]) Or $i = Number($aGraphArray[7]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x",$i,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x",$i,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) Next EndSelect ;----- draw y=0 ----- _GDIPlus_PenSetColor($aGraphArray[23],$hColorY0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x",0,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x",0,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y",0,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y",0,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]), _ $aGraphArray[23]) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23],$hColor) ;set Color back to user def EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridY ; Description ...: Adds Y gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorX0 - [optional] RGB value, defining Color of X=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks=1, $hColor=0xFFf0f0f0, $hColorX0=0xFF000000) ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23],$hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[8] To $aGraphArray[9] Step $Ticks If $i = Number($aGraphArray[8]) Or $i = Number($aGraphArray[9]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y",$i,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y",$i,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]), _ $aGraphArray[23]) Next EndSelect ;----- draw abcissa/ordinate ----- _GDIPlus_PenSetColor($aGraphArray[23],$hColorX0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x",0,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x",0,$aGraphArray[6],$aGraphArray[7],$aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y",0,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y",0,$aGraphArray[8],$aGraphArray[9],$aGraphArray[5]), _ $aGraphArray[23]) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23],$hColor) ;set Color back to user def EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Refresh ; Description ...: refreshes the graphic ; Syntax.........: _GraphGDIPlus_Refresh(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================== Func _GraphGDIPlus_Refresh(ByRef $aGraphArray) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($aGraphArray[1],$aGraphArray[16],$aGraphArray[2], _ $aGraphArray[3],$aGraphArray[4]+1,$aGraphArray[5]+1) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_RedrawRect ; Description ...: INTERNAL FUNCTION - Re-draws the border ; Syntax.........: _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; Notes..........: This prevents drawing over the border of the graph area ; ========================================================================================= Func _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) ;----- draw border ----- _GDIPlus_GraphicsDrawRect($aGraphArray[17],0,0,$aGraphArray[4],$aGraphArray[5],$aGraphArray[22]) ;draw border EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _GraphGDIPlus_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; ========================================================================================= Func _GraphGDIPlus_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow))))) Case "p" Return ($iValue / ($iTotalPixels/ ($iHigh - $iLow))) + $iLow EndSwitch EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_SaveImage ; Description ...: INTERNAL FUNCTION - save drawn image to file ; Syntax.........: _GraphGDIPlus_Reference_Pixel($file, $hWnd) ; Parameters ....: $file - filename ; $hWnd - handle to GUI ; Autor .........: ptrex, ProgAndy, UEZ ; ========================================================================================= Func _GraphGDIPlus_SaveImage($file, $hWnd) Local $hDC, $memBmp, $memDC, $hImage, $w, $h Const $SRCCOPY = 0x00CC0020 If $file <> "" And $hWnd <> "" Then $size = WinGetClientSize($hWnd) $w = $size[0] $h = $size[1] $hDC = _WinAPI_GetDC($hWnd) $memDC = _WinAPI_CreateCompatibleDC($hDC) $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h) _WinAPI_SelectObject ($memDC, $memBmp) _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, $SRCCOPY) $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp) _GDIPlus_ImageSaveToFile($hImage, $file) If @error Then Return SetError(1, 0, 0) Else Return SetError(0, 0, 0) EndIf _GDIPlus_ImageDispose ($hImage) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($memDC) _WinAPI_DeleteObject ($memBmp) Else Return SetError(1, 0, 0) EndIf EndFuncAdded function _GraphGDIPlus_SaveImage() and anti aliasing (_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)) for smoother display of the graph lines.When you add the line _GraphGDIPlus_SaveImage(@ScriptDir & "\test.jpg", $GUI) to your example above..._Draw_Graph() _GraphGDIPlus_SaveImage(@ScriptDir & "\test.jpg", $GUI) While 1 Sleep(100) WEnd...it will save the content of the GUI to a jpg file!UEZ Edited November 9, 2009 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
winux38 Posted February 14, 2010 Share Posted February 14, 2010 EXCELLENT UDF very usefull. very good job - Added function to control Smooth mode (_GraphGDIPlus_SmoothMode(ByRef $aGraphArray,$iMode=0) -added array for $aGraphGDIPlusaGraphArrayINTERNAL to allow several instance of graphic in the same window. Unfortunatlly works well with 2 but not with 3?? (Sorry I am not an expert in GDI). - Formated file to make it more UDF like. - Added enum to get named offset in $aGraphArray instead of literal value. expandcollapse popup#include-once #include <GDIplus.au3> ; #INDEX# ======================================================================================================================= ; Title .........: GraphGDIPlus_UDF ; AutoIt Version : 3.2.10++ ; Language ......: English ; Description ...: This module contains various functions for manipulating Graph object ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_GraphGDIPlus_Create ;_GraphGDIPlus_Delete ;_GraphGDIPlus_ReDraw ;_GraphGDIPlus_Clear ;_GraphGDIPlus_Set_RangeX ;_GraphGDIPlus_Set_RangeY ;_GraphGDIPlus_Plot_Start ;_GraphGDIPlus_Plot_Line ;_GraphGDIPlus_Plot_Point ;_GraphGDIPlus_Plot_Dot ;_GraphGDIPlus_Set_PenColor ;_GraphGDIPlus_Set_PenSize ;_GraphGDIPlus_Set_PenDash ;_GraphGDIPlus_Set_GridX ;_GraphGDIPlus_Set_GridY ;_GraphGDIPlus_Refresh ;_GraphGDIPlus_SaveImage ;_GraphGDIPlus_SmoothMode ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _GraphGDIPlus_RedrawRect ; _GraphGDIPlus_Reference_Pixel ; =============================================================================================================================== ; Offset for fields in $GraphArray Local Enum $_GRAPH_NOUSE = 0 , _ ; [0] Not used $_GRAPH_HANDLE , _ ; [1] graphic control handle $_GRAPH_LEFT , _ ; [2] left $_GRAPH_TOP , _ ; [3] top $_GRAPH_WIDTH , _ ; [4] width $_GRAPH_HEIGHT , _ ; [5] height $_GRAPH_XLOW , _ ; [6] x low $_GRAPH_XHIGH , _ ; [7] x high $_GRAPH_YLOW , _ ; [8] y low $_GRAPH_YHIGH , _ ; [9] y high $_GRAPH_HXTICKS , _ ; [10] x ticks handles $_GRAPH_HXLABELS , _ ; [11] x labels handles $_GRAPH_HYTICKS , _ ; [12] y ticks handles $_GRAPH_HYLABELS , _ ; [13] y labels handles $_GRAPH_BORDERCOLOR , _ ; [14] Border Color $_GRAPH_FILLCOLOR , _ ; [15] Fill Color $_GRAPH_HBITMAP , _ ; [16] Bitmap Handle $_GRAPH_HBACKBUFFER , _ ; [17] Backbuffer Handle $_GRAPH_LASTXPOS , _ ; [18] Last used x pos $_GRAPH_LASTYPOS , _ ; [19] Last used y pos $_GRAPH_HPEN , _ ; [20] Pen (main) Handle $_GRAPH_HBRUSH , _ ; [21] Brush (fill) Handle $_GRAPH_HPENBORDER , _ ; [22] Pen (border) Handle $_GRAPH_HPENGRID , _ ; [23] Pen (grid) Handle $_GRAPH_INTERNALINDEX , _ ; [24] Index in internal graph array $_GRAPH_SMOOTHMODE , _ ; [25] Smooth mode(default=0) $_GRAPH_SIZE ; must be the last one Global $aGraphGDIPlusaGraphArrayINTERNAL[1] ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Create ; Description ...: Creates graph area, and prepares array of specified data ; Syntax.........: _GraphGDIPlus_Create($hWnd,$iLeft,$iTop,$iWidth,$iHeight,$hColorBorder = 0xFF000000,$hColorFill = 0xFFFFFFFF) ; Parameters ....: $hWnd - Handle to GUI ; $iLeft - left most position in GUI ; $iTop - top most position in GUI ; $iWidth - width of graph in pixels ; $iHeight - height of graph in pixels ; $hColorBorder - Color of graph border (ARGB) ; $hColorFill - Color of background (ARGB) ; Return values .: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] x low ; [7] x high ; [8] y low ; [9] y high ; [10] x ticks handles ; [11] x labels handles ; [12] y ticks handles ; [13] y labels handles ; [14] Border Color ; [15] Fill Color ; [16] Bitmap Handle ; [17] Backbuffer Handle ; [18] Last used x pos ; [19] Last used y pos ; [20] Pen (main) Handle ; [21] Brush (fill) Handle ; [22] Pen (border) Handle ; [23] Pen (grid) Handle ; [24] Index in internal graph array ; [25] Smooth mode (default=0) ; ======================================================================================= Func _GraphGDIPlus_Create($hWnd,$iLeft,$iTop,$iWidth,$iHeight,$hColorBorder = 0xFF000000,$hColorFill = 0xFFFFFFFF) Local $graphics,$bitmap,$backbuffer,$brush,$bpen,$gpen,$pen Local $ahTicksLabelsX[1] Local $ahTicksLabelsY[1] Local $ahTicksX[1] Local $ahTicksY[1] Local $aGraphArray[1] local $i ;----- Set GUI transparency to SOLID (prevents GDI+ glitches) ----- WinSetTrans($hWnd,"",255) ;----- GDI+ Initiate ----- _GDIPlus_Startup() $graphics=_GDIPlus_GraphicsCreateFromHWND($hWnd) ;graphics area $bitmap=_GDIPlus_BitmapCreateFromGraphics($iWidth+1,$iHeight+1,$graphics);buffer bitmap $backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap) ;buffer area _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 0) ;----- Set background Color ----- $brush = _GDIPlus_BrushCreateSolid($hColorFill) _GDIPlus_GraphicsfillRect($backbuffer,0,0,$iWidth,$iHeight,$brush) ;----- Set border Pen + color ----- $bpen = _GDIPlus_PenCreate($hColorBorder) _GDIPlus_PenSetEndCap($bpen,$GDIP_LINECAPROUND) ;----- Set Grid Pen + color ----- $gpen = _GDIPlus_PenCreate(0xFFf0f0f0) _GDIPlus_PenSetEndCap($gpen,$GDIP_LINECAPROUND) ;----- set Drawing Pen + Color ----- $pen = _GDIPlus_PenCreate() ;drawing pen initially black, user to set _GDIPlus_PenSetEndCap($pen,$GDIP_LINECAPROUND) _GDIPlus_GraphicsDrawRect($backbuffer,0,0,$iWidth,$iHeight,$pen) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,$iLeft,$iTop,$iWidth+1,$iHeight+1) ;----- register redraw ----- GUIRegisterMsg(0x0006,"_GraphGDIPlus_ReDraw") ;----- prep + load array ----- Dim $aGraphArray[$_GRAPH_SIZE] = ["", _ $graphics, _ ; [1] graphic control handle $iLeft,$iTop, _ ; [2] left, [3] top $iWidth,$iHeight, _ ; [4] width, [5] height 0,1,0,1, _ ; [6] x low, [7] x high, [8] y low, [9] y high $ahTicksX,$ahTicksLabelsX, _ ; [10] x ticks handles, [11] x labels handles $ahTicksY,$ahTicksLabelsY, _ ; [12] y ticks handles, [13] y labels handles $hColorBorder,$hColorFill, _ ; [14] Border Color, [15] Fill Color $bitmap,$backbuffer, _ ; [16] Bitmap Handle, [17] Backbuffer Handle 0,0, _ ; [18] Last used x pos, [19] Last used y pos $pen,$brush,$bpen,$gpen, _ ; [20] Pen (main) Handle, [21] Brush (fill) Handle, [22] Pen (border) Handle, [23] Pen (grid) Handle -1,0] ; [24] Index in $aGraphGDIPlusaGraphArrayINTERNAL, [25] Smooth mode $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL,1)-1] = $aGraphArray $aGraphArray[$_GRAPH_INTERNALINDEX] = UBound($aGraphGDIPlusaGraphArrayINTERNAL,1)-1 redim $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL,1)+1] $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL,1)-1]=-1 Return $aGraphArray EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_ReDraw ; Description ...: redraw of the GDI+ Image upon window min/maximize ; Syntax.........: _GraphGDIPlus_Delete($hWnd) ; Parameters ....: $hWnd - GUI handle ; Return values .: None ; ======================================================================================= Func _GraphGDIPlus_ReDraw($hWnd) local $i ;----- Allows redraw of the GDI+ Image upon window min/maximize ----- _WinAPI_RedrawWindow($hWnd,0,0,0x0100) for $i=0 to UBound($aGraphGDIPlusaGraphArrayINTERNAL,1)-1 if $aGraphGDIPlusaGraphArrayINTERNAL[$i] <> -1 then _GraphGDIPlus_Refresh($aGraphGDIPlusaGraphArrayINTERNAL[$i]) EndIf Next EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Delete ; Description ...: Deletes previously created graph and related ticks/labels ; Syntax.........: _GraphGDIPlus_Delete($hWnd,ByRef $aGraphArray) ; Parameters ....: $hWnd - GUI handle ; $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iKeepGDIPlus - if not zero, function will not _GDIPlus_Shutdown() ; Return values .: None ; ======================================================================================= Func _GraphGDIPlus_Delete($hWnd,ByRef $aGraphArray,$iKeepGDIPlus = 0) Local $ahTicksX,$ahTicksLabelsX,$ahTicksY,$ahTicksLabelsY,$i ;----- delete x ticks/labels ----- $ahTicksX = $aGraphArray[$_GRAPH_HXTICKS] $ahTicksLabelsX = $aGraphArray[$_GRAPH_HXLABELS] For $i = 1 to (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next For $i = 1 to (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next ;----- delete y ticks/labels ----- $ahTicksY = $aGraphArray[$_GRAPH_HYTICKS] $ahTicksLabelsY = $aGraphArray[$_GRAPH_HYLABELS] For $i = 1 to (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next ;----- delete graphic control ----- _GDIPlus_GraphicsDispose($aGraphArray[$_GRAPH_HBACKBUFFER]) _GDIPlus_BitmapDispose($aGraphArray[$_GRAPH_HBITMAP]) _GDIPlus_GraphicsDispose($aGraphArray[$_GRAPH_HANDLE]) _GDIPlus_BrushDispose($aGraphArray[$_GRAPH_HBRUSH]) _GDIPlus_PenDispose($aGraphArray[$_GRAPH_HPEN]) _GDIPlus_PenDispose($aGraphArray[$_GRAPH_HPENBORDER]) _GDIPlus_PenDispose($aGraphArray[$_GRAPH_HPENGRID]) If $iKeepGDIPlus = 0 Then _GDIPlus_Shutdown() _WinAPI_InvalidateRect($hWnd) ;----- Remove entry in $aGraphGDIPlusaGraphArrayINTERNAL ----- $aGraphGDIPlusaGraphArrayINTERNAL[$aGraphArray [$_GRAPH_INTERNALINDEX]]=-1 ;----- close array ----- $aGraphArray = 0 EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Clear ; Description ...: Clears graph content ; Syntax.........: _GraphGDIPlus_Clear(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; Return values .: None ; ======================================================================================= Func _GraphGDIPlus_Clear(ByRef $aGraphArray) ;----- Set background Color ----- _GDIPlus_GraphicsfillRect($aGraphArray[$_GRAPH_HBACKBUFFER],0,0,$aGraphArray[$_GRAPH_WIDTH],$aGraphArray[$_GRAPH_HEIGHT], $aGraphArray[$_GRAPH_HBRUSH]) ;----- set border + Color ----- _GraphGDIPlus_RedrawRect($aGraphArray) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($aGraphArray[$_GRAPH_HANDLE],$aGraphArray[$_GRAPH_HBITMAP],$aGraphArray[$_GRAPH_LEFT],$aGraphArray[$_GRAPH_TOP],$aGraphArray[$_GRAPH_WIDTH]+1,$aGraphArray[$_GRAPH_HEIGHT]+1) EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeX ; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the X axis (can be negative) ; $iHigh - the highest value for the X axis ; $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; Return values .: None ; ======================================================================================= Func _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) Local $ahTicksX,$ahTicksLabelsX,$i ;----- load user vars to array ----- $aGraphArray[$_GRAPH_XLOW] = $iLow $aGraphArray[$_GRAPH_XHIGH] = $iHigh ;----- prepare nested array ----- $ahTicksX = $aGraphArray[$_GRAPH_HXTICKS] $ahTicksLabelsX = $aGraphArray[$_GRAPH_HXLABELS] ;----- delete any existing ticks ----- For $i = 1 to (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next Dim $ahTicksX[1] ;----- create new ticks ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("",(($i - 1) * ($aGraphArray[$_GRAPH_WIDTH] / $iXTicks)) + $aGraphArray[$_GRAPH_LEFT], _ $aGraphArray[$_GRAPH_TOP] + $aGraphArray[$_GRAPH_HEIGHT],1,5) GUICtrlSetBkcolor(-1,0x000000) GUICtrlSetState(-1,128) Next ;----- delete any existing labels ----- For $i = 1 to (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($aGraphArray[$_GRAPH_LEFT] + (($aGraphArray[$_GRAPH_WIDTH] / $iXTicks) * ($i - 1))) - (($aGraphArray[$_GRAPH_WIDTH] / $iXTicks) / 2), _ $aGraphArray[$_GRAPH_TOP] + $aGraphArray[$_GRAPH_HEIGHT] + 10,$aGraphArray[$_GRAPH_WIDTH] / $iXTicks,13,1) GUICtrlSetBkcolor(-1,-2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f",_GraphGDIPlus_Reference_Pixel("p",(($i - 1) * ($aGraphArray[$_GRAPH_WIDTH] / $iXTicks)), _ $aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[$_GRAPH_HXTICKS] = $ahTicksX $aGraphArray[$_GRAPH_HXLABELS] = $ahTicksLabelsX EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeY ; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the Y axis (can be negative) ; $iHigh - the highest value for the Y axis ; $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; Return values .: None ; ======================================================================================= Func _GraphGDIPlus_Set_RangeY(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) Local $ahTicksY,$ahTicksLabelsY,$i ;----- load user vars to array ----- $aGraphArray[$_GRAPH_YLOW] = $iLow $aGraphArray[$_GRAPH_YHIGH] = $iHigh ;----- prepare nested array ----- $ahTicksY = $aGraphArray[$_GRAPH_HYTICKS] $ahTicksLabelsY = $aGraphArray[$_GRAPH_HYLABELS] ;----- delete any existing ticks ----- For $i = 1 to (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next Dim $ahTicksY[1] ;----- create new ticks ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("",$aGraphArray[$_GRAPH_LEFT] - 5, _ ($aGraphArray[$_GRAPH_TOP] + $aGraphArray[$_GRAPH_HEIGHT]) - (($aGraphArray[$_GRAPH_HEIGHT] / $iYTicks) * ($i - 1)),5,1) GUICtrlSetBkcolor(-1,0x000000) GUICtrlSetState(-1,128) Next ;----- delete any existing labels ----- For $i = 1 to (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("",$aGraphArray[$_GRAPH_LEFT] - 40, _ ($aGraphArray[$_GRAPH_TOP] + $aGraphArray[$_GRAPH_HEIGHT]) - (($aGraphArray[$_GRAPH_HEIGHT] / $iYTicks) * ($i - 1)) - 6,30,13,2) GUICtrlSetBkcolor(-1,-2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i],StringFormat("%." & $iRound & "f",_GraphGDIPlus_Reference_Pixel("p", _ (($i - 1) * ($aGraphArray[$_GRAPH_HEIGHT] / $iYTicks)),$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[$_GRAPH_HYTICKS] = $ahTicksY $aGraphArray[$_GRAPH_HYLABELS] = $ahTicksLabelsY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Start ; Description ...: Move starting point of plot ; Syntax.........: _GraphGDIPlus_Plot_Start(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to start at ; $iY - y value to start at ; Return values .: None ; ======================================================================================== Func _GraphGDIPlus_Plot_Start(ByRef $aGraphArray,$iX,$iY) ;----- MOVE pen to start point ----- $aGraphArray[$_GRAPH_LASTXPOS] = _GraphGDIPlus_Reference_Pixel("x",$iX,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]) $aGraphArray[$_GRAPH_LASTYPOS] = _GraphGDIPlus_Reference_Pixel("y",$iY,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Line ; Description ...: draws straight line to x,y from previous point / starting point ; Syntax.........: _GraphGDIPlus_Plot_Line(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw to ; $iY - y value to draw to ; Return values .: None ; ======================================================================================== Func _GraphGDIPlus_Plot_Line(ByRef $aGraphArray,$iX,$iY) ;----- Draw line from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x",$iX,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]) $iY = _GraphGDIPlus_Reference_Pixel("y",$iY,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]) _GDIPlus_GraphicsDrawLine($aGraphArray[$_GRAPH_HBACKBUFFER],$aGraphArray[$_GRAPH_LASTXPOS],$aGraphArray[$_GRAPH_LASTYPOS],$iX,$iY,$aGraphArray[$_GRAPH_HPEN]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[$_GRAPH_LASTXPOS] = $iX $aGraphArray[$_GRAPH_LASTYPOS] = $iY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Point ; Description ...: draws point at coords ; Syntax.........: _GraphGDIPlus_Plot_Point(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; Return values .: None ; ======================================================================================== Func _GraphGDIPlus_Plot_Point(ByRef $aGraphArray,$iX,$iY) ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x",$iX,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]) $iY = _GraphGDIPlus_Reference_Pixel("y",$iY,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]) _GDIPlus_GraphicsDrawRect($aGraphArray[$_GRAPH_HBACKBUFFER],$iX-1,$iY-1,2,2,$aGraphArray[$_GRAPH_HPEN]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[$_GRAPH_LASTXPOS] = $iX $aGraphArray[$_GRAPH_LASTYPOS] = $iY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Dot ; Description ...: draws single pixel dot at coords ; Syntax.........: _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; Return values .: None ; ======================================================================================== Func _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x",$iX,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]) $iY = _GraphGDIPlus_Reference_Pixel("y",$iY,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]) _GDIPlus_GraphicsDrawRect($aGraphArray[$_GRAPH_HBACKBUFFER],$iX,$iY,1,1,$aGraphArray[$_GRAPH_HPEN]) ;draws 2x2 dot ?HOW to get 1x1 pixel????? _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[$_GRAPH_LASTXPOS] = $iX $aGraphArray[$_GRAPH_LASTYPOS] = $iY EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenColor ; Description ...: sets the Color for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKColor) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $hColor - the Color of the next item (ARGB) ; Return values .: None ; ======================================================================================== Func _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray,$hColor) ;----- apply pen Color ----- _GDIPlus_PenSetColor($aGraphArray[$_GRAPH_HPEN],$hColor) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenSize ; Description ...: sets the pen for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iSize - size of pen line ; Return values .: None ; ======================================================================================== Func _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ;----- apply pen size ----- _GDIPlus_PenSetWidth($aGraphArray[$_GRAPH_HPEN],$iSize) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenDash ; Description ...: sets the pen dash style for the next drawing ; Syntax.........: GraphGDIPlus_Set_PenDash(ByRef $aGraphArray,$iDash = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iDash - style of dash, where: ; 0 = solid line ; 1 = simple dashed line ; 2 = simple dotted line ; 3 = dash dot line ; 4 = dash dot dot line ; Return values .: None ; ======================================================================================== Func _GraphGDIPlus_Set_PenDash(ByRef $aGraphArray,$iDash = 0) Local $Style Switch $iDash Case 0 ;solid line _____ $Style = $GDIP_DASHSTYLESOLID Case 1 ;simple dash ----- $Style = $GDIP_DASHSTYLEDASH Case 2 ;simple dotted ..... $Style = $GDIP_DASHSTYLEDOT Case 3 ;dash dot -.-.- $Style = $GDIP_DASHSTYLEDASHDOT Case 4 ;dash dot dot -..-..-.. $Style = $GDIP_DASHSTYLEDASHDOTDOT EndSwitch ;----- apply pen dash ----- _GDIPlus_PenSetDashStyle($aGraphArray[$_GRAPH_HPEN],$Style) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridX ; Description ...: Adds X gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorY0 - [optional] RGB value, defining Color of Y=0 line, Default black ; Return values .: None ; ======================================================================================= Func _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks=1, $hColor=0xFFf0f0f0, $hColorY0=0xFF000000) ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[$_GRAPH_HPENGRID],$hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[$_GRAPH_XLOW] To $aGraphArray[$_GRAPH_XHIGH] Step $Ticks If $i = Number($aGraphArray[$_GRAPH_XLOW]) Or $i = Number($aGraphArray[$_GRAPH_XHIGH]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[$_GRAPH_HBACKBUFFER], _ _GraphGDIPlus_Reference_Pixel("x",$i,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x",$i,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]), _ $aGraphArray[$_GRAPH_HEIGHT] - 1, _ $aGraphArray[$_GRAPH_HPENGRID]) Next EndSelect ;----- draw y=0 ----- _GDIPlus_PenSetColor($aGraphArray[$_GRAPH_HPENGRID],$hColorY0) _GDIPlus_GraphicsDrawLine($aGraphArray[$_GRAPH_HBACKBUFFER], _ _GraphGDIPlus_Reference_Pixel("x",0,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x",0,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]), _ $aGraphArray[$_GRAPH_HEIGHT] - 1, _ $aGraphArray[$_GRAPH_HPENGRID]) _GDIPlus_GraphicsDrawLine($aGraphArray[$_GRAPH_HBACKBUFFER], _ 1, _ _GraphGDIPlus_Reference_Pixel("y",0,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]), _ $aGraphArray[$_GRAPH_WIDTH] - 1, _ _GraphGDIPlus_Reference_Pixel("y",0,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]), _ $aGraphArray[$_GRAPH_HPENGRID]) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[$_GRAPH_HPENGRID],$hColor) ;set Color back to user def EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridY ; Description ...: Adds Y gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorX0 - [optional] RGB value, defining Color of X=0 line, Default black ; Return values .: None ; ======================================================================================= Func _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks=1, $hColor=0xFFf0f0f0, $hColorX0=0xFF000000) ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[$_GRAPH_HPENGRID],$hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[$_GRAPH_YLOW] To $aGraphArray[$_GRAPH_YHIGH] Step $Ticks If $i = Number($aGraphArray[$_GRAPH_YLOW]) Or $i = Number($aGraphArray[$_GRAPH_YHIGH]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[$_GRAPH_HBACKBUFFER], _ 1, _ _GraphGDIPlus_Reference_Pixel("y",$i,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]), _ $aGraphArray[$_GRAPH_WIDTH] - 1, _ _GraphGDIPlus_Reference_Pixel("y",$i,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]), _ $aGraphArray[$_GRAPH_HPENGRID]) Next EndSelect ;----- draw abcissa/ordinate ----- _GDIPlus_PenSetColor($aGraphArray[$_GRAPH_HPENGRID],$hColorX0) _GDIPlus_GraphicsDrawLine($aGraphArray[$_GRAPH_HBACKBUFFER], _ _GraphGDIPlus_Reference_Pixel("x",0,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x",0,$aGraphArray[$_GRAPH_XLOW],$aGraphArray[$_GRAPH_XHIGH],$aGraphArray[$_GRAPH_WIDTH]), _ $aGraphArray[$_GRAPH_HEIGHT] - 1, _ $aGraphArray[$_GRAPH_HPENGRID]) _GDIPlus_GraphicsDrawLine($aGraphArray[$_GRAPH_HBACKBUFFER], _ 1, _ _GraphGDIPlus_Reference_Pixel("y",0,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]), _ $aGraphArray[$_GRAPH_WIDTH] - 1, _ _GraphGDIPlus_Reference_Pixel("y",0,$aGraphArray[$_GRAPH_YLOW],$aGraphArray[$_GRAPH_YHIGH],$aGraphArray[$_GRAPH_HEIGHT]), _ $aGraphArray[$_GRAPH_HPENGRID]) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[$_GRAPH_HPENGRID],$hColor) ;set Color back to user def EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Refresh ; Description ...: refreshes the graphic ; Syntax.........: _GraphGDIPlus_Refresh(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; Return values .: None ; ======================================================================================== Func _GraphGDIPlus_Refresh(ByRef $aGraphArray) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($aGraphArray[$_GRAPH_HANDLE],$aGraphArray[$_GRAPH_HBITMAP],$aGraphArray[$_GRAPH_LEFT], _ $aGraphArray[$_GRAPH_TOP],$aGraphArray[$_GRAPH_WIDTH]+1,$aGraphArray[$_GRAPH_HEIGHT]+1) EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_RedrawRect ; Description ...: INTERNAL FUNCTION - Re-draws the border ; Syntax.........: _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; Notes..........: This prevents drawing over the border of the graph area ; Return values .: None ; ========================================================================================= Func _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) ;----- draw border ----- _GDIPlus_GraphicsDrawRect($aGraphArray[$_GRAPH_HBACKBUFFER],0,0,$aGraphArray[$_GRAPH_WIDTH],$aGraphArray[$_GRAPH_HEIGHT],$aGraphArray[$_GRAPH_HPENBORDER]) ;draw border EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _GraphGDIPlus_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; Return values .: Pixel reference ; ========================================================================================= Func _GraphGDIPlus_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels/($iHigh-$iLow))*(($iHigh-$iLow)*(($iValue-$iLow)/($iHigh-$iLow))))) Case "p" Return ($iValue / ($iTotalPixels/ ($iHigh - $iLow))) + $iLow EndSwitch EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_SaveImage ; Description ...: INTERNAL FUNCTION - save drawn image to file ; Syntax.........: _GraphGDIPlus_Reference_Pixel($file, $hWnd) ; Parameters ....: $file - filename ; $hWnd - handle to GUI ; Return values .: Pixel reference ; Author ........: ptrex, ProgAndy, UEZ ; ========================================================================================= Func _GraphGDIPlus_SaveImage($file, $hWnd) Local $hDC, $memBmp, $memDC, $hImage, $w, $h Const $SRCCOPY = 0x00CC0020 If $file <> "" And $hWnd <> "" Then $size = WinGetClientSize($hWnd) $w = $size[0] $h = $size[1] $hDC = _WinAPI_GetDC($hWnd) $memDC = _WinAPI_CreateCompatibleDC($hDC) $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h) _WinAPI_SelectObject ($memDC, $memBmp) _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, $SRCCOPY) $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp) _GDIPlus_ImageSaveToFile($hImage, $file) If @error Then Return SetError(1, 0, 0) Else Return SetError(0, 0, 0) EndIf _GDIPlus_ImageDispose ($hImage) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($memDC) _WinAPI_DeleteObject ($memBmp) Else Return SetError(1, 0, 0) EndIf EndFunc ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_SmoothMode ; Description ...: Set smooth mode(default=1) ; Syntax.........: _GraphGDIPlus_Delete($aGraphArray,$iMode) ; Parameters ....: $aGraphArray - GUI handle ; $iMode - smooth mode ; 0 - No smooth ; 1 - Smooth on a box of 8x4 ; 2 - Smooth on a box of 8x8 ; Return values .: None ; Author .........: ptrex, ProgAndy, UEZ, winux38 ; ======================================================================================= Func _GraphGDIPlus_SmoothMode(ByRef $aGraphArray,$iMode=0) _GDIPlus_GraphicsSetSmoothingMode($aGraphArray[$_GRAPH_HBACKBUFFER], $iMode) EndFunc Below is a test script. Validating graph2 produces a strange behaviour. expandcollapse popup#include <Array.au3> #include "GraphGDIPlus UDF.au3" Opt("GUIOnEventMode", 1) local $xsize,$ysize,$k $xsize=1000 $ysize=600 Global $iMin=-15 Global $iMax=20 ;----- Create random data table ----- local $XYval[1][3], $j=0 For $i = -5 to 5 step 0.1 redim $XYval[$j+1][3] $XYval[$j][0]=$i $XYval[$j][1]=Random($iMin, $iMax) $XYval[$j][2]="" if $XYval[$j][1] > ($iMin+(0.75*($iMax-$iMin))) then $XYval[$j][2]="B" ElseIf $XYval[$j][1] < ($iMin+(0.25*($iMax-$iMin))) then $XYval[$j][2]="S" EndIf $j+=1 next ;----- Create window for graph ----- $GUI = GUICreate("",$xsize,$ysize) GUISetOnEvent(-3,"_Exit") GUISetState() ;----- Create area for graph0 ----- local $graph=-1 $Graph = _GraphGDIPlus_Create($GUI,40, 30, $xsize/3,$ysize/3,0xFF000000,0xFF88B3DD) _GraphGDIPlus_Set_RangeX($Graph,-5,5,10,1) _GraphGDIPlus_Set_RangeY($Graph,-25,25,10,1) ;----- Create area for graph1 ----- local $graph1=-1 $Graph1 = _GraphGDIPlus_Create($GUI,80+$xsize/3, 30, $xsize/3,$ysize/3,0xFF000000,0xFF88B3DD) _GraphGDIPlus_Set_RangeX($Graph1,-5,5,1,1) _GraphGDIPlus_Set_RangeY($Graph1,-50,50,1,1) _GraphGDIPlus_SmoothMode($Graph1, 1) ;----- Create area for graph2 ----- local $graph2=-1 #cs $Graph2 = _GraphGDIPlus_Create($GUI,40, 60+$ysize/3, $xsize/3,$ysize/3,0xFF00FF00,0xFF88B3DD) _GraphGDIPlus_Set_RangeX($Graph2,-5,5,1,1) _GraphGDIPlus_Set_RangeY($Graph2,-10,50,1,1) #ce local $firstloop=1 While 1 Sleep(100) ;----- Setup for the graph0 ----- if $graph<>-1 Then _PrintGraph($graph,$XYval) EndIf ;----- Setup for the graph1 ----- if $graph1<>-1 Then _PrintGraph($graph1,$XYval) EndIf ;----- Setup for the graph2 ----- if $graph2<>-1 Then _PrintGraph($graph2,$XYval) EndIf if $firstloop=1 Then $firstloop=0 _GraphGDIPlus_SaveImage(@ScriptDir & "\test.jpg", $GUI) EndIf ;----- left shift of value array ----- For $i=0 to UBound($XYval,1)-2 $XYval[$i][1]=$XYval[$i+1][1] next $XYval[$i][1]=Random($iMin,$iMax) $XYval[$i][2]="" if $XYval[$i][1] > ($iMin+(0.75*($iMax-$iMin))) then $XYval[$i][2]="B" ElseIf $XYval[$i][1] < ($iMin+(0.25*($iMax-$iMin))) then $XYval[$i][2]="S" EndIf WEnd Func _Draw_Graph() ;----- Set line color and size ----- _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87) _GraphGDIPlus_Set_PenSize($Graph,2) ;----- draw lines ----- $First = True For $i = -5 to 5 step 0.1 $y = _X2Function($i) If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y) $First = False _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87) _GraphGDIPlus_Plot_Line($Graph,$i,$y) _GraphGDIPlus_Refresh($Graph) Next EndFunc Func _Draw_Graph1(byref $lgraph, byref $xyval) ;----- Set line color and size ----- local $pencolor[4]=[0xFFFF0000, 0xFF00FF00,0xFFFFFF00,0xFFFF00FF] local $colorindex=0 ;----- draw lines ----- $First = True For $i=0 to UBound($xyval,1)-1 If $First = True Then _GraphGDIPlus_Plot_Start($lgraph,$xyval[$i][0],$xyval[$i][1]) $First = False EndIf _GraphGDIPlus_Set_PenSize($lgraph,1) _GraphGDIPlus_Set_PenColor($lgraph,0xFF325D87) _GraphGDIPlus_Plot_Line($lgraph,$xyval[$i][0],$xyval[$i][1]) if $xyval[$i][1] > $iMin+(0.75*($iMax-$iMin)) Then _GraphGDIPlus_Set_PenSize($lgraph,4) _GraphGDIPlus_Set_PenColor($lgraph,$pencolor[0]) _GraphGDIPlus_Plot_Dot($lgraph,$xyval[$i][0],$xyval[$i][1]) ElseIf $xyval[$i][1] < $iMin+(0.25*($iMax-$iMin)) Then _GraphGDIPlus_Set_PenSize($lgraph,4) _GraphGDIPlus_Set_PenColor($lgraph,$pencolor[1]) _GraphGDIPlus_Plot_Dot($lgraph,$xyval[$i][0],$xyval[$i][1]) EndIf $colorindex+=1 $colorindex =BitAND($colorindex,0x00000003) _GraphGDIPlus_Refresh($lgraph) Next EndFunc Func _X2Function($iZ) Return ($iZ*$iZ) EndFunc Func _X3Function($iZ) Return $iZ^3+2*$iZ^2-$iZ EndFunc Func _GammaFunction($iZ) $nProduct = ((2^$iZ) / (1 + $iZ)) For $n = 2 to 1000 $nProduct *= ((1 + (1/$n))^$iZ) / (1 + ($iZ / $n)) Next Return (1/$iZ) * $nProduct EndFunc func _PrintGraph($lgraph,$lxyval) _GraphGDIPlus_Clear($lgraph) _GraphGDIPlus_Set_GridX($lgraph,1,0xFF6993BE) _GraphGDIPlus_Set_GridY($lgraph,5,0xFF6993BE) _Draw_Graph1($lgraph, $lxyval) EndFunc Func _Exit() ;----- close down GDI+ and clear graphic ----- _GraphGDIPlus_Delete($GUI,$Graph) Exit EndFunc Link to comment Share on other sites More sharing options...
andybiochem Posted February 20, 2010 Author Share Posted February 20, 2010 works well with 2 but not with 3 [graphs]?? (Sorry I am not an expert in GDI). I've just updated my original post above to correct the 'multiple graphs' issue. The problem turned out to be an issue when using WinSetTrans with GDI+. Removing the WinSetTrans code when creating the graphs solved the problem of displaying > 2 graphs. Unfortunately left with the problem of the GDI being 'clipped' by the screen edge. The only way I could think of correcting this was by GUIRegisterMsg 0x0003 which is WIN_MOVE. So evey time the GUI gets moved, the graphs are flushed. Should work ok now. Cheers! - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
aphesia Posted February 24, 2010 Share Posted February 24, 2010 rly rly usefull for my project at school. Now i wonder: can i make the graph draw faster? i got 80.000 measurepoints each second on a grid like 100x30.. that would take ages until the diagram is finished thanks Link to comment Share on other sites More sharing options...
joseLB Posted December 4, 2010 Share Posted December 4, 2010 Hi Andy, good to see these improvements over your basic udf. Great Job again and thanks for th reference!!!! By the way, they are EXTREMLY faster and flicker free!!! I suggest everyone to move from the old ones to this one, it takes almost no time.... I think you can mention this on your original udf...Well, what about a new routine that allows to put labels somewhere in graphics, something like:Func _GraphGDIPlus_Plot_Label(ByRef $aGraphArray, $iX, $iY, $text, ?$font?, ?size?) ThanksJose Link to comment Share on other sites More sharing options...
kiffab Posted August 26, 2012 Share Posted August 26, 2012 Hi Been using this to create a graph from a database I have. Is it possible to set the colour of the X and Y axis TEXT? i.e. the values on X and Y axis cheers Link to comment Share on other sites More sharing options...
ValeryVal Posted September 6, 2012 Share Posted September 6, 2012 Is it possible to set the colour of the X and Y axis TEXT? i.e. the values on X and Y axisYes. It's possible. See sample (function _ReSetTicksColor($Color)): expandcollapse popup#include "GraphGDIPlus.au3" #include <WindowsConstants.au3> Global $Graph Opt("GUIOnEventMode", 1) $GUI = GUICreate("",600,600, -1, -1, $WS_POPUPWINDOW, BitOR($WS_EX_APPWINDOW, $WS_EX_TOPMOST)) GUISetOnEvent(-3,"_Exit") GUISetState() ;----- Create Graph area ----- $Graph = _GraphGDIPlus_Create($GUI,40,30,530,520,0xFF000000,0xFF88B3DD) ;----- Set Text Color ----- _GraphGDIPlus_Set_TextColor($Graph, 0x00DDAA) ;----- Set X axis range from -5 to 5 ----- _GraphGDIPlus_Set_RangeX($Graph,-5,5,10,1,1) _GraphGDIPlus_Set_RangeY($Graph,-5,5,10,1,1) ;----- Set Y axis range from -5 to 5 ----- _GraphGDIPlus_Set_GridX($Graph,1,0xFF9369BE) _GraphGDIPlus_Set_GridY($Graph,1,0xFF9369BE) _ReSetTicksColor(0x00FF00) ;----- Draw the graph ----- _Draw_Graph() While 1 Sleep(100) WEnd Func _Draw_Graph() ;----- Set line color and size ----- _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87) _GraphGDIPlus_Set_PenSize($Graph,2) ;----- draw lines ----- $First = True For $i = -5 to 5 Step 0.005 $y = _GammaFunction($i) If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y) $First = False _GraphGDIPlus_Plot_Line($Graph,$i,$y) _GraphGDIPlus_Refresh($Graph) Next EndFunc Func _GammaFunction($iZ) $nProduct = ((2^$iZ) / (1 + $iZ)) For $n = 2 to 1000 $nProduct *= ((1 + (1/$n))^$iZ) / (1 + ($iZ / $n)) Next Return (1/$iZ) * $nProduct EndFunc Func _Exit() ;----- close down GDI+ and clear graphic ----- _GraphGDIPlus_Delete($GUI,$Graph) Exit EndFunc Func _ReSetTicksColor($Color) local $ahTicksX, $ahTicksLabelsX local $ahTicksY, $ahTicksLabelsY ;----- Reset TicksX color ----- $ahTicksX = $Graph[10] For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlSetColor($ahTicksX[$i], $Color) Next ;----- Reset TicksLabelsX color ----- $ahTicksLabelsX = $Graph[11] For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetColor($ahTicksLabelsX[$i], $Color) Next ;----- Reset TicksY color ----- $ahTicksY = $Graph[12] For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlSetColor($ahTicksY[$i], $Color) Next ;----- Reset TicksLabelsY color ----- $ahTicksLabelsY = $Graph[13] For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetColor($ahTicksLabelsY[$i], $Color) Next EndFunc The point of world view Link to comment Share on other sites More sharing options...
bobmcrae Posted December 16, 2012 Share Posted December 16, 2012 (edited) anybiochem, Congratulations on an excellent contribution to the AutoIT community. I have used this UDF for some graphing and it worked very well. I found the need to implement labels on a created graph. After a bit of work, I was able to get labels to display in the proper location and, generally, orientation. However, as the window is re-drawn (due to move, re-size, or losing focus) the labels in the graph area become occluded. You will see from the function I added to your UDF, I am not handling moves or re-sizes. While I have attempted to follow the UDF and realize that I probably need to add these new labels to the $aGraphArray, but unsure how to do that and whether that is even possible. Could you advise? Func _GraphGDIPlus_CreateLabel($hGUI,$text,$xPos,$yPos,$fontStyle=0x0000,$fontSize=14) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawString($hGraphic, $text, $xPos, $yPos,'Arial',$fontSize,$fontStyle) EndFunc Edited December 16, 2012 by bobmcrae Link to comment Share on other sites More sharing options...
UEZ Posted December 16, 2012 Share Posted December 16, 2012 @bobmcrae: andybiochem is offline now for more than 1 year. To your question: writing it to the graphic handle directly will not solve your issue. Use the backbuffer ($backbuffer) instead. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
bobmcrae Posted December 16, 2012 Share Posted December 16, 2012 Thanks for the super-fast reply & suggestion UEZ. I tried using $backbuffer, but that did not work (label did not display). I will troubleshoot some more with this suggestion though. $Graph = _GraphGDIPlus_Create($GUI,.08*$xSize,.06*$ySize,.9*$xSize,.8*$ySize,0xFF000000,0xFF88B3DD) ... _GraphGDIPlus_CreateLabel($Graph[17],'BFI: ' & getBFI($testFile),.93*$xSize,.25*$ySize,$RIGHT) Link to comment Share on other sites More sharing options...
UEZ Posted December 16, 2012 Share Posted December 16, 2012 (edited) Test this: Modified GraphGDIPlus.au3 (changed some functions from int to float to be more precise and changed save function): expandcollapse popup;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# =============================================================================== ; Title .........: GraphGDIPlus ; AutoIt Version: 3.3.0.0+ ; Language: English ; Description ...: A Graph control to draw line graphs, using GDI+, also double-buffered. ; Notes .........: ; ======================================================================================= ; #VARIABLES/INCLUDES# ================================================================== #include-once #include <GDIplus.au3> Global $aGraphGDIPlusaGraphArrayINTERNAL[1] ; ======================================================================================= ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Create ; Description ...: Creates graph area, and prepares array of specified data ; Syntax.........: _GraphGDIPlus_Create($hWnd,$iLeft,$iTop,$iWidth,$iHeight,$hColorBorder = 0xFF000000,$hColorFill = 0xFFFFFFFF) ; Parameters ....: $hWnd - Handle to GUI ; $iLeft - left most position in GUI ; $iTop - top most position in GUI ; $iWidth - width of graph in pixels ; $iHeight - height of graph in pixels ; $hColorBorder - Color of graph border (ARGB) ; $hColorFill - Color of background (ARGB) ; Return values .: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] x low ; [7] x high ; [8] y low ; [9] y high ; [10] x ticks handles ; [11] x labels handles ; [12] y ticks handles ; [13] y labels handles ; [14] Border Color ; [15] Fill Color ; [16] Bitmap Handle ; [17] Backbuffer Handle ; [18] Last used x pos ; [19] Last used y pos ; [20] Pen (main) Handle ; [21] Brush (fill) Handle ; [22] Pen (border) Handle ; [23] Pen (grid) Handle ; ======================================================================================= Func _GraphGDIPlus_Create($hWnd, $iLeft, $iTop, $iWidth, $iHeight, $hColorBorder = 0xFF000000, $hColorFill = 0xFFFFFFFF, $iSmooth = 2) Local $graphics, $bitmap, $backbuffer, $brush, $bpen, $gpen, $pen Local $ahTicksLabelsX[1] Local $ahTicksLabelsY[1] Local $ahTicksX[1] Local $ahTicksY[1] Local $aGraphArray[1] ;----- Set GUI transparency to SOLID (prevents GDI+ glitches) ----- ;WinSetTrans($hWnd, "", 255) - causes problems when more than 2 graphs used ;----- GDI+ Initiate ----- _GDIPlus_Startup() $graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) ;graphics area $bitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth + 1, $iHeight + 1, $graphics);buffer bitmap $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ;buffer area _GDIPlus_GraphicsSetSmoothingMode($backbuffer, $iSmooth) ;----- Set background Color ----- $brush = _GDIPlus_BrushCreateSolid($hColorFill) _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $iWidth, $iHeight, $brush) ;----- Set border Pen + color ----- $bpen = _GDIPlus_PenCreate($hColorBorder) _GDIPlus_PenSetEndCap($bpen, $GDIP_LINECAPROUND) ;----- Set Grid Pen + color ----- $gpen = _GDIPlus_PenCreate(0xFFf0f0f0) _GDIPlus_PenSetEndCap($gpen, $GDIP_LINECAPROUND) ;----- set Drawing Pen + Color ----- $pen = _GDIPlus_PenCreate() ;drawing pen initially black, user to set _GDIPlus_PenSetEndCap($pen, $GDIP_LINECAPROUND) _GDIPlus_GraphicsDrawRect($backbuffer, 0, 0, $iWidth, $iHeight, $pen) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, $iLeft, $iTop, $iWidth + 1, $iHeight + 1) ;----- register redraw ----- GUIRegisterMsg(0x0006, "_GraphGDIPlus_ReDraw") ;0x0006 = win activate GUIRegisterMsg(0x0003, "_GraphGDIPlus_ReDraw") ;0x0003 = win move ;----- prep + load array ----- Dim $aGraphArray[24] = ["", $graphics, $iLeft, $iTop, $iWidth, $iHeight, 0, 1, 0, 1, _ $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $hColorBorder, $hColorFill, _ $bitmap, $backbuffer, 0, 0, $pen, $brush, $bpen, $gpen] ;----- prep re-draw array for all graphs created ----- ReDim $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL) + 1] $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1] = $aGraphArray Return $aGraphArray EndFunc ;==>_GraphGDIPlus_Create Func _GraphGDIPlus_ReDraw($hWnd) ;----- Allows redraw of the GDI+ Image upon window min/maximize ----- Local $i _WinAPI_RedrawWindow($hWnd, 0, 0, 0x0100) For $i = 1 To UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1 If $aGraphGDIPlusaGraphArrayINTERNAL[$i] = 0 Then ContinueLoop _GraphGDIPlus_Refresh($aGraphGDIPlusaGraphArrayINTERNAL[$i]) Next EndFunc ;==>_GraphGDIPlus_ReDraw ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Delete ; Description ...: Deletes previously created graph and related ticks/labels ; Syntax.........: _GraphGDIPlus_Delete($hWnd,ByRef $aGraphArray) ; Parameters ....: $hWnd - GUI handle ; $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iKeepGDIPlus - if not zero, function will not _GDIPlus_Shutdown() ; ======================================================================================= Func _GraphGDIPlus_Delete($hWnd, ByRef $aGraphArray, $iKeepGDIPlus = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $i, $aTemp ;----- delete x ticks/labels ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next ;----- delete y ticks/labels ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next ;----- delete graphic control ----- _GDIPlus_GraphicsDispose($aGraphArray[17]) _GDIPlus_BitmapDispose($aGraphArray[16]) _GDIPlus_GraphicsDispose($aGraphArray[1]) _GDIPlus_BrushDispose($aGraphArray[21]) _GDIPlus_PenDispose($aGraphArray[20]) _GDIPlus_PenDispose($aGraphArray[22]) _GDIPlus_PenDispose($aGraphArray[23]) If $iKeepGDIPlus = 0 Then _GDIPlus_Shutdown() _WinAPI_InvalidateRect($hWnd) ;----- remove form global redraw array ----- For $i = 1 To UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1 $aTemp = $aGraphGDIPlusaGraphArrayINTERNAL[$i] If IsArray($aTemp) = 0 Then ContinueLoop If $aTemp[1] = $aGraphArray[1] Then $aGraphGDIPlusaGraphArrayINTERNAL[$i] = 0 Next ;----- close array ----- $aGraphArray = 0 EndFunc ;==>_GraphGDIPlus_Delete ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Clear ; Description ...: Clears graph content ; Syntax.........: _GraphGDIPlus_Clear(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================= Func _GraphGDIPlus_Clear(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- Set background Color ----- _GDIPlus_GraphicsFillRect($aGraphArray[17], 0, 0, $aGraphArray[4], $aGraphArray[5], $aGraphArray[21]) ;----- set border + Color ----- _GraphGDIPlus_RedrawRect($aGraphArray) EndFunc ;==>_GraphGDIPlus_Clear ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Refresh ; Description ...: refreshes the graphic ; Syntax.........: _GraphGDIPlus_Refresh(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================== Func _GraphGDIPlus_Refresh(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($aGraphArray[1], $aGraphArray[16], $aGraphArray[2], _ $aGraphArray[3], $aGraphArray[4] + 1, $aGraphArray[5] + 1) EndFunc ;==>_GraphGDIPlus_Refresh ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeX ; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the X axis (can be negative) ; $iHigh - the highest value for the X axis ; $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray, $iLow, $iHigh, $iXTicks = 1, $bLabels = 1, $iRound = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksX, $ahTicksLabelsX, $i ;----- load user vars to array ----- $aGraphArray[6] = $iLow $aGraphArray[7] = $iHigh ;----- prepare nested array ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] ;----- delete any existing ticks ----- For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next Dim $ahTicksX[1] ;----- create new ticks ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("", (($i - 1) * ($aGraphArray[4] / $iXTicks)) + $aGraphArray[2], _ $aGraphArray[3] + $aGraphArray[5], 1, 5) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetState(-1, 128) Next ;----- delete any existing labels ----- For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($aGraphArray[2] + (($aGraphArray[4] / $iXTicks) * ($i - 1))) - (($aGraphArray[4] / $iXTicks) / 2), _ $aGraphArray[3] + $aGraphArray[5] + 10, $aGraphArray[4] / $iXTicks, 13, 1) GUICtrlSetBkColor(-1, -2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f", _GraphGDIPlus_Reference_Pixel("p", (($i - 1) * ($aGraphArray[4] / $iXTicks)), _ $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[10] = $ahTicksX $aGraphArray[11] = $ahTicksLabelsX EndFunc ;==>_GraphGDIPlus_Set_RangeX ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeY ; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the Y axis (can be negative) ; $iHigh - the highest value for the Y axis ; $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeY(ByRef $aGraphArray, $iLow, $iHigh, $iYTicks = 1, $bLabels = 1, $iRound = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksY, $ahTicksLabelsY, $i ;----- load user vars to array ----- $aGraphArray[8] = $iLow $aGraphArray[9] = $iHigh ;----- prepare nested array ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] ;----- delete any existing ticks ----- For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next Dim $ahTicksY[1] ;----- create new ticks ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 5, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)), 5, 1) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetState(-1, 128) Next ;----- delete any existing labels ----- For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 40, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)) - 6, 30, 13, 2) GUICtrlSetBkColor(-1, -2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i], StringFormat("%." & $iRound & "f", _GraphGDIPlus_Reference_Pixel("p", _ (($i - 1) * ($aGraphArray[5] / $iYTicks)), $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[12] = $ahTicksY $aGraphArray[13] = $ahTicksLabelsY EndFunc ;==>_GraphGDIPlus_Set_RangeY ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Start ; Description ...: Move starting point of plot ; Syntax.........: _GraphGDIPlus_Plot_Start(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to start at ; $iY - y value to start at ; ======================================================================================== Func _GraphGDIPlus_Plot_Start(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- MOVE pen to start point ----- $aGraphArray[18] = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $aGraphArray[19] = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) EndFunc ;==>_GraphGDIPlus_Plot_Start ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Line ; Description ...: draws straight line to x,y from previous point / starting point ; Syntax.........: _GraphGDIPlus_Plot_Line(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw to ; $iY - y value to draw to ; ======================================================================================== Func _GraphGDIPlus_Plot_Line(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw line from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) ;~ _GDIPlus_GraphicsDrawLine($aGraphArray[17], $aGraphArray[18], $aGraphArray[19], $iX, $iY, $aGraphArray[20]) DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $aGraphArray[17], "handle", $aGraphArray[20], "float", $aGraphArray[18], "float", $aGraphArray[19], "float", $iX, "float", $iY) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Line ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Point ; Description ...: draws point at coords ; Syntax.........: _GraphGDIPlus_Plot_Point(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Point(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) ;~ _GDIPlus_GraphicsDrawRect($aGraphArray[17], $iX-1, $iY-1, 2, 2, $aGraphArray[20]) DllCall($ghGDIPDll, "int", "GdipDrawRectangle", "handle", $aGraphArray[17], "handle", $aGraphArray[20], "float", $iX-1, "float", $iY-1,"float", 2, "float", 2) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Point ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Dot ; Description ...: draws single pixel dot at coords ; Syntax.........: _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) ;~ _GDIPlus_GraphicsDrawRect($aGraphArray[17], $iX, $iY, 1, 1, $aGraphArray[20]) ;draws 2x2 dot ?HOW to get 1x1 pixel????? DllCall($ghGDIPDll, "int", "GdipDrawRectangle", "handle", $aGraphArray[17], "handle", $aGraphArray[20], "float", $iX, "float", $iY,"float", 1, "float", 1) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Dot ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenColor ; Description ...: sets the Color for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKColor) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $hColor - the Color of the next item (ARGB) ; ======================================================================================== Func _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray, $hColor) If IsArray($aGraphArray) = 0 Then Return ;----- apply pen Color ----- _GDIPlus_PenSetColor($aGraphArray[20], $hColor) EndFunc ;==>_GraphGDIPlus_Set_PenColor ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenSize ; Description ...: sets the pen for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iSize - size of pen line ; ======================================================================================== Func _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray, $iSize = 1) If IsArray($aGraphArray) = 0 Then Return ;----- apply pen size ----- _GDIPlus_PenSetWidth($aGraphArray[20], $iSize) EndFunc ;==>_GraphGDIPlus_Set_PenSize ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenDash ; Description ...: sets the pen dash style for the next drawing ; Syntax.........: GraphGDIPlus_Set_PenDash(ByRef $aGraphArray,$iDash = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iDash - style of dash, where: ; 0 = solid line ; 1 = simple dashed line ; 2 = simple dotted line ; 3 = dash dot line ; 4 = dash dot dot line ; ======================================================================================== Func _GraphGDIPlus_Set_PenDash(ByRef $aGraphArray, $iDash = 0) If IsArray($aGraphArray) = 0 Then Return Local $Style Switch $iDash Case 0 ;solid line _____ $Style = $GDIP_DASHSTYLESOLID Case 1 ;simple dash ----- $Style = $GDIP_DASHSTYLEDASH Case 2 ;simple dotted ..... $Style = $GDIP_DASHSTYLEDOT Case 3 ;dash dot -.-.- $Style = $GDIP_DASHSTYLEDASHDOT Case 4 ;dash dot dot -..-..-.. $Style = $GDIP_DASHSTYLEDASHDOTDOT EndSwitch ;----- apply pen dash ----- _GDIPlus_PenSetDashStyle($aGraphArray[20], $Style) EndFunc ;==>_GraphGDIPlus_Set_PenDash ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridX ; Description ...: Adds X gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorY0 - [optional] RGB value, defining Color of Y=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xFFf0f0f0, $hColorY0 = 0xFF000000) If IsArray($aGraphArray) = 0 Then Return ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[6] To $aGraphArray[7] Step $Ticks If $i = Number($aGraphArray[6]) Or $i = Number($aGraphArray[7]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) Next EndSelect ;----- draw y=0 ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColorY0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;set Color back to user def EndFunc ;==>_GraphGDIPlus_Set_GridX ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridY ; Description ...: Adds Y gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorX0 - [optional] RGB value, defining Color of X=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xFFf0f0f0, $hColorX0 = 0xFF000000) If IsArray($aGraphArray) = 0 Then Return ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[8] To $aGraphArray[9] Step $Ticks If $i = Number($aGraphArray[8]) Or $i = Number($aGraphArray[9]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) Next EndSelect ;----- draw abcissa/ordinate ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColorX0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;set Color back to user def EndFunc ;==>_GraphGDIPlus_Set_GridY ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_RedrawRect ; Description ...: INTERNAL FUNCTION - Re-draws the border ; Syntax.........: _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; Notes..........: This prevents drawing over the border of the graph area ; ========================================================================================= Func _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- draw border ----- _GDIPlus_GraphicsDrawRect($aGraphArray[17], 0, 0, $aGraphArray[4], $aGraphArray[5], $aGraphArray[22]) ;draw border EndFunc ;==>_GraphGDIPlus_RedrawRect ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _GraphGDIPlus_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; ========================================================================================= Func _GraphGDIPlus_Reference_Pixel($iType, $iValue, $iLow, $iHigh, $iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow))))) Case "p" Return ($iValue / ($iTotalPixels / ($iHigh - $iLow))) + $iLow EndSwitch EndFunc ;==>_GraphGDIPlus_Reference_Pixel ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_SaveImage ; Description ...: INTERNAL FUNCTION - save drawn image to file ; Syntax.........: _GraphGDIPlus_SaveImage($aGraphArray, $file) ; Parameters ....: ByRef $aGraphArray - the array returned from _GraphGDIPlus_Create ; $file - filename ; Autor .........: UEZ ; ========================================================================================= Func _GraphGDIPlus_SaveImage(ByRef $aGraphArray, $file) If IsArray($aGraphArray) = 0 Then Return _GDIPlus_ImageSaveToFile($aGraphArray[16], $file) If @error Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_GraphGDIPlus_SaveImage Func _GraphGDIPlus_DrawText(ByRef $aGraphArray, $sString, $iX, $iY, $iBrushColor = 0xFF000000, $sFont = "Arial", $iFontSize = 12, $iStyle = 0) If IsArray($aGraphArray) = 0 Then Return Local $hBrush = _GDIPlus_BrushCreateSolid($iBrushColor) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iStyle) Local $tLayout = _GDIPlus_RectFCreate($iX, $iY, 0, 0) _GDIPlus_GraphicsDrawStringEx($aGraphArray[17], $sString, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) Return 1 EndFunc ;==>_GraphGDIPlus_DrawText and add this line _GraphGDIPlus_DrawText($Graph, "Gamma Function in real time", 0, 0) to the example code in _Draw_Graph() function Func _Draw_Graph() ;----- Set line color and size ----- _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87) _GraphGDIPlus_Set_PenSize($Graph,2) ;----- draw lines ----- $First = True _GraphGDIPlus_DrawText($Graph, "Gamma Function in real time", 0, 0) For $i = -5 to 5 Step 0.05 $y = _GammaFunction($i) If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y) $First = False _GraphGDIPlus_Plot_Line($Graph,$i,$y) _GraphGDIPlus_Refresh($Graph) Next EndFunc Br, UEZ Edited December 17, 2012 by UEZ robertocm 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
bobmcrae Posted December 17, 2012 Share Posted December 17, 2012 UEZ: Perfect! I also like the fact that the string is associated with the graph object so its position is relative to the graph. Thanks very much for taking the time to help me with this issue. Link to comment Share on other sites More sharing options...
AZJIO Posted December 8, 2013 Share Posted December 8, 2013 (edited) Examples, 14 pieces, 2.75 KB, Ru GraphGDIPlus_Example.7z Edited December 8, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now