Recent

Author Topic: [Solved] Trackbar flickering  (Read 3800 times)

Joanna

  • Hero Member
  • *****
  • Posts: 768
[Solved] Trackbar flickering
« on: March 05, 2024, 10:34:32 am »
Hi everyone
I have a ttrackbar control inside of a panel. When I resize it it flickers despite of the fact that I have set doublebuffered to true for both the trackbar and panel.

I searched the forums for previous thread about this and it seemed that it had been solved by adding csParentBackground to the control style. It didn't seem to stop flickering for me and on closer inspection i saw this.
Quote
csParentBackground = CSPARENTBACKGROUND

enum TControlStyleType.csParentBackground

C:\lazarus\lcl\controls.pp(257,5)

Description

[not implemented]

tells WinXP to paint the theme background of parent on controls background

 (Source)

Package

LCLBase

Does anyone have any other ideas on how to reduce trackball flickering ? it only gets worse when the panel with trackbar is nested inside of another control.

im using
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64
with windows 7
« Last Edit: March 11, 2024, 02:44:26 am by Joanna »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

440bx

  • Hero Member
  • *****
  • Posts: 4057
Re: Trackbar flickering
« Reply #1 on: March 05, 2024, 10:39:38 am »
Question: is the location of the trackbar constant ?  IOW, when resizing, does the trackbar need to move or stay in the same place ?
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Joanna

  • Hero Member
  • *****
  • Posts: 768
Re: Trackbar flickering
« Reply #2 on: March 05, 2024, 10:44:39 am »
The trackbar will stretch to fill its parent and as it stretches  the little notches under it become further apart.
So if I am resizing from right  the left side of trackball will not move
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

wp

  • Hero Member
  • *****
  • Posts: 11921
Re: Trackbar flickering
« Reply #3 on: March 05, 2024, 11:01:57 am »
No flickering here: Win11, Laz/main+FPC 3.2.2 (32 bit) or Laz 2.0.12/FPC 3.2.0 (32bit). But strong flicker in a VM with Win 7, it even flickers when the form size changes but the trackbar is not anchored/aligned and remains unchanged - I don't think that there's much you can do...
« Last Edit: March 05, 2024, 11:08:05 am by wp »

440bx

  • Hero Member
  • *****
  • Posts: 4057
Re: Trackbar flickering
« Reply #4 on: March 05, 2024, 11:19:57 am »
Disclaimer: I don't know how to do this in the LCL...

in a normal window procedure I'd set the result of processing the WM_ERASEBKGND  to a non-zero value (usually 1), telling Windows that the background has been erased.  Erasing the background is usually the source of flicker - since you have enabled double buffered painting it should be ok to lie about having erased the background - there is at least a chance this will eliminate the flicker.  I'd do that for _both_, the panel and the trackbar.

Just in case, WM_ERASEBKGND is documented at:
https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-erasebkgnd

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Joanna

  • Hero Member
  • *****
  • Posts: 768
Re: Trackbar flickering
« Reply #5 on: March 05, 2024, 01:22:43 pm »
Thanks for the answers.
I haven’t tried this on other operating systems yet hopefully it will work better. So I don’t want any windows dependencies.

The thing that concerns me more is
enum TControlStyleType.csParentBackground not being implemented. Why is it not implemented ? It was implemented for windows xp?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: Trackbar flickering
« Reply #6 on: March 05, 2024, 02:02:26 pm »
->  @440bx, fyi (->  as it’s Windows): I had sometimes such situation where I noticed that it had not much effect to ‘return 1’ (for True). Maybe because the control’s background itself already had an unwanted color. What did I want to do instead? To enforce a very early repaint in the desired color. Especially I had that when working with the dark mode: where I saw for some controls white flashes at resize (wm_maximize)  or at program’s start.
For the scenario: a Form, and an already existing component in it, i give a simple example snippet that might be easily adapted for other controls and colors.

Code: Pascal  [Select][+][-]
  1. unit MainUnit;
  2. ..
  3. type
  4.  
  5.   TSplitter = class(ExtCtrls.TSplitter)
  6.     procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;
  7. ..
  8.  
  9. implementation
  10.  
  11. ..
  12. procedure TSplitter.WMEraseBkgnd(var Message: TLMEraseBkgnd);
  13. var vRect : TRect;
  14. begin
  15.   if Not IsDarkModeEnabled then
  16.      exit;  // No need here in light mode
  17.   if Message.DC = 0 then Exit;
  18.   Brush.Color := $00353535;
  19.   vRect := Rect(0, 0, Width, Height);
  20.   FillRect(Message.DC, vRect, Brush.Reference.Handle);
  21. end;

