Gui timer flickering

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dalborgo
Posts: 5
Joined: 15 May 2014, 17:18

Gui timer flickering

23 May 2014, 19:24

I implement a simple timer. There is a way to avoid its flickering?

Code: Select all


#SingleInstance
#Include Timer.ahk
Gui +AlwaysOnTop -MaximizeBox -Resize -MinimizeBox 
Gui, Add, Text, vClock center w230 yp+28, 00:00
Gui, Show, W260 H230, Tavoli
Timer("TEST",0)
Loop{
	msec:= Timer("TEST","E")	
        sec:=Floor(msec /1000)
	tim:= SecToHHMMSS(sec)
	GuiControl,, clock, % tim
	  
	Sleep 1000
}


SecToHHMMSS(Sec) {
	OldFormat := A_FormatFloat
    SetFormat, Float, 2.0
	Hrs  := Sec//3600/1
    SetFormat, Float, 02.0
	Min := Mod(Sec//60, 60)/1
	Sec := Mod(Sec,60)/1
	SetFormat, Float, %OldFormat%
	Return (Hrs ? Hrs ":" : "") Min ":" Sec
}


Thanks in advance
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: Gui timer flickering

24 May 2014, 15:51

When you post a script that relies on code not in your script,
please provide a reference to the code --> #Include Timer.ahk
http://ahkscript.org/boards/viewtopic.php?f=19&t=551

>>[is t]here is a way to avoid its flickering?

I can't see the flicker but I can make a suggestion that >might< help.

within the loop, you update the variable 'tim' and display that in the gui.
I would add an additional variable 'prev_tim' that was filled by the previous loop. So that 'tim' hasn't changed, the gui won't be updated.

tim:= SecToHHMMSS(sec)
if (prev_tim != tim)
GuiControl,, clock, % tim
prev_tim := tim

IMO, I would also change the script so that updating the gui isn't the only thing it must do. Instead of loop, I would use the command 'settimer' with a delay of 100ms. Which would have the script check approx 10 times per second for a needed update.
Also, the "sleep 1000" would not be needed.

With only a settimer, you would need to add #Persistent to your script.
dalborgo
Posts: 5
Joined: 15 May 2014, 17:18

Re: Gui timer flickering

24 May 2014, 18:34

Thank you for the advices.

I tried that but the result is the same.

I can't show that because when i make a registration (screencast) the text flick disapears on the video. it seems a sort of refresh rate problem.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Gui timer flickering

24 May 2014, 21:49

Use a 'ReadOnly Edit' instead of Text control.
My Scripts and Functions: V1  V2
dalborgo
Posts: 5
Joined: 15 May 2014, 17:18

Re: Gui timer flickering

25 May 2014, 09:57

I've found a workaround to solve it.

Following the line guide of Leefme, you must add a text colored as the background color.
It must be partially inside (x or y negative) the gui and must be the first thing the graphic engine draws at every cycle.

it will be the only element flashing but it's invisible couse its color.

the 'settimer' delay must be a low value.
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: Gui timer flickering

25 May 2014, 20:54

>>I've found a workaround to solve it.

To solve what?
It seem what you describe will add flicker instead of remove it.

If you want to show us the problem, then >you< post this script.
Do not make us have to re-create your problem from a description.

As far as using a low settimer value, why?

Please explain.
dalborgo
Posts: 5
Joined: 15 May 2014, 17:18

Re: Gui timer flickering

26 May 2014, 09:39

I can't see the flicker but I can make a suggestion that >might< help.
If you can't see it, maybe it's only my trouble relative to two monitors or something else.

Code: Select all

#SingleInstance
#Include Timer.ahk
Gui +AlwaysOnTop -MaximizeBox -Resize -MinimizeBox
Gui, Color, 000000
Gui, Font, s14 cblack, Verdana
Gui, Add, Text, vToResolve center w230 y-20, ()
Gui, Font, s24 cgray, Verdana
Gui, Add, Text, vClock center w230 yp+28, 00:00
Gui, Show, W260 H230, Tavoli
Timer("TEST",0)
#Persistent
SetTimer, cycle, 10
return
cycle:    


Loop{
    msec:= Timer("TEST","E")   
    sec:=Floor(msec /1000)
    tim:= SecToHHMMSS(sec)
    giuv:=Mod(msec, 1000)
    Gui, Font, cblack
    GuiControl,Font, ToResolve
    if (giuv == 0)   
        GuiControl,, clock, % tim     
}
return

SecToHHMMSS(Sec) {
    OldFormat := A_FormatFloat
    SetFormat, Float, 2.0
    Hrs  := Sec//3600/1
    SetFormat, Float, 02.0
    Min := Mod(Sec//60, 60)/1
    Sec := Mod(Sec,60)/1
    SetFormat, Float, %OldFormat%
    Return (Hrs ? Hrs ":" : "") Min ":" Sec
}
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: Gui timer flickering

26 May 2014, 13:35

I don't know that I reduce the flicker, but try these changes to your script.

Code: Select all

#SingleInstance
#Include Timer.ahk
Gui +AlwaysOnTop -MaximizeBox -Resize -MinimizeBox
Gui, Color, 000000
Gui, Font, s14 cblack, Verdana

Gui, Add, Text, vToResolve center w230 y-20, () ; why did 'dalborgo' have this line
;Gui, Add, Text, vToResolve center w230 y0, ()  ; dinno

Gui, Font, s24 cgray, Verdana
;WS_CLIPSIBLINGS (0x4000000)
Gui, Add, Text, vClock center -0x4000000 w230 yp+28, 00:00
; Gui, Add, Text, vClock center w230 yp+28, 00:00

;Gui, Show, W260 H230 x2400 y-200, Tavoli
Gui, Show, W260 H230 , Tavoli

Timer("TEST",0)
#Persistent
;SetTimer, cycle, 10 ; much too often
SetTimer, cycle, 100
return


cycle:   
;Loop{                               ; the loop makes the update happen continuously and very rapidly, bad idea
    msec:= Timer("TEST","E")   
    sec:=Floor(msec /1000)
    tim:= SecToHHMMSS(sec)
    giuv:=Mod(msec, 1000)  ; why?
if (prev_msec = msec)                ; the previous pass had the same value as this, don't bother updating
   return

;    Gui, Font, cblack
;    GuiControl,Font, ToResolve ; why are you updating the color of an unused control?
;    if (giuv == 0)   
   GuiControl, -Redraw, clock
        GuiControl,, clock, % tim     
   GuiControl, +Redraw, clock

prev_msec :=msec            ; this forwards the currrent value on to the next pass for comparison


;} ; donpt need or want the loop

return     ; normal end of a settimer subroutine

SecToHHMMSS(Sec) {
    OldFormat := A_FormatFloat
    SetFormat, Float, 2.0
    Hrs  := Sec//3600/1
    SetFormat, Float, 02.0
    Min := Mod(Sec//60, 60)/1
    Sec := Mod(Sec,60)/1
    SetFormat, Float, %OldFormat%
    Return (Hrs ? Hrs ":" : "") Min ":" Sec
}
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Gui timer flickering

26 May 2014, 21:27

Hey hey hey!.... Woah woah, don't forget to use these:
SetWinDelay, 0 and SetBatchLines, -1
Cheers
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: Gui timer flickering

27 May 2014, 04:51

joedf wrote:Hey hey hey!.... Woah woah, don't forget to use these:
SetWinDelay, 0 and SetBatchLines, -1
Cheers
And what will that do for the situation?
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Gui timer flickering

27 May 2014, 08:45

Well, it normally reduces flicker for me :P
It doesn't for you? :?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
william_ahk
Posts: 486
Joined: 03 Dec 2018, 20:02

Re: Gui timer flickering

23 Sep 2021, 19:48

joedf wrote:
26 May 2014, 21:27
Hey hey hey!.... Woah woah, don't forget to use these:
SetWinDelay, 0 and SetBatchLines, -1
Cheers
Thank you so much! SetWinDelay, 0 worked for me. Hope I know this earlier, I was trying things like adding another layer of text on top in the old threads! :facepalm:
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Gui timer flickering

23 Sep 2021, 21:45

@william_ahk Glad I could help! :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
william_ahk
Posts: 486
Joined: 03 Dec 2018, 20:02

Re: Gui timer flickering

24 Sep 2021, 01:32

@joedf I think this should be in the docs like under the GuiControl page as a note for flicker prevention :)
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Gui timer flickering

24 Sep 2021, 02:13

william_ahk wrote:
24 Sep 2021, 01:32
@joedf I think this should be in the docs like under the GuiControl page as a note for flicker prevention :)
You should check this out, it goes above and beyond the flicker reduction that those can do for you.

viewtopic.php?f=6&t=77668

The only issue is that it can't be used in every case. If I remember it is only one pic control or one window or one... anyways, it's not for every case.
william_ahk
Posts: 486
Joined: 03 Dec 2018, 20:02

Re: Gui timer flickering

24 Sep 2021, 03:33

@Hellbent This is even better! Definitely should be in the docs too.
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Gui timer flickering

24 Sep 2021, 09:23

@Hellbent Nice! thanks for sharing. :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
Maestr0
Posts: 136
Joined: 05 Dec 2013, 17:43

Re: Gui timer flickering

04 Jan 2022, 16:36

Hellbent wrote:
24 Sep 2021, 02:13
william_ahk wrote:
24 Sep 2021, 01:32
@joedf I think this should be in the docs like under the GuiControl page as a note for flicker prevention :)
You should check this out, it goes above and beyond the flicker reduction that those can do for you.

viewtopic.php?f=6&t=77668

The only issue is that it can't be used in every case. If I remember it is only one pic control or one window or one... anyways, it's not for every case.
Thank you for sharing, I'd missed that post and it fixed what I was looking to fix.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 355 guests