Mercurial > hg > indyvon
changeset 87:beb89bd18839
Faster clipping calculation (fixes performance bottleneck).
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Wed, 06 Oct 2010 18:09:37 +0400 |
parents | 069ea63803a2 |
children | 18abc7d66d49 |
files | src/net/kryshen/indyvon/core.clj |
diffstat | 1 files changed, 30 insertions(+), 12 deletions(-) [+] |
line diff
1.1 --- a/src/net/kryshen/indyvon/core.clj Wed Oct 06 18:08:21 2010 +0400 1.2 +++ b/src/net/kryshen/indyvon/core.clj Wed Oct 06 18:09:37 2010 +0400 1.3 @@ -212,19 +212,37 @@ 1.4 (.concatenate tr *initial-transform*) ; component -> absolute 1.5 tr)) 1.6 1.7 +;; (defn- clip 1.8 +;; "Intersect clipping area with the specified shape or bounds. 1.9 +;; Returns new clip (Shape or nil if empty)." 1.10 +;; ([x y w h] 1.11 +;; (clip (Rectangle2D$Double. x y w h))) 1.12 +;; ([shape] 1.13 +;; (let [a1 (Area. shape) 1.14 +;; a2 (if (instance? Area *clip*) *clip* (Area. *clip*))] 1.15 +;; (.transform a1 (relative-transform)) 1.16 +;; (.intersect a1 a2) 1.17 +;; (if (.isEmpty a1) 1.18 +;; nil 1.19 +;; a1)))) 1.20 + 1.21 +;; Use faster clipping calculation provided by Graphics2D. 1.22 (defn- clip 1.23 - "Intersect clipping area with the specified shape or bounds. 1.24 - Returns new clip (Shape or nil if empty)." 1.25 - ([x y w h] 1.26 - (clip (Rectangle2D$Double. x y w h))) 1.27 - ([shape] 1.28 - (let [a1 (Area. shape) 1.29 - a2 (if (instance? Area *clip*) *clip* (Area. *clip*))] 1.30 - (.transform a1 (relative-transform)) 1.31 - (.intersect a1 a2) 1.32 - (if (.isEmpty a1) 1.33 - nil 1.34 - a1)))) 1.35 + "Intersect clipping area with the specified bounds in current 1.36 + transform coordinates. Returns new clip in the AWT component 1.37 + coordinates (Shape or nil if empty)." 1.38 + [x y w h] 1.39 + (let [^Graphics2D clip-g (.create *graphics*)] 1.40 + (doto clip-g 1.41 + (.setClip x y w h) 1.42 + (.setTransform *initial-transform*) 1.43 + (.clip *clip*)) 1.44 + (try 1.45 + (if (.isEmpty (.getClipBounds clip-g)) 1.46 + nil 1.47 + (.getClip clip-g)) 1.48 + (finally 1.49 + (.dispose clip-g))))) 1.50 1.51 (defn- ^Graphics2D apply-theme 1.52 "Set graphics' color and font to match theme.