How can i change the rotation icon in fabricjs

前端 未结 7 1935
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-03 03:45

Please guide me to modify Fabricjs to add custom icon for Rotation.

I get some of the answers but it is not working fine.

Please let me know the code to chan

7条回答
  •  囚心锁ツ
    2021-01-03 04:17

    This code works in Edge ,Chrome , FireFox, Try this, or You can copy the function from core js library file and then you can replace the ctx.drawImage function

     fabric.Object.prototype.drawControls = function (ctx) {
                if (!this.hasControls) {
                    return this;
                }
                var wh = this._calculateCurrentDimensions(), width = wh.x, height = wh.y, scaleOffset = this.cornerSize, left = -(width + scaleOffset) / 2, top = -(height + scaleOffset) / 2, methodName = this.transparentCorners ? "stroke" : "fill";
                ctx.save();
                ctx.strokeStyle = ctx.fillStyle = this.cornerColor;
                if (!this.transparentCorners) {
                    ctx.strokeStyle = this.cornerStrokeColor;
                }
                this._setLineDash(ctx, this.cornerDashArray, null);
                this._drawControl("tl", ctx, methodName, left, top);
                this._drawControl("tr", ctx, methodName, left + width, top);
                this._drawControl("bl", ctx, methodName, left, top + height);
                this._drawControl("br", ctx, methodName, left + width, top + height);
                if (!this.get("lockUniScaling")) {
                    this._drawControl("mt", ctx, methodName, left + width / 2, top);
                    this._drawControl("mb", ctx, methodName, left + width / 2, top + height);
                    this._drawControl("mr", ctx, methodName, left + width, top + height / 2);
                    this._drawControl("ml", ctx, methodName, left, top + height / 2);
                }
                if (this.hasRotatingPoint) {
                    this._drawControl("mtr", ctx, methodName, left + width / 2, top - this.rotatingPointOffset);
                    var rotate = new Image(), rotateLeft, rotateTop;
                    rotate.src = rotate_icon;
                    rotateLeft = left + width / 2;
                    rotateTop = top - this.rotatingPointOffset;
                    ctx.drawImage(rotate, rotateLeft-3, rotateTop-1, 18, 18);
    
                }
                ctx.restore();
                return this;
            };
    

提交回复
热议问题