[tiled] r681 - in trunk: . examples src/tiled/core src/tiled/mapeditor src/tiled/mapeditor/util/cutter src/tiled/mapeditor/widget

svn@biggeruniverse.com svn at biggeruniverse.com
Sat Jun 24 06:50:22 PDT 2006


Author: bjorn
Date: 2006-06-24 08:50:21 -0500 (Sat, 24 Jun 2006)
New Revision: 681

Modified:
   trunk/TODO
   trunk/examples/iso-test3.tmx
   trunk/src/tiled/core/TileSet.java
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/util/cutter/BasicTileCutter.java
   trunk/src/tiled/mapeditor/widget/BrushBrowser.java
   trunk/src/tiled/mapeditor/widget/TabbedTilesetsPane.java
   trunk/src/tiled/mapeditor/widget/TilePalettePanel.java
Log:
Improved embedded tabbed tilesets pane in that it takes the number of tiles in a row from the tileset if available. Also, it is now possible to select a tile region, but this doesn't generate any event yet and should still cause the creation of a stamp brush.

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2006-06-24 00:50:03 UTC (rev 680)
+++ trunk/TODO	2006-06-24 13:50:21 UTC (rev 681)
@@ -1,12 +1,12 @@
 ROADMAP TO FUTURE RELEASES
 
 0.7.0
-* Remove copy constructors in favour of clone method
-* Add import/export of options
-* Allow embedding of tile palette beneath the map view
+* Remove copy constructors in favour of clone method (DONE)
+* Add import/export of options (WIP)
+* Allow embedding of tile palette beneath the map view (WIP)
 * Replace tile button with a brush preview beneath the layer table
 * Allow creation of stamp brush from the tile palette
