Hi Chris,
This is not really a 2D question, as you will see the same behavior
in AWT. The pen for drawing hangs conceptually to the right and
down from any given point. When you draw an outline shape, you get
extra lines to the right and bottom of the coordinate path you gave.
Fills, OTOH, fill the interior of the coordinate path. While your reversal
looks right ( and would draw in any event because it's now on top,
actually you are being fooled by the extra line adjacent to the very next
pixel. )
One way to prove this to yourself is to fill a rect with multiple colors
and decreasing sizes, then draw rectangles with the same
coordinates. This is another "one off" gotcha and is important to
understand when drawing, filling and erasing graphic areas.
See the awt.Graphics API doc:
------------Begin Quote--------------------
Coordinates are infinitely thin and lie between the pixels of the output
device. Operations which draw the outline of a figure operate by traversing
an infinitely thin path between pixels with a pixel-sized pen that hangs
down and to the right of the anchor point on the path. Operations which fill
a figure operate by filling the interior of that infinitely thin path.
Operations which render horizontal text render the ascending portion of
character glyphs entirely above the baseline coordinate.
The graphics pen hangs down and to the right from the path it traverses.
This has the following implications:
If you draw a figure that covers a given rectangle, that figure occupies one
extra row of pixels on the right and bottom edges as compared to filling a
figure that is bounded by that same rectangle.
If you draw a horizontal line along the same y coordinate as the baseline of
a line of text, that line is drawn entirely below the text, except for any
descenders.
------------End Quote--------------------
Joe Sam Shirah
Autumn Software
-----Original Message-----
From: Chris Roffler <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Thursday, July 01, 1999 5:19 PM
Subject: Re: [JAVA2D] drawing a rectangle
Sorry, my comments should have read :
In this scenario I expected the rectangle frame not to show at all.
However, the bottom edge and the right edge are displayed . Any Ideas ??
Thanks
Chris
chris roffler wrote:
>
> Trouble drawing a rectangle. Below is the code for drawing a rectangle
> and a filled rectangle (same rectangle)
> In this scenario the frame on the top and the left side of the rectangle
> does not show up.
> The fill operation 'over' draws the frame. When I switch the draw and
> fill sequence it's ok.
>
> Any ideas ? I am going n……
>
> Thanks
>
> Chris Roffler
> ---------------------------------------------
> import javax.swing.*;
> import java.awt.geom.*;
> import java.awt.*;
>
> public class Chris
> extends
> JPanel
> {
> Rectangle2D r;
>
> public Chris()
> {
> super();
>
> r = new Rectangle2D.Float(10,10, 100,3);
> setBackground(Color.white);
> }
>
> public void paint(Graphics g)
> {
> Graphics2D d2 =(Graphics2D)g;
>
> d2.setBackground(Color.white);
> super.paint(d2);
>
> d2.setColor(Color.black);
> d2.draw(r);
>
> d2.setColor(Color.white);
> d2.fill(r);
>
> System.out.println(r);
>
> }
> }
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".