changeset 1702:c8543026d609

extract cursor-canvas code Ignore-this: 7c9fe7c56c173ca59458f8c29e743a84
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 29 Apr 2018 12:21:39 +0000
parents c8779022f557
children b46f6977168b
files light9/web/timeline/cursor_canvas.coffee light9/web/timeline/timeline.coffee
diffstat 2 files changed, 69 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light9/web/timeline/cursor_canvas.coffee	Sun Apr 29 12:21:39 2018 +0000
@@ -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
--- a/light9/web/timeline/timeline.coffee	Fri Apr 27 08:08:59 2018 +0000
+++ b/light9/web/timeline/timeline.coffee	Sun Apr 29 12:21:39 2018 +0000
@@ -687,74 +687,6 @@
   
 
 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: