IlvGraphic
. and boundingBoxIlvGraphic
. are fundamental
and should be defined jointly. public IlvRect boundingBox(IlvTransformer t)
drawrect
field. In order
to return the bounding box of the object, the boundingBox
method simply applies the transformer to the rectangle: class MyRectangle extends IlvGraphic { // The geometric rectangle that defines the object. final IlvRect drawrect = new IlvRect(); //constructor public MyRectangle(float x, float y, float width, float height) { drawrect.reshape(x, y, width, height); } // The bounding box method. public IlvRect boundingBox(IlvTransformer t) { //Copies the original rectangle to avoid its modification IlvRect rect = new IlvRect(drawrect); if (t != null) t.apply(rect); return rect; } }
boundingBox
is
a very important method. Since it is called very frequently, it must
be written in a highly optimized way. draw
, copy
and applyTransform
methods. For an example
of how this is done, see The ShadowEllipse class. draw
method is used to
draw the graphic object. The signature of the method is as follows:
public void draw(Graphics dst, IlvTransformer t)
dst
parameter is the destination Graphics
where the object is drawn. As in the boundingBox
method, the IlvTransformer
parameter is the 2D transformation matrix used to draw the object
in the drawing port. boundingBox
with the same transformation parameter).
This is why these two methods should be defined jointly. Graphics
class. If you
use Java™
2 and need to perform
Java2D™
drawings, you can cast
the dst
parameter in a Graphics2D
object and then use the drawing methods of this class. boundingBox
with a transformer is the same as when calling boundingBox
with a null
transformer
and then applying the transformer to the resulting rectangle. That
is: obj.boundingBox(t) = t.apply(obj.boundingBox(null))
t
, the rectangle
obtained by calling obj.boundingBox(t)
is
contained in the rectangle obtained by applying the transformer to obj.boundingBox(null)
. Equality of both rectangles
is not necessary. zoomable()
correctly. If zoomable()
returns true
, but the object does not
follow the zoom factor, the object may be drawn incorrectly. zoomable
method: public boolean zoomable()
true
. contains
is called
by interactors to check whether a point is part of an object shape.
public boolean contains(IlvPoint p, IlvPoint tp, IlvTransformer t)
false
for the transparent area of your object. x
,y
). p
. IlvRect
parameter. dx
, dy
). center
by an angle of angle
degrees. scalex
, scalex
). neww
, newh
). applyTransform
to modify the bounding rectangle of the graphic object. public void applyTransform(IlvTransformer t)
applyTransform
method may be used in the example class, MyRectangle
: class MyRectangle extends IlvGraphic { // The rectangle that defines the object. final IlvRect drawrect = new IlvRect(); ... public void applyTransform(IlvTransformer t) { t.apply(drawrect); } }
IlvManager
also includes several
convenient methods to move and reshape a graphic object managed by
this manager. These are as follows: