javascript - Use Fabric.js freeDraw how to remove controls and borders -


/**   * created xj on 2017/9/11.   */  var circle,origx,origy;  prototypefabric.circle={      drawcircle:function(){          circlemode=true;      },      addcenterpoint:function(options){          var pointer=canvas.getpointer(options.e);          origx=pointer.x;          origy=pointer.y;          circle= new fabric.circle({              radius: 1,              fill: '',              stroke: 'red',              strokewidth: 1,              left: pointer.x,              top: pointer.y,              originx:'center',              originy:'center',              selectable: false,              hasborders: false,              hascontrols: false          });          canvas.add(circle);        },      generatecircle:function(options){          var pointer=canvas.getpointer(options.e);          var r=calculate.linelength(origx,origy,pointer.x,pointer.y).tofixed(2);          text=new fabric.text('radius'+r+'('+origx.tofixed(2)+','+origy.tofixed(2)+')',{left:pointer.x,top:pointer.y,fontsize:12,hasborders: false,              hascontrols: false});          canvas.add(text);            circle.set({              radius:calculate.linelength(origx,origy,pointer.x,pointer.y).tofixed(2),              selectable: true,              hasborders: false,              hascontrols: false          });          canvas.selection = true;      }  }

this main function, have set controls, hope when drawing down,it has no borders,and haven't controled, can selectable , scale when mousedown, when down ,it have borders , controls, 1 tell me mistake is, thanks

var prototypefabric = new function () {      this.initcanvas = function () {          canvas = window._canvas = new fabric.canvas('c');          canvas.setwidth($("#mycanvas").width());          canvas.setheight($(window).height()-$(".div_header").height()-$(".canvas_header").height()-$(".canvas_footer").height());          //canvas.selection = false;            canvas.on('mouse:down', function (options) {              startx=options.e.x;              starty=options.e.y;                            if(circlemode){                  isdown=true;                  prototypefabric.circle.addcenterpoint(options);              }          });          canvas.on('mouse:up', function (options) {              circlemode=false;              isdown=false;          });          canvas.on('mouse:move', function (options) {                           canvas.remove(text);              canvas.renderall();                if(circlemode&&isdown){                  prototypefabric.circle.generatecircle(options);                  canvas.renderall();              }              canvas.renderall();          });      };    };  var calculate={      linelength:function(x1,y1,x2,y2){          return math.sqrt(math.pow(x2-x1,2)+math.pow(y2-y1,2))      }  };

the above mouse event,when $('.create-circle') click, begin draw circle, canvas mousedown set isdown=true;

    $('.create-circle').click(function() {          polygonmode = false;          linemode=false;          //circlemode=true;          prototypefabric.circle.drawcircle();      });


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -