//(c): Matti Katila package gzz.modules.pp2; import gzz.modules.pp.*; import gzz.modules.pp.vob.*; import gzz.*; import gzz.view.*; import gzz.view.buoy.*; import gzz.vob.*; import gzz.client.*; import gzz.gfx.gl.*; /** A single PP plane/paper, with given view context. * This class takes care of drawing the stencil, * the background and the vobs inside the plane. */ public class SinglePaper { private static final String rcsid = "$Id: SinglePaper.java,v 1.1 2003/02/05 14:46:08 mudyc Exp $"; public static boolean dbg = false; private static void pa(String s) { System.out.println("SinglePaper:"+s); } // Singleton why do I do everything with singleton? // Even I hate globals.. private static SinglePaper paper; private SinglePaper() { // ingenting } public static SinglePaper i() { if (paper == null) paper = new SinglePaper(); return paper; } public static SinglePaper i(ViewContext vc, PPDims d, GraphicsAPI.Window win) { i().set(vc,d, win); return i(); } public void set(ViewContext vc, PPDims d, GraphicsAPI.Window win) { this.context = vc; ((AbstractViewContext)context).setCellView(cellview); this.d = d; this.coordinatePlaneView = new CoordinatePlaneView(d.contains, d.pan); this.window = win; } private TextStyle style = GraphicsAPI.getInstance().getTextStyle("Sans", 0, 20); private CellView cellview = new ImageCell(new PPCellView(style, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")); private PPDims d; private ViewContext context; // Visual characteristics of the virtual paper and ripple /** The scale of the background. * bgscale in paper coordinates = 1 in background coords. */ public float bgscale = 200; /** Border size of the irregularframe. */ public float irreguBorder = 50; /** Ripple length of irregularframe. */ public float irreguRipple = 500; /** For debugging: whether to use stencil or not. */ public boolean useStencil = true; private Vob black = GLCache.getCallList("Color 0 0 0\n"); private CoordinatePlaneView coordinatePlaneView; private GraphicsAPI.Window window; /** Render the plane. * @param frameCS The Box-coordinate system of the frame. * The scale is assumed to be single pixels (although * for example buoys will set this differently). * The height and width define the viewport. * @param panZoom The coordinate system from virtual paper coordinates * to panned-and-zoomed coordinates. * The origin of the panned-and-zoomed coordinates * will be set to the center of the frameCS, and * the scale is 1 to 1 pixel. */ void render(final VobScene vs, final int frameCS, final int panZoom) { final GLVobCoorder glc = (GLVobCoorder)vs.coords; float[] sqs = new float[2]; glc.getSqSize(frameCS, sqs); if (sqs[1] < 5) return; if (dbg) pa("Sqs frame: "+sqs[0]+" "+sqs[1]); // CS from center of frameCS to screen int framecenterCS = vs.translateCS(frameCS, "FCTR", sqs[0]/2, sqs[1]/2); // CS from virtualpaper to screen final int paper2screen = glc.concat(framecenterCS, panZoom); vs.matcher.add(frameCS, paper2screen, "PAPER2S"); final int bg2screen = vs.scaleCS(paper2screen, "BGSCA", bgscale, bgscale); final Cell cursor = context.getAccursed(); final Cell plane = cursor.h(d.contains); // BgVob takes two coordsys: // frame2screen and paper2screen final BgVob bg = BgVob.create(plane, window); final IrregularFrame f = IrregularFrame.create(-16000,-16000,16000,16000, irreguBorder, irreguRipple, 2); final int frameUnit = vs.unitSqCS(frameCS, "USQ"); // Irregu needs frame 2 paper final int screen2paper = glc.invert(paper2screen); vs.matcher.add(paper2screen, screen2paper, "INVER2S"); final int frameUnit2paper = glc.concat(screen2paper, frameUnit); vs.matcher.add(screen2paper, frameUnit2paper, "f2pap"); final int paper2screen_shifted = vs.translateCS(paper2screen, "SHIFTUP", 0, 0, -30); class Putter implements Runnable { Vob v; Putter(Vob v) { this.v = v; } public void run() { vs.map.put(v, paper2screen, frameUnit2paper); } } Runnable placeContent = new Runnable() { public void run() { // XXX Unclean! // vs.map.put(bg, frameUnit, bg2screen); bg.put(vs, frameUnit, bg2screen); vs.map.put(black); coordinatePlaneView.render(vs, paper2screen_shifted, context, frameCS); }}; if(useStencil) Stencil.drawStenciled(vs, new Putter(f.getContent()), new Putter(f.getBlank()), new Putter(f.getFrame()), placeContent, true); else { (new Putter(f.getContent())).run(); (new Putter(f.getFrame())).run(); (new Putter(f.getBlank())).run(); placeContent.run(); } } }