Recent

Author Topic: How to disable double buffering of TCustomControl with lclgtk2 ?  (Read 6703 times)

sainimu78

  • Full Member
  • ***
  • Posts: 117
How to disable double buffering of TCustomControl with lclgtk2 ?
« on: February 28, 2018, 07:11:34 pm »
How to disable double buffering of TCustomControl with lclgtk2 ?

Why TCustomControl.Canvas.Rectangle(50, 50, 100, 100); can't draw the shape immediately ?

Where the buffer will be painted ? I know on windows to draw a buffer to a client region using BitBlt. What functions are using in lclgtk2 ?

--------------------------------------------------------------------

I uploaded a simple project.
I'm trying to use X11 api to do custom paint on scn:TMyPanel.
The project shows my problems:
1. scn:TMyPanel can not paint on the correct region, it paint on the whole form but the client of scn:TMyPanel.
2. The painted region of scn:TMyPanel will be ereased after TMyPanel.Paint

---------------------------------------------------------------------
Conclusion

My problem:
I want to do completely custom painting on a TWinControl, I implemented custom painting in an overrided Paint procedure and I found that the painted region will be ereased after Paint no matter of setting Msg.Result = 1 for both WMPaint and WMEreaseBkgnd.
My efforts:
I write an equvalent code in lazarus mainly using x11 APIs to replace the third party lib functions and I uploaded the project.
My asking:
With my experience I can't find out where the code ereases the painted region, someone who is familiar with lclgtk2 or gtk2 gdk ... may help.
« Last Edit: March 02, 2018, 03:23:17 pm by sainimu78 »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #1 on: February 28, 2018, 10:19:53 pm »
Only class procedures can be called using a class type name. Canvas methods are not class procedures, they require some object instance to be prefixed to the call (not an object's type name).

e.g.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, Forms, Controls, Graphics;
  9.  
  10. type
  11.  
  12.   TTest = class(TCustomControl)
  13.   protected
  14.     procedure Paint; override;
  15.   public
  16.     constructor Create(AOwner: TComponent); override;
  17.   end;
  18.  
  19.   TForm1 = class(TForm)
  20.     procedure FormCreate(Sender: TObject);
  21.   private
  22.     test: TTest;
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. procedure TTest.Paint;
  33. begin
  34.   Canvas.Brush.Color := Color;
  35.   Canvas.Rectangle(ClientRect);
  36.   Canvas.Brush.Color := clBlue;
  37.   Canvas.Rectangle(50, 50, 100, 100);
  38. end;
  39.  
  40. constructor TTest.Create(AOwner: TComponent);
  41. begin
  42.   inherited Create(AOwner);
  43.  
  44.   SetInitialBounds(20, 20, 200, 200);
  45.   ParentColor := False;
  46. end;
  47.  
  48. procedure TForm1.FormCreate(Sender: TObject);
  49. begin
  50.   test := TTest.Create(Self);
  51.   test.Parent:=Self;
  52. end;
  53.  
  54. end.

sainimu78

  • Full Member
  • ***
  • Posts: 117
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #2 on: March 01, 2018, 04:19:35 am »

Yes that's right.

If I directly paint things on the TTest.Handle
Code: Pascal  [Select][+][-]
  1. procedure TTest.Paint;
  2. begin
  3.   pW := PGtkWidget(Self.Handle);
  4.   pH := gtk_get_window(pW);
  5.   pD := gdk_x11_get_drawable(pH);
  6.   ThirdPartyPaint(pD);//in this it will get x11 gc and paint on it.
  7. end;

I can see the changing happened immediately on the TTest, but the changing will be ereased after TTest.Paint. With lclgtk2 any ways to achieve painting completely by myself?


taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #3 on: March 01, 2018, 04:43:24 am »


Yes that's right.

If I directly paint things on the TTest.Handle
Code: Pascal  [Select][+][-]
  1. procedure TTest.Paint;
  2. begin
  3.   pW := PGtkWidget(Self.Handle);
  4.   pH := gtk_get_window(pW);
  5.   pD := gdk_x11_get_drawable(pH);
  6.   ThirdPartyPaint(pD);//in this it will get x11 gc and paint on it.
  7. end;

I can see the changing happened immediately on the TTest, but the changing will be ereased after TTest.Paint. With lclgtk2 any ways to achieve painting completely by myself?
have you tried to use canvas.handle instead of acquiring a new drawable surface? Keep in mind I have no idea how GTK works and no inclination to learn.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

sainimu78

  • Full Member
  • ***
  • Posts: 117
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #4 on: March 01, 2018, 05:23:01 am »
Maybe ok, but I never tried, because ThirdPartyPaint will create a gl render context on it. Canvas.Handle is no use here I think.

sainimu78

  • Full Member
  • ***
  • Posts: 117
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #5 on: March 01, 2018, 05:28:38 am »
Really need help, I don't know how to achieve this. I tried TCustomOpenGLControl , it doesn't work on arm-linux.

Despite other things, I think TWinControl should support painting completely by user. I reported this issue but no solution yet.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #6 on: March 01, 2018, 05:57:03 am »
Really need help, I don't know how to achieve this. I tried TCustomOpenGLControl , it doesn't work on arm-linux.

Despite other things, I think TWinControl should support painting completely by user. I reported this issue but no solution yet.

Maybe ok, but I never tried, because ThirdPartyPaint will create a gl render context on it. Canvas.Handle is no use here I think.
On windows I would write a custom handler procedure, to replace the default one, handle the paint message by calling the controls onpaint handler, and pass all other messages to the default. In general terms I would 
1) make sure that canvas.handle can not be used directly.
2) check to see if you can replace the canvas.handle with your own PD to avoid replacement.
3) dig in to the gtk2 units to see where and how it gets its drawing surface and see how to replace it with your own
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

