I have a draggable line with a stroke width of 2 and want the user to be able to drag the line even if he clicks and drags near the surrounding area. As per my understanding, the way to do that is to define a custom drawHitFunc for the line. I adapted the code from tutorial here: http://www.html5canvastutorials.com/kineticjs/html5-canvas-kineticjs-custom-hit-function-tutorial/ to define my custom drawHitFunc for the line.
My custom draw hit function is simple--same line but much thicker (25 pixels wide). However, this does not seem to work. The drag only works if I carefully place my mouse pointer right on the line and then drag. Based on the drawHitFunc defined below, it should work even if I click and drag near the line. What am I doing wrong?
Here is the drawHitFunc snippet:
function(canvas) { var context = canvas.getContext(); context.beginPath(); context.lineWidth = 25; context.moveTo(this.getPoints()[0].x, this.getPoints()[0].y); context.lineTo(this.getPoints()[1].x, this.getPoints()[1].y); context.closePath(); canvas.fillStroke(this); }
The full failing example is at: http://jsfiddle.net/BwF6K/
Any help pointing out what I missed is appreciated.
Thanks.