Mercurial > hg > indyvon
changeset 9:160e9ec945a2
Fix dispatching of mouse motion events.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Sun, 13 Jun 2010 02:49:09 +0400 |
parents | c53ec3052ae7 |
children | 9af27ccccfac |
files | src/indyvon/core.clj |
diffstat | 1 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/indyvon/core.clj Sat Jun 12 06:06:41 2010 +0400 +++ b/src/indyvon/core.clj Sun Jun 13 02:49:09 2010 +0400 @@ -78,10 +78,6 @@ (hovered? [this layer]) (picked? [this layer])) -(defn- assoc-conj [vmap key val] - "Add val to the sequence associated with key in vmap." - (assoc vmap key (conj (get vmap key) val))) - (defn- registered-parent "Returns first context parent registered for event processing." [context-tree context] @@ -93,8 +89,9 @@ (defn- register-context [context-tree context] - (assoc-conj - context-tree (registered-parent context-tree context) context)) + (let [parent (registered-parent context-tree context)] + (assoc context-tree parent (conj (context-tree parent) context) + context nil))) (defn- inside? ([x y context] @@ -228,15 +225,23 @@ (reify-layer (render! [this context g] (register (:dispatcher context) context) + (.setColor g Color/WHITE) + (.fillRect g 0 0 (:width context) (:height context))) + (size [this context] [50 30]))) + (def layer2 + (reify-layer + (render! [this context g] + (register (:dispatcher context) context) (.setColor g Color/BLUE) - (.fillRect g 0 0 50 30)) - (size [this context] [50 30]))) + (.fillRect g 0 0 (:width context) (:height context)) + (render-layer! context layer1 g 10 5)) + (size [this context] [70 65]))) (def layer (reify-layer (render! [this context g] - (register (:dispatcher context) context) + ;;(register (:dispatcher context) context) (.drawLine g 0 0 (:width context) (:height context)) - (render-layer! context layer1 g 15 20)) + (render-layer! context layer2 g 15 20)) (size [this context] [100 100]))) (doto frame (.addWindowListener @@ -248,12 +253,21 @@ (defmethod handle-layer-event [layer1 MouseEvent/MOUSE_ENTERED] [layer context event] - (println "ENTERED")) + (println "1 ENTERED")) (defmethod handle-layer-event [layer1 MouseEvent/MOUSE_EXITED] [layer context event] - (println "EXITED")) + (println "1 EXITED")) (defmethod handle-layer-event [layer1 MouseEvent/MOUSE_MOVED] [layer context event] - (println "MOVED")) + (println "1 MOVED")) + (defmethod handle-layer-event [layer2 MouseEvent/MOUSE_ENTERED] + [layer context event] + (println "2 ENTERED")) + (defmethod handle-layer-event [layer2 MouseEvent/MOUSE_EXITED] + [layer context event] + (println "2 EXITED")) + (defmethod handle-layer-event [layer2 MouseEvent/MOUSE_MOVED] + [layer context event] + (println "2 MOVED")) ) ) \ No newline at end of file