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

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


    final Rectangle bounds = og.getBounds();
    Iterator<MapObject> itr = og.getObjects();
    g2d.translate(bounds.x * tsize.width, bounds.y * tsize.height);

    while (itr.hasNext()) {
      MapObject mo = itr.next();
      double ox = mo.getX() * zoom;
      double oy = mo.getY() * zoom;

      Image objectImage = mo.getImage(zoom);
      if (objectImage != null) {
        g2d.drawImage(objectImage, (int) ox, (int) oy, null);
      }

      if (mo.getWidth() == 0 || mo.getHeight() == 0) {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setColor(Color.black);
        g2d.fillOval((int) ox + 1, (int) oy + 1, (int) (10 * zoom), (int) (10 * zoom));
        g2d.setColor(Color.orange);
        g2d.fillOval((int) ox, (int) oy, (int) (10 * zoom), (int) (10 * zoom));
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
      } else {
        g2d.setColor(Color.black);
        g2d.drawRect((int) ox + 1, (int) oy + 1, (int) (mo.getWidth() * zoom), (int) (mo.getHeight() * zoom));
        g2d.setColor(Color.orange);
        g2d.drawRect((int) ox, (int) oy, (int) (mo.getWidth() * zoom), (int) (mo.getHeight() * zoom));
      }
      if (zoom > 0.0625) {
        final String s = mo.getName() != null ? mo.getName() : "(null)";
        g2d.setColor(Color.black);
        g2d.drawString(s, (int) (ox - 5) + 1, (int) (oy - 5) + 1);
        g2d.setColor(Color.white);
        g2d.drawString(s, (int) (ox - 5), (int) (oy - 5));
      }
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();
View Full Code Here

      } else if (mouseButton == MouseEvent.BUTTON1 && layer instanceof ObjectGroup) {
        // TODO: Fix this to use pixels in the first place
        // (with optional snap to grid)
        int w = currentMap.getTileWidth();
        int h = currentMap.getTileHeight();
        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;
View Full Code Here

  protected void paintObjectGroup(Graphics2D g, ObjectGroup og) {
    // NOTE: Direct copy from OrthoMapView (candidate for generalization)
    Iterator<?> itr = og.getObjects();

    while (itr.hasNext()) {
      MapObject mo = (MapObject) itr.next();
      double ox = mo.getX() * zoom;
      double oy = mo.getY() * zoom;

      if (mo.getWidth() == 0 || mo.getHeight() == 0) {
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(Color.black);
        g.fillOval((int) ox + 1, (int) oy + 1, (int) (10 * zoom), (int) (10 * zoom));
        g.setColor(Color.orange);
        g.fillOval((int) ox, (int) oy, (int) (10 * zoom), (int) (10 * zoom));
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
      } else {
        g.setColor(Color.black);
        g.drawRect((int) ox + 1, (int) oy + 1, (int) (mo.getWidth() * zoom), (int) (mo.getHeight() * zoom));
        g.setColor(Color.orange);
        g.drawRect((int) ox, (int) oy, (int) (mo.getWidth() * zoom), (int) (mo.getHeight() * zoom));
      }
      if (zoom > 0.0625) {
        final String s = mo.getName() != null ? mo.getName() : "(null)";
        g.setColor(Color.black);
        g.drawString(s, (int) (ox - 5) + 1, (int) (oy - 5) + 1);
        g.setColor(Color.white);
        g.drawString(s, (int) (ox - 5), (int) (oy - 5));
      }
View Full Code Here

    final int x = getAttribute(t, "x", 0);
    final int y = getAttribute(t, "y", 0);
    final int width = getAttribute(t, "width", 0);
    final int height = getAttribute(t, "height", 0);

    MapObject obj = new MapObject(x, y, width, height);
    if (name != null) {
      obj.setName(name);
    }
    if (type != null) {
      obj.setType(type);
    }

    NodeList children = t.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if ("image".equalsIgnoreCase(child.getNodeName())) {
        String source = getAttributeValue(child, "source");
        if (source != null) {
          if (!new File(source).isAbsolute()) {
            source = xmlPath + source;
          }
          obj.setImageSource(source);
        }
        break;
      }
    }

    Properties props = new Properties();
    readProperties(children, props);

    obj.setProperties(props);
    return obj;
  }
View Full Code Here

TOP

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

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.