An instance pivots about the middle of what its symbol draws
place-symbol sets a new instance's anchor to clip/center — the middle of the bounds of everything the symbol draws over all its frames, or the stage's middle for a symbol that draws nothing — and a stage drop puts that middle under the pointer. The anchor is set once and never follows the symbol, as Flash's transformation point and After Effects' anchor point do, so a symbol that grows later moves nothing on screen. The drop preview marks the pivot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
41b4bdf110
commit
1a42481575
7 changed files with 145 additions and 87 deletions
|
|
@ -212,7 +212,7 @@
|
|||
(assoc-in [:symbols :outer] {:id :outer :frames 200 :nodes {}})
|
||||
(assoc-in [:symbols :inner] {:id :inner :frames 10 :nodes {}})
|
||||
(assoc-in [:symbols :loose] {:id :loose :frames 30 :nodes {}})
|
||||
(clip/place-symbol :outer :inner 5 (random-uuid) [0 0])))
|
||||
(clip/place-symbol nil :outer :inner 5 (random-uuid) nil)))
|
||||
|
||||
(deftest no-symbol-is-special
|
||||
(let [c (nested)]
|
||||
|
|
@ -228,9 +228,9 @@
|
|||
(testing "placing is refused when it would make a cycle"
|
||||
(is (clip/contains-symbol? c :outer :inner))
|
||||
(is (not (clip/contains-symbol? c :inner :outer)))
|
||||
(is (= c (clip/place-symbol c :inner :outer 0 (random-uuid) [0 0]))
|
||||
(is (= c (clip/place-symbol c nil :inner :outer 0 (random-uuid) nil))
|
||||
"outer inside inner, which is inside outer")
|
||||
(is (= c (clip/place-symbol c :inner :inner 0 (random-uuid) [0 0]))
|
||||
(is (= c (clip/place-symbol c nil :inner :inner 0 (random-uuid) nil))
|
||||
"a symbol inside itself"))
|
||||
(testing "and the result is a valid document whose instance saves"
|
||||
(is (empty? (clip/problems c)))
|
||||
|
|
@ -275,7 +275,7 @@
|
|||
(let [here (nested)
|
||||
there (-> (clip/blank)
|
||||
(assoc-in [:symbols :inner] {:id :inner :frames 4 :nodes {}})
|
||||
(clip/place-symbol :main :inner 0 #uuid "00000000-0000-4000-8000-0000000000aa" [0 0]))
|
||||
(clip/place-symbol nil :main :inner 0 #uuid "00000000-0000-4000-8000-0000000000aa" nil))
|
||||
{:keys [clip ids]} (clip/adopt here there [:main] {:main :take})]
|
||||
(is (= {:main :take :inner :inner-2} ids)
|
||||
"the root gets the name asked for; a taken id gets the next free one")
|
||||
|
|
@ -290,7 +290,7 @@
|
|||
:channels {[:audio :gain] (ch/keyed {0 0.0 5 1.0})}}
|
||||
c (-> (clip/blank)
|
||||
(assoc-in [:symbols :talk] {:id :talk :frames 30 :nodes {:v voice}})
|
||||
(clip/place-symbol :main :talk 50 #uuid "00000000-0000-4000-8000-0000000000bb" [0 0]))
|
||||
(clip/place-symbol nil :main :talk 50 #uuid "00000000-0000-4000-8000-0000000000bb" nil))
|
||||
[t] (clip/audio-tracks c :main)]
|
||||
(is (= [10 40] (:span t)) "the same frames of the source")
|
||||
(is (= [50 80] (node/placed-span t)) "starting where the instance starts")
|
||||
|
|
@ -301,3 +301,28 @@
|
|||
[t] (clip/audio-tracks c :main)]
|
||||
(is (= [10 22] (:span t)))
|
||||
(is (= [50 62] (node/placed-span t)))))))
|
||||
|
||||
(deftest an-instance-pivots-about-the-middle-of-what-it-draws
|
||||
(let [square (fn [x y] {:kind :poly :z "a1" :id :sq
|
||||
:channels {[:geom :pts] (ch/framed [x y (+ x 10) y (+ x 10) (+ y 10) x (+ y 10)])
|
||||
[:style :color] (ch/framed :brow)}})
|
||||
c (-> (clip/blank)
|
||||
(assoc-in [:symbols :box] {:id :box :frames 4 :nodes {:sq (assoc (square 20 30) :id :sq)}})
|
||||
(assoc-in [:symbols :empty] {:id :empty :frames 4 :nodes {}}))
|
||||
u #uuid "00000000-0000-4000-8000-0000000000cc"
|
||||
placed (fn [c sid point] (get-in (clip/place-symbol c nil :main sid 0 u point)
|
||||
[:symbols :main :nodes u :channels]))]
|
||||
(is (= [25 35] (clip/center c nil :box)) "the middle of the square")
|
||||
(is (= [160 100] (clip/center c nil :empty)) "nothing drawn: the stage's middle")
|
||||
(testing "the anchor is the middle, and it moves nothing at the identity"
|
||||
(is (= [25 35] (get-in (placed c :box nil) [[:xform :anchor] :value])))
|
||||
(is (= [0 0] (get-in (placed c :box nil) [[:xform :pos] :value]))
|
||||
"dropped on the timeline: where it was drawn"))
|
||||
(testing "dropped on a stage pixel, its middle goes there"
|
||||
(is (= [75 65] (get-in (placed c :box [100 100]) [[:xform :pos] :value]))))
|
||||
(testing "and growing the symbol later does not move an instance's pivot"
|
||||
(let [c (clip/place-symbol c nil :main :box 0 u nil)
|
||||
grown (assoc-in c [:symbols :box :nodes :sq2] (assoc (square 80 30) :id :sq2 :z "a2"))]
|
||||
(is (= [55 35] (clip/center grown nil :box)) "the symbol's middle moved")
|
||||
(is (= [25 35] (get-in grown [:symbols :main :nodes u :channels [:xform :anchor] :value]))
|
||||
"the instance's did not")))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue