use of maspack.render.MouseRayEvent in project artisynth_core by artisynth.
the class GLMouseAdapter method mousePressed.
public void mousePressed(MouseEvent e) {
int mask = (e.getModifiersEx() & ALL_MODIFIERS);
int selectionMask = getSelectionButtonMask();
// Start checking draggers
Dragger3d drawTool = viewer.myDrawTool;
boolean grabbed = false;
if (viewer.myDraggers.size() > 0 || drawTool != null) {
MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
for (Dragger3d d : viewer.myDraggers) {
// pass event to any visible Dragger3dBase, or any other Dragger3d
if (d.isVisible()) {
updateDraggerModeAndFlags(mask, d);
if (d.mousePressed(rayEvt)) {
grabbed = true;
dragAction = DRAGGER_ACTION;
break;
}
}
}
if (drawTool != null && drawTool.isVisible()) {
updateDraggerModeAndFlags(mask, drawTool);
if (drawTool.mousePressed(rayEvt)) {
grabbed = true;
dragAction = DRAGGER_ACTION;
}
}
}
if (grabbed) {
viewer.repaint();
} else {
if (viewer.getEllipticCursorActive() && (mask & ellipticCursorResizeMask) == ellipticCursorResizeMask) {
dragAction = ELLIPTIC_CURSOR_RESIZE;
ellipticCursorStartSize = new Vector2d(viewer.getEllipticCursorSize());
} else if (mask == getTranslateButtonMask()) {
dragAction = TRANSLATE;
} else if (mask == getRotateButtonMask()) {
dragAction = ROTATE;
} else if (mask == getZoomButtonMask()) {
dragAction = ZOOM;
} else if (viewer.isSelectionEnabled() && (mask & selectionMask) == selectionMask) {
if (viewer.getSelectOnPress()) {
checkForSelection(e);
dragAction = NO_ACTION;
viewer.setDragBox(null);
} else {
if (viewer.getEllipticSelection()) {
checkForSelection(e);
}
dragAction = DRAG_SELECT;
}
} else {
dragAction = NO_ACTION;
}
}
dragStartX = lastX = e.getX();
dragStartY = lastY = e.getY();
}
use of maspack.render.MouseRayEvent in project artisynth_core by artisynth.
the class GLMouseAdapter method mouseReleased.
public void mouseReleased(MouseEvent e) {
// End any dragger modes
Dragger3d drawTool = viewer.myDrawTool;
boolean grabbed = false;
if (dragAction == DRAG_SELECT) {
checkForSelection(e);
viewer.setDragBox(null);
} else if (dragAction == DRAGGER_ACTION) {
if (viewer.myDraggers.size() > 0 || drawTool != null) {
MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
for (Dragger3d d : viewer.myDraggers) {
// pass event to any visible Dragger3dBase, or any other Dragger3d
if (d.isVisible()) {
if (d.mouseReleased(rayEvt)) {
grabbed = true;
d.clearFlags();
d.setDragMode(DragMode.OFF);
break;
}
}
}
if (drawTool != null && drawTool.isVisible()) {
if (drawTool.mouseReleased(rayEvt)) {
grabbed = true;
drawTool.clearFlags();
drawTool.setDragMode(DragMode.OFF);
}
}
}
if (grabbed) {
viewer.repaint();
}
}
dragAction = NO_ACTION;
// if (dragAction == NO_ACTION) {
// Dragger3d drawTool = viewer.myDrawTool;
// boolean grabbed = false;
//
// if (viewer.myDraggers.size() > 0 || drawTool != null) {
// MouseRayEvent rayEvt = MouseRayEvent.create (e, viewer);
// for (Dragger3d d : viewer.myDraggers) {
// // pass event to any visible Dragger3dBase, or any other Dragger3d
// if (d.isVisible()) {
// if (d.mouseReleased (rayEvt)) {
// grabbed = true;
// break;
// }
// }
// }
// if (drawTool != null && drawTool.isVisible()) {
// if (drawTool.mouseReleased (rayEvt)) {
// grabbed = true;
// }
// }
// }
// if (grabbed) {
// viewer.repaint();
// }
// }
// else if (dragAction == DRAG_SELECT) {
// checkForSelection (e);
// viewer.setDragBox (null);
// }
}
use of maspack.render.MouseRayEvent in project artisynth_core by artisynth.
the class GLMouseAdapter method mouseDragged.
public void mouseDragged(MouseEvent e) {
currentCursor = new Point(e.getX(), e.getY());
int xOff = e.getX() - lastX, yOff = e.getY() - lastY;
switch(dragAction) {
case ROTATE:
{
viewer.rotate(-xOff / 200.0, -yOff / 200.0);
break;
}
case ZOOM:
{
double r = yOff < 0 ? 0.99 : 1.01;
double s = Math.pow(r, Math.abs(yOff));
viewer.zoom(s);
// viewer.repaint();
break;
}
case TRANSLATE:
{
double dpp = viewer.centerDistancePerPixel();
viewer.translate(dpp * xOff, -dpp * yOff);
break;
}
case DRAGGER_ACTION:
{
Dragger3d drawTool = viewer.myDrawTool;
boolean grabbed = false;
int mods = e.getModifiersEx() & ALL_MODIFIERS;
if (viewer.myDraggers.size() > 0 || drawTool != null) {
MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
for (Dragger3d d : viewer.myDraggers) {
// pass to any visible Dragger3dBase, or any other Dragger3d
if (d.isVisible()) {
updateDraggerFlags(mods, d);
if (d.mouseDragged(rayEvt)) {
grabbed = true;
break;
}
}
}
if (drawTool != null && drawTool.isVisible()) {
updateDraggerFlags(mods, drawTool);
if (drawTool.mouseDragged(rayEvt)) {
grabbed = true;
}
}
}
if (grabbed) {
viewer.repaint();
}
break;
}
case DRAG_SELECT:
{
if (viewer.getEllipticSelection()) {
Vector2d csize = viewer.getEllipticCursorSize();
float x = e.getX();
float y = e.getY();
// Increase to make the program check for selection more often when dragging a circle.
int sensitivity = 4;
if (Math.abs(x - dragStartX) > csize.x / sensitivity || Math.abs(y - dragStartY) > csize.y / sensitivity) {
checkForSelection(e);
// viewer.setSelectionCircle(null);
dragStartX = (int) x;
dragStartY = (int) y;
}
} else {
int x = dragStartX;
int y = dragStartY;
int w = e.getX() - x;
int h = e.getY() - y;
if (w == 0) {
w = 1;
} else if (w < 0) {
x = e.getX();
w = -w;
}
if (h == 0) {
h = 1;
} else if (h < 0) {
y = e.getY();
h = -h;
}
viewer.setDragBox(new Rectangle(x, y, w, h));
viewer.repaint();
}
break;
}
case ELLIPTIC_CURSOR_RESIZE:
{
Vector2d csize = new Vector2d(ellipticCursorStartSize);
csize.x = Math.max(1, csize.x + e.getX() - dragStartX);
csize.y = Math.max(1, csize.y + e.getY() - dragStartY);
viewer.setEllipticCursorSize(csize);
break;
}
}
if (viewer.getEllipticCursorActive()) {
viewer.repaint();
}
lastX = e.getX();
lastY = e.getY();
}
use of maspack.render.MouseRayEvent in project artisynth_core by artisynth.
the class GLMouseAdapter method mouseClicked.
public void mouseClicked(MouseEvent e) {
Dragger3d drawTool = viewer.myDrawTool;
int mods = e.getModifiersEx() & ALL_MODIFIERS;
boolean grabbed = false;
if (viewer.myDraggers.size() > 0 || drawTool != null) {
MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
for (Dragger3d d : viewer.myDraggers) {
// pass event to any visible Dragger3dBase, or any other Dragger3d
if (d.isVisible()) {
updateDraggerModeAndFlags(mods, d);
if (d.mouseClicked(rayEvt)) {
grabbed = true;
dragAction = DRAGGER_ACTION;
break;
}
}
}
if (drawTool != null && drawTool.isVisible()) {
updateDraggerModeAndFlags(mods, drawTool);
if (drawTool.mouseClicked(rayEvt)) {
grabbed = true;
}
}
}
if (grabbed) {
viewer.repaint();
}
}
use of maspack.render.MouseRayEvent in project artisynth_core by artisynth.
the class GLMouseAdapter method mouseMoved.
public void mouseMoved(MouseEvent e) {
currentCursor = new Point(e.getX(), e.getY());
if (viewer.getEllipticSelection()) {
viewer.repaint();
} else {
int mods = e.getModifiersEx() & ALL_MODIFIERS;
Dragger3d drawTool = viewer.myDrawTool;
boolean grabbed = false;
if (viewer.myDraggers.size() > 0 || drawTool != null) {
MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
for (Dragger3d d : viewer.myDraggers) {
// pass event to any visible Dragger3dBase, or any other Dragger3d
if (d.isVisible()) {
updateDraggerFlags(mods, d);
if (d.mouseMoved(rayEvt)) {
grabbed = true;
break;
}
}
}
if (drawTool != null && drawTool.isVisible()) {
updateDraggerFlags(mods, drawTool);
if (drawTool.mouseMoved(rayEvt)) {
grabbed = true;
}
}
}
if (grabbed) {
viewer.repaint();
}
}
}
Aggregations