Recent

Author Topic: Certain controls don't draw correctly  (Read 2444 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Certain controls don't draw correctly
« on: May 01, 2021, 04:57:28 pm »
I'm having problems drawing a TPagecontrol.

Drop a TButton on a form.

Add this procedure

Code: Pascal  [Select][+][-]
  1. procedure BoxAround(aControl : TWinControl; aOffset : integer);
  2. var
  3.   Left : integer;
  4.   Top : integer;
  5.   Right : integer;
  6.   Bottom : integer;
  7.   aCanvas : TCanvas;
  8. begin
  9.   Top := aControl.Top - aOffset;
  10.   Left := aControl.Left - aOffset;
  11.   Bottom := (aControl.Top + aControl.Height) + (aOffset - 1);
  12.   Right := aControl.Width + aControl.Left + (aOffset - 1);
  13.  
  14.   aCanvas := (aControl.Parent as TForm).Canvas;
  15.  
  16.   aCanvas.Pen.Color := clBlack;
  17.   aCanvas.Pen.Width := 1;
  18.  
  19.   aCanvas.Line(Left, Top, Right, Top);
  20.   aCanvas.Line(Left, Top, Left, Bottom);
  21.   aCanvas.Line(Left, Bottom, Right, Bottom);
  22.   aCanvas.Line(Right, Bottom, Right, Top);
  23. end;  
  24.  

In the forms OnPaint event add

Code: Pascal  [Select][+][-]
  1. BoxAround(Button1, 1);
  2.  

the result is a box around the button. All OK.

Change the button for a TPagecontrol and you can see that the pagecontrol doesn't draw correctly (look at the bottom right corner).

What am I missing?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6892
Re: Certain controls don't draw correctly
« Reply #1 on: May 01, 2021, 05:17:47 pm »
are you talking about something like this ?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. Var
  3.   R:TRect;
  4. begin
  5.   R := PageControl1.BoundsRect;
  6.   InflateRect(R, 5,5);
  7.   With Form1.Canvas do
  8.    Begin
  9.     Pen.Color := clRed;
  10.     Pen.Style := psSolid;
  11.     Pen.Width := 4;
  12.     Frame(R);
  13.    end;
  14. end;                          
  15.  
  16.  
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Certain controls don't draw correctly
« Reply #2 on: May 01, 2021, 05:29:27 pm »
No, does the same thing. Look at the top and bottom corners. The spacing is different.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6892
Re: Certain controls don't draw correctly
« Reply #3 on: May 01, 2021, 05:49:25 pm »
Looks normal here..

Please post an image of what you have..
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Certain controls don't draw correctly
« Reply #4 on: May 01, 2021, 05:52:57 pm »
I see nothing wrong here either, but I'm on Linux-gtk2 x86_64. YMMV.

ETA: After looking more closely ... do you mean the top-right corner? That might be the "normal" artifact of lines not reaching the last point. You don't se it on the other lines because the one starts at the end (or start) of the other, but the top and right ones both end in the same "non-painted" point.

I didn't test with a button, though, to see if it's different ... :-[
« Last Edit: May 01, 2021, 06:00:47 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: Certain controls don't draw correctly
« Reply #5 on: May 01, 2021, 06:03:10 pm »
The bottom right corner looks fine (win64 Laz 2.1 and Laz 2.0.12)

The bottom top corner is missing a pixel (same as in lucamar's pic). But it's the same around a button.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Certain controls don't draw correctly
« Reply #6 on: May 01, 2021, 06:03:37 pm »
OK.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: Certain controls don't draw correctly
« Reply #7 on: May 01, 2021, 06:08:33 pm »
I think what you need is:
Code: Pascal  [Select][+][-]
  1.       aCanvas.Pen.Cosmetic := False;
  2.       aCanvas.Pen.EndCap := pecSquare;

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Certain controls don't draw correctly
« Reply #8 on: May 01, 2021, 06:19:55 pm »
No, the issue is the pixel gap, 2 instead of 1.   The control doesn't  fill it's bounds correctly.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1189
  • Professional amateur ;-P
Re: Certain controls don't draw correctly
« Reply #9 on: May 01, 2021, 06:24:42 pm »
Hey Lucamar,

ETA: [snip]

This has been bugging me to no end...

What is your meaning for ETA?

For me it's Estimated Time of Arrival and it's throwing me in a spin trying to guess what you mean by this acronym. LOL ;)

Cheers,
Gus

PS: I deeply apologise for the blatant off topic !!!
But the not knowing is just pulling me apart :)
« Last Edit: May 01, 2021, 06:28:28 pm by Gustavo 'Gus' Carreno »
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

