[vassalengine-svn] SF.net SVN: vassalengine: [1968] VASSAL-src/branches/uckelman-tiling/VASSAL /bui
Brought to you by:
rodneykinney,
uckelman
From: <uck...@us...> - 2007-04-24 18:58:57
|
Revision: 1968 http://svn.sourceforge.net/vassalengine/?rev=1968&view=rev Author: uckelman Date: 2007-04-24 11:58:53 -0700 (Tue, 24 Apr 2007) Log Message: ----------- Current state of Map during repaint changes. Modified Paths: -------------- VASSAL-src/branches/uckelman-tiling/VASSAL/build/module/Map.java Modified: VASSAL-src/branches/uckelman-tiling/VASSAL/build/module/Map.java =================================================================== --- VASSAL-src/branches/uckelman-tiling/VASSAL/build/module/Map.java 2007-04-24 18:57:37 UTC (rev 1967) +++ VASSAL-src/branches/uckelman-tiling/VASSAL/build/module/Map.java 2007-04-24 18:58:53 UTC (rev 1968) @@ -511,16 +511,16 @@ } /** - * Every map must include a {@link StackMetrics} as one of its build components, which governs the stacking behavior - * of GamePieces on the map + * Every map must include a {@link StackMetrics} as one of its build + * components, which governs the stacking behavior of GamePieces on the map */ public void setStackMetrics(StackMetrics sm) { metrics = sm; } /** - * Every map must include a {@link StackMetrics} as one of its build components, which governs the stacking behavior - * of GamePieces on the map + * Every map must include a {@link StackMetrics} as one of its build + * components, which governs the stacking behavior of GamePieces on the map * * @return the StackMetrics for this map */ @@ -567,9 +567,10 @@ } /** - * Expects to be added to a {@link GameModule}. Determines a unique id for this map. Registers itself as - * {@link KeyStrokeSource}. Registers itself as a {@link GameComponent}. Registers itself as a drop target and drag - * source + * Expects to be added to a {@link GameModule}. Determines a unique id + * for this map. Registers itself as {@link KeyStrokeSource}. Registers + * itself as a {@link GameComponent}. Registers itself as a drop target + * and drag source * * @see #getId * @see DragBuffer @@ -623,11 +624,12 @@ } public void sideChanged(String oldSide, String newSide) { - repaint(); // FIXME + repaint(); // FIXME: what is a minimal repaint here? } /** - * Set the boards for this map. Each map may contain more than one {@link Board} + * Set the boards for this map. + * Each map may contain more than one {@link Board}. */ public synchronized void setBoards(Enumeration boardList) { boards.removeAllElements(); @@ -706,6 +708,7 @@ } return r; } + /** * Return the board with the given name * @@ -731,7 +734,8 @@ } /** - * @return the size of the map in pixels at 100% zoom, including the edge buffer + * @return the size of the map in pixels at 100% zoom, including the + * edge buffer */ public synchronized Dimension mapSize() { Rectangle r = new Rectangle(0, 0); @@ -745,8 +749,8 @@ } /** - * @return true if the given point may not be a local location. I.e., if this grid will attempt to snap it to the - * nearest grid location + * @return true if the given point may not be a local location. + * I.e., if this grid will attempt to snap it to the nearest grid location */ public boolean isLocationRestricted(Point p) { Board b = findBoard(p); @@ -1018,20 +1022,34 @@ public static Map activeMap = null; public static void clearActiveMap() { if (activeMap != null) { - activeMap.repaint(); // FIXME +// activeMap.repaint(); // FIXME: repaint selection only! activeMap = null; } } public void mousePressed(MouseEvent e) { - // Deselect any counters on the last Map with focus - if (!this.equals(activeMap)) { + if (this != activeMap) { + java.util.List l = new ArrayList(); + // FIXME: getPieces() should return an Iterator! + for (Enumeration en = KeyBuffer.getBuffer().getPieces(); + en.hasMoreElements(); ) { + GamePiece p = (GamePiece) en.nextElement(); + if (p.getMap() == activeMap) l.add(en.nextElement()); + } + + for (Iterator it = l.iterator(); it.hasNext(); ) { + GamePiece p = (GamePiece) it.next(); + KeyBuffer.getBuffer().remove(p); +// activeMap.repaint(p); + } +// FIXME: what is this intended to repaint? +/* boolean dirty = false; java.util.List l = new ArrayList(); - for (Enumeration en = KeyBuffer.getBuffer().getPieces(); en.hasMoreElements();) { - l.add(en.nextElement()); - } + for (Enumeration en = KeyBuffer.getBuffer().getPieces(); + en.hasMoreElements();) l.add(en.nextElement()); + for (Iterator it = l.iterator(); it.hasNext();) { GamePiece p = (GamePiece) it.next(); if (p.getMap() == activeMap) { @@ -1041,7 +1059,8 @@ } if (dirty && activeMap != null) { activeMap.repaint(); - } + } +*/ } activeMap = this; @@ -1083,8 +1102,8 @@ theMap.requestFocus(); } // Clicking with mouse always repaints the map - clearFirst = true; - theMap.repaint(); // FIXME +// clearFirst = true; +// theMap.repaint(); // FIXME: what is this intended to repaint? activeMap = this; } @@ -1122,7 +1141,7 @@ public void dragExit(DropTargetEvent dte) { scroll_dx = 0; scroll_dy = 0; - repaint(); // FIXME +// repaint(); // FIXME: this appears to be unnecessary } public void drop(DropTargetDropEvent dtde) { @@ -1152,6 +1171,7 @@ restartDelay(); } } + /* * Delay before starting scroll at edge */ @@ -1245,9 +1265,7 @@ theMap.repaint(); } - /** - * @deprecated FIXME - */ + /** @deprecated FIXME */ public void repaint(boolean cf) { clearFirst = cf; theMap.repaint(); @@ -1294,6 +1312,20 @@ theMap.repaint(r.x, r.y, r.width, r.height); } + /** + * Repaint the given GamePiece + */ + public void repaint(GamePiece p) { +// FIXME: maybe add a function to GamePiece which calls this? + if (p.getMap() == this) { + Point c = p.getPosition(); + Rectangle r = Boolean.TRUE.equals(p.getProperty(Properties.SELECTED)) ? + highlighter.boundingBox(p) : p.boundingBox(); + r.translate(c.x, c.y); + repaint(r); + } + } + protected void drawBoards(Graphics g) { Rectangle clip = g.getClipBounds(); @@ -1436,12 +1468,12 @@ setFocusTraversalKeysEnabled(false); map = m; -// drm = new DebugRepaintManager(this); + drm = new DebugRepaintManager(this); } protected void paintComponent(Graphics og) { -// if (RepaintManager.currentManager(this) != drm) -// RepaintManager.setCurrentManager(drm); + if (RepaintManager.currentManager(this) != drm) + RepaintManager.setCurrentManager(drm); Graphics g = (og == null) ? null : og.create(); try { Rectangle clip = g.getClipBounds(); @@ -1457,6 +1489,7 @@ */ //System.out.println("clip: " + clip); + /* try { throw new Throwable(); @@ -1588,8 +1621,8 @@ } /** - * @return an array of all GamePieces on the map. This is a read-only copy. Altering the array does not alter the - * pieces on the map. + * @return an array of all GamePieces on the map. This is a read-only + * copy. Altering the array does not alter the pieces on the map. */ public GamePiece[] getPieces() { return pieces.getPieces(); @@ -1599,6 +1632,29 @@ return pieces.getAllPieces(); } + /** + * @return an array of all GamePieces visible in the View. This is a + * read-only copy. Removing or adding elements of the array does not + * alter which pieces are on the map. + */ + public GamePiece[] getPiecesInView() { + // FIXME: do this more efficiently with a BSP tree + ArrayList visible = new ArrayList(); + Rectangle visibleRect = mapRectangle(theMap.getVisibleRect()); + GamePiece[] pp = pieces.getPieces(); + + for (int i = 0; i < pp.length; ++i) { + Point p = pp[i].getPosition(); + Rectangle bounds = pp[i].boundingBox(); + bounds.translate(p.x, p.y); + + if (bounds.intersects(visibleRect)) + visible.add(pp[i]); + } + + return (GamePiece[]) visible.toArray(); + } + public void setPieceCollection(PieceCollection pieces) { this.pieces = pieces; } @@ -1841,7 +1897,8 @@ } /** - * Use the provided {@link PieceFinder} instance to locate a visible piece at the given location + * Use the provided {@link PieceFinder} instance to locate a visible + * piece at the given location */ public GamePiece findPiece(Point pt, PieceFinder finder) { GamePiece[] stack = pieces.getPieces(); @@ -1855,8 +1912,8 @@ } /** - * Use the provided {@link PieceFinder} instance to locate any piece at the given location, regardless of whether it - * is visible or not + * Use the provided {@link PieceFinder} instance to locate any piece at + * the given location, regardless of whether it is visible or not */ public GamePiece findAnyPiece(Point pt, PieceFinder finder) { GamePiece[] stack = pieces.getAllPieces(); @@ -1937,12 +1994,13 @@ } pieces.add(p); p.setMap(this); - theMap.repaint(); // FIXME + theMap.repaint(); // FIXME: what to repaint? } } /** - * Reorder the argument GamePiece to the new index. When painting the map, pieces are drawn in order of index + * Reorder the argument GamePiece to the new index. + * When painting the map, pieces are drawn in order of index * * @deprecated use {@link PieceCollection#moveToFront} */ @@ -1950,8 +2008,8 @@ } /** - * Returns the index of a piece. When painting the map, pieces are drawn in order of index Return -1 if the piece is - * not on this map + * Returns the index of a piece. When painting the map, pieces are drawn + * in order of index Return -1 if the piece is not on this map */ public int indexOf(GamePiece s) { return pieces.indexOf(s); @@ -1962,7 +2020,7 @@ */ public void removePiece(GamePiece p) { pieces.remove(p); - theMap.repaint(); // FIXME + theMap.repaint(); // FIXME: what to repaint? } /** @@ -2255,9 +2313,10 @@ return theMap; } /** - * Implements default logic for merging pieces at a given location within a map Returns a {@link Command} that merges - * the input {@link GamePiece} with an existing piece at the input position, provided the pieces are stackable, - * visible, in the same layer, etc. + * Implements default logic for merging pieces at a given location within + * a map. Returns a {@link Command} that merges the input {@link GamePiece} + * with an existing piece at the input position, provided the pieces are + * stackable, visible, in the same layer, etc. */ public static class Merger implements DeckVisitor { private Point pt; @@ -2300,5 +2359,4 @@ } } } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |