Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

GuiControl flicker problem and test


  • Please log in to reply
7 replies to this topic
simpleminded
  • Guests
  • Last active:
  • Joined: --
Ive made a GUI to display statistics and im getting a flicker updating a picture tile in a way the manual suggests. On researching this flicker problem has been around for some time. Ive found threads such as This This This This as well as others, but none have a real solution or workaround on them.

Please help solve the flicker simply so me and the others that hit this problem can have flicker free gui pictures? One suggestion was that it could be solved with GDI but I dont know enough about that to make anything discrete.

Env: AHK_L, Win7 x64
Personal Abililty: little but improving, can handle small ahk projects, this is my first big gui.
Aim: My main project gui has a droplist with many choices, I wanted a picture tile for each one (like my cycle test) but the flickering as each tile changes with the droplist scrolling makes it look very scrappy.

When I asked about this people couldnt really understand and said post the code, which I couldnt because they dont have my stats files but ive now made this test script to show/isolate the problem. Run it and see, itll collect the 3 images it needs from the web itself. When pressed each test runs for 3 short cycles (with no error trapping so pls wait for them to complete).

Main Multi Control Test
#SingleInstance force
BGpic = L752307914.jpg
Tilepic = gearscolor.png
Tilepic2 = gearsgreyscale.png

;-------get images-----------
IfNotExist, L752307914.jpg
UrlDownloadToFile http://img.freecodesource.com/formspring-backgrounds/images/bg/L752307914.jpg, L752307914.jpg
IfNotExist, gearscolor.png
UrlDownloadToFile http://img2.imageshack.us/img2/8574/gearscolor.png, gearscolor.png
IfNotExist, gearsgreyscale.png
UrlDownloadToFile http://img2.imageshack.us/img2/6049/gearsgrayscale.png, gearsgreyscale.png

;-------gui frame------------
Gui, Add, Picture, vPic0 w280 h300 x1 y1, %BGpic%
Gui, Add, Picture, BackgroundTrans vPic1 w160 h160 x60 y100, %TilePic%

Gui, Add, Button, x10 y40 w80 vHideShow gHideShow, Hide and Show
Gui, Add, Button, x100 y10 w80 vContUpd gContUpd, Control Update
Gui, Add, Button, x190 y10 w80 vMoveOob gMoveOob, Move OOB 
Gui, Add, Button, x10 y10 w80 vCycling gCycling, Cycle Tile
Gui, Add, Button, x100 y40 w80 vResize gResize, Resize
Gui, Add, Button, x190 y40 w80 vHideUpdSh gHideUpdSh, Hid Upd Show
Gui, Show, w280 h300,
return

;------test buttons----------
HideShow:  ; Hides then shows the picture
Loop 3
	{
	sleep, 1000
	GuiControl, Hide ,Pic1
	sleep, 1000
	GuiControl, Show ,Pic1
	}
return

ContUpd:  ; direct update of a control
Loop 3
	{
	sleep, 1000
	GuiControl,,Pic1, %TilePic%
	}
return

MoveOob: ; Move picture off gui, update it there, bring it back
Loop 3
	{
	sleep, 1000
	GuiControl, Move ,Pic1 , -x500 -y500
	sleep, 1000
	GuiControl,,Pic1, %TilePic%
	sleep, 1000
	GuiControl, Move ,Pic1, x60 y100
	}
return

HideUpdSh:  ; hide update show (it even flickers when hidden)
Loop 3
	{
sleep 1000
GuiControl,Hide,Pic1
sleep 1000
GuiControl,,Pic1, %TilePic%
sleep 1000
GuiControl,Show,Pic1
	}
return

Resize:  ; shrink to nothing then resize
Loop 3
	{
sleep 1000
GuiControl,,Pic1,*w-2 *h-2 %TilePic%
sleep 1000
GuiControl,,Pic1,*w160 *h160 %TilePic%
	}
return

Cycling:  ; updating one over another, eg as in a picture for each droplist choice
Loop 3
	{
sleep 1000
GuiControl,,Pic1,%TilePic%
sleep 1000
GuiControl,,Pic1, %TilePic2%
	}
return

;-------------bye-------------------
Esc::ExitApp
GuiClose:
ExitApp


Smaller Single Test (Cycling Only, what i need)
#SingleInstance force
BGpic = L752307914.jpg
Tilepic = gearscolor.png
Tilepic2 = gearsgreyscale.png

