Community
Participate
Working Groups
R3.5. GC.drawRectangle(x, y, 0, 0) should draw a point. Same if the arguments are passed in as rectangle to GC.drawRectangle(Rectangle). Snippet: /******************************************************************************* * Copyright (c) 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package p; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class Snippet { public static void main(String[] args) { Display display= new Display(); Shell shell= new Shell(display); shell.setLayout(new FillLayout()); final Composite composite= new Composite(shell, SWT.NONE); composite.setSize(10, 200); composite.addPaintListener(new PaintListener() { public void paintControl(PaintEvent event) { GC gc= event.gc; gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_RED)); Rectangle rect= new Rectangle(1, 1, 0, 0); gc.drawRectangle(rect); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
This is consistent on all platforms with advance on and off. I'd say this is by design...
>I'd say this is by design... What design? ;-) For me the Javadoc is the design and according to that a point is expected. If not, then please updated the Javadoc.
(In reply to comment #2) > What design? ;-) For me the Javadoc is the design and according to that a point > is expected. If not, then please updated the Javadoc. not every single detail can be in the doc... for example, all of these: GDK: gdk_draw_rectangle() Cairo: cairo_rectangle() Carbon: CGContextStrokeRect() Cocoa: NSBezierPath#appendBezierPathWithRect() win32 gdi: Rectangle() win32 gdi+: Graphics_DrawRectangle() have the same 'design', yet nothing is said about it the doc. I read our javadoc, not sure what part of it leads the user to believe that h=0 and w=0 should draw a point. GC#drawPoint() does that.
>I read our javadoc, not sure what part of it leads the user to believe that h=0 >and w=0 should draw a point. GC#drawPoint() does that. Note that h and w is not the amount of pixels that are drawn: according to the Javadoc the rectangle is from x to x+w ==> pixel count = w-1 y to y+h ==> pixel count = h-1 ==> x,y, w=0, h=0 should draw from x to x and y to y and hence result in a point.
If anything, I don't think it should draw a point (drawPoint() means a single pixel only), but rather a square the size of the current pen width.
And if width xor height is 0 it should to draw a line.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. If the bug is still relevant, please remove the "stalebug" whiteboard tag.