// (c) Benja Fallenstein and Matti Katila and Tuomas J. Lukka package org.fenfire.view.buoy; import org.fenfire.view.View2D; import org.nongnu.libvob.*; import org.nongnu.libvob.impl.DefaultVobMatcher; import org.nongnu.libvob.buoy.*; import java.awt.event.MouseEvent; /** A BuoyViewMainNode showing a 2D plane rendered through * a View2D. This class implements the keyboard and mouse * command for moving on the spatial plane. */ public abstract class AbstractMainNode2D implements BuoyViewMainNode { public static boolean dbg = true; private static void pa(String s) { System.out.println(s); } protected Object plane; protected View2D view2d; public View2D getView2D() { return view2d; } protected float panX, panY; /** The box2screen coordinate system we set last. */ protected int box2screen = -1; /** The box2paper coordinate system last set. * Important rule: must always be matching child of box2screen, * with key "BOX2PAPER". * This is also done by the NodeType2D classes, to ensure proper * interpolation. */ protected int box2paper = -1; protected float boxw, boxh; public AbstractMainNode2D(Object plane, View2D view2d, float panX, float panY) { this.plane = plane; this.view2d = view2d; this.panX = panX; this.panY = panY; } protected float[] v2dwh = new float[2]; /** Clip the panX and panY values to the size of the canvas. */ protected void clipPan() { view2d.getSize(plane, v2dwh); if(v2dwh[0] >= 0) { if(panX < 0) panX = 0; if(panX > v2dwh[0]) panX = v2dwh[0]; if(panY < 0) panY = 0; if(panY > v2dwh[1]) panY = v2dwh[1]; } } protected void mouseMoveClick(int x, int y, VobScene oldVobScene) { float[] pt = new float[] { x, y, 0 }; if(dbg) pa("P1: "+pt[0]+" "+pt[1]+" "+pt[2]); oldVobScene.coords.inverseTransformPoints3( box2screen, pt, pt); if(dbg) pa("P2: "+pt[0]+" "+pt[1]+" "+pt[2]); oldVobScene.coords.transformPoints3(box2paper, pt, pt); if(dbg) pa("P3: "+pt[0]+" "+pt[1]+" "+pt[2]); panX = pt[0]; panY = pt[1]; clipPan(); AbstractUpdateManager.chg(); } }