;-------get images-----------
IfNotExist, L752307914.jpg
UrlDownloadToFile http://img.freecodesource.com/formspring-backgrounds/images/bg/L752307914.jpg, L752307914.jpg
IfNotExist, gearscolor.png
UrlDownloadToFile http://img2.imageshack.us/img2/8574/gearscolor.png, gearscolor.png
IfNotExist, gearsgreyscale.png
UrlDownloadToFile http://img2.imageshack.us/img2/6049/gearsgrayscale.png, gearsgreyscale.png

;-------gui frame------------
Gui, Add, Picture, vPic0 w280 h300 x1 y1, %BGpic%
Gui, Add, Picture, BackgroundTrans vPic1 w160 h160 x60 y100, %TilePic%
Gui, Add, Button, x10 y10 w80 vCycling gCycling, Cycle Tile
Gui, Show, w280 h300,
return

;------test button----------
Cycling:  ; updating one over another, eg as in a picture for each droplist choice
Loop 3
	{
sleep 1000
GuiControl,,Pic1,%TilePic%
sleep 1000
GuiControl,,Pic1, %TilePic2%
	}
return

;-------------bye-------------------
Esc::ExitApp
GuiClose:
ExitApp



See what i mean? Thanks a lot for any help.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
>>See what i mean? Thanks a lot for any help.
Not very often :)

clarity: 10
working test case : 10
ahk version info : 10
looked for answers in the forum : 10
provided forum references : 10
included ' in contractions : -6
registered user : 0 :cry: would be easier to chart your progress :wink:


I suggest that the problem can have several contributing factors:
1. graphics card speed & abilities
2. system speed and load
3. how fast you want to toggle between images
4. what method is used to show the images

In the rare cases where I saw flicker, it was that a rectangular section around the image was white for a brief instant.

So I tried adding 2 controls in the same location.
When I switched so that gearscolor.png was added later and therefore "on top" of gearsgreyscale.png, I haven't seen any flicker.

I added a section to change the image faster based on the mouse movement, and the fflicker sometimes appears
Here's the code

#SingleInstance force
BGpic = L752307914.jpg
Tilepic = gearscolor.png
Tilepic2 = gearsgreyscale.png

;-------get images-----------
IfNotExist, L752307914.jpg
UrlDownloadToFile http://img.freecodesource.com/formspring-backgrounds/images/bg/L752307914.jpg, L752307914.jpg
IfNotExist, gearscolor.png
UrlDownloadToFile http://img2.imageshack.us/img2/8574/gearscolor.png, gearscolor.png
IfNotExist, gearsgreyscale.png
UrlDownloadToFile http://img2.imageshack.us/img2/6049/gearsgrayscale.png, gearsgreyscale.png

;-------gui frame------------
Gui, Add, Picture, vPic0 w280 h300 x1 y1, %BGpic%

Gui, Add, Picture, BackgroundTrans vPic2 w160 h160 x60 y100, %TilePic2%
Gui, Add, Picture, BackgroundTrans vPic1 w160 h160 x60 y100, %TilePic%

Gui, Add, Button, x10 y10 w80 vCycling gCycling, Cycle Tile
Gui, Show, w280 h300,

; settimer, mouse_loc, 100 ; <------ enable change on mouse movement
return

;------test button----------
Cycling:  ; updating one over another, eg as in a picture for each droplist choice
Loop 10
   {
sleep 1000
GuiControl,show,Pic1
sleep 1000
GuiControl,hide,Pic1
   }
return

;-------------bye-------------------
Esc::ExitApp
GuiClose:
ExitApp

;-------- change the picture based on mouse movement -------

mouse_loc:
mousegetpos, x

tooltip
;tooltip %x% %prevx%
if prevx=%x%
return

y++
if y&1 ; odd or even
GuiControl,show,Pic1
else
GuiControl,hide,Pic1

prevx=%x%

return

f12::reload	; <---- easier to make changes and test


simpleminded
  • Guests
  • Last active:
  • Joined: --
Hi Leef_me, thanks for the input

"included ' in contractions : -6 " < im sorry i have no idea what this is