Lazarus 3.2  FPC 3.2.2 Win10 64bit

Joanna

  • Hero Member
  • *****
  • Posts: 768
Re: Trackbar flickering
« Reply #7 on: March 05, 2024, 02:32:37 pm »
Another thing I forgot to mention is that the colors in my controls are not defined by windows color themes, I choose them from inside program.
Sometimes when the trackbar is nested more it will start to show as a black rectangle while resizing. {I use dark theme in windows }

d7_2_laz, how is procedure WMEraseBkgnd called? I noticed that it isn’t overriding ancestor method if there is any.
 What if parent.color was substituted for Brush.Color := $00353535;?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2079
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Trackbar flickering
« Reply #8 on: March 05, 2024, 02:40:31 pm »
how is procedure WMEraseBkgnd called?
You do not "call" it at all.

WM = Window Message
EraseBkgnd = the Identifier

So whenever the Window Message for EraseBkgnd flies over your TSplitter object, it will be executed automagical and overrides the original behavior.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Joanna

  • Hero Member
  • *****
  • Posts: 768
Re: Trackbar flickering
« Reply #9 on: March 05, 2024, 02:53:38 pm »
Identifier not found TLMEraseBkgnd
Does anyone know which unit has TLMEraseBkgnd?
« Last Edit: March 05, 2024, 02:57:41 pm by Joanna »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: Trackbar flickering
« Reply #10 on: March 05, 2024, 03:00:21 pm »
d7_2_laz, how is procedure WMEraseBkgnd called? I noticed that it isn’t overriding ancestor method if there is any.
 What if parent.color was substituted for Brush.Color := $00353535;?

I think it’s called by one ancestor of the control, here probably (without having debugged) controls.pp  (see image).
And it will be called, as KodeZwreg says, 'automagical' by intercepting the windows message loop by the anchestor. You simply hook into this message for to do something within.
But - as you suspected - it probably Windows-specific, don't know if there are equivalents on other OSses.

For the second question: you mean: substitute the hard coded element by any variable, eg. parent.color? Yes, of course, the essential element is only that the “unwanted color” doesn’t stay visible .. and visible .. and visible .. until the painting will come into effect. But will be applied as early as possible. I had very good results by that (need to add that the dark theme here is by metadarkstyle component).

Lazarus 3.2  FPC 3.2.2 Win10 64bit

Joanna

  • Hero Member
  • *****
  • Posts: 768
Re: Trackbar flickering
« Reply #11 on: March 05, 2024, 03:13:26 pm »
Identifier not found for isdarkmodeenabled and fillrect which units am I missing?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: Trackbar flickering
« Reply #12 on: March 05, 2024, 03:21:56 pm »
No no, as said this dark mode thing was only one use case example where some effects were particularly noticeable.
Here, “IsDarkModeEnabled” was from the metadarkstyle package; without this package, it should be removed of course.

"FillRect" ->  from unit Windows, OS-specific too.
« Last Edit: March 05, 2024, 03:27:07 pm by d7_2_laz »
Lazarus 3.2  FPC 3.2.2 Win10 64bit

Joanna

  • Hero Member
  • *****
  • Posts: 768
Re: Trackbar flickering
« Reply #13 on: March 05, 2024, 03:38:11 pm »
Code: Pascal  [Select][+][-]
  1. PROCEDURE TMY_TRACKBAR.WMERASEBKGND( VAR MESSAGE: TLMERASEBKGND) ;
  2.            var vRect : TRect;
  3. begin
  4.   //if Not IsDarkModeEnabled then
  5.   //   exit;  // No need here in light mode
  6.   if Message.DC = 0
  7.      then Exit;
  8.   Brush.Color := Parent.Color;   //       $00353535;
  9.   vRect := Rect(0, 0, Width, Height);
  10.   FillRect(Message.DC, vRect, Brush.Reference.Handle);
  11.  END;
it fails on line where vrect is assigned
TRACKBARS_UNIT_2024.pas(179,18) Fatal: Syntax error, ")" expected but "," found
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: Trackbar flickering
« Reply #14 on: March 05, 2024, 04:03:27 pm »
it fails on line where vrect is assigned

Oh, I remember such trap .. has something to do with the order of units within the use clause (there might be different TRect definitions around).
Try with direct assignment, eg. vrect.Left:=0;  vrect.Top:=0;   etc,
Lazarus 3.2  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018