// (c) Tuomas J. Lukka package gzz.vob; /** A simple class to lazily manage the coordinate systems * of a box. *

* The model here is that we have a standardized coordinate system - * the "default" size, with unit aspect ratio. In this coordinate system, * the box has a certain width and height. * The transformation from this coordinate system to screen can perform * stretching or other transformations. *

* This class is only a wrapper for the data and for lazily * generating the unit square system -- for now!. Later, we * may optimize this type of coordsys. *

* Note that this class is reusable to avoid object creation overhead: * a common use would be *

 * 	Box b = new Box();
 * 	for(...) {
 * 		b.set(kjxg);
 * 		... use b
 * 	}
 * 
*/ public class Box { /** The key used to put the unitcoordsys under whcoordsys. */ static Object uckey = new Object(); VobScene vs; float w, h; int whcoordsys; int unitcoordsys; /** Set this box to a new box. * @param vs The vobscene to use * @param whcoordsys The standardized coordinate system for the box * @param w The width of the box * @param h The height of the box */ public void set(VobScene vs, int whcoordsys, float w, float h) { this.vs = vs; this.whcoordsys = whcoordsys; this.unitcoordsys = -1; this.w = w; this.h = h; } /** Create the unit square coordsys. */ private void createUnitCoordsys() { unitcoordsys = vs.coords.coordsys(whcoordsys, 0, 0, 0, w, h); vs.matcher.addSub(whcoordsys, unitcoordsys, uckey); } /** Return the width of the box in the standardized coordinate * system. */ public float getWidth() { return w; } /** Return the height of the box in the standardized coordinate * system. */ public float getHeight() { return h; } /** Return the standardized coordinate system in which * the rectangle (0,w)x(0,h) maps onto the final box. */ public int getWHCoordsys() { return whcoordsys;} /** Return the unit square coordinate system in which * the rectangle (0,1)x(0,1) maps onto the final box. */ public int getUnitCoordsys() { if(unitcoordsys <= 0) createUnitCoordsys(); return unitcoordsys; } /** Set this box to be a sub-box in WH coordinates. */ public void setSubWH(Box parent, Object key, float bx, float by, float bw, float bh) { vs = parent.vs; whcoordsys = vs.coords.coordsys(parent.whcoordsys, 0, bx, by, 1, 1); unitcoordsys = -1; w = bw; h = bh; } }