1 package org.catacomb.graph.gui; 2 3 4 5 6 7 public class TurnZoomHandler extends MouseHandler { 8 9 private int xc; 10 private int yc; 11 12 private int x0; 13 private int y0; 14 15 private int x1; 16 private int y1; 17 18 19 20 public void init(Mouse m) { 21 xc = m.getX(); 22 yc = m.getY(); 23 24 x0 = xc; 25 y0 = yc; 26 27 x1 = xc; 28 y1 = yc; 29 } 30 31 32 public void advance(Mouse m) { 33 int x = m.getX(); 34 int y = m.getY(); 35 if (x <= 1 || x >= m.getCanvasWidth() || 36 y <= 1 || y >= m.getCanvasHeight()) { 37 setClaimIn(); 38 } 39 } 40 41 42 43 44 public void applyOnDrag(Mouse m) { 45 int x = m.getX(); 46 int y = m.getY(); 47 48 if ((x-x1)*(x-x1) + (y-y1)*(y-y1) > 64) { 49 50 double a = (x1 - x0) * (y - y0) - (y1 - y0) * (x - x0); 51 int d2 = (x1-x0)*(x1-x0) + (y1-y0)*(y1-y0); 52 53 if (d2 > 32) { 54 a = a / d2; 55 double f = Math.exp(0.16 * a); 56 57 m.zoom(f, xc, yc); 58 } 59 60 x0 = x1; 61 x1 = x; 62 63 y0 = y1; 64 y1 = y; 65 } 66 } 67 68 69 70 } 71