From: Erik V. <ev...@us...> - 2009-12-19 16:48:46
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv1867/rails/ui/swing/hexmap Modified Files: GUIHex.java GUITile.java Log Message: Better positioning and sizing of tokens and home indicators Index: GUIHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/GUIHex.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** GUIHex.java 15 Dec 2009 18:56:11 -0000 1.28 --- GUIHex.java 19 Dec 2009 16:48:31 -0000 1.29 *************** *** 27,30 **** --- 27,32 ---- public static int NORMAL_TOKEN_SIZE = 15; + public static double TILE_GRID_SCALE = 14.0; + public static double CITY_SIZE = 16.0; public static Color BAR_COLOUR = Color.BLUE; *************** *** 322,348 **** Map<PublicCompanyI, City> homes = getHexModel().getHomes(); if (homes != null) { ! //log.debug("+++ Home hex "+getName()); ! /* ! StringBuffer b = new StringBuffer(); ! for (Iterator<PublicCompanyI> it = homes.keySet().iterator(); it.hasNext();) { ! ! PublicCompanyI co = it.next(); ! ! if (!co.hasStarted() && !co.hasFloated()) { ! if (b.length() > 0) b.append(","); ! b.append(co.getName()); ! } ! } ! String label = b.toString(); ! g2.drawString( ! label, ! rectBound.x ! + (rectBound.width - fontMetrics.stringWidth(label)) ! * 1 / 2, ! rectBound.y ! + ((fontMetrics.getHeight() + rectBound.height) * 3 / 10)); ! */ ! City city; Point p; homes: for (PublicCompanyI company : homes.keySet()) { --- 324,330 ---- Map<PublicCompanyI, City> homes = getHexModel().getHomes(); + if (homes != null) { ! City city; Point p; homes: for (PublicCompanyI company : homes.keySet()) { *************** *** 359,363 **** } } ! p = getTokenOrigin (1, 0, getHexModel().getCities().size(), city.getNumber()-1); //log.debug("+++ Home of "+company.getName()+" hex"+getName()+" city"+city.getName() --- 341,345 ---- } } ! p = getTokenCenter (1, 0, getHexModel().getCities().size(), city.getNumber()-1); //log.debug("+++ Home of "+company.getName()+" hex"+getName()+" city"+city.getName() *************** *** 435,440 **** for (int i = 0; i < tokens.size(); i++) { PublicCompanyI co = ((BaseToken) tokens.get(i)).getCompany(); ! Point origin = getTokenOrigin(numTokens, i, 1, 0); ! drawBaseToken(g2, co, origin, tokenDiameter); } } --- 417,422 ---- for (int i = 0; i < tokens.size(); i++) { PublicCompanyI co = ((BaseToken) tokens.get(i)).getCompany(); ! Point center = getTokenCenter(numTokens, i, 1, 0); ! drawBaseToken(g2, co, center, tokenDiameter); } } *************** *** 452,456 **** for (int j = 0; j < tokens.size(); j++) { ! origin = getTokenOrigin(numTokens, j, numStations, i); co = ((BaseToken) tokens.get(j)).getCompany(); drawBaseToken(g2, co, origin, tokenDiameter); --- 434,438 ---- for (int j = 0; j < tokens.size(); j++) { ! origin = getTokenCenter(numTokens, j, numStations, i); co = ((BaseToken) tokens.get(j)).getCompany(); drawBaseToken(g2, co, origin, tokenDiameter); *************** *** 506,518 **** Color oldColor = g2.getColor(); ! double tokenScale = 15.0 / 21.0; String name = co.getName(); Font font = GUIToken.getTokenFont(name.length()); g2.setFont(new Font("Helvetica", Font.BOLD, ! (int) (font.getSize() * tokenScale))); g2.setColor(Color.BLACK); ! g2.drawString(name, (int) (origin.x + (12 - 3*name.length()) * tokenScale), ! (int) (origin.y + 14 * tokenScale)); g2.setColor(oldColor); --- 488,500 ---- Color oldColor = g2.getColor(); ! double scale = 0.5 * zoomFactor; String name = co.getName(); Font font = GUIToken.getTokenFont(name.length()); g2.setFont(new Font("Helvetica", Font.BOLD, ! (int) (font.getSize() * zoomFactor * 0.75))); g2.setColor(Color.BLACK); ! g2.drawString(name, (int) (origin.x + (-4 - 3*name.length()) * scale), ! (int) (origin.y + 4 * scale)); g2.setColor(oldColor); *************** *** 537,541 **** } ! private Point getTokenOrigin(int numTokens, int currentToken, int numStations, int stationNumber) { Point p = new Point(center.x, center.y); --- 519,523 ---- } ! private Point getTokenCenter(int numTokens, int currentToken, int numStations, int stationNumber) { Point p = new Point(center.x, center.y); *************** *** 550,554 **** int positionCode = station.getPosition(); if (positionCode != 0) { ! y = 16 * zoomFactor; double r = Math.toRadians(30 * (positionCode / 50)); xx = x * Math.cos(r) + y * Math.sin(r); --- 532,536 ---- int positionCode = station.getPosition(); if (positionCode != 0) { ! y = TILE_GRID_SCALE * zoomFactor; double r = Math.toRadians(30 * (positionCode / 50)); xx = x * Math.cos(r) + y * Math.sin(r); *************** *** 561,577 **** switch (station.getBaseSlots()) { case 2: ! x += (-8 + 16 * currentToken) * zoomFactor; break; case 3: if (currentToken < 2) { ! x += (-8 + 16 * currentToken) * zoomFactor; ! y += 8 * zoomFactor; } else { ! y -= 8 * zoomFactor; } break; case 4: ! x += (-8 + 16 * currentToken % 2) * zoomFactor; ! y += (8 - 16 * currentToken / 2) * zoomFactor; } --- 543,559 ---- switch (station.getBaseSlots()) { case 2: ! x += (-0.5 + currentToken) * CITY_SIZE * zoomFactor; break; case 3: if (currentToken < 2) { ! x += (-0.5 + currentToken) * CITY_SIZE * zoomFactor; ! y += -3 + 0.25 * SQRT3 * CITY_SIZE * zoomFactor; } else { ! y -= 3 + 0.5 * CITY_SIZE * zoomFactor; } break; case 4: ! x += (-0.5 + currentToken % 2) * CITY_SIZE * zoomFactor; ! y += (0.5 - currentToken / 2) * CITY_SIZE * zoomFactor; } Index: GUITile.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/GUITile.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** GUITile.java 18 Dec 2009 20:04:31 -0000 1.20 --- GUITile.java 19 Dec 2009 16:48:32 -0000 1.21 *************** *** 24,29 **** protected TileI tile = null; protected String tileType = null; - //protected double xCenterRelativeLocation = SVG_X_CENTER_LOC; - //protected double yCenterRelativeLocation = SVG_Y_CENTER_LOC; protected BufferedImage tileImage = null; --- 24,27 ---- *************** *** 44,49 **** public static final double DEG60 = Math.PI / 3; - //public static final double DFLT_X_CENTER_LOC = 0.5; - //public static final double DFLT_Y_CENTER_LOC = 0.5; public static final double SVG_X_CENTER_LOC = 0.489; public static final double SVG_Y_CENTER_LOC = 0.426; --- 42,45 ---- *************** *** 245,255 **** int zoomStep = guiHex.getHexMap().getZoomStep(); tileImage = imageLoader.getTile(tileId, zoomStep); - //if (tileType == null) { - // tileType = imageLoader.getTileType(tileId); - // if (tileType.equalsIgnoreCase("svg")) { - // xCenterRelativeLocation = SVG_X_CENTER_LOC; - // yCenterRelativeLocation = SVG_Y_CENTER_LOC; - // } - //} if (tileImage != null) { --- 241,244 ---- |