Jump to content
Sign in to follow this  
Notniat

Problem with Line Graph

Recommended Posts

Notniat

Hey guys, so I wrote the following code to generate a graph dependant on your latency to a server, but I just can't seem to figure out how to clean old lines without disposing my whole window?

Thanks for the help guys

Regard

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Date.au3>

_GDIPlus_Startup()
$kPen = _GDIPlus_PenCreate()
$greenPen = _GDIPlus_PenCreate(0xFF667F00)
$redPen = _GDIPlus_PenCreate(0xFFE53C36)
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 20, 2)
$hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$Display = GUICreate("temptext", 200, 110, @DesktopWidth / 2, @DesktopHeight / 2, BitOR($WS_POPUP, $WS_CLIPCHILDREN), $WS_EX_LAYERED + $WS_EX_TOPMOST)
GUISetBkColor(0x010101, $Display)
;GUICtrlCreatePic("", 0, 0, 200, 24, -1, BitOR(0x00100000, 0x00000020))
GUISetState(@SW_SHOW, $Display)
_WinAPI_SetLayeredWindowAttributes($Display, 0x010101)
$tGraphic = _GDIPlus_GraphicsCreateFromHWND($Display)
$ttLayout = _GDIPlus_RectFCreate(50, 50, 50, 50)
$c = 0

$sLast = ''

$c = 25


;_GDIPlus_GraphicsFillRect($tGraphic,50,50,50,50)
Constants()

Func Constants()
_GDIPlus_GraphicsClear($tGraphic, 0xFF000FFF)
_GDIPlus_GraphicsDispose($tGraphic)
$tGraphic = _GDIPlus_GraphicsCreateFromHWND($Display)
$ttLayout = _GDIPlus_RectFCreate(50, 50, 50, 50)
_GDIPlus_GraphicsDrawLine($tGraphic, 0, 100, 300, 100, $kPen) ; Horisontal axes
_GDIPlus_GraphicsDrawLine($tGraphic, 25, 0, 25, 110, $kPen); Vertical axes
For $i = 0 To 900 Step 100
_GDIPlus_GraphicsDrawLine($tGraphic, 0, $i / 10, 300, $i / 10, $greenPen) ; Horisontal axes
_GDIPlus_GraphicsDrawString($tGraphic, $i, 0, 90 - ($i / 10 - 7))
Next

For $i = 45 To 295 Step 20
_GDIPlus_GraphicsDrawLine($tGraphic, $i, 0, $i, 110, $greenPen); Vertical axes
Next
Global $s = Ping("www.server.com", 1000) ;server IP goes here
EndFunc   ;==>Constants

While 1
$redPen = _GDIPlus_PenCreate(0xFFE53C36)
;_GDIPlus_GraphicsClear($tGraphic, 0xFF000FFF)
$ping = Ping("www.PathOfExile.com", 1000)
$e = _GDIPlus_GraphicsDrawLine($tGraphic, $c, 100 - $s / 10, $c + 20, 100 - $ping / 10, $redPen); Latency axes
$s = $ping
$c = $c + 20
;Sleep(1000)
If $c > 175 Then
$c = 25
_GDIPlus_PenDispose($redPen)
_GDIPlus_GraphicsClear($e)
_GDIPlus_GraphicsDispose($e)
EndIf
WEnd


_GDIPlus_PenDispose($kPen)
_GDIPlus_GraphicsDispose($tGraphic)
_GDIPlus_Shutdown()
Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites
Melba23

Notniat,

When you post code please use Code tags - put [autoit] before and [/autoit] after your posted code. Then you get a scrolling box as you can see above now I have added the tags. ;)

m23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
UEZ

I wrote some time ago this one here:

#include <GDIPlus.au3>
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()
Global $iW = 800, $iH = 400
Global $hGui = GUICreate("GDI+ Draw Graph", $iW, $iH)
GUISetBkColor(0x000000)
GUISetState()

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
Global $hPen = _GDIPlus_PenCreate(0xFFFFFF00)
Global $hPen2 = _GDIPlus_PenCreate(0xFFFFFFFF, 4)
Global $hPen_FG = _GDIPlus_PenCreate(0xFFFFFFFF, 2)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)

Global $iDensity = 0.25, $iAmplitudeMin = 100, $iAmplitudeMax = 300, $iPosX = 10
Global $aCoordinates[Int($iW * $iDensity)][2]
Global Const $iUB = UBound($aCoordinates)
$aCoordinates[0][0] = 1
Global $b1st = True

GUISetOnEvent(-3, "_Exit")

Do
    For $i = 1 To $iUB - 1

        DrawBg($hBackbuffer, $iPosX, 0, $iAmplitudeMin, $iW, $iAmplitudeMax - $iAmplitudeMin)

        $aCoordinates[$i][0] = $i / $iDensity
        $aCoordinates[$i][1] = Random($iAmplitudeMin, $iAmplitudeMax, 1)
        _GDIPlus_GraphicsDrawLines($hBackbuffer, $aCoordinates, $hPen)

