Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control customization part 1 - Set dashed line to controls and borders #2932

Merged
merged 18 commits into from
May 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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