示例#1
0
  @Override
  public Mouse.Dragger onMouseDown(Window.Event<Window.MouseState> e, int button) {

    // if we haven't been drawn, then we can't interact

    if (all == null) return null;

    Vec2 point = convertCoordinateSystem(new Vec2(e.after.x, e.after.y));

    Set<FLine> hit = new LinkedHashSet<>();

    Window.Event<Window.MouseState> eMarked = e /*.copy()*/;
    eMarked.properties.put(interaction, this);

    List<Mouse.Dragger> draggers =
        all.stream()
            .filter(f -> f.attributes.get(projectedArea) != null)
            .filter(f -> f.attributes.get(projectedArea).apply(f).contains(point.x, point.y))
            .flatMap(
                f -> f.attributes.getOr(Mouse.onMouseDown, Collections::emptyMap).values().stream())
            .map(omd -> omd.onMouseDown(eMarked, button))
            .filter(x -> x != null)
            .collect(Collectors.toList());

    if (draggers.size() > 0) {
      return (event, termination) -> {

        //				event = event.copy();
        event.properties.put(interaction, this);

        Iterator<Mouse.Dragger> it = draggers.iterator();
        while (it.hasNext()) {
          if (!it.next().update(event, termination)) it.remove();
        }
        return draggers.size() > 0;
      };
    }

    return null;
  }
示例#2
0
  @Override
  public Mouse.Dragger onMouseMove(Window.Event<Window.MouseState> e) {
    if (all == null) return null;

    Vec2 point = convertCoordinateSystem(new Vec2(e.after.x, e.after.y));

    Set<FLine> hit = new LinkedHashSet<FLine>();

    Window.Event<Window.MouseState> eMarked = e /*.copy()*/;
    eMarked.properties.put(interaction, this);

    Set<FLine> intersects =
        all.stream()
            .filter(f -> f.attributes.has(projectedArea))
            .filter(f -> f.attributes.get(projectedArea).apply(f).contains(point.x, point.y))
            .collect(Collectors.toSet());

    Set<FLine> enter = new LinkedHashSet<>(intersects);
    enter.removeAll(previousIntersection);

    Set<FLine> exit = new LinkedHashSet<>(previousIntersection);
    exit.removeAll(intersects);

    previousIntersection = intersects;

    List<Mouse.Dragger> draggers =
        intersects
            .stream()
            .flatMap(
                f -> f.attributes.getOr(Mouse.onMouseMove, Collections::emptyMap).values().stream())
            .map(omd -> omd.onMouseMove(eMarked))
            .filter(x -> x != null)
            .collect(Collectors.toList());

    draggers.addAll(
        enter
            .stream()
            .flatMap(
                f ->
                    f.attributes.getOr(Mouse.onMouseEnter, Collections::emptyMap).values().stream())
            .map(omd -> omd.onMouseEnter(eMarked))
            .filter(x -> x != null)
            .collect(Collectors.toList()));

    exit.stream()
        .flatMap(
            f -> f.attributes.getOr(Mouse.onMouseExit, Collections::emptyMap).values().stream())
        .forEach(omd -> omd.onMouseExit(eMarked));

    if (draggers.size() > 0) {
      return (event, termination) -> {
        //				event = event.copy();
        event.properties.put(interaction, this);

        Iterator<Mouse.Dragger> it = draggers.iterator();
        while (it.hasNext()) {
          if (!it.next().update(event, termination)) it.remove();
        }
        return draggers.size() > 0;
      };
    }

    return null;
  }