[tiled] r710 - in trunk/src/tiled: core io/xml mapeditor mapeditor/actions mapeditor/dialogs mapeditor/resources view

svn at biggeruniverse.com svn at biggeruniverse.com
Fri Dec 15 02:12:05 PST 2006


Author: aturk
Date: 2006-12-15 04:12:04 -0600 (Fri, 15 Dec 2006)
New Revision: 710

Modified:
   trunk/src/tiled/core/Map.java
   trunk/src/tiled/core/TileLayer.java
   trunk/src/tiled/io/xml/XMLMapTransformer.java
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/actions/MergeAllLayersAction.java
   trunk/src/tiled/mapeditor/dialogs/TileDialog.java
   trunk/src/tiled/mapeditor/resources/gui.properties
   trunk/src/tiled/view/HexMapView.java
   trunk/src/tiled/view/IsoMapView.java
   trunk/src/tiled/view/MapView.java
   trunk/src/tiled/view/OrthoMapView.java
   trunk/src/tiled/view/ShiftedMapView.java
Log:
+ MapView and derivatives now support layers with independent tile dimensions (still alpha)
+ TileLayer changed slightly to support the above
+ Made "Merge All" more user-friendly
+ "Merge Down" now merges the current layer down

Modified: trunk/src/tiled/core/Map.java
===================================================================
--- trunk/src/tiled/core/Map.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/core/Map.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -411,6 +411,8 @@
 
     /**
      * Returns default tile width for this map.
+     * 
+     * @return the default tile width
      */
     public int getTileWidth() {
         return tileWidth;
@@ -418,6 +420,8 @@
 
     /**
      * Returns default tile height for this map.
+     * 
+     * @return the default tile height
      */
     public int getTileHeight() {
         return tileHeight;

Modified: trunk/src/tiled/core/TileLayer.java
===================================================================
--- trunk/src/tiled/core/TileLayer.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/core/TileLayer.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -12,6 +12,7 @@
 
 package tiled.core;
 
+import java.awt.Dimension;
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.geom.Area;
@@ -28,7 +29,8 @@
 {
     protected Tile[][] map;
     protected HashMap tileInstanceProperties = new HashMap();
-
+    protected Dimension tileDimensions;
+    
     public Properties getTileInstancePropertiesAt(int x, int y) {
         if (!bounds.contains(x, y)) {
             return null;
@@ -48,6 +50,7 @@
      * Default contructor.
      */
     public TileLayer() {
+        tileDimensions = new Dimension(0, 0);
     }
 
     /**
@@ -74,6 +77,7 @@
      */
     TileLayer(Map m) {
         super(m);
+        tileDimensions = new Dimension(m.getTileWidth(), m.getTileHeight());
     }
 
     /**
@@ -86,6 +90,16 @@
         setMap(m);
     }
 
+    public void setMap(Map m) {
+        super.setMap(m);
+        if(m != null)
+            tileDimensions = new Dimension(m.getTileWidth(), m.getTileHeight());
+    }
+    
+    public Dimension getTileSize() {
+        return new Dimension(tileDimensions);
+    }
+    
     /**
      * Rotates the layer by the given Euler angle.
      *
@@ -297,6 +311,9 @@
      *         outside this layer
      */
     public Tile getTileAt(int tx, int ty) {
+        if(!bounds.contains(tx, ty))
+            return null;
+        
         try {
             return map[ty - bounds.y][tx - bounds.x];
         } catch (ArrayIndexOutOfBoundsException e) {

Modified: trunk/src/tiled/io/xml/XMLMapTransformer.java
===================================================================
--- trunk/src/tiled/io/xml/XMLMapTransformer.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/io/xml/XMLMapTransformer.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -137,6 +137,19 @@
         }
     }
 
+    private static Node findChild(Node node, String childName) {
+        NodeList children = node.getChildNodes();
+
+        for (int i = 0; i < children.getLength(); i++) {
+            Node child = children.item(i);
+            if (child.getNodeName().equalsIgnoreCase(childName)) {
+                return child;
+            }
+        }
+
+        return null;
+    }
+
     private Object unmarshalClass(Class reflector, Node node)
         throws InstantiationException, IllegalAccessException,
                InvocationTargetException {
@@ -729,6 +742,8 @@
         Map unmarshalledMap = unmarshal(is);
         unmarshalledMap.setFilename(filename);
 
+        map = null;
+        
         return unmarshalledMap;
     }
 

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -2079,6 +2079,9 @@
                 layerTable.changeSelection(totalLayers - currentLayer - 1, 0,
                         false, false);
             }
+            
+            mapView.revalidate();
+            mapView.repaint();
         }
     }
 

Modified: trunk/src/tiled/mapeditor/actions/MergeAllLayersAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/MergeAllLayersAction.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/mapeditor/actions/MergeAllLayersAction.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -37,9 +37,11 @@
     protected void doPerformAction() {
         Map map = editor.getCurrentMap();
 
-        if (JOptionPane.showConfirmDialog(editor.getAppFrame(),
-                                          "Do you wish to merge tile images, and create a new tile set?",
-                                          "Merge Tiles?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION ) {
+        int ret = JOptionPane.showConfirmDialog(editor.getAppFrame(),
+                "Do you wish to merge tile images, and create a new tile set?",
+                "Merge Tiles?", JOptionPane.YES_NO_CANCEL_OPTION);
+        
+        if ( ret == JOptionPane.YES_OPTION ) {
             TileMergeHelper tmh = new TileMergeHelper(map);
             int len = map.getTotalLayers();
             //TODO: Add a dialog option: "Yes, visible only"
@@ -48,11 +50,12 @@
             map.addLayer(newLayer);
             newLayer.setName("Merged Layer");
             map.addTileset(tmh.getSet());
-        } else {
+            editor.setCurrentLayer(0);
+        } else if ( ret == JOptionPane.NO_OPTION ) {
             while (map.getTotalLayers() > 1) {
-                map.mergeLayerDown(map.getTotalLayers() - 1);
+                map.mergeLayerDown(editor.getCurrentLayerIndex());
             }
+            editor.setCurrentLayer(0);
         }
-        editor.setCurrentLayer(0);
     }
 }

Modified: trunk/src/tiled/mapeditor/dialogs/TileDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/TileDialog.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/mapeditor/dialogs/TileDialog.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -71,7 +71,7 @@
     private static final String CREATE_BUTTON = Resources.getString("dialog.tile.button.createtile");
     private static final String DUPLICATE_BUTTON = Resources.getString("dialog.tile.button.duptile");
     private static final String ANIMATION_BUTTON = Resources.getString("dialog.tile.button.animation");
-    private static final String PREVIEW_TAB = Resources.getString("general.button.preview");
+    private static final String PREVIEW_TAB = Resources.getString("dialog.tile.tab.view");
     private static final String TILES_TAB = Resources.getString("general.tile.tiles");
     private static final String IMAGES_TAB = "Images";
     private static final String NAME_LABEL = Resources.getString("dialog.newtileset.name.label");
@@ -161,7 +161,7 @@
         imageList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
         imageList.addListSelectionListener(this);
         JScrollPane sp = new JScrollPane(imageList);
-        sp.setPreferredSize(new Dimension(150, 150));
+        sp.setPreferredSize(new Dimension(250, 150));
 
         // Buttons
         createTileButton = new JButton(CREATE_BUTTON);

Modified: trunk/src/tiled/mapeditor/resources/gui.properties
===================================================================
--- trunk/src/tiled/mapeditor/resources/gui.properties	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/mapeditor/resources/gui.properties	2006-12-15 10:12:04 UTC (rev 710)
@@ -155,6 +155,7 @@
 dialog.tile.button.newtile=Add Tile
 dialog.tile.imgload.error.message=Error while loading image:
 dialog.tile.imgload.error.title=Error while loading image
+dialog.tile.tab.view=View Tileset
 dialog.tile.title=Edit Tileset
 dialog.tileimage.title=Choose Tile Image
 dialog.tilepalette.title=Palette

Modified: trunk/src/tiled/view/HexMapView.java
===================================================================
--- trunk/src/tiled/view/HexMapView.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/view/HexMapView.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -18,6 +18,7 @@
 import javax.swing.SwingConstants;
 
 import tiled.core.*;
+import tiled.mapeditor.MapEditor;
 import tiled.mapeditor.selection.SelectionLayer;
 
 /**
@@ -63,6 +64,10 @@
         super(map, null);
     }
 
+    public HexMapView(Map map, MapEditor editor) {
+        super(map, editor);
+    }
+    
     public int getScrollableBlockIncrement(Rectangle visibleRect,
             int orientation, int direction) {
         Dimension tsize = getTileSize();
@@ -149,14 +154,21 @@
     }
 
     private Dimension getTileSize() {
-        return new Dimension(
+        if(currentLayer instanceof TileLayer) {
+            Dimension d = ((TileLayer)currentLayer).getTileSize();
+            d.height *= zoom;
+            d.width *= zoom;
+            return d;
+        } else {
+            return new Dimension(
                 (int)(map.getTileWidth() * zoom),
                 (int)(map.getTileHeight() * zoom));
+        }
     }
 
-    protected void paintGrid(Graphics2D g2d) {
+    protected void paintGrid(Graphics2D g2d, TileLayer layer) {
         g2d.setColor(Color.black);
-        Dimension tileSize = getTileSize();
+        Dimension tileSize = layer.getTileSize();
         // Determine area to draw from clipping rectangle
         Rectangle clipRect = g2d.getClipBounds();
         Point topLeft = screenToTileCoords(
@@ -184,7 +196,7 @@
         }
     }
 
-    protected void paintCoordinates(Graphics2D g2d) {
+    protected void paintCoordinates(Graphics2D g2d, TileLayer layer) {
         // TODO: Implement paintCoordinates for HexMapView
     }
 
@@ -252,7 +264,7 @@
      */
     private Point2D getTopLeftCornerOfHex(int x, int y) {
         Dimension tileSize = getTileSize();
-        Point2D centre = tileToScreenCoords(x, y);
+        Point2D centre = tileToScreenCoords(tileSize, x, y);
         double leftX = centre.getX() - tileSize.getWidth() / 2;
         double topY = centre.getY() - tileSize.getHeight() / 2;
         return new Point2D.Double(leftX, topY);
@@ -314,7 +326,7 @@
      *
      * @return The point at the centre of the Hex.
      */
-    public Point tileToScreenCoords(double x, double y) {
+    public Point tileToScreenCoords(Dimension tileSize, double x, double y) {
         double xx = getWidthBetweenHexCentres() * x;
         double yy = getTileHeight() * y;
         if (x % 2 == 0) {

Modified: trunk/src/tiled/view/IsoMapView.java
===================================================================
--- trunk/src/tiled/view/IsoMapView.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/view/IsoMapView.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -19,9 +19,12 @@
 import javax.swing.SwingConstants;
 
 import tiled.core.*;
+import tiled.mapeditor.MapEditor;
 import tiled.mapeditor.selection.SelectionLayer;
 
 /**
+ * Renderer for Isometric maps
+ * 
  * @version $Id$
  */
 public class IsoMapView extends MapView
@@ -35,6 +38,10 @@
         super(map, null);
     }
 
+    public IsoMapView(Map map, MapEditor editor) {
+        super(map, editor);
+    }
+    
     public int getScrollableBlockIncrement(Rectangle visibleRect,
             int orientation, int direction) {
         Dimension tsize = getTileSize();
@@ -56,6 +63,9 @@
     }
 
     protected void paintLayer(Graphics2D g2d, TileLayer layer) {
+        
+        currentLayer = layer;
+        
         // Turn anti alias on for selection drawing
         g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                 RenderingHints.VALUE_ANTIALIAS_ON);
@@ -67,7 +77,7 @@
 
         Point rowItr = screenToTileCoords(clipRect.x, clipRect.y);
         rowItr.x--;
-        Point drawLoc = tileToScreenCoords(rowItr.x, rowItr.y);
+        Point drawLoc = tileToScreenCoords(tileSize, rowItr.x, rowItr.y);
         drawLoc.x -= tileSize.width / 2;
         drawLoc.y += tileSize.height;
 
@@ -117,9 +127,10 @@
 
     protected void paintObjectGroup(Graphics2D g2d, ObjectGroup og) {
         // TODO: Implement objectgroup painting for IsoMapView
+        currentLayer = og;
     }
 
-    protected void paintGrid(Graphics2D g2d) {
+    protected void paintGrid(Graphics2D g2d, TileLayer layer) {
         Dimension tileSize = getTileSize();
         Rectangle clipRect = g2d.getClipBounds();
 
@@ -137,23 +148,25 @@
                     clipRect.x, clipRect.y + clipRect.height).y);
 
         for (int y = startY; y <= endY; y++) {
-            Point start = tileToScreenCoords(startX, y);
-            Point end = tileToScreenCoords(endX, y);
+            Point start = tileToScreenCoords(tileSize, startX, y);
+            Point end = tileToScreenCoords(tileSize, endX, y);
             g2d.drawLine(start.x, start.y, end.x, end.y);
         }
         for (int x = startX; x <= endX; x++) {
-            Point start = tileToScreenCoords(x, startY);
-            Point end = tileToScreenCoords(x, endY);
+            Point start = tileToScreenCoords(tileSize, x, startY);
+            Point end = tileToScreenCoords(tileSize, x, endY);
             g2d.drawLine(start.x, start.y, end.x, end.y);
         }
     }
 
-    protected void paintCoordinates(Graphics2D g2d) {
+    protected void paintCoordinates(Graphics2D g2d, TileLayer layer) {
         g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                 RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
 
         Rectangle clipRect = g2d.getClipBounds();
-        Dimension tileSize = getTileSize();
+        Dimension tileSize = layer.getTileSize();
+        tileSize.width *= zoom;
+        tileSize.height *= zoom;
         int tileStepY = tileSize.height / 2 == 0 ? 1 : tileSize.height / 2;
         Font font = new Font("SansSerif", Font.PLAIN, tileSize.height / 4);
         g2d.setFont(font);
@@ -161,7 +174,7 @@
 
         Point rowItr = screenToTileCoords(clipRect.x, clipRect.y);
         rowItr.x--;
-        Point drawLoc = tileToScreenCoords(rowItr.x, rowItr.y);
+        Point drawLoc = tileToScreenCoords(tileSize, rowItr.x, rowItr.y);
         drawLoc.y += tileSize.height / 2;
 
         // Determine area to draw from clipping rectangle
@@ -205,7 +218,19 @@
     }
 
     protected void paintPropertyFlags(Graphics2D g2d, TileLayer layer) {
-        throw new RuntimeException("Not yet implemented");    // todo
+        Dimension tsize = getTileSize();
+        if (tsize.width <= 0 || tsize.height <= 0) {
+            return;
+        }
+        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
+                             RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+
+        // Determine tile size and offset
+        Font font = new Font("SansSerif", Font.PLAIN, tsize.height / 4);
+        g2d.setFont(font);
+        FontRenderContext fontRenderContext = g2d.getFontRenderContext();
+        
+        //TODO: finish this
     }
 
     public void repaintRegion(Rectangle region) {
@@ -217,12 +242,12 @@
         int mapY1 = region.y;
         int mapX2 = mapX1 + region.width;
         int mapY2 = mapY1 + region.height;
+        
+        int x1 = tileToScreenCoords(tileSize, mapX1, mapY2).x;
+        int y1 = tileToScreenCoords(tileSize, mapX1, mapY1).y - maxExtraHeight;
+        int x2 = tileToScreenCoords(tileSize, mapX2, mapY1).x;
+        int y2 = tileToScreenCoords(tileSize, mapX2, mapY2).y;
 
-        int x1 = tileToScreenCoords(mapX1, mapY2).x;
-        int y1 = tileToScreenCoords(mapX1, mapY1).y - maxExtraHeight;
-        int x2 = tileToScreenCoords(mapX2, mapY1).x;
-        int y2 = tileToScreenCoords(mapX2, mapY2).y;
-
         repaint(new Rectangle(x1, y1, x2 - x1, y2 - y1));
     }
 
@@ -270,20 +295,31 @@
     }
 
     protected Dimension getTileSize() {
-        return new Dimension(
+        if(currentLayer instanceof TileLayer) {
+            Dimension d = ((TileLayer)currentLayer).getTileSize();
+            d.height *= zoom;
+            d.width *= zoom;
+            return d;
+        } else {
+            return new Dimension(
                 (int)(map.getTileWidth() * zoom),
                 (int)(map.getTileHeight() * zoom));
+        }
     }
 
     protected double getTileRatio() {
-        return (double)map.getTileWidth() / (double)map.getTileHeight();
+        if(currentLayer instanceof TileLayer) {
+            Dimension d = ((TileLayer)currentLayer).getTileSize();
+            return (double)d.width / (double)d.height;
+        } else {
+            return (double)map.getTileWidth() / (double)map.getTileHeight();
+        }
     }
 
     /**
-     * Returns the location on the screen of the top corner of a tile.
+     * @see tiled.view.MapView#tileToScreenCoords(Dimension, double, double)
      */
-    public Point tileToScreenCoords(double x, double y) {
-        Dimension tileSize = getTileSize();
+    public Point tileToScreenCoords(Dimension tileSize, double x, double y) {
         int originX = (map.getHeight() * tileSize.width) / 2;
         return new Point(
                 (int)((x - y) * tileSize.width / 2) + originX,

Modified: trunk/src/tiled/view/MapView.java
===================================================================
--- trunk/src/tiled/view/MapView.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/view/MapView.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -38,6 +38,7 @@
     public static int ZOOM_NORMALSIZE = 5;
 
     protected Map map;
+    protected MapLayer currentLayer;
     protected Brush currentBrush;
     protected int modeFlags;
     protected double zoom = 1.0;
@@ -220,16 +221,16 @@
         int orientation = p.getOrientation();
 
         if (orientation == Map.MDO_ISO) {
-            mapView = new IsoMapView(p);
+            mapView = new IsoMapView(p, editor);
         }
         else if (orientation == Map.MDO_ORTHO) {
             mapView = new OrthoMapView(p, editor); // FIXME
         }
         else if (orientation == Map.MDO_HEX) {
-            mapView = new HexMapView(p);
+            mapView = new HexMapView(p, editor);
         }
         else if (orientation == Map.MDO_SHIFTED) {
-            mapView = new ShiftedMapView(p);
+            mapView = new ShiftedMapView(p, editor);
         }
 
         return mapView;
@@ -256,7 +257,7 @@
         g2d.setStroke(new BasicStroke(2.0f));
 
         // Do an initial fill with the background color
-        // todo: make background color configurable
+        // TODO: make background color configurable
         //try {
         //    String colorString = displayPrefs.get("backgroundColor", "");
         //    g2d.setColor(Color.decode(colorString));
@@ -291,7 +292,24 @@
 
         // Grid color (also used for coordinates)
         g2d.setColor(gridColor);
-
+        
+        //----- everything after this point requires a valid TileLayer
+        //we don't show grid on object layers anyway...
+        TileLayer tl = null;
+        if (editor != null && !(editor.getCurrentLayer() instanceof TileLayer)) {
+            // I guess we shouldn't assume the bottom layer is a tile layer...
+            for(int i=0;i<map.getTotalLayers();i++) {
+                if(map.getLayer(i) instanceof TileLayer) {
+                    tl = (TileLayer)map.getLayer(i);
+                }
+            }
+        } else if (editor != null) {
+            tl = (TileLayer) editor.getCurrentLayer();
+        }
+        
+        if(tl == null)
+            return;
+        
         if (showGrid) {
             // Grid opacity
             if (gridOpacity < 255) {
@@ -314,24 +332,21 @@
             }
 
             g2d.setStroke(new BasicStroke());
-            paintGrid(g2d);
+            paintGrid(g2d, tl);
         }
 
         if (getMode(PF_COORDINATES)) {
             g2d.setComposite(AlphaComposite.SrcOver);
-            paintCoordinates(g2d);
+            paintCoordinates(g2d, tl);
         }
 
-        if (editor != null && editor.getCurrentLayer() instanceof TileLayer) {
-            g2d.setComposite(AlphaComposite.SrcOver);
+        g2d.setComposite(AlphaComposite.SrcOver);
 
-            TileLayer tl = (TileLayer) editor.getCurrentLayer();
-            if (tl != null && tl.isVisible()) {
-                paintPropertyFlags(g2d, tl);
-            }
+        if (tl.isVisible()) {
+            paintPropertyFlags(g2d, tl);
         }
     }
-
+    
     public void paintSubMap(MultilayerPlane m, Graphics2D g2d,
                             float mapOpacity) {
         Iterator li = m.getLayers();
@@ -361,6 +376,12 @@
         }
     }
 
+    protected Dimension getDefaultTileSize() {
+        return new Dimension(
+                (int)(map.getTileWidth() * zoom),
+                (int)(map.getTileHeight() * zoom));
+    }
+    
     /**
      * Draws a TileLayer. Implemented in a subclass.
      *
@@ -449,14 +470,14 @@
      *
      * @param g2d the graphics context to draw the grid onto
      */
-    protected abstract void paintGrid(Graphics2D g2d);
+    protected abstract void paintGrid(Graphics2D g2d, TileLayer currentLayer);
 
     /**
      * Draws the coordinates on each tile.
      *
      * @param g2d the graphics context to draw the coordinates onto
      */
-    protected abstract void paintCoordinates(Graphics2D g2d);
+    protected abstract void paintCoordinates(Graphics2D g2d, TileLayer layer);
 
     protected abstract void paintPropertyFlags(Graphics2D g2d, TileLayer layer);
 
@@ -474,5 +495,13 @@
 
     public abstract Point screenToTileCoords(int x, int y);
 
-    public abstract Point tileToScreenCoords(double x, double y);
+    /**
+     * Returns the location on the screen of the top corner of a tile.
+     * 
+     * @param tileSize 
+     * @param x 
+     * @param y 
+     * @return Point
+     */
+    public abstract Point tileToScreenCoords(Dimension tileSize, double x, double y);
 }

Modified: trunk/src/tiled/view/OrthoMapView.java
===================================================================
--- trunk/src/tiled/view/OrthoMapView.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/view/OrthoMapView.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -69,6 +69,9 @@
     }
 
     protected void paintLayer(Graphics2D g2d, TileLayer layer) {
+        
+        currentLayer = layer;
+        
         // Determine tile size and offset
         Dimension tsize = getTileSize();
         if (tsize.width <= 0 || tsize.height <= 0) {
@@ -108,7 +111,9 @@
 
     protected void paintObjectGroup(Graphics2D g, ObjectGroup og) {
         Iterator itr = og.getObjects();
-
+        currentLayer = og;
+        
+        
         while (itr.hasNext()) {
             MapObject mo = (MapObject) itr.next();
             double ox = mo.getX() * zoom;
@@ -124,9 +129,11 @@
         }
     }
 
-    protected void paintGrid(Graphics2D g2d) {
+    protected void paintGrid(Graphics2D g2d, TileLayer layer) {
         // Determine tile size
-        Dimension tsize = getTileSize();
+        Dimension tsize = layer.getTileSize();
+        tsize.width *= zoom;
+        tsize.height *= zoom;
         if (tsize.width <= 0 || tsize.height <= 0) {
             return;
         }
@@ -146,8 +153,10 @@
         }
     }
 
-    protected void paintCoordinates(Graphics2D g2d) {
-        Dimension tsize = getTileSize();
+    protected void paintCoordinates(Graphics2D g2d, TileLayer layer) {
+        Dimension tsize = layer.getTileSize();
+        tsize.width *= zoom;
+        tsize.height *= zoom;
         if (tsize.width <= 0 || tsize.height <= 0) {
             return;
         }
@@ -258,9 +267,16 @@
     }
 
     protected Dimension getTileSize() {
-        return new Dimension(
-                (int) (map.getTileWidth() * zoom),
-                (int) (map.getTileHeight() * zoom));
+        if(currentLayer instanceof TileLayer) {
+            Dimension d = ((TileLayer)currentLayer).getTileSize();
+            d.height *= zoom;
+            d.width *= zoom;
+            return d;
+        } else {
+            return new Dimension(
+                (int)(map.getTileWidth() * zoom),
+                (int)(map.getTileHeight() * zoom));
+        }
     }
 
     protected Polygon createGridPolygon(int tx, int ty, int border) {
@@ -275,8 +291,7 @@
         return poly;
     }
 
-    public Point tileToScreenCoords(double x, double y) {
-        Dimension tsize = getTileSize();
+    public Point tileToScreenCoords(Dimension tsize, double x, double y) {
         return new Point((int) x * tsize.width, (int) y * tsize.height);
     }
 }

Modified: trunk/src/tiled/view/ShiftedMapView.java
===================================================================
--- trunk/src/tiled/view/ShiftedMapView.java	2006-11-17 10:48:43 UTC (rev 709)
+++ trunk/src/tiled/view/ShiftedMapView.java	2006-12-15 10:12:04 UTC (rev 710)
@@ -13,11 +13,13 @@
 package tiled.view;
 
 import java.awt.*;
+
 import javax.swing.SwingConstants;
 
 import tiled.core.Map;
 import tiled.core.ObjectGroup;
 import tiled.core.TileLayer;
+import tiled.mapeditor.MapEditor;
 
 /**
  * @version $Id$
@@ -39,6 +41,13 @@
         verSide = 0;
     }
 
+    public ShiftedMapView(Map map, MapEditor editor) {
+        super(map, editor);
+
+        horSide = 16;
+        verSide = 0;
+    }
+    
     public int getScrollableBlockIncrement(Rectangle visibleRect,
             int orientation, int direction) {
         int unit =
@@ -80,9 +89,9 @@
     protected void paintObjectGroup(Graphics2D g2d, ObjectGroup og) {
     }
 
-    protected void paintGrid(Graphics2D g2d) {
+    protected void paintGrid(Graphics2D g2d, TileLayer layer) {
         // Determine tile size
-        Dimension tsize = getTileSize();
+        Dimension tsize = layer.getTileSize();
         if (tsize.width <= 0 || tsize.height <= 0) return;
         int onceX = (tsize.width - (int)(horSide * zoom)) / 2;
         int repeatX = tsize.width - onceX;
@@ -115,7 +124,7 @@
         g2d.setColor(prevColor);
     }
 
-    protected void paintCoordinates(Graphics2D g2d) {
+    protected void paintCoordinates(Graphics2D g2d, TileLayer layer) {
     }
 
     protected void paintPropertyFlags(Graphics2D g2d, TileLayer layer) {
@@ -130,16 +139,23 @@
     }
 
     protected Dimension getTileSize() {
-        return new Dimension(
+        if(currentLayer instanceof TileLayer) {
+            Dimension d = ((TileLayer)currentLayer).getTileSize();
+            d.height *= zoom;
+            d.width *= zoom;
+            return d;
+        } else {
+            return new Dimension(
                 (int)(map.getTileWidth() * zoom),
                 (int)(map.getTileHeight() * zoom));
+        }
     }
 
     protected Polygon createGridPolygon(int tx, int ty, int border) {
         return new Polygon();
     }
 
-    public Point tileToScreenCoords(double x, double y) {
+    public Point tileToScreenCoords(Dimension tileSize, double x, double y) {
         return new Point(0, 0);
     }
 }




More information about the tiled-commit mailing list