Skip to content

Commit

Permalink
Control customization part 1 - Set dashed line to controls and borders (
Browse files Browse the repository at this point in the history
#2932)

added:
cornerDashArray
borderDashArray
borderScaleFactor influences both border and controls now
changed default corner size to 13: (a default size of 12 is always out of focus when borders are on focus and viceversa, at least now they are same. difference is not noticeable because the 1st and 12th pixel where always across 2 different pixels)
  • Loading branch information
asturur committed May 3, 2016
1 parent e032cae commit 3c9fb41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/mixins/object_interactivity.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@
height = wh.y + strokeWidth;

ctx.save();
ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
ctx.strokeStyle = this.borderColor;
ctx.lineWidth = strokeWidth;
this._setLineDash(ctx, this.borderDashArray, null);

ctx.strokeRect(
-width / 2,
Expand Down Expand Up @@ -254,10 +253,8 @@
height = wh.y + strokeWidth + 2 * this.padding;

ctx.save();

ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
this._setLineDash(ctx, this.borderDashArray, null);
ctx.strokeStyle = this.borderColor;
ctx.lineWidth = strokeWidth;

ctx.strokeRect(
-width / 2,
Expand Down Expand Up @@ -294,9 +291,8 @@
ctx.save();

ctx.lineWidth = 1;

ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;
ctx.strokeStyle = ctx.fillStyle = this.cornerColor;
this._setLineDash(ctx, this.cornerDashArray, null);

// top-left
this._drawControl('tl', ctx, methodName,
Expand Down
20 changes: 19 additions & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
* @type Number
* @default
*/
cornerSize: 12,
cornerSize: 13,

/**
* When true, object's controlling corners are rendered as transparent inside (i.e. stroke instead of fill)
Expand Down Expand Up @@ -441,13 +441,27 @@
*/
borderColor: 'rgba(102,153,255,0.75)',

/**
* Array specifying dash pattern of an object's borders (hasBorder must be true)
* @since 1.6.2
* @type Array
*/
borderDashArray: null,

/**
* Color of controlling corners of an object (when it's active)
* @type String
* @default
*/
cornerColor: 'rgba(102,153,255,0.5)',

/**
* Array specifying dash pattern of an object's control (hasBorder must be true)
* @since 1.6.2
* @type Array
*/
cornerDashArray: null,

/**
* When true, this object will use center point as the origin of transformation
* when being scaled via the controls.
Expand Down Expand Up @@ -1117,8 +1131,12 @@
options;
matrix = fabric.util.multiplyTransformMatrices(vpt, matrix);
options = fabric.util.qrDecompose(matrix);

ctx.save();
ctx.translate(options.translateX, options.translateY);
ctx.lineWidth = 1 / this.borderScaleFactor;
ctx.globalAlpha = this.isMoving ? this.borderOpacityWhenMoving : 1;

if (this.group && this.group === this.canvas.getActiveGroup()) {
ctx.rotate(degreesToRadians(options.angle));
this.drawBordersInGroup(ctx, options);
Expand Down

0 comments on commit 3c9fb41

Please sign in to comment.