Package tiled.core

Examples of tiled.core.MapLayer


    viewer = new CheckboxTableViewer(table);
    TableViewerColumn mainColumn = new TableViewerColumn(viewer,SWT.LEFT,0);
    mainColumn.setLabelProvider(new ColumnLabelProvider() {
      @Override
      public String getText(Object element) {
        MapLayer p = (MapLayer) element;
        return p.getName();
      }
     
     
    });
    TableLayout layout = new TableLayout();
View Full Code Here


    // Resize and select the region
    Rectangle brushRedraw = currentBrush.getBounds();
    cursorHighlight.resize(brushRedraw.width, brushRedraw.height, 0, 0);
    cursorHighlight.selectRegion(currentBrush.getShape());
    MapLayer layer = currentBrush.getLayer(0);
    cursorHighlight.copyTileData(layer);
    if (mapView != null) {
      mapView.setBrush(currentBrush);
    }
  }
View Full Code Here

    bMouseIsDown = true;
    bMouseIsDragging = false;
    mousePressLocation = mapView.screenToTileCoords(e.x, e.y);
    mouseInitialPressLocation = mousePressLocation;

    MapLayer layer = getCurrentLayer();

    if (mouseButton == 2
        || (mouseButton == 1 && (e.stateMask & SWT.ALT) != 0)) {
      // Remember screen location for scrolling with middle mouse button
      mouseInitialScreenLocation = new Point(e.x, e.y);
View Full Code Here

    doMouse(e);
    bMouseIsDragging = true;
  }

  public void mouseReleased(MouseEvent event) {
    final MapLayer layer = getCurrentLayer();
    final Point limp = mouseInitialPressLocation;
   
    if (event.button == 1 && currentDragger != null) {
      currentDragger.handleDragFinish(event);
      currentDragger = null;

      mouseButton = SWT.DEFAULT;
      bMouseIsDown = false;
      bMouseIsDragging = false;
      mapView.redraw();
      return;
    }

    if (currentPointerState == PS_MARQUEE) {
      // Uncommented to allow single tile selections
      /*
       * Point tile = mapView.screenToTileCoords(event.x, event.y); if
       * (tile.y - limp.y == 0 && tile.x - limp.x == 0) { if
       * (marqueeSelection != null) {
       * currentMap.removeLayerSpecial(marqueeSelection); marqueeSelection
       * = null; } }
       */

      // There should be a proper notification mechanism for this...
      // if (marqueeSelection != null) {
      // tileInstancePropertiesDialog.setSelection(marqueeSelection);
      // }
    } else if (currentPointerState == PS_MOVE) {
      if (layer != null && (moveDist.x != 0 || moveDist.y != 0)) {
         addEdit(new MoveLayerEdit(layer, moveDist));
      }
    } else if (currentPointerState == PS_PAINT) {
      if (layer instanceof TileLayer) {
        currentBrush.endPaint();
      }
    } else if (currentPointerState == PS_MOVEOBJ) {
      if (initialObjectLocation != null && currentObject != null) {
        Point translation = new Point(currentObject.getX() - initialObjectLocation.x, currentObject.getY() - initialObjectLocation.y);
        if (layer instanceof ObjectGroup && currentObject != null
            && (translation.x != 0 || translation.y != 0)) {
           addEdit(new MoveObjectsEdit(currentObject, translation));
           initialObjectLocation = null;
        }
      }
    }

    if (/* bMouseIsDragging && */currentPointerState == PS_PAINT
        || currentPointerState == PS_ADDOBJ) {
      Point tile = mapView.screenToTileCoords(event.x, event.y);
      int minx = Math.min(limp.x, tile.x);
      int miny = Math.min(limp.y, tile.y);

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

      // STAMP
      if (mouseButton == 3 && layer instanceof TileLayer) {
        // Right mouse button dragged: create and set custom brush
        TileLayer brushLayer = new TileLayer(bounds);
        brushLayer.copyFrom(getCurrentLayer());
        brushLayer.setOffset(tile.x - (int) bounds.width / 2, tile.y
            - (int) bounds.height / 2);

        // Do a quick check to make sure the selection is not empty
        if (brushLayer.isEmpty()) {
          MessageDialog.openInformation(getSite().getShell(),
          Resources.getString("dialog.selection.empty"),
          Resources.getString("dialog.selection.empty"));
        } else {
          setBrush(new CustomBrush(brushLayer));
          cursorHighlight.setOffset(tile.x - (int) bounds.width / 2,
              tile.y - (int) bounds.height / 2);
        }
      } else if (mouseButton == 1 && 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.x, event.y);
         */
        ObjectGroup group = (ObjectGroup) layer;
         addEdit(new AddObjectsEdit(group, object));
        group.addObject(object);
        mapView.redraw();
      }

      // get rid of any visible marquee
      if (marqueeSelection != null) {
        currentMap.removeLayerSpecial(marqueeSelection);
        setMarqueeSelection(null);
      }
    }

    if (paintEdit != null) {
      if (layer != null) {
        try {
          MapLayer endLayer = paintEdit.getStart().createDiff(layer);
          paintEdit.end(endLayer);
          addEdit(paintEdit);
        } catch (Exception e) {
          e.printStackTrace();
        }
View Full Code Here

    if (currentMap == null || currentLayer < 0) {
      return;
    }

    Point tile = mapView.screenToTileCoords(event.x, event.y);
    MapLayer layer = getCurrentLayer();

    if (layer == null) {
      return;
    } else if (mouseButton == 3) {
      if (layer instanceof TileLayer) {
        if (!bMouseIsDragging) {
          // Click event is sent before the drag event
          // so this one always happens
          Tile newTile = ((TileLayer) layer)
              .getTileAt(tile.x, tile.y);
          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;
View Full Code Here

      if (!redraw.equals(brushRedraw)) {
        if (currentBrush instanceof CustomBrush) {
          CustomBrush customBrush = (CustomBrush) currentBrush;
          ListIterator<MapLayer> layers = customBrush.getLayers();
          while (layers.hasNext()) {
            MapLayer layer = layers.next();
            layer.setOffset(brushRedraw.x, brushRedraw.y);
          }
        }
        if (currentBrush instanceof ITileBrush && ((ITileBrush) currentBrush).getTile() != null)
          mapView.repaintRegion(redraw, ((ITileBrush) currentBrush).getTile().getSize());
        else
View Full Code Here

        if (currentMap != null && marqueeSelection != null) {
            clipboardLayer = new TileLayer(
                    marqueeSelection.getSelectedAreaBounds());
            ListIterator<?> itr = currentMap.getLayers();
            while(itr.hasNext()) {
                MapLayer layer = (MapLayer) itr.next();
                if (layer instanceof TileLayer) {
                    clipboardLayer.maskedMergeOnto(
                            layer,
                            marqueeSelection.getSelectedArea());
                }
View Full Code Here

  }
 
  protected ObjectSelectionLayer getObjectSelectionLayer() {
    Iterator<MapLayer> layers = currentMap.getLayersSpecial();
    for (; layers.hasNext();) {
      MapLayer next = layers.next();
      if (next instanceof ObjectSelectionLayer) {
        return (ObjectSelectionLayer) next;
      }
    }
    return null;
View Full Code Here

//              Resources.getString("action.layer.duplicate.name"),
//              Resources.getString("action.layer.duplicate.tooltip"), Resources.getImageDescriptor("gimp-duplicate-16.png"));
//    }

    protected void doPerformAction() {
        MapLayer currentLayer = editor.getCurrentLayer();
        Map currentMap = editor.getMap();

        if (currentLayer != null) {
            try {
                MapLayer clone = (MapLayer) currentLayer.clone();
                String newName = Resources.getString(
                        "action.layer.duplicate.newlayer.name");
                clone.setName(MessageFormat.format(newName, new Object[]{clone.getName()}));
                currentMap.addLayer(clone);
                editor.setCurrentLayer(currentMap.getTotalLayers() - 1);
            } catch (CloneNotSupportedException ex) {
                ex.printStackTrace();
            }
View Full Code Here

public class AddLayerAction extends AbstractLayerAction
{

    protected void doPerformAction() {
        Map currentMap = editor.getMap();
        MapLayer newLayer = currentMap.addLayer();
        editor.setCurrentLayer(currentMap.getTotalLayers() - 1);
        if (viewer != null)
          viewer.editElement(newLayer,0);
    }
View Full Code Here

TOP

Related Classes of tiled.core.MapLayer

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.