;~      _GDIPlus_GraphicsFillEllipse($hBackbuffer, $aCoordinates[$i][0] - 4 , $aCoordinates[$i][1] - 4, 8, 8, $hBrush)
;~      _GDIPlus_GraphicsDrawLine($hBackbuffer, $aCoordinates[$i][0] - 1, $iAmplitudeMin, $aCoordinates[$i][0], $iAmplitudeMax, $hPen2)
        DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $hBackbuffer, "handle", $hPen2, "float", $aCoordinates[$i][0] - 2, "float", $iAmplitudeMin, "float", $aCoordinates[$i][0] - 2, "float", $iAmplitudeMax)

        _GDIPlus_GraphicsDrawLine($hBackbuffer, 0, $iAmplitudeMin, 0, $iAmplitudeMax, $hPen_FG)
        _GDIPlus_GraphicsDrawLine($hBackbuffer, 0, $iAmplitudeMax, $iW, $iAmplitudeMax, $hPen_FG)

        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, $iPosX, 0, $iW - $iPosX * 2, $iH)
        If $i < $iUB And $b1st Then
            $aCoordinates[0][0] = $i
        EndIf
        Sleep(100)
    Next
    $b1st = False
Until False

Func DrawBg(ByRef $hContext, $iLines, $iX, $iY, $iW, $iH)
    Local $hBrush_BG = _GDIPlus_BrushCreateSolid(0xFF004000)
    _GDIPlus_GraphicsFillRect($hContext, $iX, $iY, $iW, $iH, $hBrush_BG)
    Local $hPen_BG = _GDIPlus_PenCreate(0xFF00B000)
    Local $i, $fStep = $iH / ($iLines - 1)
    For $i = $iLines To $iH Step $fStep
        _GDIPlus_GraphicsDrawLine($hContext, 0, $iY + $i, $iW, $iY + $i, $hPen_BG)
    Next
    _GDIPlus_PenDispose($hPen_BG)
    _GDIPlus_BrushDispose($hBrush_BG)
EndFunc   ;==>DrawBg

Func _Exit()
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_PenDispose($hPen_FG)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    GUIDelete()
    Exit
EndFunc   ;==>_Exit

Func _GDIPlus_GraphicsDrawLines($hGraphics, $aPoints, $hPen)
    Local $iI, $iCount, $pPoints, $tPoints, $aResult
    $iCount = $aPoints[0][0]
    $tPoints = DllStructCreate("float[" & $iCount * 2 & "]")
    $pPoints = DllStructGetPtr($tPoints)
    For $iI = 1 To $iCount
        DllStructSetData($tPoints, 1, $aPoints[$iI][0], (($iI - 1) * 2) + 1)
        DllStructSetData($tPoints, 1, $aPoints[$iI][1], (($iI - 1) * 2) + 2)
    Next
    $aResult = DllCall($ghGDIPDll, "uint", "GdipDrawLines", "handle", $hGraphics, "handle", $hPen, "ptr", $pPoints, "int", $iCount)
    $tPoints = 0
    Return 1
EndFunc   ;==>_GDIPlus_GraphicsDrawLines

Maybe you can adapt it for your needs.

Br,

UEZ

Edited 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
trancexx

I have a visually impaired friend using, what I believe is called, NVDA screen reader and I clearly remember him teling me he has big problems here reading text within code tags. Apparently the reader can't read lines correctly because of the style tags. If that, or something similar is the reason Notniat that you don't use code tags when posting, then I apologize in behalf of the forum staff for moderator editing your post. Maybe send short PM to the moderator to avoid that in the future.

If it's just your ignorance then forget that I wrote this post and do what he says.

Thank you for understanding.

Edited by trancexx
  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Notniat

Hey guys, yeah thanks for the help, I apologise for not using the tags, and will defenatly use them in future :) Thanks for the helps

Share this post


Link to post
Share on other sites
Melba23

Notniat,

No need to apologise - but now you (and any other new members reading the thread) now know what to do in future. :)

We did have a visually impaired member a while ago who asked us not to use code tags when replying for the very reasons trancexx mentioned above, but as that was the only case I have come across in my time here I have the default position of suggesting the use of tags (and adding them for long code postings). I am sure that someone who requires the bare text for some good reason will soon tell me, as indeed happened in the case I mentioned. ;)

Glad you got your question answered. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Notniat

Hey UEZ, Thanks for your reply, it has helped in deed, just wondering in general, is there no way of clearing old line drawn?

Regards

Share this post


Link to post
Share on other sites
UEZ

No, it is not possible. You must clean the whole graphic handle and redraw the content again or you use several GUI layers for each e.g. pens but that is an overkill.

I can remember that on the old good C64 it was possible to move sprites without erasing the background.

But time has changed...

Br,

UEZ

Edited 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Notniat

Okay cool.. Thanks for your help man :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×