diff light9/web/paint/paint-elements.coffee @ 1573:20f48a0e7135

hover mode shows best match Ignore-this: 3b25ed8ebb8e6be38a3afa0d077e78ba
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 28 May 2017 09:05:37 +0000
parents 0480fc790527
children ef7ddef3acb5
line wrap: on
line diff
--- a/light9/web/paint/paint-elements.coffee	Sun May 28 08:50:56 2017 +0000
+++ b/light9/web/paint/paint-elements.coffee	Sun May 28 09:05:37 2017 +0000
@@ -5,6 +5,9 @@
   addStroke: (pts, color) ->
     @strokes.push({pts: pts, color: color})
 
+  hover: (pos) ->
+    @strokes = [{pts: [pos, [pos[0], pos[1] + .01]], color: "#ffffff"}]
+
   getDoc: ->
     {strokes: @strokes}
 
@@ -31,6 +34,7 @@
   listeners: 'iron-resize': 'onResize'
   properties: {
     bg: { type: String },
+    tool: { type: String },
     painting: { type: Object } # output
   }
   ready: ->
@@ -43,21 +47,36 @@
     @$.paint.addEventListener('touchmove', @onMove.bind(@))
     @$.paint.addEventListener('touchend', @onUp.bind(@))
 
+    @hover = _.throttle((ev) =>
+          @painting.hover(@evPos(ev))
+          @fire('paintingChanged', @painting)
+        , 100)
+
+
   evPos: (ev) ->
     px = (if ev.touches?.length? then [Math.round(ev.touches[0].clientX),
                                        Math.round(ev.touches[0].clientY)] else [ev.x, ev.y])
     return [px[0] / @size[0], px[1] / @size[1]]
 
   onDown: (ev) ->
-    # if it's on an existing one, do selection
-    @stroke = new Stroke(@evPos(ev), '#aaaaaa', @size)
-    @stroke.appendElem(@$.paint)
+    switch @tool
+      when "hover"
+        @onMove(ev)
+      when "paint"
+        # if it's on an existing one, do selection
+        @stroke = new Stroke(@evPos(ev), '#aaaaaa', @size)
+        @stroke.appendElem(@$.paint)
     @scopeSubtree(@$.paint)
 
   onMove: (ev) ->
-    # ..or move selection
-    return unless @stroke
-    @stroke.move(@evPos(ev))
+    switch @tool
+      when "hover"
+        @hover(ev)
+
+      when "paint"
+        # ..or move selection
+        return unless @stroke
+        @stroke.move(@evPos(ev))
 
   onUp: (ev) ->
     return unless @stroke