changeset 51:a20b1fccc0ef

Beginning of transformations.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 29 Jul 2010 15:59:33 +0400
parents 409b1b16053d
children 7fcc0869ce00
files src/net/kryshen/indyvon/core.clj src/net/kryshen/indyvon/demo.clj
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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))))