[tiled] r703 - in trunk/src/tiled: mapeditor view

svn at biggeruniverse.com svn at biggeruniverse.com
Sat Nov 4 08:46:33 PST 2006


Author: bjorn
Date: 2006-11-04 10:46:32 -0600 (Sat, 04 Nov 2006)
New Revision: 703

Modified:
   trunk/src/tiled/mapeditor/MapEditor.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:
Accepted patch by Pedro Miller Rabinovitch that adds boundaries checks to middle mouse button map scrolling, as well adding ability to do left click map scrolling while holding ALT.

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-10-26 22:02:16 UTC (rev 702)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-11-04 16:46:32 UTC (rev 703)
@@ -822,8 +822,8 @@
                     Tile newTile = ((TileLayer)layer).getTileAt(tile.x, tile.y);
                     setCurrentTile(newTile);
                 } else if (currentPointerState == PS_PAINT) {
-                    //in case we are dragging to create a custom brush, let the user
-                    //know where we are creating it from
+                    // In case we are dragging to create a custom brush, let
+                    // the user know where we are creating it from
                     if (marqueeSelection == null) {
                         marqueeSelection = new SelectionLayer(
                                 currentMap.getWidth(), currentMap.getHeight());
@@ -843,32 +843,45 @@
 
                     marqueeSelection.selectRegion(selRect);
                     if (oldArea != null) {
-                        oldArea.add(
-                                marqueeSelection.getSelectedAreaBounds());
+                        oldArea.add(marqueeSelection.getSelectedAreaBounds());
                         mapView.repaintRegion(oldArea);
                     }
                 }
             } else if (layer instanceof ObjectGroup && !bMouseIsDragging) {
                 // TODO: Add support for ObjectGroups here
             }
