changeset 48:a948ac563f6f

Graph: draw the vertex being dragged above others.
author Mikhail Kryshen <mikhail@kryshen.net>
date Wed, 28 Jul 2010 04:47:30 +0400
parents 180d7690d09a
children ca728127d605
files src/kryshen/indyvon/graph.clj
diffstat 1 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/kryshen/indyvon/graph.clj	Wed Jul 28 04:46:34 2010 +0400
+++ b/src/kryshen/indyvon/graph.clj	Wed Jul 28 04:47:30 2010 +0400
@@ -33,15 +33,14 @@
   (doseq [v (.vertices (.getGraph layout))]
     (draw-anchored! v :center :center (+ x (.getX v)) (+ y (.getY v)))))
 
-(defn- draw-movable-vertices!
-  [^GraphLayout layout x y dragged fix-x fix-y]
-  (doseq [v (.vertices (.getGraph layout))]
-    (let [x (+ x (.getX v))
-          y (+ y (.getY v))
-          anchor (anchor v :center :center)
-          size (layer-size v)
-          x (- x (:x anchor))
-          y (- y (:y anchor))]
+(defn- draw-movable-vertex!
+  [^Vertex2D v ^GraphLayout layout x y dragged fix-x fix-y]
+  (let [x (+ x (.getX v))
+        y (+ y (.getY v))
+        anchor (anchor v :center :center)
+        size (layer-size v)
+        x (- x (:x anchor))
+        y (- y (:y anchor))]
     (with-bounds x y (:width size) (:height size)
       (with-handlers v
         (draw! v)
@@ -65,8 +64,18 @@
                  (.invalidateLayout layout)
                  (*update*)
                  (ref-set fix-x x)
-                 (ref-set fix-y y)))))))))))
-
+                 (ref-set fix-y y))))))))))
+  
+(defn- draw-movable-vertices!
+  [^GraphLayout layout x y dragged-ref fix-x fix-y]
+  (let [dragged @dragged-ref]
+    (doseq [v (.vertices (.getGraph layout))
+            :when (not= v dragged)]
+      (draw-movable-vertex! v layout x y dragged-ref fix-x fix-y))
+    ;; Draw the vertex being dragged above others.
+    (when dragged
+      (draw-movable-vertex! dragged layout x y dragged-ref fix-x fix-y))))
+    
 (defn- draw-edges! [^GraphLayout layout x y]
   ;; TODO: extend Layer on Edge2D and draw like vertices.
   (.translate *graphics* x y)