コード例 #1
0
 private void fireTilesChangedIncludeBorder(Set<Tile> tiles) {
   if (showBorder
       && (tileProvider instanceof Dimension)
       && (((Dimension) tileProvider).getDim() == DIM_NORMAL)
       && (((Dimension) tileProvider).getBorder() != null)) {
     final Set<Point> coordSet = new HashSet<>();
     for (Tile tile : tiles) {
       final int tileX = tile.getX(),
           tileY = tile.getY(),
           borderSize = ((Dimension) tileProvider).getBorderSize();
       for (int dx = -borderSize; dx <= borderSize; dx++) {
         for (int dy = -borderSize; dy <= borderSize; dy++) {
           coordSet.add(getTileCoordinates(tileX + dx, tileY + dy));
         }
       }
     }
     for (TileListener listener : listeners) {
       listener.tilesChanged(this, coordSet);
     }
   } else {
     Set<Point> coords = tiles.stream().map(this::getTileCoordinates).collect(Collectors.toSet());
     for (TileListener listener : listeners) {
       listener.tilesChanged(this, coords);
     }
   }
 }
コード例 #2
0
ファイル: FLineInteraction.java プロジェクト: cassiel/Field2
  @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;
  }
コード例 #3
0
ファイル: FLineInteraction.java プロジェクト: cassiel/Field2
  @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;
  }