How to start drawing a path immediately after setting the canvas to drawing mode in FabricJS? -


i'm trying detect if object has been selected on mouse down event, , if no object selected start drawing in fabric. such can't leave canvas in drawing mode, need set once have determined mouse down event had no target. @ moment i've tried retriggering mouse down event on canvas la:

this.canvas.on('mouse:down', function (e) {         if(e.target === null){ //the event had no target             this.isdrawingmode = true; //set canvas drawing mode             this.trigger('mouse:down'); //retrigger mouse down event     }}); 

but i'm not lucky. event retriggered path doesn't begin drawing on canvas. have ideas?

you can call function called fabric if in drawingmode before mouse down.

be aware of if condition inserted !this.isdrawingmode or infinite loop of recursion.

var canvas = new fabric.canvas('c');  canvas.add(new fabric.rect({width: 50, height: 50}));  canvas.on('mouse:down', function(opt) {    if (!opt.target && !this.isdrawingmode) {      canvas.isdrawingmode = true;      canvas._onmousedownindrawingmode(opt.e)    }  })
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.18/fabric.min.js"></script>  <canvas id="c" ></canvas>


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -