[Picross-commit] SF.net SVN: picross: [22] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-07 14:57:22
|
Revision: 22 http://picross.svn.sourceforge.net/picross/?rev=22&view=rev Author: yvan_norsa Date: 2007-06-07 07:57:23 -0700 (Thu, 07 Jun 2007) Log Message: ----------- pretty graphics Modified Paths: -------------- trunk/applet/index.html trunk/src/picross/PicrossModel.java trunk/src/picross/grid/GridModel.java trunk/src/picross/grid/GridUI.java Modified: trunk/applet/index.html =================================================================== --- trunk/applet/index.html 2007-06-07 11:29:21 UTC (rev 21) +++ trunk/applet/index.html 2007-06-07 14:57:23 UTC (rev 22) @@ -10,7 +10,8 @@ <applet code="picross.applet.PicrossApplet" archive="picross.jar,bundleHelper.jar,log4j.jar,mmvcs.jar" - width="450" - height="375" /> + width="550" + height="400" + cache_option="no" /> </body> </html> Modified: trunk/src/picross/PicrossModel.java =================================================================== --- trunk/src/picross/PicrossModel.java 2007-06-07 11:29:21 UTC (rev 21) +++ trunk/src/picross/PicrossModel.java 2007-06-07 14:57:23 UTC (rev 22) @@ -54,27 +54,182 @@ /** Constructor. */ PicrossModel() { - this.width = 5; - this.height = 5; + this.width = 19; + this.height = 14; this.data = new boolean[this.width][this.height]; + /* + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { + this.data[i][j] = true; + } + } + */ + this.data[0][7] = true; + this.data[0][8] = true; + this.data[0][13] = true; - this.data[0][1] = true; - this.data[0][3] = true; - this.data[1][0] = true; - this.data[1][1] = true; - this.data[1][2] = true; - this.data[1][3] = true; - this.data[1][4] = true; - this.data[2][1] = true; - this.data[2][3] = true; - this.data[3][0] = true; - this.data[3][1] = true; - this.data[3][2] = true; - this.data[3][3] = true; - this.data[3][4] = true; - this.data[4][1] = true; - this.data[4][3] = true; + this.data[1][6] = true; + this.data[1][7] = true; + this.data[1][8] = true; + this.data[1][9] = true; + this.data[1][12] = true; + this.data[1][13] = true; + + this.data[2][6] = true; + this.data[2][7] = true; + this.data[2][8] = true; + this.data[2][9] = true; + this.data[2][12] = true; + this.data[2][13] = true; + + this.data[3][5] = true; + this.data[3][6] = true; + this.data[3][8] = true; + this.data[3][9] = true; + this.data[3][10] = true; + this.data[3][11] = true; + this.data[3][12] = true; + this.data[3][13] = true; + + this.data[4][5] = true; + this.data[4][6] = true; + this.data[4][7] = true; + this.data[4][8] = true; + this.data[4][9] = true; + this.data[4][10] = true; + this.data[4][11] = true; + this.data[4][12] = true; + this.data[4][13] = true; + + this.data[5][0] = true; + this.data[5][1] = true; + this.data[5][2] = true; + this.data[5][3] = true; + this.data[5][4] = true; + this.data[5][5] = true; + this.data[5][6] = true; + this.data[5][7] = true; + this.data[5][8] = true; + this.data[5][9] = true; + this.data[5][10] = true; + this.data[5][11] = true; + this.data[5][12] = true; + this.data[5][13] = true; + + this.data[6][0] = true; + this.data[6][1] = true; + this.data[6][2] = true; + this.data[6][3] = true; + this.data[6][4] = true; + this.data[6][5] = true; + this.data[6][6] = true; + this.data[6][7] = true; + this.data[6][8] = true; + this.data[6][9] = true; + this.data[6][10] = true; + this.data[6][11] = true; + this.data[6][12] = true; + this.data[6][13] = true; + + this.data[7][1] = true; + this.data[7][2] = true; + this.data[7][3] = true; + this.data[7][4] = true; + this.data[7][5] = true; + this.data[7][6] = true; + this.data[7][7] = true; + this.data[7][8] = true; + this.data[7][9] = true; + this.data[7][10] = true; + this.data[7][11] = true; + this.data[7][12] = true; + this.data[7][13] = true; + + this.data[8][8] = true; + this.data[8][9] = true; + this.data[8][10] = true; + this.data[8][11] = true; + this.data[8][12] = true; + this.data[8][13] = true; + + this.data[9][7] = true; + this.data[9][8] = true; + this.data[9][9] = true; + this.data[9][10] = true; + this.data[9][11] = true; + this.data[9][12] = true; + this.data[9][13] = true; + + this.data[10][7] = true; + this.data[10][8] = true; + this.data[10][9] = true; + this.data[10][10] = true; + this.data[10][11] = true; + this.data[10][12] = true; + this.data[10][13] = true; + + this.data[11][6] = true; + this.data[11][7] = true; + this.data[11][8] = true; + this.data[11][9] = true; + this.data[11][10] = true; + this.data[11][11] = true; + this.data[11][12] = true; + this.data[11][13] = true; + + this.data[12][6] = true; + this.data[12][7] = true; + this.data[12][8] = true; + this.data[12][9] = true; + this.data[12][10] = true; + this.data[12][11] = true; + this.data[12][12] = true; + this.data[12][13] = true; + + this.data[13][6] = true; + this.data[13][7] = true; + this.data[13][8] = true; + this.data[13][9] = true; + this.data[13][10] = true; + this.data[13][11] = true; + this.data[13][12] = true; + this.data[13][13] = true; + + this.data[14][6] = true; + this.data[14][7] = true; + this.data[14][8] = true; + this.data[14][9] = true; + this.data[14][10] = true; + this.data[14][11] = true; + this.data[14][12] = true; + this.data[14][13] = true; + + this.data[15][7] = true; + this.data[15][8] = true; + this.data[15][9] = true; + this.data[15][10] = true; + this.data[15][11] = true; + this.data[15][12] = true; + this.data[15][13] = true; + + this.data[16][9] = true; + this.data[16][10] = true; + this.data[16][11] = true; + this.data[16][12] = true; + this.data[16][13] = true; + + this.data[17][8] = true; + this.data[17][9] = true; + this.data[17][10] = true; + this.data[17][11] = true; + this.data[17][12] = true; + this.data[17][13] = true; + + this.data[18][9] = true; + this.data[18][10] = true; + this.data[18][11] = true; + this.data[18][12] = true; } /*** Accessors ***/ Modified: trunk/src/picross/grid/GridModel.java =================================================================== --- trunk/src/picross/grid/GridModel.java 2007-06-07 11:29:21 UTC (rev 21) +++ trunk/src/picross/grid/GridModel.java 2007-06-07 14:57:23 UTC (rev 22) @@ -243,7 +243,7 @@ * (while dragging), do nothing */ if (this.lastModified != null - && this.lastModified == this.boxes[row][column]) { + && this.lastModified == this.boxes[column][row]) { return; } @@ -254,53 +254,53 @@ * (if we are in a checks serie and we are on a box which * is already checked), do nothing */ - if (this.boxes[row][column].equals(this.lastModified)) { + if (this.boxes[column][row].equals(this.lastModified)) { return; } } - if (this.boxes[row][column].isEmpty() + if (this.boxes[column][row].isEmpty() && (this.lastModified == null || !this.lastModified.isEmpty())) { if (type == GridController.CHECK_ACTION) { - this.boxes[row][column].check(); + this.boxes[column][row].check(); } else { //if (type == GridController.CROSS_ACTION) { - this.boxes[row][column].cross(); + this.boxes[column][row].cross(); } this.mediator.check(row, column, type); - } else if (!this.boxes[row][column].isEmpty() + } else if (!this.boxes[column][row].isEmpty() && (this.lastModified == null || this.lastModified.isEmpty())) { - if (this.boxes[row][column].isChecked()) { + if (this.boxes[column][row].isChecked()) { //GridModel.log.debug("checked"); if (type == GridController.CHECK_ACTION) { - this.boxes[row][column].empty(); + this.boxes[column][row].empty(); this.mediator.uncheck(row, column, type); } else { //if (type == GridController.CROSS_ACTION) { - this.boxes[row][column].cross(); + this.boxes[column][row].cross(); this.mediator.check(row, column, GridController.CROSS_ACTION); } - } else { //if (this.boxes[row][column].isCrossed()) { + } else { //if (this.boxes[column][row].isCrossed()) { //GridModel.log.debug("crossed"); if (type == GridController.CROSS_ACTION) { - this.boxes[row][column].empty(); + this.boxes[column][row].empty(); this.mediator.uncheck(row, column, type); } else { //GridModel.log.debug("check()"); - this.boxes[row][column].check(); + this.boxes[column][row].check(); this.mediator.check(row, column, GridController.CHECK_ACTION); } } } - this.lastModified = this.boxes[row][column]; + this.lastModified = this.boxes[column][row]; this.checkCompleted(); } Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-07 11:29:21 UTC (rev 21) +++ trunk/src/picross/grid/GridUI.java 2007-06-07 14:57:23 UTC (rev 22) @@ -35,10 +35,17 @@ import java.awt.Color; 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.RenderingHints; +import java.awt.font.FontRenderContext; + +import java.awt.geom.Rectangle2D; + import javax.swing.JPanel; import org.apache.log4j.Logger; @@ -55,7 +62,7 @@ private static final long serialVersionUID = 2050855523399115878L; /** Space left before the top hints. */ - private static final int TOP_HINTS = 10; + private static final int TOP_HINTS = 10 + 3; /** Width occupied by a row hint. */ private static final int ROW_HINT_WIDTH = 10; @@ -69,6 +76,12 @@ /** 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); + private static final Color HINT_FILL_COLOR = new Color(131, 155, 200); + 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); + /** A box width. */ private static final int BOX_WIDTH = 25; @@ -127,6 +140,8 @@ /** Controller attached to this view. */ private transient GridController controller; + int hintBoxSize; + /*** Constructor ***/ /** @@ -158,15 +173,51 @@ this.colData = colData; this.rowData = rowData; - this.leftBoundary = - this.rowData[0].length * GridUI.ROW_HINT_WIDTH; + /**/ + //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(); + + this.hintBoxSize = (int) (textWidth > textHeight + ? textWidth : textHeight); + //this.bigHintBoxSize = this.hintBoxSize + 3; + this.hintBoxSize += 2; + + /**/ + + + + /* + 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 * GridUI.COL_HINT_HEIGHT); + + (this.colData[0].length * this.hintBoxSize); + //this.topBoundary = 70; + this.bottomBoundary = this.topBoundary + (this.height * GridUI.BOX_HEIGHT); @@ -180,8 +231,8 @@ this.boxes = new GridBox[this.width][this.height]; - for (int i = 0; i < this.boxes.length; i++) { - for (int j = 0; j < this.boxes[i].length; j++) { + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { /* * We compute here the rectangle corresponding to each box * so we'll be able @@ -189,9 +240,9 @@ */ this.boxes[i][j] = new GridBox(new Rectangle(this.leftBoundary + + (i * GridUI.BOX_WIDTH), + this.topBoundary + (j * GridUI.BOX_WIDTH), - this.topBoundary - + (i * GridUI.BOX_WIDTH), GridUI.BOX_WIDTH, GridUI.BOX_HEIGHT)); } @@ -215,8 +266,12 @@ Rectangle clipRect = g.getClipBounds(); if (this.topHintsRect.intersects(clipRect)) { - GridUI.log.debug("top hints"); + Graphics2D g2d = (Graphics2D) g.create(); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + //GridUI.log.debug("top hints"); + int x = 0; int y = GridUI.TOP_HINTS; @@ -225,40 +280,51 @@ for (int j = 0; j < this.colData.length; j++) { if (this.colData[j][i] != GridModel.EMPTY_HINT) { - g.drawString(String.valueOf(this.colData[j][i]), - x, y); + int hintX = x + (((x + GridUI.COL_HINT_WIDTH) - x) / 2); + this.drawColHint(g2d, this.colData[j][i], hintX, y); } x += GridUI.BOX_WIDTH; } - y += GridUI.COL_HINT_HEIGHT; + y += this.hintBoxSize + 2; } + + g2d.dispose(); } if (this.leftHintsRect.intersects(clipRect)) { - GridUI.log.debug("left hints"); + //GridUI.log.debug("left hints"); + Graphics2D g2d = (Graphics2D) g.create(); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + int y = this.topBoundary; for (int i = 0; i < this.rowData.length; i++) { int x = 0; + int hintY = y + GridUI.ROW_HINT_HEIGHT; + for (int j = 0; j < this.rowData[i].length; j++) { if (this.rowData[i][j] != GridModel.EMPTY_HINT) { - g.drawString(String.valueOf(this.rowData[i][j]), - x, y + GridUI.ROW_HINT_HEIGHT); + this.drawRowHint(g2d, this.rowData[i][j], x, hintY); } - x += GridUI.ROW_HINT_WIDTH; + x += this.hintBoxSize + 2; } y += GridUI.BOX_HEIGHT; } + + g2d.dispose(); } - for (int i = 0; i < this.height; i++) { - for (int j = 0; j < this.width; j++) { + for (int i = 0; i < this.width; i++) { + for (int j = 0; j < this.height; j++) { + //GridUI.log.debug("currentRect : " + i + "," + j); + Rectangle currentRect = this.boxes[i][j].getRect(); if (currentRect.intersects(clipRect)) { @@ -277,6 +343,68 @@ /*** Methods ***/ + private void drawColHint(Graphics2D g2d, int value, int hintX, int y) { + g2d.setColor(GridUI.HINT_FILL_COLOR); + + 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) { + g2d.drawString(String.valueOf(value), + hintX + (this.hintBoxSize / 3), + y); + } else { + g2d.drawString(String.valueOf(value), + hintX, + y); + } + } + + private void drawRowHint(Graphics2D g2d, int value, int hintX, int y) { + g2d.setColor(GridUI.HINT_FILL_COLOR); + + g2d.fillRoundRect(hintX, + y - GridUI.ROW_HINT_HEIGHT, + this.hintBoxSize, + this.hintBoxSize, + 8, 8); + + g2d.setColor(GridUI.HINT_FORE_COLOR); + + g2d.drawRoundRect(hintX, + y - GridUI.ROW_HINT_HEIGHT, + this.hintBoxSize, + this.hintBoxSize, + 8, 8); + + 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 methods tells wether a point is inside the grid or not. * @@ -353,16 +481,16 @@ */ private void setBoxState(int row, int column, boolean state, int type) { if (!state) { - this.boxes[row][column].empty(); + this.boxes[column][row].empty(); } else { if (type == GridController.CHECK_ACTION) { - this.boxes[row][column].check(); + this.boxes[column][row].check(); } else { //if (type == GridController.CROSS_ACTION) { - this.boxes[row][column].cross(); + this.boxes[column][row].cross(); } } - this.repaint(this.boxes[row][column].getRect()); + this.repaint(this.boxes[column][row].getRect()); } /** @@ -375,7 +503,7 @@ //GridUI.log.debug("setRollover(" + row + ", " + column + ")"); this.rolloverEnded(); - this.rollover = this.boxes[row][column]; + this.rollover = this.boxes[column][row]; this.repaint(this.rollover.getRect()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |