Bug 139791 - [Win32] GC.fillPolygon paints at wrong coordinates when GDI+ is used
Summary: [Win32] GC.fillPolygon paints at wrong coordinates when GDI+ is used
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows All
: P3 normal with 2 votes (vote)
Target Milestone: 4.11 M3   Edit
Assignee: Niraj Modi CLA
QA Contact: Mike Marchand CLA
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks:
 
Reported: 2006-05-02 14:34 EDT by Florian Priester CLA
Modified: 2019-05-01 16:12 EDT (History)
6 users (show)

See Also:


Attachments
Screenshot (magnified) (2.15 KB, image/png)
2006-05-02 14:36 EDT, Florian Priester CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Priester CLA 2006-05-02 14:34:38 EDT
SWT-win32, v3231

When the advanced graphics mode is used, a call to GC.fillPolygon
in some cases results in the polygon being painted at coordinates
that are different from those seen in normal mode. Some of these
coordinates may lie slightly outside the region specified by the
point array. This seems wrong, or is it expected for some reason?

---

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class PolygonTest {
  public static void main(String[] args) {
    Display display = new Display();
    
    Shell shell = new Shell(display);
    shell.addListener(SWT.Paint, new Listener() {
      public void handleEvent(Event e) {
        int[] pts = {
          75, 100,
          100, 75,
          125, 100,
          100, 125};
        
        e.gc.drawLine(0, 100, 199, 100);
        e.gc.drawLine(100, 0, 100, 199);
        e.gc.drawRectangle(75, 75, 50, 50);
        
        e.gc.setAdvanced(true);
        
        e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED));
        e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLUE));
        
        e.gc.fillPolygon(pts);
        e.gc.drawPolygon(pts);
      }
    });
    
    Rectangle rect = shell.computeTrim(0, 0, 200, 200);
    shell.setSize(rect.width, rect.height);
    shell.open();
    
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    
    display.dispose();
  }
}
Comment 1 Florian Priester CLA 2006-05-02 14:36:18 EDT
Created attachment 40083 [details]
Screenshot (magnified)

fillPolygon and drawPolygon called with the same coordinates

Left:  Normal mode
Right: Advanced mode
Comment 2 Eclipse Genie CLA 2019-02-03 15:17:00 EST
New Gerrit change created: https://git.eclipse.org/r/136209
Comment 3 Niraj Modi CLA 2019-02-04 01:45:43 EST
(In reply to Eclipse Genie from comment #2)
> New Gerrit change created: https://git.eclipse.org/r/136209

Able to reproduce the problem, am looking into this patch.
Comment 4 Niraj Modi CLA 2019-02-04 09:35:44 EST
(In reply to Eclipse Genie from comment #2)
> New Gerrit change created: https://git.eclipse.org/r/136209

Above patch works, but seems like a hack.
Similar problem is solved in other GC functions, am working on an alternate patch.
Comment 5 Eclipse Genie CLA 2019-02-04 09:45:39 EST
New Gerrit change created: https://git.eclipse.org/r/136237
Comment 6 Niraj Modi CLA 2019-02-04 10:10:39 EST
(In reply to Eclipse Genie from comment #5)
> New Gerrit change created: https://git.eclipse.org/r/136237

Hi Mike,
Please test the updated patch set 3.
Comment 7 Niraj Modi CLA 2019-02-04 11:53:28 EST
Further tested https://git.eclipse.org/r/#/c/136237/ patch set 3. Found one breaking scenario(snippet modified from comment 0). Sharing my observations:
1. Apart from data.gdipXOffset correction we also need correction for data.gdipYOffset
2. Also the offsetCorrection value of 0.5f(instead of 1 pixel as suggested in patch set 3 above) is also sufficient for fixing this issue.

Will share an updated patch shortly
-------------------------------------------------------------------------------
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class PolygonTest {
  public static void main(String[] args) {
    Display display = new Display();
    
    Shell shell = new Shell(display);
    shell.addListener(SWT.Paint, new Listener() {
      public void handleEvent(Event e) {
        int[] pts = {
          77, 100,
          100, 77,
          125, 100,
          100, 125};
        
        e.gc.drawLine(0, 100, 199, 100);
        e.gc.drawLine(100, 0, 100, 199);
        e.gc.drawRectangle(75, 75, 50, 50);
        
        e.gc.setAdvanced(true);
        
        e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED));
        e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLUE));
        
        e.gc.fillPolygon(pts);
        e.gc.drawPolygon(pts);
      }
    });
    
    Rectangle rect = shell.computeTrim(0, 0, 200, 200);
    shell.setSize(rect.width, rect.height);
    shell.open();
    
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    
    display.dispose();
  }
}
Comment 9 Niraj Modi CLA 2019-02-04 12:20:51 EST
(In reply to Eclipse Genie from comment #8)
> Gerrit change https://git.eclipse.org/r/136237 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=796a41a7ac80115a4a90c80b42d2989134aed2ef

Changes merged to master, resolving now.
Comment 10 Niraj Modi CLA 2019-02-04 12:23:26 EST
Thanks Mike for your quick reviews and inputs!
Comment 11 Mike Marchand CLA 2019-02-04 12:24:14 EST
(In reply to Niraj Modi from comment #10)
> Thanks Mike for your quick reviews and inputs!

Glad to help, thank you Niraj!
Comment 12 Lars Vogel CLA 2019-02-04 13:50:00 EST
Thanks Mike and Niraj this will significantly improve the dark theme on windows.
Comment 13 Eclipse Genie CLA 2019-02-06 03:09:50 EST
New Gerrit change created: https://git.eclipse.org/r/136342
Comment 15 Niraj Modi CLA 2019-02-19 02:13:03 EST
Verified the fix in SWT and Eclipse in IBuild id: I20190218-1800 @Win7
Comment 16 Philipp Schn. CLA 2019-05-01 16:10:12 EDT
I had to create a bug ticket because of the bugfix: https://bugs.eclipse.org/bugs/show_bug.cgi?id=546898 -> look at: https://bugs.eclipse.org/bugs/attachment.cgi?id=278457