37 |
* a View2D. This class implements the keyboard and mouse |
* a View2D. This class implements the keyboard and mouse |
38 |
* command for moving on the spatial plane. |
* command for moving on the spatial plane. |
39 |
*/ |
*/ |
40 |
public class MainNode2D implements BuoyViewMainNode { |
public class MainNode2D extends AbstractMainNode2D { |
41 |
public static boolean dbg = true; |
public static boolean dbg = true; |
42 |
private static void pa(String s) { System.out.println(s); } |
private static void pa(String s) { System.out.println(s); } |
43 |
|
|
|
protected Object plane; |
|
|
protected View2D view2d; |
|
|
|
|
|
protected float panX, panY; |
|
44 |
protected float zoom; |
protected float zoom; |
45 |
|
|
46 |
private float tmp[] = new float[2]; |
private float tmp[] = new float[2]; |
47 |
|
|
|
public View2D getView2D() { return view2d; } |
|
|
|
|
48 |
/** Create a main node with a given plane, pan, and zoom. |
/** Create a main node with a given plane, pan, and zoom. |
49 |
*/ |
*/ |
50 |
public MainNode2D(Object plane, View2D view2d, |
public MainNode2D(Object plane, View2D view2d, |
51 |
float panX, float panY, float zoom) { |
float panX, float panY, float zoom) { |
52 |
this.plane = plane; this.view2d = view2d; |
super(plane, view2d, panX, panY); |
|
this.panX = panX; this.panY = panY; |
|
53 |
this.zoom = zoom; |
this.zoom = zoom; |
54 |
} |
} |
55 |
|
|
64 |
} |
} |
65 |
} |
} |
66 |
|
|
|
private int box2screen = -1; |
|
|
private int box2paper = -1; |
|
|
private float w, h; |
|
|
|
|
67 |
public void renderMain(VobScene vs, int into) { |
public void renderMain(VobScene vs, int into) { |
68 |
vs.coords.getSqSize(into, tmp); |
vs.coords.getSqSize(into, tmp); |
69 |
w = tmp[0]; h = tmp[1]; |
boxw = tmp[0]; boxh = tmp[1]; |
70 |
box2screen = into; |
box2screen = into; |
71 |
|
|
72 |
// create the coordsys, then position it through other method |
// create the coordsys, then position it through other method |
73 |
// this way, we only have the positioning code in one place |
// this way, we only have the positioning code in one place |
74 |
box2paper = vs.coords.orthoBox(0,0,0,0,0,0,0,0); |
box2paper = vs.coords.orthoBox(0,0,0,0,0,0,0,0); |
75 |
vs.matcher.add(box2screen, box2paper, "MainNode2D_B2P"); |
vs.matcher.add(box2screen, box2paper, "BOX2PAPER"); |
76 |
setZoomPan(vs, box2paper); |
setZoomPan(vs, box2paper); |
77 |
|
|
78 |
view2d.render(vs, plane, into, into, box2paper); |
view2d.render(vs, plane, into, into, box2paper); |
85 |
*/ |
*/ |
86 |
private void setZoomPan(VobScene vs, int mainFrame) { |
private void setZoomPan(VobScene vs, int mainFrame) { |
87 |
vs.coords.setOrthoBoxParams(box2paper, 0, |
vs.coords.setOrthoBoxParams(box2paper, 0, |
88 |
panX-w/zoom/2, panY-h/zoom/2, |
panX-boxw/zoom/2, panY-boxh/zoom/2, |
89 |
1/zoom, 1/zoom, w, h); |
1/zoom, 1/zoom, boxw, boxh); |
90 |
} |
} |
91 |
|
|
92 |
public void keystroke(String s) { |
public void keystroke(String s) { |
99 |
private float m_state_zoom = -1; |
private float m_state_zoom = -1; |
100 |
private float pan[] = new float[2]; |
private float pan[] = new float[2]; |
101 |
|
|
|
private float[] v2dwh = new float[2]; |
|
|
|
|
|
/** Clip the values in Pan to the size of the canvas. |
|
|
*/ |
|
|
private 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]; |
|
|
} |
|
|
} |
|
102 |
|
|
103 |
public boolean mouse(MouseEvent e, VobScene oldVobScene) { |
public boolean mouse(MouseEvent e, VobScene oldVobScene) { |
104 |
if (e.getID() == MouseEvent.MOUSE_PRESSED) { |
if (e.getID() == MouseEvent.MOUSE_PRESSED) { |
133 |
// Move around by clicking |
// Move around by clicking |
134 |
if(m_state[2] == e.BUTTON1_MASK && |
if(m_state[2] == e.BUTTON1_MASK && |
135 |
e.getID() == MouseEvent.MOUSE_CLICKED){ |
e.getID() == MouseEvent.MOUSE_CLICKED){ |
136 |
|
mouseMoveClick(e.getX(), e.getY(), oldVobScene); |
|
float[] pt = new float[] { e.getX(), e.getY(), 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(); |
|
137 |
return false; |
return false; |
138 |
} |
} |
139 |
|
|