Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Cannot fill and outline a half circle reliably


I cannot seem to fill and then outline a half circle using the arc functions on GC (fillArc(), drawArc()).
The drawArc does not consistently sweep the same region as fillArc(), probably because drawArc requires that the width and height be one less than with fillArc()

public static void main(String args[]){
        Display d = new Display();
        final Color red = new Color(d, 255,10,10);
        final Color yellow = new Color(d, 255, 255, 10);
        final Shell shell = new Shell(d);
        shell.setSize(400, 290);

        shell.addPaintListener(new PaintListener() {
                public void paintControl(PaintEvent e) {
                        e.gc.setBackground(red);
                        e.gc.fillArc(30,0,91,91,180,180);
                        e.gc.drawArc(30,0,90,90,180,180);
                       
                        e.gc.setBackground(yellow);
                        e.gc.fillArc(150,20,90,90,0,180);
                        e.gc.drawArc(150,20,89,89,0,180);
                }
        });

        shell.open();
        while (!shell.isDisposed())
                while (!d.readAndDispatch())
                        d.sleep();
}


The problem might be that OS.Pie takes ints, and one of the two dimension (fill or draw) will always be ODD.  So one of the two will be subject to integer rounding problems.

When GC generates x1, y1 and x2, y2 for the Pie function, could it generate these further away from the ellipse's center?  The OS might interpret the intersection of these lines with the ellipse better.
Or, is it possible to call API in the platform with doubles instead of ints?

I think there is probably an (x1, y1) and (x2, y2) that would give the desired results, but it might take some effort to find them.

Back to the top