Changeset - b48b0d9812cf
[Not reviewed]
default
0 2 0
Drew Perttula - 8 years ago 2017-06-10 10:24:53
drewp@bigasterisk.com
pass ctx to more handlers to show that they need it
Ignore-this: 6cede95405430f375b1e068e44a604d
2 files changed with 21 insertions and 20 deletions:
0 comments (0 inline, 0 general)
light9/web/timeline/adjustable.coffee
Show inline comments
 
@@ -130,16 +130,17 @@ class window.AdjustableFloatObject exten
 
    
 
    @config.graph.patchObject(@config.subj, @config.pred,
 
                              @config.graph.LiteralRoundedFloat(newValue),
 
                              @config.ctx)
 
                              
 
class window.AdjustableFade extends Adjustable
 
  constructor: (@yForV, @i0, @i1, @note, offset) ->
 
  constructor: (@yForV, @i0, @i1, @note, offset, ctx) ->
 
    @config = {
 
      getSuggestedTargetOffset: -> offset
 
      getTarget: @getTarget.bind(@)
 
      ctx: ctx
 
    }
 
    super(@config)
 

	
 
  getTarget: ->
 
    mid = @note.worldPts[@i0].x(.5).add(@note.worldPts[@i1].x(.5))
 
    $V([@note.zoomInX(mid.e(1)), @yForV(mid.e(2))])
 
