[tiled] r704 - in trunk/src/tiled: core mapeditor mapeditor/dialogs mapeditor/resources mapeditor/widget view
svn at biggeruniverse.com
svn at biggeruniverse.com
Sat Nov 4 10:53:05 PST 2006
Author: bjorn
Date: 2006-11-04 12:53:04 -0600 (Sat, 04 Nov 2006)
New Revision: 704
Added:
trunk/src/tiled/mapeditor/resources/propertyflag-12.png
Modified:
trunk/src/tiled/core/TileLayer.java
trunk/src/tiled/mapeditor/MapEditor.java
trunk/src/tiled/mapeditor/Resources.java
trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java
trunk/src/tiled/mapeditor/widget/ResizePanel.java
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:
Applied patches tipfix2 and propflags1 by Christian Henz, improving the implementation of tile instance properties.
Modified: trunk/src/tiled/core/TileLayer.java
===================================================================
--- trunk/src/tiled/core/TileLayer.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/core/TileLayer.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -16,6 +16,7 @@
import java.awt.Rectangle;
import java.awt.geom.Area;
import java.util.Properties;
+import java.util.HashMap;
/**
* A TileLayer is a specialized MapLayer, used for tracking two dimensional
@@ -26,31 +27,31 @@
public class TileLayer extends MapLayer
{
protected Tile[][] map;
- protected Properties[][] tileInstanceProperties;
+ protected HashMap tileInstanceProperties = new HashMap();
public Properties getTileInstancePropertiesAt(int x, int y) {
- try {
- return tileInstanceProperties[y - bounds.y][x - bounds.x];
- } catch (ArrayIndexOutOfBoundsException e) {
+ if (!bounds.contains(x, y)) {
return null;
}
+ Object key = new Point(x, y);
+ return (Properties) tileInstanceProperties.get(key);
}
public void setTileInstancePropertiesAt(int x, int y, Properties tip) {
- try {
- tileInstanceProperties[y - bounds.y][x - bounds.x] = tip;
- } catch (ArrayIndexOutOfBoundsException e) {
+ if (bounds.contains(x, y)) {
+ Object key = new Point(x, y);
+ tileInstanceProperties.put(key, tip);
}
}
/**
- * Default contructor
+ * Default contructor.
*/
public TileLayer() {
}
/**
- * Construct a TileLayer from the given width and height
+ * Construct a TileLayer from the given width and height.
*
* @param w width in tiles
* @param h height in tiles
@@ -194,13 +195,18 @@
* this causes a reallocation of the data array, and all previous data is
* lost.
*
- * @param bounds
+ * @param bounds new new bounds of this tile layer (in tiles)
* @see MapLayer#setBounds
*/
protected void setBounds(Rectangle bounds) {
super.setBounds(bounds);
map = new Tile[bounds.height][bounds.width];
- tileInstanceProperties = new Properties[bounds.height][bounds.width];
+
+ // Tile instance properties is null when this method is called from
+ // the constructor of MapLayer
+ if (tileInstanceProperties != null) {
+ tileInstanceProperties.clear();
+ }
}
/**
@@ -247,7 +253,7 @@
* is locked, an exception is thrown.
*
* @param tile the Tile to be removed
- * @throws LayerLockedException
+ * @throws LayerLockedException when this layer is locked
*/
public void removeTile(Tile tile) throws LayerLockedException {
if (getLocked()) {
@@ -400,7 +406,7 @@
}
/**
- * Unlike mergeOnto, copyTo includes the null tile when merging
+ * Unlike mergeOnto, copyTo includes the null tile when merging.
*
* @see MapLayer#copyFrom
* @see MapLayer#mergeOnto
@@ -429,16 +435,18 @@
// Clone the layer data
clone.map = new Tile[map.length][];
- clone.tileInstanceProperties = new Properties[map.length][];
+ clone.tileInstanceProperties = new HashMap();
for (int i = 0; i < map.length; i++) {
clone.map[i] = new Tile[map[i].length];
System.arraycopy(map[i], 0, clone.map[i], 0, map[i].length);
- clone.tileInstanceProperties[i] = new Properties[map[i].length];
for (int j = 0; j < map[i].length; j++) {
- if (tileInstanceProperties[i][j] != null) {
- clone.tileInstanceProperties[i][j] = new Properties(tileInstanceProperties[i][j]);
+ Properties p = getTileInstancePropertiesAt(i, j);
+
+ if (p != null) {
+ Integer key = new Integer(i + j * bounds.width);
+ clone.tileInstanceProperties.put(key, p.clone());
}
}
}
@@ -459,7 +467,7 @@
return;
Tile[][] newMap = new Tile[height][width];
- Properties[][] newTileInstanceProperties = new Properties[height][width];
+ HashMap newTileInstanceProperties = new HashMap();
int maxX = Math.min(width, bounds.width + dx);
int maxY = Math.min(height, bounds.height + dy);
@@ -467,7 +475,11 @@
for (int x = Math.max(0, dx); x < maxX; x++) {
for (int y = Math.max(0, dy); y < maxY; y++) {
newMap[y][x] = getTileAt(x - dx, y - dy);
- newTileInstanceProperties[y][x] = getTileInstancePropertiesAt(x - dx, y - dy);
+
+ Properties tip = getTileInstancePropertiesAt(x - dx, y - dy);
+ if (tip != null) {
+ newTileInstanceProperties.put(new Point(x, y), tip);
+ }
}
}
Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/mapeditor/MapEditor.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -1141,31 +1141,31 @@
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
- if (command.equals("paint")) {
+ if ("paint".equals(command)) {
setCurrentPointerState(PS_PAINT);
resetBrush();
- } else if (command.equals("erase")) {
+ } else if ("erase".equals(command)) {
setCurrentPointerState(PS_ERASE);
resetBrush();
- } else if (command.equals("point")) {
+ } else if ("point".equals(command)) {
setCurrentPointerState(PS_POINT);
resetBrush();
- } else if (command.equals("pour")) {
+ } else if ("pour".equals(command)) {
setCurrentPointerState(PS_POUR);
resetBrush();
- } else if (command.equals("eyed")) {
+ } else if ("eyed".equals(command)) {
setCurrentPointerState(PS_EYED);
resetBrush();
- } else if (command.equals("marquee")) {
+ } else if ("marquee".equals(command)) {
setCurrentPointerState(PS_MARQUEE);
resetBrush();
- } else if (command.equals("move")) {
+ } else if ("move".equals(command)) {
setCurrentPointerState(PS_MOVE);
resetBrush();
- } else if (command.equals("moveobject")) {
+ } else if ("moveobject".equals(command)) {
setCurrentPointerState(PS_MOVEOBJ);
resetBrush();
- } else if (command.equals("palette")) {
+ } else if ("palette".equals(command)) {
if (currentMap != null) {
if (tilePaletteDialog == null) {
tilePaletteDialog =
@@ -1173,7 +1173,7 @@
}
tilePaletteDialog.setVisible(true);
}
- } else if (command.equals("tileInstanceProperties")) {
+ } else if ("tileInstanceProperties".equals(command)) {
if (currentMap != null) {
tileInstancePropertiesDialog.setVisible(true);
}
@@ -1870,7 +1870,7 @@
}
if (filename != null) {
- MapView myView = MapView.createViewforMap(currentMap);
+ MapView myView = MapView.createViewforMap(currentMap, this);
myView.setShowGrid(mapView.getShowGrid());
myView.setMode(MapView.PF_NOSPECIAL, true);
myView.setZoom(mapView.getZoom());
@@ -1964,7 +1964,7 @@
} else {
final Preferences display = prefs.node("display");
mapEventAdapter.fireEvent(MapEventAdapter.ME_MAPACTIVE);
- mapView = MapView.createViewforMap(currentMap);
+ mapView = MapView.createViewforMap(currentMap, this);
mapView.addMouseListener(this);
mapView.addMouseMotionListener(this);
mapView.addComponentListener(this);
@@ -1979,8 +1979,6 @@
mapScrollPane.setViewport(mapViewport);
setCurrentPointerState(PS_PAINT);
- currentMap.addMapChangeListener(this);
-
gridMenuItem.setState(mapView.getShowGrid());
coordinatesMenuItem.setState(
mapView.getMode(MapView.PF_COORDINATES));
Modified: trunk/src/tiled/mapeditor/Resources.java
===================================================================
--- trunk/src/tiled/mapeditor/Resources.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/mapeditor/Resources.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -54,7 +54,7 @@
* @throws IOException if an error occurs during reading
* @throws IllegalArgumentException when the resource could not be found
*/
- private static Image getImage(String filename) throws IOException,
+ public static Image getImage(String filename) throws IOException,
IllegalArgumentException {
return ImageIO.read(Resources.class.getResourceAsStream(
"resources/" + filename));
Modified: trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -14,6 +14,7 @@
import java.awt.Dimension;
import java.awt.Rectangle;
+import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
@@ -21,6 +22,8 @@
import java.util.Properties;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
+import javax.swing.event.TableModelListener;
+import javax.swing.event.TableModelEvent;
import tiled.core.MapLayer;
import tiled.core.Tile;
@@ -35,9 +38,9 @@
* @version $Id$
*/
public class TileInstancePropertiesDialog extends JDialog
+ implements TableModelListener
{
private JTable propertiesTable;
- private Properties properties = new Properties();
private PropertiesTableModel tableModel = new PropertiesTableModel();
private static final String DIALOG_TITLE = "Tile Properties"; // todo: Resource this
@@ -46,16 +49,40 @@
private static final String DELETE_BUTTON = Resources.getString("general.button.delete");
private final MapEditor editor;
- private LinkedList propertiesList = new LinkedList(); // Holds all currently selected Properties
+ /** Holds all currently selected Properties. */
+ private final LinkedList propertiesCoordinates = new LinkedList();
+ private final Properties mergedProperties = new Properties();
public TileInstancePropertiesDialog(MapEditor editor) {
super(editor.getAppFrame(), DIALOG_TITLE, false);
this.editor = editor;
+
+ tableModel.addTableModelListener(this);
+
init();
pack();
setLocationRelativeTo(getOwner());
}
+ private Properties getPropertiesAt(Point p) {
+ MapLayer ml = editor.getCurrentLayer();
+ if (!(ml instanceof TileLayer)) {
+ return null;
+ }
+
+ return ((TileLayer) ml).getTileInstancePropertiesAt(p.x, p.y);
+ }
+
+ private void setPropertiesAt(Point point, Properties properties) {
+ MapLayer ml = editor.getCurrentLayer();
+ if (!(ml instanceof TileLayer)) {
+ return;
+ }
+
+ ((TileLayer) ml).setTileInstancePropertiesAt(point.x, point.y,
+ properties);
+ }
+
private void init() {
propertiesTable = new JTable(tableModel);
JScrollPane propScrollPane = new JScrollPane(propertiesTable);
@@ -105,8 +132,9 @@
public void setSelection(SelectionLayer selection) {
// Start off fresh...
- properties.clear();
- propertiesList.clear();
+ //Properties mergedProperties = new Properties();
+ mergedProperties.clear();
+ propertiesCoordinates.clear();
// Get all properties of all selected tiles...
MapLayer ml = editor.getCurrentLayer();
@@ -116,58 +144,59 @@
int maxJ = (int) (r.getY() + r.getHeight());
int maxI = (int) (r.getX() + r.getWidth());
+ // todo: BL - Why are tiles checked on null? Surely whether a tile
+ // todo: is null or not has nothing to do with whether you can place
+ // todo: a property as a certain location?
for (int j = (int) r.getY(); j < maxJ; j++) {
for (int i = (int) r.getX(); i < maxI; i++) {
Tile t = selection.getTileAt(i, j);
if (t != null) {
- Properties p = tl.getTileInstancePropertiesAt(i, j);
- if (p != null) propertiesList.add(p);
+ propertiesCoordinates.add(new Point(i, j));
}
}
}
- }
- if (!propertiesList.isEmpty()) {
- // Start with properties of first tile instance
- Properties p = (Properties) propertiesList.get(0);
+ if (!propertiesCoordinates.isEmpty()) {
+ // Start with properties of first tile instance
+ Point point = (Point) propertiesCoordinates.get(0);
+ Properties p = tl.getTileInstancePropertiesAt(point.x, point.y);
- for (Enumeration e = p.keys(); e.hasMoreElements();) {
- String key = (String) e.nextElement();
- properties.put(key, p.getProperty(key));
- }
+ if (p != null) {
+ mergedProperties.putAll(p);
- for (int i = 1; i < propertiesList.size(); i++) {
- // Merge the other properties...
- p = (Properties) propertiesList.get(i);
+ for (int i = 1; i < propertiesCoordinates.size(); i++) {
+ // Merge the other properties...
+ point = (Point) propertiesCoordinates.get(i);
+ p = tl.getTileInstancePropertiesAt(point.x, point.y);
- for (Enumeration e = properties.keys(); e.hasMoreElements();) {
- // We only care for properties that are already "known"...
+ if (p != null) {
+ for (Enumeration e = mergedProperties.keys(); e.hasMoreElements();) {
+ // We only care for properties that are already "known"...
+ String key = (String) e.nextElement();
+ String val = mergedProperties.getProperty(key);
+ String mval = p.getProperty(key);
- String key = (String) e.nextElement();
- String val = properties.getProperty(key);
- String mval = p.getProperty(key);
-
- if (mval == null) {
- properties.remove(key); // Drop non-common properties
- } else if (!mval.equals(val)) {
- properties.setProperty(key, "?"); // Hide non-common values
+ if (mval == null) {
+ // Drop non-common properties
+ mergedProperties.remove(key);
+ } else if (!mval.equals(val)) {
+ // Hide non-common values
+ mergedProperties.setProperty(key, "?");
+ }
+ }
+ } else {
+ mergedProperties.clear();
+ break;
+ }
}
}
}
}
- updateInfo(); // Refresh display
+ tableModel.setProperties(mergedProperties);
}
- private void updateInfo() {
- tableModel.setProperties(properties);
- }
- public void getProps() {
- updateInfo();
- setVisible(true);
- }
-
private void buildPropertiesAndApply() {
// Make sure there is no active cell editor anymore
TableCellEditor cellEditor = propertiesTable.getCellEditor();
@@ -176,17 +205,15 @@
}
// Apply possibly changed properties.
- properties.clear();
- properties.putAll(tableModel.getProperties());
-
applyPropertiesToTiles();
}
private void deleteFromSelectedTiles(String key) {
- for (int i = 0; i < propertiesList.size(); i++) {
- Properties p = (Properties) propertiesList.get(i);
- p.remove(key);
+ for (int i = 0; i < propertiesCoordinates.size(); i++) {
+ Point point = (Point) propertiesCoordinates.get(i);
+ Properties p = getPropertiesAt(point);
+ if (p != null) p.remove(key);
}
}
@@ -208,18 +235,48 @@
}
private void applyPropertiesToTiles() {
- for (int i = 0; i < propertiesList.size(); i++) {
- Properties tp = (Properties) propertiesList.get(i);
+ Properties properties = tableModel.getProperties();
- for (Enumeration e = properties.keys();
- e.hasMoreElements();) {
+ // First delete all Properties that were previously selected
+ for( int i = 0; i < propertiesCoordinates.size(); i++ ) {
+ Point point = (Point) propertiesCoordinates.get( i );
+ Properties tp = getPropertiesAt( point );
+ if (tp != null) {
+ for (Enumeration e = mergedProperties.keys();
+ e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ String val = (String) properties.get(key);
+
+ if (!"?".equals(val)) {
+ // Property was removed or has a valid new value
+ tp.remove(key);
+ }
+ }
+ }
+ }
+
+ // Now update all selected Properties with the
+ // new data
+ for (int i = 0; i < propertiesCoordinates.size(); i++) {
+ Point point = (Point) propertiesCoordinates.get(i);
+ Properties tp = getPropertiesAt(point);
+ if (tp == null) {
+ tp = new Properties();
+ setPropertiesAt( point, tp );
+ }
+
+ for (Enumeration e = properties.keys(); e.hasMoreElements();) {
String key = (String) e.nextElement();
String val = properties.getProperty(key);
- if (!val.equals("?")) {
+ if (!"?".equals(val)) {
tp.setProperty(key, val);
}
}
}
}
+
+ public void tableChanged(TableModelEvent e) {
+ applyPropertiesToTiles();
+ }
}
Added: trunk/src/tiled/mapeditor/resources/propertyflag-12.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/tiled/mapeditor/resources/propertyflag-12.png
___________________________________________________________________
Name: svn:mime-type
+ image/png
Modified: trunk/src/tiled/mapeditor/widget/ResizePanel.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/ResizePanel.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/mapeditor/widget/ResizePanel.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -50,7 +50,7 @@
DragHandler dragHandler = new DragHandler();
- inner = MapView.createViewforMap(map);
+ inner = MapView.createViewforMap(map, null);
inner.setZoom(zoom);
inner.addMouseListener(dragHandler);
inner.addMouseMotionListener(dragHandler);
Modified: trunk/src/tiled/view/HexMapView.java
===================================================================
--- trunk/src/tiled/view/HexMapView.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/view/HexMapView.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -60,7 +60,7 @@
* @param map the map to be displayed by this map view
*/
public HexMapView(Map map) {
- super(map);
+ super(map, null);
}
public int getScrollableBlockIncrement(Rectangle visibleRect,
@@ -188,6 +188,10 @@
// TODO: Implement paintCoordinates for HexMapView
}
+ protected void paintPropertyFlags(Graphics2D g2d, TileLayer layer) {
+ throw new RuntimeException("Not yet implemented"); // todo
+ }
+
public Point screenToTileCoords(int screenX, int screenY) {
// An algorithm copied from the net years ago
// Note the C style short variable names :-)
Modified: trunk/src/tiled/view/IsoMapView.java
===================================================================
--- trunk/src/tiled/view/IsoMapView.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/view/IsoMapView.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -32,7 +32,7 @@
* @param map the map to be displayed by this map view
*/
public IsoMapView(Map map) {
- super(map);
+ super(map, null);
}
public int getScrollableBlockIncrement(Rectangle visibleRect,
@@ -204,6 +204,10 @@
}
}
+ protected void paintPropertyFlags(Graphics2D g2d, TileLayer layer) {
+ throw new RuntimeException("Not yet implemented"); // todo
+ }
+
public void repaintRegion(Rectangle region) {
Dimension tileSize = getTileSize();
int maxExtraHeight =
Modified: trunk/src/tiled/view/MapView.java
===================================================================
--- trunk/src/tiled/view/MapView.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/view/MapView.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -18,6 +18,8 @@
import javax.swing.Scrollable;
import tiled.core.*;
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
import tiled.mapeditor.brush.Brush;
import tiled.mapeditor.selection.SelectionLayer;
@@ -52,15 +54,35 @@
};
private static final Color DEFAULT_BACKGROUND_COLOR = new Color(64, 64, 64);
+ /** The default grid color (black). */
public static final Color DEFAULT_GRID_COLOR = Color.black;
+ protected static Image propertyFlagImage;
+
+ // todo: BL - The map view should NOT need the editor. It is currently used
+ // todo: to determine whether to draw property flags based on the selected
+ // todo: layer. A better solution has to be found.
+ private final MapEditor editor;
+
/**
* Creates a new <code>MapView</code> that displays the specified map.
*
* @param map the map to be displayed by this map view
*/
- protected MapView(Map map) {
+ protected MapView(Map map, MapEditor editor) {
+ // Setup static bits on first invocation
+ if (MapView.propertyFlagImage == null) {
+ try {
+ MapView.propertyFlagImage =
+ Resources.getImage("propertyflag-12.png");
+ }
+ catch (Exception e) {
+ }
+ }
+
this.map = map;
+ this.editor = editor;
+
setOpaque(true);
}
@@ -192,18 +214,21 @@
* @return a suitable instance of a MapView for the given Map
* @see Map#getOrientation()
*/
- public static MapView createViewforMap(Map p) {
+ public static MapView createViewforMap(Map p, MapEditor editor) {
MapView mapView = null;
int orientation = p.getOrientation();
if (orientation == Map.MDO_ISO) {
mapView = new IsoMapView(p);
- } else if (orientation == Map.MDO_ORTHO) {
- mapView = new OrthoMapView(p);
- } else if (orientation == Map.MDO_HEX) {
+ }
+ else if (orientation == Map.MDO_ORTHO) {
+ mapView = new OrthoMapView(p, editor); // FIXME
+ }
+ else if (orientation == Map.MDO_HEX) {
mapView = new HexMapView(p);
- } else if (orientation == Map.MDO_SHIFTED) {
+ }
+ else if (orientation == Map.MDO_SHIFTED) {
mapView = new ShiftedMapView(p);
}
@@ -250,11 +275,11 @@
if (layer.isVisible()) {
if (layer instanceof SelectionLayer) {
g2d.setComposite(AlphaComposite.getInstance(
- AlphaComposite.SRC_ATOP, 0.3f));
+ AlphaComposite.SRC_ATOP, 0.3f));
g2d.setColor(
- ((SelectionLayer)layer).getHighlightColor());
+ ((SelectionLayer) layer).getHighlightColor());
}
- paintLayer(g2d, (TileLayer)layer);
+ paintLayer(g2d, (TileLayer) layer);
}
}
@@ -272,18 +297,20 @@
if (gridOpacity < 255) {
g2d.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_ATOP,
- (float)gridOpacity / 255.0f));
- } else {
+ (float) gridOpacity / 255.0f));
+ }
+ else {
g2d.setComposite(AlphaComposite.SrcOver);
}
// Configure grid antialiasing
if (antialiasGrid) {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- } else {
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ }
+ else {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_OFF);
+ RenderingHints.VALUE_ANTIALIAS_OFF);
}
g2d.setStroke(new BasicStroke());
@@ -294,27 +321,39 @@
g2d.setComposite(AlphaComposite.SrcOver);
paintCoordinates(g2d);
}
+
+ if (editor != null && editor.getCurrentLayer() instanceof TileLayer) {
+ g2d.setComposite(AlphaComposite.SrcOver);
+
+ TileLayer tl = (TileLayer) editor.getCurrentLayer();
+ if (tl != null && tl.isVisible()) {
+ paintPropertyFlags(g2d, tl);
+ }
+ }
}
- public void paintSubMap(MultilayerPlane m, Graphics2D g2d, float mapOpacity) {
- Iterator li = m.getLayers();
- MapLayer layer;
+ public void paintSubMap(MultilayerPlane m, Graphics2D g2d,
+ float mapOpacity) {
+ Iterator li = m.getLayers();
+ MapLayer layer;
- while (li.hasNext()) {
+ while (li.hasNext()) {
layer = (MapLayer) li.next();
if (layer != null) {
float opacity = layer.getOpacity() * mapOpacity;
if (layer.isVisible() && opacity > 0.0f) {
if (opacity < 1.0f) {
g2d.setComposite(AlphaComposite.getInstance(
- AlphaComposite.SRC_ATOP, opacity));
- } else {
+ AlphaComposite.SRC_ATOP, opacity));
+ }
+ else {
g2d.setComposite(AlphaComposite.SrcOver);
}
if (layer instanceof TileLayer) {
paintLayer(g2d, (TileLayer) layer);
- } else if (layer instanceof ObjectGroup) {
+ }
+ else if (layer instanceof ObjectGroup) {
paintObjectGroup(g2d, (ObjectGroup) layer);
}
}
@@ -419,6 +458,8 @@
*/
protected abstract void paintCoordinates(Graphics2D g2d);
+ protected abstract void paintPropertyFlags(Graphics2D g2d, TileLayer layer);
+
/**
* Returns a Polygon that matches the grid around the specified <b>Map</b>.
*
@@ -432,5 +473,6 @@
// Conversion functions
public abstract Point screenToTileCoords(int x, int y);
+
public abstract Point tileToScreenCoords(double x, double y);
}
Modified: trunk/src/tiled/view/OrthoMapView.java
===================================================================
--- trunk/src/tiled/view/OrthoMapView.java 2006-11-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/view/OrthoMapView.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -12,21 +12,15 @@
package tiled.view;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.Polygon;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
+import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.util.Iterator;
-
+import java.util.Properties;
import javax.swing.SwingConstants;
import tiled.core.*;
+import tiled.mapeditor.MapEditor;
import tiled.mapeditor.selection.SelectionLayer;
/**
@@ -39,8 +33,8 @@
*
* @param map the map to be displayed by this map view
*/
- public OrthoMapView(Map map) {
- super(map);
+ public OrthoMapView(Map map, MapEditor editor) {
+ super(map, editor);
}
public int getScrollableBlockIncrement(Rectangle visibleRect,
@@ -49,7 +43,8 @@
if (orientation == SwingConstants.VERTICAL) {
return (visibleRect.height / tsize.height) * tsize.height;
- } else {
+ }
+ else {
return (visibleRect.width / tsize.width) * tsize.width;
}
}
@@ -59,7 +54,8 @@
Dimension tsize = getTileSize();
if (orientation == SwingConstants.VERTICAL) {
return tsize.height;
- } else {
+ }
+ else {
return tsize.width;
}
}
@@ -75,7 +71,9 @@
protected void paintLayer(Graphics2D g2d, TileLayer layer) {
// Determine tile size and offset
Dimension tsize = getTileSize();
- if (tsize.width <= 0 || tsize.height <= 0) return;
+ if (tsize.width <= 0 || tsize.height <= 0) {
+ return;
+ }
Polygon gridPoly = createGridPolygon(0, -tsize.height, 0);
// Determine area to draw from clipping rectangle
@@ -99,7 +97,8 @@
g2d.fillPolygon(gridPoly);
gridPoly.translate(-gx, -gy);
//paintEdge(g, layer, gx, gy);
- } else {
+ }
+ else {
tile.draw(g2d, gx, gy, zoom);
}
}
@@ -116,10 +115,11 @@
double oy = mo.getY() * zoom;
g.setColor(Color.black);
- g.fillOval((int)ox, (int)oy, (int)(10 * zoom), (int)(10 * zoom));
+ g.fillOval((int) ox, (int) oy, (int) (10 * zoom),
+ (int) (10 * zoom));
if (zoom > 0.0625) {
g.setColor(Color.white);
- g.drawString(mo.getType(), (int)(ox - 12), (int)(oy - 5));
+ g.drawString(mo.getType(), (int) (ox - 12), (int) (oy - 5));
}
}
}
@@ -127,7 +127,9 @@
protected void paintGrid(Graphics2D g2d) {
// Determine tile size
Dimension tsize = getTileSize();
- if (tsize.width <= 0 || tsize.height <= 0) return;
+ if (tsize.width <= 0 || tsize.height <= 0) {
+ return;
+ }
// Determine lines to draw from clipping rectangle
Rectangle clipRect = g2d.getClipBounds();
@@ -146,9 +148,11 @@
protected void paintCoordinates(Graphics2D g2d) {
Dimension tsize = getTileSize();
- if (tsize.width <= 0 || tsize.height <= 0) return;
+ if (tsize.width <= 0 || tsize.height <= 0) {
+ return;
+ }
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// Determine tile size and offset
Font font = new Font("SansSerif", Font.PLAIN, tsize.height / 4);
@@ -169,10 +173,10 @@
for (int x = startX; x < endX; x++) {
String coords = "(" + x + "," + y + ")";
Rectangle2D textSize =
- font.getStringBounds(coords, fontRenderContext);
+ font.getStringBounds(coords, fontRenderContext);
- int fx = gx + (int)((tsize.width - textSize.getWidth()) / 2);
- int fy = gy + (int)((tsize.height + textSize.getHeight()) / 2);
+ int fx = gx + (int) ((tsize.width - textSize.getWidth()) / 2);
+ int fy = gy + (int) ((tsize.height + textSize.getHeight()) / 2);
g2d.drawString(coords, fx, fy);
gx += tsize.width;
@@ -181,11 +185,60 @@
}
}
+
+ protected void paintPropertyFlags(Graphics2D g2d, TileLayer layer) {
+
+ 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();
+
+ // Determine area to draw from clipping rectangle
+ Rectangle clipRect = g2d.getClipBounds();
+ int startX = clipRect.x / tsize.width;
+ int startY = clipRect.y / tsize.height;
+ int endX = (clipRect.x + clipRect.width) / tsize.width + 1;
+ int endY = (clipRect.y + clipRect.height) / tsize.height + 1;
+
+ int y = startY * tsize.height;
+
+ for (int j = startY; j <= endY; j++) {
+ int x = startX * tsize.width;
+
+ for (int i = startX; i <= endX; i++) {
+ try {
+ Properties p = layer.getTileInstancePropertiesAt(i, j);
+ if (p == null || p.isEmpty()) {
+ }
+ else {
+ //g2d.drawString( "PROP", x, y );
+ g2d.drawImage(MapView.propertyFlagImage, x, y, null);
+ }
+ }
+ catch (Exception e) {
+ System.out.print("Exception\n");
+ }
+
+ x += tsize.width;
+ }
+ y += tsize.height;
+ }
+ }
+
public void repaintRegion(Rectangle region) {
Dimension tsize = getTileSize();
- if (tsize.width <= 0 || tsize.height <= 0) return;
+ if (tsize.width <= 0 || tsize.height <= 0) {
+ return;
+ }
int maxExtraHeight =
- (int)(map.getTileHeightMax() * zoom - tsize.height);
+ (int) (map.getTileHeightMax() * zoom - tsize.height);
// Calculate the visible corners of the region
int startX = region.x * tsize.width;
@@ -206,8 +259,8 @@
protected Dimension getTileSize() {
return new Dimension(
- (int)(map.getTileWidth() * zoom),
- (int)(map.getTileHeight() * zoom));
+ (int) (map.getTileWidth() * zoom),
+ (int) (map.getTileHeight() * zoom));
}
protected Polygon createGridPolygon(int tx, int ty, int border) {
@@ -224,6 +277,6 @@
public Point tileToScreenCoords(double x, double y) {
Dimension tsize = getTileSize();
- return new Point((int)x * tsize.width, (int)y * tsize.height);
+ 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-04 16:46:32 UTC (rev 703)
+++ trunk/src/tiled/view/ShiftedMapView.java 2006-11-04 18:53:04 UTC (rev 704)
@@ -33,7 +33,7 @@
* @param map the map to be displayed by this map view
*/
public ShiftedMapView(Map map) {
- super(map);
+ super(map, null);
horSide = 16;
verSide = 0;
@@ -118,6 +118,10 @@
protected void paintCoordinates(Graphics2D g2d) {
}
+ protected void paintPropertyFlags(Graphics2D g2d, TileLayer layer) {
+ throw new RuntimeException("Not yet implemented"); // todo
+ }
+
public void repaintRegion(Rectangle region) {
}
More information about the tiled-commit
mailing list