changeset 62:44a7acf60c16

Asynchronous scaled display.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 26 Aug 2010 03:42:44 +0400
parents 88bb47e3a401
children 2d74abee0c93
files src/net/kryshen/indyvon/demo.clj src/net/kryshen/indyvon/layers.clj
diffstat 2 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/demo.clj	Wed Aug 25 22:03:01 2010 +0400
+++ b/src/net/kryshen/indyvon/demo.clj	Thu Aug 26 03:42:44 2010 +0400
@@ -30,7 +30,7 @@
 
 (def layer1b (border layer1 2 3))
 
-(def layer1c (async-layer layer1 20 30))
+;;(def layer1c (async-layer layer1 20 30))
 
 (def layer2
      (reify
@@ -41,9 +41,12 @@
            (.fillRect 0 0 *width* *height*))
          (with-rotate 0.5 0 0
            (draw! layer1b 30 25))
-         (draw! layer1c 55 5))
+         (draw! layer1 55 5))
       (layer-size [layer] (Size. 70 65))))
 
+(def layer2m
+     (miniature layer2 30 30))
+
 (def layer3
      (border (text-layer "Sample\ntext" :right :center)))
 
@@ -78,6 +81,7 @@
            (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED]))
            (.drawLine 0 0 *width* *height*))
          (draw! layer2 15 20)
+         (draw! layer2m 120 50)
          (draw! layer3 100 100 80 50)
          (draw! fps))
       (layer-size [layer] (Size. 400 300))))
--- a/src/net/kryshen/indyvon/layers.clj	Wed Aug 25 22:03:01 2010 +0400
+++ b/src/net/kryshen/indyvon/layers.clj	Thu Aug 26 03:42:44 2010 +0400
@@ -230,6 +230,23 @@
      (layer-size [layer]
         (Size. width height)))))
 
+(defn miniature
+  "Creates layer that asynchroniously renders view of the content
+  scaled to the specified size."
+  [content width height]
+  (async-layer
+   (reify
+    Layer
+    (render! [this]
+       (let [size (layer-size content)
+             sx (/ width (:width size))
+             sy (/ height (:height size))]
+         (.scale *graphics* sx sy)
+         (draw! content 0 0 (:width size) (:height size))))
+    (layer-size [this]
+       (Size. width height)))
+   width height))
+
 (defn viewport
   "Creates scrollable viewport layer."
   ([content] (viewport content :left :top))