sainimu78

  • Full Member
  • ***
  • Posts: 117
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #7 on: March 01, 2018, 06:26:53 am »
@ondrej, @juha, @mattias, @michl, @zeljko, @bart, @sakelsenmat, @blikblum, @jesss, @martin, @paul.

How to contact code authors in the forum?

These authors on svn may know what to do. I don't care the team whether fix it or not, I would like to do it. But I can't find where ereasing the client region.
I need a more useful advices.

What I'm trying to do is to find a working solution for both lclgtk2 and lclwin32 not just lclgtk2.
« Last Edit: March 01, 2018, 06:33:34 am by sainimu78 »

balazsszekely

  • Guest
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #8 on: March 01, 2018, 06:45:22 am »
@ondrej, @juha, @zeljko, @bart, @martin  regularly visit the forum, however you should send a mail to the "Lazarus mailing list": http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4467
  • I like bugs.
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #9 on: March 01, 2018, 10:13:09 am »
Really need help, I don't know how to achieve this. I tried TCustomOpenGLControl , it doesn't work on arm-linux.
It should be fixed then. What kind of problems does it have? Can you fix them? A patch would be accepted most likely.

Quote
Despite other things, I think TWinControl should support painting completely by user. I reported this issue but no solution yet.
I am no expert with graphics stuff but it looks like you want to bypass the whole LCL. If you want that then don't use LCL. Use the GTK2 API directly.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

sainimu78

  • Full Member
  • ***
  • Posts: 117
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #10 on: March 01, 2018, 12:44:09 pm »
https://pan.baidu.com/s/1qZJInsK
I put the sample proj on baidu disk, can you download it?

usage:
1. uncompress
2. cd board/proj_bin/please_help
3. export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
4. lazarus SceneTool.lpi
5. goto bookmark 1
6. you will see the painted region will be ereased.

balazsszekely

  • Guest
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #11 on: March 01, 2018, 12:50:27 pm »
@sainimu78
Download 55 Mb from an external page? Are you serious? Just attach here a simple test project(no binaries, just source). Use the "Attachments and other options" below.

sainimu78

  • Full Member
  • ***
  • Posts: 117
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #12 on: March 01, 2018, 01:06:17 pm »
@sainimu78
Download 55 Mb from an external page? Are you serious? Just attach here a simple test project(no binaries, just source). Use the "Attachments and other options" below.
I know that, I'm a full member you see that, but not now. I'm the one who asks for help.

Actually, the project of lazarus is simple, but it needs a third party to create a render context. Because I'm not familiar with x11 gtk gdk... things, frankly, I don't know how to write the equvalent in lazarus, but I will try and upload again.
« Last Edit: March 01, 2018, 01:11:56 pm by sainimu78 »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4467
  • I like bugs.
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #13 on: March 01, 2018, 01:16:55 pm »
@sainimu78, what kind of problems does TCustomOpenGLControl have on arm-linux?
IMO they should be fixed instead of trying some weird hacks bypassing LCL.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to disable double buffering of TCustomControl with lclgtk2 ?
« Reply #14 on: March 01, 2018, 01:51:09 pm »
Actually, the project of lazarus is simple, but it needs a third party to create a render context. Because I'm not familiar with x11 gtk gdk... things, frankly, I don't know how to write the equvalent in lazarus, but I will try and upload again.

I don't see any "simple" project here. Without code and without knowledge of third party painter nobody can help you.
Probably you should override LM_PAINT message and set result to 1 , so gtk won't do any painting after you.

 

TinyPortal © 2005-2018