View Issue Details

IDProjectCategoryView StatusLast Update
0038852LazarusLCLpublic2021-05-05 20:20
Reporterwp Assigned Towp  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Summary0038852: TGraphicControl draws Polygon relative to owner in gtk2 when Pen.style = psClear
DescriptionA control derived from TGraphicControl is not drawn correctly in gtk2 when a particular overload of the Polygon method is called with Pen.Style = psClear.
See forum discussion https://forum.lazarus.freepascal.org/index.php/topic,54329.msg404509.html#msg404509.
Steps To ReproduceThe attached project implements a simple descendant of TGraphicControl which draws two red rectangles inside its interior. The first one (left) is drawn by

    Canvas.Polygon([Point(20, 20), Point(80, 20), Point(80, 80), Point(20, 80)]);

the second one (right) is drawn by

  var
    P: Array[0..3] of TPoint;
  ...
    P[0] := Point(80, 20);
    P[1] := Point(140, 20);
    P[2] := Point(140, 80);
    P[3] := Point(80, 80);
    Canvas.Polygon(P, 4);

In the demo program the control is right-bottom-anchored to its containing form. When the form size is changed the control thus follows the right/bottom corner of the form and, of course, the inner rectangles are expected to follow the control. But only the second rectangle does this, the first rectangle remains stationary on the form.

It turned out that the state of the Pen.Style is critical for this issue. The error occurs when Pen.Style = psClear when the Polygon is drawn. Swithching Pen.Style to psSolid (by UNDEFining the define SHOW_BUG) also the first rectangle is painted as expected.
Additional InformationThe error occurs only on gtk2 widgetset. gtk3, qt5, win32 and cocoa are behaving correctly.
TagsNo tags attached.
Fixed in Revision65088
LazTarget-
WidgetsetGTK 2
Attached Files

Activities

wp

2021-05-04 12:30

developer  

gtk2_polygon.zip (3,714 bytes)

Anton Kavalenka

2021-05-04 13:28

reporter   ~0130750

can not reproduce with Lazarus 2.1 SVN

wp

2021-05-04 14:30

developer   ~0130754

Last edited: 2021-05-04 14:42

View 2 revisions

Sorry, zipped a wrong project...

Updated trunk on Ubuntu 20.10 and LMDE4 Debbie to r65083, and both clearly show the issue (but only on gtk2 widget set!)
gtk2_polygon-2.zip (2,000 bytes)

Anton Kavalenka

2021-05-04 16:19

reporter   ~0130756

This fixes problem
Canvas.Brush.Color := clRed;
  Canvas.Pen.Color:=clRed;
  Canvas.Pen.Style:=psSolid;
  // This call is in error
  Canvas.Polygon([Point(20, 20), Point(80, 20), Point(80, 80), Point(20, 80)]);

wp

2021-05-04 17:27

developer   ~0130757

This is a work-around, not a fix.

Anton Kavalenka

2021-05-05 14:25

reporter   ~0130763

A flawed logic
 
// create the PointsArray, which is a copy of Points moved by the DCOrigin
  // only if needed
  if (DevCtx.IsNullPen and (DevCtx.IsNullBrush or Winding)) then
    PointArray := nil
  else
 ....

Array should be created and offset regardless of winding because device context may belong to parent control (as in the case of TGraphicControl) or to the widget itself (TWinControl descendant)

Anton Kavalenka

2021-05-05 14:40

reporter   ~0130764

This may help
gtk2winapi.diff (517 bytes)   
Index: lcl/interfaces/gtk2/gtk2winapi.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2winapi.inc	(revision 65086)
+++ lcl/interfaces/gtk2/gtk2winapi.inc	(working copy)
@@ -6921,7 +6921,7 @@
 
   // create the PointsArray, which is a copy of Points moved by the DCOrigin
   // only if needed
-  if (DevCtx.IsNullPen and (DevCtx.IsNullBrush or Winding)) then
+  if (DevCtx.IsNullPen and (DevCtx.IsNullBrush {or Winding})) then
     PointArray := nil
   else
   begin
gtk2winapi.diff (517 bytes)   

wp

2021-05-05 20:20

developer   ~0130770

Thanks, good detective work!
I applied it, and the test programs that I have with the Winding parameter are still behaving correctly.

Issue History

Date Modified Username Field Change
2021-05-04 12:30 wp New Issue
2021-05-04 12:30 wp File Added: gtk2_polygon.zip
2021-05-04 13:28 Anton Kavalenka Note Added: 0130750
2021-05-04 14:30 wp Note Added: 0130754
2021-05-04 14:30 wp File Added: gtk2_polygon-2.zip
2021-05-04 14:42 wp Note Edited: 0130754 View Revisions
2021-05-04 16:19 Anton Kavalenka Note Added: 0130756
2021-05-04 17:27 wp Note Added: 0130757
2021-05-05 14:25 Anton Kavalenka Note Added: 0130763
2021-05-05 14:40 Anton Kavalenka Note Added: 0130764
2021-05-05 14:40 Anton Kavalenka File Added: gtk2winapi.diff
2021-05-05 20:20 wp Assigned To => wp
2021-05-05 20:20 wp Status new => resolved
2021-05-05 20:20 wp Resolution open => fixed
2021-05-05 20:20 wp Fixed in Revision => 65088
2021-05-05 20:20 wp LazTarget => -
2021-05-05 20:20 wp Widgetset GTK 2 => GTK 2
2021-05-05 20:20 wp Note Added: 0130770