Package de.yaams.extensions.basemap.tiled.core

Examples of de.yaams.extensions.basemap.tiled.core.ObjectGroup


      if (marqueeSelection != null) {
        if (currentLayer instanceof TileLayer) {
          layer = new TileLayer(marqueeSelection.getSelectedAreaBounds());
        } else if (currentLayer instanceof ObjectGroup) {
          layer = new ObjectGroup(marqueeSelection.getSelectedAreaBounds());
        }
        layer.setMap(currentMap);
        layer.maskedCopyFrom(currentLayer, marqueeSelection.getSelectedArea());
      }
View Full Code Here


    public void actionPerformed(ActionEvent evt) {
      if (currentMap != null && marqueeSelection != null) {
        if (getCurrentLayer() instanceof TileLayer) {
          clipboardLayer = new TileLayer(marqueeSelection.getSelectedAreaBounds());
        } else if (getCurrentLayer() instanceof ObjectGroup) {
          clipboardLayer = new ObjectGroup(marqueeSelection.getSelectedAreaBounds());
        }
        clipboardLayer.maskedCopyFrom(getCurrentLayer(), marqueeSelection.getSelectedArea());
      }
    }
View Full Code Here

        MapLayer ml = getCurrentLayer();

        if (getCurrentLayer() instanceof TileLayer) {
          clipboardLayer = new TileLayer(marqueeSelection.getSelectedAreaBounds());
        } else if (getCurrentLayer() instanceof ObjectGroup) {
          clipboardLayer = new ObjectGroup(marqueeSelection.getSelectedAreaBounds());
        }
        clipboardLayer.maskedCopyFrom(ml, marqueeSelection.getSelectedArea());

        Rectangle area = marqueeSelection.getSelectedAreaBounds();
        Area mask = marqueeSelection.getSelectedArea();
View Full Code Here

          }
        }
      } 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();
          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_REMOVEOBJ:
        if (layer instanceof ObjectGroup) {
          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) {
            undoSupport.postEdit(new RemoveObjectEdit(group, obj));
            group.removeObject(obj);
            // TODO: repaint only affected area
            mapView.repaint();
          }
        }
        break;
      case PS_MOVEOBJ:
        if (layer instanceof ObjectGroup) {
          Point pos = mapView.screenToPixelCoords(event.getX(), event.getY());
          if (currentObject == null) {
            ObjectGroup group = (ObjectGroup) layer;
            currentObject = group.getObjectNear(pos.x, pos.y, mapView.getZoom());
            if (currentObject == null) { // No object to move
              break;
            }
            mouseLastPixelLocation = pos;
            moveDist = new Point(0, 0);
View Full Code Here

        MapObject object = new MapObject(bounds.x * w, bounds.y * h, bounds.width * w, bounds.height * h);
        /*
         * Point pos = mapView.screenToPixelCoords( event.getX(),
         * event.getY());
         */
        ObjectGroup group = (ObjectGroup) layer;
        undoSupport.postEdit(new AddObjectEdit(group, object));
        group.addObject(object);
        mapView.repaint();
      }

      // get rid of any visible marquee
      if (marqueeSelection != null) {
View Full Code Here

    return tile;
  }

  private MapLayer unmarshalObjectGroup(Node t) throws Exception {
    ObjectGroup og = null;
    try {
      og = (ObjectGroup) unmarshalClass(ObjectGroup.class, t);
    } catch (Exception e) {
      e.printStackTrace();
      return og;
    }

    final int offsetX = getAttribute(t, "x", 0);
    final int offsetY = getAttribute(t, "y", 0);
    og.setOffset(offsetX, offsetY);

    // Add all objects from the objects group
    NodeList children = t.getChildNodes();

    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if ("object".equalsIgnoreCase(child.getNodeName())) {
        og.addObject(readMapObject(child));
      }
    }

    Properties props = new Properties();
    readProperties(children, props);
    og.setProperties(props);

    return og;
  }
View Full Code Here

    MapLayer ml = new TileLayer(ret, ret.getWidth(), ret.getHeight());
    ml.setName("bg");
    ret.addLayer(ml);
    for (int i = 1; i < 7; i++) {
      // TODO: I believe this should be ObjectGroup
      ml = new ObjectGroup(ret, 0, 0);
      ml.setName("ObjectLayer " + i);
      ret.addLayer(ml);
    }
    ml = new TileLayer(ret, ret.getWidth(), ret.getHeight());
    ml.setName("fg 1");
View Full Code Here

   * @param m
   *            the object to write
   * @throws java.io.IOException
   */
  private void writeObject(MapObject m) throws IOException {
    final ObjectGroup o = m.getObjectGroup();
    final Rectangle b = o.getBounds();
    startTable();
    writelnKeyAndValue("label", "object");

    // TODO: The object groups coordinates are in tiles, not pixels
    writelnKeyAndValue("x", m.getX() + b.x);
View Full Code Here

TOP

Related Classes of de.yaams.extensions.basemap.tiled.core.ObjectGroup

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.