Recent

Author Topic: MainForm.Canvas.TextOut fails on gtk3 and customdrawn  (Read 1790 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 405
MainForm.Canvas.TextOut fails on gtk3 and customdrawn
« on: March 18, 2023, 10:51:37 am »
The following code works fine for gtk2 but fails for customdrawn and gtk3.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Application.MainForm.Canvas.TextOut(0,0,'TextOut');
  4. end;

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: MainForm.Canvas.TextOut fails on gtk3 and customdrawn
« Reply #1 on: March 18, 2023, 08:30:44 pm »
Pls open issue about gtk3, I'll take care of it.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: MainForm.Canvas.TextOut fails on gtk3 and customdrawn
« Reply #2 on: March 18, 2023, 10:16:30 pm »
The following code works fine for gtk2 but fails for customdrawn and gtk3.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Application.MainForm.Canvas.TextOut(0,0,'TextOut');
  4. end;
This does not look like very clever code to me anyway: A control such as the form must be able to repaint itself whenever the operating system requests it to do so. Even in cases where this code works it has the problem that the painted text will disappear when the OS requests a repaint at any time after the button click. Suppose the user drags the part of the form which displays the painted text off of the screen for some reason. When he drags the form back the text will be gone because the form does not know that it should paint it.

Many controls have an OnPaint event to control painting. Move the code into the OnPaint event handler of the form, set a flag that the user-defined text should be drawn and request a repaint of the form. This works - even on gtk3:

Code: Pascal  [Select][+][-]
  1. var
  2.   ShowUserText: Boolean = false;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. begin
  6.   ShowUserText := true;
  7.   Invalidate;
  8. end;
  9.  
  10. procedure TForm1.FormPaint(Sender: TObject);
  11. begin
  12.   inherited;
  13.   if ShowUserText then
  14.     Canvas.TextOut(0, 0, 'TextOut');
  15. end;

lagprogramming

  • Sr. Member
  • ****
  • Posts: 405
Re: MainForm.Canvas.TextOut fails on gtk3 and customdrawn
« Reply #3 on: March 19, 2023, 11:53:04 am »
@wp
Yes the example code is not clever, here is it's history. Customdrawn has many bugs and like the gtk2 LCLwidgetset in the old days some of them are related to painting. For example, in Linux, if you add a default TEdit on a form, you set the LCLwidgetset to customdrawn and you run the program, the default "Edit1" text will appear only after clicking the TEdit. So I've tried to compare the result of paint messages and I've noticed this similarity between customdrawn and gtk3, both of them being presented by Lazarus as "alpha" stage. The code is not clever but it shows a difference between what's shown in gtk3 and customdrawn vs. gtk2. By the way, if a LCLwidgetset has double buffered drawing, the erase might occur only when invalidate routine is called, right!?

@zeljko
I don't know if it's an issue for gtk3, probably it's not.

Looking at the title of the subject I have doubts is good enough.  :-[

 

TinyPortal © 2005-2018