47 |
this.panX = panX; this.panY = panY; |
this.panX = panX; this.panY = panY; |
48 |
} |
} |
49 |
|
|
50 |
|
/** Cause the changes to the zooming and panning variables |
51 |
|
* to be shown in the given vobscene. |
52 |
|
* This changes the parameters of the coordinate systems |
53 |
|
* created by render(). |
54 |
|
*/ |
55 |
|
protected abstract void setZoomPan(VobScene vs, int mainFrame); |
56 |
|
|
57 |
protected float[] v2dwh = new float[2]; |
protected float[] v2dwh = new float[2]; |
58 |
|
|
59 |
/** Clip the panX and panY values to the size of the canvas. |
/** Clip the panX and panY values to the size of the canvas. |
98 |
pa("Key:"+s); |
pa("Key:"+s); |
99 |
} |
} |
100 |
|
|
101 |
|
// Mouse press state |
102 |
|
// x, y, buttons |
103 |
|
protected int[] m_state = null; |
104 |
|
protected float pan[] = new float[2]; |
105 |
|
|
106 |
|
// Mouse x/y position on the paper |
107 |
|
protected float m_pos[] = new float[3]; |
108 |
|
|
109 |
|
protected void readMouseState(MouseEvent e, VobScene oldVobScene) { |
110 |
|
m_state = new int[]{ e.getX(), e.getY(), e.getModifiers()}; |
111 |
|
pan[0] = panX; pan[1] = panY; |
112 |
|
m_pos[0] = m_state[0]; m_pos[1] = m_state[1]; m_pos[2] = 0; |
113 |
|
oldVobScene.coords.inverseTransformPoints3(box2screen, m_pos, m_pos); |
114 |
|
} |
115 |
|
|
116 |
|
public boolean mouse(MouseEvent e, VobScene oldVobScene) { |
117 |
|
if (e.getID() == MouseEvent.MOUSE_PRESSED) { |
118 |
|
readMouseState(e, oldVobScene); |
119 |
|
return false; |
120 |
|
} |
121 |
|
|
122 |
|
if (m_state == null) throw new Error("Mouse state not found!"); |
123 |
|
return doMouse(e, oldVobScene); |
124 |
|
} |
125 |
|
|
126 |
|
protected boolean doMouse(MouseEvent e, VobScene oldVobScene) { |
127 |
|
// Move by dragging with button 1 |
128 |
|
if(m_state[2] == e.BUTTON1_MASK && |
129 |
|
e.getID() == MouseEvent.MOUSE_DRAGGED) { |
130 |
|
|
131 |
|
float[] pos2 = new float[] { e.getX(), e.getY(), 0 }; |
132 |
|
oldVobScene.coords.inverseTransformPoints3(box2screen, pos2, pos2); |
133 |
|
|
134 |
|
panX = pan[0] + (m_pos[0] - pos2[0])/getZoom(); |
135 |
|
panY = pan[1] + (m_pos[1] - pos2[1])/getZoom(); |
136 |
|
clipPan(); |
137 |
|
|
138 |
|
setZoomPan(oldVobScene, box2screen); |
139 |
|
return true; |
140 |
|
} |
141 |
|
|
142 |
|
// Move around by clicking |
143 |
|
if(m_state[2] == e.BUTTON1_MASK && |
144 |
|
e.getID() == MouseEvent.MOUSE_CLICKED){ |
145 |
|
mouseMoveClick(e.getX(), e.getY(), oldVobScene); |
146 |
|
return false; |
147 |
|
} |
148 |
|
|
149 |
|
if(dbg) pa("nothing!"); |
150 |
|
return false; |
151 |
|
} |
152 |
|
|
153 |
|
protected float getZoom() { return 1; } |
154 |
} |
} |