changeset 131:24d4c9f3be90

Added transform and component to MouseEvent.
author Mikhail Kryshen <mikhail@kryshen.net>
date Fri, 13 Apr 2012 20:26:21 +0400
parents 43f78efe0903
children 77a3a609b2fe
files src/net/kryshen/indyvon/core.clj
diffstat 1 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/core.clj	Fri Apr 13 20:24:19 2012 +0400
+++ b/src/net/kryshen/indyvon/core.clj	Fri Apr 13 20:26:21 2012 +0400
@@ -196,7 +196,7 @@
 
 ;; TODO: modifiers
 (defrecord MouseEvent [id when x y x-on-screen y-on-screen button
-                       wheel-rotation])
+                       wheel-rotation transform component])
 
 ;; TODO: KeyEvent
 
@@ -326,11 +326,16 @@
     (.concatenate tr *initial-transform*) ; component -> absolute
     tr))
 
-(defn transform-point [^AffineTransform tr x y]
+(defn transform-point [^AffineTransform tr ^double x ^double y]
   (let [p (Point2D$Double. x y)]
     (.transform tr p p)
     [(.x p) (.y p)]))
 
+(defn inverse-transform-point [^AffineTransform tr ^double x ^double y]
+  (let [p (Point2D$Double. x y)]
+    (.inverseTransform tr p p)
+    [(.x p) (.y p)]))
+
 ;; (defn- clip
 ;;   "Intersect clipping area with the specified shape or bounds.
 ;;    Returns new clip (Shape or nil if empty)."
@@ -599,7 +604,7 @@
                      (dissoc (var *graphics*))
                      (assoc (var *font-context*) (font-context)))]
     (DispatcherNode. handle handlers *event-dispatcher* clip
-                     (inverse-relative-transform)
+                     (relative-transform)
                      bindings)))
 
 (defn- add-node [tree node]
@@ -621,14 +626,16 @@
 
 (defn- translate-mouse-event [^java.awt.event.MouseEvent event
                               ^AffineTransform tr id]
-  (let [[x y] (transform-point tr (.getX event) (.getY event))
+  (let [[x y] (inverse-transform-point tr (.getX event) (.getY event))
         rotation (if (instance? MouseWheelEvent event)
                    (.getWheelRotation ^MouseWheelEvent event)
                    nil)]
-    (MouseEvent. id (.getWhen event) x y
-                 (.getXOnScreen event) (.getYOnScreen event)
-                 (.getButton event)
-                 rotation)))
+    (->MouseEvent id (.getWhen event) x y
+                  (.getXOnScreen event) (.getYOnScreen event)
+                  (.getButton event)
+                  rotation
+                  tr
+                  (.getComponent event))))
 
 (defn- translate-and-dispatch
   ([nodes first-only ^java.awt.event.MouseEvent event]