Mercurial > hg > indyvon
changeset 41:2475c99fbb8c
Update graph bounds when moving vertex.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Sat, 10 Jul 2010 07:28:19 +0400 |
parents | a96dfbfd6d4e |
children | d3e3c43df1cd |
files | src/kryshen/indyvon/graph.clj |
diffstat | 1 files changed, 11 insertions(+), 11 deletions(-) [+] |
line diff
1.1 --- a/src/kryshen/indyvon/graph.clj Sat Jul 10 03:04:47 2010 +0400 1.2 +++ b/src/kryshen/indyvon/graph.clj Sat Jul 10 07:28:19 2010 +0400 1.3 @@ -29,13 +29,13 @@ 1.4 (.getLeftBound v) 1.5 (.getTopBound v)))) 1.6 1.7 -(defn- draw-vertices! [^Graph graph x y] 1.8 - (doseq [v (.vertices graph)] 1.9 +(defn- draw-vertices! [^GraphLayout layout x y] 1.10 + (doseq [v (.vertices (.getGraph layout))] 1.11 (draw-anchored! v :center :center (+ x (.getX v)) (+ y (.getY v))))) 1.12 1.13 (defn- draw-movable-vertices! 1.14 - [^Graph graph x y dragged fix-x fix-y] 1.15 - (doseq [v (.vertices graph)] 1.16 + [^GraphLayout layout x y dragged fix-x fix-y] 1.17 + (doseq [v (.vertices (.getGraph layout))] 1.18 (let [x (+ x (.getX v)) 1.19 y (+ y (.getY v)) 1.20 anchor (anchor v :center :center) 1.21 @@ -62,15 +62,16 @@ 1.22 (let [dx (- x @fix-x) 1.23 dy (- y @fix-y)] 1.24 (.layoutLocation v (+ vx dx) (+ vy dy)) 1.25 + (.updateBounds layout) 1.26 (*update*) 1.27 (ref-set fix-x x) 1.28 (ref-set fix-y y))))))))))) 1.29 1.30 -(defn- draw-edges! [^Graph graph x y] 1.31 +(defn- draw-edges! [^GraphLayout layout x y] 1.32 ;; TODO: extend Layer on Edge2D and draw like vertices. 1.33 (.translate *graphics* x y) 1.34 (let [path (Path2D$Double.)] 1.35 - (doseq [^Edge2D e (.edges graph)] 1.36 + (doseq [^Edge2D e (.edges (.getGraph layout))] 1.37 (.getPath e path) 1.38 (.draw *graphics* path))) 1.39 (.translate *graphics* (- x) (- y))) 1.40 @@ -87,12 +88,11 @@ 1.41 (render! [layer] 1.42 (let [bounds (.getBounds layout) 1.43 x (- (.getX bounds)) 1.44 - y (- (.getY bounds)) 1.45 - graph (.getGraph layout)] 1.46 - (draw-edges! graph x y) 1.47 + y (- (.getY bounds))] 1.48 + (draw-edges! layout x y) 1.49 (if movable 1.50 - (draw-movable-vertices! graph x y dragged fix-x fix-y) 1.51 - (draw-vertices! graph x y)))) 1.52 + (draw-movable-vertices! layout x y dragged fix-x fix-y) 1.53 + (draw-vertices! layout x y)))) 1.54 (size [layer] 1.55 (let [bounds (.getBounds layout)] 1.56 (Size. (.getWidth bounds) (.getHeight bounds))))