# HG changeset patch # User Drew Perttula # Date 2018-04-29 12:21:39 # Node ID c8543026d6097b452702916bafbd63325c5c4ea8 # Parent c8779022f557ffabb47c3cc6b7477609fbb7b814 extract cursor-canvas code Ignore-this: 7c9fe7c56c173ca59458f8c29e743a84 diff --git a/light9/web/timeline/cursor_canvas.coffee b/light9/web/timeline/cursor_canvas.coffee new file mode 100644 --- /dev/null +++ b/light9/web/timeline/cursor_canvas.coffee @@ -0,0 +1,69 @@ + +Polymer + is: 'light9-cursor-canvas' + behaviors: [ Polymer.IronResizableBehavior ] + listeners: 'iron-resize': 'update' + + ready: -> + @mouseX = 0 + @mouseY = 0 + @cursorPath = null + @ctx = @$.canvas.getContext('2d') + + update: (ev) -> + @$.canvas.width = ev.target.offsetWidth + @$.canvas.height = ev.target.offsetHeight + @redraw() + + setMouse: (pos) -> + @mouseX = pos.e(1) + @mouseY = pos.e(2) + @redraw() + + setCursor: (y1, h1, y2, h2, fullZoomX, zoomInX, cursor) -> + + xZoomedOut = fullZoomX(cursor.t()) + xZoomedIn = zoomInX(cursor.t()) + + @cursorPath = { + top0: $V([xZoomedOut, y1]) + top1: $V([xZoomedOut, y1 + h1]) + mid0: $V([xZoomedIn + 2, y2 + h2]) + mid1: $V([xZoomedIn - 2, y2 + h2]) + mid2: $V([xZoomedOut - 1, y1 + h1]) + mid3: $V([xZoomedOut + 1, y1 + h1]) + bot0: $V([xZoomedIn, y2 + h2]) + bot1: $V([xZoomedIn, @offsetParent.offsetHeight]) + } + @redraw() + + redraw: -> + @ctx.clearRect(0, 0, @$.canvas.width, @$.canvas.height) + + @ctx.strokeStyle = '#fff' + @ctx.lineWidth = 0.5 + @ctx.beginPath() + Drawing.line(@ctx, $V([0, @mouseY]), $V([@$.canvas.width, @mouseY])) + Drawing.line(@ctx, $V([@mouseX, 0]), $V([@mouseX, @$.canvas.height])) + @ctx.stroke() + + if @cursorPath + @ctx.strokeStyle = '#ff0303' + @ctx.lineWidth = 1.5 + @ctx.beginPath() + Drawing.line(@ctx, @cursorPath.top0, @cursorPath.top1) + @ctx.stroke() + + @ctx.fillStyle = '#9c0303' + @ctx.beginPath() + @ctx.moveTo(@cursorPath.mid0.e(1), @cursorPath.mid0.e(2)) + @ctx.lineTo(p.e(1), p.e(2)) for p in [ + @cursorPath.mid1, @cursorPath.mid2, @cursorPath.mid3] + @ctx.fill() + + @ctx.strokeStyle = '#ff0303' + @ctx.lineWidth = 3 + @ctx.beginPath() + Drawing.line(@ctx, @cursorPath.bot0, @cursorPath.bot1, '#ff0303', '3px') + @ctx.stroke() + \ No newline at end of file diff --git a/light9/web/timeline/timeline.coffee b/light9/web/timeline/timeline.coffee --- a/light9/web/timeline/timeline.coffee +++ b/light9/web/timeline/timeline.coffee @@ -687,74 +687,6 @@ deleteNote = (graph, song, note, selecti Polymer - is: 'light9-cursor-canvas' - behaviors: [ Polymer.IronResizableBehavior ] - listeners: 'iron-resize': 'update' - - ready: -> - @mouseX = 0 - @mouseY = 0 - @cursorPath = null - @ctx = @$.canvas.getContext('2d') - - update: (ev) -> - @$.canvas.width = ev.target.offsetWidth - @$.canvas.height = ev.target.offsetHeight - @redraw() - - setMouse: (pos) -> - @mouseX = pos.e(1) - @mouseY = pos.e(2) - @redraw() - - setCursor: (y1, h1, y2, h2, fullZoomX, zoomInX, cursor) -> - - xZoomedOut = fullZoomX(cursor.t()) - xZoomedIn = zoomInX(cursor.t()) - - @cursorPath = { - top0: $V([xZoomedOut, y1]) - top1: $V([xZoomedOut, y1 + h1]) - mid0: $V([xZoomedIn + 2, y2 + h2]) - mid1: $V([xZoomedIn - 2, y2 + h2]) - mid2: $V([xZoomedOut - 1, y1 + h1]) - mid3: $V([xZoomedOut + 1, y1 + h1]) - bot0: $V([xZoomedIn, y2 + h2]) - bot1: $V([xZoomedIn, @offsetParent.offsetHeight]) - } - @redraw() - - redraw: -> - @ctx.clearRect(0, 0, @$.canvas.width, @$.canvas.height) - - @ctx.strokeStyle = '#fff' - @ctx.lineWidth = 0.5 - @ctx.beginPath() - Drawing.line(@ctx, $V([0, @mouseY]), $V([@$.canvas.width, @mouseY])) - Drawing.line(@ctx, $V([@mouseX, 0]), $V([@mouseX, @$.canvas.height])) - @ctx.stroke() - - if @cursorPath - @ctx.strokeStyle = '#ff0303' - @ctx.lineWidth = 1.5 - @ctx.beginPath() - Drawing.line(@ctx, @cursorPath.top0, @cursorPath.top1) - @ctx.stroke() - - @ctx.fillStyle = '#9c0303' - @ctx.beginPath() - @ctx.moveTo(@cursorPath.mid0.e(1), @cursorPath.mid0.e(2)) - @ctx.lineTo(p.e(1), p.e(2)) for p in [ - @cursorPath.mid1, @cursorPath.mid2, @cursorPath.mid3] - @ctx.fill() - - @ctx.strokeStyle = '#ff0303' - @ctx.lineWidth = 3 - @ctx.beginPath() - Drawing.line(@ctx, @cursorPath.bot0, @cursorPath.bot1, '#ff0303', '3px') - @ctx.stroke() - -Polymer is: 'light9-adjusters-canvas' behaviors: [ Polymer.IronResizableBehavior ] properties: