Mercurial > hg > indyvon
changeset 90:dd7b8dbb20bc
Viewport miniature: preserve aspect ratio; draw visible area highlight synchronously.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Sun, 28 Nov 2010 03:46:59 +0300 |
parents | 54f6e6d196c3 |
children | f87363889015 |
files | src/net/kryshen/indyvon/async.clj src/net/kryshen/indyvon/component.clj src/net/kryshen/indyvon/core.clj src/net/kryshen/indyvon/layers.clj |
diffstat | 4 files changed, 46 insertions(+), 26 deletions(-) [+] |
line diff
1.1 --- a/src/net/kryshen/indyvon/async.clj Mon Nov 22 16:02:27 2010 +0300 1.2 +++ b/src/net/kryshen/indyvon/async.clj Sun Nov 28 03:46:59 2010 +0300 1.3 @@ -23,7 +23,7 @@ 1.4 net.kryshen.indyvon.core) 1.5 (:import 1.6 (net.kryshen.indyvon.core Size Location) 1.7 - (java.awt Image) 1.8 + (java.awt Image AlphaComposite) 1.9 (java.awt.image BufferedImage) 1.10 (java.util.concurrent ThreadFactory ThreadPoolExecutor 1.11 ThreadPoolExecutor$DiscardOldestPolicy 1.12 @@ -111,13 +111,18 @@ 1.13 (defn- draw-offscreen [async-layer] 1.14 ;;(Thread/sleep 1000) 1.15 (with-buffer async-layer :back [b] 1.16 - (draw-root! (:content async-layer) 1.17 - (.getGraphics ^Image (:image b)) 1.18 - (:width async-layer) 1.19 - (:height async-layer) 1.20 - ;; TODO: use operational event dispatcher. 1.21 - dummy-event-dispatcher)) 1.22 - (update async-layer)) 1.23 + (let [g (.getGraphics ^Image (:image b))] 1.24 + ;; Clear the buffer. 1.25 + (.setComposite g AlphaComposite/Clear) 1.26 + (.fillRect g 0 0 (:width async-layer) (:height async-layer)) 1.27 + (.setComposite g AlphaComposite/Src) 1.28 + (draw-root! (:content async-layer) 1.29 + g 1.30 + (:width async-layer) 1.31 + (:height async-layer) 1.32 + ;; TODO: use operational event dispatcher. 1.33 + dummy-event-dispatcher)) 1.34 + (update async-layer))) 1.35 1.36 (defn- draw-offscreen-async [async-layer] 1.37 (.execute ^ThreadPoolExecutor (:executor async-layer)
2.1 --- a/src/net/kryshen/indyvon/component.clj Mon Nov 22 16:02:27 2010 +0300 2.2 +++ b/src/net/kryshen/indyvon/component.clj Sun Nov 28 03:46:59 2010 +0300 2.3 @@ -38,6 +38,8 @@ 2.4 (proxy [JPanel] [] 2.5 (paintComponent [g] 2.6 (let [size (.getSize ^Component this)] 2.7 + (.setColor g (:back-color *theme*)) 2.8 + (.fillRect g 0 0 (.width size) (.height size)) 2.9 (draw-root! layer g (.width size) (.height size) 2.10 event-dispatcher this))) 2.11 (getPreferredSize []
3.1 --- a/src/net/kryshen/indyvon/core.clj Mon Nov 22 16:02:27 2010 +0300 3.2 +++ b/src/net/kryshen/indyvon/core.clj Sun Nov 28 03:46:59 2010 +0300 3.3 @@ -369,8 +369,6 @@ 3.4 ;; RenderingHints/KEY_ANTIALIASING 3.5 ;; RenderingHints/VALUE_ANTIALIAS_ON) 3.6 (apply-theme) 3.7 - (with-color (:back-color *theme*) 3.8 - (.fillRect graphics 0 0 width height)) 3.9 (let [tmp-watcher (Object.)] 3.10 ;; Keep current context observers until the rendering is 3.11 ;; complete. Some observers may be invoked twice if they
4.1 --- a/src/net/kryshen/indyvon/layers.clj Mon Nov 22 16:02:27 2010 +0300 4.2 +++ b/src/net/kryshen/indyvon/layers.clj Sun Nov 28 03:46:59 2010 +0300 4.3 @@ -204,6 +204,11 @@ 4.4 4.5 (def *miniature-thread-priority* 2) 4.6 4.7 +(defn- scaling 4.8 + [width height max-width max-height] 4.9 + (min (/ max-width width) 4.10 + (/ max-height height))) 4.11 + 4.12 (defn miniature 4.13 "Creates layer that asynchronously renders view of the content 4.14 scaled to the specified size." 4.15 @@ -213,12 +218,17 @@ 4.16 Layer 4.17 (render! [this] 4.18 (let [size (layer-size content) 4.19 - sx (/ width (:width size)) 4.20 - sy (/ height (:height size))] 4.21 - (.scale *graphics* sx sy) 4.22 - (draw! content 0 0 (:width size) (:height size)))) 4.23 + s (scaling (:width size) (:height size) width height)] 4.24 + (.scale *graphics* s s) 4.25 + (draw! content 4.26 + (align-x (:width size) (/ width s) :center) 4.27 + (align-y (:height size) (/ height s) :center) 4.28 + (:width size) (:height size)))) 4.29 (layer-size [this] 4.30 (Size. width height))) 4.31 + ;; (let [size (layer-size content) 4.32 + ;; s (scaling (:width size) (:height size) width height)] 4.33 + ;; (Size. (* (:width size) s) (* (:height size) s))))) 4.34 width height *miniature-thread-priority*)) 4.35 4.36 (defrecord Viewport [content h-align v-align 4.37 @@ -278,18 +288,23 @@ 4.38 (defn viewport-miniature 4.39 "Creates miniature view of the viewport's contents." 4.40 [viewport width height] 4.41 - (miniature 4.42 - (decorate-layer (:content viewport) [_] 4.43 - (repaint-on-update viewport) 4.44 - (let [[x y w h] (viewport-visible-bounds viewport)] 4.45 - (with-color :alt-back-color 4.46 - (.fillRect *graphics* 0 0 *width* *height*)) 4.47 - (with-color :back-color 4.48 - (.fillRect *graphics* x y w h)) 4.49 - (draw! (:content viewport)) 4.50 - (with-color :border-color 4.51 - (.drawRect *graphics* x y w h)))) 4.52 - width height)) 4.53 + (let [miniature (miniature (:content viewport) width height)] 4.54 + (decorate-layer miniature [_] 4.55 + ;;(repaint-on-update viewport) 4.56 + (let [size (layer-size (:content viewport)) 4.57 + s (scaling (:width size) (:height size) width height) 4.58 + [x y w h] (viewport-visible-bounds viewport) 4.59 + x (* x s) 4.60 + y (* y s) 4.61 + w (* w s) 4.62 + h (* h s)] 4.63 + (with-color :alt-back-color 4.64 + (.fillRect *graphics* 0 0 *width* *height*)) 4.65 + (with-color :back-color 4.66 + (.fillRect *graphics* x y w h)) 4.67 + (draw! miniature) 4.68 + (with-color :border-color 4.69 + (.drawRect *graphics* x y w h)))))) 4.70 4.71 ;; 4.72 ;; Layer context decorators.