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 wrap: on
line diff
--- a/src/net/kryshen/indyvon/async.clj	Mon Apr 07 15:23:58 2014 +0400
+++ b/src/net/kryshen/indyvon/async.clj	Mon Apr 07 20:19:02 2014 +0400
@@ -167,9 +167,9 @@
 (defn async-view 
   "Creates a View that draws the content asynchronously using an
    offscreen buffer."
-  ([content width height]
-     (async-view content width height nil))
-  ([content width height priority]
+  ([width height content]
+     (async-view width height nil content))
+  ([width height priority content]
      ;; TODO: use operational event dispatcher.
      (->AsyncView (make-scene content)
                   width
--- a/src/net/kryshen/indyvon/core.clj	Mon Apr 07 15:23:58 2014 +0400
+++ b/src/net/kryshen/indyvon/core.clj	Mon Apr 07 20:19:02 2014 +0400
@@ -510,14 +510,14 @@
            (render! view))
          (finally
           (.dispose graphics)))))
-  ([view x y]
-     (draw! view x y true))
-  ([view x y clip?]
+  ([x y view]
+     (draw! x y true view))
+  ([x y clip? view]
      (let [geom (geometry 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?]
+       (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]
      (if clip?
        (with-bounds* x y width height render! view)
        (with-bounds-noclip* x y width height render! view))))
@@ -525,20 +525,20 @@
 (defn draw-aligned!
   "Draws the View.  Location is relative to the view's anchor point
    for the specified alignment."
-  ([view h-align v-align x y]
+  ([h-align v-align x y view]
      (let [geom (geometry view)
            w (width geom)
            h (height geom)]
-       (draw! view
-              (- x (anchor-x geom h-align w))
+       (draw! (- 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]
+              w h
+              view)))
+  ([h-align v-align x y w h view]
      (let [geom (geometry view)]
-       (draw! view
-              (- x (anchor-x geom h-align w))
+       (draw! (- x (anchor-x geom h-align w))
               (- y (anchor-y geom v-align h))
-              w h))))
+              w h
+              view))))
 
 ;;
 ;; Event handling.
--- a/src/net/kryshen/indyvon/demo.clj	Mon Apr 07 15:23:58 2014 +0400
+++ b/src/net/kryshen/indyvon/demo.clj	Mon Apr 07 20:19:02 2014 +0400
@@ -43,8 +43,8 @@
         (.fillRect *graphics* shadow-offset shadow-offset width height))
       (with-color color
         (.fillRect *graphics* offset offset width height))
-      (draw! (border content border-width padding)
-             offset offset width height))
+      (draw! offset offset width height
+             (border border-width padding content)))
     ;; Event handlers
     (:mouse-entered _ (repaint))
     (:mouse-exited _ (repaint))
@@ -88,7 +88,7 @@
   (let [padding 4
         border-width 1
         shadow-offset 2
-        face (border content padding border-width)
+        face (border padding border-width content)
         highlight (atom 0)
         animation-speed (atom 0)]
     (interval-view
@@ -109,8 +109,8 @@
                          width height))
             (with-color color
               (.fillRect *graphics* offset offset width height))
-            (draw! (border content border-width padding)
-                   offset offset width height))
+            (draw! offset offset width height
+                   (border border-width padding content)))
           ;; Event handlers
           (:mouse-entered _
             (reset! animation-speed 4)
@@ -150,7 +150,7 @@
    (geometry [view]
      (->Size 30 20))))
 
-(def test-view1b (border test-view1 2 3))
+(def test-view1b (border 2 3 test-view1))
 
 (def test-view2
   (reify
@@ -160,14 +160,14 @@
        (.setColor Color/YELLOW)
        (.fillRect 0 0 *width* *height*))
      (with-rotate 0.5 0 0
-       (draw! test-view1b 30 25))
-     (draw! test-view1 55 5))
+       (draw! 30 25 test-view1b))
+     (draw! 55 5 test-view1))
    (geometry [view]
      (->Size 70 65))))
 
-(def test-view2m (miniature test-view2 30 30))
+(def test-view2m (miniature 30 30 test-view2))
 
