23 |
protected Object plane; |
protected Object plane; |
24 |
public Object getPlane() { return plane; } |
public Object getPlane() { return plane; } |
25 |
|
|
26 |
|
/** An object representing a focus on a 2D plane. |
27 |
|
* The SimpleFocus implementation below just stores |
28 |
|
* an X and Y coordinate, but other implementations |
29 |
|
* could store e.g. an accursed node on the plane. |
30 |
|
*/ |
31 |
|
public interface Focus { |
32 |
|
float getPanX(); |
33 |
|
float getPanY(); |
34 |
|
void setPan(float panX, float panY); |
35 |
|
} |
36 |
|
|
37 |
|
public static class SimpleFocus implements Focus { |
38 |
|
protected float panX, panY; |
39 |
|
public SimpleFocus(float panX, float panY) { |
40 |
|
this.panX = panX; |
41 |
|
this.panY = panY; |
42 |
|
} |
43 |
|
public float getPanX() { return panX; } |
44 |
|
public float getPanY() { return panY; } |
45 |
|
public void setPan(float panX, float panY) { |
46 |
|
this.panX = panX; |
47 |
|
this.panY = panY; |
48 |
|
} |
49 |
|
} |
50 |
|
|
51 |
/** The view shown in this buoy node. |
/** The view shown in this buoy node. |
52 |
*/ |
*/ |
53 |
protected View2D view2d; |
protected View2D view2d; |
54 |
public View2D getView2D() { return view2d; } |
public View2D getView2D() { return view2d; } |
55 |
|
|
56 |
protected float panX, panY; |
protected Focus focus; |
57 |
public float getPanX() { return panX; } |
public Focus getFocus() { return focus; } |
58 |
public float getPanY() { return panY; } |
public void setFocus(Focus f) { this.focus = focus; } |
59 |
|
|
60 |
public interface Factory { |
public interface Factory { |
61 |
AbstractMainNode2D create(Object plane, View2D view2d, |
AbstractMainNode2D create(Object plane, View2D view2d, |
62 |
float panx, float pany); |
float panX, float panY); |
63 |
} |
} |
64 |
|
|
65 |
|
|
77 |
protected float boxw, boxh; |
protected float boxw, boxh; |
78 |
|
|
79 |
public AbstractMainNode2D(Object plane, View2D view2d, |
public AbstractMainNode2D(Object plane, View2D view2d, |
80 |
float panX, float panY) { |
Focus focus) { |
81 |
this.plane = plane; this.view2d = view2d; |
this.plane = plane; this.view2d = view2d; |
82 |
this.panX = panX; this.panY = panY; |
this.focus = focus; |
83 |
} |
} |
84 |
|
|
85 |
|
|
112 |
protected void clipPan() { |
protected void clipPan() { |
113 |
view2d.getSize(plane, v2dwh); |
view2d.getSize(plane, v2dwh); |
114 |
if(v2dwh[0] >= 0) { |
if(v2dwh[0] >= 0) { |
115 |
if(panX < 0) panX = 0; |
float panX = focus.getPanX(), panY = focus.getPanY(); |
116 |
if(panX > v2dwh[0]) panX = v2dwh[0]; |
boolean chg = false; |
117 |
if(panY < 0) panY = 0; |
if(focus.getPanX() < 0) { panX = 0; chg = true; } |
118 |
if(panY > v2dwh[1]) panY = v2dwh[1]; |
if(focus.getPanX() > v2dwh[0]) { |
119 |
|
panX = v2dwh[0]; chg = true; |
120 |
|
} |
121 |
|
if(focus.getPanY() < 0) { panY = 0; chg = true; } |
122 |
|
if(focus.getPanY() > v2dwh[1]) { |
123 |
|
panY = v2dwh[1]; |
124 |
|
chg = true; |
125 |
|
} |
126 |
|
if(chg) focus.setPan(panX, panY); |
127 |
} |
} |
128 |
} |
} |
129 |
|
|
165 |
oldVobScene.coords.transformPoints3(box2paper, pt, pt); |
oldVobScene.coords.transformPoints3(box2paper, pt, pt); |
166 |
if(dbg) p("P3: "+pt[0]+" "+pt[1]+" "+pt[2]); |
if(dbg) p("P3: "+pt[0]+" "+pt[1]+" "+pt[2]); |
167 |
|
|
168 |
panX = pt[0]; panY = pt[1]; |
focus.setPan(pt[0], pt[1]); |
169 |
clipPan(); |
clipPan(); |
170 |
|
|
171 |
AbstractUpdateManager.chg(); |
AbstractUpdateManager.chg(); |
182 |
|
|
183 |
protected void readMouseState(MouseEvent e, VobScene oldVobScene) { |
protected void readMouseState(MouseEvent e, VobScene oldVobScene) { |
184 |
m_state = new int[]{ e.getX(), e.getY(), e.getModifiers()}; |
m_state = new int[]{ e.getX(), e.getY(), e.getModifiers()}; |
185 |
pan[0] = panX; pan[1] = panY; |
pan[0] = focus.getPanX(); pan[1] = focus.getPanY(); |
186 |
m_pos[0] = m_state[0]; m_pos[1] = m_state[1]; m_pos[2] = 0; |
m_pos[0] = m_state[0]; m_pos[1] = m_state[1]; m_pos[2] = 0; |
187 |
oldVobScene.coords.inverseTransformPoints3(box2screen, m_pos, m_pos); |
oldVobScene.coords.inverseTransformPoints3(box2screen, m_pos, m_pos); |
188 |
} |
} |
215 |
float[] pos2 = new float[] { e.getX(), e.getY(), 0 }; |
float[] pos2 = new float[] { e.getX(), e.getY(), 0 }; |
216 |
oldVobScene.coords.inverseTransformPoints3(box2screen, pos2, pos2); |
oldVobScene.coords.inverseTransformPoints3(box2screen, pos2, pos2); |
217 |
|
|
218 |
panX = pan[0] + (m_pos[0] - pos2[0])/getZoom(); |
focus.setPan(pan[0] + (m_pos[0] - pos2[0])/getZoom(), |
219 |
panY = pan[1] + (m_pos[1] - pos2[1])/getZoom(); |
pan[1] + (m_pos[1] - pos2[1])/getZoom()); |
220 |
clipPan(); |
clipPan(); |
221 |
|
|
222 |
setZoomPan(oldVobScene, box2screen); |
setZoomPan(oldVobScene, box2screen); |