Recent

Author Topic: [Solved] Form Refreshing, flickering problem!  (Read 563 times)

loaded

  • Full Member
  • ***
  • Posts: 172
[Solved] Form Refreshing, flickering problem!
« on: December 27, 2020, 10:07:39 am »
Hi everyone
Simultaneously according to the user's mouse position on the form.
When I want to draw lines with anti-aliased bgrabitmap, the form flickers.
Regarding the topic, if I move functions to the onpaint routine of the form. The problem is getting better a bit.
My goal is to flip a multi-point polygon. At the beginning of the road, are there any different solution methods regarding the issue? I would like to learn.

The initial work I did;
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  2. var
  3.  bmp:TBGRABitmap;
  4. begin
  5.   Refresh;
  6.   bmp := TBGRABitmap.Create(clientWidth,ClientHeight);
  7.   bmp.CanvasBGRA.Pen.Width:=3;
  8.   bmp.CanvasBGRA.Pen.Color:=clred;
  9.   bmp.CanvasBGRA.Line(0,0,x,y);
  10.   bmp.Draw(canvas,0,0);
  11.   bmp.Free;
  12. end;
  13.  
« Last Edit: December 27, 2020, 03:55:15 pm by loaded »
Installing the spelling, google translate is used :)

speter

  • Full Member
  • ***
  • Posts: 160
Re: Form Refreshing, flickering problem!
« Reply #1 on: December 27, 2020, 12:56:56 pm »
I would guess that the flickering is because (a) you call refresh (which redraws the form using the onpaint event handler); and/or (b) you are drawing a bitmap then freeing it.

Hope this helps a bit. :)

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.10 / FPC 3.2.0 / Windows 10 (64bit)

circular

  • Hero Member
  • *****
  • Posts: 3666
    • Personal webpage
Re: Form Refreshing, flickering problem!
« Reply #2 on: December 27, 2020, 02:58:19 pm »
Hello @loaded

First good habit: always draw in OnPaint and call Invalidate (not Refresh) when you need to update.

That won't solve everything. One approach is to set the DoubleBuffer property to True.

Another one is to use TBGRAVirtualScreen form BGRAControls that will prevent flickering and store the bitmap for you. In this case, the function to call is DiscardBitmap and you draw in the OnRedraw event.
Conscience is the debugger of the mind

loaded

  • Full Member
  • ***
  • Posts: 172
Re: Form Refreshing, flickering problem!
« Reply #3 on: December 27, 2020, 03:55:00 pm »
speter, thank you very much for your answer. I had previous experience with your suggestions. But that wasn't the answer I was looking for.

circular, thank you very much for your answer. I experimented with BGRAVirtualScreen on recommendation.
The result really surprised me that I had the speed and refresh experience I wanted.
Thank you this is awesome.
I want to ask here in order not to cause pollution, I would be very glad if you answer. Even if you don't, thanks.
-Can the BGRAVirtualScreen floor be made transparent? Can we see and touch the controls under it?
-Can keyboard features be added like onkeypress, onkeydown?
Installing the spelling, google translate is used :)

circular

  • Hero Member
  • *****
  • Posts: 3666
    • Personal webpage
Re: [Solved] Form Refreshing, flickering problem!
« Reply #4 on: December 27, 2020, 04:16:58 pm »
If you need the background to be transparent, you can use TBGRAGraphicControl.

Yes you can add key handlers. If they are not published, visible in the object inspector, you still can defined handlers by assigning the OnKey* properties.

Some other remarks:
- TBGRAVirtualScreen is a container, you can put controls in it. TBGRAGraphicControl is not.
- On Retina display (MacOS) you can set the BitmapAutoscale property to False. In this case, the drawing surface will be twice as wide and high. So prefer to use BitmapWidth and BitmapHeight rather than the control's width and height to know the dimensions of the surface.
« Last Edit: December 27, 2020, 04:26:06 pm by circular »
Conscience is the debugger of the mind

loaded

  • Full Member
  • ***
  • Posts: 172
Re: [Solved] Form Refreshing, flickering problem!
« Reply #5 on: December 27, 2020, 04:58:11 pm »
circular , Thank you very much for sparing your precious time and providing useful information. Respects.
Installing the spelling, google translate is used :)

circular

  • Hero Member
  • *****
  • Posts: 3666
    • Personal webpage
Re: [Solved] Form Refreshing, flickering problem!
« Reply #6 on: December 27, 2020, 05:18:27 pm »
You're welcome  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018