diff --git a/light9/web/adjustable.coffee b/light9/web/adjustable.coffee --- a/light9/web/adjustable.coffee +++ b/light9/web/adjustable.coffee @@ -45,6 +45,22 @@ class Adjustable endDrag: () -> 0 + _editorCoordinates: () -> # vec2 of mouse relative to + ev = d3.event.sourceEvent + + if ev.target.tagName == "LIGHT9-TIMELINE-EDITOR" + rootElem = ev.target + else + rootElem = ev.target.closest('light9-timeline-editor') + + # storing root on the object to remember it across calls in case + # you drag outside the editor. + @root = rootElem.getBoundingClientRect() if rootElem + offsetParentPos = $V([ev.pageX - @root.left, ev.pageY - @root.top]) + + setMouse(offsetParentPos) # for debugging + return offsetParentPos + class window.AdjustableFloatObservable extends Adjustable constructor: (@config) -> # config also has: @@ -54,27 +70,11 @@ class window.AdjustableFloatObservable e _getValue: () -> @config.observable() - - _editorCoordinates: () -> # vec2 of mouse relative to - ev = d3.event.sourceEvent - - if ev.target.tagName == "LIGHT9-TIMELINE-EDITOR" - rootElem = ev.target - else - rootElem = ev.target.closest('light9-timeline-editor') - - @root = rootElem.getBoundingClientRect() if rootElem - offsetParentPos = $V([ev.pageX - @root.left, ev.pageY - @root.top]) - - setMouse(offsetParentPos) - return offsetParentPos continueDrag: (pos) -> # pos is vec2 of pixels relative to the drag start. epos = @_editorCoordinates() - log('offsetParentPos', epos.elements) - newValue = @config.getValueForPos(epos) @config.observable(newValue) @@ -85,15 +85,22 @@ class window.AdjustableFloatObservable e class window.AdjustableFloatObject extends Adjustable constructor: (@config) -> - # config has graph, subj, pred, ctx, getSuggestedTargetOffset + # config also has: + # graph + # subj + # pred + # ctx + # getTargetTransform(value) -> getTarget result for value + # getValueForPos + super(@config) - _getValue: () -> # for drag math + _getValue: () -> @config.graph.floatValue(@config.subj, @config.pred) - getCenter: () -> - $V([100 + 200 * @_getValue(), 200]) - + getTarget: () -> + @config.getTargetTransform(@_getValue()) + subscribe: (onChange) -> @config.graph.subscribe @config.subj, @config.pred, null, (patch) => onChange() @@ -101,5 +108,5 @@ class window.AdjustableFloatObject exten continueDrag: (pos) -> # pos is vec2 of pixels relative to the drag start - newValue = @dragStartValue + pos.e(1) / 200 + newValue = @config.getValueForPos(@_editorCoordinates()) @config.graph.patchObject(@config.subj, @config.pred, @config.graph.Literal(newValue), @_ctx) diff --git a/light9/web/graph.coffee b/light9/web/graph.coffee --- a/light9/web/graph.coffee +++ b/light9/web/graph.coffee @@ -65,9 +65,9 @@ class window.SyncedGraph applyAndSendPatch: (patch, cb) -> @applyPatch(patch) - #console.log('patch to server:') - #console.log(' delete:', JSON.stringify(patch.delQuads)) - #console.log(' add:', JSON.stringify(patch.addQuads)) + console.log('patch to server:') + console.log(' delete:', JSON.stringify(patch.delQuads)) + console.log(' add:', JSON.stringify(patch.addQuads)) # post to server applyPatch: (patch) -> diff --git a/light9/web/timeline-elements.html b/light9/web/timeline-elements.html --- a/light9/web/timeline-elements.html +++ b/light9/web/timeline-elements.html @@ -2,6 +2,42 @@ + + + + + + @@ -14,6 +50,7 @@ flex-direction: column; position: relative; border: 1px solid black; + overflow: hidden; } light9-timeline-audio { width: 100%; @@ -33,6 +70,9 @@ }
+ + + timeline editor: song [uri]
@@ -251,16 +291,6 @@ -