Mercurial > hg > indyvon
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 wrap: on
line diff
--- a/src/indyvon/core.clj Mon Apr 14 20:01:00 2014 +0400 +++ b/src/indyvon/core.clj Tue Apr 15 23:45:14 2014 +0400 @@ -510,35 +510,35 @@ (render! view)) (finally (.dispose graphics))))) - ([x y view] - (draw! x y true view)) - ([x y clip? view] + ([view x y] + (draw! view x y true)) + ([view x y clip?] (let [geom (geometry view)] - (draw! x y (width geom) (height geom) clip? view))) - ([x y width height view] - (draw! x y width height true view)) - ([x y width height clip? view] + (draw! view x y (width geom) (height geom) clip?))) + ([view x y width height] + (draw! view x y width height true)) + ([view x y width height clip?] (if clip? (with-bounds* x y width height render! view) (with-bounds-noclip* x y width height render! view)))) (defn draw-aligned! "Draws the View. Location is relative to the view's anchor point - for the specified alignment." - ([h-align v-align x y view] + for the specified alignment." + ([view h-align v-align x y] (let [geom (geometry view) w (width geom) h (height geom)] - (draw! (- x (anchor-x geom h-align w)) + (draw! view + (- x (anchor-x geom h-align w)) (- y (anchor-y geom v-align h)) - w h - view))) - ([h-align v-align x y w h view] + w h))) + ([view h-align v-align x y w h] (let [geom (geometry view)] - (draw! (- x (anchor-x geom h-align w)) + (draw! view + (- x (anchor-x geom h-align w)) (- y (anchor-y geom v-align h)) - w h - view)))) + w h)))) ;; ;; Event handling.
--- a/src/indyvon/demo.clj Mon Apr 14 20:01:00 2014 +0400 +++ b/src/indyvon/demo.clj Tue Apr 15 23:45:14 2014 +0400 @@ -43,8 +43,8 @@ (.fillRect *graphics* shadow-offset shadow-offset width height)) (with-color color (.fillRect *graphics* offset offset width height)) - (draw! offset offset width height - (border border-width padding content))) + (draw! (border border-width padding content) + offset offset width height)) ;; Event handlers (:mouse-entered _ (repaint)) (:mouse-exited _ (repaint)) @@ -109,8 +109,8 @@ width height)) (with-color color (.fillRect *graphics* offset offset width height)) - (draw! offset offset width height - (border border-width padding content))) + (draw! (border border-width padding content) + offset offset width height)) ;; Event handlers (:mouse-entered _ (reset! animation-speed 4) @@ -160,8 +160,8 @@ (.setColor Color/YELLOW) (.fillRect 0 0 *width* *height*)) (with-rotate 0.5 0 0 - (draw! 30 25 test-view1b)) - (draw! 55 5 test-view1)) + (draw! test-view1b 30 25)) + (draw! test-view1 55 5)) (geometry [view] (->Size 70 65)))) @@ -180,13 +180,13 @@ ;; Random color to see when repaint happens. (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED])) (.fillOval 5 5 20 20)) - (draw! 30 20 test-view2) - (draw! 120 50 test-view2m) - (draw! 100 100 80 50 test-view3) - (draw! 50 160 button1) + (draw! test-view2 30 20) + (draw! test-view2m 120 50) + (draw! test-view3 100 100 80 50) + (draw! button1 50 160) (with-rotate (/ Math/PI 6) 250 200 - (draw! 210 140 button1)) - (draw! 100 200 button2) + (draw! button1 210 140)) + (draw! button2 100 200) (with-bounds 180 240 140 30 (draw-button! :button (label :center :center "Immediate button") @@ -206,10 +206,10 @@ (decorate-view vp [_] (draw! vp) (draw-aligned! - :left :bottom 5 (- *height* 5) (label (str "Drag mouse to pan," \newline - "use mouse wheel to zoom."))) - (draw! (- *width* 105) 5 vp-miniature)))) + "use mouse wheel to zoom.")) + :left :bottom 5 (- *height* 5)) + (draw! vp-miniature (- *width* 105) 5)))) (defn show-frame [view] (doto (make-jframe "Test" view)
--- a/src/indyvon/viewport.clj Mon Apr 14 20:01:00 2014 +0400 +++ b/src/indyvon/viewport.clj Tue Apr 15 23:45:14 2014 +0400 @@ -91,7 +91,7 @@ (binding [*viewport* view *viewport-transform* transform] (with-transform transform - (draw! 0 0 (width geom) (height geom) false content)))) + (draw! content 0 0 (width geom) (height geom) false)))) (:mouse-pressed e (swap! state assoc :fix-x (:x-on-screen e) @@ -188,10 +188,10 @@ ch (height geom) s (scaling cw ch mw mh)] (.scale *graphics* s s) - (draw! (align-x :center cw (/ mw s)) + (draw! content + (align-x :center cw (/ mw s)) (align-y :center ch (/ mh s)) - cw ch - content))) + cw ch))) (geometry [_] (->Size mw mh)))))
--- a/src/indyvon/views.clj Mon Apr 14 20:01:00 2014 +0400 +++ b/src/indyvon/views.clj Tue Apr 15 23:45:14 2014 +0400 @@ -60,11 +60,11 @@ (reify View (render! [l] - (draw! left top + (draw! content + left top (- *width* left right) (- *height* top bottom) - false - content)) + false)) (geometry [l] (->NestedGeometry (geometry content) top left bottom right)))))) @@ -106,7 +106,7 @@ h (- *height* abs-y)] (with-color :shadow-color (.fillRect *graphics* shadow-x shadow-y w h)) - (draw! x y w h content))) + (draw! content x y w h))) (geometry [_] (->NestedGeometry (geometry content) y x shadow-y shadow-x)))))) @@ -134,7 +134,7 @@ widths-sum (last xs) scale (/ *width* widths-sum)] (doseq [[c w x] (map vector contents widths xs)] - (draw! x 0 w *height* c)))) + (draw! c x 0 w *height*)))) (geometry [_] (reduce #(->Size (+ (width %1) (width %2)) (max (height %1) (height %2))) @@ -153,7 +153,7 @@ heights-sum (last ys) scale (/ *height* heights-sum)] (doseq [[c h y] (map vector contents heights ys)] - (draw! 0 y *width* h c)))) + (draw! c 0 y *width* h)))) (geometry [_] (reduce #(->Size (max (width %1) (width %2)) (+ (height %1) (height %2))) @@ -354,57 +354,58 @@ p)) (defn- draw-relative! - ([transform x y view] + ([view transform x y] (let [p (to-graphics-coords transform x y)] - (draw! (.getX p) (.getY p) view))) - ([transform x y w h view] + (draw! view (.getX p) (.getY p)))) + ([view transform x y w h] (let [p (to-graphics-coords transform x y)] - (draw! (.getX p) (.getY p) w h view)))) + (draw! view (.getX p) (.getY p) w h)))) (defn- draw-relative-aligned! - [transform h-align v-align x y view] + [view transform h-align v-align x y] (let [geom (geometry view) w (width geom) h (height geom) p (to-graphics-coords transform x y) x (- (.getX p) (anchor-x geom h-align w)) y (- (.getY p) (anchor-y geom v-align h))] - (draw! x y w h view))) + (draw! view x y w h))) (defn overlay! "Draws view in the overlay context above the other views." ([view] - (overlay* draw-relative! (.getTransform *graphics*) 0 0 view)) - ([x y view] - (overlay* draw-relative! (.getTransform *graphics*) x y view)) - ([x y w h view] - (overlay* draw-relative! (.getTransform *graphics*) x y w h view))) + (overlay* draw-relative! view (.getTransform *graphics*) 0 0)) + ([view x y] + (overlay* draw-relative! view (.getTransform *graphics*) x y)) + ([view x y w h] + (overlay* draw-relative! view (.getTransform *graphics*) x y w h))) -(defn overlay-aligned! [h-align v-align x y view] +(defn overlay-aligned! [view h-align v-align x y] (overlay* draw-relative-aligned! + view (.getTransform *graphics*) - h-align v-align x y - view)) + h-align v-align + x y)) -(defn with-overlays* [rec? f & args] +(defn with-overlays* [recursive? f & args] (binding [*above* []] (apply f args) - (if rec? + (if recursive? (loop [above *above*] (when (seq above) (var-set #'*above* []) - (doseq [f above] - (f)) + (doseq [of above] + (of)) (recur *above*))) (doseq [of *above*] (of))))) -(defmacro with-overlays [rec? & body] - `(with-overlays* ~rec? (fn [] ~@body))) +(defmacro with-overlays [recursive? & body] + `(with-overlays* ~recursive? (fn [] ~@body))) (defn layered ([content] (layered true content)) - ([rec? content] + ([recursive? content] (decorate-view content [_] - (with-overlays* rec? render! content)))) + (with-overlays* recursive? render! content))))