changeset 86:069ea63803a2

Correctly highlight visible area in viewport miniature.
author Mikhail Kryshen <mikhail@kryshen.net>
date Wed, 06 Oct 2010 18:08:21 +0400
parents e718a69f7d99
children beb89bd18839
files src/net/kryshen/indyvon/layers.clj
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/layers.clj	Fri Oct 01 18:45:17 2010 +0400
+++ b/src/net/kryshen/indyvon/layers.clj	Wed Oct 06 18:08:21 2010 +0400
@@ -220,8 +220,10 @@
    width height))
 
 (defrecord Viewport [content h-align v-align
-                     ;; state (refs)
-                     x y fix-x fix-y last-width last-height]
+                     ;; State (refs)
+                     ;; TODO: group into data structures.
+                     x y fix-x fix-y last-width last-height
+                     vp-x vp-y]
   Layer
   (render! [layer]
     (repaint-on-update layer)
@@ -231,9 +233,11 @@
          (alter x + (align-x *width* @last-width h-align))
          (alter y + (align-y *height* @last-height v-align))
          (ref-set last-width *width*)
-         (ref-set last-height *height*))
+         (ref-set last-height *height*)
+         (ref-set vp-x (+ @x (:x anchor)))
+         (ref-set vp-y (+ @y (:y anchor))))
         ;; TODO: notify observers when size changes.
-        (draw! content (- 0 @x (:x anchor)) (- 0 @y (:y anchor))))
+        (draw! content (- @vp-x) (- @vp-y)))
       (:mouse-pressed e
        (dosync
         (ref-set fix-x (:x-on-screen e))
@@ -260,13 +264,14 @@
      (Viewport. content h-align v-align
                 (ref 0) (ref 0)    ; x y
                 (ref 0) (ref 0)    ; fix-x fix-y
-                (ref 0) (ref 0)))) ; last-width last-height
+                (ref 0) (ref 0)    ; last-width last-height
+                (ref 0) (ref 0)))) ; vp-x vp-y
 
 (defn- viewport-visible-bounds
-  [viewport]
+  [vp]
   (dosync
-   [@(:x viewport) @(:y viewport)
-    @(:last-width viewport) @(:last-height viewport)]))
+   [@(:vp-x vp) @(:vp-y vp)
+    @(:last-width vp) @(:last-height vp)]))
 
 (defn viewport-miniature
   "Creates miniature view of the viewport's contents."