// (c): Tuomas J. Lukka package gzz.gfx.gl; import gzz.media.*; import gzz.media.impl.*; import java.util.*; import java.awt.Point; import java.awt.Dimension; /** Manage image and page spans for OpenGL. */ public class GLSpans { /** A rectangle in a texture. */ static class Rect { int texId; float x0, y0, x1, y1; }; static HashMap pages = new HashMap(); static class LoadedTexRect { LoadedTexRect(String file) { GZZGL.Image img = GZZGL.createImage(file); this.w = img.getSize(0); this.h = img.getSize(1); this.rect = GZZGL.createTexRect(img); } GZZGL.TexRect rect; int w; int h; } /** Return a Rect containing the first page of the * given pagespan. */ static public Rect getRect(PageSpan span) { Rect r = (Rect)pages.get(span); if(r == null) { // ScrollBlockManager.PageSpanBase span = // (ScrollBlockManager.PageSpanBase)span0; PageImageScroll sb = (PageImageScroll)span.getScrollBlock(); int page = span.offset(); Point p = span.getLocation(); Dimension d = span.getSize(); String file = sb.imageFilename(page); float resmult = sb.imageFileResolution(page) / sb.coordinateResolution() ; LoadedTexRect rect = getImage(file); r = new Rect(); r.texId = rect.rect.getTexId(); r.x0 = (float)rect.rect.getTexCoord(0, resmult * p.x / rect.w); r.x1 = (float)rect.rect.getTexCoord(0, resmult * (p.x+d.width) / rect.w); r.y0 = (float)rect.rect.getTexCoord(1, resmult * p.y / rect.h); r.y1 = (float)rect.rect.getTexCoord(1, resmult * (p.y+d.height) / rect.h); pages.put(span, r); } return r; } // Temporary imagecache-like thing XXX static HashMap images = new HashMap(); static public LoadedTexRect getImage(String file) { LoadedTexRect res = (LoadedTexRect) images.get(file); if(res == null) { res = new LoadedTexRect(file); images.put(file, res); } return res; } }