bgrabitmap / bgracontrols

🆗 BGRA Controls is a set of graphical UI elements that you can use with Lazarus LCL applications.
https://bgrabitmap.github.io/bgracontrols/
182 stars 30 forks source link

BGRAVirtualScreen bug #165

Closed lainz closed 7 months ago

lainz commented 7 months ago

Hi, seems that BGRAVirtualScreen don't discard bitmap if the width of the control doesn't change... even if I want it to discard.

Check \bgracontrols\test\test_bgravirtualscreen_blur

@circular17 can you fix it?

lainz commented 7 months ago

Instructions: open the demo, and resize the window, the bottom virtual screen is resized and repainted correctly, but the static bgravirtualscreen at the top left are not repainted.

lainz commented 7 months ago

I noticed the bug is here:

procedure TCustomBGRAVirtualScreen.BGRASetSize(AWidth, AHeight: integer);
begin
  if (FBGRA <> nil) {and ((AWidth <> FBGRA.Width) or (AHeight <> FBGRA.Height))} then
  begin
    FBGRA.SetSize(AWidth, AHeight);
    RedrawBitmapContent;
    FDiscardedRect := EmptyRect;
  end;
end;

and ((AWidth <> FBGRA.Width) or (AHeight <> FBGRA.Height))

Commenting that code works. Still waiting for your input.

rchastain commented 7 months ago

Hi, seems that BGRAVirtualScreen don't discard bitmap if the width of the control doesn't change... even if I want it to discard.

Check \bgracontrols\test\test_bgravirtualscreen_blur

Hi. I don't see this example in the repository.

lainz commented 7 months ago

Hi, seems that BGRAVirtualScreen don't discard bitmap if the width of the control doesn't change... even if I want it to discard. Check \bgracontrols\test\test_bgravirtualscreen_blur

Hi. I don't see this example in the repository.

In dev-bgracontrols branch.

circular17 commented 7 months ago

Hi Leandro,

It is on purpose that BGRASetSize function doesn't change the content if the size is the same. Consider a button, unless it is resized, most of the time, we don't want to redraw it.

So please don't change BGRASetSize function this way. Are there any other approach, like calling DiscardBitmap function in the OnResize event of the form?

Regards

lainz commented 7 months ago

Hi, but you've tested the demo? It has DiscardBitmap on resize.

procedure TForm1.FormResize(Sender: TObject);
var
  i: integer;
  vs: TBGRAVirtualScreen;
begin
  for i:=0 to Self.ControlCount-1 do
  begin
    if (Self.Controls[i] is TBGRAVirtualScreen) then
    begin
      vs := (Self.Controls[i] as TBGRAVirtualScreen);
      vs.DiscardBitmap;
    end;
  end;
end;
circular17 commented 7 months ago

Ah ok, there was a misunderstanding. I thought you expected it to discard automatically on resize.

I haven't tested the project yet. From the code you've cited, it seems there is a call to DiscardBitmap that normally would redraw the content.

I will dig deeper into it.

lainz commented 7 months ago

The discard code on resize was wrong. I've fixed it, still buggy... now the bug is when resizing it don't update the bitmap, only when the resize is done..

circular17 commented 7 months ago

Hi Leandro,

Indeed, I came to the same conclusion, that it was cycling the main controls of the form, whereas the panels you're considering are inside the first virtual screen.

After that, I don't notice the problem of delayed update you're mentionning.

Regards

lainz commented 7 months ago

Maybe because I'm using Windows. Or because I'm using Lazarus 2.2.6

lainz commented 7 months ago

This is a video showing the problem, notice that the top left virtual screen are not updated until I release the mouse: https://github.com/bgrabitmap/bgracontrols/assets/4131395/146aac96-1d5d-41c2-9c86-309574dd206b

circular17 commented 7 months ago

Indeed, I can see the fixed panels are not update.

I tried it on Windows 11 and Lazarus 3.0. It is laggy but updates all panels.

lainz commented 7 months ago

Maybe we can add a boolean that triggers the update without checking width and height like I showed in previous comments.

Something like "optimized Discard" if set to true is like

If fbgra <> nil and optimized Discard and width and height...

By default is true. And if set to false it will discard anyways no matter the width and height.

That makes it run smoothly.

lainz commented 7 months ago

Oh I see, I will try on latest lazarus first.

lainz commented 7 months ago

Thanks, it works fine on latest Lazarus.

circular17 commented 7 months ago

Glad it is all well for you