Esempio n. 1
0
  @Override
  public void mouseMoved(MouseEvent e) {
    e.translatePoint(-x, -y);
    for (Entity entity : entities) entity.setHovered(false);
    for (Entity entity : entities) if (entity.mouseMoved(e)) break;

    e.translatePoint(x, y);
  }
Esempio n. 2
0
  @Override
  public void mousePressed(MouseEvent e) {
    if (Game.currentGame.placedStruct || Game.currentGame.activeStruct != null) return;

    e.translatePoint(-x, -y);
    if (e.getButton() == MouseEvent.BUTTON1) // LMB
    {
      if (selectedEntity != null
          && selectedEntity instanceof Struct
          && ((Struct) selectedEntity).guiPoint != null
          && ((Struct) selectedEntity).components.size() > 0) return;

      selectedEntity = null;
      for (Entity entity : entities) entity.setClicked(false);
      for (Entity entity : entities) {
        if (entity.mousePressed(e)) {
          selectedEntity = entity;
          break;
        }
      }
    } else if (e.getButton() == MouseEvent.BUTTON3
        && selectedEntity != null
        && selectedEntity instanceof Villager) {
      Entity target = null;
      for (Entity entity : entities) {
        if (entity.mousePressed(e)) {
          target = entity;
          break;
        }
      }

      setVillagerTarget((Villager) selectedEntity, e.getX(), e.getY(), target);
    } else if (e.getButton() == MouseEvent.BUTTON3) // after Drag
    {
      Entity target = null;
      for (Entity entity : entities) {
        if (entity.isClicked() && entity instanceof Villager) continue;

        if (entity.mousePressed(e)) {
          target = entity;
          break;
        }
      }

      for (Entity entity : entities) {
        if (entity.isClicked() && entity instanceof Villager) {
          setVillagerTarget((Villager) entity, e.getX(), e.getY(), target);
        }
      }
    }

    e.translatePoint(x, y);
  }
Esempio n. 3
0
 private void repairEvent(MouseEvent e, double zoom) {
   if (zoom != 1.0) {
     int oldx = e.getX();
     int oldy = e.getY();
     int newx = (int) Math.round(e.getX() / zoom);
     int newy = (int) Math.round(e.getY() / zoom);
     e.translatePoint(newx - oldx, newy - oldy);
   }
 }
Esempio n. 4
0
 private MouseEvent transformMouseEvent(MouseEvent e) {
   if (this == e.getComponent()) {
     return e;
   } else {
     Point lp = getLocationInQueryTextArea(e.getComponent());
     e.setSource(this);
     e.translatePoint(lp.x, lp.y);
     return e;
   }
 }
Esempio n. 5
0
    public void mouseDragged(java.awt.event.MouseEvent e) {
      if (dragTargetArea != null) {
        // Since we're dragging, this is no longer considered a click
        isClick = false;

        // Draw the target feedback and position the drag button based
        // on the mouse's new location
        e.translatePoint(dragSourceArea.x, dragSourceArea.y);
        Point p = makeSafePoint(e.getX(), e.getY());
        paintTargetFeedback(p.x, p.y);
        getDragButton().setLocation(p.x - cursorOffset.x, p.y - cursorOffset.y);
      }
    }
Esempio n. 6
0
    public void mouseReleased(java.awt.event.MouseEvent e) {
      if (dragTargetArea != null) {

        // Turn off the drag button and feedback
        getDragButton().setVisible(false);
        paintTargetFeedback(-1, -1);

        e.translatePoint(dragSourceArea.x, dragSourceArea.y);
        Point p = makeSafePoint(e.getX(), e.getY());

        JButton b = (JButton) e.getSource();
        if (isClick || dragTargetArea.contains(p.x, p.y)) {
          // if we're considered a simple click, or the dragging ended
          // within the target area, perform the move.
          slide(buttons.indexOf(b));
        } else {
          // The drag finished outside the target, so just show the
          // hidden button and don't move anything.
          b.setVisible(true);
        }
        dragTargetArea = null;
        dragSourceArea = null;
      }
    }
Esempio n. 7
0
 public void translate(final MouseEvent me) {
   me.translatePoint(-insets.left, -insets.top);
 }
Esempio n. 8
0
 private void redispatchEvent(MouseEvent mouseevent) {
   Point point = mouseevent.getComponent().getLocation();
   mouseevent.translatePoint(point.x, point.y);
   frm.dispatchEvent(mouseevent);
 }
    private MouseEvent transformMouseEvent(MouseEvent event) {
      if (event == null) {
        throw new IllegalArgumentException("MouseEvent is null");
      }
      MouseEvent newEvent;
      if (event instanceof MouseWheelEvent) {
        MouseWheelEvent mouseWheelEvent = (MouseWheelEvent) event;
        newEvent =
            new MouseWheelEvent(
                mouseWheelEvent.getComponent(),
                mouseWheelEvent.getID(),
                mouseWheelEvent.getWhen(),
                mouseWheelEvent.getModifiers(),
                mouseWheelEvent.getX(),
                mouseWheelEvent.getY(),
                mouseWheelEvent.getClickCount(),
                mouseWheelEvent.isPopupTrigger(),
                mouseWheelEvent.getScrollType(),
                mouseWheelEvent.getScrollAmount(),
                mouseWheelEvent.getWheelRotation());
      } else {
        newEvent =
            new MouseEvent(
                event.getComponent(),
                event.getID(),
                event.getWhen(),
                event.getModifiers(),
                event.getX(),
                event.getY(),
                event.getClickCount(),
                event.isPopupTrigger(),
                event.getButton());
      }
      if (view != null && at.getDeterminant() != 0) {
        Rectangle viewBounds = getTransformedSize();
        Insets insets = JXTransformer.this.getInsets();
        int xgap = (getWidth() - (viewBounds.width + insets.left + insets.right)) / 2;
        int ygap = (getHeight() - (viewBounds.height + insets.top + insets.bottom)) / 2;

        double x = newEvent.getX() + viewBounds.getX() - insets.left;
        double y = newEvent.getY() + viewBounds.getY() - insets.top;
        Point2D p = new Point2D.Double(x - xgap, y - ygap);

        Point2D tp;
        try {
          tp = at.inverseTransform(p, null);
        } catch (NoninvertibleTransformException ex) {
          // can't happen, we check it before
          throw new AssertionError("NoninvertibleTransformException");
        }
        // Use transformed coordinates to get the current component
        mouseCurrentComponent =
            SwingUtilities.getDeepestComponentAt(view, (int) tp.getX(), (int) tp.getY());
        if (mouseCurrentComponent == null) {
          mouseCurrentComponent = JXTransformer.this;
        }
        Component tempComponent = mouseCurrentComponent;
        if (mouseDraggedComponent != null) {
          tempComponent = mouseDraggedComponent;
        }

        Point point =
            SwingUtilities.convertPoint(view, (int) tp.getX(), (int) tp.getY(), tempComponent);
        newEvent.setSource(tempComponent);
        newEvent.translatePoint(point.x - event.getX(), point.y - event.getY());
      }
      return newEvent;
    }