From: Erik V. <ev...@us...> - 2010-03-11 20:39:04
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv20300/rails/ui/swing/hexmap Modified Files: HexMap.java EWHexMap.java NSHexMap.java Log Message: Restrict map display area to hexes actually occurring in Map.xml. Index: NSHexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/NSHexMap.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** NSHexMap.java 31 Jan 2010 22:22:36 -0000 1.12 --- NSHexMap.java 11 Mar 2010 20:38:19 -0000 1.13 *************** *** 28,42 **** hexArray = mapManager.getHexes(); MapHex mh; h = new GUIHex[hexArray.length][hexArray[0].length]; ! for (int i = 0; i < hexArray.length; i++) { ! for (int j = 0; j < hexArray[0].length; j++) { mh = hexArray[i][j]; if (mh != null) { GUIHex hex = ! new GUIHex(this, Math.round(cx + 3 * i * scale), ! (int) Math.round(cy + (2 * j + (i & 1)) * GUIHex.SQRT3 * scale), ! scale, i, j); hex.setHexModel(mh); --- 28,46 ---- hexArray = mapManager.getHexes(); MapHex mh; + int ii, jj; + h = new GUIHex[hexArray.length][hexArray[0].length]; ! for (int i = minX; i < hexArray.length; i++) { ! ii = i - minX + 1; ! for (int j = minY; j < hexArray[0].length; j++) { ! jj = j - minY + 1; mh = hexArray[i][j]; if (mh != null) { GUIHex hex = ! new GUIHex(this, Math.round(cx + 3 * ii * scale), ! (int) Math.round(cy + (2 * jj + (ii & 1)) * GUIHex.SQRT3 * scale), ! scale, ii, jj); hex.setHexModel(mh); *************** *** 65,74 **** hexArray = mapManager.getHexes(); GUIHex hex; for (int i = 0; i < hexArray.length; i++) { for (int j = 0; j < hexArray[0].length; j++) { hex = h[i][j]; if (hex != null) { ! hex.scaleHex(cx + 3 * i * scale, ! cy + (2 * j + (i & 1)) * GUIHex.SQRT3 * scale, scale, zoomFactor); } --- 69,82 ---- hexArray = mapManager.getHexes(); GUIHex hex; + int ii, jj; + for (int i = 0; i < hexArray.length; i++) { + ii = i = minX + 1; for (int j = 0; j < hexArray[0].length; j++) { + jj = j - minY + 1; hex = h[i][j]; if (hex != null) { ! hex.scaleHex(cx + 3 * ii * scale, ! cy + (2 * jj + (ii & 1)) * GUIHex.SQRT3 * scale, scale, zoomFactor); } *************** *** 84,87 **** --- 92,96 ---- Graphics2D g2 = (Graphics2D) g; String label; + int ii, jj; boolean lettersGoHorizontal = mapManager.lettersGoHorizontal(); *************** *** 93,108 **** for (int i = 1; i < hexArray.length; i++) { label = lettersGoHorizontal ? String.valueOf((char)('@'+i)) : String.valueOf(i); g2.drawString(label, ! (cx - 30 -3*label.length() + 3 * scale * (i + xOffset)), yTop); g2.drawString(label, ! (cx - 30 -3*label.length() + 3 * scale * (i + xOffset)), yBottom); } for (int j = 1; j < 2 * hexArray[0].length; j++) { label = lettersGoHorizontal ? String.valueOf(j) --- 102,119 ---- for (int i = 1; i < hexArray.length; i++) { + ii = i - minX + 1; label = lettersGoHorizontal ? String.valueOf((char)('@'+i)) : String.valueOf(i); g2.drawString(label, ! (cx - 30 -3*label.length() + 3 * scale * (ii + xOffset)), yTop); g2.drawString(label, ! (cx - 30 -3*label.length() + 3 * scale * (ii + xOffset)), yBottom); } for (int j = 1; j < 2 * hexArray[0].length; j++) { + jj = j - minY + 1; label = lettersGoHorizontal ? String.valueOf(j) *************** *** 110,117 **** g2.drawString(label, xLeft, ! (int)(cy + 56 + j * GUIHex.SQRT3 * scale)); g2.drawString(label, xRight, ! (int)(cy + 56 + j * GUIHex.SQRT3 * scale)); } } --- 121,128 ---- g2.drawString(label, xLeft, ! (int)(cy + 56 + jj * GUIHex.SQRT3 * scale)); g2.drawString(label, xRight, ! (int)(cy + 56 + jj * GUIHex.SQRT3 * scale)); } } Index: EWHexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/EWHexMap.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** EWHexMap.java 31 Jan 2010 22:22:36 -0000 1.13 --- EWHexMap.java 11 Mar 2010 20:38:19 -0000 1.14 *************** *** 17,22 **** public EWHexMap() { scale = defaultScale = 2 * Scale.get(); ! cx = scale / 2; ! cy = 0; } --- 17,23 ---- public EWHexMap() { scale = defaultScale = 2 * Scale.get(); ! //cx = scale / 2; ! cx = -scale/2; ! cy = scale/2; } *************** *** 28,34 **** hexArray = mapManager.getHexes(); MapHex mh; h = new GUIHex[hexArray.length][hexArray[0].length]; ! for (int i = 0; i < hexArray.length; i++) { ! for (int j = 0; j < hexArray[0].length; j++) { mh = hexArray[i][j]; if (mh != null) { --- 29,39 ---- hexArray = mapManager.getHexes(); MapHex mh; + int ii, jj; + h = new GUIHex[hexArray.length][hexArray[0].length]; ! for (int i = minX; i < hexArray.length; i++) { ! ii = i - minX + 1; ! for (int j = minY; j < hexArray[0].length; j++) { ! jj = j - minY + 1; mh = hexArray[i][j]; if (mh != null) { *************** *** 37,42 **** this, (cx + scale ! * ((GUIHex.SQRT3 * i) + (GUIHex.SQRT3 / 2 * (j & 1)))), ! (cy + j * 1.5 * scale), scale, i, j); hex.setHexModel(mh); --- 42,47 ---- this, (cx + scale ! * ((GUIHex.SQRT3 * ii) + (GUIHex.SQRT3 / 2 * (j & 1)))), ! (cy + jj * 1.5 * scale), scale, ii, jj); hex.setHexModel(mh); *************** *** 55,61 **** preferredSize = new Dimension( ! (int) Math.round((hexArray.length + 1) * GUIHex.SQRT3 * scale * zoomFactor), ! (int) Math.round((hexArray[0].length + 1) * 1.5 * scale * zoomFactor)); } --- 60,66 ---- preferredSize = new Dimension( ! (int) Math.round((maxX-minX + 3) * GUIHex.SQRT3 * scale * zoomFactor), ! (int) Math.round((maxY-minY + 3) * 1.5 * scale * zoomFactor)); } *************** *** 66,75 **** hexArray = mapManager.getHexes(); GUIHex hex; ! for (int i = 0; i < hexArray.length; i++) { ! for (int j = 0; j < hexArray[0].length; j++) { hex = h[i][j]; if (hex != null) { ! hex.scaleHex(cx + scale * ((GUIHex.SQRT3 * i) + (GUIHex.SQRT3 / 2 * (j & 1))), ! cy + j * 1.5 * scale, scale, zoomFactor); --- 71,83 ---- hexArray = mapManager.getHexes(); GUIHex hex; ! int ii, jj; ! for (int i = minX; i < hexArray.length; i++) { ! ii = i - minX + 1; ! for (int j = minY; j < hexArray[0].length; j++) { ! jj = j - minY + 1; hex = h[i][j]; if (hex != null) { ! hex.scaleHex(cx + scale * ((GUIHex.SQRT3 * ii) + (GUIHex.SQRT3 / 2 * (jj & 1))), ! cy + jj * 1.5 * scale, scale, zoomFactor); *************** *** 87,111 **** Graphics2D g2 = (Graphics2D) g; String label; boolean lettersGoHorizontal = mapManager.lettersGoHorizontal(); ! int xOffset = mapManager.letterAHasEvenNumbers() ? 1 : 0; ! int xLeft = cx + 10; ! int xRight = (int)(cx + 5 + scale * (GUIHex.SQRT3/2 * 2*hexArray.length)); ! int yTop = cy + 10; ! int yBottom = (int)(cy - 10 + hexArray[0].length * 1.5 * scale); ! for (int i = 1; i < 2*hexArray.length; i++) { label = lettersGoHorizontal ? String.valueOf((char)('@'+i)) : String.valueOf(i); g2.drawString(label, ! (int) (cx + (26-3*label.length()) + scale * (GUIHex.SQRT3/2 * (i + xOffset))), yTop); g2.drawString(label, ! (int) (cx + (26-3*label.length()) + scale * (GUIHex.SQRT3/2 * (i + xOffset))), yBottom); } ! for (int j = 1; j < hexArray[0].length; j++) { label = lettersGoHorizontal ? String.valueOf(j) --- 95,122 ---- Graphics2D g2 = (Graphics2D) g; String label; + int ii, jj; boolean lettersGoHorizontal = mapManager.lettersGoHorizontal(); ! int xOffset = (mapManager.letterAHasEvenNumbers() ? 0 : 1) + (minCol % 2); ! int xLeft = cx + scale; ! int xRight = (int)(cx + scale * (3 + GUIHex.SQRT3/2 * (maxCol-minCol+1))); ! int yTop = cy; ! int yBottom = (int)(cy + scale + (maxRow-minRow+1) * 1.5 * scale); ! for (int i = minCol; i <= maxCol; i++) { ! ii = i - minCol + 1; label = lettersGoHorizontal ? String.valueOf((char)('@'+i)) : String.valueOf(i); g2.drawString(label, ! (int) (cx + (26-3*label.length()) + scale * (GUIHex.SQRT3/2 * (ii + xOffset))), yTop); g2.drawString(label, ! (int) (cx + (26-3*label.length()) + scale * (GUIHex.SQRT3/2 * (ii + xOffset))), yBottom); } ! for (int j = minRow; j <= maxRow; j++) { ! jj = j - minRow + 1; label = lettersGoHorizontal ? String.valueOf(j) *************** *** 113,120 **** g2.drawString(label, xLeft, ! (int)(cy - 10 + j * 1.5 * scale)); g2.drawString(label, xRight, ! (int)(cy - 10 + j * 1.5 * scale)); } --- 124,131 ---- g2.drawString(label, xLeft, ! (int)(cy - 10 + jj * 1.5 * scale)); g2.drawString(label, xRight, ! (int)(cy - 10 + jj * 1.5 * scale)); } Index: HexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/HexMap.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** HexMap.java 3 Feb 2010 20:16:40 -0000 1.22 --- HexMap.java 11 Mar 2010 20:38:00 -0000 1.23 *************** *** 47,50 **** --- 47,52 ---- protected GUIHex selectedHex = null; protected Dimension preferredSize; + protected int minX, minY, maxX, maxY; + protected int minCol, maxCol, minRow, maxRow; /** A list of all allowed tile lays */ *************** *** 67,70 **** --- 69,80 ---- this.orUIManager = orUIManager; this.mapManager = mapManager; + minX = mapManager.getMinX(); + minY = mapManager.getMinY(); + maxX = mapManager.getMaxX(); + maxY = mapManager.getMaxY(); + minRow = mapManager.getMinRow(); + minCol = mapManager.getMinCol(); + maxRow = mapManager.getMaxRow(); + maxCol = mapManager.getMaxCol(); setupHexes(); } *************** *** 162,173 **** } @Override public Dimension getMinimumSize() { Dimension dim = new Dimension(); Rectangle r = (h[h.length][h[0].length]).getBounds(); ! dim.height = r.height + 40; ! dim.width = r.width + 100; return dim; } @Override --- 172,185 ---- } + /* @Override public Dimension getMinimumSize() { Dimension dim = new Dimension(); Rectangle r = (h[h.length][h[0].length]).getBounds(); ! dim.height = (maxRow-minRow) + 40; ! dim.width = (maxCol-minCol) + 100; return dim; } + */ @Override |