[tiled] r763 - trunk/src/tiled/view

tiled-svn at biggeruniverse.com tiled-svn at biggeruniverse.com
Sun Jun 29 08:22:46 PDT 2008


Author: bjorn
Date: 2008-06-29 10:22:45 -0500 (Sun, 29 Jun 2008)
New Revision: 763

Modified:
   trunk/src/tiled/view/HexMapView.java
   trunk/src/tiled/view/MapView.java
   trunk/src/tiled/view/OrthoMapView.java
Log:
Added rendering of object groups to the HexMapView.
The positioning when adding objects is still a bit broken though.

Modified: trunk/src/tiled/view/HexMapView.java
===================================================================
--- trunk/src/tiled/view/HexMapView.java	2008-06-29 15:07:21 UTC (rev 762)
+++ trunk/src/tiled/view/HexMapView.java	2008-06-29 15:22:45 UTC (rev 763)
@@ -15,6 +15,7 @@
 // for console logging
 
 import java.awt.*;
+import java.util.Iterator;
 
 import javax.swing.SwingConstants;
 
@@ -461,8 +462,8 @@
         Point [] fourPoints = new Point [4];
         Point [] fourTiles = new Point [4];
 
-        int x = screenX;
-        int y = screenY;
+        final int x = screenX;
+        final int y = screenY;
 
         // determine the two columns of hexes we are between
         // we are between col and col+1.
@@ -533,21 +534,11 @@
     }
 
     /**
-     * Get the height of a tile of the map.
-     * I do not know why this function is here.
-     *
-     * @return The tile height as double.
-     */
-    private double getTileHeight() {
-        return map.getTileHeight();
-    }
-
-    /**
      * Repaint a region of the viewport.
      * This function has been disabled. I have tried it
      * but it seems to repaint with some offset.
      *
-     * @param The rectangle of the viewport to be repainted.
+     * @param region The rectangle of the viewport to be repainted.
      */
     public void repaintRegion(Rectangle region) {
         super.repaintRegion(region);
@@ -685,15 +676,53 @@
     }
 
     public Point screenToPixelCoords(int x, int y) {
-        // TODO: add proper implementation
-        return new Point();
+        return new Point(
+                (int) (x / zoom), (int) (y / zoom));
     }
 
     protected void paintPropertyFlags(Graphics2D g2d, TileLayer layer) {
-        throw new RuntimeException("Not yet implemented");    // todo
+        // TODO: Implement property flags painting for HexMapView
     }
 
-    protected void paintObjectGroup(Graphics2D g2d, ObjectGroup og) {
-        // TODO: Implement objectgroup painting for HexMapView
+    protected void paintObjectGroup(Graphics2D g, ObjectGroup og) {
+        // NOTE: Direct copy from OrthoMapView (candidate for generalization)
+        Iterator itr = og.getObjects();
+
+        while (itr.hasNext()) {
+            MapObject mo = (MapObject) itr.next();
+            double ox = mo.getX() * zoom;
+            double oy = mo.getY() * zoom;
+
+            if (mo.getWidth() == 0 || mo.getHeight() == 0) {
+                g.setRenderingHint(
+                        RenderingHints.KEY_ANTIALIASING,
+                        RenderingHints.VALUE_ANTIALIAS_ON);
+                g.setColor(Color.black);
+                g.fillOval((int) ox + 1, (int) oy + 1,
+                        (int) (10 * zoom), (int) (10 * zoom));
+                g.setColor(Color.orange);
+                g.fillOval((int) ox, (int) oy,
+                        (int) (10 * zoom), (int) (10 * zoom));
+                g.setRenderingHint(
+                        RenderingHints.KEY_ANTIALIASING,
+                        RenderingHints.VALUE_ANTIALIAS_OFF);
+            } else {
+                g.setColor(Color.black);
+                g.drawRect((int) ox + 1, (int) oy + 1,
+                    (int) (mo.getWidth() * zoom),
+                    (int) (mo.getHeight() * zoom));
+                g.setColor(Color.orange);
+                g.drawRect((int) ox, (int) oy,
+                    (int) (mo.getWidth() * zoom),
+                    (int) (mo.getHeight() * zoom));
+            }
+            if (zoom > 0.0625) {
+                final String s = mo.getName() != null ? mo.getName() : "(null)";
+                g.setColor(Color.black);
+                g.drawString(s, (int) (ox - 5) + 1, (int) (oy - 5) + 1);
+                g.setColor(Color.white);
+                g.drawString(s, (int) (ox - 5), (int) (oy - 5));
+            }
+        }
     }
 }

Modified: trunk/src/tiled/view/MapView.java
===================================================================
--- trunk/src/tiled/view/MapView.java	2008-06-29 15:07:21 UTC (rev 762)
+++ trunk/src/tiled/view/MapView.java	2008-06-29 15:22:45 UTC (rev 763)
@@ -42,8 +42,6 @@
     protected double zoom = 1.0;
     protected int zoomLevel = ZOOM_NORMALSIZE;
 
-    protected Polygon propPoly;
-    
     // Grid properties
     protected boolean showGrid;
     protected boolean antialiasGrid;
@@ -469,6 +467,15 @@
 
     public abstract Point screenToTileCoords(int x, int y);
 
+    /**
+     * Returns the pixel coordinates on the map based on the given screen
+     * coordinates. The map pixel coordinates may be different in more ways
+     * than the zoom level, depending on the projection the view implements.
+     *
+     * @param x x in screen coordinates
+     * @param y y in screen coordinates
+     * @return the position in map pixel coordinates
+     */
     public abstract Point screenToPixelCoords(int x, int y);
 
     /**

Modified: trunk/src/tiled/view/OrthoMapView.java
===================================================================
--- trunk/src/tiled/view/OrthoMapView.java	2008-06-29 15:07:21 UTC (rev 762)
+++ trunk/src/tiled/view/OrthoMapView.java	2008-06-29 15:22:45 UTC (rev 763)
@@ -27,6 +27,8 @@
  */
 public class OrthoMapView extends MapView
 {
+    private Polygon propPoly;
+
     /**
      * Creates a new orthographic map view that displays the specified map.
      *
@@ -119,9 +121,18 @@
             double oy = mo.getY() * zoom;
 
             if (mo.getWidth() == 0 || mo.getHeight() == 0) {
+                g.setRenderingHint(
+                        RenderingHints.KEY_ANTIALIASING,
+                        RenderingHints.VALUE_ANTIALIAS_ON);
+                g.setColor(Color.black);
+                g.fillOval((int) ox + 1, (int) oy + 1,
+                        (int) (10 * zoom), (int) (10 * zoom));
                 g.setColor(Color.orange);
                 g.fillOval((int) ox, (int) oy,
                         (int) (10 * zoom), (int) (10 * zoom));                
+                g.setRenderingHint(
+                        RenderingHints.KEY_ANTIALIASING,
+                        RenderingHints.VALUE_ANTIALIAS_OFF);
             } else {
                 g.setColor(Color.black);
                 g.drawRect((int) ox + 1, (int) oy + 1,
@@ -238,9 +249,7 @@
             for (int i = startX; i <= endX; i++) {
                 try {
                     Properties p = layer.getTileInstancePropertiesAt(i, j);
-                    if (p == null || p.isEmpty()) {
-                    }
-                    else {
+                    if (p != null && !p.isEmpty()) {
                         //g2d.drawString( "PROP", x, y );
                         //g2d.drawImage(MapView.propertyFlagImage, x + (tsize.width - 12), y, null);
                     	g2d.translate(x + (tsize.width - 13), y+1);




More information about the tiled-commit mailing list