Mercurial > hg > indyvon
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 wrap: on
line diff
--- a/src/net/kryshen/indyvon/core.clj Fri Apr 06 20:49:21 2012 +0400 +++ b/src/net/kryshen/indyvon/core.clj Thu Apr 12 19:40:05 2012 +0400 @@ -20,7 +20,7 @@ (ns net.kryshen.indyvon.core (:import (java.awt Graphics2D RenderingHints Component Color Font Shape - Cursor EventQueue) + Rectangle Cursor EventQueue) (java.awt.geom AffineTransform Point2D$Double Rectangle2D$Double Area) (java.awt.event MouseListener MouseMotionListener MouseWheelListener MouseWheelEvent) @@ -42,9 +42,9 @@ (def ^:dynamic ^Shape *clip*) -(def ^:dynamic *clipped* - "True value indicates that *clip* is a subset of - (Rectangle. 0 0 *width* *height*).") +(def ^:dynamic ^Shape *input-clip* + "Clipping area used for dispatching pointer events (intersected with + *clip*). If nil, *clip* will be used.") (def ^:dynamic *time* "Timestamp of the current frame (in nanoseconds).") @@ -343,14 +343,14 @@ ;; Use faster clipping calculation provided by Graphics2D. (defn- clip - "Intersect clipping area with the specified bounds in current + "Intersect clipping area with the specified Shape in current transform coordinates. Returns new clip in the AWT component coordinates (Shape or nil if empty)." - [x y w h] + [^Shape shape] (let [^Graphics2D clip-g (.create *graphics*)] (try (doto clip-g - (.setClip x y w h) + (.setClip shape) (.setTransform *initial-transform*) (.clip *clip*)) (if (.isEmpty (.getClipBounds clip-g)) @@ -382,7 +382,7 @@ (.translate graphics (double x) (double y)) (binding [*width* w *height* h - *clipped* false + *input-clip* (Rectangle2D$Double. 0.0 0.0 w h) *graphics* graphics] (apply f args)) (finally @@ -394,13 +394,13 @@ y (long y) w (long w) h (long h)] - (when-let [clip (clip x y w h)] + (when-let [clip (clip (Rectangle. x y w h))] (let [^Graphics2D graphics (create-graphics x y w h)] (try (binding [*width* w *height* h *clip* clip - *clipped* true + *input-clip* nil *graphics* graphics] (apply f args)) (finally @@ -588,9 +588,9 @@ (handle-hovered? parent handle))) (defn- make-node [handle handlers] - (let [clip (if *clipped* - *clip* - (clip 0 0 *width* *height*))] + (let [clip (if *input-clip* + (clip *input-clip*) + *clip*)] (DispatcherNode. handle handlers *event-dispatcher* clip (inverse-relative-transform) (get-thread-bindings)))) @@ -776,7 +776,7 @@ *width* width *height* height *clip* (Rectangle2D$Double. 0.0 0.0 width height) - *clipped* true + *input-clip* nil *time* (System/nanoTime)] (apply-theme) (let [tmp-watcher (Object.)]