changeset 155:c3782e84486f

Reverted some of the changes in 9997ac717c3c.
author Mikhail Kryshen <mikhail@kryshen.net>
date Tue, 15 Apr 2014 23:45:14 +0400
parents ed36fcf061de
children dc13cacf3a43
files src/indyvon/core.clj src/indyvon/demo.clj src/indyvon/viewport.clj src/indyvon/views.clj
diffstat 4 files changed, 64 insertions(+), 63 deletions(-) [+]
line diff
     1.1 --- a/src/indyvon/core.clj	Mon Apr 14 20:01:00 2014 +0400
     1.2 +++ b/src/indyvon/core.clj	Tue Apr 15 23:45:14 2014 +0400
     1.3 @@ -510,35 +510,35 @@
     1.4             (render! view))
     1.5           (finally
     1.6            (.dispose graphics)))))
     1.7 -  ([x y view]
     1.8 -     (draw! x y true view))
     1.9 -  ([x y clip? view]
    1.10 +  ([view x y]
    1.11 +     (draw! view x y true))
    1.12 +  ([view x y clip?]
    1.13       (let [geom (geometry view)]
    1.14 -       (draw! x y (width geom) (height geom) clip? view)))
    1.15 -  ([x y width height view]
    1.16 -     (draw! x y width height true view))
    1.17 -  ([x y width height clip? view]
    1.18 +       (draw! view x y (width geom) (height geom) clip?)))
    1.19 +  ([view x y width height]
    1.20 +     (draw! view x y width height true))
    1.21 +  ([view x y width height clip?]
    1.22       (if clip?
    1.23         (with-bounds* x y width height render! view)
    1.24         (with-bounds-noclip* x y width height render! view))))
    1.25  
    1.26  (defn draw-aligned!
    1.27    "Draws the View.  Location is relative to the view's anchor point
    1.28 -   for the specified alignment."
    1.29 -  ([h-align v-align x y view]
    1.30 +  for the specified alignment."
    1.31 +  ([view h-align v-align x y]
    1.32       (let [geom (geometry view)
    1.33             w (width geom)
    1.34             h (height geom)]
    1.35 -       (draw! (- x (anchor-x geom h-align w))
    1.36 +       (draw! view
    1.37 +              (- x (anchor-x geom h-align w))
    1.38                (- y (anchor-y geom v-align h))
    1.39 -              w h
    1.40 -              view)))
    1.41 -  ([h-align v-align x y w h view]
    1.42 +              w h)))
    1.43 +  ([view h-align v-align x y w h]
    1.44       (let [geom (geometry view)]
    1.45 -       (draw! (- x (anchor-x geom h-align w))
    1.46 +       (draw! view
    1.47 +              (- x (anchor-x geom h-align w))
    1.48                (- y (anchor-y geom v-align h))
    1.49 -              w h
    1.50 -              view))))
    1.51 +              w h))))
    1.52  
    1.53  ;;
    1.54  ;; Event handling.
     2.1 --- a/src/indyvon/demo.clj	Mon Apr 14 20:01:00 2014 +0400
     2.2 +++ b/src/indyvon/demo.clj	Tue Apr 15 23:45:14 2014 +0400
     2.3 @@ -43,8 +43,8 @@
     2.4          (.fillRect *graphics* shadow-offset shadow-offset width height))
     2.5        (with-color color
     2.6          (.fillRect *graphics* offset offset width height))
     2.7 -      (draw! offset offset width height
     2.8 -             (border border-width padding content)))
     2.9 +      (draw! (border border-width padding content)
    2.10 +             offset offset width height))
    2.11      ;; Event handlers
    2.12      (:mouse-entered _ (repaint))
    2.13      (:mouse-exited _ (repaint))
    2.14 @@ -109,8 +109,8 @@
    2.15                           width height))
    2.16              (with-color color
    2.17                (.fillRect *graphics* offset offset width height))
    2.18 -            (draw! offset offset width height
    2.19 -                   (border border-width padding content)))
    2.20 +            (draw! (border border-width padding content)
    2.21 +                   offset offset width height))
    2.22            ;; Event handlers
    2.23            (:mouse-entered _
    2.24              (reset! animation-speed 4)
    2.25 @@ -160,8 +160,8 @@
    2.26         (.setColor Color/YELLOW)
    2.27         (.fillRect 0 0 *width* *height*))
    2.28       (with-rotate 0.5 0 0
    2.29 -       (draw! 30 25 test-view1b))
    2.30 -     (draw! 55 5 test-view1))
    2.31 +       (draw! test-view1b 30 25))
    2.32 +     (draw! test-view1 55 5))
    2.33     (geometry [view]
    2.34       (->Size 70 65))))
    2.35  
    2.36 @@ -180,13 +180,13 @@
    2.37         ;; Random color to see when repaint happens.
    2.38         (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED]))
    2.39         (.fillOval 5 5 20 20))
    2.40 -     (draw! 30 20 test-view2)
    2.41 -     (draw! 120 50 test-view2m)
    2.42 -     (draw! 100 100 80 50 test-view3)
    2.43 -     (draw! 50 160 button1)
    2.44 +     (draw! test-view2 30 20)
    2.45 +     (draw! test-view2m 120 50)
    2.46 +     (draw! test-view3 100 100 80 50)
    2.47 +     (draw! button1 50 160)
    2.48       (with-rotate (/ Math/PI 6) 250 200
    2.49 -       (draw! 210 140 button1))
    2.50 -     (draw! 100 200 button2)
    2.51 +       (draw! button1 210 140))
    2.52 +     (draw! button2 100 200)
    2.53       (with-bounds 180 240 140 30
    2.54         (draw-button! :button
    2.55          (label :center :center "Immediate button")
    2.56 @@ -206,10 +206,10 @@
    2.57     (decorate-view vp [_]
    2.58       (draw! vp)
    2.59       (draw-aligned!
    2.60 -      :left :bottom 5 (- *height* 5)
    2.61        (label (str "Drag mouse to pan," \newline
    2.62 -                  "use mouse wheel to zoom.")))
    2.63 -     (draw! (- *width* 105) 5 vp-miniature))))
    2.64 +                  "use mouse wheel to zoom."))
    2.65 +      :left :bottom 5 (- *height* 5))
    2.66 +     (draw! vp-miniature (- *width* 105) 5))))
    2.67  
    2.68  (defn show-frame [view]
    2.69    (doto (make-jframe "Test" view)
     3.1 --- a/src/indyvon/viewport.clj	Mon Apr 14 20:01:00 2014 +0400
     3.2 +++ b/src/indyvon/viewport.clj	Tue Apr 15 23:45:14 2014 +0400
     3.3 @@ -91,7 +91,7 @@
     3.4          (binding [*viewport* view
     3.5                    *viewport-transform* transform]
     3.6            (with-transform transform
     3.7 -            (draw! 0 0 (width geom) (height geom) false content))))
     3.8 +            (draw! content 0 0 (width geom) (height geom) false))))
     3.9        (:mouse-pressed e
    3.10         (swap! state assoc
    3.11                :fix-x (:x-on-screen e)
    3.12 @@ -188,10 +188,10 @@
    3.13              ch (height geom)
    3.14              s (scaling cw ch mw mh)]
    3.15          (.scale *graphics* s s)
    3.16 -        (draw! (align-x :center cw (/ mw s))
    3.17 +        (draw! content
    3.18 +               (align-x :center cw (/ mw s))
    3.19                 (align-y :center ch (/ mh s))
    3.20 -               cw ch
    3.21 -               content)))
    3.22 +               cw ch)))
    3.23      (geometry [_]
    3.24        (->Size mw mh)))))
    3.25  
     4.1 --- a/src/indyvon/views.clj	Mon Apr 14 20:01:00 2014 +0400
     4.2 +++ b/src/indyvon/views.clj	Tue Apr 15 23:45:14 2014 +0400
     4.3 @@ -60,11 +60,11 @@
     4.4         (reify
     4.5          View
     4.6          (render! [l]
     4.7 -           (draw! left top
     4.8 +           (draw! content
     4.9 +                  left top
    4.10                    (- *width* left right)
    4.11                    (- *height* top bottom)
    4.12 -                  false
    4.13 -                  content))
    4.14 +                  false))
    4.15          (geometry [l]
    4.16            (->NestedGeometry (geometry content) top left bottom right))))))
    4.17  
    4.18 @@ -106,7 +106,7 @@
    4.19                  h (- *height* abs-y)]
    4.20              (with-color :shadow-color
    4.21                (.fillRect *graphics* shadow-x shadow-y w h))
    4.22 -            (draw! x y w h content)))
    4.23 +            (draw! content x y w h)))
    4.24          (geometry [_]
    4.25            (->NestedGeometry (geometry content)
    4.26                              y x shadow-y shadow-x))))))
    4.27 @@ -134,7 +134,7 @@
    4.28             widths-sum (last xs)
    4.29             scale (/ *width* widths-sum)]
    4.30         (doseq [[c w x] (map vector contents widths xs)]
    4.31 -         (draw! x 0 w *height* c))))
    4.32 +         (draw! c x 0 w *height*))))
    4.33     (geometry [_]
    4.34       (reduce #(->Size (+ (width %1) (width %2))
    4.35                        (max (height %1) (height %2)))
    4.36 @@ -153,7 +153,7 @@
    4.37             heights-sum (last ys)
    4.38             scale (/ *height* heights-sum)]
    4.39         (doseq [[c h y] (map vector contents heights ys)]
    4.40 -         (draw! 0 y *width* h c))))
    4.41 +         (draw! c 0 y *width* h))))
    4.42     (geometry [_]
    4.43       (reduce #(->Size (max (width %1) (width %2))
    4.44                        (+ (height %1) (height %2)))
    4.45 @@ -354,57 +354,58 @@
    4.46      p))
    4.47  
    4.48  (defn- draw-relative!
    4.49 -  ([transform x y view]
    4.50 +  ([view transform x y]
    4.51       (let [p (to-graphics-coords transform x y)]
    4.52 -       (draw! (.getX p) (.getY p) view)))
    4.53 -  ([transform x y w h view]
    4.54 +       (draw! view (.getX p) (.getY p))))
    4.55 +  ([view transform x y w h]
    4.56       (let [p (to-graphics-coords transform x y)]
    4.57 -       (draw! (.getX p) (.getY p) w h view))))
    4.58 +       (draw! view (.getX p) (.getY p) w h))))
    4.59  
    4.60  (defn- draw-relative-aligned!
    4.61 -  [transform h-align v-align x y view]
    4.62 +  [view transform h-align v-align x y]
    4.63    (let [geom (geometry view)
    4.64          w (width geom)
    4.65          h (height geom)
    4.66          p (to-graphics-coords transform x y)
    4.67          x (- (.getX p) (anchor-x geom h-align w))
    4.68          y (- (.getY p) (anchor-y geom v-align h))]
    4.69 -    (draw! x y w h view)))
    4.70 +    (draw! view x y w h)))
    4.71  
    4.72  (defn overlay!
    4.73    "Draws view in the overlay context above the other views."
    4.74    ([view]
    4.75 -     (overlay* draw-relative! (.getTransform *graphics*) 0 0 view))
    4.76 -  ([x y view]
    4.77 -     (overlay* draw-relative! (.getTransform *graphics*) x y view))
    4.78 -  ([x y w h view]
    4.79 -     (overlay* draw-relative! (.getTransform *graphics*) x y w h view)))
    4.80 +     (overlay* draw-relative! view (.getTransform *graphics*) 0 0))
    4.81 +  ([view x y]
    4.82 +     (overlay* draw-relative! view (.getTransform *graphics*) x y))
    4.83 +  ([view x y w h]
    4.84 +     (overlay* draw-relative! view (.getTransform *graphics*) x y w h)))
    4.85  
    4.86 -(defn overlay-aligned! [h-align v-align x y view]
    4.87 +(defn overlay-aligned! [view h-align v-align x y]
    4.88    (overlay* draw-relative-aligned!
    4.89 +            view
    4.90              (.getTransform *graphics*)
    4.91 -            h-align v-align x y
    4.92 -            view))
    4.93 +            h-align v-align
    4.94 +            x y))
    4.95  
    4.96 -(defn with-overlays* [rec? f & args]
    4.97 +(defn with-overlays* [recursive? f & args]
    4.98    (binding [*above* []]
    4.99      (apply f args)
   4.100 -    (if rec?
   4.101 +    (if recursive?
   4.102        (loop [above *above*]
   4.103          (when (seq above)
   4.104            (var-set #'*above* [])
   4.105 -          (doseq [f above]
   4.106 -            (f))
   4.107 +          (doseq [of above]
   4.108 +            (of))
   4.109            (recur *above*)))
   4.110        (doseq [of *above*]
   4.111          (of)))))
   4.112  
   4.113 -(defmacro with-overlays [rec? & body]
   4.114 -  `(with-overlays* ~rec? (fn [] ~@body)))
   4.115 +(defmacro with-overlays [recursive? & body]
   4.116 +  `(with-overlays* ~recursive? (fn [] ~@body)))
   4.117  
   4.118  (defn layered
   4.119    ([content]
   4.120       (layered true content))
   4.121 -  ([rec? content]
   4.122 +  ([recursive? content]
   4.123       (decorate-view content [_]
   4.124 -       (with-overlays* rec? render! content))))
   4.125 +       (with-overlays* recursive? render! content))))