[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool AbstractTool.java,1.27,1.28 ExtrusionT
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31672/src/net/sourceforge/bprocessor/gl/tool Modified Files: AbstractTool.java ExtrusionTool.java PencilTool.java RotationTool.java Tool.java ToolFactory.java Log Message: new cursors for drag and rotate along with better rotation and drag, still small bugs when rotating while an surface is selected and zoomfactor different from 1 Index: Tool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Tool.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Tool.java 17 Nov 2005 16:58:16 -0000 1.11 --- Tool.java 18 Nov 2005 01:27:56 -0000 1.12 *************** *** 11,14 **** --- 11,15 ---- import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; + import java.awt.event.MouseWheelListener; import java.util.Collection; *************** *** 16,20 **** * The tool interface */ ! public interface Tool extends MouseListener, MouseMotionListener, KeyListener { /** The select tool */ public static final int SELECT_TOOL = 0; --- 17,21 ---- * The tool interface */ ! public interface Tool extends MouseListener, MouseMotionListener, KeyListener, MouseWheelListener { /** The select tool */ public static final int SELECT_TOOL = 0; *************** *** 29,32 **** --- 30,35 ---- /** The Rotation tool */ public static final int ROTATION_TOOL = 5; + /** The prevoius tool (the tool used before this one) */ + public static final int PREVIOUS_TOOL = 6; /** Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ToolFactory.java 17 Nov 2005 16:58:16 -0000 1.13 --- ToolFactory.java 18 Nov 2005 01:27:56 -0000 1.14 *************** *** 52,55 **** --- 52,61 ---- private RotationTool rotation; + /** The previous tool */ + private Tool previousTool; + + /** The curretn tool */ + private Tool currentTool; + /** * Constructor *************** *** 62,65 **** --- 68,79 ---- Cursor pencilcursor = Toolkit.getDefaultToolkit().createCustomCursor(pencilimage, new Point(7, 8), "Pencil"); + url = cl.getResource("Biconrotcam.gif"); + Image rotationImage = Toolkit.getDefaultToolkit().getImage(url); + Cursor rotationCursor = + Toolkit.getDefaultToolkit().createCustomCursor(rotationImage, new Point(7, 8), "Rotation"); + url = cl.getResource("Bicondrag.gif"); + Image dragImage = Toolkit.getDefaultToolkit().getImage(url); + Cursor dragCursor = + Toolkit.getDefaultToolkit().createCustomCursor(dragImage, new Point(7, 8), "Drag"); Toolbar tb = Toolbar.getInstance(); *************** *** 82,86 **** extrusion = new ExtrusionTool(glv, pencilcursor); clipplane = new ClipplaneTool(glv, pencilcursor); ! rotation = new RotationTool(glv, pencilcursor); Notifier.getInstance().addListener(select); --- 96,100 ---- extrusion = new ExtrusionTool(glv, pencilcursor); clipplane = new ClipplaneTool(glv, pencilcursor); ! rotation = new RotationTool(glv, rotationCursor, dragCursor); Notifier.getInstance().addListener(select); *************** *** 108,111 **** --- 122,136 ---- /** + * Get the previous tool + * @return The tool + */ + public Tool getPrevious() { + Tool temp = previousTool; + previousTool = currentTool; + currentTool = temp; + return temp; + } + + /** * Get the tool i if it is a legal tool * @param i The tool number *************** *** 113,127 **** --- 138,159 ---- */ public Tool get(int i) { + previousTool = currentTool; if (i == Tool.SELECT_TOOL) { + currentTool = select; return select; } else if (i == Tool.MOVE_TOOL) { + currentTool = move; return move; } else if (i == Tool.EXTRUSION_TOOL) { + currentTool = extrusion; return extrusion; } else if (i == Tool.PENCIL_TOOL) { + currentTool = pencil; return pencil; } else if (i == Tool.CLIP_TOOL) { + currentTool = clipplane; return clipplane; } else if (i == Tool.ROTATION_TOOL) { + currentTool = rotation; return rotation; } else { Index: ExtrusionTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ExtrusionTool.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** ExtrusionTool.java 17 Nov 2005 18:14:00 -0000 1.27 --- ExtrusionTool.java 18 Nov 2005 01:27:56 -0000 1.28 *************** *** 473,476 **** --- 473,477 ---- } } + super.keyPressed(e); } } Index: PencilTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/PencilTool.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** PencilTool.java 15 Nov 2005 19:04:10 -0000 1.33 --- PencilTool.java 18 Nov 2005 01:27:56 -0000 1.34 *************** *** 388,391 **** --- 388,394 ---- vertex.setName("current"); current = vertex; + } else { + // just to take an initial bug + current = new Vertex("", 0, 0, 0); } } Index: AbstractTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractTool.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** AbstractTool.java 17 Nov 2005 16:58:16 -0000 1.27 --- AbstractTool.java 18 Nov 2005 01:27:56 -0000 1.28 *************** *** 17,20 **** --- 17,21 ---- import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; + import java.awt.event.MouseWheelEvent; import java.util.List; *************** *** 33,40 **** /** The mouse position last time the mouse was pressed initializes to (0,0) */ ! private static int[] pressPos = new int[2]; /** The mouse position last time there was a mouse event */ ! private static int[] lastPos = new int[2]; /** The mouse movement in x axis since press */ --- 34,41 ---- /** The mouse position last time the mouse was pressed initializes to (0,0) */ ! protected static int[] pressPos = new int[2]; /** The mouse position last time there was a mouse event */ ! protected static int[] previousPos = new int[2]; /** The mouse movement in x axis since press */ *************** *** 65,70 **** protected Object target; ! /** The cursor associated with this tool */ ! protected Cursor cursor; --- 66,70 ---- protected Object target; ! /** The cursor associated with this tool */ protected Cursor cursor; *************** *** 93,96 **** --- 93,111 ---- /** + * Invoked when the mouse wheel is used + * @param e The mouseWheelEvent + */ + public void mouseWheelMoved(MouseWheelEvent e) { + int rotation = e.getWheelRotation(); + View v = glv.getView(); + if (rotation > 0) { + v.zoom(1.1); + } else { + v.zoom(0.9); + } + glv.repaint(false); + } + + /** * Invoked when a key has been pressed. * @param e The KeyEvent *************** *** 164,176 **** View v = glv.getView(); - if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK) { - v.translateCenter(new double[] {(x - lastPos[0]) / (30 * (glv.getView()).getZoomFactor()), - (y - lastPos[1]) / (30 * (glv.getView()).getZoomFactor()), - 0.0}); - } - - lastPos[0] = x; - lastPos[1] = y; dragged(e); glv.repaint(true); } --- 179,186 ---- View v = glv.getView(); dragged(e); + + previousPos[0] = x; + previousPos[1] = y; glv.repaint(true); } *************** *** 187,193 **** dy = y - pressPos[1]; - lastPos[0] = x; - lastPos[1] = y; moved(e); glv.repaint(true); } --- 197,204 ---- dy = y - pressPos[1]; moved(e); + + previousPos[0] = x; + previousPos[1] = y; glv.repaint(true); } *************** *** 223,229 **** dx = 0; dy = 0; ! lastPos[0] = pressPos[0]; ! lastPos[1] = pressPos[1]; ! pressed(e); glv.repaint(true); } --- 234,245 ---- dx = 0; dy = 0; ! previousPos[0] = pressPos[0]; ! previousPos[1] = pressPos[1]; ! if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || ! e.getButton() == MouseEvent.BUTTON2) { ! glv.changeTool(Tool.ROTATION_TOOL); ! } else { ! pressed(e); ! } glv.repaint(true); } *************** *** 235,240 **** public void mouseReleased(MouseEvent e) { int currentButton = e.getButton(); ! ! released(e); glv.repaint(true); } --- 251,260 ---- public void mouseReleased(MouseEvent e) { int currentButton = e.getButton(); ! if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || ! e.getButton() == MouseEvent.BUTTON2) { ! glv.changeTool(Tool.PREVIOUS_TOOL); ! } else { ! released(e); ! } glv.repaint(true); } Index: RotationTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RotationTool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RotationTool.java 17 Nov 2005 16:58:16 -0000 1.1 --- RotationTool.java 18 Nov 2005 01:27:56 -0000 1.2 *************** *** 8,11 **** --- 8,12 ---- import net.sourceforge.bprocessor.gl.GLView; + import net.sourceforge.bprocessor.gl.view.View; import java.awt.event.ActionListener; *************** *** 43,46 **** --- 44,53 ---- protected int mode = ROTATION; + /** The cursor for rotation */ + private Cursor rotationCursor; + + /** The cursor for drag */ + private Cursor dragCursor; + static { timer = new Timer(40, null); *************** *** 50,58 **** * KeyListener for the GL Canvas * @param glv The 3D canvas ! * @param cursor The Mouse cursor */ ! public RotationTool(GLView glv, Cursor cursor) { ! super(glv, cursor); timer.start(); rotateAction = new CameraMoveTimer(this, glv); } --- 57,68 ---- * KeyListener for the GL Canvas * @param glv The 3D canvas ! * @param cursor1 The Mouse cursor for rotation ! * @param cursor2 The Mouse cursor for drag */ ! public RotationTool(GLView glv, Cursor cursor1, Cursor cursor2) { ! super(glv, cursor1); timer.start(); + rotationCursor = cursor1; + dragCursor = cursor2; rotateAction = new CameraMoveTimer(this, glv); } *************** *** 75,82 **** */ protected void dragged(MouseEvent e) { ! if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { ! mode = ROLL; } else { ! mode = ROTATION; } } --- 85,101 ---- */ protected void dragged(MouseEvent e) { ! View v = glv.getView(); ! if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK || ! e.getButton() == MouseEvent.BUTTON2) { ! glv.setCursor(dragCursor); ! v.translateCenter(new double[] {(e.getX() - previousPos[0]) / (30 * v.getZoomFactor()), ! (e.getY() - previousPos[1]) / (30 * v.getZoomFactor()), ! 0.0}); } else { ! if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { ! mode = ROLL; ! } else { ! mode = ROTATION; ! } } } *************** *** 87,96 **** */ protected void pressed(MouseEvent e) { ! if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { ! mode = ROLL; ! } else { ! mode = ROTATION; ! } if (e.getButton() == MouseEvent.BUTTON1) { timer.addActionListener(rotateAction); } --- 106,116 ---- */ protected void pressed(MouseEvent e) { ! glv.setCursor(rotationCursor); if (e.getButton() == MouseEvent.BUTTON1) { + if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) { + mode = ROLL; + } else { + mode = ROTATION; + } timer.addActionListener(rotateAction); } |