Thread: [Picross-commit] SF.net SVN: picross: [23] trunk/src/picross/grid/GridUI.java
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-07 19:05:51
|
Revision: 23 http://picross.svn.sourceforge.net/picross/?rev=23&view=rev Author: yvan_norsa Date: 2007-06-07 12:05:53 -0700 (Thu, 07 Jun 2007) Log Message: ----------- code cleanup Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-07 14:57:23 UTC (rev 22) +++ trunk/src/picross/grid/GridUI.java 2007-06-07 19:05:53 UTC (rev 23) @@ -62,8 +62,11 @@ private static final long serialVersionUID = 2050855523399115878L; /** Space left before the top hints. */ - private static final int TOP_HINTS = 10 + 3; + private static final int TOP_HINTS = 13; + /** Space left after the left hints. */ + private static final int LEFT_HINTS = 10; + /** Width occupied by a row hint. */ private static final int ROW_HINT_WIDTH = 10; @@ -76,11 +79,18 @@ /** Height occupied by a column hint. */ private static final int COL_HINT_HEIGHT = 12; - private static final Color HINT_FORE_COLOR = new Color(188, 211, 227); + /** Outline color for the hints boxes. */ + private static final Color HINT_OUTLINE_COLOR = new Color(188, 211, 227); + + /** Background color for the hints boxes. */ private static final Color HINT_FILL_COLOR = new Color(131, 155, 200); + + /** Color of the hints text. */ private static final Color HINT_TEXT_COLOR = new Color(233, 246, 255); - private static final Font HINT_FONT = new Font("Sans Serif", Font.BOLD, 10); + /** Font used for the hints. */ + private static final Font HINT_FONT = + new Font("Sans Serif", Font.BOLD, 10); /** A box width. */ private static final int BOX_WIDTH = 25; @@ -94,6 +104,12 @@ /** Extra space at the bottom of the grid. */ private static final int BOTTOM_SPACE = 5; + /** Text used to compute the hints boxes size. */ + private static final String SAMPLE_HINT = "42"; + + /** Diameter of the arc for hint boxes. */ + private static final int ROUND_DIAMETER = 8; + /*** Static field ***/ /** Class' logger. */ @@ -140,7 +156,8 @@ /** Controller attached to this view. */ private transient GridController controller; - int hintBoxSize; + /** Size of the hints boxes. */ + private int hintBoxSize; /*** Constructor ***/ @@ -173,54 +190,33 @@ this.colData = colData; this.rowData = rowData; - /**/ + // Computes the size of a hint box + FontRenderContext frc = new FontRenderContext(null, true, true); + Rectangle2D textBounds = + GridUI.HINT_FONT.getStringBounds(GridUI.SAMPLE_HINT, frc); - //FontRenderContext frc = g2d.getFontRenderContext(); - FontRenderContext frc = new FontRenderContext(null, true, - true); - Rectangle2D textBounds = - GridUI.HINT_FONT - .getStringBounds("42", frc); + double textWidth = textBounds.getWidth(); + double textHeight = textBounds.getHeight(); - double textWidth = textBounds.getWidth(); - double textHeight = textBounds.getHeight(); + this.hintBoxSize = ((int) (textWidth > textHeight + ? textWidth : textHeight)) + 2; - this.hintBoxSize = (int) (textWidth > textHeight - ? textWidth : textHeight); - //this.bigHintBoxSize = this.hintBoxSize + 3; - this.hintBoxSize += 2; + // Now computes the grid boundaries - /**/ + this.leftBoundary = GridUI.LEFT_HINTS + + (this.rowData[0].length * this.hintBoxSize); - - - /* - this.leftBoundary = - this.rowData[0].length * GridUI.ROW_HINT_WIDTH; - */ - - for (int i = 0; i < this.rowData[0].length; i++) { - int size = (this.rowData[0][i] / 10) + 1; - //this.leftBoundary += size * GridUI.ROW_HINT_WIDTH; - this.leftBoundary += size * this.hintBoxSize; - } - - //this.leftBoundary = 70; - - this.leftBoundary += 10; - this.rightBoundary = this.leftBoundary + (this.width * GridUI.BOX_WIDTH); this.topBoundary = GridUI.TOP_HINTS - //+ (this.colData[0].length * GridUI.COL_HINT_HEIGHT); + (this.colData[0].length * this.hintBoxSize); - //this.topBoundary = 70; - this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); + // Space occupied by the hints + this.topHintsRect = new Rectangle(this.leftBoundary, 0, this.width * GridUI.BOX_WIDTH, this.topBoundary); @@ -280,7 +276,10 @@ for (int j = 0; j < this.colData.length; j++) { if (this.colData[j][i] != GridModel.EMPTY_HINT) { - int hintX = x + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); + // Center the hint + int hintX = x + + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); + this.drawColHint(g2d, this.colData[j][i], hintX, y); } @@ -343,66 +342,85 @@ /*** Methods ***/ - private void drawColHint(Graphics2D g2d, int value, int hintX, int y) { - g2d.setColor(GridUI.HINT_FILL_COLOR); + /** + * Draws a column hint. + * + * @param g2d the graphic context + * @param value hint value + * @param x X coordinate + * @param y Y coordinate + */ + private void drawColHint(Graphics2D g2d, int value, int x, int y) { + this.drawHintBox(g2d, x, y, GridUI.COL_HINT_HEIGHT); + this.setHintPen(g2d); - g2d.fillRoundRect(hintX, - y - GridUI.COL_HINT_HEIGHT, - this.hintBoxSize, - this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_FORE_COLOR); - - g2d.drawRoundRect(hintX, - y - GridUI.COL_HINT_HEIGHT, - this.hintBoxSize, - this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_TEXT_COLOR); - g2d.setFont(GridUI.HINT_FONT); - if (value < 10) { + // Tries to center the hint text g2d.drawString(String.valueOf(value), - hintX + (this.hintBoxSize / 3), + x + (this.hintBoxSize / 3), y); } else { g2d.drawString(String.valueOf(value), - hintX, + x, y); } } - private void drawRowHint(Graphics2D g2d, int value, int hintX, int y) { + /** + * Draws a row hint. + * + * @param g2d the graphic context + * @param value hint value + * @param x X coordinate + * @param y Y coordinate + */ + private void drawRowHint(Graphics2D g2d, int value, int x, int y) { + this.drawHintBox(g2d, x, y, GridUI.ROW_HINT_HEIGHT); + this.setHintPen(g2d); + + if (value < 10) { + g2d.drawString(String.valueOf(value), + x + (this.hintBoxSize / 3) - 1, + y - 3); + } else { + g2d.drawString(String.valueOf(value), + x + 1, + y - 3); + } + } + + /** + * Draws a hint box. + * + * @param g2d the graphic context + * @param x X coordinate + * @param y Y coordinate + * @param hintHeight the hint height + */ + private void drawHintBox(Graphics2D g2d, int x, int y, int hintHeight) { g2d.setColor(GridUI.HINT_FILL_COLOR); - - g2d.fillRoundRect(hintX, - y - GridUI.ROW_HINT_HEIGHT, + g2d.fillRoundRect(x, + y - hintHeight, this.hintBoxSize, this.hintBoxSize, - 8, 8); - - g2d.setColor(GridUI.HINT_FORE_COLOR); + GridUI.ROUND_DIAMETER, GridUI.ROUND_DIAMETER); - g2d.drawRoundRect(hintX, - y - GridUI.ROW_HINT_HEIGHT, + g2d.setColor(GridUI.HINT_OUTLINE_COLOR); + g2d.drawRoundRect(x, + y - hintHeight, this.hintBoxSize, this.hintBoxSize, - 8, 8); + GridUI.ROUND_DIAMETER, GridUI.ROUND_DIAMETER); + } + /** + * Sets the hint color and font. + * + * @param g2d the graphic context + */ + private void setHintPen(Graphics2D g2d) { g2d.setColor(GridUI.HINT_TEXT_COLOR); g2d.setFont(GridUI.HINT_FONT); - - if (value < 10) { - g2d.drawString(String.valueOf(value), - hintX + (this.hintBoxSize / 3) - 1, - y - 3); - } else { - g2d.drawString(String.valueOf(value), - hintX + 1, - y - 3); - } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-07 19:37:17
|
Revision: 24 http://picross.svn.sourceforge.net/picross/?rev=24&view=rev Author: yvan_norsa Date: 2007-06-07 12:37:17 -0700 (Thu, 07 Jun 2007) Log Message: ----------- 5x5 boxes groups Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-07 19:05:53 UTC (rev 23) +++ trunk/src/picross/grid/GridUI.java 2007-06-07 19:37:17 UTC (rev 24) @@ -338,6 +338,48 @@ } } } + + g.setColor(Color.RED); + + int currentY = this.topBoundary; + int boxWidth = 5 * GridUI.BOX_WIDTH; + int boxHeight = 5 * GridUI.BOX_HEIGHT; + + int i = 0; + + while (i < this.height) { + int currentX = this.leftBoundary; + int j = 0; + + while (j < this.width) { + if ((i + 5) <= this.height) { + if ((j + 5 <= this.width)) { + g.drawRect(currentX, currentY, + boxWidth, boxHeight); + } else { + g.drawRect(currentX, currentY, + (this.width - j) * GridUI.BOX_WIDTH, + boxHeight); + } + } else { + if ((j + 5 <= this.width)) { + g.drawRect(currentX, currentY, + boxWidth, + (this.height - i) * GridUI.BOX_HEIGHT); + } else { + g.drawRect(currentX, currentY, + (this.width - j) * GridUI.BOX_WIDTH, + (this.height - i) * GridUI.BOX_HEIGHT); + } + } + + currentX += boxWidth; + j += 5; + } + + currentY += boxHeight; + i += 5; + } } /*** Methods ***/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <yva...@us...> - 2007-06-11 10:38:35
|
Revision: 30 http://picross.svn.sourceforge.net/picross/?rev=30&view=rev Author: yvan_norsa Date: 2007-06-11 03:38:34 -0700 (Mon, 11 Jun 2007) Log Message: ----------- changed blocks drawing Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-11 10:25:17 UTC (rev 29) +++ trunk/src/picross/grid/GridUI.java 2007-06-11 10:38:34 UTC (rev 30) @@ -364,70 +364,52 @@ private void initBlocks() { this.blocksLines = new ArrayList<Line2D>(); + this.blocksLines.add(new Line2D.Double(this.leftBoundary, + this.topBoundary, + this.leftBoundary, + this.bottomBoundary)); + this.blocksLines.add(new Line2D.Double(this.leftBoundary, + this.topBoundary, + this.rightBoundary, + this.topBoundary)); + this.blocksLines.add(new Line2D.Double(this.rightBoundary, + this.bottomBoundary, + this.leftBoundary, + this.bottomBoundary)); + this.blocksLines.add(new Line2D.Double(this.rightBoundary, + this.bottomBoundary, + this.rightBoundary, + this.topBoundary)); + + int boxWidth = GridUI.BLOCK_WIDTH * GridUI.BOX_WIDTH; int boxHeight = GridUI.BLOCK_HEIGHT * GridUI.BOX_HEIGHT; + + int i = 1; + int currentY = this.topBoundary + boxHeight; - int i = 0; - int currentY = this.topBoundary; + while ((i + GridUI.BLOCK_HEIGHT) < this.height) { + this.blocksLines.add(new Line2D.Double(this.leftBoundary, + currentY, + this.rightBoundary, + currentY)); - while (i < this.height) { - int j = 0; - int currentX = this.leftBoundary; - - while (j < this.width) { - if ((i + GridUI.BLOCK_HEIGHT) <= this.height) { - if ((j + GridUI.BLOCK_WIDTH <= this.width)) { - GridUI.addRectToLines(this.blocksLines, - currentX, currentY, - boxWidth, boxHeight); - } else { - GridUI.addRectToLines(this.blocksLines, - currentX, currentY, - (this.width - j) - * GridUI.BOX_WIDTH, - boxHeight); - } - } else { - if ((j + GridUI.BLOCK_WIDTH <= this.width)) { - GridUI.addRectToLines(this.blocksLines, - currentX, currentY, - boxWidth, - (this.height - i) - * GridUI.BOX_HEIGHT); - } else { - GridUI.addRectToLines(this.blocksLines, - currentX, currentY, - (this.width - j) - * GridUI.BOX_WIDTH, - (this.height - i) - * GridUI.BOX_HEIGHT); - } - } - - currentX += boxWidth; - j += GridUI.BLOCK_WIDTH; - } - currentY += boxHeight; i += GridUI.BLOCK_HEIGHT; } - } + + i = 1; + int currentX = this.leftBoundary + boxWidth; - /** - * 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)); + while ((i + GridUI.BLOCK_WIDTH) < this.width) { + this.blocksLines.add(new Line2D.Double(currentX, + this.topBoundary, + currentX, + this.bottomBoundary)); + + currentX += boxWidth; + i += GridUI.BLOCK_WIDTH; + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-13 15:04:37
|
Revision: 33 http://picross.svn.sourceforge.net/picross/?rev=33&view=rev Author: yvan_norsa Date: 2007-06-13 08:04:38 -0700 (Wed, 13 Jun 2007) Log Message: ----------- fixed blocks drawing Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-12 14:21:43 UTC (rev 32) +++ trunk/src/picross/grid/GridUI.java 2007-06-13 15:04:38 UTC (rev 33) @@ -399,7 +399,7 @@ int i = 1; int currentY = this.topBoundary + boxHeight; - while ((i + GridUI.BLOCK_HEIGHT) < this.height) { + while (i < this.height) { this.blocksLines.add(new Line2D.Double(this.leftBoundary, currentY, this.rightBoundary, @@ -412,7 +412,7 @@ i = 1; int currentX = this.leftBoundary + boxWidth; - while ((i + GridUI.BLOCK_WIDTH) < this.width) { + while (i < this.width) { this.blocksLines.add(new Line2D.Double(currentX, this.topBoundary, currentX, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yva...@us...> - 2007-06-13 15:32:37
|
Revision: 34 http://picross.svn.sourceforge.net/picross/?rev=34&view=rev Author: yvan_norsa Date: 2007-06-13 08:32:37 -0700 (Wed, 13 Jun 2007) Log Message: ----------- fixed blocks and boundaries Modified Paths: -------------- trunk/src/picross/grid/GridUI.java Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-13 15:04:38 UTC (rev 33) +++ trunk/src/picross/grid/GridUI.java 2007-06-13 15:32:37 UTC (rev 34) @@ -247,16 +247,19 @@ int hintBoxWidth = this.hintBoxIcon.getIconWidth(); int hintBoxHeight = this.hintBoxIcon.getIconHeight(); + this.leftHintsDecal = hintBoxWidth + GridUI.HINTS_SPACE; + this.topHintsDecal = hintBoxHeight + GridUI.HINTS_SPACE; + // Now computes the grid boundaries this.leftBoundary = GridUI.LEFT_HINTS - + (this.rowData[0].length * hintBoxWidth); + + (this.rowData[0].length * leftHintsDecal); this.rightBoundary = this.leftBoundary + (this.width * GridUI.BOX_WIDTH); this.topBoundary = GridUI.TOP_HINTS - + (this.colData[0].length * hintBoxHeight); + + (this.colData[0].length * topHintsDecal); this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); @@ -273,13 +276,10 @@ this.topHintsX = this.leftBoundary + (GridUI.BOX_WIDTH / 2) - (hintBoxWidth / 2); - this.topHintsDecal = hintBoxHeight + GridUI.HINTS_SPACE; this.leftHintsY = this.topBoundary + (GridUI.BOX_HEIGHT / 2) - (hintBoxHeight / 2); - this.leftHintsDecal = hintBoxWidth + GridUI.HINTS_SPACE; - this.centerHintHeight = (hintBoxHeight / 2) + (hintHeight / 2); this.centerLowHintWidth = @@ -399,7 +399,7 @@ int i = 1; int currentY = this.topBoundary + boxHeight; - while (i < this.height) { + while ((i + GridUI.BLOCK_HEIGHT) <= this.height) { this.blocksLines.add(new Line2D.Double(this.leftBoundary, currentY, this.rightBoundary, @@ -412,7 +412,7 @@ i = 1; int currentX = this.leftBoundary + boxWidth; - while (i < this.width) { + while ((i + GridUI.BLOCK_WIDTH) <= this.width) { this.blocksLines.add(new Line2D.Double(currentX, this.topBoundary, currentX, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |