[tiled] r740 - in trunk/src/tiled/mapeditor: . brush widget

tiled-svn at biggeruniverse.com tiled-svn at biggeruniverse.com
Thu Apr 17 06:57:42 PDT 2008


Author: bjorn
Date: 2008-04-17 08:57:42 -0500 (Thu, 17 Apr 2008)
New Revision: 740

Added:
   trunk/src/tiled/mapeditor/widget/BrushPreview.java
Removed:
   trunk/src/tiled/mapeditor/widget/TileButton.java
Modified:
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/brush/AbstractBrush.java
   trunk/src/tiled/mapeditor/brush/Brush.java
   trunk/src/tiled/mapeditor/widget/BrushBrowser.java
Log:
Replaced TileButton with a non-functional BrushPreview.


Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2008-04-17 13:51:10 UTC (rev 739)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2008-04-17 13:57:42 UTC (rev 740)
@@ -117,7 +117,7 @@
     private JList       editHistoryList;
     private MiniMapViewer miniMap;
 
-    private TileButton  tilePaletteButton;
+    private BrushPreview brushPreview;
     private JFrame      appFrame;
     private JSlider     opacitySlider;
     private JLabel      zoomLabel, tileCoordsLabel;
@@ -556,11 +556,9 @@
         toolBar.add(Box.createRigidArea(new Dimension(5, 5)));
         toolBar.add(Box.createGlue());
 
-        tilePaletteButton = new TileButton();
-        tilePaletteButton.setActionCommand("palette");
-        mapEventAdapter.addListener(tilePaletteButton);
-        tilePaletteButton.addActionListener(this);
-        toolBar.add(tilePaletteButton);
+        brushPreview = new BrushPreview();
+        mapEventAdapter.addListener(brushPreview);
+        toolBar.add(brushPreview);
 
         return toolBar;
     }
@@ -1346,7 +1344,7 @@
                    }
                }
                mapView.repaint();
-               tilePaletteButton.setTile(currentTile);
+               brushPreview.setBrush(currentBrush);
             }
         } else if (command.equals(Resources.getString("menu.tilesets.manager"))) {
             if (currentMap != null) {
@@ -2205,7 +2203,7 @@
             if (!(currentBrush instanceof CustomBrush)) {
                 ((ShapeBrush) currentBrush).setTile(tile);
             }
-            tilePaletteButton.setTile(currentTile);
+            brushPreview.setBrush(currentBrush);
         }
     }
 

Modified: trunk/src/tiled/mapeditor/brush/AbstractBrush.java
===================================================================
--- trunk/src/tiled/mapeditor/brush/AbstractBrush.java	2008-04-17 13:51:10 UTC (rev 739)
+++ trunk/src/tiled/mapeditor/brush/AbstractBrush.java	2008-04-17 13:57:42 UTC (rev 740)
@@ -12,9 +12,7 @@
 
 package tiled.mapeditor.brush;
 
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.Shape;
+import java.awt.*;
 
 import tiled.core.MultilayerPlane;
 import tiled.view.MapView;
@@ -26,8 +24,8 @@
     protected MultilayerPlane affectedMp;
     protected int sx, sy;
     protected boolean paintingStarted = false;
-	protected int initLayer;
-    
+    protected int initLayer;
+
     public AbstractBrush() {
     }
 
@@ -49,27 +47,30 @@
     public int getAffectedLayers() {
         return numLayers;
     }
-    
+
     public void startPaint(MultilayerPlane mp, int x, int y, int button, int layer) {
-    	affectedMp = mp;
-		initLayer = layer;
-    	paintingStarted = true;
+        affectedMp = mp;
+        initLayer = layer;
+        paintingStarted = true;
     }
-    
+
     public Rectangle doPaint(int x, int y) throws Exception {
-    	if(!paintingStarted) throw new Exception("Attempted to call doPaint() without calling startPaint()!");
-    	return null;
+        if (!paintingStarted) throw new Exception("Attempted to call doPaint() without calling startPaint()!");
+        return null;
     }
-    
+
     public void endPaint() {
-    	paintingStarted = false;
+        paintingStarted = false;
     }
-    
+
     public void drawPreview(Graphics2D g2d, int x, int y, MapView mv) {
-    	sx = x;
-    	sy = y;
-    	drawPreview(g2d, mv);
+        sx = x;
+        sy = y;
+        drawPreview(g2d, mv);
     }
 
-	public abstract Shape getShape();
+    public void drawPreview(Graphics2D g2d, Dimension dimension) {
+    }
+
+    public abstract Shape getShape();
 }

Modified: trunk/src/tiled/mapeditor/brush/Brush.java
===================================================================
--- trunk/src/tiled/mapeditor/brush/Brush.java	2008-04-17 13:51:10 UTC (rev 739)
+++ trunk/src/tiled/mapeditor/brush/Brush.java	2008-04-17 13:57:42 UTC (rev 740)
@@ -12,8 +12,7 @@
 
 package tiled.mapeditor.brush;
 
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
+import java.awt.*;
 
 import tiled.core.MultilayerPlane;
 import tiled.view.MapView;
