Jump to content

Graphic Refresh Mystery ?


jennico
 Share

Recommended Posts

hi there,

when you run my example you will notice that the program (or the graphic?) accelerates immensely when you keep moving the mouse over the gui. (watch the count !)

What's the reason for that behaviour and could this fact be used to speed up graphic refreshs ?

Dim $x=Round((@DesktopWidth-10)/2),$y=Round((@DesktopHeight-20)/2),$srt,$cnt,$stp=1,$dir
$GUI=GUICreate(" Graphic Example",@DesktopWidth-10,@DesktopHeight-20)
GUISetState()
$pos=WinGetClientSize("")
GUICtrlCreateGraphic(0,0,$pos[0],$pos[1])
GUICtrlSetGraphic(-1,8,0x35229F);$GUI_GR_COLOR
GUICtrlSetGraphic(-1,18,$x,$y);$GUI_GR_PIXEL
While 1
    $msg=GUIGetMsg()
    If $msg=-3 Then Exit
    $cnt+=1
    $srt+=1
    GUICtrlSetGraphic(-1,8,0x35229F)
    If Random(0,1)<.3 Then GUICtrlSetGraphic(-1,8,0xFFFF00)
    If $dir=0 Then $x+=1
    If $dir=1 Then $y-=1
    If $dir=2 Then $x-=1
    If $dir=3 Then $y+=1
    GUICtrlSetGraphic(-1,18,$x,$y)
    If $srt=$stp Then
        $srt=0
        $dir+=1
        If $dir=4 Then $dir=0
        If $dir=0 Or $dir=2 Then $stp+=1
        If WinActive($GUI) Then GUICtrlSetGraphic(-1,22,$x,$y);$GUI_GR_REFRESH
        WinSetTitle($GUI,""," Prime Cubic Distribution  -  "&$cnt)
    EndIf
WEnd

or is something bad in my syntax ?

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

I don't remember exactly why but I think it was that somehow GUIGetMsg() reacts to mouse movement.

But if you only want it to be faster you should remove GUIGetMsg() since it sleeps the script when there is no messages. Try OnEventMode, it will be much faster without sleeps.

Edited by AdmiralAlkex
Link to comment
Share on other sites

hmmm, i got it myself.

it's guigetmsg() which slows the script down. guess that is what is meant by "idles the cpu".

Opt("GUIOnEventMode",1)
Dim $x=Round((@DesktopWidth-10)/2),$y=Round((@DesktopHeight-20)/2),$srt,$cnt,$stp=1,$dir
$GUI=GUICreate(" Graphic Example",@DesktopWidth-10,@DesktopHeight-20)
GUISetState()
$pos=WinGetClientSize("")
GUICtrlCreateGraphic(0,0,$pos[0],$pos[1])
GUICtrlSetGraphic(-1,8,0x35229F);$GUI_GR_COLOR
GUICtrlSetGraphic(-1,18,$x,$y);$GUI_GR_PIXEL
GUISetOnEvent(-3,"_Exit")
While 1
    ;$msg=GUIGetMsg()
    ;If $msg=-3 Then Exit
    $cnt+=1
    $srt+=1
    GUICtrlSetGraphic(-1,8,0x35229F)
    If Random(0,1)<.3 Then GUICtrlSetGraphic(-1,8,0xFFFF00)
    If $dir=0 Then $x+=1
    If $dir=1 Then $y-=1
    If $dir=2 Then $x-=1
    If $dir=3 Then $y+=1
    GUICtrlSetGraphic(-1,18,$x,$y)
    If $srt=$stp Then
        $srt=0
        $dir+=1
        If $dir=4 Then $dir=0
        If $dir=0 Or $dir=2 Then $stp+=1
        If WinActive($GUI) Then GUICtrlSetGraphic(-1,22,$x,$y);$GUI_GR_REFRESH
        WinSetTitle($GUI,""," Graphic Example  -  "&$cnt)
    EndIf
WEnd

Func _Exit()
    Exit
EndFunc

better use oneventmode. but is this valid for all kinds of scripts or only graphic controls ?

j.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

this was simultaneous posting.

i am a little bit shocked about the fact that guigetmsg slows down scripts. is this true with all kinds of scripts ?

how does guigetmsg() work then ?

j

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

If GUIGetMsg() doesn't return anything (is empty) then it does an internal Sleep(), the reason is that you could have a loop like this below without using much cpupower. I don't know why it is like this but it doesn't matter for me, I usually rewrite all my scripts to OnEventMode after a while since I find it easier to use and faster.

While 1
$msg=GUIGetMsg()
If $msg=-3 Then Exit
WEnd
Link to comment
Share on other sites

i prefer guigetmsg() because you cannot pass parameters thru guictrlsetonevent(). and, like above, the _Exit() funtion just with a single command looks stupid.

i think, what is true is: never use guigetmsg() in a main program loop, if you use it then only in a special loop, when the program really does not have to do anything.

i read that before, but i forgot it. i have to care about that from now on. :)

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

I don't agree, OnEventMode looks better since you can use one func for all events like this

Func _GuiEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_SECONDARYDOWN
    ;Some code
        Case $GUI_EVENT_SECONDARYUP
    ;Some code
        Case $GUI_EVENT_PRIMARYUP
    ;Some code
        Case $GUI_EVENT_RESTORE
    ;Some code
        Case $GUI_EVENT_CLOSE
    ;Some code
    EndSwitch
EndFunc
Edited by AdmiralAlkex
Link to comment
Share on other sites

well i don't see the advantage, since you can send all gui messages to the same function as well if you want.

but doesn't matter here. :)

Edit: you can also switch the Opt("GUIOnEventMode",1) within the script when needed.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...