to answer
1) Fastish, I have a radeon 4850 due for an upgrade soon
2) quad core, low load
3) My droplist has > 30 items, user may scroll for as long as it takes to recognise the tile/dataset they want, so what, 5 or 6 a second max, down to 1.
4) this, a control update of some sort, but it flickers and even tho its going to be a free utility when im done, I dont even want to release it flickering like that.


Lastly your code, thank you so much for giving it a go but yes the flicker still appears, I tried doing the load behind and reveal thing too, but it uses the same controls on my test piece (show hide in this case).... the whole function appears to be unable to give smooth viewing :(

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
SetControlDelay applies to the Control Commands. Not sure if it also applies to the GuiControl commands.

Also look at SetBatchLines and maybe Priority to see if you can execute the script faster?

simpleminded
  • Guests
  • Last active:
  • Joined: --
thanks engunner, Ive experimented with SetControlDelay and SetBatchLines values from -1 up to 5000 and process priorities from realtime to low to see if anything changed (including all three at once) but sadly theres no improvement on the flickering :(


Solving this would be a tremendous help to others i think, in a world where guis are king, having one picture update over another is the natural way to change images on buttons, tiles, backgrounds etc, infact because of its wide application im a little surprised no one has tackled this from an ahk kernel point of view (not that i know much about that, i make ahk things to teach myself to program) but if the problem really is this hard to solve then maybe it could be added to one of the new branches as a wishlist item?

simpleminded
  • Guests
  • Last active:
  • Joined: --
a possible solution, based on a suggestion from Chris in an old thread posted further down (thanks leef). It has some drawbacks, but its better than before.


#SingleInstance force
BGpic = L752307914.jpg
Tilepic = gearscolor.png
Tilepic2 = gearsgreyscale.png

;-------get images-----------
IfNotExist, L752307914.jpg
UrlDownloadToFile http://img.freecodesource.com/formspring-backgrounds/images/bg/L752307914.jpg, L752307914.jpg
IfNotExist, gearscolor.png
UrlDownloadToFile http://img2.imageshack.us/img2/8574/gearscolor.png, gearscolor.png
IfNotExist, gearsgreyscale.png
UrlDownloadToFile http://img2.imageshack.us/img2/6049/gearsgrayscale.png, gearsgreyscale.png

;-------gui frame------------
Gui, Add, Picture, vPic0 w280 h300 x1 y1, %BGpic%
Gui, Add, Picture, BackgroundTrans vPic1 w160 h160 x60 y100, %TilePic%
Gui, Add, Button, x10 y10 w80 vCycling gCycling, Cycle Tile
Gui, Show, w280 h300,
return

;------test buttons----------
Cycling:  ; updating one over another, eg as in a picture for each droplist choice

Loop 3
	{
sleep 1000
SendMessage, 0xB, false 
GuiControl,,Pic1,%TilePic%
SendMessage, 0xB, true  ; Turn redrawing back on.
WinSet Redraw  ; Force the window to repaint.	
sleep 1000
SendMessage, 0xB, false 
GuiControl,,Pic1,%TilePic2%
SendMessage, 0xB, true  ; Turn redrawing back on.
WinSet Redraw  ; Force the window to repaint.	
	}
	
return

;-------------bye-------------------
Esc::ExitApp
GuiClose:
ExitApp




That does actually make the test piece work, however it has 2 bugs, one I can replicate on the test but the other i cannot atm.

The one i can replicate: if there is a webpage with linked graphics (such as the corner of this forum) or window controls such as buttons on the ahk manual, then that flashes through and breaks up the gui for the time it takes to refresh.

The one i cant yet: it makes the other controls on my main gui flash at the same time as the redraw, including several groupboxes and over 40 edit boxes with data. Lifes never predictable being a coder i see :D



As we see in the thread above, even after discussing it Chris described it as a "serious flaw" and said there would be a MoveFast no redraw control added, but sadly that never made the cut.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Sorry I can't offer any suggestions, but ...

Chris (...) said there would be a MoveFast no redraw [command] added, but sadly that never made the cut.

That wouldn't help you anyway, since you're not moving controls.

chudus
  • Members
  • 11 posts
  • Last active: Dec 14 2014 04:52 PM
  • Joined: 08 Jan 2013

Im not sure it will help someone, but i have the same problem here with fast update of the small picture "moving" by guicontrol ...

my solution is make another gui in same place with same picture ... you know ..something like 2 layers

when you refresh  (delete/create) cover picture there is always other one and background dont flicker throw ...