MCPcopy Create free account
hub / github.com/SimHacker/micropolis / doZoom

Method doZoom

micropolis-java/src/micropolisj/gui/MainWindow.java:1112–1130  ·  view source on GitHub ↗
(int dir, Point mousePt)

Source from the content-addressed store, hash-verified

1110 }
1111
1112 private void doZoom(int dir, Point mousePt)
1113 {
1114 int oldZoom = drawingArea.getTileSize();
1115 int newZoom = dir < 0 ? (oldZoom / 2) : (oldZoom * 2);
1116 if (newZoom < 8) { newZoom = 8; }
1117 if (newZoom > 32) { newZoom = 32; }
1118
1119 if (oldZoom != newZoom)
1120 {
1121 // preserve effective mouse position in viewport when changing zoom level
1122 double f = (double)newZoom / (double)oldZoom;
1123 Point pos = drawingAreaScroll.getViewport().getViewPosition();
1124 int newX = (int)Math.round(mousePt.x * f - (mousePt.x - pos.x));
1125 int newY = (int)Math.round(mousePt.y * f - (mousePt.y - pos.y));
1126 drawingArea.selectTileSize(newZoom);
1127 drawingAreaScroll.validate();
1128 drawingAreaScroll.getViewport().setViewPosition(new Point(newX, newY));
1129 }
1130 }
1131
1132 private void doZoom(int dir)
1133 {

Callers 2

actionPerformedMethod · 0.95
onMouseWheelMovedMethod · 0.95

Calls 4

getTileSizeMethod · 0.80
selectTileSizeMethod · 0.80
getViewRectMethod · 0.80
validateMethod · 0.45

Tested by

no test coverage detected