-(def test-view3 (border (label "Sample\ntext" :right :bottom)))
+(def test-view3 (border (label :right :bottom "Sample\ntext")))
 
 (def root
   (reify
@@ -180,16 +180,16 @@
        ;; Random color to see when repaint happens.
        (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED]))
        (.fillOval 5 5 20 20))
-     (draw! test-view2 30 20)
-     (draw! test-view2m 120 50)
-     (draw! test-view3 100 100 80 50)
-     (draw! button1 50 160)
+     (draw! 30 20 test-view2)
+     (draw! 120 50 test-view2m)
+     (draw! 100 100 80 50 test-view3)
+     (draw! 50 160 button1)
      (with-rotate (/ Math/PI 6) 250 200
-       (draw! button1 210 140))
-     (draw! button2 100 200)
+       (draw! 210 140 button1))
+     (draw! 100 200 button2)
      (with-bounds 180 240 140 30
        (draw-button! :button
-        (label "Immediate button" :center :center)
+        (label :center :center "Immediate button")
         #(println "Button clicked!"))))
    (geometry [view]
      (->Size 400 300))))
@@ -198,7 +198,7 @@
 (def vp (viewport root))
 
 ;; Miniature (rendered asynchronously)
-(def vp-miniature (-> vp (viewport-miniature 100 75) border shadow))
+(def vp-miniature (->> vp (viewport-miniature 100 75) border shadow))
 
 ;; Main scene
 (def scene
@@ -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."))
-      :left :bottom 5 (- *height* 5))
-     (draw! vp-miniature (- *width* 105) 5))))
+                  "use mouse wheel to zoom.")))
+     (draw! (- *width* 105) 5 vp-miniature))))
 
 (defn show-frame [view]
   (doto (make-jframe "Test" view)
@@ -220,4 +220,4 @@
   (show-frame scene))
 
 (comment
-  (show-frame (viewport-miniature vp 200 150)))
+  (show-frame (viewport-miniature 200 150 vp)))
--- a/src/net/kryshen/indyvon/viewport.clj	Mon Apr 07 15:23:58 2014 +0400
+++ b/src/net/kryshen/indyvon/viewport.clj	Mon Apr 07 20:19:02 2014 +0400
@@ -91,7 +91,7 @@
         (binding [*viewport* view
                   *viewport-transform* transform]
           (with-transform transform
-            (draw! content 0 0 (width geom) (height geom) false))))
+            (draw! 0 0 (width geom) (height geom) false content))))
       (:mouse-pressed e
        (swap! state assoc
               :fix-x (:x-on-screen e)
@@ -128,8 +128,8 @@
 (defn viewport
   "Creates scrollable viewport view."
   ([content]
-     (viewport content :left :top))
-  ([content h-align v-align]
+     (viewport :left :top content))
+  ([h-align v-align content]
      (->Viewport content h-align v-align (atom viewport-initial-state))))
 
 (defn- scale-viewport [state vp s relative? x y]
@@ -177,8 +177,9 @@
 (defn miniature
   "Creates a view that asynchronously renders the content view scaled to
   the specified size."
-  [content mw mh]
+  [mw mh content]
   (async-view
+   mw mh *miniature-thread-priority*
    (reify
     View
     (render! [this]
@@ -187,18 +188,17 @@
             ch (height geom)
             s (scaling cw ch mw mh)]
         (.scale *graphics* s s)
-        (draw! content
-               (align-x :center cw (/ mw s))
+        (draw! (align-x :center cw (/ mw s))
                (align-y :center ch (/ mh s))
-               cw ch)))
+               cw ch
+               content)))
     (geometry [_]
-      (->Size mw mh)))
-   mw mh *miniature-thread-priority*))
+      (->Size mw mh)))))
 
 (defn viewport-miniature
   "Creates miniature view of the viewport's contents."
-  [viewport m-width m-height]
-  (let [miniature (miniature (:content viewport) m-width m-height)]
+  [m-width m-height viewport]
+  (let [miniature (miniature m-width m-height (:content viewport))]
     (decorate-view miniature [l]
       (repaint-on-update viewport)
       (let [geom (geometry (:content viewport))
--- a/src/net/kryshen/indyvon/views.clj	Mon Apr 07 15:23:58 2014 +0400
+++ b/src/net/kryshen/indyvon/views.clj	Mon Apr 07 20:19:02 2014 +0400
@@ -52,31 +52,31 @@
 
 (defn padding
   "Adds padding to the content view."
-  ([content pad]
-     (padding content pad pad pad pad))
-  ([content top left bottom right]
+  ([distance content]
+     (padding distance distance distance distance content))
+  ([top left bottom right content]
      (if (== 0 top left bottom right)
        content
        (reify
         View
         (render! [l]
-           (draw! content
-                  left top
+           (draw! left top
                   (- *width* left right)
                   (- *height* top bottom)
-                  false))
+                  false
+                  content))
         (geometry [l]
           (->NestedGeometry (geometry content) top left bottom right))))))
 
 (defn border
   "Adds a border to the content view."
   ([content]
-     (border content 1))
-  ([content thikness]
-     (border content thikness 0))
-  ([content thikness gap]
-     (let [view (padding content (+ thikness gap))
-           t (double thikness)]
+     (border 1 content))
+  ([thickness content]
+     (border thickness 0 content))
+  ([thickness gap content]
+     (let [view (padding (+ thickness gap) content)
+           t (double thickness)]
        (decorate-view view [_]
          (render! view)
          (with-color :border-color
@@ -91,8 +91,8 @@
 (defn shadow
   "Adds a shadow to the content view."
   ([content]
-     (shadow content 1 1))
-  ([content x-offset y-offset]
+     (shadow 1 1 content))
+  ([x-offset y-offset content]
      (let [x (if (neg? x-offset) (- x-offset) 0)
            y (if (neg? y-offset) (- y-offset) 0)
            abs-x (if (neg? x-offset) (- x-offset) x-offset)
@@ -106,7 +106,7 @@
                 h (- *height* abs-y)]
             (with-color :shadow-color
               (.fillRect *graphics* shadow-x shadow-y w h))
-            (draw! content x y w h)))
+            (draw! x y w h content)))
         (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! c x 0 w *height*))))
+         (draw! x 0 w *height* c))))
    (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! c 0 y *width* h))))
+         (draw! 0 y *width* h c))))
    (geometry [_]
      (reduce #(->Size (max (width %1) (width %2))
                       (+ (height %1) (height %2)))
@@ -191,8 +191,8 @@
 (defn label
   "Creates a view to display multiline text."
   ([text]
-     (label text :left :top))
-  ([text h-align v-align]
+     (label :left :top text))
+  ([h-align v-align text]
      (let [lines (re-split #"\r\n|\n|\r|\u0085|\u2028|\u2029" (str text))]
        (reify View
         (render! [view]
@@ -312,7 +312,7 @@
           (render! content))))))
 
 (defn- fps-label [text]
-  (padding (label text :right :bottom) 5))
+  (padding 5 (label :right :bottom text)))
 
 (defn fps-view
   "Creates a view that draws content and displays the
@@ -354,36 +354,37 @@
     p))
 
 (defn- draw-relative!
-  ([view transform x y]
+  ([transform x y view]
      (let [p (to-graphics-coords transform x y)]
-       (draw! view (.getX p) (.getY p))))
-  ([view transform x y w h]
+       (draw! (.getX p) (.getY p) view)))
+  ([transform x y w h view]
      (let [p (to-graphics-coords transform x y)]
-       (draw! view (.getX p) (.getY p) w h))))
+       (draw! (.getX p) (.getY p) w h view))))
 
 (defn- draw-relative-aligned!
-  [view transform h-align v-align x y]
+  [transform h-align v-align x y view]
   (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! view x y w h)))
+    (draw! x y w h view)))
 
 (defn overlay!
   "Draws view in the overlay context above the other views."
   ([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)))
+     (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)))
 
-(defn overlay-aligned! [view h-align v-align x y]
+(defn overlay-aligned! [h-align v-align x y view]
   (overlay* draw-relative-aligned!
-            view (.getTransform *graphics*)
-            h-align v-align x y))
+            (.getTransform *graphics*)
+            h-align v-align x y
+            view))
 
 (defn with-overlays* [rec? f & args]
   (binding [*above* []]
@@ -403,7 +404,7 @@
 
 (defn layered
   ([content]
-     (layered content true))
-  ([content rec?]
+     (layered true content))
+  ([rec? content]
      (decorate-view content [_]
        (with-overlays* rec? render! content))))