changeset 125:11f2030257f9

Separate dynamic Var to specify clipping area for mouse events.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 12 Apr 2012 19:40:05 +0400
parents 6dae98ac9af4
children 24c7935a8f06
files src/net/kryshen/indyvon/core.clj
diffstat 1 files changed, 14 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/src/net/kryshen/indyvon/core.clj	Fri Apr 06 20:49:21 2012 +0400
     1.2 +++ b/src/net/kryshen/indyvon/core.clj	Thu Apr 12 19:40:05 2012 +0400
     1.3 @@ -20,7 +20,7 @@
     1.4  (ns net.kryshen.indyvon.core
     1.5    (:import
     1.6     (java.awt Graphics2D RenderingHints Component Color Font Shape
     1.7 -             Cursor EventQueue)
     1.8 +             Rectangle Cursor EventQueue)
     1.9     (java.awt.geom AffineTransform Point2D$Double Rectangle2D$Double Area)
    1.10     (java.awt.event MouseListener MouseMotionListener
    1.11                     MouseWheelListener MouseWheelEvent)
    1.12 @@ -42,9 +42,9 @@
    1.13  
    1.14  (def ^:dynamic ^Shape *clip*)
    1.15  
    1.16 -(def ^:dynamic *clipped*
    1.17 -  "True value indicates that *clip* is a subset of
    1.18 -  (Rectangle. 0 0 *width* *height*).")
    1.19 +(def ^:dynamic ^Shape *input-clip*
    1.20 +  "Clipping area used for dispatching pointer events (intersected with
    1.21 +  *clip*). If nil, *clip* will be used.")
    1.22  
    1.23  (def ^:dynamic *time*
    1.24    "Timestamp of the current frame (in nanoseconds).")
    1.25 @@ -343,14 +343,14 @@
    1.26  
    1.27  ;; Use faster clipping calculation provided by Graphics2D.
    1.28  (defn- clip
    1.29 -  "Intersect clipping area with the specified bounds in current
    1.30 +  "Intersect clipping area with the specified Shape in current
    1.31     transform coordinates. Returns new clip in the AWT component
    1.32     coordinates (Shape or nil if empty)."
    1.33 -  [x y w h]
    1.34 +  [^Shape shape]
    1.35    (let [^Graphics2D clip-g (.create *graphics*)]
    1.36      (try
    1.37        (doto clip-g
    1.38 -        (.setClip x y w h)
    1.39 +        (.setClip shape)
    1.40          (.setTransform *initial-transform*)
    1.41          (.clip *clip*))
    1.42        (if (.isEmpty (.getClipBounds clip-g))
    1.43 @@ -382,7 +382,7 @@
    1.44        (.translate graphics (double x) (double y))
    1.45        (binding [*width* w
    1.46                  *height* h
    1.47 -                *clipped* false
    1.48 +                *input-clip* (Rectangle2D$Double. 0.0 0.0 w h)
    1.49                  *graphics* graphics]
    1.50          (apply f args))
    1.51        (finally
    1.52 @@ -394,13 +394,13 @@
    1.53          y (long y)
    1.54          w (long w)
    1.55          h (long h)]
    1.56 -    (when-let [clip (clip x y w h)]
    1.57 +    (when-let [clip (clip (Rectangle. x y w h))]
    1.58        (let [^Graphics2D graphics (create-graphics x y w h)]
    1.59          (try
    1.60            (binding [*width* w
    1.61                      *height* h
    1.62                      *clip* clip
    1.63 -                    *clipped* true
    1.64 +                    *input-clip* nil
    1.65                      *graphics* graphics]
    1.66              (apply f args))
    1.67            (finally
    1.68 @@ -588,9 +588,9 @@
    1.69      (handle-hovered? parent handle)))
    1.70  
    1.71  (defn- make-node [handle handlers]
    1.72 -  (let [clip (if *clipped*
    1.73 -               *clip*
    1.74 -               (clip 0 0 *width* *height*))]
    1.75 +  (let [clip (if *input-clip*
    1.76 +               (clip *input-clip*)
    1.77 +               *clip*)]
    1.78      (DispatcherNode. handle handlers *event-dispatcher* clip
    1.79                       (inverse-relative-transform)
    1.80                       (get-thread-bindings))))
    1.81 @@ -776,7 +776,7 @@
    1.82              *width* width
    1.83              *height* height
    1.84              *clip* (Rectangle2D$Double. 0.0 0.0 width height)
    1.85 -            *clipped* true
    1.86 +            *input-clip* nil
    1.87              *time* (System/nanoTime)]
    1.88      (apply-theme)
    1.89      (let [tmp-watcher (Object.)]