Recent

Author Topic: TListBox flickers when scrolling (laz 1.4.0)  (Read 23009 times)

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
TListBox flickers when scrolling (laz 1.4.0)
« on: May 17, 2015, 03:05:54 pm »
Hi all!
I have the following problem - in one of my programs, I use TListBox component to show some data to the user - items are manually drawn (lbOwnerDrawFixed -> OnItemDraw), doublebuffered is set to true. Everything was fine in Lazarus 1.2.6, but now I have installed version 1.4.0 and the component flickers when scrolling. It seems the newly shown items are first drawn empty and then, a fraction of second later, redrawn in OnItemDraw event. As I said, it was not happening when compiled in Lazarus 1.2.6 (exactly the same code).
I have also noticed that this does not happen in TCheckListBox (in the same app).
Here is OnDrawItem handler (nothing interesting there I think):
Code: [Select]
procedure TfSupportedGamesForm.lbGamesListDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
const
  clSideBar       = $00EFEFEF;
  clSideBarBinded = clLime;
  clHorSplit      = clSilver;
  DefIconSize     = 32;
  LeftBarWidth    = 6;
var
  TempGameData: TGameData;
  WorkBitmap:   TBitmap;
  WorkRect:     TRect;
begin
TempGameData := ACCManager.GamesDataManager.GameData[Index];
WorkBitmap := TBitmap.Create;
try
  WorkBitmap.Width := Rect.Right - Rect.Left;
  WorkBitmap.Height := Rect.Bottom - Rect.Top;
  WorkRect := Classes.Rect(0,0,WorkBitmap.Width,WorkBitmap.Height);
  with WorkBitmap.Canvas do
    begin
      If (odSelected in State) then
        begin
          Brush.Color := clSideBar;
          Pen.Color := clSideBar;
        end
      else
        begin
          Brush.Color := lbGamesList.Color;
          Pen.Color := lbGamesList.Color;
        end;
      Rectangle(WorkRect);
      If fGameIsBinded and IsEqualGUID(fBindedGame,TempGameData.Identifier) then
        begin
          Brush.Color := clSideBarBinded;
          Pen.Color := clSideBarBinded;
        end
      else
        begin
          Brush.Color := clSideBar;
          Pen.Color := clSideBar;
        end;
      Rectangle(WorkRect.Left,WorkRect.Top,WorkRect.Left + LeftBarWidth,WorkRect.Bottom);
      Brush.Style := bsClear;
      Font := lbGamesList.Font;
      Font.Style := [fsBold];
      TextOut(WorkRect.Left + LeftBarWidth + DefIconSize + 6,
              WorkRect.Top + 4,TempGameData.Title);
      Font.Style := [];
      TextOut(WorkRect.Left + LeftBarWidth + DefIconSize + 6,
              WorkRect.Bottom - 4 - TextHeight(TempGameData.Info),TempGameData.Info);
      Pen.Color := clHorSplit;
      MoveTo(WorkRect.Left,WorkRect.Bottom - 1);
      LineTo(WorkRect.Right,WorkRect.Bottom - 1);
      Draw(WorkRect.Left + LeftBarWidth + 2,WorkRect.Top + (WorkRect.Bottom - WorkRect.Top - DefIconSize) div 2,
           ACCManager.GamesDataManager.GameIcons.GetIcon(TempGameData.Icon));
    end;
  lbGamesList.Canvas.Draw(Rect.Left,Rect.Top,WorkBitmap);
  If (odFocused in State) then lbGamesList.Canvas.DrawFocusRect(Rect);
finally
  WorkBitmap.Free;
end;
end;   
Full source of the program can be found here: https://github.com/ncs-sniper/AdjustableCruiseControl. This particular part of the program is in this unit https://github.com/ncs-sniper/AdjustableCruiseControl/blob/master/MainProgram/SupportedGamesForm.pas
Was the component changed? And is there any solution to this?

balazsszekely

  • Guest
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #1 on: May 17, 2015, 05:59:36 pm »
I see no flickering. Tested with 1.4 and 1.5(SVN version), XP and Win7(both 32 bit).

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #2 on: May 17, 2015, 06:05:19 pm »
Depends on what have you tested it on, if you have fast enough computer, the redraw is so fast you can't notice it. I have tried it on other systems than my primary, and it is definitely there.

balazsszekely

  • Guest
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #3 on: May 17, 2015, 06:44:22 pm »
I'm not saying it's not there, I just cannot reproduce it. :)
I did adjust my virtual machine settings(1 CPU, 512 MB RAM), still no flickering.
Anyway you can find TListBox source in .../lcl/stdctrls.pp and /lcl/include/customlistbox.inc. Compare 1.2.6 with 1.4 and see what is the difference if any.

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #4 on: May 17, 2015, 06:54:06 pm »
I have done a small test, I have put sleep(100) at the start of drawitem event handler, and there IS a difference in behavior.
In program compiled in 1.2.6, the handler is called BEFORE the listbox is visibly scrolled, so when new items are about to be shown, they are already rendered. But in program compiled in 1.4.0, the listbox is scrolled, the new items are rendered empty, and only then the handler is called. This redraw is causing it.
I have just tried clear installation in virtualbox, and it is the same, so my lazarus installation is not broken.
I will look into the sources, but right now, it seems to me like a bug.

