Package tiled.core

Examples of tiled.core.Tile


    private void init() {
        Preferences prefs = TiledConfiguration.root();
        highlightColor = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);

        selTile = new Tile();
        selection = new Area();
    }
View Full Code Here


    }

    public Tile createCell(int tx, int ty, int start, int len, boolean all) {
        Cell c = new Cell(myMap, tx, ty, start, len, all);
        Iterator<Cell> itr = cells.iterator();
        Tile tile;

        while (itr.hasNext()) {
            Cell check = itr.next();
            if (check.equals(c)) {
                return check.getTile();
            }
        }

        cells.add(c);

        tile = new Tile();
        c.setTile(tile);

        //GENERATE MERGED TILE IMAGE
        //FIXME: although faster, the following doesn't seem to handle alpha on some platforms...
//        GraphicsConfiguration config =
//            GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        Image tileImg = new Image(Display.getDefault(),c.getWidth(),c.getHeight());
        GC gc = new GC(tileImg);
    c.render(gc);
    gc.dispose();
        tile.setImage(tileImg);

        myTs.addTile(tile);

        return tile;
    }
View Full Code Here

        public boolean equals(Cell c) {
            Iterator<Tile> me = sandwich.iterator();
            Iterator<Tile> them = c.sandwich.iterator();
            while (me.hasNext()) {
                Tile m = me.next();
                Tile t = them.next();
                if (m != null && t != null && !m.equals(t)) {
                    return false;
                } else if (m != null && t != null && t != m) {
                    return false;
                } else if ((m != null && t == null) || (m == null && t != null)) {
View Full Code Here

        // Draw this map layer
        for (int y = 0; y < rows; y++) {
            Point columnItr = new Point(rowItr.x,rowItr.y);

            for (int x = 0; x < columns; x++) {
                Tile tile = layer.getTileAt(columnItr.x, columnItr.y);

                if (tile != null) {
                    if (layer instanceof SelectionLayer) {
                      if (shouldPaintBrushTile())
                        RenderingUtil.drawTile(gc, tile, drawLoc.x, drawLoc.y, zoom);
View Full Code Here

    } 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,
View Full Code Here

    setBrush(sb);

    // Get the first non-null tile from the first tileset containing
    // non-null tiles.
    Vector<TileSet> tilesets = currentMap.getTilesets();
    Tile firstTile = null;
    if (!tilesets.isEmpty()) {
      Iterator<TileSet> it = tilesets.iterator();
      while (it.hasNext() && firstTile == null) {
        firstTile = it.next().getFirstTile();
      }
View Full Code Here

        tiles = new NumberedSet();
        images = new NumberedSet();
        tileDimensions = new Rectangle(0,0,0,0);
        defaultTileProperties = new Properties();
        tilesetChangeListeners = new LinkedList();
        whiteTile = new Tile();
        whiteTile.setImage(new Image(Display.getDefault(),new Rectangle(0,0,32,32)));
    }
View Full Code Here

            tilesPerRow = basicTileCutter.getTilesPerRow();
        }

        Image tile = cutter.getNextTile();
        while (tile != null) {
            Tile newTile = new Tile();
            newTile.setImage(addImage(tile));
            addNewTile(newTile);
            tile = cutter.getNextTile();
        }
    }
View Full Code Here

     *
     * @return The first tile in this tileset, or <code>null</code> if none
     *         exists.
     */
    public Tile getFirstTile() {
        Tile ret = null;
        int i = 0;
        while (ret == null && i <= getMaxTileId()) {
            ret = getTile(i);
            i++;
        }
View Full Code Here

        for (int id = 0; id <= images.getMaxId(); ++id) {
            int relations = 0;
            itr = iterator();

            while (itr.hasNext()) {
                Tile t = (Tile) itr.next();
                // todo: move the null check back into the iterator?
                if (t != null && t.getImageId() == id) {
                    relations++;
                }
            }
            if (relations != 1) {
                return false;
View Full Code Here

TOP

Related Classes of tiled.core.Tile

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.