changeset 116:b76c0d00898b

Remember *graphics* binding in with-color and with-transform (performance + makes sure we restore state on the same instance). Update font context when changing transform.
author Mikhail Kryshen <mikhail@kryshen.net>
date Tue, 28 Feb 2012 02:31:10 +0400
parents d7ff88fa680f
children a50a304e58d8
files src/net/kryshen/indyvon/core.clj
diffstat 1 files changed, 14 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/src/net/kryshen/indyvon/core.clj	Fri Feb 24 01:30:51 2012 +0400
     1.2 +++ b/src/net/kryshen/indyvon/core.clj	Tue Feb 28 02:31:10 2012 +0400
     1.3 @@ -377,12 +377,13 @@
     1.4                       `(~color-or-keyword *theme*)
     1.5                       color-or-keyword)]
     1.6      `(let [color# ~color-form
     1.7 -           old-color# (.getColor *graphics*)]
     1.8 +           g# *graphics*
     1.9 +           old-color# (.getColor g#)]
    1.10         (try
    1.11 -         (.setColor *graphics* color#)
    1.12 +         (.setColor g# color#)
    1.13           ~@body
    1.14           (finally
    1.15 -          (.setColor *graphics* old-color#))))))
    1.16 +          (.setColor g# old-color#))))))
    1.17  
    1.18  (defn with-hints*
    1.19    [hints f & args]
    1.20 @@ -407,12 +408,14 @@
    1.21  ;;            :rotate (/ Math/PI 2))
    1.22  
    1.23  (defmacro with-transform [transform & body]
    1.24 -  `(let [old-t# (.getTransform *graphics*)]
    1.25 +  `(let [g# *graphics*
    1.26 +         old-t# (.getTransform g#)]
    1.27       (try
    1.28 -       (.transform *graphics* ~transform)
    1.29 -       ~@body
    1.30 +       (.transform g# ~transform)
    1.31 +       (binding [*font-context* (.getFontRenderContext g#)]
    1.32 +         ~@body)
    1.33         (finally
    1.34 -        (.setTransform *graphics* old-t#)))))
    1.35 +        (.setTransform g# old-t#)))))
    1.36  
    1.37  (defmacro with-rotate [theta ax ay & body]
    1.38    `(let [transform# (AffineTransform/getRotateInstance ~theta ~ax ~ay)]
    1.39 @@ -420,12 +423,13 @@
    1.40  
    1.41  (defmacro with-translate [x y & body]
    1.42    `(let [x# ~x
    1.43 -         y# ~y]
    1.44 +         y# ~y
    1.45 +         g# *graphics*]
    1.46       (try
    1.47 -       (.translate *graphics* x# y#)
    1.48 +       (.translate g# x# y#)
    1.49         ~@body
    1.50         (finally
    1.51 -        (.translate *graphics* (- x#) (- y#))))))
    1.52 +        (.translate g# (- x#) (- y#))))))
    1.53  
    1.54  (defn draw!
    1.55    "Draws layer."