@@ -159,15 +160,14 @@ class window.AdjustableFade extends Adju
 
    diamSec = @note.worldPts[@i1].e(1) - @note.worldPts[@i0].e(1)
 
    newSec0 = goalCenterSec - diamSec / 2
 
    newSec1 = goalCenterSec + diamSec / 2
 

	
 
    originSec = graph.floatValue(@note.uri, U(':originTime'))
 

	
 
    ctx = @note.song
 
    p0 = @_makePatch(graph, @i0, newSec0, originSec, ctx)
 
    p1 = @_makePatch(graph, @i1, newSec1, originSec, ctx)
 
    p0 = @_makePatch(graph, @i0, newSec0, originSec, @config.ctx)
 
    p1 = @_makePatch(graph, @i1, newSec1, originSec, @config.ctx)
 

	
 
    graph.applyAndSendPatch(@_addPatches(p0, p1))
 

	
 
  _makePatch: (graph, idx, newSec, originSec, ctx) ->
 
    graph.getObjectPatch(@note.worldPts[idx].uri,
 
                         graph.Uri(':time'),
light9/web/timeline/timeline.coffee
Show inline comments
 
@@ -440,15 +440,16 @@ Polymer
 
    selection: { type: Object, notify: true }
 
    dia: { type: Object, notify: true }
 
    uri: { type: String, notify: true }
 
    zoomInX: { type: Object, notify: true }
 
    setAdjuster: {type: Function, notify: true }
 
    inlineRect: { type: Object, notify: true }
 
    song: { type: String, notify: true }
 
  observers: [
 
    'onUri(graph, dia, uri, zoomInX, setAdjuster)'
 
    'update(graph, dia, uri, zoomInX, setAdjuster)'
 
    'onUri(graph, dia, uri, zoomInX, setAdjuster, song)'
 
    'update(graph, dia, uri, zoomInX, setAdjuster, song)'
 
    ]
 
  ready: ->
 
    @adjusterIds = {} # id : true
 

	
 
  detached: ->
 
    log('detatch', @uri)
 
@@ -502,22 +503,22 @@ Polymer
 
        [@pointUris, @worldPts] = @_getCurvePoints(curve, originTime)
 
        curveWidthCalc = () => @_curveWidth(@worldPts)
 
    
 
        screenPts = ($V([@zoomInX(pt.e(1)), @offsetTop + (1 - pt.e(2)) * @offsetHeight]) for pt in @worldPts)
 
    
 
        @dia.setNote(@uri, screenPts, effect)
 
        @_updateAdjusters(screenPts, curveWidthCalc, yForV)
 
        @_updateAdjusters(screenPts, curveWidthCalc, yForV, U(@song))
 
        @_updateInlineAttrs(screenPts)
 
        
 
  _updateAdjusters: (screenPts, curveWidthCalc, yForV) ->   
 
  _updateAdjusters: (screenPts, curveWidthCalc, yForV, ctx) ->   
 
    if screenPts[screenPts.length - 1].e(1) - screenPts[0].e(1) < 100
 
      @clearAdjusters()
 
    else
 
      @_makeOffsetAdjuster(yForV, curveWidthCalc)
 
      @_makeCurvePointAdjusters(yForV, @worldPts)
 
      @_makeFadeAdjusters(yForV)
 
      @_makeOffsetAdjuster(yForV, curveWidthCalc, ctx)
 
      @_makeCurvePointAdjusters(yForV, @worldPts, ctx)
 
      @_makeFadeAdjusters(yForV, ctx)
 

	
 
  _updateInlineAttrs: (screenPts) ->
 
    leftX = Math.max(2, screenPts[Math.min(1, screenPts.length - 1)].e(1) + 5)
 
    rightX = screenPts[Math.min(2, screenPts.length - 1)].e(1) - 5
 
    if screenPts.length < 3
 
      rightX = leftX + 120
 
@@ -552,23 +553,23 @@ Polymer
 
    tMax - tMin
 
    
 
  _makeCurvePointAdjusters: (yForV, worldPts) ->
 
    for pointNum in [0...worldPts.length]
 
      @_makePointAdjuster(yForV, worldPts, pointNum)
 

	
 
  _makePointAdjuster: (yForV, worldPts, pointNum) ->
 
  _makePointAdjuster: (yForV, worldPts, pointNum, ctx) ->
 
    U = (x) => @graph.Uri(x)
 

	
 
    adjId = @uri + '/p' + pointNum
 
    @adjusterIds[adjId] = true
 
    @setAdjuster adjId, =>
 
      adj = new AdjustableFloatObject({
 
        graph: @graph
 
        subj: worldPts[pointNum].uri
 
        pred: U(':time')
 
        ctx: U(@song)
 
        ctx: ctx
 
        getTargetPosForValue: (value) =>
 
          $V([@zoomInX(value), yForV(worldPts[pointNum].e(2))])
 
        getValueForPos: (pos) =>
 
          origin = @graph.floatValue(@uri, U(':originTime'))
 
          (@zoomInX.invert(pos.e(1)) - origin)
 
        getSuggestedTargetOffset: () => @_suggestedOffset(worldPts[pointNum]),
 
@@ -577,41 +578,41 @@ Polymer
 
        # note: don't use originTime from the closure- we need the
 
        # graph dependency
 
        adj._currentValue + @graph.floatValue(@uri, U(':originTime'))
 
        )
 
      adj
 

	
 
  _makeOffsetAdjuster: (yForV, curveWidthCalc) ->
 
  _makeOffsetAdjuster: (yForV, curveWidthCalc, ctx) ->
 
    U = (x) => @graph.Uri(x)
 

	
 
    adjId = @uri + '/offset'
 
    @adjusterIds[adjId] = true
 
    @setAdjuster adjId, => 
 
      adj = new AdjustableFloatObject({
 
        graph: @graph
 
        subj: @uri
 
        pred: U(':originTime')
 
        ctx: U(@song)
 
        ctx: ctx
 
        getDisplayValue: (v, dv) => "o=#{dv}"
 
        getTargetPosForValue: (value) =>
 
          # display bug: should be working from pt[0].t, not from origin
 
          $V([@zoomInX(value + curveWidthCalc() / 2), yForV(.5)])
 
        getValueForPos: (pos) =>
 
          @zoomInX.invert(pos.e(1)) - curveWidthCalc() / 2
 
        getSuggestedTargetOffset: () => $V([-10, 0])
 
      })
 
      adj
 

	
 
  _makeFadeAdjusters: (yForV) ->
 
    @_makeFadeAdjuster(yForV, @uri + '/fadeIn', 0, 1, $V([-50, -10]))
 
  _makeFadeAdjusters: (yForV, ctx) ->
 
    @_makeFadeAdjuster(yForV, ctx, @uri + '/fadeIn', 0, 1, $V([-50, -10]))
 
    n = @worldPts.length
 
    @_makeFadeAdjuster(yForV, @uri + '/fadeOut', n - 2, n - 1, $V([50, -10]))
 
    @_makeFadeAdjuster(yForV, ctx, @uri + '/fadeOut', n - 2, n - 1, $V([50, -10]))
 

	
 
  _makeFadeAdjuster: (yForV, adjId, i0, i1, offset) ->
 
  _makeFadeAdjuster: (yForV, ctx, adjId, i0, i1, offset) ->
 
    @adjusterIds[adjId] = true
 
    @setAdjuster adjId, => new AdjustableFade(yForV, i0, i1, @, offset)
 
    @setAdjuster adjId, => new AdjustableFade(yForV, i0, i1, @, offset, ctx)
 
    
 
  _suggestedOffset: (pt) ->
 
    if pt.e(2) > .5
 
      $V([0, 30])
 
    else
 
      $V([0, -30])
0 comments (0 inline, 0 general)