Package tiled.mapeditor.selection

Examples of tiled.mapeditor.selection.SelectionLayer


        } 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 itr = map.getLayers();
            while (itr.hasNext()) {
                MapLayer layer = (MapLayer) 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

        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 UnitGroup && !bMouseIsDragging) {
                // Get the unit on this location and display the relative options dialog
                UnitGroup group = (UnitGroup) layer;
                Point pos = mapView.screenToPixelCoords(
                        event.getX(), event.getY());
                MapUnit unit = group.getUnitAt(pos.x, pos.y);
                if (unit != null) {
                    UnitDialog od = new UnitDialog(appFrame, unit, undoSupport);
                    od.getProps();
                    //TODO change to only updating the unit if that isn't done automatically yet
                    mapChanged(new MapChangedEvent(currentMap));
                }
            } else if (layer instanceof ZoneGroup && !bMouseIsDragging) {
                // Get the zone on this location and display the relative options dialog
                ZoneGroup group = (ZoneGroup) layer;
                Point pos = mapView.screenToPixelCoords(
                        event.getX(), event.getY());
                MapZone zone = group.getZoneAt(pos.x, pos.y);
                if (zone != null) {
                    ZoneDialog od = new ZoneDialog(appFrame, zone, undoSupport);
                    od.updateInfo();
                    od.setVisible(true);
                    //TODO change to only updating the zone, if that isn't done automatically yet
                    mapChanged(new MapChangedEvent(currentMap));
                }
            }
        } else if (mouseButton == MouseEvent.BUTTON2 ||
                (mouseButton == MouseEvent.BUTTON1 &&
                 (event.getModifiersEx() & MouseEvent.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));
                          if(currentTile instanceof AnimatedTile) {
                            animatedTiles.add(new AnimTile(tile.x, tile.y, (AnimatedTile) currentTile, layer));
                          }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                case PS_ERASE:
                    paintEdit.setPresentationName(TOOL_ERASE);
                    if (layer instanceof TileLayer) {
                      if(((TileLayer) layer).getTileAt(tile.x, tile.y) instanceof AnimatedTile) {
                        removeAnimTileAt(tile.x, tile.y);
                      }
                        ((TileLayer) layer).setTileAt(tile.x, tile.y, null);
                        mapView.repaintRegion(new Rectangle(
                                tile.x, tile.y, 1, 1));
                    }
                    break;
                case PS_POUR:
                  //TODO add animated tiles here, is a real bitch due to undo/redo
                    paintEdit = null;
                    if (layer instanceof TileLayer) {
                      if(!(currentTile instanceof AnimatedTile)) {
                          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:
                    if (layer instanceof TileLayer) {
                        Point translation = new Point(
                                tile.x - mousePressLocation.x,
                                tile.y - mousePressLocation.y);

                        translateAnimTiles(translation, layer);
                        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_ADDUNIT:
                    if (layer instanceof  UnitGroup) {
                        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);
                        }
                    }
                    break;
                case PS_REMOVEUNIT:
                  if (layer instanceof UnitGroup) {
                        UnitGroup group = (UnitGroup) layer;
                        Point pos = mapView.screenToPixelCoords(
                                event.getX(), event.getY());
                        MapUnit unit = group.getUnitAt(pos.x, pos.y);
                        if (unit != null) {
                            undoSupport.postEdit(new RemoveUnitEdit(group, unit));
                            group.removeUnit(unit);
                            // TODO: repaint only affected area
                            mapView.repaint();
                        }
                    } else if (layer instanceof ZoneGroup) {
                        ZoneGroup group = (ZoneGroup) layer;
                        Point pos = mapView.screenToPixelCoords(
                                event.getX(), event.getY());
                        MapZone zone = group.getZoneAt(pos.x, pos.y);
                        if (zone != null) {
                            undoSupport.postEdit(new RemoveZoneEdit(group, zone));
                            group.removeZone(zone);
                            // TODO: repaint only affected area
                            mapView.repaint();
                        }
                    }
                    break;
                case PS_MOVEUNIT:
                  if (layer instanceof UnitGroup) {
                        Point pos = mapView.screenToPixelCoords(
                                event.getX(), event.getY());
                        if (currentUnit == null) {
                            UnitGroup group = (UnitGroup) layer;
                            currentUnit = group.getUnitAt(pos.x, pos.y);
                            if (currentUnit == null) { // No unit to move
                                break;
                            }
                            mouseLastPixelLocation = pos;
                            moveDist = new Point(0, 0);
                            break;
                        }
                        Point translation = new Point(
                                pos.x - mouseLastPixelLocation.x,
                                pos.y - mouseLastPixelLocation.y);
                        currentUnit.translate(translation.x, translation.y);
                        moveDist.translate(translation.x, translation.y);
                        mouseLastPixelLocation = pos;
                        mapView.repaint();
                    } else if (layer instanceof ZoneGroup) {
                        Point pos = mapView.screenToPixelCoords(
                                event.getX(), event.getY());
                        if (currentZone == null) {
                            ZoneGroup group = (ZoneGroup) layer;
                            currentZone = group.getZoneAt(pos.x, pos.y);
                            if (currentZone == null) { // No unit to move
                                break;
                            }
                            mouseLastPixelLocation = pos;
                            moveDist = new Point(0, 0);
                            break;
                        }
                        Point translation = new Point(
                                pos.x - mouseLastPixelLocation.x,
                                pos.y - mouseLastPixelLocation.y);
                        currentZone.translate(translation.x, translation.y);
                        moveDist.translate(translation.x, translation.y);
                        mouseLastPixelLocation = pos;
                        mapView.repaint();
                    }
                    break;
                case PS_ADDZON:
                    if (layer instanceof  ZoneGroup) {
                        if (marqueeSelection == null) {
                            marqueeSelection = new SelectionLayer(
                                    currentMap.getWidth(),
                                    currentMap.getHeight());
                            currentMap.addLayerSpecial(marqueeSelection);
                        }
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) {
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

    mapView.addMouseMoveListener(mouseListener);
    mapView.addMouseTrackListener(mouseListener);
    mapScrollView.setContent(mapView);
    currentMap.addMapChangeListener(this);

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

    ShapeBrush sb = new ShapeBrush();
    sb.makeQuadBrush(new Rectangle(0, 0, 1, 1));
View Full Code Here

          && marqueeSelection.getSelectedArea().contains(tile.x,
              tile.y)) {
        contains = true;
      }
      if (marqueeSelection == null && !contains) {
        setMarqueeSelection(new SelectionLayer(currentMap.getWidth(),
            currentMap.getHeight()));
        currentMap.addLayerSpecial(marqueeSelection);
      } else if (marqueeSelection != null
          && (e.stateMask & SWT.BUTTON1) > 0) {
        currentMap.removeLayerSpecial(marqueeSelection);
        if (contains) {
          setMarqueeSelection(null);
        } else {
          setMarqueeSelection(new SelectionLayer(
              currentMap.getWidth(), currentMap.getHeight()));
          currentMap.addLayerSpecial(marqueeSelection);
        }
      }
    } else if (currentPointerState == PS_MOVE) {
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) {
            setMarqueeSelection(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(Converter
              .SWTRectToAWT(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.x, event.y);
        MapObject obj = group.getObjectNear(pos.x, pos.y,
            mapView.getZoom());
        if (obj != null) {
          int tileWidth = mapView.getMap().getTileWidth();
          int tileHeight = mapView.getMap().getTileHeight();
          ObjectPropertyDialog dialog = new ObjectPropertyDialog(
              getSite().getShell(), obj, this, tileWidth, tileHeight);
          dialog.open();
          mapView.redraw();
        }
      }
    } else if (mouseButton == 2
        || (mouseButton == 1 && (event.stateMask & SWT.ALT) != 0)) {
      // Scroll with middle mouse button
      int dx = event.x - mouseInitialScreenLocation.x;
      int dy = event.y - mouseInitialScreenLocation.y;
      Point currentPosition = mapScrollView.getOrigin();
      // JViewport mapViewPort = mapScrollPane.getViewport();
      // Point currentPosition = mapViewPort.getViewPosition();
      mouseInitialScreenLocation = new Point(event.x - dx, event.y - dy);

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

      // Take into account map boundaries in order to prevent
      // scrolling past them
      Point viewSize = mapView.getSize();
      Point viewportSize = mapScrollView.getSize();
      int maxX = viewSize.x - viewportSize.x;
      int maxY = viewSize.y - viewportSize.y;
      newPosition.x = Math.min(maxX, Math.max(0, newPosition.x));
      newPosition.y = Math.min(maxY, Math.max(0, newPosition.y));

      mapScrollView.setOrigin(newPosition);
      // mapViewPort.setViewPosition(newPosition);
    } else if (mouseButton == 1) {
      switch (currentPointerState) {
      case PS_PAINT:
         paintEdit.setPresentationName(TOOL_PAINT);
        if (layer instanceof TileLayer && canPaint(currentBrush)) {
          try {
            mapView.repaintRegion(currentBrush.doPaint(tile.x,
                tile.y));
            currentMap.fireMapChanged();
          } 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.redraw();
        }
        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);
        mousePressLocation = tile;
        moveDist.x += translation.x;
        moveDist.y += translation.y;
        mapView.redraw();
        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.stateMask & SWT.SHIFT) > 0) {
            marqueeSelection.add(new Area(Converter
                .SWTRectToAWT(selRect)));
          } else if ((event.stateMask & SWT.CONTROL) > 0) {
            marqueeSelection.subtract(new Area(Converter
                .SWTRectToAWT(selRect)));
          } else {
            marqueeSelection.selectRegion(Converter
                .SWTRectToAWT(selRect));
          }
          if (oldArea != null) {
            oldArea.add(marqueeSelection.getSelectedAreaBounds());
            mapView.repaintRegion(oldArea);
          }
        }
        break;
      case PS_ADDOBJ:
        if (layer instanceof ObjectGroup) {
          if (marqueeSelection == null) {
            setMarqueeSelection(new SelectionLayer(
                currentMap.getWidth(), currentMap.getHeight()));
            currentMap.addLayerSpecial(marqueeSelection);
          }

          Point limp = mouseInitialPressLocation;
View Full Code Here

TOP

Related Classes of 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.