balazsszekely

  • Guest
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #5 on: May 17, 2015, 07:07:51 pm »
Quote
I will look into the sources, but right now, it seems to me like a bug.
Yes, it's possible. If you find a bug, please report it here:
http://bugs.freepascal.org/main_page.php
Attach a small example where the issue is easily reproducible. Alternatively, you can create a patch if you like.

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #6 on: May 17, 2015, 09:26:36 pm »
For now, I have not found anything that could explain it. At least not in TListBox/TCustomListBox.
BTW is there any way how to step into LCL source while debugging?

EDIT 2015-05-18 00:21
It seems to be happening only in windows, when I do the same in linux (lubuntu 15.04 32bit) it works as expected.
« Last Edit: May 18, 2015, 12:23:22 am by ncs-sniper »

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #7 on: May 20, 2015, 02:32:25 am »
So, there is no one able to tell me what might be wrong? Only information I have got is that user GetMem does not see the flickering. That is nice and good for him, but in the end, totally useless information.
I have compiled the same source on the same system, 1.2.6 produced program where the flickering does not happen, and 1.4.0 produced program that flickers (both tried on WinXP 64b, WinXP 32b and Win7 64b). Don't tell me there was no change in the LCL!
BTW it is best visible when you rapidly scroll the listbox using scrollbar.
I am not some programming guru, so reading through the whole LCL in search for hidden errors is beyond me.

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #8 on: May 20, 2015, 03:09:49 am »
there have been changes in the LCL.

i have seen behavior changes in my program using DBLookupListbox between 1.2.6 and 1.4.
while not the same-same as you have experienced, it is somewhat in the same ball-park.

i have some idea that i may not be doing something not in the best way and will be working on re-writing that unit of my program.

you should be able to debug step through the LCL using F7/F8 - no workee for you?

you might want to post a small example that demos the problem, as suggested.
Lazarus Ver 2.2.6 FPC Ver 3.2.2
Windows 10 Pro 64-bit

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #9 on: May 20, 2015, 03:45:30 am »
As for stepping the LCL - I have recompiled it (the LCL) with -g, now it is possible. But there are no changes in the path I have investigated.
Writing an example is problematic. I have not been able to produce the same glitch reliably (happens only sometimes) in simple code. Probably because in simplest example, the redraw is so fast I can't notice it too. But I will surely try again.
For now, the whole project where it happens is available on github and there should be no problem for anyone to compile and try it.

balazsszekely

  • Guest
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #10 on: May 20, 2015, 05:07:16 am »
Quote
@ncs-sniper
That is nice and good for him, but in the end, totally useless information.
I don't know about the useless part, but at least I did download your program and I ran a few test just to help you!
Sorry but I cannot fight with an invisible enemy(again, I'm not saying the flickering is not there, I just cannot reproduce it).
Can somebody else confirm that flickering? Until then, here is what you can do:
1. The developers(some of them) are not very active on this forum. You can try to send a mail to Lazarus Mailing List(http://lists.lazarus.freepascal.org/mailman/listinfo). Unfortunately without a reliable example I  doubt they will be able to help you.
2. For now stay with 1.2.6
3. Replace TListBox with something else(VirtualStringTree, TreeView without buttons, lines, root).

Ps: Please stop complaining about not getting help. We all do this in our free time and there is more important issues than TListBox flickering.
« Last Edit: May 20, 2015, 06:32:59 am by GetMem »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #11 on: May 20, 2015, 11:10:24 am »
Just to add more "totally useless informtion": No flicker on my system (Win 7 64 bit, i5 processor, built-in graphics, Laz 1.5/fpc 2.6.4).

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #12 on: May 20, 2015, 04:22:28 pm »
Easy guys, I really DO appreciate any feedback. Fact that someone does not see my problem is something I can certainly work with, but common, you must know I does not move me any closer to a solution. I am also open to an option that something is wrong in my laz. installation. I just can't see what. When I compile the same source in fresh installation in virtualbox, the same happens.
I have considered staying with 1.2.6, but there are things I really like in 1.4.
As for replacing the component - I would like to keep it as simple as possible, but it might be a solution, I am just not there yet. I have moved from delphi to lazarus because I thought there will be less problems, and then this...
Yes, I will try to create some example. But I doubt it will be simple, not every problem manifests itself in simple situation.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #13 on: May 20, 2015, 04:36:27 pm »
Looking carefully, there is something like a flicker in the last line of the listbox when scrolling down, and in the first line when scrolling up. Is this what you mean? If not describe exactly what you are doing.
« Last Edit: May 20, 2015, 05:07:09 pm by wp »

ncs-sniper

  • Jr. Member
  • **
  • Posts: 53
Re: TListBox flickers when scrolling (laz 1.4.0)
« Reply #14 on: May 20, 2015, 05:09:09 pm »
You mean in last line of the shown items, or last item of entire listbox? EDIT - you have edited and answered it before I have finished this post :); yes, exactly that.
As I already wrote, when I scroll the listbox very quickly (both up and down), the items that were not visible and are about to be shown are not rendered (the ondraw... handler is not called) when such item is shown on the screen. It is first rendered empty (probably with background color, but I am not sure, have to try it) and only then the handler is called. In 1.2.6, the handler was called before the item have to be shown.
« Last Edit: May 20, 2015, 05:12:12 pm by ncs-sniper »

 

TinyPortal © 2005-2018