Mercurial > hg > indyvon
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 wrap: on
line diff
--- a/src/net/kryshen/indyvon/core.clj Fri Feb 24 01:30:51 2012 +0400 +++ b/src/net/kryshen/indyvon/core.clj Tue Feb 28 02:31:10 2012 +0400 @@ -377,12 +377,13 @@ `(~color-or-keyword *theme*) color-or-keyword)] `(let [color# ~color-form - old-color# (.getColor *graphics*)] + g# *graphics* + old-color# (.getColor g#)] (try - (.setColor *graphics* color#) + (.setColor g# color#) ~@body (finally - (.setColor *graphics* old-color#)))))) + (.setColor g# old-color#)))))) (defn with-hints* [hints f & args] @@ -407,12 +408,14 @@ ;; :rotate (/ Math/PI 2)) (defmacro with-transform [transform & body] - `(let [old-t# (.getTransform *graphics*)] + `(let [g# *graphics* + old-t# (.getTransform g#)] (try - (.transform *graphics* ~transform) - ~@body + (.transform g# ~transform) + (binding [*font-context* (.getFontRenderContext g#)] + ~@body) (finally - (.setTransform *graphics* old-t#))))) + (.setTransform g# old-t#))))) (defmacro with-rotate [theta ax ay & body] `(let [transform# (AffineTransform/getRotateInstance ~theta ~ax ~ay)] @@ -420,12 +423,13 @@ (defmacro with-translate [x y & body] `(let [x# ~x - y# ~y] + y# ~y + g# *graphics*] (try - (.translate *graphics* x# y#) + (.translate g# x# y#) ~@body (finally - (.translate *graphics* (- x#) (- y#)))))) + (.translate g# (- x#) (- y#)))))) (defn draw! "Draws layer."