Mercurial > hg > indyvon
changeset 152:9997ac717c3c
Changed order of arguments for many functions: attributes go before content.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Mon, 07 Apr 2014 20:19:02 +0400 |
parents | cb108c6fa079 |
children | 291afc2a8ca2 |
files | src/net/kryshen/indyvon/async.clj src/net/kryshen/indyvon/core.clj src/net/kryshen/indyvon/demo.clj src/net/kryshen/indyvon/viewport.clj src/net/kryshen/indyvon/views.clj |
diffstat | 5 files changed, 88 insertions(+), 87 deletions(-) [+] |
line diff
1.1 --- a/src/net/kryshen/indyvon/async.clj Mon Apr 07 15:23:58 2014 +0400 1.2 +++ b/src/net/kryshen/indyvon/async.clj Mon Apr 07 20:19:02 2014 +0400 1.3 @@ -167,9 +167,9 @@ 1.4 (defn async-view 1.5 "Creates a View that draws the content asynchronously using an 1.6 offscreen buffer." 1.7 - ([content width height] 1.8 - (async-view content width height nil)) 1.9 - ([content width height priority] 1.10 + ([width height content] 1.11 + (async-view width height nil content)) 1.12 + ([width height priority content] 1.13 ;; TODO: use operational event dispatcher. 1.14 (->AsyncView (make-scene content) 1.15 width
2.1 --- a/src/net/kryshen/indyvon/core.clj Mon Apr 07 15:23:58 2014 +0400 2.2 +++ b/src/net/kryshen/indyvon/core.clj Mon Apr 07 20:19:02 2014 +0400 2.3 @@ -510,14 +510,14 @@ 2.4 (render! view)) 2.5 (finally 2.6 (.dispose graphics))))) 2.7 - ([view x y] 2.8 - (draw! view x y true)) 2.9 - ([view x y clip?] 2.10 + ([x y view] 2.11 + (draw! x y true view)) 2.12 + ([x y clip? view] 2.13 (let [geom (geometry view)] 2.14 - (draw! view x y (width geom) (height geom) clip?))) 2.15 - ([view x y width height] 2.16 - (draw! view x y width height true)) 2.17 - ([view x y width height clip?] 2.18 + (draw! x y (width geom) (height geom) clip? view))) 2.19 + ([x y width height view] 2.20 + (draw! x y width height true view)) 2.21 + ([x y width height clip? view] 2.22 (if clip? 2.23 (with-bounds* x y width height render! view) 2.24 (with-bounds-noclip* x y width height render! view)))) 2.25 @@ -525,20 +525,20 @@ 2.26 (defn draw-aligned! 2.27 "Draws the View. Location is relative to the view's anchor point 2.28 for the specified alignment." 2.29 - ([view h-align v-align x y] 2.30 + ([h-align v-align x y view] 2.31 (let [geom (geometry view) 2.32 w (width geom) 2.33 h (height geom)] 2.34 - (draw! view 2.35 - (- x (anchor-x geom h-align w)) 2.36 + (draw! (- x (anchor-x geom h-align w)) 2.37 (- y (anchor-y geom v-align h)) 2.38 - w h))) 2.39 - ([view h-align v-align x y w h] 2.40 + w h 2.41 + view))) 2.42 + ([h-align v-align x y w h view] 2.43 (let [geom (geometry view)] 2.44 - (draw! view 2.45 - (- x (anchor-x geom h-align w)) 2.46 + (draw! (- x (anchor-x geom h-align w)) 2.47 (- y (anchor-y geom v-align h)) 2.48 - w h)))) 2.49 + w h 2.50 + view)))) 2.51 2.52 ;; 2.53 ;; Event handling.
3.1 --- a/src/net/kryshen/indyvon/demo.clj Mon Apr 07 15:23:58 2014 +0400 3.2 +++ b/src/net/kryshen/indyvon/demo.clj Mon Apr 07 20:19:02 2014 +0400 3.3 @@ -43,8 +43,8 @@ 3.4 (.fillRect *graphics* shadow-offset shadow-offset width height)) 3.5 (with-color color 3.6 (.fillRect *graphics* offset offset width height)) 3.7 - (draw! (border content border-width padding) 3.8 - offset offset width height)) 3.9 + (draw! offset offset width height 3.10 + (border border-width padding content))) 3.11 ;; Event handlers 3.12 (:mouse-entered _ (repaint)) 3.13 (:mouse-exited _ (repaint)) 3.14 @@ -88,7 +88,7 @@ 3.15 (let [padding 4 3.16 border-width 1 3.17 shadow-offset 2 3.18 - face (border content padding border-width) 3.19 + face (border padding border-width content) 3.20 highlight (atom 0) 3.21 animation-speed (atom 0)] 3.22 (interval-view 3.23 @@ -109,8 +109,8 @@ 3.24 width height)) 3.25 (with-color color 3.26 (.fillRect *graphics* offset offset width height)) 3.27 - (draw! (border content border-width padding) 3.28 - offset offset width height)) 3.29 + (draw! offset offset width height 3.30 + (border border-width padding content))) 3.31 ;; Event handlers 3.32 (:mouse-entered _ 3.33 (reset! animation-speed 4) 3.34 @@ -150,7 +150,7 @@ 3.35 (geometry [view] 3.36 (->Size 30 20)))) 3.37 3.38 -(def test-view1b (border test-view1 2 3)) 3.39 +(def test-view1b (border 2 3 test-view1)) 3.40 3.41 (def test-view2 3.42 (reify 3.43 @@ -160,14 +160,14 @@ 3.44 (.setColor Color/YELLOW) 3.45 (.fillRect 0 0 *width* *height*)) 3.46 (with-rotate 0.5 0 0 3.47 - (draw! test-view1b 30 25)) 3.48 - (draw! test-view1 55 5)) 3.49 + (draw! 30 25 test-view1b)) 3.50 + (draw! 55 5 test-view1)) 3.51 (geometry [view] 3.52 (->Size 70 65)))) 3.53 3.54 -(def test-view2m (miniature test-view2 30 30)) 3.55 +(def test-view2m (miniature 30 30 test-view2)) 3.56 3.57 -(def test-view3 (border (label "Sample\ntext" :right :bottom))) 3.58 +(def test-view3 (border (label :right :bottom "Sample\ntext"))) 3.59 3.60 (def root 3.61 (reify 3.62 @@ -180,16 +180,16 @@ 3.63 ;; Random color to see when repaint happens. 3.64 (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED])) 3.65 (.fillOval 5 5 20 20)) 3.66 - (draw! test-view2 30 20) 3.67 - (draw! test-view2m 120 50) 3.68 - (draw! test-view3 100 100 80 50) 3.69 - (draw! button1 50 160) 3.70 + (draw! 30 20 test-view2) 3.71 + (draw! 120 50 test-view2m) 3.72 + (draw! 100 100 80 50 test-view3) 3.73 + (draw! 50 160 button1) 3.74 (with-rotate (/ Math/PI 6) 250 200 3.75 - (draw! button1 210 140)) 3.76 - (draw! button2 100 200) 3.77 + (draw! 210 140 button1)) 3.78 + (draw! 100 200 button2) 3.79 (with-bounds 180 240 140 30 3.80 (draw-button! :button 3.81 - (label "Immediate button" :center :center) 3.82 + (label :center :center "Immediate button") 3.83 #(println "Button clicked!")))) 3.84 (geometry [view] 3.85 (->Size 400 300)))) 3.86 @@ -198,7 +198,7 @@ 3.87 (def vp (viewport root)) 3.88 3.89 ;; Miniature (rendered asynchronously) 3.90 -(def vp-miniature (-> vp (viewport-miniature 100 75) border shadow)) 3.91 +(def vp-miniature (->> vp (viewport-miniature 100 75) border shadow)) 3.92 3.93 ;; Main scene 3.94 (def scene 3.95 @@ -206,10 +206,10 @@ 3.96 (decorate-view vp [_] 3.97 (draw! vp) 3.98 (draw-aligned! 3.99 + :left :bottom 5 (- *height* 5) 3.100 (label (str "Drag mouse to pan," \newline 3.101 - "use mouse wheel to zoom.")) 3.102 - :left :bottom 5 (- *height* 5)) 3.103 - (draw! vp-miniature (- *width* 105) 5)))) 3.104 + "use mouse wheel to zoom."))) 3.105 + (draw! (- *width* 105) 5 vp-miniature)))) 3.106 3.107 (defn show-frame [view] 3.108 (doto (make-jframe "Test" view) 3.109 @@ -220,4 +220,4 @@ 3.110 (show-frame scene)) 3.111 3.112 (comment 3.113 - (show-frame (viewport-miniature vp 200 150))) 3.114 + (show-frame (viewport-miniature 200 150 vp)))
4.1 --- a/src/net/kryshen/indyvon/viewport.clj Mon Apr 07 15:23:58 2014 +0400 4.2 +++ b/src/net/kryshen/indyvon/viewport.clj Mon Apr 07 20:19:02 2014 +0400 4.3 @@ -91,7 +91,7 @@ 4.4 (binding [*viewport* view 4.5 *viewport-transform* transform] 4.6 (with-transform transform 4.7 - (draw! content 0 0 (width geom) (height geom) false)))) 4.8 + (draw! 0 0 (width geom) (height geom) false content)))) 4.9 (:mouse-pressed e 4.10 (swap! state assoc 4.11 :fix-x (:x-on-screen e) 4.12 @@ -128,8 +128,8 @@ 4.13 (defn viewport 4.14 "Creates scrollable viewport view." 4.15 ([content] 4.16 - (viewport content :left :top)) 4.17 - ([content h-align v-align] 4.18 + (viewport :left :top content)) 4.19 + ([h-align v-align content] 4.20 (->Viewport content h-align v-align (atom viewport-initial-state)))) 4.21 4.22 (defn- scale-viewport [state vp s relative? x y] 4.23 @@ -177,8 +177,9 @@ 4.24 (defn miniature 4.25 "Creates a view that asynchronously renders the content view scaled to 4.26 the specified size." 4.27 - [content mw mh] 4.28 + [mw mh content] 4.29 (async-view 4.30 + mw mh *miniature-thread-priority* 4.31 (reify 4.32 View 4.33 (render! [this] 4.34 @@ -187,18 +188,17 @@ 4.35 ch (height geom) 4.36 s (scaling cw ch mw mh)] 4.37 (.scale *graphics* s s) 4.38 - (draw! content 4.39 - (align-x :center cw (/ mw s)) 4.40 + (draw! (align-x :center cw (/ mw s)) 4.41 (align-y :center ch (/ mh s)) 4.42 - cw ch))) 4.43 + cw ch 4.44 + content))) 4.45 (geometry [_] 4.46 - (->Size mw mh))) 4.47 - mw mh *miniature-thread-priority*)) 4.48 + (->Size mw mh))))) 4.49 4.50 (defn viewport-miniature 4.51 "Creates miniature view of the viewport's contents." 4.52 - [viewport m-width m-height] 4.53 - (let [miniature (miniature (:content viewport) m-width m-height)] 4.54 + [m-width m-height viewport] 4.55 + (let [miniature (miniature m-width m-height (:content viewport))] 4.56 (decorate-view miniature [l] 4.57 (repaint-on-update viewport) 4.58 (let [geom (geometry (:content viewport))
5.1 --- a/src/net/kryshen/indyvon/views.clj Mon Apr 07 15:23:58 2014 +0400 5.2 +++ b/src/net/kryshen/indyvon/views.clj Mon Apr 07 20:19:02 2014 +0400 5.3 @@ -52,31 +52,31 @@ 5.4 5.5 (defn padding 5.6 "Adds padding to the content view." 5.7 - ([content pad] 5.8 - (padding content pad pad pad pad)) 5.9 - ([content top left bottom right] 5.10 + ([distance content] 5.11 + (padding distance distance distance distance content)) 5.12 + ([top left bottom right content] 5.13 (if (== 0 top left bottom right) 5.14 content 5.15 (reify 5.16 View 5.17 (render! [l] 5.18 - (draw! content 5.19 - left top 5.20 + (draw! left top 5.21 (- *width* left right) 5.22 (- *height* top bottom) 5.23 - false)) 5.24 + false 5.25 + content)) 5.26 (geometry [l] 5.27 (->NestedGeometry (geometry content) top left bottom right)))))) 5.28 5.29 (defn border 5.30 "Adds a border to the content view." 5.31 ([content] 5.32 - (border content 1)) 5.33 - ([content thikness] 5.34 - (border content thikness 0)) 5.35 - ([content thikness gap] 5.36 - (let [view (padding content (+ thikness gap)) 5.37 - t (double thikness)] 5.38 + (border 1 content)) 5.39 + ([thickness content] 5.40 + (border thickness 0 content)) 5.41 + ([thickness gap content] 5.42 + (let [view (padding (+ thickness gap) content) 5.43 + t (double thickness)] 5.44 (decorate-view view [_] 5.45 (render! view) 5.46 (with-color :border-color 5.47 @@ -91,8 +91,8 @@ 5.48 (defn shadow 5.49 "Adds a shadow to the content view." 5.50 ([content] 5.51 - (shadow content 1 1)) 5.52 - ([content x-offset y-offset] 5.53 + (shadow 1 1 content)) 5.54 + ([x-offset y-offset content] 5.55 (let [x (if (neg? x-offset) (- x-offset) 0) 5.56 y (if (neg? y-offset) (- y-offset) 0) 5.57 abs-x (if (neg? x-offset) (- x-offset) x-offset) 5.58 @@ -106,7 +106,7 @@ 5.59 h (- *height* abs-y)] 5.60 (with-color :shadow-color 5.61 (.fillRect *graphics* shadow-x shadow-y w h)) 5.62 - (draw! content x y w h))) 5.63 + (draw! x y w h content))) 5.64 (geometry [_] 5.65 (->NestedGeometry (geometry content) 5.66 y x shadow-y shadow-x)))))) 5.67 @@ -134,7 +134,7 @@ 5.68 widths-sum (last xs) 5.69 scale (/ *width* widths-sum)] 5.70 (doseq [[c w x] (map vector contents widths xs)] 5.71 - (draw! c x 0 w *height*)))) 5.72 + (draw! x 0 w *height* c)))) 5.73 (geometry [_] 5.74 (reduce #(->Size (+ (width %1) (width %2)) 5.75 (max (height %1) (height %2))) 5.76 @@ -153,7 +153,7 @@ 5.77 heights-sum (last ys) 5.78 scale (/ *height* heights-sum)] 5.79 (doseq [[c h y] (map vector contents heights ys)] 5.80 - (draw! c 0 y *width* h)))) 5.81 + (draw! 0 y *width* h c)))) 5.82 (geometry [_] 5.83 (reduce #(->Size (max (width %1) (width %2)) 5.84 (+ (height %1) (height %2))) 5.85 @@ -191,8 +191,8 @@ 5.86 (defn label 5.87 "Creates a view to display multiline text." 5.88 ([text] 5.89 - (label text :left :top)) 5.90 - ([text h-align v-align] 5.91 + (label :left :top text)) 5.92 + ([h-align v-align text] 5.93 (let [lines (re-split #"\r\n|\n|\r|\u0085|\u2028|\u2029" (str text))] 5.94 (reify View 5.95 (render! [view] 5.96 @@ -312,7 +312,7 @@ 5.97 (render! content)))))) 5.98 5.99 (defn- fps-label [text] 5.100 - (padding (label text :right :bottom) 5)) 5.101 + (padding 5 (label :right :bottom text))) 5.102 5.103 (defn fps-view 5.104 "Creates a view that draws content and displays the 5.105 @@ -354,36 +354,37 @@ 5.106 p)) 5.107 5.108 (defn- draw-relative! 5.109 - ([view transform x y] 5.110 + ([transform x y view] 5.111 (let [p (to-graphics-coords transform x y)] 5.112 - (draw! view (.getX p) (.getY p)))) 5.113 - ([view transform x y w h] 5.114 + (draw! (.getX p) (.getY p) view))) 5.115 + ([transform x y w h view] 5.116 (let [p (to-graphics-coords transform x y)] 5.117 - (draw! view (.getX p) (.getY p) w h)))) 5.118 + (draw! (.getX p) (.getY p) w h view)))) 5.119 5.120 (defn- draw-relative-aligned! 5.121 - [view transform h-align v-align x y] 5.122 + [transform h-align v-align x y view] 5.123 (let [geom (geometry view) 5.124 w (width geom) 5.125 h (height geom) 5.126 p (to-graphics-coords transform x y) 5.127 x (- (.getX p) (anchor-x geom h-align w)) 5.128 y (- (.getY p) (anchor-y geom v-align h))] 5.129 - (draw! view x y w h))) 5.130 + (draw! x y w h view))) 5.131 5.132 (defn overlay! 5.133 "Draws view in the overlay context above the other views." 5.134 ([view] 5.135 - (overlay* draw-relative! view (.getTransform *graphics*) 0 0)) 5.136 - ([view x y] 5.137 - (overlay* draw-relative! view (.getTransform *graphics*) x y)) 5.138 - ([view x y w h] 5.139 - (overlay* draw-relative! view (.getTransform *graphics*) x y w h))) 5.140 + (overlay* draw-relative! (.getTransform *graphics*) 0 0 view)) 5.141 + ([x y view] 5.142 + (overlay* draw-relative! (.getTransform *graphics*) x y view)) 5.143 + ([x y w h view] 5.144 + (overlay* draw-relative! (.getTransform *graphics*) x y w h view))) 5.145 5.146 -(defn overlay-aligned! [view h-align v-align x y] 5.147 +(defn overlay-aligned! [h-align v-align x y view] 5.148 (overlay* draw-relative-aligned! 5.149 - view (.getTransform *graphics*) 5.150 - h-align v-align x y)) 5.151 + (.getTransform *graphics*) 5.152 + h-align v-align x y 5.153 + view)) 5.154 5.155 (defn with-overlays* [rec? f & args] 5.156 (binding [*above* []] 5.157 @@ -403,7 +404,7 @@ 5.158 5.159 (defn layered 5.160 ([content] 5.161 - (layered content true)) 5.162 - ([content rec?] 5.163 + (layered true content)) 5.164 + ([rec? content] 5.165 (decorate-view content [_] 5.166 (with-overlays* rec? render! content))))