jamie

  • Hero Member
  • *****
  • Posts: 6892
Re: Certain controls don't draw correctly
« Reply #10 on: May 01, 2021, 06:25:20 pm »
what you are seeing is a widget problem..

The PageControl is a windows control and the sheets within the page control have their own border hugging the main frame.

THat is most likely what you are seeing..

using more manually drawn controls may yield a different results like the TnoteBook joined with a TtabControl etc..

but I really don't think its worth the trip.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12800
Re: Certain controls don't draw correctly
« Reply #11 on: May 01, 2021, 06:36:35 pm »
I think he means the distance between the pagecontrol and the custom-drawn border which is different at the top and bottom, and at the left and at the right - see screenshot.

But Delphi does the same.

The pagecontrol is not drawn by Lazarus nor by Delphi, but by Windows. Therefore, there's nothing we can do against it. Except for this: if you really need uniform distance to your manual margin then take care of it when drawing your borders:
Code: Pascal  [Select][+][-]
  1. procedure BoxAroundAdj(aControl : TWinControl; aOffset : integer);
  2. var
  3.   Left : integer;
  4.   Top : integer;
  5.   Right : integer;
  6.   Bottom : integer;
  7.   aCanvas : TCanvas;
  8. begin
  9.   Top := aControl.Top - aOffset;
  10.   Left := aControl.Left - aOffset - 2;
  11.   Bottom := (aControl.Top + aControl.Height) + aOffset;
  12.   Right := aControl.Width + aControl.Left + aOffset - 1;
  13.  
  14.   aCanvas := (aControl.Parent as TForm).Canvas;
  15.  
  16.   aCanvas.Pen.Color := clBlack;
  17.   aCanvas.Pen.Width := 1;
  18.   aCanvas.Pen.Cosmetic := false;
  19.   aCanvas.Pen.EndCap := pecSquare;
  20.  
  21.   aCanvas.Line(Left, Top, Right, Top);
  22.   aCanvas.Line(Left, Top, Left, Bottom);
  23.   aCanvas.Line(Left, Bottom, Right, Bottom);
  24.   aCanvas.Line(Right, Bottom, Right, Top);
  25. end;

But you should be aware that these manual corrections will have to change probably when Microsoft once will decide to fix the painting of the pagecontrol, or do it differently... Better to keep your hands off of this. The best advice is: if you need a border accurate at the pixel level then use a completely customdrawn pagecontrol such as the one in ATFlatControls.
« Last Edit: May 01, 2021, 06:41:58 pm by wp »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: Certain controls don't draw correctly
« Reply #12 on: May 01, 2021, 06:41:37 pm »
No, the issue is the pixel gap, 2 instead of 1.   The control doesn't  fill it's bounds correctly.
Actually, no...

First, set the Forms color to some other value. So you can see what part is painted by whom.
You will see that the PageControl has some pixels on its outside that are colored like the form.

Before continuing....

Note that an aOffest = 1 => means the box has no gap at all.
With Offset = 1 you draw at "Left - 1" => no gap.
That actually works correct for the page control (ignore the top / see below).
It's the button that leaves a gap, where it should not.

It seems the button leaves a transparent pixel in it's WinControls space. I took my screen-grabber ("ShareX") and it detects both (button and PageControl) to be exactly in the drawn black border.

Back to the PageControl. If it has no pages, then there is a gap on the top. It seems windows still reserves 2 pixels, and keeps them transparent (the area for the tabs, is always transparent / put some tabs on, and you will see the form color, on the right to the tabs).


So to me it seems to all work.
But Windows seems to have its own rules how much of the space of a WinControl it actually paints on.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Certain controls don't draw correctly
« Reply #13 on: May 01, 2021, 06:44:13 pm »
Well that sucks.

{$IFDEF WINDOWS}
HopeForTheBest;
{$ENDIF}
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11164
  • Debugger - SynEdit - and more
    • wiki
Re: Certain controls don't draw correctly
« Reply #14 on: May 01, 2021, 06:53:12 pm »
Just one more thing, that came to (my) mind.

If you think about hardcoding adjustments for pagecontrols => the gaps may be theme depending (whatever windows theme you or the user selected), and maybe depend on the existence and/or version of a manifest.

I have not tested any of that....
 

 

TinyPortal © 2005-2018