Package de.yaams.extensions.basemap.tiled.mapeditor.selection

Examples of de.yaams.extensions.basemap.tiled.mapeditor.selection.SelectionLayer


    undoHandler = new UndoHandler(this);
    undoSupport = new UndoableEditSupport();
    undoSupport.addUndoableEditListener(undoHandler);

    cursorHighlight = new SelectionLayer(1, 1);
    cursorHighlight.select(0, 0);
    cursorHighlight.setVisible(prefs.getBoolean("cursorhighlight", true));

    mapEventAdapter = new MapEventAdapter();
View Full Code Here


          setCurrentTile(newTile);
        } else if (currentPointerState == PS_PAINT) {
          // In case we are dragging to create a custom brush, let
          // the user know where we are creating it from
          if (marqueeSelection == null) {
            marqueeSelection = new SelectionLayer(currentMap.getWidth(), currentMap.getHeight());
            currentMap.addLayerSpecial(marqueeSelection);
          }

          Point limp = mouseInitialPressLocation;
          Rectangle oldArea = marqueeSelection.getSelectedAreaBounds();
          int minx = Math.min(limp.x, tile.x);
          int miny = Math.min(limp.y, tile.y);

          Rectangle selRect = new Rectangle(minx, miny, Math.max(limp.x, tile.x) - minx + 1, Math.max(limp.y, tile.y) - miny + 1);

          marqueeSelection.selectRegion(selRect);
          if (oldArea != null) {
            oldArea.add(marqueeSelection.getSelectedAreaBounds());
            mapView.repaintRegion(oldArea);
          }
        }
      } else if (layer instanceof ObjectGroup && !bMouseIsDragging) {
        // Get the object on this location and display the relative
        // options dialog
        ObjectGroup group = (ObjectGroup) layer;
        Point pos = mapView.screenToPixelCoords(event.getX(), event.getY());
        MapObject obj = group.getObjectNear(pos.x, pos.y, mapView.getZoom());
        if (obj != null) {
          ObjectDialog od = new ObjectDialog(YaFrame.get(), obj, undoSupport);
          od.getProps();
        }
      }
    } else if (mouseButton == MouseEvent.BUTTON2 || mouseButton == MouseEvent.BUTTON1
        && (event.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
      // Scroll with middle mouse button
      int dx = event.getX() - mouseInitialScreenLocation.x;
      int dy = event.getY() - mouseInitialScreenLocation.y;
      JViewport mapViewPort = mapScrollPane.getViewport();
      Point currentPosition = mapViewPort.getViewPosition();
      mouseInitialScreenLocation = new Point(event.getX() - dx, event.getY() - dy);

      Point newPosition = new Point(currentPosition.x - dx, currentPosition.y - dy);

      // Take into account map boundaries in order to prevent
      // scrolling past them
      int maxX = mapView.getWidth() - mapViewPort.getWidth();
      int maxY = mapView.getHeight() - mapViewPort.getHeight();
      newPosition.x = Math.min(maxX, Math.max(0, newPosition.x));
      newPosition.y = Math.min(maxY, Math.max(0, newPosition.y));

      mapViewPort.setViewPosition(newPosition);
    } else if (mouseButton == MouseEvent.BUTTON1) {
      switch (currentPointerState) {
      case PS_PAINT:
        paintEdit.setPresentationName(TOOL_PAINT);
        if (layer instanceof TileLayer) {
          try {
            mapView.repaintRegion(currentBrush.doPaint(tile.x, tile.y));
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
        break;
      case PS_ERASE:
        paintEdit.setPresentationName(TOOL_ERASE);
        if (layer instanceof TileLayer) {
          ((TileLayer) layer).setTileAt(tile.x, tile.y, null);
          mapView.repaintRegion(new Rectangle(tile.x, tile.y, 1, 1));
        }
        break;
      case PS_POUR:
        paintEdit = null;
        if (layer instanceof TileLayer) {
          TileLayer tileLayer = (TileLayer) layer;
          Tile oldTile = tileLayer.getTileAt(tile.x, tile.y);
          pour(tileLayer, tile.x, tile.y, currentTile, oldTile);
          mapView.repaint();
        }
        break;
      case PS_EYED:
        if (layer instanceof TileLayer) {
          TileLayer tileLayer = (TileLayer) layer;
          Tile newTile = tileLayer.getTileAt(tile.x, tile.y);
          setCurrentTile(newTile);
        }
        break;
      case PS_MOVE: {
        Point translation = new Point(tile.x - mousePressLocation.x, tile.y - mousePressLocation.y);

        layer.translate(translation.x, translation.y);
        moveDist.translate(translation.x, translation.y);
        mapView.repaint();
        break;
      }
      case PS_MARQUEE:
        if (!(layer instanceof TileLayer)) {
          break;
        }
        if (marqueeSelection != null) {
          Point limp = mouseInitialPressLocation;
          Rectangle oldArea = marqueeSelection.getSelectedAreaBounds();
          int minx = Math.min(limp.x, tile.x);
          int miny = Math.min(limp.y, tile.y);

          Rectangle selRect = new Rectangle(minx, miny, Math.max(limp.x, tile.x) - minx + 1, Math.max(limp.y, tile.y) - miny + 1);

          if (event.isShiftDown()) {
            marqueeSelection.add(new Area(selRect));
          } else if (event.isControlDown()) {
            marqueeSelection.subtract(new Area(selRect));
          } else {
            marqueeSelection.selectRegion(selRect);
          }
          if (oldArea != null) {
            oldArea.add(marqueeSelection.getSelectedAreaBounds());
            mapView.repaintRegion(oldArea);
          }
        }
        break;
      case PS_ADDOBJ:
        if (layer instanceof ObjectGroup) {
          if (marqueeSelection == null) {
            marqueeSelection = new SelectionLayer(currentMap.getWidth(), currentMap.getHeight());
            currentMap.addLayerSpecial(marqueeSelection);
          }

          Point limp = mouseInitialPressLocation;
          Rectangle oldArea = marqueeSelection.getSelectedAreaBounds();
View Full Code Here

      boolean contains = false;
      if (marqueeSelection != null && marqueeSelection.getSelectedArea().contains(tile.x, tile.y)) {
        contains = true;
      }
      if (marqueeSelection == null && !contains) {
        marqueeSelection = new SelectionLayer(currentMap.getWidth(), currentMap.getHeight());
        currentMap.addLayerSpecial(marqueeSelection);
      } else if (marqueeSelection != null && e.getModifiers() == InputEvent.BUTTON1_MASK) {
        currentMap.removeLayerSpecial(marqueeSelection);
        if (contains) {
          marqueeSelection = null;
        } else {
          marqueeSelection = new SelectionLayer(currentMap.getWidth(), currentMap.getHeight());
          currentMap.addLayerSpecial(marqueeSelection);
        }
      }
    } else if (currentPointerState == PS_MOVE) {
      // Initialize move distance to (0, 0)
View Full Code Here

    public void actionPerformed(ActionEvent e) {
      if (currentMap != null) {
        if (marqueeSelection != null) {
          currentMap.removeLayerSpecial(marqueeSelection);
        }
        marqueeSelection = new SelectionLayer(currentMap.getWidth(), currentMap.getHeight());
        marqueeSelection.selectRegion(marqueeSelection.getBounds());
        currentMap.addLayerSpecial(marqueeSelection);
      }
    }
View Full Code Here

    } else if (command.equals(FIND_ALL_BUTTON)) {
      if (sl != null) {
        map.removeLayerSpecial(sl);
      }

      sl = new SelectionLayer(map.getWidth(), map.getHeight());
      Rectangle bounds = new Rectangle();
      final Iterator<MapLayer> itr = map.getLayers();
      while (itr.hasNext()) {
        MapLayer layer = itr.next();
        if (layer instanceof TileLayer) {
View Full Code Here

    if (sl != null) {
      map.removeLayerSpecial(sl);
      map.touch();
    }

    sl = new SelectionLayer(map.getWidth(), map.getHeight());
    Rectangle bounds = new Rectangle();

    int startx = currentMatch == null ? 0 : currentMatch.x;
    int starty = currentMatch == null ? 0 : currentMatch.y;
View Full Code Here

TOP

Related Classes of de.yaams.extensions.basemap.tiled.mapeditor.selection.SelectionLayer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.