# HG changeset patch # User Mikhail Kryshen <mikhail@kryshen.net> # Date 1280404773 -14400 # Node ID a20b1fccc0ef314ff957bf132d801597a9d378ab # Parent 409b1b16053dbe81fad5b540ba9bdebe5988ef19 Beginning of transformations. diff -r 409b1b16053d -r a20b1fccc0ef src/net/kryshen/indyvon/core.clj --- a/src/net/kryshen/indyvon/core.clj Thu Jul 29 01:28:30 2010 +0400 +++ b/src/net/kryshen/indyvon/core.clj Thu Jul 29 15:59:33 2010 +0400 @@ -7,6 +7,7 @@ (ns net.kryshen.indyvon.core (:import (java.awt Graphics2D Component Color Font AWTEvent) + (java.awt.geom AffineTransform) (java.awt.event MouseListener MouseMotionListener) (java.awt.font FontRenderContext))) @@ -152,6 +153,26 @@ (finally (.setColor *graphics* color#))))) +;; TODO: +;; +;; (with-transform +;; (rotate ...) +;; (draw ...) +;; (scale ...) +;; (draw ...)) + +(defmacro with-transform [transform & body] + `(let [old-t# (.getTransform *graphics*)] + (try + (.transform *graphics* ~transform) + ~@body + (finally + (.setTransform *graphics* old-t#))))) + +(defmacro with-rotate [theta ax ay & body] + `(let [transform# (AffineTransform/getRotateInstance ~theta ~ax ~ay)] + (with-transform transform# ~@body))) + (defn- geometry-vec [geometry] (if (vector? geometry) geometry diff -r 409b1b16053d -r a20b1fccc0ef src/net/kryshen/indyvon/demo.clj --- a/src/net/kryshen/indyvon/demo.clj Thu Jul 29 01:28:30 2010 +0400 +++ b/src/net/kryshen/indyvon/demo.clj Thu Jul 29 15:59:33 2010 +0400 @@ -37,7 +37,8 @@ (doto *graphics* (.setColor Color/YELLOW) (.fillRect 0 0 (:width *bounds*) (:height *bounds*))) - (draw! layer1b 10 5) + (with-rotate 0.5 0 0 + (draw! layer1b 10 5)) (draw! layer1 55 5)) (layer-size [layer] (Size. 70 65))))