@@ -88,6 +87,13 @@
     public void drawPreview(Graphics2D g2d, MapView mv);
 
     /**
+     * Draws a preview of the editing operation when applicable. This is meant for off-map brush preview.
+     * @param g2d The graphics context to draw to.
+     * @param dimension
+     */
+    public void drawPreview(Graphics2D g2d, Dimension dimension);
+
+    /**
      * Returns wether this brush equals another brush.
      *
      * @param brush

Modified: trunk/src/tiled/mapeditor/widget/BrushBrowser.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/BrushBrowser.java	2008-04-17 13:51:10 UTC (rev 739)
+++ trunk/src/tiled/mapeditor/widget/BrushBrowser.java	2008-04-17 13:57:42 UTC (rev 740)
@@ -103,9 +103,9 @@
         while (itr.hasNext()) {
             Brush brush = (Brush) itr.next();
             Rectangle bb = brush.getBounds();
-        	float o = maxWidth/2.0f - bb.width/2.0f;
-        	g.translate((int)o, (int)o);
-            brush.drawPreview((Graphics2D) g, null);
+            float o = maxWidth/2.0f - bb.width/2.0f;
+            g.translate((int)o, (int)o);
+            brush.drawPreview((Graphics2D) g, new Dimension(maxWidth, maxWidth));
             g.translate((int)-o, (int)-o);
 
             if (brush == selectedBrush) {
@@ -115,7 +115,7 @@
             g.translate(maxWidth,0);
             x += maxWidth;
             if (x + maxWidth > getWidth()) {
-            	g.translate(-x, maxWidth);
+                g.translate(-x, maxWidth);
                 x = 0;
             }
         }

Copied: trunk/src/tiled/mapeditor/widget/BrushPreview.java (from rev 729, trunk/src/tiled/mapeditor/widget/TileButton.java)
===================================================================
--- trunk/src/tiled/mapeditor/widget/BrushPreview.java	                        (rev 0)
+++ trunk/src/tiled/mapeditor/widget/BrushPreview.java	2008-04-17 13:57:42 UTC (rev 740)
@@ -0,0 +1,41 @@
+/*
+ *  Tiled Map Editor, (c) 2004-2006
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  Adam Turk <aturk at biggeruniverse.com>
+ *  Bjorn Lindeijer <b.lindeijer at xs4all.nl>
+ */
+
+package tiled.mapeditor.widget;
+
+import tiled.mapeditor.Resources;
+import tiled.mapeditor.brush.AbstractBrush;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * @version $Id$
+ */
+public class BrushPreview extends JPanel
+{
+    private AbstractBrush brush;
+
+    public BrushPreview() {
+        setPreferredSize(new Dimension(22, 22));
+    }
+
+    public void setBrush(AbstractBrush brush) {
+        this.brush = brush;
+    }
+
+    public void paint(Graphics graphics) {
+        if (brush != null) {
+            brush.drawPreview((Graphics2D) graphics, size());
+        }
+    }
+}


Property changes on: trunk/src/tiled/mapeditor/widget/BrushPreview.java
___________________________________________________________________
Name: svn:keywords
   + Id

Deleted: trunk/src/tiled/mapeditor/widget/TileButton.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/TileButton.java	2008-04-17 13:51:10 UTC (rev 739)
+++ trunk/src/tiled/mapeditor/widget/TileButton.java	2008-04-17 13:57:42 UTC (rev 740)
@@ -1,55 +0,0 @@
-/*
- *  Tiled Map Editor, (c) 2004-2006
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  Adam Turk <aturk at biggeruniverse.com>
- *  Bjorn Lindeijer <b.lindeijer at xs4all.nl>
- */
-
-package tiled.mapeditor.widget;
-
-import java.awt.Image;
-import java.awt.Insets;
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-
-import tiled.core.Tile;
-import tiled.mapeditor.Resources;
-
-/**
- * @version $Id$
- */
-public class TileButton extends JButton
-{
-    private static final int ICON_SIZE = 22;
-    private static final Icon DEFAULT_ICON = Resources.getIcon("empty.png");
-
-    public TileButton() {
-        setMargin(new Insets(0, 0, 0, 0));
-        setIcon(DEFAULT_ICON);
-    }
-
-    public void setTile(Tile tile) {
-        Icon icon = DEFAULT_ICON;
-
-        if (tile != null && tile.getImage() != null) {
-            Image tileImg = tile.getImage();
-            int imgWidth = tileImg.getWidth(null);
-
-            if (imgWidth > ICON_SIZE) {
-                icon = new ImageIcon(tileImg.getScaledInstance(ICON_SIZE,
-                        (tileImg.getHeight(null) * ICON_SIZE) / imgWidth,
-                        Image.SCALE_SMOOTH));
-            } else {
-                icon = new ImageIcon(tileImg);
-            }
-        }
-
-        setIcon(icon);
-    }
-}




More information about the tiled-commit mailing list