/* PPCanvasCursor.java * * Copyright (c) 2003, Matti Katila * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by 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.*; import java.awt.event.*; // implement fisheye in here later.. /** XXX */ public class PPCanvasCursor implements BuoyViewMainNode { private static final String rcsid = "$Id: PPCanvasCursor.java,v 1.1 2003/02/05 11:45:42 mudyc Exp $"; public static boolean dbg = false; private static void pa(String s) { System.out.println("BuoyAdaptor:"+s); } // Geometry /** The width of the main view. */ public float mainWidth = 600; /** The width of the left edge panel. */ public float leftPanelWidth = 100; /** The height of the entries in the left edge panel. */ public float leftPanelObjectHeight = 100; /** The "over-size" of the entries in the left panel */ public float leftPanelRealHeight = 170, leftPanelRealWidth = 230; /** The zoom in the left panel */ public float leftPanelZoom = .8f; /** The height of the main view. */ public float mainHeight = 600; /** The Y position of the main view. */ public float mainY = 100; /** Buoy floater settings. */ public float buoyCenterY = 400, buoyRadius = 400; /** Buoy viewport geometry. */ public float buoyVPWidth = 400, buoyVPHeight = 400; /** Link buoy viewport geometry. */ public float linkbuoyVPWidth = 200, linkbuoyVPHeight = 100; /** The center of the visible area. */ float centerX(VobScene vs) { return (vs.size.width-leftPanelWidth)/2; } /** The zoom to be used for the buoys. */ public float buoyZoom = 1; /** The zoom to be used for the link creation buoys. */ public float linkbuoyZoom = .5f; // Current state /** The current zoom. * Pixels for 1 paper coordinate unit. */ public float zoom = 1; /** The current virtual-paper coordinates. */ public float panx=0, pany=0; /** Whether showing normal or link-making buoys. */ public boolean showLinkbuoys = false; // 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; Vob black = GLCache.getCallList("Color 0 0 0\n"); CoordinatePlaneView coordinatePlaneView; GraphicsAPI.Window window; private PPDims d; private Cell current; private AbstractViewContext avc; public PPCanvasCursor(Cell c, AbstractViewContext avc, PPDims d, GraphicsAPI.Window w) { this.current = c; this.avc = avc; this.d = d; this.window = w; } public void renderMain(VobScene vs, int into) { int mainctr = vs.translateCS(0, "MAINVPCTR", centerX(vs), mainY + mainHeight/2); int frameCS = vs.orthoBoxCS(mainctr, "MAINVP", 10, (-mainWidth)/2, -mainHeight/2, 1, 1, mainWidth, mainHeight); vs.activate(frameCS); // cell to frame CS int c2fCS = vs.coords.ortho(0, 0, 0, 0, 10, 10); vs.matcher.add(frameCS, c2fCS, "C2F"); SinglePlane plane = new SinglePlane(); plane.context = avc; plane.render(vs, frameCS, c2fCS); } public void keystroke(String s) { } public boolean mouse(MouseEvent e, VobScene oldVobScene) { return false; } /** A single PP plane, with given view context. * This class takes care of drawing the stencil, * the background and the vobs inside the plane. */ class SinglePlane { ViewContext context; /** 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(); } } } }