@Override public void mouseDragged(MouseEvent e) { if (_mousedown != null && _up == null) { _display_offset[0] += e.getX() - _mousedown[0]; _display_offset[1] += e.getY() - _mousedown[1]; _mousedown = new int[] {e.getX(), e.getY()}; } if (_up != null) { if (_up.getType() == BoardObject.type.ROAD) { if (((Road) _up).oneDown == false) { _up.setX(e.getX()); _up.setY(e.getY()); } else { ((Road) _up).setX2(e.getX()); ((Road) _up).setY2(e.getY()); } } else { _up.setX(e.getX() - _up.getW() / 2); _up.setY(e.getY() - _up.getH() / 2); } } repaint(); }
private int[] setUpNearest(MouseEvent e) { int mousex = e.getX() - _display_offset[0]; int mousey = e.getY() - _display_offset[1]; int i = 0; int j; j = (int) Math.round((mousey - hextop) * 1.0 / intervalUp); if ((j % 2 + (rings - 1) % 2) == 0 || (((j - 1) % 2 + (rings) % 2) == 0)) { int glob = 1; for (i = 0; (Math.floor((i + 1) / 2) * radius + Math.floor(i / 2) * radius * 2) < mousex - hexleft - radius / 2; i++) glob += (((i % 2) == 0) ? 1 : 3); double dx = (Math.floor((i + 1) / 2) * radius + Math.floor(i / 2) * radius * 2) - (mousex - hexleft - radius / 2); if ((i % 2) == 1 && dx > radius / 2) { i = i - 1; glob -= 1; } else if ((i % 2) == 0 && dx > radius) { i = i - 1; glob -= 3; } i = glob; } else { int glob = 0; for (i = 0; (Math.floor((i + 1) / 2) * radius * 2 + Math.floor(i / 2) * radius) < mousex - hexleft; i++) glob += (((i % 2) == 0) ? 3 : 1); double dx = (Math.floor((i + 1) / 2) * radius * 2 + Math.floor(i / 2) * radius) - (mousex - hexleft); if ((i % 2) == 0 && dx > radius / 2) { i = i - 1; glob -= 1; } else if ((i % 2) == 1 && dx > radius) { i = i - 1; glob -= 3; } i = glob; } return new int[] {i, j}; }
@Override public void mousePressed(MouseEvent e) { if (_up == null) _mousedown = new int[] {e.getX(), e.getY()}; }
/** MOUSE EVENTS! */ @Override public void mouseClicked(MouseEvent e) { callObjectAtLocation(e.getX() - _display_offset[0], e.getY() - _display_offset[1]); repaint(); }