checkpoint
[anneal.git] / src / edu / berkeley / qfat / MeshViewer.java
index 7a9fcd5..a0e9c61 100644 (file)
@@ -18,12 +18,14 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
     private float angley = 0;
 
     private Mesh.Vertex closest = null;
+    private Point       closestOriginallyAt = null;
     private int         mousex;
     private int         mousey;
     private Matrix      projection = null;
     private Point       clickPoint = null;
     private GLCanvas    glcanvas;
     private boolean     updateVisibilities = false;
+    private boolean     mouseInside = false;
 
     private HashSet<Mesh> meshes = new HashSet<Mesh>();
 
@@ -33,6 +35,8 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
     public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
     public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
 
+    public void addKeyListener(KeyListener kl) { glcanvas.addKeyListener(kl); }
+
     public synchronized void init(GLAutoDrawable gld) {
         GL gl = glcanvas.getGL();//gld.getGL();
         gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@@ -75,6 +79,10 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
 
         GL gl = glcanvas.getGL();//drawable.getGL();
         GLU glu = new GLU();
+
+        if (!mouseInside) gl.glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
+        else gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+
         gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
         gl.glPointSize(5.0f);
         gl.glLoadIdentity();
@@ -109,6 +117,7 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
             //Matrix projection = Matrix.getProjectionMatrix(gl);
             double dist = Double.MAX_VALUE;
             closest = null;
+            closestOriginallyAt = null;
             for(Mesh mesh : meshes)
                 if (mesh.option_selectable)
                     for(Mesh.Vertex v : mesh.vertices()) {
@@ -185,8 +194,8 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
     public void keyReleased(KeyEvent e) { }
 
     public void mouseClicked(MouseEvent e) { }
-    public void mouseEntered(MouseEvent e) { }
-    public void mouseExited(MouseEvent e) { }
+    public void mouseEntered(MouseEvent e) { mouseInside = true; }
+    public void mouseExited(MouseEvent e) { mouseInside = false; }
     public void mousePressed(MouseEvent e) {
         clickPoint = getMouse();
     }
@@ -206,9 +215,9 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
         if ((e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0) {
             if (closest != null && projection != null) {
                 synchronized(this) {
-                    Point clickClosest = closest == null ? null : closest.getPoint();
+                    if (closestOriginallyAt==null) closestOriginallyAt = closest.getPoint();
                     Vec d1 = projection.inverse().times(getMouse()).minus(projection.inverse().times(clickPoint));
-                    Vec delta = d1.plus(clickClosest).minus(closest.getPoint());
+                    Vec delta = d1.plus(closestOriginallyAt).minus(closest.getPoint());
                     closest.move(delta, false);
                 }
             }