-* Add support for tile instance properties (see Christian's patch)
+* Add support for tile instance properties (see Christian's patch) (WIP)
 
 0.8.0
 * Set up a layer->map->mapview changes event trail to automatically handle
@@ -28,10 +28,7 @@
 * Add ability to select multiple layers from layer table
 * Add preview of new tileset when creating a tileset
 * Add the Shifted view, which emulates several tiling configurations
-* Add "stamp" tool
-* Add a navigation minimap
 * Add full support for animated tiles
-* Add palette brush
 * Add support for animated tiles
 * Add additional "tile cutters"
 * Rewrite main mapeditor code

Modified: trunk/examples/iso-test3.tmx
===================================================================
--- trunk/examples/iso-test3.tmx	2006-06-24 00:50:03 UTC (rev 680)
+++ trunk/examples/iso-test3.tmx	2006-06-24 13:50:21 UTC (rev 681)
@@ -1,7 +1,6 @@
-<?xml version="1.0" ?>
-<map name="Untitled" orientation="isometric" tilewidth="32" tileheight="16">
- <dimensions width="32" height="16"/>
- <tileset firstgid="1" name="Sunny Beach">
+<?xml version="1.0"?>
+<map version="0.99b" orientation="isometric" width="32" height="16" tilewidth="32" tileheight="16">
+ <tileset name="Sunny Beach" firstgid="1">
   <tile id="0">
    <image format="png">
     <data encoding="base64">
@@ -213,9 +212,10 @@
    </image>
   </tile>
  </tileset>
- <layer id="0" name="Layer 0">
+ <layer name="Layer 0" width="32" height="16">
   <data encoding="base64" compression="gzip">
-   H4sIAAAAAAAAAGNkYGBgHOGYYxC4YbBgASAWGiC7uYGYBYhFBtBuGTT76ZE2eICYDYilgVhqAPwPsp8diFmBWHIA7OcHYk4kLDwA8T8Y8Gg5NIrpjQEhjUB2AAgAAA==
+   H4sIAAAAAAAAANWVywqAIBREFXpSUFSbHv//nc1GcKOOMhItztJ79TCD1hhjSSbQgAccGecUzKADN7jE+wdyfw9acH7w/gWMHrvwbT4r2MRuHWy+1G6Z/aFs5/oruUfNbDPUzDbjrzTbf4LpFeOqpJ+qXpXMUf0ZqTm+F+dR1avUnJAXVa9ic2JemF69sBzz5AAIAAA=
   </data>
+  <tileproperties/>
  </layer>
 </map>

Modified: trunk/src/tiled/core/TileSet.java
===================================================================
--- trunk/src/tiled/core/TileSet.java	2006-06-24 00:50:03 UTC (rev 680)
+++ trunk/src/tiled/core/TileSet.java	2006-06-24 13:50:21 UTC (rev 681)
@@ -23,9 +23,9 @@
 import java.util.Vector;
 import javax.imageio.ImageIO;
 
+import tiled.mapeditor.util.TransparentImageFilter;
+import tiled.mapeditor.util.cutter.BasicTileCutter;
 import tiled.mapeditor.util.cutter.TileCutter;
-import tiled.mapeditor.util.cutter.BasicTileCutter;
-import tiled.mapeditor.util.TransparentImageFilter;
 import tiled.util.NumberedSet;
 
 /**
@@ -48,6 +48,7 @@
     private TileCutter tileCutter;
     private Rectangle tileDimensions;
     private int tileSpacing;
+    private int tilesPerRow;
     private String externalSource;
     private File tilebmpFile;
     private String name;
@@ -116,13 +117,15 @@
         tileCutter = cutter;
         tileSetImage = tilebmp;
 
+        cutter.setImage(tilebmp);
+
         tileDimensions = new Rectangle(cutter.getTileDimensions());
         if (cutter instanceof BasicTileCutter) {
-            tileSpacing = ((BasicTileCutter) cutter).getTileSpacing();
+            BasicTileCutter basicTileCutter = (BasicTileCutter) cutter;
+            tileSpacing = basicTileCutter.getTileSpacing();
+            tilesPerRow = basicTileCutter.getTilesPerRow();
         }
 
-        cutter.setImage(tilebmp);
-
         Image tile = cutter.getNextTile();
         while (tile != null) {
             Tile newTile = new Tile();
@@ -333,6 +336,14 @@
     }
 
     /**
+     * Returns the number of tiles per row in the original tileset image.
+     * @return the number of tiles per row in the original tileset image.
+     */
+    public int getTilesPerRow() {
+        return tilesPerRow;
+    }
+
+    /**
      * Gets the tile with <b>local</b> id <code>i</code>.
      *
      * @param i local id of tile

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-06-24 00:50:03 UTC (rev 680)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-06-24 13:50:21 UTC (rev 681)
@@ -71,8 +71,8 @@
     private static final int PS_MOVE    = 6;
     private static final int PS_MOVEOBJ = 7;
 
-    private static final int APP_WIDTH = 600;
-    private static final int APP_HEIGHT = 400;
+    private static final int APP_WIDTH = 640;
+    private static final int APP_HEIGHT = 480;
 
     private Cursor curDefault;
     private Cursor curPaint;
@@ -298,6 +298,7 @@
                 JSplitPane.HORIZONTAL_SPLIT, true, mapScrollPane, dataPanel);
         mainSplit.setOneTouchExpandable(true);
         mainSplit.setResizeWeight(1.0);
+        mainSplit.setBorder(null);
 
         tabbedTilesetsPane = new TabbedTilesetsPane(this);
         JSplitPane paletteSplit = new JSplitPane(

Modified: trunk/src/tiled/mapeditor/util/cutter/BasicTileCutter.java
===================================================================
--- trunk/src/tiled/mapeditor/util/cutter/BasicTileCutter.java	2006-06-24 00:50:03 UTC (rev 680)
+++ trunk/src/tiled/mapeditor/util/cutter/BasicTileCutter.java	2006-06-24 13:50:21 UTC (rev 681)
@@ -17,16 +17,19 @@
 import java.awt.image.BufferedImage;
 
 /**
+ * Cuts tiles from a tileset image according to a regular rectangular pattern.
+ * Supports a variable spacing between tiles and an offset from the origin.
+ *
  * @version $Id$
  */
 public class BasicTileCutter implements TileCutter
 {
     private int nextX, nextY;
     private BufferedImage image;
-    private int tileWidth;
-    private int tileHeight;
-    private int tileSpacing;
-    private int offset;
+    private final int tileWidth;
+    private final int tileHeight;
+    private final int tileSpacing;
+    private final int offset;
 
     public BasicTileCutter(int tileWidth, int tileHeight, int tileSpacing,
                            int offset)
@@ -77,4 +80,12 @@
     public int getTileSpacing() {
         return tileSpacing;
     }
+
+    /**
+     * Returns the number of tiles per row in the tileset image.
+     * @return the number of tiles per row in the tileset image.
+     */
+    public int getTilesPerRow() {
+        return (image.getWidth() + tileSpacing) / (tileWidth + tileSpacing);
+    }
 }

Modified: trunk/src/tiled/mapeditor/widget/BrushBrowser.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/BrushBrowser.java	2006-06-24 00:50:03 UTC (rev 680)
+++ trunk/src/tiled/mapeditor/widget/BrushBrowser.java	2006-06-24 13:50:21 UTC (rev 681)
@@ -16,7 +16,6 @@
 import java.awt.event.MouseEvent;
 import java.util.Iterator;
 import java.util.LinkedList;
-
 import javax.swing.JPanel;
 import javax.swing.event.MouseInputAdapter;
 
@@ -77,15 +76,15 @@
         int[] dimensions = { 1, 2, 4, 8, 12, 20 };
 
         for (int n = 1; n < dimensions.length; n++) {
-            ShapeBrush b = new ShapeBrush();
-            b.makeCircleBrush(dimensions[n] / 2);
-            brushes.add(b);
+            ShapeBrush brush = new ShapeBrush();
+            brush.makeCircleBrush(dimensions[n] / 2);
+            brushes.add(brush);
         }
 
         for (int n = 0; n < dimensions.length; n++) {
-            ShapeBrush b = new ShapeBrush();
-            b.makeQuadBrush(new Rectangle(0, 0, dimensions[n], dimensions[n]));
-            brushes.add(b);
+            ShapeBrush brush = new ShapeBrush();
+            brush.makeQuadBrush(new Rectangle(0, 0, dimensions[n], dimensions[n]));
+            brushes.add(brush);
         }
     }
 
@@ -102,14 +101,14 @@
         Iterator itr = brushes.iterator();
         int x = 0;
         while (itr.hasNext()) {
-            Brush b = (Brush)itr.next();
-            Rectangle bb = b.getBounds();
+            Brush brush = (Brush) itr.next();
+            Rectangle bb = brush.getBounds();
         	float o = maxWidth/2.0f - bb.width/2.0f;
         	g.translate((int)o, (int)o);
-            b.drawPreview((Graphics2D) g, null);
+            brush.drawPreview((Graphics2D) g, null);
             g.translate((int)-o, (int)-o);
 
-            if (b == selectedBrush) {
+            if (brush == selectedBrush) {
                 g.drawRect(0, 0, maxWidth, maxWidth);
             }
 
@@ -122,11 +121,11 @@
         }
     }
 
-    public void setSelectedBrush(Brush b) {
+    public void setSelectedBrush(Brush brush) {
         Iterator itr = brushes.iterator();
         while (itr.hasNext()) {
             Brush br = (Brush) itr.next();
-            if (br.equals(b)) {
+            if (br.equals(brush)) {
                 selectedBrush = br;
                 break;
             }

Modified: trunk/src/tiled/mapeditor/widget/TabbedTilesetsPane.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/TabbedTilesetsPane.java	2006-06-24 00:50:03 UTC (rev 680)
+++ trunk/src/tiled/mapeditor/widget/TabbedTilesetsPane.java	2006-06-24 13:50:21 UTC (rev 681)
@@ -30,11 +30,6 @@
 /**
  * Shows one tab for each Tileset.
  *
- * todo: Since the width of this widget is no longer arbitrary but related
- * todo: to the width of the map editor, there should be an option to set
- * todo: the number of tiles in a row equal to what it was on the tileset
- * todo: image.
- *
  * @version $Id$
  */
 public class TabbedTilesetsPane extends JTabbedPane implements TileSelectionListener
@@ -88,7 +83,7 @@
                     tilePanel.addTileSelectionListener(this);
                     JScrollPane paletteScrollPane = new JScrollPane(tilePanel,
                             JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
-                            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+                            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                     addTab(tileset.getName(), paletteScrollPane);
                 }
             }

Modified: trunk/src/tiled/mapeditor/widget/TilePalettePanel.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/TilePalettePanel.java	2006-06-24 00:50:03 UTC (rev 680)
+++ trunk/src/tiled/mapeditor/widget/TilePalettePanel.java	2006-06-24 13:50:21 UTC (rev 681)
@@ -12,10 +12,7 @@
 
 package tiled.mapeditor.widget;
 
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Rectangle;
+import java.awt.*;
 import java.awt.event.MouseEvent;
 import java.util.Vector;
 import javax.swing.JPanel;
@@ -39,20 +36,31 @@
     private TileSet tileset;
     private EventListenerList tileSelectionListeners;
     private Vector tilesetMap;
+    private Rectangle selection;
 
     public TilePalettePanel() {
         tileSelectionListeners = new EventListenerList();
 
         MouseInputAdapter mouseInputAdapter = new MouseInputAdapter() {
+            private Point origin;
+
             public void mousePressed(MouseEvent e) {
-                Tile clickedTile = getTileAtPoint(e.getX(), e.getY());
+                origin = getTileCoordinates(e.getX(), e.getY());
+                setSelection(new Rectangle(origin.x, origin.y, 0, 0));
+                Tile clickedTile = getTileAt(origin.x, origin.y);
                 if (clickedTile != null) {
                     fireTileSelectionEvent(clickedTile);
                 }
             }
 
             public void mouseDragged(MouseEvent e) {
-                mousePressed(e);
+                Point point = getTileCoordinates(e.getX(), e.getY());
+                Rectangle select = new Rectangle(origin.x, origin.y, 0, 0);
+                select.add(point);
+                if (!select.equals(selection)) {
+                    setSelection(select);
+                }
+                // todo: Fire tile region selection event
             }
         };
         addMouseListener(mouseInputAdapter);
@@ -99,23 +107,68 @@
         repaint();
     }
 
-    private Tile getTileAtPoint(int x, int y) {
+    /**
+     * Converts pixel coordinates to tile coordinates. The returned coordinates
+     * are adjusted with respect to the number of tiles per row.
+     */
+    private Point getTileCoordinates(int x, int y) {
         int twidth = tileset.getTileWidth() + 1;
         int theight = tileset.getTileHeight() + 1;
-        int tilesPerRow = Math.max(1, (getWidth() - 1) / twidth);
 
-        // We like Tiled to behave in a predictibile manner; i.e.,
-        // it should not pick the first tile of the next row if
-        // there is empty space on the right of the row.
-        if (x > tilesPerRow * twidth - 1) {
-            x = tilesPerRow * twidth - 1;
+        int tileX = Math.min(x / twidth, getTilesPerRow() - 1);
+        int tileY = y / theight;
+
+        return new Point(tileX, tileY);
+    }
+
+    /**
+     * Retrieves the tile at the given tile coordinates. It assumes the tile
+     * coordinates are adjusted to the number of tiles per row.
+     *
+     * @return the tile at the given tile coordinates, or <code>null</code>
+     *         if the index is out of range
+     */
+    private Tile getTileAt(int x, int y) {
+        int tilesPerRow = getTilesPerRow();
+        int tileAt = y * tilesPerRow + x;
+
+        if (tileAt >= tilesetMap.size()) {
+            return null;
+        } else {
+            return (Tile) tilesetMap.get(tileAt);
         }
+    }
 
-        int tileAt = (y / theight) * tilesPerRow + x / twidth;
+    /**
+     * Returns the number of tiles to display per row. This gets calculated
+     * dynamically unless the tileset specifies this value.
+     */
+    private int getTilesPerRow() {
+        // todo: It should be an option to follow the tiles per row given
+        // todo: by the tileset.
+        if (tileset.getTilesPerRow() == 0) {
+            int twidth = tileset.getTileWidth() + 1;
+            return Math.max(1, (getWidth() - 1) / twidth);
+        } else {
+            return tileset.getTilesPerRow();
+        }
+    }
 
-        if (tileAt >= tilesetMap.size()) return null;
+    private void setSelection(Rectangle rect) {
+        repaintSelection();
+        selection = rect;
+        repaintSelection();
+    }
 
-        return (Tile) tilesetMap.get(tileAt);
+    private void repaintSelection() {
+        if (selection != null) {
+            int twidth = tileset.getTileWidth() + 1;
+            int theight = tileset.getTileHeight() + 1;
+
+            repaint(selection.x * twidth, selection.y * theight,
+                    (selection.width + 1) * twidth + 1,
+                    (selection.height + 1) * theight + 1);
+        }
     }
 
     public void paint(Graphics g) {
@@ -127,7 +180,7 @@
             // Draw the tiles
             int twidth = tileset.getTileWidth() + 1;
             int theight = tileset.getTileHeight() + 1;
-            int tilesPerRow = Math.max(1, (getWidth() - 1) / twidth);
+            int tilesPerRow = getTilesPerRow();
 
             int startY = clip.y / theight;
             int endY = (clip.y + clip.height) / theight + 1;
@@ -151,6 +204,22 @@
                 }
                 gy += theight;
             }
+
+            // Draw the selection
+            if (selection != null) {
+                g.setColor(new Color(100, 100, 255));
+                g.draw3DRect(
+                        selection.x * twidth, selection.y * theight,
+                        (selection.width + 1) * twidth,
+                        (selection.height + 1) * theight,
+                        false);
+                ((Graphics2D) g).setComposite(AlphaComposite.getInstance(
+                        AlphaComposite.SRC_ATOP, 0.2f));
+                g.fillRect(
+                        selection.x * twidth + 1, selection.y * theight + 1,
+                        (selection.width + 1) * twidth - 1,
+                        (selection.height + 1) * theight - 1);
+            }
         }
     }
 
@@ -189,7 +258,7 @@
             int twidth = tileset.getTileWidth() + 1;
             int theight = tileset.getTileHeight() + 1;
             int tileCount = tilesetMap.size();
-            int tilesPerRow = Math.max(1, (getWidth() - 1) / twidth);
+            int tilesPerRow = getTilesPerRow();
             int rows = tileCount / tilesPerRow +
                     (tileCount % tilesPerRow > 0 ? 1 : 0);
 
@@ -228,7 +297,8 @@
     }
 
     public boolean getScrollableTracksViewportWidth() {
-        return true;
+        // todo: Update when this has become an option
+        return tileset.getTilesPerRow() == 0;
     }
 
     public boolean getScrollableTracksViewportHeight() {




More information about the tiled-commit mailing list