Page 1 of 1

Drawing position of primitives, text, ect.

Posted: Wed Mar 11, 2009 2:21 am
by Blart
The (x, y) coordinate you specify for drawing different primitives, text, and images seems rather inconsistent.

(x, y) specifies the upper-left corner of a rectangle. (x, y) specifies the center of a circle. (x, y) specifies the center of an image, unless you set the image's center manually. (x, y) specifies the bottom-left corner of a line of text (I haven't seen where wrapped text goes yet).

I can see how the way circles are handled makes sense (but what about ovals?!) but the rest feels a but confusing.

P.S. When drawing a line of text, what would I add to y to make it seem like I'm drawing from the top-left corner of the text? I tried adding the font size, but I'm not sure that's right or not.

Re: Drawing position of primitives, text, ect.

Posted: Wed Mar 11, 2009 6:52 am
by osuf oboys
Blart wrote:The (x, y) coordinate you specify for drawing different primitives, text, and images seems rather inconsistent.

(x, y) specifies the upper-left corner of a rectangle. (x, y) specifies the center of a circle. (x, y) specifies the center of an image, unless you set the image's center manually. (x, y) specifies the bottom-left corner of a line of text (I haven't seen where wrapped text goes yet).
Lower left corner of the first line.
I can see how the way circles are handled makes sense (but what about ovals?!) but the rest feels a but confusing.
The only two exceptions to the center rule are rectangles and text (unless I'm mistaken). For rectangles, I presume it makes sense for "pixel perfection".
P.S. When drawing a line of text, what would I add to y to make it seem like I'm drawing from the top-left corner of the text? I tried adding the font size, but I'm not sure that's right or not.
Subtract ...getFont():getHeight() from y. Also note that the distance the "same point" on two following lines of wrapped text is ...getFont():getHeight() * getFont():getLineHeight().