annotate web/timeline/TimelineEditor.coffee @ 2376:4556eebe5d73

topdir reorgs; let pdm have its src/ dir; separate vite area from light9/
author drewp@bigasterisk.com
date Sun, 12 May 2024 19:02:10 -0700
parents light9/web/timeline/TimelineEditor.coffee@611c3e97de2f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2062
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
1 log = debug('timeline')
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
2 debug.enable('*')
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
3
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
4 Drawing = window.Drawing
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
5 ROW_COUNT = 7
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
6
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
7
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
8 @customElement('light9-timeline-editor')
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
9 class TimelineEditor extends LitElement
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
10 @getter_properties:
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
11 viewState: { type: Object }
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
12 debug: {type: String}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
13 graph: {type: Object, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
14 project: {type: Object}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
15 setAdjuster: {type: Function, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
16 playerSong: {type: String, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
17 followPlayerSong: {type: Boolean, notify: true, value: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
18 song: {type: String, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
19 show: {type: String, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
20 songTime: {type: Number, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
21 songDuration: {type: Number, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
22 songPlaying: {type: Boolean, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
23 selection: {type: Object, notify: true}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
24 @getter_observers: [
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
25 '_onSong(playerSong, followPlayerSong)',
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
26 '_onGraph(graph)',
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
27 '_onSongDuration(songDuration, viewState)',
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
28 '_onSongTime(song, playerSong, songTime, viewState)',
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
29 '_onSetAdjuster(setAdjuster)',
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
30 ]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
31 constructor: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
32 super()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
33 @viewState = new ViewState()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
34 window.viewState = @viewState
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
35
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
36 ready: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
37 super.ready()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
38 @addEventListener 'mousedown', (ev) => @$.adjustersCanvas.onDown(ev)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
39 @addEventListener 'mousemove', (ev) => @$.adjustersCanvas.onMove(ev)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
40 @addEventListener 'mouseup', (ev) => @$.adjustersCanvas.onUp(ev)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
41
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
42 ko.options.deferUpdates = true
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
43
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
44 @selection = {hover: ko.observable(null), selected: ko.observable([])}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
45
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
46 window.debug_zoomOrLayoutChangedCount = 0
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
47 window.debug_adjUpdateDisplay = 0
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
48
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
49 ko.computed(@zoomOrLayoutChanged.bind(@))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
50
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
51 @trackMouse()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
52 @bindKeys()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
53 @bindWheelZoom(@)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
54
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
55 setInterval(@updateDebugSummary.bind(@), 100)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
56
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
57 @addEventListener('iron-resize', @_onIronResize.bind(@))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
58 Polymer.RenderStatus.afterNextRender(this, @_onIronResize.bind(@))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
59
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
60 Polymer.RenderStatus.afterNextRender this, =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
61 setupDrop(@$.zoomed.$.rows, @$.zoomed.$.rows, @, @$.zoomed.onDrop.bind(@$.zoomed))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
62
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
63 _onIronResize: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
64 @viewState.setWidth(@offsetWidth)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
65 @viewState.coveredByDiagramTop(@$.coveredByDiagram.offsetTop)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
66 @viewState.rowsY(@$.zoomed.$.rows.offsetTop) if @$.zoomed?.$?.rows?
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
67 @viewState.audioY(@$.audio.offsetTop)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
68 @viewState.audioH(@$.audio.offsetHeight)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
69 if @$.zoomed?.$?.time?
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
70 @viewState.zoomedTimeY(@$.zoomed.$.time.offsetTop)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
71 @viewState.zoomedTimeH(@$.zoomed.$.time.offsetHeight)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
72
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
73 _onSongTime: (song, playerSong, t) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
74 if song != playerSong
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
75 @viewState.cursor.t(0)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
76 return
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
77 @viewState.cursor.t(t)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
78
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
79 _onSongDuration: (d) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
80 d = 700 if d < 1 # bug is that asco isn't giving duration, but 0 makes the scale corrupt
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
81 @viewState.zoomSpec.duration(d)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
82
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
83 _onSong: (s) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
84 @song = @playerSong if @followPlayerSong
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
85
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
86 _onGraph: (graph) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
87 @project = new Project(graph)
2160
611c3e97de2f factor out the show-specific strs
drewp@bigasterisk.com
parents: 2062
diff changeset
88 @show = showRoot
2062
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
89
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
90 _onSetAdjuster: () ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
91 @makeZoomAdjs()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
92
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
93 updateDebugSummary: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
94 elemCount = (tag) -> document.getElementsByTagName(tag).length
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
95 @debug = "#{window.debug_zoomOrLayoutChangedCount} layout change,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
96 #{elemCount('light9-timeline-note')} notes,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
97 #{@selection.selected().length} selected
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
98 #{elemCount('light9-timeline-graph-row')} rows,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
99 #{window.debug_adjsCount} adjuster items registered,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
100 #{window.debug_adjUpdateDisplay} adjuster updateDisplay calls,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
101 "
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
102
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
103 zoomOrLayoutChanged: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
104 vs = @viewState
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
105 dependOn = [vs.zoomSpec.t1(), vs.zoomSpec.t2(), vs.width()]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
106
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
107 # shouldn't need this- deps should get it
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
108 @$.zoomed.gatherNotes() if @$.zoomed?.gatherNotes?
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
109
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
110 # todo: these run a lot of work purely for a time change
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
111 if @$.zoomed?.$?.audio?
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
112 #@dia.setTimeAxis(vs.width(), @$.zoomed.$.audio.offsetTop, vs.zoomInX)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
113 @$.adjustersCanvas.updateAllCoords()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
114
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
115 trackMouse: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
116 # not just for show- we use the mouse pos sometimes
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
117 for evName in ['mousemove', 'touchmove']
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
118 @addEventListener evName, (ev) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
119 ev.preventDefault()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
120
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
121 # todo: consolidate with _editorCoordinates version
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
122 if ev.touches?.length
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
123 ev = ev.touches[0]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
124
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
125 root = @$.cursorCanvas.getBoundingClientRect()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
126 @viewState.mouse.pos($V([ev.pageX - root.left, ev.pageY - root.top]))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
127
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
128 # should be controlled by a checkbox next to follow-player-song-choice
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
129 @sendMouseToVidref() unless window.location.hash.match(/novidref/)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
130
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
131 sendMouseToVidref: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
132 now = Date.now()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
133 if (!@$.vidrefLastSent? || @$.vidrefLastSent < now - 200) && !@songPlaying
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
134 @$.vidrefTime.body = {t: @viewState.latestMouseTime(), source: 'timeline', song: @song}
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
135 @$.vidrefTime.generateRequest()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
136 @$.vidrefLastSent = now
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
137
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
138 bindWheelZoom: (elem) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
139 elem.addEventListener 'mousewheel', (ev) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
140 @viewState.onMouseWheel(ev.deltaY)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
141
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
142 bindKeys: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
143 shortcut.add "Ctrl+P", (ev) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
144 @$.music.seekPlayOrPause(@viewState.latestMouseTime())
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
145 shortcut.add "Ctrl+Escape", => @viewState.frameAll()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
146 shortcut.add "Shift+Escape", => @viewState.frameToEnd()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
147 shortcut.add "Escape", => @viewState.frameCursor()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
148 shortcut.add "L", =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
149 @$.adjustersCanvas.updateAllCoords()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
150 shortcut.add 'Delete', =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
151 for note in @selection.selected()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
152 @project.deleteNote(@graph.Uri(@song), note, @selection)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
153
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
154 makeZoomAdjs: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
155 yMid = => @$.audio.offsetTop + @$.audio.offsetHeight / 2
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
156
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
157 valForPos = (pos) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
158 x = pos.e(1)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
159 t = @viewState.fullZoomX.invert(x)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
160 @setAdjuster('zoom-left', => new AdjustableFloatObservable({
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
161 observable: @viewState.zoomSpec.t1,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
162 getTarget: () =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
163 $V([@viewState.fullZoomX(@viewState.zoomSpec.t1()), yMid()])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
164 getSuggestedTargetOffset: () => $V([-50, 10])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
165 getValueForPos: valForPos
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
166 }))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
167
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
168 @setAdjuster('zoom-right', => new AdjustableFloatObservable({
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
169 observable: @viewState.zoomSpec.t2,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
170 getTarget: () =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
171 $V([@viewState.fullZoomX(@viewState.zoomSpec.t2()), yMid()])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
172 getSuggestedTargetOffset: () => $V([50, 10])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
173 getValueForPos: valForPos
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
174 }))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
175
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
176 panObs = ko.pureComputed({
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
177 read: () =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
178 (@viewState.zoomSpec.t1() + @viewState.zoomSpec.t2()) / 2
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
179 write: (value) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
180 zs = @viewState.zoomSpec
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
181 span = zs.t2() - zs.t1()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
182 zs.t1(value - span / 2)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
183 zs.t2(value + span / 2)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
184 })
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
185
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
186 @setAdjuster('zoom-pan', => new AdjustableFloatObservable({
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
187 observable: panObs
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
188 emptyBox: true
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
189 # fullzoom is not right- the sides shouldn't be able to go
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
190 # offscreen
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
191 getTarget: () => $V([@viewState.fullZoomX(panObs()), yMid()])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
192 getSuggestedTargetOffset: () => $V([0, 0])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
193 getValueForPos: valForPos
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
194 }))