[Picross-commit] SF.net SVN: picross: [27] trunk/src/picross/grid/GridUI.java
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-08 12:27:54
|
Revision: 27 http://picross.svn.sourceforge.net/picross/?rev=27&view=rev Author: yvan_norsa Date: 2007-06-08 05:27:52 -0700 (Fri, 08 Jun 2007) Log Message: ----------- precomputes the grid blocks Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-08 12:07:03 UTC (rev 26) +++ trunk/src/picross/grid/GridUI.java 2007-06-08 12:27:52 UTC (rev 27) @@ -37,13 +37,18 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.font.FontRenderContext; +import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.List; + import javax.swing.ImageIcon; import javax.swing.JPanel; @@ -178,6 +183,9 @@ /** Used to center a high hint horizontally. */ private int centerHighHintWidth; + /** Boxes blocks. */ + private List<Line2D> blocksLines; + /*** Constructor ***/ /** @@ -292,6 +300,8 @@ //GridUI.log.debug("rightBoundary : " + this.rightBoundary); //GridUI.log.debug("bottomBoundary : " + this.bottomBoundary); + this.initBlocks(); + this.setPreferredSize(new Dimension(this.rightBoundary + GridUI.RIGHT_SPACE, this.bottomBoundary @@ -304,7 +314,7 @@ protected void paintComponent(Graphics g) { super.paintComponent(g); - Graphics newG = g.create(); + Graphics2D newG = (Graphics2D) g.create(); Rectangle clipRect = newG.getClipBounds(); @@ -317,7 +327,6 @@ } // Paints the boxes - for (int i = 0; i < this.width; i++) { for (int j = 0; j < this.height; j++) { //GridUI.log.debug("currentRect : " + i + "," + j); @@ -341,6 +350,19 @@ // Draws the blocks newG.setColor(GridUI.BLOCKS_COLOR); + for (Line2D line : this.blocksLines) { + newG.draw(line); + } + + newG.dispose(); + } + + /*** Methods ***/ + + /** Precomputes the blocks lines. */ + private void initBlocks() { + this.blocksLines = new ArrayList<Line2D>(); + int boxWidth = GridUI.BLOCK_WIDTH * GridUI.BOX_WIDTH; int boxHeight = GridUI.BLOCK_HEIGHT * GridUI.BOX_HEIGHT; @@ -354,22 +376,30 @@ while (j < this.width) { if ((i + GridUI.BLOCK_HEIGHT) <= this.height) { if ((j + GridUI.BLOCK_WIDTH <= this.width)) { - newG.drawRect(currentX, currentY, - boxWidth, boxHeight); + GridUI.addRectToLines(this.blocksLines, + currentX, currentY, + boxWidth, boxHeight); } else { - newG.drawRect(currentX, currentY, - (this.width - j) * GridUI.BOX_WIDTH, - boxHeight); + GridUI.addRectToLines(this.blocksLines, + currentX, currentY, + (this.width - j) + * GridUI.BOX_WIDTH, + boxHeight); } } else { if ((j + GridUI.BLOCK_WIDTH <= this.width)) { - newG.drawRect(currentX, currentY, - boxWidth, - (this.height - i) * GridUI.BOX_HEIGHT); + GridUI.addRectToLines(this.blocksLines, + currentX, currentY, + boxWidth, + (this.height - i) + * GridUI.BOX_HEIGHT); } else { - newG.drawRect(currentX, currentY, - (this.width - j) * GridUI.BOX_WIDTH, - (this.height - i) * GridUI.BOX_HEIGHT); + GridUI.addRectToLines(this.blocksLines, + currentX, currentY, + (this.width - j) + * GridUI.BOX_WIDTH, + (this.height - i) + * GridUI.BOX_HEIGHT); } } @@ -380,12 +410,25 @@ currentY += boxHeight; i += GridUI.BLOCK_HEIGHT; } + } - newG.dispose(); + /** + * Add a rectangle lines to a list. + * + * @param lines list to add the lines to + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width width of the rectangle + * @param height height of the retangle + */ + private static void addRectToLines(List<Line2D> lines, + int x, int y, int width, int height) { + lines.add(new Line2D.Double(x, y, x + width, y)); + lines.add(new Line2D.Double(x, y, x, y + height)); + lines.add(new Line2D.Double(x + width, y + height, x, y + height)); + lines.add(new Line2D.Double(x + width, y + height, x + width, y)); } - /*** Methods ***/ - /** * Draws the top hints. * @@ -573,4 +616,3 @@ } } } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |