#include ; $GUI_DISABLE #include "SSLG.au3" #include ;Just some timing variables Global $iAvg = 0, $iAvg_Add = 0 Global $iCt = 0, $iCt_Add = 0 Global $iMax = 0, $iMin = 60000 ;Setup Global Const $Increments = 100 Global $UpdateIntervalMs = 100 Global $iSleep = 25 Global $bGenSamples = True Opt('GuiOnEventMode', 1) $GUI = GUICreate("GDI+ Scrolling Single Line Graph", 800, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_SYSMENU, $WS_MINIMIZEBOX)) OnAutoItExitRegister(_Exit) GUISetOnEvent(-3, _Exit) GUISetState() ;_SSLG_CreateGraph($iLeft, $iTop, $iWidth, $iHeight, $iY_Min, $iY_Max, $iIncrements, $iBackGround = Default) Global $Graph1 = _SSLG_CreateGraph(10, 10, -20, 300, 0, 100, $Increments) GUICtrlSetData(-1, "Click me to enable" & @CRLF & "Resize the window to your liking" & @CRLF & "Click Again for a randomized experience") GUICtrlSetOnEvent(-1, graph_) GUICtrlSetState(-1, BitOR(GUICtrlGetState(-1), $GUI_DISABLE)) _SSLG_ClearGraph($Graph1) ;Create already cleared the graph ;Only needed for the example ================================================== Global $Slider1 = GUICtrlCreateSlider(35, 350, 800 - 45, 40) GUICtrlSetLimit(-1, 100, 1) GUICtrlSetData(-1, $iSleep) GUICtrlSetOnEvent(-1, slider_) GUICtrlSetTip(-1, $iSleep) UpdateSpeed($iSleep) Global $Checkbox1 = GUICtrlCreateCheckbox("", 10, 350, 25, 25) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetOnEvent(-1, checkbox_) ;============================================================================== GUIRegisterMsg($WM_EXITSIZEMOVE, WM_EXITSIZEMOVE) ;Wait for first activation While BitAND(GUICtrlGetState($Graph1), $GUI_DISABLE) = $GUI_DISABLE Sleep(1000) WEnd AdlibRegister(Update, $UpdateIntervalMs) Local $i = 0, $t Local $y While 1 $t = TimerInit() If $bGenSamples Then ;_SSLG_AddSample($Graph1, $i) $y = Int(Sin($i / 30) * 40) + 45 _SSLG_AddSample($Graph1, $y) _SSLG_AddSample($Graph1, Random($y / 2, $y * 2)) For $j = 0 To Random(1, 10, 1) _SSLG_AddSample($Graph1, Random(0, 100)) Next Else For $j = 0 To 5 _SSLG_AddSample($Graph1) Next EndIf $iAvg_Add += TimerDiff($t) $iCt_Add += 1 Sleep($iSleep) $i += Random(1, 15, 1) If $i > 179 Then $i = 0 WEnd Func Update() Local $iErr, $iSamples Local $bCompress, $bFill Local $t = TimerInit() Static $i = 0 $i = $i + 1 If $i > 0 Then $bCompress = True $bFill = True Else $bCompress = True $bFill = True EndIf ;_SSLG_UpdateGraph($idSSLG, $bCompress = False, $bFill = False) If _SSLG_UpdateGraph($Graph1, $bCompress, $bFill) Then $iSamples = @extended Local $iT = TimerDiff($t) If $iT > $iMax Then $iMax = $iT If $iT < $iMin Then $iMin = $iT $iAvg += $iT $iCt += 1 If $iCt >= 1000 Then Exit EndIf If $i > 100 Then $i = -100 EndFunc ;==>Update Func UpdateSpeed($iSleepMs) ;Try to keep update interval in sync with sample generation $UpdateIntervalMs = $iSleepMs * 10 AdlibRegister(Update, $UpdateIntervalMs) EndFunc ;==>UpdateSpeed ;Callbacks ==================================================================== Func WM_EXITSIZEMOVE($hWnd, $Msg, $wParam, $lParam) _SSLG_SetResizeGraph($Graph1) Return $GUI_RUNDEFMSG EndFunc ;==>WM_EXITSIZEMOVE Func slider_() $iSleep = GUICtrlRead($Slider1) GUICtrlSetTip($Slider1, $iSleep) UpdateSpeed($iSleep) EndFunc ;==>slider_ Func checkbox_() $bGenSamples = (GUICtrlRead($Checkbox1) = $GUI_CHECKED) EndFunc ;==>checkbox_ Func graph_() ConsoleWrite("*Click*" & @CRLF) Local $iState = GUICtrlGetState($Graph1) If Not BitAND($iState, $GUI_DISABLE) Then Sleep(1000) GUICtrlSetData($Graph1, "Click me to enable") GUICtrlSetState($Graph1, BitOR($iState, $GUI_DISABLE)) Return Else Local $iY_Min = Random(0, 1, 1) Local $iY_Max = ($iY_Min - 1) * -100 $iY_Min *= 100 _SSLG_SetYRange($Graph1, $iY_Min, $iY_Max) GUICtrlSetData($Graph1, "") EndIf Local $iGrid = Random(-5, 50, 1) If $iGrid < 0 Then $iGrid = 0 GUICtrlSetState($Graph1, BitXOR($iState, $GUI_DISABLE)) ;_SSLG_SetSetSampleIndicator($idSSLG, $iLineColor = False, $iPenSize = Default) If Random(0, 1, 1) = 0 Then _SSLG_SetSetSampleIndicator($Graph1, 0xffFF0000, 2) Else _SSLG_SetSetSampleIndicator($Graph1, False) EndIf ;_SSLG_SetGrid($idSSLG, $iX_c, $iY_c, $iGridColor = Default, $iPenSize = Default) _SSLG_SetGrid($Graph1, $iGrid, $iGrid / 2) Local $iColor = Random(0x0, 0xFF, 1) + Random(0x0, 0xFF, 1) * 256 + Random(0x0, 0xFF, 1) * 65536 ;_SSLG_SetLine($idSSLG, $iLineColor, $iPenSize = Default, $iFillColor = Default) _SSLG_SetLine($Graph1, 0xFF00FF00, Random(1, 5, 1), $iColor) GUICtrlSetBkColor($Graph1, $iColor) EndFunc ;==>graph_ Func _Exit() AdlibUnRegister(Update) Local $sRes = StringFormat("Update: %dx Avg %0.2fMs\r\nMin %0.2fMs, Max %0.2fMs\r\n\r\nAdd: %dx Avg %0.2fMs\r\n", $iCt, ($iAvg / $iCt), $iMin, $iMax, $iCt_Add, ($iAvg_Add / $iCt_Add)) ConsoleWrite($sRes) MsgBox(0, @ScriptName, $sRes) OnAutoItExitUnRegister(_Exit) Exit EndFunc ;==>_Exit