-        } else if (mouseButton == MouseEvent.BUTTON2) {
+        } else if (mouseButton == MouseEvent.BUTTON2 ||
+                (mouseButton == MouseEvent.BUTTON1 &&
+                 (event.getModifiersEx() & MouseEvent.ALT_DOWN_MASK ) != 0)) {
             // Scroll with middle mouse button
             int dx = event.getX() - mouseInitialScreenLocation.x;
             int dy = event.getY() - mouseInitialScreenLocation.y;
-            mouseInitialScreenLocation = new Point(event.getX() - dx, event.getY() - dy);
             JViewport mapViewPort = mapScrollPane.getViewport();
             Point currentPosition = mapViewPort.getViewPosition();
-            // TODO: Take into account map boundaries in order to prevent
-            // TODO: scrolling past them
-            mapViewPort.setViewPosition(new Point(currentPosition.x - dx,
-                                                  currentPosition.y - dy));
+            mouseInitialScreenLocation = new Point(
+                    event.getX() - dx,
+                    event.getY() - dy);
+
+            Point newPosition = new Point(
+                    currentPosition.x - dx,
+                    currentPosition.y - dy);
+
+            // Take into account map boundaries in order to prevent
+            // scrolling past them
+            int maxX = mapView.getWidth() - mapViewPort.getWidth();
+            int maxY = mapView.getHeight() - mapViewPort.getHeight();
+            newPosition.x = Math.min(maxX, Math.max(0, newPosition.x));
+            newPosition.y = Math.min(maxY, Math.max(0, newPosition.y));
+
+            mapViewPort.setViewPosition(newPosition);
         } else if (mouseButton == MouseEvent.BUTTON1) {
             switch (currentPointerState) {
                 case PS_PAINT:
                     paintEdit.setPresentationName(TOOL_PAINT);
                     if (layer instanceof TileLayer) {
                         try {
-                            mapView.repaintRegion(currentBrush.doPaint(tile.x, tile.y));
+                            mapView.repaintRegion(
+                                    currentBrush.doPaint(tile.x, tile.y));
                         } catch (Exception e) {
                             e.printStackTrace();
                         }
@@ -884,15 +897,16 @@
                 case PS_POUR:  // POUR only works on TileLayers
                     paintEdit = null;
                     if (layer instanceof TileLayer) {
-                        Tile oldTile = ((TileLayer)layer).getTileAt(tile.x, tile.y);
-                        pour((TileLayer) layer, tile.x, tile.y, currentTile, oldTile);
+                        TileLayer tileLayer = (TileLayer) layer;
+                        Tile oldTile = tileLayer.getTileAt(tile.x, tile.y);
+                        pour(tileLayer, tile.x, tile.y, currentTile, oldTile);
                         mapView.repaint();
                     }
                     break;
                 case PS_EYED:
                     if (layer instanceof TileLayer) {
-                        Tile newTile = ((TileLayer)layer).getTileAt(
-                                tile.x, tile.y);
+                        TileLayer tileLayer = (TileLayer) layer;
+                        Tile newTile = tileLayer.getTileAt(tile.x, tile.y);
                         setCurrentTile(newTile);
                     } else if (layer instanceof ObjectGroup) {
                         // TODO: Add support for ObjectGroups here
@@ -956,24 +970,27 @@
         mousePressLocation = mapView.screenToTileCoords(e.getX(), e.getY());
         mouseInitialPressLocation = mousePressLocation;
 
-        if (mouseButton == MouseEvent.BUTTON1) {
+        if (mouseButton == MouseEvent.BUTTON2 ||
+                (mouseButton == MouseEvent.BUTTON1 &&
+                        (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0)) {
+            // Remember screen location for scrolling with middle mouse button
+            mouseInitialScreenLocation = new Point(e.getX(), e.getY());
+        }
+        else if (mouseButton == MouseEvent.BUTTON1) {
             switch (currentPointerState) {
                 case PS_PAINT:
                     currentBrush.startPaint(currentMap, tile.x, tile.y,
-                            mouseButton, currentLayer);
+                                            mouseButton, currentLayer);
                 case PS_ERASE:
                 case PS_POUR:
                     MapLayer layer = getCurrentLayer();
                     paintEdit =
-                        new MapLayerEdit(layer, createLayerCopy(layer), null);
+                            new MapLayerEdit(layer, createLayerCopy(layer),
+                                             null);
                     break;
                 default:
             }
         }
-        else if (mouseButton == MouseEvent.BUTTON2) {
-            // Remember screen location for scrolling with middle mouse button
-            mouseInitialScreenLocation = new Point(e.getX(), e.getY());
-        }
 
         if (currentPointerState == PS_MARQUEE) {
             if (marqueeSelection == null) {

Modified: trunk/src/tiled/view/HexMapView.java
===================================================================
--- trunk/src/tiled/view/HexMapView.java	2006-10-26 22:02:16 UTC (rev 702)
+++ trunk/src/tiled/view/HexMapView.java	2006-11-04 16:46:32 UTC (rev 703)
@@ -137,7 +137,7 @@
         }
     }
 
-    protected void paintLayer(Graphics2D g2d, ObjectGroup og) {
+    protected void paintObjectGroup(Graphics2D g2d, ObjectGroup og) {
     }
 
     /**

Modified: trunk/src/tiled/view/IsoMapView.java
===================================================================
--- trunk/src/tiled/view/IsoMapView.java	2006-10-26 22:02:16 UTC (rev 702)
+++ trunk/src/tiled/view/IsoMapView.java	2006-11-04 16:46:32 UTC (rev 703)
@@ -115,7 +115,7 @@
         }
     }
 
-    protected void paintLayer(Graphics2D g2d, ObjectGroup og) {
+    protected void paintObjectGroup(Graphics2D g2d, ObjectGroup og) {
         // TODO: Implement objectgroup painting for IsoMapView
     }
 

Modified: trunk/src/tiled/view/MapView.java
===================================================================
--- trunk/src/tiled/view/MapView.java	2006-10-26 22:02:16 UTC (rev 702)
+++ trunk/src/tiled/view/MapView.java	2006-11-04 16:46:32 UTC (rev 703)
@@ -113,6 +113,7 @@
     /**
      * Sets a new brush. The brush can draw a preview of the change while
      * editing.
+     * @param brush the new brush
      */
     public void setBrush(Brush brush) {
         currentBrush = brush;
@@ -312,9 +313,9 @@
                     }
 
                     if (layer instanceof TileLayer) {
-                        paintLayer(g2d, (TileLayer)layer);
+                        paintLayer(g2d, (TileLayer) layer);
                     } else if (layer instanceof ObjectGroup) {
-                        paintLayer(g2d, (ObjectGroup)layer);
+                        paintObjectGroup(g2d, (ObjectGroup) layer);
                     }
                 }
             }
@@ -324,6 +325,7 @@
     /**
      * Draws a TileLayer. Implemented in a subclass.
      *
+     * @param g2d   the graphics context to draw the layer onto
      * @param layer the TileLayer to be drawn
      */
     protected abstract void paintLayer(Graphics2D g2d, TileLayer layer);
@@ -331,9 +333,10 @@
     /**
      * Draws an ObjectGroup. Implemented in a subclass.
      *
+     * @param g2d   the graphics context to draw the object group onto
      * @param og    the ObjectGroup to be drawn
      */
-    protected abstract void paintLayer(Graphics2D g2d, ObjectGroup og);
+    protected abstract void paintObjectGroup(Graphics2D g2d, ObjectGroup og);
 
     protected void paintEdge(Graphics2D g2d, MapLayer layer, int x, int y) {
         /*
@@ -404,16 +407,20 @@
 
     /**
      * Draws the map grid.
+     *
+     * @param g2d the graphics context to draw the grid onto
      */
     protected abstract void paintGrid(Graphics2D g2d);
 
     /**
      * Draws the coordinates on each tile.
+     *
+     * @param g2d the graphics context to draw the coordinates onto
      */
     protected abstract void paintCoordinates(Graphics2D g2d);
 
     /**
-     * Returns a Polygon that matches the grid around the specified <b>Map</b>
+     * Returns a Polygon that matches the grid around the specified <b>Map</b>.
      *
      * @param tx
      * @param ty

Modified: trunk/src/tiled/view/OrthoMapView.java
===================================================================
--- trunk/src/tiled/view/OrthoMapView.java	2006-10-26 22:02:16 UTC (rev 702)
+++ trunk/src/tiled/view/OrthoMapView.java	2006-11-04 16:46:32 UTC (rev 703)
@@ -107,7 +107,7 @@
         }
     }
 
-    protected void paintLayer(Graphics2D g, ObjectGroup og) {
+    protected void paintObjectGroup(Graphics2D g, ObjectGroup og) {
         Iterator itr = og.getObjects();
 
         while (itr.hasNext()) {

Modified: trunk/src/tiled/view/ShiftedMapView.java
===================================================================
--- trunk/src/tiled/view/ShiftedMapView.java	2006-10-26 22:02:16 UTC (rev 702)
+++ trunk/src/tiled/view/ShiftedMapView.java	2006-11-04 16:46:32 UTC (rev 703)
@@ -77,7 +77,7 @@
     protected void paintLayer(Graphics2D g2d, TileLayer layer) {
     }
 
-    protected void paintLayer(Graphics2D g2d, ObjectGroup og) {
+    protected void paintObjectGroup(Graphics2D g2d, ObjectGroup og) {
     }
 
     protected void paintGrid(Graphics2D g2d) {




More information about the tiled-commit mailing list