changeset 3:6bc931b1b755

Event processing.
author Mikhail Kryshen <mikhail@kryshen.net>
date Tue, 08 Jun 2010 15:24:45 +0400
parents 0f2a98f71a9c
children 0771180bf7c2
files src/indyvon/core.clj
diffstat 1 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/indyvon/core.clj	Mon Jun 07 21:13:05 2010 +0400
+++ b/src/indyvon/core.clj	Tue Jun 08 15:24:45 2010 +0400
@@ -60,6 +60,12 @@
 ;; Event handling
 ;;
 
+(defmulti handle-layer-event 
+  (fn [layer event]
+    [layer (.getID event)]))
+
+(defmethod handle-layer-event :default [layer event])
+
 (defprotocol EventDispatcher
   (register [this layer])
   (commit [this])
@@ -82,6 +88,7 @@
       (dosync (ref-set contexts-d @contexts-r)
               (ref-set contexts-r [])))
      (dispatch [this event]
+               (println "dispatch" this event)
                ;; TODO
                ))))
 
@@ -110,19 +117,24 @@
 ;;     (getPreferredSize []
 ;;                       (size layer))))
 
-(defn make-component [layer]
-  (proxy [Component] []
-    (update [g] (.paint this g))
-    (paint [g]
-           (let [size (.getSize this)
-                 width (.width size)
-                 height (.height size)]
-             (binding [*graphics* g
-                       *update-fn* (make-update-fn this)]
-               (render-layer! layer 0 0 width height false))))
-    (getPreferredSize []
-                      (let [s (size layer)]
-                        (Dimension. (s 0) (s 1))))))
+(defn make-component
+  ([layer]
+     (make-component layer (make-event-dispatcher)))
+  ([layer event-dispatcher]
+     (proxy [Component] []
+       (update [g] (.paint this g))
+       (paint [g]
+              (let [size (.getSize this)
+                    width (.width size)
+                    height (.height size)]
+                (binding [*graphics* g
+                          *update-fn* (make-update-fn this)]
+                  (render-layer! layer 0 0 width height false))))
+       (getPreferredSize []
+                         (let [s (size layer)]
+                           (Dimension. (s 0) (s 1))))
+       (processEvent [event]
+                     (dispatch event-dispatcher event)))))
 
 (comment
   (do