コード例 #1
0
 /*
  * Zoom in/out. Translate the viewing window such that the place under the mouse pointer is a fixed point. If p is null, zoom around the center of
  * the viewport.
  */
 void zoom(double f, Point p) {
   double ex = modelBounds.getWidth() * f;
   double ey = modelBounds.getHeight() * f;
   modelBounds.expandBy(ex / 2, ey / 2);
   if (p != null) {
     // Note: Graphics Y coordinates increase down the screen, hence the opposite signs.
     double tx = ex * -((p.getX() / this.width) - 0.5);
     double ty = ey * +((p.getY() / this.height) - 0.5);
     modelBounds.translate(tx, ty);
   }
   // update the display
   drawLevel = DRAW_PARTIAL;
 }
コード例 #2
0
 public void mouseDragged(MouseEvent e) {
   Point c = e.getPoint();
   if (startDrag == null) {
     startDrag = c;
     dragX = c.x;
     dragY = c.y;
   }
   double dx = dragX - c.x;
   double dy = c.y - dragY;
   if (ctrlPressed || mouseButton == RIGHT) {
     zoom(dy * 0.01, startDrag);
   } else {
     double tx = modelBounds.getWidth() * dx / getWidth();
     double ty = modelBounds.getHeight() * dy / getHeight();
     modelBounds.translate(tx, ty);
   }
   dragX = c.x;
   dragY = c.y;
   drawLevel = DRAW_PARTIAL;
 }