Project

General

Profile

Revision 504

Added by Greg Tress about 16 years ago

Robot identification circles line up properly

View differences:

trunk/code/projects/colonet/client/Colonet.java
881 881
			int maxHeight = getHeight() - 2*BORDER;
882 882
			double widthRatio = 1.0 * maxWidth / img.getWidth();
883 883
			double heightRatio = 1.0 * maxHeight / img.getHeight();
884
			double scale = 0;
884 885
			int newWidth = 0;
885 886
			int newHeight = 0;
886 887
			int x = 0;
887 888
			int y = 0;
888 889
			
889 890
			if (widthRatio > heightRatio) {  //height is the limiting factor
891
			    scale = heightRatio;
890 892
			    newHeight = maxHeight;
891
			    newWidth = img.getWidth() * maxHeight / img.getHeight();
893
			    newWidth = (int) (img.getWidth() * scale);
892 894
			    y = BORDER;
893 895
			    x = (maxWidth - newWidth) / 2 + BORDER;
894 896
			} else {  //width is the limiting factor
897
			    scale = widthRatio;
895 898
			    newWidth = maxWidth;
896
			    newHeight = img.getHeight() * maxWidth / img.getWidth();
899
			    newHeight = (int) (img.getHeight() * scale);
897 900
			    x = BORDER;
898 901
			    y = (maxHeight - newHeight) / 2 + BORDER;
899 902
			}
......
905 908
			// Draw Identifiers
906 909
			if (robotIcons == null)
907 910
				return;
908
			
911
				
909 912
			((Graphics2D)g).setStroke(new BasicStroke(2));
910 913
			for (int i = 0; i < robotIcons.size(); i++) {
911 914
				RobotIcon r = robotIcons.get(i);
912 915
				g.setColor(r.color);
913
				if (widthRatio > heightRatio) {
914
				    
915
				
916
				} else {
917
				    
918
				}
919
				g.drawOval(r.x-RADIUS, r.y-RADIUS, 2*r.RADIUS, 2*r.RADIUS);
916
				int px = (int) (x + r.x * scale);
917
				int py = (int) (y + r.y * scale);
918
				g.drawOval(px-RADIUS, py-RADIUS, 2*r.RADIUS, 2*r.RADIUS);
920 919
				// If the robot has a destination, draw the vector
921 920
				if (r.destx >= 0) {
922
				    g.drawLine(r.x, r.y, r.destx, r.desty);
921
				    g.drawLine(px, py, (int)(x + r.destx * scale), (int)(y + r.desty * scale));
923 922
				}
924 923
			}
925 924
			

Also available in: Unified diff