Ebola57 Posted February 24, 2020 Share Posted February 24, 2020 (edited) Hi communnity Trying to turn all the way I am not able to find the solution to my problem, allready browse topics relative to GDI+, but as I am not skilled at all with, can't figure out my error, so please any help appreciated it I leeched most a code from WideBoyDixon that die a wonderfulle function to create 3D Pie, here the code cleaned of what I didn't need 3D pie adapted from https://www.autoitscript.com/forum/topic/97241-3d-pie-chart/ expandcollapse popup; Get a darker version of a colour by extracting the RGB components Func _GetDarkerColour($Colour) Local $Red, $Green, $Blue $Red = (BitAND($Colour, 0xff0000) / 0x10000) - 40 $Green = (BitAND($Colour, 0x00ff00) / 0x100) - 40 $Blue = (BitAND($Colour, 0x0000ff)) - 40 If $Red < 0 Then $Red = 0 If $Green < 0 Then $Green = 0 If $Blue < 0 Then $Blue = 0 Return ($Red * 0x10000) + ($Green * 0x100) + $Blue EndFunc ;==>_GetDarkerColour ; Draw the pie chart Func _DrawPie($Pie_Margin, $PIE_DEPTH, $PIE_AREA, $Pie_Diameter, $ahBrush, $ahPen, $hGraphics, $hBitmap, $hBuffer, $PI, $Percentage, $Aspect, $rotation, $style = 1, $holesize = 100) $Aspect = 0.6 Local $nCount, $nTotal = 0, $angleStart, $angleSweep, $X, $Y Local $pieLeft = $Pie_Margin Local $pieTop = $PIE_AREA / 2 - ($Pie_Diameter / 2) * $Aspect Local $pieWidth = $Pie_Diameter, $pieHeight = $Pie_Diameter * $Aspect, $hPath ; Total up the values For $nCount = 0 To UBound($Percentage) - 1 $nTotal += $Percentage[$nCount] Next ; Set the fractional values For $nCount = 0 To UBound($Percentage) - 1 $Percentage[$nCount] /= $nTotal Next ; Make sure we don't over-rotate $rotation = Mod($rotation, 360) ; Clear the graphics buffer _GDIPlus_GraphicsClear($hBuffer, 0xFFF0F0F0) ; Set the initial angles based on the fractional values Local $Angles[UBound($Percentage) + 1] For $nCount = 0 To UBound($Percentage) If $nCount = 0 Then $Angles[$nCount] = $rotation Else $Angles[$nCount] = $Angles[$nCount - 1] + ($Percentage[$nCount - 1] * 360) EndIf Next ; Adjust the angles based on the aspect For $nCount = 0 To UBound($Percentage) $X = $Pie_Diameter * Cos($Angles[$nCount] * $PI / 180) $Y = $Pie_Diameter * Sin($Angles[$nCount] * $PI / 180) $Y -= ($Pie_Diameter - $pieHeight) * Sin($Angles[$nCount] * $PI / 180) If $X = 0 Then $Angles[$nCount] = 90 + ($Y < 0) * 180 Else $Angles[$nCount] = ATan($Y / $X) * 180 / $PI EndIf If $X < 0 Then $Angles[$nCount] += 180 If $X >= 0 And $Y < 0 Then $Angles[$nCount] += 360 $X = $Pie_Diameter * Cos($Angles[$nCount] * $PI / 180) $Y = $pieHeight * Sin($Angles[$nCount] * $PI / 180) Next ; Decide which pieces to draw first and last Local $nStart = -1, $nEnd = -1 For $nCount = 0 To UBound($Percentage) - 1 $angleStart = Mod($Angles[$nCount], 360) $angleSweep = Mod($Angles[$nCount + 1] - $Angles[$nCount] + 360, 360) If $angleStart <= 270 And ($angleStart + $angleSweep) >= 270 Then $nStart = $nCount EndIf If ($angleStart <= 90 And ($angleStart + $angleSweep) >= 90) _ Or ($angleStart <= 450 And ($angleStart + $angleSweep) >= 450) Then $nEnd = $nCount EndIf If $nEnd >= 0 And $nStart >= 0 Then ExitLoop Next ; Draw the first piece _DrawPiePiece( $ahBrush, $ahPen,$hBuffer, $pieLeft, $pieTop, $pieWidth, $pieHeight, $PIE_DEPTH * (1 - $Aspect), $nStart, $Angles) ; Draw pieces "to the right" $nCount = Mod($nStart + 1, UBound($Percentage)) While $nCount <> $nEnd _DrawPiePiece( $ahBrush, $ahPen,$hBuffer, $pieLeft, $pieTop, $pieWidth, $pieHeight, $PIE_DEPTH * (1 - $Aspect), $nCount, $Angles) $nCount = Mod($nCount + 1, UBound($Percentage)) WEnd ; Draw pieces "to the left" $nCount = Mod($nStart + UBound($Percentage) - 1, UBound($Percentage)) While $nCount <> $nEnd _DrawPiePiece( $ahBrush, $ahPen,$hBuffer, $pieLeft, $pieTop, $pieWidth, $pieHeight, $PIE_DEPTH * (1 - $Aspect), $nCount, $Angles) $nCount = Mod($nCount + UBound($Percentage) - 1, UBound($Percentage)) WEnd ; Draw the last piece _DrawPiePiece( $ahBrush, $ahPen,$hBuffer, $pieLeft, $pieTop, $pieWidth, $pieHeight, $PIE_DEPTH * (1 - $Aspect), $nEnd, $Angles) ; Now draw the bitmap on to the device context of the window _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) EndFunc ;==>_DrawPie Func _DrawPiePiece( $ahBrush, $ahPen, $hGraphics, $iX, $iY, $iWidth, $iHeight, $iDepth, $nCount, $Angles) Local $hPath, $fDrawn = False Local $iStart = Mod($Angles[$nCount], 360), $iSweep = Mod($Angles[$nCount + 1] - $Angles[$nCount] + 360, 360) ; Draw side $hPath = _GDIPlus_PathCreate() If $iStart < 180 And ($iStart + $iSweep > 180) Then _GDIPlus_PathAddArc($hPath, $iX, $iY, $iWidth, $iHeight, $iStart, 180 - $iStart) _GDIPlus_PathAddArc($hPath, $iX, $iY + $iDepth, $iWidth, $iHeight, 180, $iStart - 180) _GDIPlus_PathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $ahBrush[$nCount][1]) _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $ahPen[$nCount]) $fDrawn = True EndIf If $iStart + $iSweep > 360 Then _GDIPlus_PathAddArc($hPath, $iX, $iY, $iWidth, $iHeight, 0, $iStart + $iSweep - 360) _GDIPlus_PathAddArc($hPath, $iX, $iY + $iDepth, $iWidth, $iHeight, $iStart + $iSweep - 360, 360 - $iStart - $iSweep) _GDIPlus_PathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $ahBrush[$nCount][1]) _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $ahPen[$nCount]) $fDrawn = True EndIf If $iStart < 180 And (Not $fDrawn) Then _GDIPlus_PathAddArc($hPath, $iX, $iY, $iWidth, $iHeight, $iStart, $iSweep) _GDIPlus_PathAddArc($hPath, $iX, $iY + $iDepth, $iWidth, $iHeight, $iStart + $iSweep, -$iSweep) _GDIPlus_PathCloseFigure($hPath) _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $ahBrush[$nCount][1]) _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $ahPen[$nCount]) EndIf _GDIPlus_PathDispose($hPath) ; Draw top _GDIPlus_GraphicsFillPie($hGraphics, $iX, $iY, $iWidth, $iHeight, $iStart, $iSweep, $ahBrush[$nCount][0]) _GDIPlus_GraphicsDrawPie($hGraphics, $iX, $iY, $iWidth, $iHeight, $iStart, $iSweep, $ahPen[$nCount]) EndFunc My not working code Display only the first time the pie expected, but when i toggle from ta1 to 2 then to 1 it doesn't appear again expandcollapse popup#include <GDIPlus.au3> #include <WinAPI.au3> #include <GUISlider.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <Date.au3> #include <Array.au3> ; Controls the size of the pie and also the depth Global Const $Pie_Diameter = 150 Global Const $Pie_Margin = 30; $Pie_Diameter * 0.025 Global Const $PIE_DEPTH = $Pie_Diameter * 0.2 Global Const $PIE_AREA = $Pie_Diameter + 2 * $Pie_Margin ;Random data for values and colours Global Const $NUM_VALUES = 3 Global $aChartValue [$NUM_VALUES] = [70,30,10] Global $aChartColour [$NUM_VALUES] = [0xFF5555, 0x55FF55, 0x5555FF] ;[$NUM_VALUES] Global Const $PI = ATan(1) * 4 ; Start GDI+ _GDIPlus_Startup() ; Create the brushes and pens Global $ahBrush[$NUM_VALUES][2], $ahPen[$NUM_VALUES] For $i = 0 To $NUM_VALUES - 1 $ahBrush[$i][0] = _GDIPlus_BrushCreateSolid(BitOR(0xff000000, $aChartColour[$i])) $ahBrush[$i][1] = _GDIPlus_BrushCreateSolid(BitOR(0xff000000, _GetDarkerColour($aChartColour[$i]))) $ahPen[$i] = _GDIPlus_PenCreate(BitOR(0xff000000, _GetDarkerColour(_GetDarkerColour($aChartColour[$i])))) Next ;Create the GUI with sliders to control the aspect, rotation, style and hole size (for donuts) Global $hMainGUI = GUICreate("Pie Chart", $PIE_AREA + 200, $PIE_AREA + 200, Default, Default) GUISetState ( @SW_SHOW, $hMainGUI) ; Child GUI1 $hChild1 = GUICreate("", 370, 215, 15, 40, BitOr($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $hMainGUI) GUICtrlSetBkColor(-1, 0xEE8844) ;$nGraphic1 = GuiCtrlCreateGraphic(100, 100, 100,100) GUISetState ( @SW_SHOW, $hChild1) ; Child GUI2 $hChild2 = GUICreate("", 370, 215, 15, 40, BitOr($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $hMainGUI) GUISetBkColor(0x887788) ;$nGraphic2 = GuiCtrlCreateGraphic(100, 100, 100, 100) GUISwitch($hMainGUI) $nTab = GUICtrlCreateTab(10, 10, 400, 300) $nTabitem1 = GUICtrlCreateTabItem("Tab1") $nTabitem2 = GUICtrlCreateTabItem("Tab2") GUICtrlCreateTabItem("") GUICtrlSetState($nTabitem1, $GUI_SHOW) ; Set up GDI+ ;Global $hDC = _WinAPI_GetDC($hChild2) ;Global $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hChild2) Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND ( $hChild1 ) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($PIE_AREA, $PIE_AREA, $hGraphics) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) _DrawPie($Pie_Margin, $PIE_DEPTH, $PIE_AREA, $Pie_Diameter, $ahBrush, $ahPen, $hGraphics, $hBitmap, $hBuffer, $PI, $aChartValue, 0.6, 0, False, 200 ) ;_DrawPie ( $aChartValue, 0.6, 0, False, 200 ) ; Wait until the user quits While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop Case $nTab Switch GUICtrlRead($nTab) Case 0 GUISetState(@SW_HIDE, $hChild2) GUISetState(@SW_SHOW, $hChild1) Case 1 GUISetState(@SW_HIDE, $hChild1) GUISetState(@SW_SHOW, $hChild2) EndSwitch EndSwitch Sleep ( 10 ) WEnd ; Release the resources For $i = 0 To UBound($aChartColour) - 1 _GDIPlus_PenDispose($ahPen[$i]) _GDIPlus_BrushDispose($ahBrush[$i][0]) _GDIPlus_BrushDispose($ahBrush[$i][1]) Next _GDIPlus_GraphicsDispose($hBuffer) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) ;_WinAPI_ReleaseDC($hMainGUI, $hDC) ; Shut down GDI+ _GDIPlus_Shutdown() ;Done Exit Thank to any skilled GDI+ helper Regards Edited February 24, 2020 by Ebola57 Link to comment Share on other sites More sharing options...
Zedna Posted February 24, 2020 Share Posted February 24, 2020 Look here for answer Ebola57 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Ebola57 Posted February 24, 2020 Author Share Posted February 24, 2020 Thank you very much Zedna Learnt of a bit about redrawing graphic/bitmap In my case this code is the key while toggling tab _WinAPI_RedrawWindow($hChild1, 0, 0, $RDW_UPDATENOW) _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) 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