I've identified a bug in Waba's Graphics.drawRect, and maybe also
SuperWaba's implementation of other graphics primitives. Presently,
Waba draws rectangles with one less pixel in width and one less pixel in
height than java.awt.Graphics does. This is a nasty bug because drawRect
is used *everywhere* in the Waba system, and fixing this bug may cause
quite a number of apps to draw one-off. What should we do here?
This is going to crop up again and again if we don't decide on a
strategy here: what about drawRoundRect? drawOval? drawArc? All of
these are correctly implemented by assuming a rectangle 1 larger and 1
higher than actually requested.
For example, the corrected code is:
public void drawRect(int x, int y, int width, int height)
{
int x2 = x + width; // got rid of a -1
int y2 = y + height; // got rid of a -1
drawLine(x, y, x2 - 1, y);
drawLine(x2, y, x2, y2 - 1);
drawLine(x2, y2, x + 1, y2);
drawLine(x, y2, x, y + 1);
}
In Java, the here are the actual boundaries. <=X means the X coordinate
of the leftmost pixel. >=X means the X coordinate of the rightmost
pixel. Etc.
Object <=X <=Y >=X >=Y
drawLine(x,y,x2,y2) x y x2 y2
drawRect(x,y,width,height) x y x+width y+height
OOPS! Waba draws >=X as x+width-1, and >=Y as y+height-1
fillRect(x,y,width,height) x y x+width-1 y+height-1
Other ones fyi:
drawRoundRect(x,y,width,
height,awidth,aheight) x y x+width y+height
fillRoundRect(x,y,width,
height,awidth,aheight) x y x+width y+height
drawOval(x,y,width,height) x y x+width y+height
fillOval(x,y,width,height) x+1 y+1 x+width-2 y+height-2
OOPS! This is *different* from drawRoundRect -- thus if you're using
drawRoundRect to do drawOval (in SuperWaba say), you're probably
off by one.
drawArc and fillArc perform similarly to drawOval/fillOval, though there
are some oddities with drawing the leftmost ray in Java (it doesn't get
filled, very weird).
|